[java-mvn-enforcer] 01/04: Separate "Pom Artifact" from "Parsed pom artifact"
Rod Widdowson
rdw at steadingsoftware.com
Tue Oct 11 08:34: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=6fb1fd8f5e34201207299fd59fbfbafcf218638a
commit 6fb1fd8f5e34201207299fd59fbfbafcf218638a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Oct 10 11:01:59 2022 +0100
Separate "Pom Artifact" from "Parsed pom artifact"
The "Pom Artifact" as container for group,artitfact,version,classifier
has diverged from "Dependency pom artifact" which is all the above plus
exclusions and is created (mostly) from a DOM element.
---
.../mvn/enforcer/impl/BaseSigChecker.java | 8 +-
.../mvn/enforcer/impl/DependencyChecker.java | 22 +--
.../shibboleth/mvn/enforcer/impl/JarEnforcer.java | 4 +-
.../shibboleth/mvn/enforcer/impl/M2SigChecker.java | 10 +-
.../shibboleth/mvn/enforcer/impl/MavenLoader.java | 4 +-
.../shibboleth/mvn/enforcer/impl/ParsedPom.java | 182 ++++++---------------
.../shibboleth/mvn/enforcer/impl/PomArtifact.java | 129 +++++++++++++++
.../mvn/enforcer/impl/ProjectPomContext.java | 10 +-
.../shibboleth/mvn/enforcer/impl/SigChecker.java | 6 +-
9 files changed, 212 insertions(+), 163 deletions(-)
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java
index 0d47d10..b8ef8db 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java
@@ -35,7 +35,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import net.shibboleth.mvn.enforcer.impl.GPGKeyRing.Signature;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
import net.shibboleth.utilities.java.support.logic.Constraint;
/**
@@ -91,10 +91,10 @@ public class BaseSigChecker {
/** Given the Path and the parent dir check the signature.
* @param jarFile the file to check
- * @param artifact the {@link PomArtifact} for the jar file.
+ * @param artifact the {@link DependencyPomArtifact} for the jar file.
* @return true if the signature passed (or some other "usual conditions)
*/
- protected boolean checkSignature(final InputStream jarFile, final PomArtifact artifact) {
+ protected boolean checkSignature(final InputStream jarFile, final DependencyPomArtifact artifact) {
final String group = artifact.getGroupId();
final String id = artifact.getArtifactId();
final String version;
@@ -154,7 +154,7 @@ public class BaseSigChecker {
* @param artifact what to load
* @return the Signature or null if we couldn't locate it.
*/
- private Signature getSignature(final PomArtifact artifact) {
+ private Signature getSignature(final DependencyPomArtifact artifact) {
Path path;
try {
path = getMavenLoader().downloadArtifact(artifact, "jar.asc");
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
index e84d9f1..b19c754 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
@@ -48,7 +48,7 @@ import org.apache.maven.shared.invoker.MavenInvocationException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
import net.shibboleth.utilities.java.support.collection.Pair;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -194,16 +194,16 @@ public class DependencyChecker {
*/
private void checkPomArtifacts(final boolean doAnalysis) {
final ParsedPom parentPom = projectContext.getParentPom();
- final List<PomArtifact> dependencies = new ArrayList<>(
+ final List<DependencyPomArtifact> dependencies = new ArrayList<>(
parentPom.getCompileDependencies().size() +
parentPom.getRuntimeDependencies().size());
dependencies.addAll(parentPom.getCompileDependencies());
dependencies.addAll(parentPom.getRuntimeDependencies());
Collections.sort(dependencies);
- PomArtifact last = null;
+ DependencyPomArtifact last = null;
- for (final PomArtifact artifact : dependencies) {
+ for (final DependencyPomArtifact artifact : dependencies) {
final String id = artifact.getArtifactId();
final String ver = artifact.getVersion();
final String sourcePomFilename = "(from " + artifact.getSourcePomFilename() + ")";
@@ -229,7 +229,7 @@ public class DependencyChecker {
if (doAnalysis) {
analyzeChild(artifact.withVersion(version));
}
- if (!ver.equals(PomArtifact.BAD_VERSION)) {
+ if (!ver.equals(DependencyPomArtifact.BAD_VERSION)) {
versionMismatch++;
}
}
@@ -282,9 +282,9 @@ public class DependencyChecker {
int dupEntries = 0;
if (!parentPom.getDuplicates().isEmpty()) {
report.format("Duplicates (different versions) found parsing the poms\n");
- for (final Pair<PomArtifact,PomArtifact> poms : parentPom.getDuplicates()) {
- final PomArtifact f = poms.getFirst();
- final PomArtifact s = poms.getSecond();
+ for (final Pair<DependencyPomArtifact,DependencyPomArtifact> poms : parentPom.getDuplicates()) {
+ final DependencyPomArtifact f = poms.getFirst();
+ final DependencyPomArtifact s = poms.getSecond();
report.format("%-30s: %10s (from %s) and %s (from %s)\n", f.getMapKey(),
f.getVersion(), f.getSourcePomFilename(),
@@ -365,7 +365,7 @@ public class DependencyChecker {
* yields a map. Looking this up with a version yields a set of the sources.
* @param artifact what to start with.
*/
- private void analyzeChild(final PomArtifact artifact) {
+ private void analyzeChild(final DependencyPomArtifact artifact) {
final File pomFile;
try {
pomFile = outputPom(artifact);
@@ -407,7 +407,7 @@ public class DependencyChecker {
*/
private void addDep(final Map<String, Map<String, Set<String>>> dependencySources,
final String dep,
- final PomArtifact artifact) {
+ final DependencyPomArtifact artifact) {
final Pair<String,String> depId = projectContext.splitFileName(dep);
if (artifact.getArtifactId().equals(depId.getFirst()) && artifact.getVersion().equals(depId.getSecond())) {
@@ -434,7 +434,7 @@ public class DependencyChecker {
* @return the file.
* @throws FileNotFoundException if the created pom file doesnt exist?
*/
- private File outputPom(final PomArtifact artifact) throws FileNotFoundException {
+ private File outputPom(final DependencyPomArtifact artifact) throws FileNotFoundException {
final ParsedPom parentPom = projectContext.getParentPom();
final File file = projectContext.getWorkingDir().resolve(new StringBuilder(artifact.getArtifactId())
.append("-")
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
index 98ca12f..d0b2ab7 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -51,7 +51,7 @@ import org.apache.maven.repository.RepositorySystem;
import org.slf4j.Logger;
import net.shibboleth.mvn.enforcer.impl.GPGKeyRing.Signature;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.XMLConstants;
@@ -449,7 +449,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
}
/** {@inheritDoc} */
- public Path downloadArtifact(final PomArtifact artifact, final String type) throws Exception {
+ public Path downloadArtifact(final DependencyPomArtifact artifact, final String type) throws Exception {
final File file = downloadArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), type);
if (file == null) {
return null;
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 e7e70ce..c413865 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
@@ -31,7 +31,7 @@ import javax.annotation.Nonnull;
import org.slf4j.Logger;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
/**
* A class to traverse over the provided ~/.m2 directory looking for jar files
@@ -89,7 +89,7 @@ public class M2SigChecker extends BaseSigChecker {
fileName.endsWith("-javadoc.jar") ) {
return result;
}
- final PomArtifact info = artifactFromPath(relativePath);
+ final DependencyPomArtifact info = artifactFromPath(relativePath);
if (info == null || info.getVersion() == null) {
log.error("Badly located jar file {}", file);
return result;
@@ -113,9 +113,9 @@ public class M2SigChecker extends BaseSigChecker {
/** Given a path "org/example/extra/artifactID/version" return the artifact coordinates.
* @param path the path to an artifact.
- * @return a suitable {@link PomArtifact}
+ * @return a suitable {@link DependencyPomArtifact}
*/
- private PomArtifact artifactFromPath(Path path) {
+ private DependencyPomArtifact artifactFromPath(Path path) {
final Path versionDir = path.getParent();
if (versionDir == null) {
return null;
@@ -159,7 +159,7 @@ public class M2SigChecker extends BaseSigChecker {
if (buf.length() > 0) {
buf.deleteCharAt(buf.length()-1);
}
- return getProjectContext().getParentPom().new PomArtifact(buf.toString(), artifactId, version, classifier);
+ return getProjectContext().getParentPom().new DependencyPomArtifact(buf.toString(), artifactId, version, classifier);
}
}
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/MavenLoader.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/MavenLoader.java
index 43db2f8..fca97fa 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/MavenLoader.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/MavenLoader.java
@@ -19,7 +19,7 @@ package net.shibboleth.mvn.enforcer.impl;
import java.nio.file.Path;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
/**
* Abstraction of a way to get hold of a maven artifact.
@@ -32,5 +32,5 @@ public interface MavenLoader {
* @return the address of the artifact
* @throws Exception on an error
*/
- Path downloadArtifact(PomArtifact artifact, String type) throws Exception;
+ Path downloadArtifact(DependencyPomArtifact artifact, String type) throws Exception;
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java
index c640150..c3125f6 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java
@@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Properties;
import java.util.Set;
@@ -52,22 +51,22 @@ import net.shibboleth.utilities.java.support.xml.XMLParserException;
public class ParsedPom {
/** Compile dependencies - what we care about. */
- private final Map<String, PomArtifact> compileDependencies = new HashMap<>();
+ private final Map<String, DependencyPomArtifact> compileDependencies = new HashMap<>();
/** BOM dependencies. */
- private final Map<String, PomArtifact> bomDependencies = new HashMap<>();
+ private final Map<String, DependencyPomArtifact> bomDependencies = new HashMap<>();
/** Rum time dependencies. */
- private final Map<String, PomArtifact> runtimeDependencies = new HashMap<>();
+ private final Map<String, DependencyPomArtifact> runtimeDependencies = new HashMap<>();
/** Duplicate dependencies. */
- private final List<Pair<PomArtifact,PomArtifact>> duplicates = new ArrayList<>();
+ private final List<Pair<DependencyPomArtifact,DependencyPomArtifact>> duplicates = new ArrayList<>();
/** Generated artifacts. */
- private final Set<PomArtifact> generated = new HashSet<>();
+ private final Set<DependencyPomArtifact> generated = new HashSet<>();
/** Inherits dependencies. */
- private final Map<String, PomArtifact> managedDependencies;
+ private final Map<String, DependencyPomArtifact> managedDependencies;
/** Which the POM.*/
@Nonnull private final String sourcePomInfo;
@@ -76,10 +75,10 @@ public class ParsedPom {
private final Properties properties = new Properties();
/** Parent Pom .*/
- private PomArtifact parent;
+ private DependencyPomArtifact parent;
/** Us. */
- private final PomArtifact us;
+ private final DependencyPomArtifact us;
/**
* Constructor.
@@ -98,7 +97,7 @@ public class ParsedPom {
@Nonnull final Path pom,
@Nonnull final String pomName,
@Nullable final Properties parentPomProperties,
- @Nonnull final Map<String, PomArtifact> map)
+ @Nonnull final Map<String, DependencyPomArtifact> map)
throws Exception {
managedDependencies = new HashMap<>(map);
@@ -119,7 +118,7 @@ public class ParsedPom {
parseParent(par.get(0));
}
- us = new PomArtifact(el, parent);
+ us = new DependencyPomArtifact(el, parent);
if (parentPomProperties == null) {
return;
@@ -154,9 +153,9 @@ public class ParsedPom {
parseManagedDependencies(dependencies);
}
}
- for (final PomArtifact bom : bomDependencies.values()) {
+ for (final DependencyPomArtifact bom : bomDependencies.values()) {
final ParsedPom parsedBom = new ParsedPom(parsers, pomLoader, pomLoader.downloadArtifact(bom, "pom"), bom.toString(), new Properties(), Collections.emptyMap());
- for (PomArtifact dep : parsedBom.getManagedDependencies().values()) {
+ for (DependencyPomArtifact dep : parsedBom.getManagedDependencies().values()) {
addWithCheck(dep, managedDependencies);
}
}
@@ -165,8 +164,8 @@ public class ParsedPom {
parseDependencies(dependencies);
}
- final Set<PomArtifact> moduleCompiles = new HashSet<>();
- final Set<PomArtifact> moduleRuntimes = new HashSet<>();
+ final Set<DependencyPomArtifact> moduleCompiles = new HashSet<>();
+ final Set<DependencyPomArtifact> moduleRuntimes = new HashSet<>();
for (final Element modules: ElementSupport.getChildElementsByTagName(el, "modules")) {
for (final Element module: ElementSupport.getChildElementsByTagName(modules, "module")) {
final Path modulePath = pom.getParent().resolve(module.getTextContent()).resolve("pom.xml");
@@ -178,10 +177,10 @@ public class ParsedPom {
}
}
}
- for (final PomArtifact dep : moduleCompiles) {
+ for (final DependencyPomArtifact dep : moduleCompiles) {
addWithCheck(dep, compileDependencies);
}
- for (final PomArtifact dep : moduleRuntimes) {
+ for (final DependencyPomArtifact dep : moduleRuntimes) {
addWithCheck(dep, runtimeDependencies);
}
}
@@ -216,7 +215,7 @@ public class ParsedPom {
final List<Element> dependencies = ElementSupport.getChildElementsByTagName(item, "dependency");
for (Element dependency : dependencies) {
- final PomArtifact artifact = new PomArtifact(dependency);
+ final DependencyPomArtifact artifact = new DependencyPomArtifact(dependency);
final List<Element> types = ElementSupport.getChildElementsByTagName(dependency, "type");
if (!types.isEmpty()) {
final String type = StringSupport.trimOrNull(types.get(0).getTextContent());
@@ -251,7 +250,7 @@ public class ParsedPom {
private void parseManagedDependencies(final Element item) {
final List<Element> dependencies = ElementSupport.getChildElementsByTagName(item, "dependency");
for (Element dependency : dependencies) {
- final PomArtifact artifact = new PomArtifact(dependency);
+ final DependencyPomArtifact artifact = new DependencyPomArtifact(dependency);
final List<Element> types = ElementSupport.getChildElementsByTagName(dependency, "type");
if (!types.isEmpty()) {
final String type = StringSupport.trimOrNull(types.get(0).getTextContent());
@@ -271,8 +270,8 @@ public class ParsedPom {
* @param artifact what to add
* @param map wghere to add it
*/
- private void addWithCheck(final PomArtifact artifact, final Map<String, PomArtifact> map) {
- final PomArtifact old = map.put(artifact.getMapKey(),artifact);
+ private void addWithCheck(final DependencyPomArtifact artifact, final Map<String, DependencyPomArtifact> map) {
+ final DependencyPomArtifact old = map.put(artifact.getMapKey(),artifact);
if (old != null && !old.equals(artifact)) {
duplicates.add(new Pair<>(old, artifact));
}
@@ -295,55 +294,55 @@ public class ParsedPom {
* @param item the <parent> element
*/
private void parseParent(Element item) {
- parent = new PomArtifact(item);
+ parent = new DependencyPomArtifact(item);
}
/** Returns the Compile Dependencies.
* @return Returns the Compile Dependencies.
*/
- @Nonnull public Collection<PomArtifact> getCompileDependencies() {
+ @Nonnull public Collection<DependencyPomArtifact> getCompileDependencies() {
return compileDependencies.values();
}
/** Returns the Runtime Dependencies.
* @return Returns the Runtime Dependencies.
*/
- @Nonnull public Collection<PomArtifact> getRuntimeDependencies() {
+ @Nonnull public Collection<DependencyPomArtifact> getRuntimeDependencies() {
return runtimeDependencies.values();
}
/** Returns the Managed Dependencies.
* @return Returns the Managed Dependencies.
*/
- @Nonnull public Map<String, PomArtifact> getManagedDependencies() {
+ @Nonnull public Map<String, DependencyPomArtifact> getManagedDependencies() {
return managedDependencies;
}
/** Get artifacts that were duplicated by this build
* @return Returns the duplicates.
*/
- @Nonnull public List<Pair<PomArtifact, PomArtifact>> getDuplicates() {
+ @Nonnull public List<Pair<DependencyPomArtifact, DependencyPomArtifact>> getDuplicates() {
return duplicates;
}
/** returns any sub modules created by this module.
* @return Returns the generated.
*/
- @Nonnull public Set<PomArtifact> getGeneratedArtifacts() {
+ @Nonnull public Set<DependencyPomArtifact> getGeneratedArtifacts() {
return generated;
}
/** Return our artifactInformation.
* @return us.
*/
- public PomArtifact getOurInfo() {
+ public DependencyPomArtifact getOurInfo() {
return us;
}
/** Return the parent.
* @return the parent.
*/
- public PomArtifact getParent() {
+ public DependencyPomArtifact getParent() {
return parent;
}
@@ -355,61 +354,20 @@ public class ParsedPom {
}
/** Encapsulation of a <dependency> element. */
- public class PomArtifact implements Comparable<PomArtifact>{
+ public class DependencyPomArtifact extends PomArtifact {
/** What version to give if we cannot find the version. */
public final static String BAD_VERSION = "VERSION_NOT_DETERMINED";
- /** <groupId>.*/
- @Nonnull private final String groupId;
-
- /** <artifactId>.*/
- @Nonnull private final String artifactId;
-
- /** <version>.*/
- @Nonnull private final String version;
-
- /** <classifier>.*/
- @Nonnull private final String classifier;
-
/** <exclusions>. */
@Nonnull private final Set<Pair<String, String>> exclusions = new HashSet<>();
- /**
- * Constructor.
- *
- * @param id the <artifactId>
- * @param group the <groupId>
- * @param ver the <version>
- */
- public PomArtifact(final String group, final String id, final String ver) {
- artifactId = id;
- groupId = group;
- version = ver;
- classifier = "";
- }
-
- /**
- * Constructor.
- *
- * @param id the <artifactId>
- * @param group the <groupId>
- * @param ver the <version>
- * @param clssfr the <classifier>
- */
- public PomArtifact(final String group, final String id, final String ver, final String clssfr) {
- artifactId = id;
- groupId = group;
- version = ver;
- classifier = clssfr;
- }
-
/**
* Constructor.
*
* @param item element to interrogate.
*/
- public PomArtifact(final Element item) {
+ public DependencyPomArtifact(final Element item) {
this(item, null);
}
@@ -419,8 +377,8 @@ public class ParsedPom {
* @param item element to interrogate.
* @param parentArtifact to inherit from
*/
- public PomArtifact(final Element item, final @Nullable PomArtifact parentArtifact) {
-
+ public DependencyPomArtifact(final Element item, final @Nullable DependencyPomArtifact parentArtifact) {
+ super(null, null, null);
final List<Element> grps = ElementSupport.getChildElementsByTagName(item, "groupId");
if (grps.size() > 0) {
groupId = getElementContent(grps.get(0));
@@ -441,7 +399,7 @@ public class ParsedPom {
} else if (parentArtifact != null) {
version = parentArtifact.getVersion();
} else {
- final PomArtifact inherited = managedDependencies.get(groupId+"+"+artifactId);
+ final DependencyPomArtifact inherited = managedDependencies.get(groupId+"+"+artifactId);
if (inherited != null) {
version = inherited.getVersion();
} else {
@@ -473,31 +431,26 @@ public class ParsedPom {
}
/**
- * @return Returns the groupId.
- */
- public String getGroupId() {
- return groupId;
- }
-
- /**
- * @return Returns the artifactId.
- */
- public String getArtifactId() {
- return artifactId;
- }
-
- /**
- * @return Returns the version.
+ * Constructor.
+ *
+ * @param group the <groupId>
+ * @param id the <artifactId>
+ * @param ver the <version>
+ * @param clssfr the <classifier>
*/
- public String getVersion() {
- return version;
+ public DependencyPomArtifact(final String group, final String id, final String ver, final String clssfr) {
+ super(group, id, ver, clssfr);
}
/**
- * @return Returns the classifier.
+ * Constructor.
+ *
+ * @param id the <artifactId>
+ * @param group the <groupId>
+ * @param ver the <version>
*/
- public String getClassifier() {
- return classifier;
+ public DependencyPomArtifact(final String group, final String id, final String ver) {
+ this(group, id, ver, "");
}
/**
@@ -507,53 +460,20 @@ public class ParsedPom {
return sourcePomInfo;
}
- /** Get the key we use in out maps.
- * @return the key - derives from groupId and EntityId
- */
- public String getMapKey() {
- return getGroupId()+"+"+getArtifactId();
- }
-
/**
* @return Returns the exclusions.
*/
public Set<Pair<String, String>> getExclusions() {
return exclusions;
}
-
- /** {@inheritDoc} */
- public int compareTo(final PomArtifact o) {
- return getArtifactId().compareTo(o.getArtifactId());
- }
-
- /** {@inheritDoc} */
- public boolean equals(final Object obj) {
- if (obj != null && obj instanceof PomArtifact ) {
- final PomArtifact him = (PomArtifact) obj;
- return him.getArtifactId().equals(getArtifactId()) &&
- him.getGroupId().equals(getGroupId()) &&
- him.getVersion().equals(getVersion()) &&
- him.getClassifier().equals(getClassifier());
- }
- return false;
- }
-
- /** {@inheritDoc} */
- public int hashCode() {
- return Objects.hash(artifactId, groupId, version, classifier);
- }
- /** {@inheritDoc} */
- public String toString() {
- return artifactId + "-" + classifier + version;
- }
-
/** return the same artifact but with an amended version.
* @param ver the version
* @return an amended artifact.
*/
- public PomArtifact withVersion(String ver) {
- return new PomArtifact(groupId, artifactId, ver, classifier);
+ public final DependencyPomArtifact withVersion(String ver) {
+ return new DependencyPomArtifact(groupId, artifactId, ver, classifier);
}
+
}
}
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/PomArtifact.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/PomArtifact.java
new file mode 100644
index 0000000..498fa71
--- /dev/null
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/PomArtifact.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID 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 net.shibboleth.mvn.enforcer.impl;
+
+import java.util.Objects;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Encapsulation of an artifact in a pom file.
+ */
+public class PomArtifact implements Comparable<PomArtifact> {
+ /** <groupId>.*/
+ @Nonnull protected String groupId;
+
+ /** <artifactId>.*/
+ @Nonnull protected String artifactId;
+
+ /** <version>.*/
+ @Nonnull protected String version;
+
+ /** <classifier>.*/
+ @Nonnull protected String classifier;
+
+ /**
+ * Constructor.
+ *
+ * @param id the <artifactId>
+ * @param group the <groupId>
+ * @param ver the <version>
+ */
+ public PomArtifact(final String group, final String id, final String ver) {
+ this(group, id, ver, "");
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param id the <artifactId>
+ * @param group the <groupId>
+ * @param ver the <version>
+ * @param clssfr the <classifier>
+ */
+ public PomArtifact(final String group, final String id, final String ver, final String clssfr) {
+ artifactId = id;
+ groupId = group;
+ version = ver;
+ classifier = clssfr;
+ }
+
+
+ /**
+ * @return Returns the groupId.
+ */
+ public final String getGroupId() {
+ return groupId;
+ }
+
+ /**
+ * @return Returns the artifactId.
+ */
+ public final String getArtifactId() {
+ return artifactId;
+ }
+
+ /**
+ * @return Returns the version.
+ */
+ public final String getVersion() {
+ return version;
+ }
+
+ /**
+ * @return Returns the classifier.
+ */
+ public final String getClassifier() {
+ return classifier;
+ }
+
+ /** Get the key we use in out maps.
+ * @return the key - derives from groupId and EntityId
+ */
+ public final String getMapKey() {
+ return getGroupId()+"+"+getArtifactId();
+ }
+
+ /** {@inheritDoc} */
+ public final int compareTo(final PomArtifact o) {
+ return getArtifactId().compareTo(o.getArtifactId());
+ }
+
+ /** {@inheritDoc} */
+ public final boolean equals(final Object obj) {
+ if (obj != null && obj instanceof PomArtifact ) {
+ final PomArtifact him = (PomArtifact) obj;
+ return him.getArtifactId().equals(getArtifactId()) &&
+ him.getGroupId().equals(getGroupId()) &&
+ him.getVersion().equals(getVersion()) &&
+ him.getClassifier().equals(getClassifier());
+ }
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public final int hashCode() {
+ return Objects.hash(artifactId, groupId, version, classifier);
+ }
+
+ /** {@inheritDoc} */
+ public final String toString() {
+ return artifactId + "-" + classifier + version;
+ }
+
+}
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
index d6c07f0..c5b002e 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
@@ -36,7 +36,7 @@ import javax.annotation.Nonnull;
import org.slf4j.Logger;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
import net.shibboleth.utilities.java.support.collection.Pair;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.xml.ParserPool;
@@ -224,10 +224,10 @@ public final class ProjectPomContext implements AutoCloseable {
*/
// Checkstyle: CyclomaticComplexity OFF
private boolean setupGroupMapping() {
- for (final PomArtifact dep : parentPom.getCompileDependencies()) {
+ for (final DependencyPomArtifact dep : parentPom.getCompileDependencies()) {
artifactToGroup.put(dep.getArtifactId(), dep.getGroupId());
}
- for (final PomArtifact dep : parentPom.getRuntimeDependencies()) {
+ for (final DependencyPomArtifact dep : parentPom.getRuntimeDependencies()) {
final String comp = artifactToGroup.get(dep.getArtifactId());
if (comp != null) {
if (!comp.equals(dep.getGroupId())) {
@@ -239,12 +239,12 @@ public final class ProjectPomContext implements AutoCloseable {
artifactToGroup.put(dep.getArtifactId(), dep.getGroupId());
}
}
- for (final PomArtifact artifact : parentPom.getManagedDependencies().values()) {
+ for (final DependencyPomArtifact artifact : parentPom.getManagedDependencies().values()) {
if (!artifactToGroup.containsKey(artifact.getArtifactId())) {
artifactToGroup.put(artifact.getArtifactId(), artifact.getGroupId());
}
}
- for (final PomArtifact artifact : parentPom.getGeneratedArtifacts()) {
+ for (final DependencyPomArtifact artifact : parentPom.getGeneratedArtifacts()) {
if (!artifactToGroup.containsKey(artifact.getArtifactId())) {
artifactToGroup.put(artifact.getArtifactId(), artifact.getGroupId());
}
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java
index 2d0ae2a..1315665 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java
@@ -28,7 +28,7 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.slf4j.Logger;
-import net.shibboleth.mvn.enforcer.impl.ParsedPom.PomArtifact;
+import net.shibboleth.mvn.enforcer.impl.ParsedPom.DependencyPomArtifact;
import net.shibboleth.utilities.java.support.collection.Pair;
/**
@@ -85,8 +85,8 @@ public class SigChecker extends BaseSigChecker {
final String jarName = Path.of(jarPath).getFileName().toString();
final Pair<String,String> name = getProjectContext().splitFileName(jarName);
final String group = getProjectContext().getGroup(name.getFirst());
- final PomArtifact jarAsArtifact =
- getProjectContext().getParentPom().new PomArtifact(group, name.getFirst(), name.getSecond());
+ final DependencyPomArtifact jarAsArtifact =
+ getProjectContext().getParentPom().new DependencyPomArtifact(group, name.getFirst(), name.getSecond());
if (checkSignature(input, jarAsArtifact)) {
return 0;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list