[java-mvn-enforcer] branch main updated: JMVN-19 Derive the artifact coordinates from the path, not the pom
Rod Widdowson
rdw at steadingsoftware.com
Sun Jan 16 14:50:10 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-mvn-enforcer.
View the commit online:
http://git.shibboleth.net/view/?p=java-mvn-enforcer.git;a=commit;h=0d325d4464161b9994f89309e64ed26db138d4a3
The following commit(s) were added to refs/heads/main by this push:
new 0d325d4 JMVN-19 Derive the artifact coordinates from the path, not the pom
0d325d4 is described below
commit 0d325d4464161b9994f89309e64ed26db138d4a3
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Jan 16 14:31:25 2022 +0000
JMVN-19 Derive the artifact coordinates from the path, not the pom
https://shibboleth.atlassian.net/browse/JMVN-19
---
.../shibboleth/mvn/enforcer/impl/M2SigChecker.java | 80 ++++++++++++++--------
1 file changed, 52 insertions(+), 28 deletions(-)
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
index de5a625..a652d2a 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
@@ -26,7 +26,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Collections;
import javax.annotation.Nonnull;
@@ -59,7 +58,7 @@ public class M2SigChecker extends BaseSigChecker {
*/
public boolean testSignatures(final Path root) {
try {
- Files.walkFileTree(root, new M2Visitor());
+ Files.walkFileTree(root, new M2Visitor(root));
} catch (final IOException e) {
log.error("Failed traversal", e);
return false;
@@ -69,10 +68,20 @@ public class M2SigChecker extends BaseSigChecker {
private class M2Visitor extends SimpleFileVisitor<Path> {
+ private final Path root;
+
+ /** Constructor.
+ * @param path where the serach starts
+ */
+ public M2Visitor(Path path) {
+ root = path;
+ }
+
/** {@inheritDoc} */
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
final FileVisitResult result = super.visitFile(file, attrs);
+ final Path relativePath = root.relativize(file);
final String fileName = file.getFileName().toString();
if (!fileName.endsWith(".jar") ||
fileName.endsWith("-tests.jar") ||
@@ -80,37 +89,52 @@ public class M2SigChecker extends BaseSigChecker {
fileName.endsWith("-javadoc.jar") ) {
return result;
}
- String rootName = fileName.substring(0, fileName.length() - ".jar".length());
- Path pomPath = file.getParent().resolve(rootName + ".pom");
- // hack for sisu-guice
- String versionExtra = "";
- if (!Files.exists(pomPath)) {
- if (rootName.endsWith("-no_aop")) {
- rootName = rootName.substring(0, rootName.length() - "-no_aop".length());
- versionExtra = "-no_aop";
- } else if (rootName.endsWith("-noaop")) {
- rootName = rootName.substring(0, rootName.length() - "-noaop".length());
- versionExtra = "-noaop";
- }
- pomPath = file.getParent().resolve(rootName + ".pom");
- }
- final ParsedPom pom ;
- try {
- pom = new ParsedPom(getProjectContext().getParserPool(), getMavenLoader(), pomPath, "rootName", null, Collections.emptyMap());
- } catch (final Exception e) {
- log.error("Could not parse pom for " + pomPath.toString(), e);
+ final PomArtifact info = artifactFromPath(relativePath);
+ if (!checkSignature(new BufferedInputStream(new FileInputStream(file.toFile())), info)) {
failCount ++;
- return result;
}
- PomArtifact info = pom.getOurInfo();
- if (!"".equals(versionExtra)) {
- info = pom.new PomArtifact(info.getGroupId(), info.getArtifactId(), info.getVersion() + versionExtra);
+ return result;
+ }
+
+ /** Given a path "org/example/extra/artiffactID/version" return the artifact coordinates.
+ * @param path
+ * @return a pomn artifact
+ */
+ private PomArtifact artifactFromPath(Path path) {
+ final Path versionDir = path.getParent();
+ final Path artifactDir = versionDir.getParent();
+ final String artifactId = artifactDir.getFileName().toString();
+ final Path groupDir = artifactDir.getParent();
+ final String version = versionDir.getFileName().toString();
+ final String fileName = path.getFileName().toString();
+ final String garnish;
+ if (version.endsWith("SNAPSHOT")) {
+ // The version garnish isn't real version garnish:
+ // org/opensaml/opensaml-core/4.2.0-SNAPSHOT/opensaml-core-4.2.0-20220109.011317-203
+ //
+ garnish = "";
+ } else if (fileName.length() > artifactId.length() + 1 + version.length() + 4) {
+ // Need to be able to handle garnished versions:
+ // org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noapp.jar
+ garnish = fileName.substring(
+ artifactId.length() // "sisu-guice"
+ + 1 // // "-"
+ + version.length(), // "2.1.7"
+ fileName.length() - 4); // ".jar"
+ } else {
+ // usual version:
+ // org/hsqldb/hrsqldb/2.5.1/hsqldb-2.5.1.jar
+ garnish = "";
}
- if (!checkSignature(new BufferedInputStream(new FileInputStream(file.toFile())), info)) {
- failCount ++;
+ final StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < (groupDir.getNameCount()); i++) {
+ buf.append(groupDir.getName(i).toString()).append('.');
}
- return result;
+ if (buf.length() > 0) {
+ buf.deleteCharAt(buf.length()-1);
+ }
+ return getProjectContext().getParentPom().new PomArtifact(buf.toString(), artifactId, version + garnish);
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list