Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ODF Validator using Maven #215

Closed
Tracked by #39
Asbjoedt opened this issue May 4, 2023 · 7 comments · Fixed by #221
Closed
Tracked by #39

Integrate ODF Validator using Maven #215

Asbjoedt opened this issue May 4, 2023 · 7 comments · Fixed by #221
Assignees
Milestone

Comments

@Asbjoedt
Copy link

Asbjoedt commented May 4, 2023

Hi!

I am having trouble integrating the ODF Validator through Maven in my Java project.

I can't find the proper import option as part of org.odftoolkit.

I also had to add <type>pom</type> to the pom.xml dependency configuration. See issue: #212

This is the code I am using, which in theory should work (I think):

import org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument;
import org.odftoolkit.odfvalidator.ODFValidator;
import org.odftoolkit.odfvalidator.result.ValidationResult;

public class validate {
    // Validate OpenDocument Spreadsheets using ODF Validator
    public boolean Validate_ODFValidator(String filepath)  throws Exception {
        boolean valid = false;

        OdfSpreadsheetDocument spreadsheet = OdfSpreadsheetDocument.loadDocument(filepath);
        ODFValidator validator = new ODFValidator();
        ValidationResult result = validator.validate(spreadsheet);

        // Inform user and return boolean
        if (result.hasErrors()) {
            System.out.println("VALIDATE: The spreadsheet file is invalid.");
            System.out.println("VALIDATE: " + result.toString());
        } else {
            valid = true;
            System.out.println("VALIDATE: The spreadsheet file is valid.");
        }
        return valid;
    }
}

Can you help me?

mistmist added a commit that referenced this issue May 23, 2023
Neither the .war file nor the -with-dependencies.jar file can be easily
reused as a Maven dependency; let's try if this works better.
@mistmist
Copy link
Contributor

mistmist commented May 23, 2023

so apparently the binary files in the maven repository are:

odfvalidator-0.11.0.war
odfvalidator-0.11.0-jar-with-dependencies.jar

the .war file is built because validator/pom.xml specifies <packaging>war</packaging>.
the -with-dependencies.jar file is built with some "maven-assembly-plugin" based on src/main/assembly/src.xml.

i'm afraid none of these is designed to be used as a library jar file, these are intended for use as a web application or a command line application.

in contrast in odfdom/pom.xml there is an ordinary <packaging>jar</packaging>.

perhaps it will "work" to manually download -with-dependencies.jar and put
<scope>system</scope>
<systemPath>somewhere/odfvalidator-0.11.0-jar-with-dependencies.jar</systemPath>
into the <dependency> element but clearly that's awful and i don't know what all the classes from all of the dependencies that are bundled in the jar file are going to do to your application.

now it's not clear to me how to add a plain jar file to be built by validator/pom.xml; is that even possible or should there be an additional pom.xml to build the plain jar file and another to build the .war file?

hmm... apparently there's an <attachClasses> element:

https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#attachClasses

if i add this i get one new file, and it appears to have the appropriate content:
validator/target/odfvalidator-0.12.0-SNAPSHOT/WEB-INF/lib/odfvalidator-0.12.0-SNAPSHOT.jar

a special syntax is required to reference it as a dependency via <classifier>classes</classifier>, see above link.

what i don't know, will "mvn deploy" upload this file or not?

@svanteschubert svanteschubert linked a pull request May 23, 2023 that will close this issue
mistmist added a commit that referenced this issue May 23, 2023
Neither the .war file nor the -with-dependencies.jar file can be easily
reused as a Maven dependency; let's try if this works better.
@mistmist mistmist added this to the 0.12.0 milestone May 24, 2023
mistmist added a commit that referenced this issue May 25, 2023
Argh, accidentally wrote archiveClasses not attachClasses as intended.
svanteschubert pushed a commit that referenced this issue May 25, 2023
Argh, accidentally wrote archiveClasses not attachClasses as intended.
@svanteschubert
Copy link
Contributor

svanteschubert commented May 25, 2023

@Asbjoedt
The automatic close of this issue by merging the first pull request #221
was a bit optimistic.

We needed two further iterations

#227
#228

but now the latest SNAPSHOT release
https://oss.sonatype.org/content/repositories/snapshots/org/odftoolkit/odfvalidator/0.12.0-SNAPSHOT/
should finally fix this issue!

Could you please test it with Maven and give feedback using the following configuration:

<groupId>org.odftoolkit</groupId>
<artifactId>odfvalidator</artifactId>
<version>0.12.0-SNAPSHOT</version>

@mistmist
Copy link
Contributor

mistmist commented May 26, 2023

according to https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#attachClasses that's not complete, you need to use:

<dependency>
  <groupId>org.odftoolkit</groupId>
  <artifactId>odfvalidator</artifactId>
  <version>0.12.0-SNAPSHOT</version>
  <classifier>classes</classifier>
</dependency>

please try and report if this actually works.

@Asbjoedt
Copy link
Author

Asbjoedt commented Jun 2, 2023

Hi

I tried to test this (spent quite some time) but I cannot resolve the dependency. I think it is my own problems with using Idea to import the jar file into the external libraries without using Maven Central. I hope you can find other help on how to test if this fix now works.

@svanteschubert
Copy link
Contributor

svanteschubert commented Jun 8, 2023

@Asbjoedt
Do you find the latest Maven JARs on your disk?

Windows:
C:\Users\<YOUR_USER_NAME>\.m2\repository\org\odftoolkit\odfvalidator\0.12.0-SNAPSHOT

Linux:
/home/<YOUR_USER_NAME>/.m2/repository/org/odftoolkit/odfvalidator/0.12.0-SNAPSHOT

I have aside of Netbeans as well IntelliJ, what is your scenario? Anything you might provide and I download to verify?

In any case, good luck! :-) @Asbjoedt

@Asbjoedt
Copy link
Author

Asbjoedt commented Jun 9, 2023

@svanteschubert

Thanks for the reply.

I don't see that file/folder.

I have this folder
C:\Users\USERNAME.m2\repository\org\odftoolkit\odfvalidator\0.12.0

It contains these two files
C:\Users\USERNAME.m2\repository\org\odftoolkit\odfvalidator\0.12.0\odfvalidator-0.12.0.pom.lastUpdated
C:\Users\USERNAME.m2\repository\org\odftoolkit\odfvalidator\0.12.0\odfvalidator-0.12.0-classes.jar.lastUpdated

@svanteschubert
Copy link
Contributor

svanteschubert commented Jul 13, 2023

@Asbjoedt
This directory is a cache for Maven artefacts, that you:

  1. Build your self and deployed locally: mvn install
  2. Downloaded from Maven because they where required by a Maven dependency of a project you built.

If you checkout the latest sources of ODF TOOLKIT:

  1. git clone https://github.com/tdf/odftoolkit odftoolkit-latest
  2. cd odftoolkit-latest
  3. mvn install

You will have the same directory on your disk:
C:\Users\<YOUR_USER_NAME>\.m2\repository\org\odftoolkit\odfvalidator\0.12.0-SNAPSHOT

Sorry, I have forgotten to mention this earlier.

Best regards,
Svante

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants