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

Version is missing in package meta-inf #1809

Closed
gertjanal opened this issue Jul 18, 2022 · 6 comments
Closed

Version is missing in package meta-inf #1809

gertjanal opened this issue Jul 18, 2022 · 6 comments
Milestone

Comments

@gertjanal
Copy link

For testing, it would be great to get the jsoup version at runtime.

    @Test
    void testVersions() {
        System.out.println(Jsoup.class.getPackage().getSpecificationVersion());
        System.out.println(Jsoup.class.getPackage().getImplementationVersion());
        System.out.println(Jsoup.class.getPackage().getSpecificationVersion());
    }

Version 1.15.2 (and before) returns

null
null
null

It shouldn't be that hard: https://stackoverflow.com/questions/921667/how-do-i-add-an-implementation-version-value-to-a-jar-manifest-using-maven

jhy added a commit that referenced this issue Aug 7, 2022
@jhy jhy added this to the 1.15.3 milestone Aug 7, 2022
@jhy
Copy link
Owner

jhy commented Aug 7, 2022

Thanks, done

@jhy jhy closed this as completed Aug 7, 2022
@jhy jhy added the improvement label Aug 7, 2022
@JamoCA
Copy link

JamoCA commented Aug 24, 2022

I'm using ColdFusion and Oracle JDK 11.0.15.1. I've updated jsoup to 1.15.3, but I'm unable to programmatically determine the version.

I'm using the following CFML code to dump version and both return an undefined object instead of the expected string denoting the current version. (Am I doing it incorrectly or is it not working?)

jsoup = createobject("java", "org.jsoup.Jsoup");
writedump(var="#jsoup.getClass().getPackage().getSpecificationVersion()#");
writedump(var="#jsoup.getClass().getPackage().getImplementationVersion()#");

@jhy
Copy link
Owner

jhy commented Aug 24, 2022

@JamoCA I just tested, and this works in Java. Not sure how that translates to ColdFusion though.

Package jsoupPackage = Jsoup.class.getPackage();
System.out.println(jsoupPackage.getImplementationTitle());
System.out.println(jsoupPackage.getImplementationVersion());

Produces:

jsoup Java HTML Parser
1.15.3

If you can get it to work, or it works for other packages and not jsoup, would be good if you can add that code here.

Also, check that your deployed package actually includes the jsoup META-INF/MANIFEST.MF file, as that's where the classloader gets this data from. I noticed packing like a fat-jar (multiple dependent jars + application code), or a shaded jar, will often drop each packages individual manifest and therefore lose the data. In that case, it might be better to create a zip of the jars so the manifests are maintained.

@JamoCA
Copy link

JamoCA commented Aug 25, 2022

I've spent a while researching this and it continues to return undefined. I have to add try/catch around the request in order to prevent it from crashing the process.

I started reviewing manifests of other JARs that we use in production. I noticed that PDFBox had a Specification-Version key in their manifest, but when dumping the object, I noticed that they also had a specific getVersion() method to provide the information.
https://pdfbox.apache.org/docs/2.0.2/javadocs/org/apache/pdfbox/util/Version.html

Could a getVersion method be added? I believe, based on this link below, that my only workaround would be to write a routine to locate the physical path of the JAR, unzip the manifest file and parse the lines of text. (Not very optimal.)
https://stackoverflow.com/q/38204059/693068

@jhy
Copy link
Owner

jhy commented Aug 25, 2022

I checked PDF Box's implementation of getVersion() -- it's coming from a resource file, not the manifest. Perhaps as a way to workaround the packaging issue in my edit above.

https://github.com/apache/pdfbox/blob/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java
https://github.com/apache/pdfbox/blob/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/version.properties

So, that might be a good approach. (Although I do note that jsoup used to use resource files for the named character entity definitions, and would see crashes on various Android forks as an app couldn't load jar resources on first install. Hopefully that's improved over the years...)

@JamoCA
Copy link

JamoCA commented Aug 25, 2022

I haven't experienced any crashes related to named entities since I've been using the jsoup library. The ability to determine the version programmatically would have been extremely beneficial so I could write workarounds in functions to deal with recent internal changes in function names and/or behavior.

I tried this example (which is pretty much the same as yours & mine) and NULL isn't returned... undefined is returned and it causes an error to be thrown.
https://timjansen.github.io/jarfiller/javabasics/jar/jarmetadata.xhtml

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

No branches or pull requests

3 participants