[Git][java-team/maven-shared-jar][upstream] New upstream version 3.2.1
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Wed Nov 11 00:28:50 GMT 2026
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / maven-shared-jar
Commits:
9944395c by Emmanuel Bourg at 2026-11-10T22:57:07+01:00
New upstream version 3.2.1
- - - - -
23 changed files:
- .asf.yaml
- + LICENSE
- README.md
- pom.xml
- src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java
- src/main/java/org/apache/maven/shared/jar/JarData.java
- src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java
- src/main/java/org/apache/maven/shared/jar/classes/JarVersionedRuntimes.java
- src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java
- src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java
- − src/site/apt/index.apt.vm
- + src/site/markdown/index.md
- src/site/site.xml
- src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java
- src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
- src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
- src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
- + src/test/java/org/apache/maven/shared/jar/classes/JarVersionedRuntimesTest.java
- src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
- src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
- + src/test/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposerTest.java
- + src/test/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzerTest.java
- + src/test/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzerTest.java
Changes:
=====================================
.asf.yaml
=====================================
@@ -22,16 +22,22 @@ notifications:
jira_options: link label
github:
- description: "Apache Maven JAR Utilities"
+ description: "Apache Maven JAR Analysis Utilities"
homepage: https://maven.apache.org/shared/maven-shared-jar/
labels:
- java
- build-management
- maven-shared
- maven
+ protected_branches:
+ master: { }
+ pull_requests:
+ del_branch_on_merge: true
enabled_merge_buttons:
squash: true
merge: false
rebase: true
autolink_jira:
- - MSHARED
\ No newline at end of file
+ - MSHARED
+ features:
+ issues: true
=====================================
LICENSE
=====================================
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
=====================================
README.md
=====================================
@@ -14,10 +14,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-Contributing to [Apache Maven JAR Utilities](https://maven.apache.org/shared/maven-shared-jar/)
+Contributing to [Apache Maven JAR Analysis Utilities](https://maven.apache.org/shared/maven-shared-jar/)
======================
-[][jira]
[][license]
[](https://search.maven.org/artifact/org.apache.maven.shared/maven-shared-jar)
[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-shared-jar/README.md)
@@ -25,7 +24,7 @@ Contributing to [Apache Maven JAR Utilities](https://maven.apache.org/shared/mav
[][test-results]
-You have found a bug or you have an idea for a cool new feature? Contributing
+You have found a bug, or you have an idea for a cool new feature? Contributing
code is a great way to give something back to the open source community. Before
you dig right into the code, there are a few guidelines that we need
contributors to follow so that we can have a chance of keeping on top of
@@ -34,7 +33,6 @@ things.
Getting Started
---------------
-+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
+ Make sure you have a [GitHub account](https://github.com/signup/free).
+ If you're planning to implement a new feature, it makes sense to discuss your changes
on the [dev list][ml-list] first.
@@ -60,37 +58,23 @@ There are some guidelines which will make applying PRs easier for us:
+ Create minimal diffs - disable on save actions like reformat source code or organize imports.
If you feel the source code should be reformatted, create a separate PR for this change.
+ Check for unnecessary whitespace with `git diff --check` before committing.
-+ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue.
-```
-[MSHARED-XXX] - Subject of the JIRA Ticket
- Optional supplemental description.
-```
+ Make sure you have added the necessary tests (JUnit/IT) for your changes.
+ Run all the tests with `mvn -Prun-its verify` to assure nothing else was accidentally broken.
+ Submit a pull request to the repository in the Apache organization.
-+ Update your JIRA ticket and include a link to the pull request in the ticket.
If you plan to contribute on a regular basis, please consider filing a [contributor license agreement][cla].
-Making Trivial Changes
-----------------------
-
-For changes of a trivial nature to comments and documentation, it is not always
-necessary to create a new ticket in JIRA. In this case, it is appropriate to
-start the first line of a commit with '(doc)' instead of a ticket number.
-
Additional Resources
--------------------
+ [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch)
-+ [Apache Maven Shared Components project page][jira]
+ [Contributor License Agreement][cla]
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
-+ [Apache Maven Twitter Account](https://twitter.com/ASFMavenProject)
-+ #Maven IRC channel on freenode.org
++ [Apache Maven X Account](https://x.com/ASFMavenProject)
++ [Apache Maven Bluesky Account](https://bsky.app/profile/maven.apache.org)
++ [Apache Maven Mastodon Account](https://mastodon.social/deck/@ASFMavenProject@fosstodon.org)
-[jira]: https://issues.apache.org/jira/projects/MSHARED/
[license]: https://www.apache.org/licenses/LICENSE-2.0
[ml-list]: https://maven.apache.org/mailing-lists.html
[code-style]: https://maven.apache.org/developers/conventions/code.html
=====================================
pom.xml
=====================================
@@ -23,25 +23,25 @@
<parent>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-components</artifactId>
- <version>43</version>
+ <version>49</version>
<relativePath />
</parent>
<artifactId>maven-shared-jar</artifactId>
- <version>3.2.0</version>
+ <version>3.2.1</version>
- <name>Apache Maven JAR Utilities</name>
+ <name>Apache Maven JAR Analysis Utilities</name>
<description>Utilities that help identify the contents of a JAR, including Java class analysis and Maven metadata analysis.</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-shared-jar.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-shared-jar.git</developerConnection>
- <tag>maven-shared-jar-3.2.0</tag>
+ <tag>maven-shared-jar-3.2.1</tag>
<url>https://github.com/apache/maven-shared-jar/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
- <system>jira</system>
- <url>https://issues.apache.org/jira/issues/?jql=project+%3D+MSHARED+AND+component+%3D+maven-shared-jar</url>
+ <system>GitHub Issues</system>
+ <url>https://github.com/apache/maven-shared-jar/issues</url>
</issueManagement>
<ciManagement>
<system>Jenkins</system>
@@ -58,7 +58,7 @@
<javaVersion>8</javaVersion>
<mavenVersion>3.6.3</mavenVersion>
<slf4jVersion>1.7.36</slf4jVersion>
- <project.build.outputTimestamp>2024-12-30T18:33:30Z</project.build.outputTimestamp>
+ <project.build.outputTimestamp>2026-09-19T17:46:04Z</project.build.outputTimestamp>
</properties>
<dependencies>
@@ -95,26 +95,26 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
- <version>1.17.1</version>
+ <version>1.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
- <version>6.10.0</version>
+ <version>6.13.0</version>
</dependency>
<!-- Required by BCEL overwritten by maven-artifact -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
- <version>3.17.0</version>
+ <version>3.20.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
- <version>4.4</version>
+ <version>4.6.0</version>
</dependency>
<dependency>
@@ -130,7 +130,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
- <version>1.4.0</version>
+ <version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
=====================================
src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java
=====================================
@@ -31,7 +31,6 @@ import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
/**
* Open a JAR file to be analyzed. Note that once created, the {@link #closeQuietly()} method should be called to
@@ -97,13 +96,7 @@ public class JarAnalyzer {
* will be closed if this occurs.
*/
public JarAnalyzer(File file) throws IOException {
- try {
- this.jarFile = new JarFile(file);
- } catch (ZipException e) {
- ZipException ioe = new ZipException("Failed to open file " + file + " : " + e.getMessage());
- ioe.initCause(e);
- throw ioe;
- }
+ this.jarFile = new JarFile(file);
// Obtain entries list.
List<JarEntry> entries = Collections.list(jarFile.entries());
=====================================
src/main/java/org/apache/maven/shared/jar/JarData.java
=====================================
@@ -50,7 +50,7 @@ public final class JarData {
/**
* Whether the JAR file is Multi-Release.
*/
- private boolean multiRelease;
+ private final boolean multiRelease;
/**
* The hashcode for the entire file's contents.
=====================================
src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java
=====================================
@@ -47,12 +47,12 @@ public class ImportVisitor extends EmptyVisitor {
* Pattern to detect if the import is qualified and allows retrieval of the actual import name from the string via
* the group 1.
*/
- private static final Pattern QUALIFIED_IMPORT_PATTERN = Pattern.compile("L([a-zA-Z][a-zA-Z0-9\\.]+);");
+ private static final Pattern QUALIFIED_IMPORT_PATTERN = Pattern.compile("L([a-zA-Z][a-zA-Z0-9\\.$]+);");
/**
* Pattern that checks whether a string is valid UTF-8. Imports that are not are ignored.
*/
- private static final Pattern VALID_UTF8_PATTERN = Pattern.compile("^[\\(\\)\\[A-Za-z0-9;/]+$");
+ private static final Pattern VALID_UTF8_PATTERN = Pattern.compile("^[\\(\\)\\[A-Za-z0-9;/;$]+$");
/**
* Create an Import visitor.
=====================================
src/main/java/org/apache/maven/shared/jar/classes/JarVersionedRuntimes.java
=====================================
@@ -33,7 +33,7 @@ public class JarVersionedRuntimes {
/**
* Information about the JAR's Multi-Release entries
*/
- private NavigableMap<Integer, JarVersionedRuntime> versionedRuntimeMap;
+ private final NavigableMap<Integer, JarVersionedRuntime> versionedRuntimeMap;
public JarVersionedRuntimes(NavigableMap<Integer, JarVersionedRuntime> versionedRuntimeMap) {
this.versionedRuntimeMap = versionedRuntimeMap;
@@ -53,10 +53,11 @@ public class JarVersionedRuntimes {
/**
* Return the JarClasses associated to the release.
* @param version the release version.
- * @return the JarClasses.
+ * @return the JarClasses, or null if the version is not present.
*/
public JarClasses getJarClasses(Integer version) {
- return versionedRuntimeMap.get(version).getJarClasses();
+ JarVersionedRuntime versionedRuntime = versionedRuntimeMap.get(version);
+ return versionedRuntime != null ? versionedRuntime.getJarClasses() : null;
}
/**
=====================================
src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java
=====================================
@@ -23,9 +23,11 @@ import javax.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
+import java.security.MessageDigest;
import java.util.List;
import java.util.jar.JarEntry;
+import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.JarData;
@@ -34,7 +36,7 @@ import org.slf4j.LoggerFactory;
/**
* Analyzer that calculates the hash code for the entire file. Can be used to detect an exact copy of the file's class
- * data. Useful to see thru a recompile, recompression, or timestamp change.
+ * data. Useful to see through a recompile, recompression, or timestamp change.
*/
@Singleton
@Named("bytecode")
@@ -49,11 +51,13 @@ public class JarBytecodeHashAnalyzer implements JarHashAnalyzer {
List<JarEntry> entries = jarAnalyzer.getClassEntries();
try {
+ MessageDigest sha1 = DigestUtils.getSha1Digest();
for (JarEntry entry : entries) {
try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
- result = DigestUtils.sha1Hex(is);
+ DigestUtils.updateDigest(sha1, is);
}
}
+ result = Hex.encodeHexString(sha1.digest());
jarData.setBytecodeHash(result);
} catch (IOException e) {
logger.warn("Unable to calculate the hashcode.", e);
=====================================
src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java
=====================================
@@ -45,11 +45,10 @@ public class JarFileHashAnalyzer implements JarHashAnalyzer {
String result = jarData.getFileHash();
if (result == null) {
- try {
- try (InputStream inputStream =
- Files.newInputStream(jarData.getFile().toPath())) {
- jarData.setFileHash(DigestUtils.sha1Hex(inputStream));
- }
+ try (InputStream inputStream =
+ Files.newInputStream(jarData.getFile().toPath())) {
+ result = DigestUtils.sha1Hex(inputStream);
+ jarData.setFileHash(result);
} catch (IOException e) {
logger.warn("Unable to calculate the hashcode.", e);
}
=====================================
src/site/apt/index.apt.vm deleted
=====================================
@@ -1,35 +0,0 @@
- -----
- Introduction
- -----
- Brett Porter
- -----
- 2013-07-24
- -----
-
- ~~ Licensed to the Apache Software Foundation (ASF) under one
- ~~ or more contributor license agreements. See the NOTICE file
- ~~ distributed with this work for additional information
- ~~ regarding copyright ownership. The ASF licenses this file
- ~~ to you under the Apache License, Version 2.0 (the
- ~~ "License"); you may not use this file except in compliance
- ~~ with the License. You may obtain a copy of the License at
- ~~
- ~~ http://www.apache.org/licenses/LICENSE-2.0
- ~~
- ~~ Unless required by applicable law or agreed to in writing,
- ~~ software distributed under the License is distributed on an
- ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~~ KIND, either express or implied. See the License for the
- ~~ specific language governing permissions and limitations
- ~~ under the License.
-
- ~~ NOTE: For help with the syntax of this file, see:
- ~~ http://maven.apache.org/doxia/references/apt-format.html
-
-${project.name}
-
- Utilities that help identify the contents of a JAR, including Java class analysis and Maven metadata analysis.
-
-* Using the Utilities
-
- Instructions on how to use the utilities can be found in the {{{./apidocs/index.html} Javadoc Overview}}.
=====================================
src/site/markdown/index.md
=====================================
@@ -0,0 +1,28 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Apache Maven JAR Analysis Utilities
+
+Utilities that help identify the contents of a JAR, including Java class analysis and Maven metadata analysis.
+
+This permits for example to prepare data for [ Dependency File Details section of Dependencies Report](./dependencies.html#Dependency_File_Details).
+
+## Using the Utilities
+
+Instructions on how to use the utilities can be found in the [ Javadoc Overview](./apidocs/index.html).
=====================================
src/site/site.xml
=====================================
@@ -19,19 +19,18 @@ specific language governing permissions and limitations
under the License.
-->
-<project xmlns="http://maven.apache.org/DECORATION/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
+<site xmlns="http://maven.apache.org/SITE/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SITE/2.1.0 https://maven.apache.org/xsd/site-2.1.0.xsd">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<item name="JavaDocs" href="apidocs/index.html"/>
<item name="Source Xref" href="xref/index.html"/>
- <!--item name="FAQ" href="faq.html"/-->
<!-- According to https://issues.apache.org/jira/browse/MNGSITE-152 -->
- <item name="License" href="http://www.apache.org/licenses/"/>
+ <item name="License" href="https://www.apache.org/licenses/"/>
<item name="Download" href="download.html"/>
</menu>
<menu ref="parent"/>
<menu ref="reports"/>
</body>
-</project>
+</site>
=====================================
src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java
=====================================
@@ -27,9 +27,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.opentest4j.AssertionFailedError;
-
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Abstract JarAnalyzer TestCase
@@ -61,7 +60,7 @@ public abstract class AbstractJarAnalyzerTestCase {
for (String failure : failures) {
sb.append("\n - \"").append(failure).append("\"");
}
- throw new AssertionFailedError(sb.toString());
+ fail(sb.toString());
}
}
}
=====================================
src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
=====================================
@@ -19,13 +19,18 @@
package org.apache.maven.shared.jar;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.stream.Collectors;
import java.util.zip.ZipException;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -53,47 +58,76 @@ class JarAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testSealed() throws Exception {
+ void sealed() throws Exception {
JarData jarData = getJarData("evil-sealed-regex-1.0.jar");
assertTrue(jarData.isSealed());
}
@Test
- void testNotSealed() throws Exception {
+ void notSealed() throws Exception {
JarData jarData = getJarData("codec.jar");
assertFalse(jarData.isSealed());
}
@Test
- void testMultiRelease() throws Exception {
+ void multiRelease() throws Exception {
JarData jarData = getJarData("multi-release-test-0.0.1.jar");
assertTrue(jarData.isMultiRelease());
}
@Test
- void testNotMultiRelease() throws Exception {
+ void notMultiRelease() throws Exception {
JarData jarData = getJarData("codec.jar");
assertFalse(jarData.isMultiRelease());
}
@Test
- void testMissingFile() {
+ void missingFile() {
assertThrows(IOException.class, () -> new JarAnalyzer(new File("foo-bar-this-should-not-exist.jar")));
}
@Test
- void testInvalidJarFile() throws Exception {
+ void invalidJarFile() throws Exception {
assertThrows(ZipException.class, () -> getJarAnalyzer("invalid.jar"));
}
@Test
- void testCloseTwice() throws Exception {
+ void closeTwice() throws Exception {
JarAnalyzer jarAnalyzer = getJarAnalyzer("codec.jar");
// no exception should be thrown
- Assertions.assertDoesNotThrow(() -> {
+ assertDoesNotThrow(() -> {
jarAnalyzer.closeQuietly();
jarAnalyzer.closeQuietly();
});
}
+
+ @Test
+ void getClassEntriesFindsClassesWithUnderscores() throws Exception {
+ File jarFile = File.createTempFile("jar-analyzer-underscore", ".jar");
+ jarFile.deleteOnExit();
+
+ try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
+ for (String entryName : new String[] {
+ "org/example/My_Helper.class",
+ "org/example/some_test.class",
+ "org/example/UPPER_CASE.class",
+ "org/example/MyHelper.class"
+ }) {
+ jos.putNextEntry(new JarEntry(entryName));
+ jos.write(new byte[] {1, 2, 3});
+ jos.closeEntry();
+ }
+ }
+
+ jarAnalyzer = new JarAnalyzer(jarFile);
+
+ List<String> classNames =
+ jarAnalyzer.getClassEntries().stream().map(JarEntry::getName).collect(Collectors.toList());
+
+ assertTrue(classNames.contains("org/example/My_Helper.class"), "Missing underscore class: " + classNames);
+ assertTrue(classNames.contains("org/example/some_test.class"), "Missing underscore class: " + classNames);
+ assertTrue(classNames.contains("org/example/UPPER_CASE.class"), "Missing underscore class: " + classNames);
+ assertTrue(classNames.contains("org/example/MyHelper.class"), "Missing regular class: " + classNames);
+ }
}
=====================================
src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
=====================================
@@ -18,11 +18,15 @@
*/
package org.apache.maven.shared.jar.classes;
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
import java.io.File;
-import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.List;
-import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.DescendingVisitor;
import org.apache.bcel.classfile.JavaClass;
@@ -31,8 +35,10 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Import Visitor Test
@@ -40,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
@Test
- void testImportsJxr() throws ClassFormatException, IOException {
+ void importsJxr() throws Exception {
File jxrjar = getSampleJar("jxr.jar");
String classname = "org/apache/maven/jxr/DirectoryIndexer.class";
ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), classname);
@@ -60,7 +66,7 @@ class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testImportsAnt() throws ClassFormatException, IOException {
+ void importsAnt() throws Exception {
File jxrjar = getSampleJar("ant.jar");
String classname = "org/apache/tools/ant/Target.class";
ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), classname);
@@ -108,7 +114,7 @@ class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
"helloworld-24.jar",
"helloworld-25.jar"
})
- void testImportByJDKVersion(String jarName) throws IOException, ClassFormatException {
+ void importByJDKVersion(String jarName) throws Exception {
File jarFile = getSampleJar(jarName);
ClassParser classParser = new ClassParser(jarFile.getAbsolutePath(), "net/test/HelloWorld.class");
@@ -122,4 +128,34 @@ class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
assertNotNull(imports, "Import List");
assertTrue(imports.size() >= 4);
}
+
+ @Test
+ void utf8StringPoolInnerClassReferenceIsKept() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ assumeTrue(compiler != null, "requires a JDK with javac");
+
+ Path source = Files.createTempDirectory("importvisitor-src").resolve("InnerRefHolder.java");
+ Files.write(
+ source,
+ ("package org.test.innertest;\n"
+ + "public class InnerRefHolder {\n"
+ + " public static final String REF = \"org/test/innertest/Outer$Inner\";\n"
+ + "}")
+ .getBytes(StandardCharsets.UTF_8));
+
+ Path classesDir = Files.createTempDirectory("importvisitor-classes");
+ assertEquals(0, compiler.run(null, null, null, "-d", classesDir.toString(), source.toString()), "compilation");
+
+ JavaClass javaClass = new ClassParser(classesDir
+ .resolve("org/test/innertest/InnerRefHolder.class")
+ .toString())
+ .parse();
+ ImportVisitor importVisitor = new ImportVisitor(javaClass);
+ DescendingVisitor descVisitor = new DescendingVisitor(javaClass, importVisitor);
+ javaClass.accept(descVisitor);
+
+ assertTrue(
+ importVisitor.getImports().contains("org.test.innertest.Outer$Inner"),
+ "imports should keep inner class references from the UTF-8 pool");
+ }
}
=====================================
src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
=====================================
@@ -33,12 +33,13 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* JarAnalyzer Classes Test Case
@@ -50,7 +51,7 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
private JarClassesAnalysis analyzer;
@Test
- void testAnalyzeJXR() throws Exception {
+ void analyzeJXR() throws Exception {
JarClasses jclass = getJarClasses("jxr.jar");
assertFalse(jclass.getImports().isEmpty(), "classes.imports.length > 0");
@@ -67,7 +68,7 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testAnalyzeANT() throws Exception {
+ void analyzeANT() throws Exception {
JarClasses jclass = getJarClasses("ant.jar");
assertFalse(jclass.getImports().isEmpty(), "classes.imports.length > 0");
@@ -84,7 +85,7 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testAnalyzeJarWithInvalidClassFile() throws Exception {
+ void analyzeJarWithInvalidClassFile() throws Exception {
JarClasses jclass = getJarClasses("invalid-class-file.jar");
// Doesn't fail, as exceptions are ignored.
@@ -96,14 +97,14 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testAnalyzeJarWithDebug() throws Exception {
+ void analyzeJarWithDebug() throws Exception {
JarClasses jclass = getJarClasses("helloworld-1.4-debug.jar");
assertTrue(jclass.isDebugPresent(), "has debug");
}
@Test
- void testAnalyzeJarWithoutDebug() throws Exception {
+ void analyzeJarWithoutDebug() throws Exception {
JarClasses jclass = getJarClasses("helloworld-1.4.jar");
assertFalse(jclass.isDebugPresent(), "no debug present");
@@ -148,14 +149,14 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testAnalyzeJarWithModuleInfoClass() throws Exception {
+ void analyzeJarWithModuleInfoClass() throws Exception {
JarData jarData = getJarData("tomcat-jni-9.0.75.jar");
JarClasses jclass = jarData.getJarClasses();
assertEquals("1.8", jclass.getJdkRevision());
}
@Test
- void testAnalyzeJarWithOnlyModuleInfoClass() throws Exception {
+ void analyzeJarWithOnlyModuleInfoClass() throws Exception {
JarData jarData = getJarData("module-info-only-test-0.0.1.jar");
assertEquals(10, jarData.getNumEntries());
// root level information
@@ -186,7 +187,7 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testAnalyzeMultiReleaseJarVersion() throws Exception {
+ void analyzeMultiReleaseJarVersion() throws Exception {
JarData jarData = getJarData("multi-release-test-0.0.1.jar");
assertEquals(37, jarData.getNumEntries());
// root level information
@@ -229,12 +230,8 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
assertEquals("[9, 11]", jarVersionedRuntimeMap.keySet().toString());
// test best fit
- try {
- jarVersionedRuntimes.getBestFitJarVersionedRuntime(null);
- fail("It should throw an NPE");
- } catch (NullPointerException e) {
- assertTrue(true);
- }
+ assertThrows(NullPointerException.class, () -> jarVersionedRuntimes.getBestFitJarVersionedRuntime(null));
+
assertNull(jarVersionedRuntimes.getBestFitJarVersionedRuntime(8)); // unreal value but good just for testing
assertEquals(
"9",
@@ -261,26 +258,11 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
.getJarClasses()
.getJdkRevision());
- try {
- jarVersionedRuntimes.getBestFitJarVersionedRuntimeBySystemProperty(null);
- fail("It should throw an NPE");
- } catch (NullPointerException e) {
- assertTrue(true);
- }
-
- try {
- getBestFitReleaseBySystemProperty(jarVersionedRuntimes, null);
- fail("It should throw an NPE");
- } catch (NullPointerException e) {
- assertTrue(true);
- }
-
- try {
- getBestFitReleaseBySystemProperty(jarVersionedRuntimes, "xxx");
- fail("It should throw an ISE");
- } catch (IllegalStateException e) {
- assertTrue(true);
- }
+ assertThrows(
+ NullPointerException.class,
+ () -> jarVersionedRuntimes.getBestFitJarVersionedRuntimeBySystemProperty(null));
+ assertThrows(NullPointerException.class, () -> getBestFitReleaseBySystemProperty(jarVersionedRuntimes, null));
+ assertThrows(IllegalStateException.class, () -> getBestFitReleaseBySystemProperty(jarVersionedRuntimes, "xxx"));
assertNull(getBestFitReleaseBySystemProperty(jarVersionedRuntimes, "8"));
assertEquals(
@@ -309,57 +291,59 @@ class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
* Exposes issue MSHARED-1413
*/
@Test
- public void testAnalyzeMultiReleaseJarWithVersion11HasALowerJdkRevisionClass() {
- try {
- // Version 11 has one class compiled to target Java 1.8
- JarData jarData = getJarData("multi-release-version-with-lower-jdk-revision-class-0.0.1.jar");
- JarClasses jclass = jarData.getJarClasses();
-
- assertNull(jclass.getJdkRevision());
-
- JarVersionedRuntimes jarVersionedRuntimes = jarData.getVersionedRuntimes();
- assertNotNull(jarVersionedRuntimes);
- Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap = jarVersionedRuntimes.getVersionedRuntimeMap();
- assertNotNull(jarVersionedRuntimeMap);
- assertEquals(1, jarVersionedRuntimeMap.size()); // 11
-
- JarVersionedRuntime jarVersionedRuntime11 = jarVersionedRuntimes.getJarVersionedRuntime(11);
- JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
- assertEquals("1.8", jarClasses11.getJdkRevision());
- } catch (Exception e) {
- fail("It should not raise an exception", e);
- }
+ void analyzeMultiReleaseJarWithVersion11HasALowerJdkRevisionClass() {
+ assertDoesNotThrow(
+ () -> {
+ // Version 11 has one class compiled to target Java 1.8
+ JarData jarData = getJarData("multi-release-version-with-lower-jdk-revision-class-0.0.1.jar");
+ JarClasses jclass = jarData.getJarClasses();
+
+ assertNull(jclass.getJdkRevision());
+
+ JarVersionedRuntimes jarVersionedRuntimes = jarData.getVersionedRuntimes();
+ assertNotNull(jarVersionedRuntimes);
+ Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap =
+ jarVersionedRuntimes.getVersionedRuntimeMap();
+ assertNotNull(jarVersionedRuntimeMap);
+ assertEquals(1, jarVersionedRuntimeMap.size()); // 11
+
+ JarVersionedRuntime jarVersionedRuntime11 = jarVersionedRuntimes.getJarVersionedRuntime(11);
+ JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
+ assertEquals("1.8", jarClasses11.getJdkRevision());
+ },
+ "It should not raise an exception");
}
/**
* Ensures no exceptions are raised when versioned content does not contain classes (just resources)
*/
@Test
- public void testAnalyzeMultiReleaseJarResourcesOnly() {
- try {
- JarData jarData = getJarData("multi-release-resources-only-0.0.1.jar");
- JarClasses jclass = jarData.getJarClasses();
-
- assertEquals("1.8", jclass.getJdkRevision());
-
- JarVersionedRuntimes jarVersionedRuntimes = jarData.getVersionedRuntimes();
- assertNotNull(jarVersionedRuntimes);
- Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap = jarVersionedRuntimes.getVersionedRuntimeMap();
- assertNotNull(jarVersionedRuntimeMap);
- assertEquals(2, jarVersionedRuntimeMap.size()); // 9 and 11
-
- JarVersionedRuntime jarVersionedRuntime9 = jarVersionedRuntimes.getJarVersionedRuntime(9);
- JarClasses jarClasses9 = jarVersionedRuntime9.getJarClasses();
- // no classes found
- assertNull(jarClasses9.getJdkRevision());
-
- JarVersionedRuntime jarVersionedRuntime11 = jarVersionedRuntimes.getJarVersionedRuntime(11);
- JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
- // no classes found
- assertNull(jarClasses11.getJdkRevision());
- } catch (Exception e) {
- fail("It should not raise an exception", e);
- }
+ void analyzeMultiReleaseJarResourcesOnly() {
+ assertDoesNotThrow(
+ () -> {
+ JarData jarData = getJarData("multi-release-resources-only-0.0.1.jar");
+ JarClasses jclass = jarData.getJarClasses();
+
+ assertEquals("1.8", jclass.getJdkRevision());
+
+ JarVersionedRuntimes jarVersionedRuntimes = jarData.getVersionedRuntimes();
+ assertNotNull(jarVersionedRuntimes);
+ Map<Integer, JarVersionedRuntime> jarVersionedRuntimeMap =
+ jarVersionedRuntimes.getVersionedRuntimeMap();
+ assertNotNull(jarVersionedRuntimeMap);
+ assertEquals(2, jarVersionedRuntimeMap.size()); // 9 and 11
+
+ JarVersionedRuntime jarVersionedRuntime9 = jarVersionedRuntimes.getJarVersionedRuntime(9);
+ JarClasses jarClasses9 = jarVersionedRuntime9.getJarClasses();
+ // no classes found
+ assertNull(jarClasses9.getJdkRevision());
+
+ JarVersionedRuntime jarVersionedRuntime11 = jarVersionedRuntimes.getJarVersionedRuntime(11);
+ JarClasses jarClasses11 = jarVersionedRuntime11.getJarClasses();
+ // no classes found
+ assertNull(jarClasses11.getJdkRevision());
+ },
+ "It should not raise an exception");
}
private void assertEntriesContains(List<JarEntry> list, final String entryToFind) {
=====================================
src/test/java/org/apache/maven/shared/jar/classes/JarVersionedRuntimesTest.java
=====================================
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.jar.classes;
+
+import java.util.Collections;
+import java.util.TreeMap;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Tests for {@link JarVersionedRuntimes}.
+ */
+class JarVersionedRuntimesTest {
+
+ @Test
+ void getJarClassesForExistingVersion() {
+ JarClasses jarClasses = new JarClasses();
+ jarClasses.setJdkRevision("11");
+ JarVersionedRuntime versionedRuntime = new JarVersionedRuntime(Collections.emptyList(), jarClasses);
+ JarVersionedRuntimes runtimes =
+ new JarVersionedRuntimes(new TreeMap<>(Collections.singletonMap(11, versionedRuntime)));
+
+ assertEquals(jarClasses, runtimes.getJarClasses(11));
+ }
+
+ /**
+ * Exposes issue #135: {@link JarVersionedRuntimes#getJarClasses(Integer)} must not throw
+ * a NullPointerException when the requested version is not present in the map.
+ */
+ @Test
+ void getJarClassesForMissingVersionReturnsNull() {
+ JarVersionedRuntime versionedRuntime = new JarVersionedRuntime(Collections.emptyList(), new JarClasses());
+ JarVersionedRuntimes runtimes =
+ new JarVersionedRuntimes(new TreeMap<>(Collections.singletonMap(11, versionedRuntime)));
+
+ assertNull(runtimes.getJarClasses(9));
+ }
+}
=====================================
src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
=====================================
@@ -49,7 +49,7 @@ class JarIdentificationAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testTaxonAnalyzerWithJXR() throws Exception {
+ void taxonAnalyzerWithJXR() throws Exception {
JarIdentification taxon = getJarTaxon("jxr.jar");
assertEquals("org.apache.maven", taxon.getGroupId(), "identification.groupId");
@@ -67,7 +67,7 @@ class JarIdentificationAnalyzerTest extends AbstractJarAnalyzerTestCase {
* @throws Exception failures
*/
@Test
- void testTaxonAnalyzerWithCODEC() throws Exception {
+ void taxonAnalyzerWithCODEC() throws Exception {
JarIdentification taxon = getJarTaxon("codec.jar");
assertEquals("org.apache.commons.codec", taxon.getGroupId(), "identification.groupId");
@@ -83,7 +83,7 @@ class JarIdentificationAnalyzerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testTaxonAnalyzerWithANT() throws Exception {
+ void taxonAnalyzerWithANT() throws Exception {
JarIdentification taxon = getJarTaxon("ant.jar");
assertEquals("org.apache.tools.ant", taxon.getGroupId(), "identification.groupId");
=====================================
src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
=====================================
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class EmbeddedMavenModelExposerTest extends AbstractJarAnalyzerTestCase {
@Test
- void testExposerWithParent() throws Exception {
+ void exposerWithParent() throws Exception {
File file = getSampleJar("test1.jar");
JarIdentification identification = new JarIdentification();
@@ -54,7 +54,7 @@ class EmbeddedMavenModelExposerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testExposerWithJXR() throws Exception {
+ void exposerWithJXR() throws Exception {
File file = getSampleJar("jxr.jar");
JarIdentification identification = new JarIdentification();
@@ -70,7 +70,7 @@ class EmbeddedMavenModelExposerTest extends AbstractJarAnalyzerTestCase {
}
@Test
- void testExposerWithANT() throws Exception {
+ void exposerWithANT() throws Exception {
File file = getSampleJar("ant.jar");
JarIdentification identification = new JarIdentification();
=====================================
src/test/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposerTest.java
=====================================
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.jar.identification.exposers;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.apache.maven.shared.jar.identification.JarIdentification;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test Case for Filename Taxon Data.
+ */
+class FilenameExposerTest {
+
+ private JarIdentification expose(String jarName) throws Exception {
+ Path dir = Files.createTempDirectory("filename-exposer");
+ File jarFile = new File(dir.toFile(), jarName);
+ jarFile.deleteOnExit();
+
+ try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile))) {
+ jos.putNextEntry(new JarEntry("README"));
+ jos.write(new byte[] {1});
+ jos.closeEntry();
+ }
+
+ JarAnalyzer analyzer = new JarAnalyzer(jarFile);
+ JarIdentification identification = new JarIdentification();
+ try {
+ new FilenameExposer().expose(identification, analyzer);
+ } finally {
+ analyzer.closeQuietly();
+ }
+ return identification;
+ }
+
+ @Test
+ void versionWithMultiDigitPrefixIsNotTruncated() throws Exception {
+ JarIdentification identification = expose("my-lib-12.3.4.jar");
+
+ assertEquals(1, identification.getPotentialArtifactIds().size());
+ assertEquals("my-lib", identification.getPotentialArtifactIds().get(0));
+ assertEquals(1, identification.getPotentialVersions().size());
+ assertEquals("12.3.4", identification.getPotentialVersions().get(0));
+ }
+
+ @Test
+ void versionWithMultiDigitPrefixNoMinorIsNotTruncated() throws Exception {
+ JarIdentification identification = expose("my-lib-10.jar");
+
+ assertEquals("my-lib", identification.getPotentialArtifactIds().get(0));
+ assertEquals("10", identification.getPotentialVersions().get(0));
+ }
+
+ @Test
+ void versionWithMultiDigitPrefixIsNotTruncatedWhenOtherSegmentsFollow() throws Exception {
+ JarIdentification identification = expose("my-lib-21.5.7.jar");
+
+ assertEquals("my-lib", identification.getPotentialArtifactIds().get(0));
+ assertEquals("21.5.7", identification.getPotentialVersions().get(0));
+ }
+
+ @Test
+ void singleDigitVersionIsPreserved() throws Exception {
+ JarIdentification identification = expose("my-lib-9.0.jar");
+
+ assertEquals("my-lib", identification.getPotentialArtifactIds().get(0));
+ assertEquals("9.0", identification.getPotentialVersions().get(0));
+ }
+
+ @Test
+ void filenameWithoutVersionHasNoVersion() throws Exception {
+ JarIdentification identification = expose("my-lib.jar");
+
+ assertEquals("my-lib", identification.getPotentialArtifactIds().get(0));
+ assertTrue(identification.getPotentialVersions().isEmpty());
+ }
+}
=====================================
src/test/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzerTest.java
=====================================
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.jar.identification.hash;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+/**
+ * Tests for the {@link JarBytecodeHashAnalyzer}.
+ */
+class JarBytecodeHashAnalyzerTest extends AbstractJarAnalyzerTestCase {
+
+ private final JarBytecodeHashAnalyzer analyzer = new JarBytecodeHashAnalyzer();
+
+ @Test
+ void computeHashCoversAllClassEntries() throws Exception {
+ JarAnalyzer jarAnalyzer = new JarAnalyzer(getSampleJar("codec.jar"));
+ try {
+ ByteArrayOutputStream allClasses = new ByteArrayOutputStream();
+ for (JarEntry entry : jarAnalyzer.getClassEntries()) {
+ try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
+ allClasses.write(readAll(is));
+ }
+ }
+ String expected = DigestUtils.sha1Hex(allClasses.toByteArray());
+
+ String actual = analyzer.computeHash(jarAnalyzer);
+
+ assertEquals(expected, actual, "bytecode hash must cover every class entry");
+ } finally {
+ jarAnalyzer.closeQuietly();
+ }
+ }
+
+ @Test
+ void distinctClassSetsProduceDistinctHashes() throws Exception {
+ JarAnalyzer jarA = new JarAnalyzer(createJar("org/foo/A.class", "org/zshared/Z.class"));
+ JarAnalyzer jarB = new JarAnalyzer(createJar("org/bar/B.class", "org/zshared/Z.class"));
+ try {
+ assertNotEquals(
+ analyzer.computeHash(jarA),
+ analyzer.computeHash(jarB),
+ "jars sharing only the last-sorted class entry must not produce the same bytecode hash");
+ } finally {
+ jarA.closeQuietly();
+ jarB.closeQuietly();
+ }
+ }
+
+ private File createJar(String... entryNames) throws IOException {
+ File file = File.createTempFile("bytecode-hash-test", ".jar");
+ file.deleteOnExit();
+ try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(file))) {
+ for (String entryName : entryNames) {
+ jos.putNextEntry(new JarEntry(entryName));
+ jos.write(entryName.getBytes(StandardCharsets.UTF_8));
+ jos.closeEntry();
+ }
+ }
+ return file;
+ }
+
+ private static byte[] readAll(InputStream is) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[8192];
+ int read;
+ while ((read = is.read(buffer)) != -1) {
+ out.write(buffer, 0, read);
+ }
+ return out.toByteArray();
+ }
+}
=====================================
src/test/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzerTest.java
=====================================
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.jar.identification.hash;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class JarFileHashAnalyzerTest extends AbstractJarAnalyzerTestCase {
+
+ private final JarFileHashAnalyzer analyzer = new JarFileHashAnalyzer();
+
+ @Test
+ void computeHashReturnsTheHashOnFirstCall() throws Exception {
+ JarAnalyzer jarAnalyzer = new JarAnalyzer(getSampleJar("codec.jar"));
+ try (InputStream in =
+ Files.newInputStream(jarAnalyzer.getJarData().getFile().toPath())) {
+ String expected = DigestUtils.sha1Hex(in);
+
+ String actual = analyzer.computeHash(jarAnalyzer);
+
+ assertNotNull(actual, "first call must return the hash it just computed, not null");
+ assertEquals(expected, actual, "file hash must be the SHA-1 of the jar file");
+ } finally {
+ jarAnalyzer.closeQuietly();
+ }
+ }
+
+ @Test
+ void computeHashIsStableAcrossCalls() throws Exception {
+ JarAnalyzer jarAnalyzer = new JarAnalyzer(getSampleJar("codec.jar"));
+ try {
+ String first = analyzer.computeHash(jarAnalyzer);
+ // Second call is served from the JarData cache rather than recomputed.
+ String second = analyzer.computeHash(jarAnalyzer);
+
+ assertEquals(first, second, "cached call must agree with the computed one");
+ } finally {
+ jarAnalyzer.closeQuietly();
+ }
+ }
+
+ @Test
+ void computeHashPopulatesJarData() throws Exception {
+ JarAnalyzer jarAnalyzer = new JarAnalyzer(getSampleJar("codec.jar"));
+ try {
+ String returned = analyzer.computeHash(jarAnalyzer);
+
+ assertEquals(
+ returned,
+ jarAnalyzer.getJarData().getFileHash(),
+ "returned hash and the value cached on JarData must agree");
+ } finally {
+ jarAnalyzer.closeQuietly();
+ }
+ }
+}
View it on GitLab: https://salsa.debian.org/java-team/maven-shared-jar/-/commit/9944395ca6782839ad7273d76021d10ddca94280
--
View it on GitLab: https://salsa.debian.org/java-team/maven-shared-jar/-/commit/9944395ca6782839ad7273d76021d10ddca94280
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261111/9d2b1004/attachment.htm>
More information about the pkg-java-commits
mailing list