[java-mvn-enforcer] 02/03: CheckStyle: low hanging fruit
Codeberg
noreply at shibboleth.net
Tue Sep 29 16:24:31 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-mvn-enforcer.
View the commit online:
https://codeberg.org/Shibboleth/java-mvn-enforcer/commit/4cbe23c1a6674ac0517514cc3ae4d9def740e268
commit 4cbe23c1a6674ac0517514cc3ae4d9def740e268
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Sep 29 15:27:17 2026 +0100
CheckStyle: low hanging fruit
---
.../mvn/enforcer/impl/BaseSigChecker.java | 8 +-
.../mvn/enforcer/impl/DependencyChecker.java | 13 +--
.../shibboleth/mvn/enforcer/impl/GPGKeyRing.java | 7 +-
.../shibboleth/mvn/enforcer/impl/JarEnforcer.java | 93 +++++++++++++++-------
.../shibboleth/mvn/enforcer/impl/M2SigChecker.java | 21 +++--
.../shibboleth/mvn/enforcer/impl/ParsedPom.java | 54 +++++++------
.../shibboleth/mvn/enforcer/impl/PomArtifact.java | 16 ++--
.../mvn/enforcer/impl/ProjectPomContext.java | 21 +++--
.../shibboleth/mvn/enforcer/impl/SigChecker.java | 5 +-
9 files changed, 153 insertions(+), 85 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 33c26b6..731c40e 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/BaseSigChecker.java
@@ -93,7 +93,9 @@ public class BaseSigChecker {
* @param type jar or zip
* @return true if the signature passed (or some other "usual conditions)
*/
- protected boolean checkSignature(final InputStream jarFile, final PomArtifact artifact, @Nonnull final String type) {
+ protected boolean checkSignature(final InputStream jarFile,
+ final PomArtifact artifact,
+ @Nonnull final String type) {
final String group = artifact.getGroupId();
final String id = artifact.getArtifactId();
final String version;
@@ -156,7 +158,9 @@ public class BaseSigChecker {
*/
@Nullable private Signature getSignatureLocal(final PomArtifact artifact, @Nonnull final String type) {
log.debug("Trying classpath store for {}.", artifact);
- final String name = ProjectPomContext.CLASSPATH_ROOT + "localSignatures/" + artifact.toString() + "." + type + ".asc";
+ final String name = ProjectPomContext.CLASSPATH_ROOT +
+ "localSignatures/" + artifact.toString() +
+ "." + type + ".asc";
try (final InputStream stream = getProjectContext().getEnforcerLoader().getResourceAsStream(name)) {
if (stream == null) {
log.debug("Signature for {} not found in classpath store", artifact);
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 9f2c02c..6f0feca 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
@@ -108,8 +108,8 @@ public class DependencyChecker {
* @param isDistVersionMismatchFatal fail if artifact version doesn't match jar
* @param isPomVersionMismatchFatal fail if artifact appears in both places.
* @param isMultipleJarVersionsFatal fail if artifact appears with multiple versions in the poms.
-
*/
+ // CheckStyle: ParameterNumber OFF
public DependencyChecker( @Nonnull final ProjectPomContext project, @Nonnull final PrintWriter writer,
final boolean isCompileRuntimeArtifactFatal, final boolean isDistVersionMismatchFatal,
final boolean isPomVersionMismatchFatal, final boolean isMultipleJarVersionsFatal) {
@@ -124,13 +124,14 @@ public class DependencyChecker {
pomVersionMismatchFatal = isPomVersionMismatchFatal;
multipleJarVersionsFatal = isMultipleJarVersionsFatal;
}
+ // CheckStyle: ParameterNumber ON
/** The Body of the Dependency test. Are all the files what we expected? Who produced what?
* @param archive what to look at
* @param doAnalysis do we want to do the "and where did everything come from" analysis.
* @return true if OK, false otherwise
*/
- public boolean checkDependencies(final ArchiveInputStream archive, final boolean doAnalysis) {
+ public boolean checkDependencies(final ArchiveInputStream<?> archive, final boolean doAnalysis) {
final ParsedPom parentPom = projectContext.getParentPom();
final int dupEntries = reportDupEntries();
if (!enumerateJars(archive)) {
@@ -305,7 +306,8 @@ public class DependencyChecker {
} else if (oldName.equals(artifact.getVersion())) {
report.format("File %s present in multiple locations\n", jarPath);
} else {
- report.format("File %s present with versions %s and %s\n", artifact.getArtifactId(), oldName, artifact.getVersion());
+ report.format("File %s present with versions %s and %s\n",
+ artifact.getArtifactId(), oldName, artifact.getVersion());
}
duplicateJars++;
}
@@ -314,7 +316,7 @@ public class DependencyChecker {
* @param archive what to look in
* @return true if OK, false otherwise
*/
- private boolean enumerateJars(final ArchiveInputStream archive) {
+ private boolean enumerateJars(final ArchiveInputStream<?> archive) {
ArchiveEntry entry = null;
try {
while ((entry = archive.getNextEntry()) != null) {
@@ -324,8 +326,7 @@ public class DependencyChecker {
}
if (entry.isDirectory()) {
continue;
- }
- else if (!entry.getName().endsWith(".jar")) {
+ } else if (!entry.getName().endsWith(".jar")) {
continue;
}
final Path nameAsPath = Path.of(entry.getName());
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/GPGKeyRing.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/GPGKeyRing.java
index 6f1c127..85d3629 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/GPGKeyRing.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/GPGKeyRing.java
@@ -122,7 +122,8 @@ import org.slf4j.Logger;
* {@link PGPPublicKeyRingCollection#PGPPublicKeyRingCollection(InputStream,
* org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator)}
*/
- @Nonnull private static PGPPublicKeyRingCollection loadRingFromAsc(@Nonnull final InputStream in) throws IOException {
+ @Nonnull
+ private static PGPPublicKeyRingCollection loadRingFromAsc(@Nonnull final InputStream in) throws IOException {
try (final InputStream decoded = PGPUtil.getDecoderStream(in)) {
final ArrayList<PGPPublicKeyRing> listr = new ArrayList<>();
@@ -149,7 +150,7 @@ import org.slf4j.Logger;
*/
protected String getKeyInfo(final Signature sigForKey) {
final PGPPublicKeyRing keyRing;
- keyRing = keyRings.getPublicKeyRing(sigForKey.getSignature().getKeyID());
+ keyRing = keyRings.getPublicKeyRing(sigForKey.getSignature().getKeyID());
if (keyRing == null) {
log.info("Provided key stream did not contain a key for {}", sigForKey);
return null;
@@ -189,7 +190,7 @@ import org.slf4j.Logger;
log.debug("Looking for key with Id {}", signature);
- return keyRings.getPublicKey(sig.getKeyID()) != null;
+ return keyRings.getPublicKey(sig.getKeyID()) != null;
}
/** Run a signature check over the streams.
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 76e9527..359af5c 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -122,7 +122,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
/** The list of things which get added to real versions. */
@Nonnull private String versionExtensions = "-SNAPSHOT -GA -jre -empty-to-avoid-conflict-with-guava";
- /** The list of classifiers we know about*/
+ /** The list of classifiers we know about. */
@Nonnull private String classifiers = "";
/** Our Maven Session . */
@@ -140,8 +140,17 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
/** {@literal ${basedir}}\target}. */
private final Path targetDir;
+ /**
+ * Constructor.
+ *
+ * @param theProject summoned up for us by the enforcer.
+ * @param theSession summoned up for us by the enforcer.
+ * @param theRepoSystem summoned up for us by the enforcer.
+ */
@Inject
- public JarEnforcer(MavenProject theProject, MavenSession theSession, RepositorySystem theRepoSystem) {
+ public JarEnforcer(final MavenProject theProject,
+ final MavenSession theSession,
+ final RepositorySystem theRepoSystem) {
project = Constraint.isNotNull(theProject, "project must not be null");
session = Constraint.isNotNull(theSession, "session must not be null");
targetDir = session.getCurrentProject().getBasedir().toPath();
@@ -149,7 +158,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
}
/**
- * Get the path for the m2 Sig check - as configured or the default
+ * Get the path for the m2 Sig check - as configured or the default.
* @return the path
*/
private Path getM2ReportPath() {
@@ -160,7 +169,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
}
/**
- * Get the path for the signature check - as configured or the default
+ * Get the path for the signature check - as configured or the default.
* @return the path
*/
private Path getSigCheckReportPath() {
@@ -171,7 +180,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
}
/**
- * Get the path for the dependency check - as configured or the default
+ * Get the path for the dependency check - as configured or the default.
* @return the path
*/
private Path getDepCheckReportPath() {
@@ -184,6 +193,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
/**
* {@inheritDoc}
*/
+ // CheckStyle: CyclomaticComplexity OFF
@Override
public void execute() throws EnforcerRuleException {
MvnEnforcerLogger.setMavenLogger(getLog());
@@ -251,6 +261,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
throw new EnforcerRuleException(e.toString() + " "+ e.getMessage(), e);
}
}
+ // CheckStyle: CyclomaticComplexity ON
/** Grab a ClassLoader for the data file. Eventually this will do a GPG test.
* @return A class loader built from the downloaded artifact
@@ -271,10 +282,12 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
if (!isGPGDataASnapshot()) {
final File asc = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "jar.asc");
if (asc == null || !asc.exists()) {
- log.error("Could not locate keyring data artifact signature for {}:{}:{}", dataGroupId, dataArtifactId, dataVersion);
- throw new FileNotFoundException("Could not locate keyring data artifact signature: probably a failed checksum");
+ log.error("Could not locate keyring data artifact signature for {}:{}:{}",
+ dataGroupId, dataArtifactId, dataVersion);
+ throw new FileNotFoundException(
+ "Could not locate keyring data artifact signature: probably a failed checksum");
}
- final File keyRingFile = new File (dataKeyRing);
+ final File keyRingFile = new File(dataKeyRing);
if (!keyRingFile.exists()) {
log.error("KeyRing {} not found", keyRingFile);
throw new FileNotFoundException(dataKeyRing);
@@ -285,27 +298,32 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
final Signature sig = new Signature(ascStream);
if (!keyRing.checkSignature(jarStream, sig)) {
- log.error("Signature check on data artifact {}:{}:{}:{} failed", dataGroupId, dataArtifactId, dataVersion);
+ log.error("Signature check on data artifact {}:{}:{}:{} failed",
+ dataGroupId, dataArtifactId, dataVersion);
throw new EnforcerRuleException("Signature check on data artifact failed");
}
}
}
- final URL url[] = {jar.toURI().toURL()};
+ final URL[] url = { jar.toURI().toURL() };
return new URLClassLoader(url);
}
- /** Do the m2 signature checks
+ /** Do the m2 signature checks.
* @param pomContext Context for the work
* @return if this worked (or was suppressed)
* @throws Exception is resolution fails
*/
+ // CheckStyle: CyclomaticComplexity OFF
private boolean performM2Check(@Nonnull final ProjectPomContext pomContext) throws Exception {
boolean m2Result = true;
if (checkM2) {
final File resolvePomFile;
- if (!"".equals(m2GroupId) || !"".equals(m2ArtifactId) || !"".equals(m2Version) || !"".equals(m2Type)) {
+ if (!"".equals(m2GroupId) || !"".equals(m2ArtifactId) || !"".equals(m2Version) ||
+ !"".equals(m2Type)) {
if ("".equals(m2GroupId) || "".equals(m2ArtifactId) || "".equals(m2Version)) {
- log.error("Must specify all of m2GroupId, m2ArtifactId, m2Version and m2Type or none. Provided {}, {}, {}, {}",
+ log.error("Must specify all of m2GroupId, m2ArtifactId" +
+ ", m2Version and m2Type or none." +
+ "Provided {}, {}, {}, {}",
m2GroupId, m2ArtifactId, m2Version, m2Type);
throw new EnforcerRuleException("Configuration for m2 check failed");
}
@@ -321,7 +339,8 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
}
if (!"".equals(m2GroupId) || !"".equals(m2ArtifactId)|| !"".equals(m2Version)) {
if ("".equals(m2GroupId) || "".equals(m2ArtifactId) || "".equals(m2Version)) {
- log.error("Must specify all of m2GroupId, m2ArtifactId and m2Version, not none. Provided {}, {}, {}",
+ log.error("Must specify all of m2GroupId, m2ArtifactId and m2Version, not none." +
+ " Provided {}, {}, {}",
m2GroupId, m2ArtifactId, m2Version);
throw new EnforcerRuleException("Configuration for m2 check failed");
}
@@ -329,7 +348,8 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
final Path resolvedPom = resolvePomFile.toPath();
// Resolved pom path is <pathTpM2Repo>/group1/group2/..../artifact/version/pomfilename
log.debug("Resolved Pom = {}", resolvedPom);
- Path root = resolvedPom.getParent().getParent().getParent(); // strip version, artifact
+ // strip version, artifact
+ Path root = resolvedPom.getParent().getParent().getParent();
int index = dataGroupId.indexOf('.');
while (index > 0) {
root = root.getParent();
@@ -350,8 +370,9 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
}
return m2Result;
}
+ // CheckStyle: CyclomaticComplexity On
- /** Do the signature check
+ /** Do the signature check.
* @param pomContext Context for the work
* @param tgzPaths the tgzFiles to look at.
* @param zipPaths the zipFiles to look at.
@@ -360,11 +381,13 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
* @throws EnforcerRuleException if we were doing an invalid SNAPSHOT/nonSNAPSHOT test
*/
private boolean performSignatureCheck(@Nonnull final ProjectPomContext pomContext,
- @Nonnull final List<Path> tgzPaths, @Nonnull final List<Path> zipPaths) throws IOException, EnforcerRuleException {
+ @Nonnull final List<Path> tgzPaths,
+ @Nonnull final List<Path> zipPaths) throws IOException, EnforcerRuleException {
boolean signatureResult = true;
if (checkSignatures) {
if (isGPGDataASnapshot() && !pomContext.isSnapShot()) {
- throw new EnforcerRuleException("Running a signature check of a non SNAPSHOT build against a SNAPSHOT of GPGData");
+ throw new EnforcerRuleException("Running a signature check of a non SNAPSHOT" +
+ " built against a SNAPSHOT of GPGData");
}
try (final PrintWriter report =
new PrintWriter(new BufferedOutputStream(new FileOutputStream(getSigCheckReportPath().toFile())))) {
@@ -375,7 +398,8 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
for (final Path tgzPath: tgzPaths) {
report.format("Scanning %s \n\n", tgzPath);
try (final InputStream inStream = new BufferedInputStream(new FileInputStream(tgzPath.toFile()))) {
- signatureResult &= sigChecker.testSignatures(new TarArchiveInputStream(new GzipCompressorInputStream(inStream)));
+ signatureResult &= sigChecker.testSignatures(
+ new TarArchiveInputStream(new GzipCompressorInputStream(inStream)));
}
}
for (final Path zipPath: zipPaths) {
@@ -393,7 +417,7 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
return signatureResult;
}
- /** Do the dependency check
+ /** Do the dependency check.
* @param pomContext Context for the work
* @param tgzPaths the tgzFiles to look at.
* @param zipPaths the zipFiles to look at.
@@ -412,17 +436,22 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
for (final Path tgzPath: tgzPaths) {
report.format("Scanning %s \n\n", tgzPath);
try (final InputStream inStream = new BufferedInputStream(new FileInputStream(tgzPath.toFile()))) {
- final DependencyChecker checker = new DependencyChecker(pomContext, report, compileRuntimeArtifactFatal,
- distVersionMismatchFatal, pomVersionMismatchFatal, multipleJarVersionsFatal);
- depdendencyResult &= checker.checkDependencies(new TarArchiveInputStream(new GzipCompressorInputStream(inStream)), listJarSources);
+ final DependencyChecker checker = new DependencyChecker(pomContext, report,
+ compileRuntimeArtifactFatal, distVersionMismatchFatal,
+ pomVersionMismatchFatal, multipleJarVersionsFatal);
+ depdendencyResult &= checker.checkDependencies(
+ new TarArchiveInputStream(
+ new GzipCompressorInputStream(inStream)), listJarSources);
}
}
for (final Path zipPath: zipPaths) {
report.format("Scanning %s \n\n", zipPath);
try (final InputStream inStream = new BufferedInputStream(new FileInputStream(zipPath.toFile()))) {
- final DependencyChecker checker = new DependencyChecker(pomContext, report, compileRuntimeArtifactFatal,
- distVersionMismatchFatal, pomVersionMismatchFatal, multipleJarVersionsFatal);
- depdendencyResult &= checker.checkDependencies(new ZipArchiveInputStream(inStream), listJarSources);
+ final DependencyChecker checker = new DependencyChecker(pomContext, report,
+ compileRuntimeArtifactFatal, distVersionMismatchFatal,
+ pomVersionMismatchFatal, multipleJarVersionsFatal);
+ depdendencyResult &=
+ checker.checkDependencies(new ZipArchiveInputStream(inStream), listJarSources);
}
}
report.format("Completed at %s\n\n", Instant.now().toString());
@@ -457,7 +486,11 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
* @return a file or null if it could not be resolved
* @throws Exception on various issues from the (maven) resolver
*/
- @Nullable public File downloadArtifact(final String groupId, final String artifactId, final String version, final String classifier, final String type) throws Exception {
+ @Nullable public File downloadArtifact(final String groupId,
+ final String artifactId,
+ final String version,
+ final String classifier,
+ final String type) throws Exception {
final Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, type, version);
final ArtifactRequest req = new ArtifactRequest(artifact, project.getRemoteProjectRepositories(), null);
@@ -475,7 +508,11 @@ public class JarEnforcer extends AbstractEnforcerRule implements MavenLoader{
/** {@inheritDoc} */
@Nullable public Path downloadArtifact(final PomArtifact artifact, final String type) throws Exception {
- final File file = downloadArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), type);
+ 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 896bd95..9403681 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
@@ -50,7 +50,9 @@ public class M2SigChecker extends BaseSigChecker {
* @param writer Where to write our report
* @param considerZips Do we want to sig check zip files?
*/
- public M2SigChecker(@Nonnull final ProjectPomContext project, @Nonnull final PrintWriter writer, boolean considerZips) {
+ public M2SigChecker(@Nonnull final ProjectPomContext project,
+ @Nonnull final PrintWriter writer,
+ final boolean considerZips) {
super(project, writer);
checkZips = considerZips;
}
@@ -71,17 +73,19 @@ public class M2SigChecker extends BaseSigChecker {
private class M2Visitor extends SimpleFileVisitor<Path> {
+ /** Where we start. */
private final Path root;
/** Constructor.
* @param path where the serach starts
*/
- public M2Visitor(Path path) {
+ public M2Visitor(final Path path) {
root = path;
}
/** {@inheritDoc} */
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ // CheckStyle: CyclomaticComplexity OFF
+ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
final FileVisitResult result = super.visitFile(file, attrs);
final Path relativePath = root.relativize(file);
@@ -92,8 +96,7 @@ public class M2SigChecker extends BaseSigChecker {
return result;
}
fileType = "zip";
- }
- else if (!fileName.endsWith(".jar") ||
+ } else if (!fileName.endsWith(".jar") ||
fileName.endsWith("-tests.jar") ||
fileName.endsWith("-sources.jar") ||
fileName.endsWith("-javadoc.jar") ) {
@@ -120,12 +123,13 @@ public class M2SigChecker extends BaseSigChecker {
}
return result;
}
+ // CheckStyle: CyclomaticComplexity ON
/** Given a path "org/example/extra/artifactID/version" return the artifact coordinates.
* @param path the path to an artifact.
* @return a suitable {@link DependencyPomArtifact}
*/
- private PomArtifact artifactFromPath(Path path) {
+ private PomArtifact artifactFromPath(final Path path) {
final Path versionDir = path.getParent();
if (versionDir == null) {
return null;
@@ -151,12 +155,15 @@ public class M2SigChecker extends BaseSigChecker {
} else if (fileName.length() > artifactId.length() + 1 + version.length() + 4) {
// Need to be able to handle classifier
// org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noapp.jar
- String s = fileName.substring(
+ //
+ // CheckStyle: TrailingComment OFF
+ final String s = fileName.substring(
artifactId.length() // "sisu-guice"
+ 1 // "-"
+ version.length() // "2.1.7"
+ 1, // "-"
fileName.length() - 4); // ".jar"
+ // CheckStyle: TrailingComment ON
assert s != null;
classifier =s;
} else {
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 d752899..c17b27e 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ParsedPom.java
@@ -47,6 +47,10 @@ import net.shibboleth.shared.xml.XMLParserException;
*/
public class ParsedPom {
+ /** Tag for when we dont know. */
+ @Nonnull
+ public static final String UNSPECIFIED_GROUP = "unspecified-group";
+
/** Log. */
@Nonnull private final Logger log;
@@ -74,8 +78,6 @@ public class ParsedPom {
/** Properties. */
@Nonnull private final Properties properties = new Properties();
- @Nonnull static final String UNSPECIFIED_GROUP = "unspecified-group";
-
/** Parent Pom .*/
private DependencyPomArtifact parent;
@@ -89,26 +91,27 @@ public class ParsedPom {
* @param pomLoader how to get a pom (for BOM loading)
* @param pom the {@link Path} to the pom.
* @param pomName an ID for the pom
- * @param thelog logger
- * @param parentPomProperties if present it is properties from the parent (which might be empty), if null we are *only*
+ * @param theLog logger
+ * @param parentPomProperties if present it is properties from the parent
+ * (which might be empty), if null we are *only*
* looking for the parent pom coordinates.
* @param map Managed dependencies from parent
* @throws Exception if we have issued locating a bom
*/
+ // CheckStyle: MethodLength|ParameterNumber|CyclomaticComplexity OFF
public ParsedPom(@Nonnull final ParserPool parsers,
@Nonnull final MavenLoader pomLoader,
@Nonnull final Path pom,
@Nonnull final String pomName,
@Nonnull final Logger theLog,
@Nullable final Properties parentPomProperties,
- @Nonnull final Map<String, DependencyPomArtifact> map)
- throws Exception {
+ @Nonnull final Map<String, DependencyPomArtifact> map) throws Exception {
log = theLog;
managedDependencies = new HashMap<>(map);
sourcePomInfo = pomName;
- Document document;
+ final Document document;
try (final InputStream stream = new BufferedInputStream(new FileInputStream(pom.toFile()))) {
document = parsers.parse(stream);
}
@@ -139,13 +142,13 @@ public class ParsedPom {
parentAsString, theLog, new Properties(), Collections.emptyMap());
final Properties props = parsedParent.getProperties();
for (final Object p:props.keySet()) {
- String pName = (String) p;
+ final String pName = (String) p;
properties.setProperty(pName, props.getProperty(pName));
}
}
}
for (final Object p:parentPomProperties.keySet()) {
- String pName = (String) p;
+ final String pName = (String) p;
properties.setProperty(pName, parentPomProperties.getProperty(pName));
}
properties.setProperty("basedir", "<bogus_base_dir>");
@@ -174,7 +177,7 @@ public class ParsedPom {
assert bomAsString!=null;
final ParsedPom parsedBom = new ParsedPom(parsers, pomLoader, bomAsPath, bomAsString,
log, new Properties(), Collections.emptyMap());
- for (DependencyPomArtifact dep : parsedBom.getManagedDependencies().values()) {
+ for (final DependencyPomArtifact dep : parsedBom.getManagedDependencies().values()) {
addWithCheck(dep, managedDependencies);
}
}
@@ -205,6 +208,7 @@ public class ParsedPom {
addWithCheck(dep, runtimeDependencies);
}
}
+ // CheckStyle: MethodLength|ParameterNumber|CyclomaticComplexity ON
/** Get the text content of the element, performing property replacement as we go.
* @param el the element
@@ -245,7 +249,7 @@ public class ParsedPom {
private void parseDependencies(final Element item) {
final List<Element> dependencies = ElementSupport.getChildElementsByTagName(item, "dependency");
- for (Element dependency : dependencies) {
+ for (final Element dependency : dependencies) {
final DependencyPomArtifact artifact = new DependencyPomArtifact(dependency);
final List<Element> types = ElementSupport.getChildElementsByTagName(dependency, "type");
if (!types.isEmpty()) {
@@ -275,12 +279,12 @@ public class ParsedPom {
}
}
- /** parse the Managed Dependencies from the provided item
+ /** Parse the Managed Dependencies from the provided item.
* @param item what to parse
*/
private void parseManagedDependencies(final Element item) {
final List<Element> dependencies = ElementSupport.getChildElementsByTagName(item, "dependency");
- for (Element dependency : dependencies) {
+ for (final Element dependency : dependencies) {
final DependencyPomArtifact artifact = new DependencyPomArtifact(dependency);
final List<Element> types = ElementSupport.getChildElementsByTagName(dependency, "type");
if (!types.isEmpty()) {
@@ -311,7 +315,7 @@ public class ParsedPom {
/** Parse the properties from the pom.
* @param item the <properties> element
*/
- private void parseProperties(Element item) {
+ private void parseProperties(final Element item) {
for (final Element child : ElementSupport.getChildElements(item)) {
final String name = child.getLocalName();
@@ -324,7 +328,7 @@ public class ParsedPom {
/** Parse the parent from the pom.
* @param item the <parent> element
*/
- private void parseParent(Element item) {
+ private void parseParent(final Element item) {
parent = new DependencyPomArtifact(item);
}
@@ -351,7 +355,7 @@ public class ParsedPom {
return managedDependencies;
}
- /** Get artifacts that were duplicated by this build
+ /** Get artifacts that were duplicated by this build.
* @return Returns the duplicates.
*/
@Nonnull public List<Pair<DependencyPomArtifact, DependencyPomArtifact>> getDuplicates() {
@@ -390,7 +394,7 @@ public class ParsedPom {
public class DependencyPomArtifact extends PomArtifact {
/** What version to give if we cannot find the version. */
- public final static String BAD_VERSION = "VERSION_NOT_DETERMINED";
+ public static final String BAD_VERSION = "VERSION_NOT_DETERMINED";
/** <exclusions>. */
@Nonnull private final Set<Pair<String, String>> exclusions = new HashSet<>();
@@ -410,6 +414,7 @@ public class ParsedPom {
* @param item element to interrogate.
* @param parentArtifact to inherit from
*/
+ // CheckStyle: CyclomaticComplexity OFF
public DependencyPomArtifact(final Element item, final @Nullable DependencyPomArtifact parentArtifact) {
super("", "", "");
final List<Element> grps = ElementSupport.getChildElementsByTagName(item, "groupId");
@@ -450,7 +455,7 @@ public class ParsedPom {
List<Element> excls = ElementSupport.getChildElementsByTagName(item, "exclusions");
if (excls.size() > 0) {
excls = ElementSupport.getChildElementsByTagName(excls.get(0), "exclusion");
- for (Element e : excls) {
+ for (final Element e : excls) {
List<Element> els = ElementSupport.getChildElementsByTagName(e, "groupId");
final String grp;
if (els.size() == 0) {
@@ -471,7 +476,7 @@ public class ParsedPom {
}
}
}
-
+ // CheckStyle: CyclomaticComplexity ON
/**
* Constructor.
*
@@ -480,18 +485,21 @@ public class ParsedPom {
* @param ver the <version>
* @param clssfr the <classifier>
*/
- private DependencyPomArtifact(@Nonnull final String group, @Nonnull final String id, @Nonnull final String ver, @Nonnull final String clssfr) {
+ private DependencyPomArtifact(@Nonnull final String group,
+ @Nonnull final String id,
+ @Nonnull final String ver,
+ @Nonnull final String clssfr) {
super(group, id, ver, clssfr);
}
- /**
+ /** Getter for {@link #sourcePomInfo}.
* @return the pom source.
*/
public String getSourcePomFilename() {
return sourcePomInfo;
}
- /**
+ /** Getter for {@link #exclusions}.
* @return Returns the exclusions.
*/
public Set<Pair<String, String>> getExclusions() {
@@ -502,7 +510,7 @@ public class ParsedPom {
* @param ver the version
* @return an amended artifact.
*/
- public final DependencyPomArtifact withVersion(@Nonnull String ver) {
+ public final DependencyPomArtifact withVersion(@Nonnull final 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
index 458910e..0df4cc8 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/PomArtifact.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/PomArtifact.java
@@ -22,6 +22,8 @@ import javax.annotation.Nonnull;
* Encapsulation of an artifact in a pom file.
*/
public class PomArtifact implements Comparable<PomArtifact> {
+
+ //CheckStyle: VisibilityModifier OFF
/** <groupId>.*/
@Nonnull protected String groupId;
@@ -33,6 +35,7 @@ public class PomArtifact implements Comparable<PomArtifact> {
/** <classifier>.*/
@Nonnull protected String classifier;
+ //CheckStyle: VisibilityModifier ON
/**
* Constructor.
@@ -53,7 +56,10 @@ public class PomArtifact implements Comparable<PomArtifact> {
* @param ver the <version>
* @param clssfr the <classifier>
*/
- public PomArtifact(@Nonnull final String group, @Nonnull final String id, @Nonnull final String ver, @Nonnull final String clssfr) {
+ public PomArtifact(@Nonnull final String group,
+ @Nonnull final String id,
+ @Nonnull final String ver,
+ @Nonnull final String clssfr) {
artifactId = id;
groupId = group;
version = ver;
@@ -61,28 +67,28 @@ public class PomArtifact implements Comparable<PomArtifact> {
}
- /**
+ /** Get the groupId.
* @return Returns the groupId.
*/
@Nonnull public final String getGroupId() {
return groupId;
}
- /**
+ /** Get the artifactId.
* @return Returns the artifactId.
*/
@Nonnull public final String getArtifactId() {
return artifactId;
}
- /**
+ /** Get the version.
* @return Returns the version.
*/
@Nonnull public final String getVersion() {
return version;
}
- /**
+ /** Get the Classifier.
* @return Returns the classifier.
*/
@Nonnull public final String getClassifier() {
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 cbc0c0c..664cb18 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
@@ -44,7 +44,8 @@ import net.shibboleth.shared.xml.ParserPool;
public final class ProjectPomContext implements AutoCloseable {
/** Where the keyrings live when on the classpath. */
- @Nonnull public final static String CLASSPATH_ROOT = "net/shibboleth/mvn/enforcer/data/";
+ @Nonnull
+ public static final String CLASSPATH_ROOT = "net/shibboleth/mvn/enforcer/data/";
/** Our log. */
@Nonnull private final Logger log;
@@ -85,9 +86,10 @@ public final class ProjectPomContext implements AutoCloseable {
* @param pool a parser pool
* @param classLoader source for extra info (like keyrings)
* @param extensions the known additions to the versions
- * @param classifiers the classifiers we know about
+ * @param clsfrs the classifiers we know about
* @throws IOException if we cannit create the temp dir
*/
+ // CheckStyle: ParameterNumber OFF
public ProjectPomContext(final MavenLoader loader,
@Nonnull final Logger logger,
@Nonnull final ParserPool pool,
@@ -99,11 +101,12 @@ public final class ProjectPomContext implements AutoCloseable {
final Path wd = Files.createTempDirectory("EnforcerCLI");
assert wd != null;
workingDir = wd;
- enforcerLoader = Constraint.isNotNull(classLoader, "Class Loader must not be null");;
+ enforcerLoader = Constraint.isNotNull(classLoader, "Class Loader must not be null");
parserPool = Constraint.isNotNull(pool, "Parse Pool must not be null");
extensionGarnish = Constraint.isNotNull(extensions, "Extensions must not be null");
classifiers = Constraint.isNotNull(clsfrs, "Classifiers must not be null");
}
+ // CheckStyle: ParameterNumber ON
/** Returns the parserPool.
* @return the parsers
@@ -138,7 +141,7 @@ public final class ProjectPomContext implements AutoCloseable {
return group;
}
- /** Return the {@link MavenLoader}
+ /** Return the {@link MavenLoader}.
* @return {@link #mavenLoader}
*/
public MavenLoader getMavenLoader() {
@@ -157,6 +160,7 @@ public final class ProjectPomContext implements AutoCloseable {
* @param pomPath Where the parent pom is.
* @return true if all worked OK, false otherwise
*/
+ // CheckStyle: ReturnCount OFF
private boolean parsePom(@Nonnull final Path pomPath) {
try {
@@ -213,6 +217,7 @@ public final class ProjectPomContext implements AutoCloseable {
}
return true;
}
+ // CheckStyle: ReturnCount ON
/** Create the reporter print stream.
* @param pomPath where to load the pom from
@@ -265,7 +270,7 @@ public final class ProjectPomContext implements AutoCloseable {
final String path = CLASSPATH_ROOT + "artifactMap.properties";
try (final InputStream stream = enforcerLoader.getResourceAsStream(path)) {
props.load(stream);
- } catch (IOException e) {
+ } catch (final IOException e) {
log.error("Could not load artifact map properties from {}", path, e);
return false;
}
@@ -296,8 +301,8 @@ public final class ProjectPomContext implements AutoCloseable {
return true;
}
- /** Split the file name into name, version and classifier infer the groupId
- * and then summon up a @{link {@link PomArtifact}
+ /** Split the file name into name, version and classifier infer the groupId.
+ * and then summon up a @{link {@link PomArtifact}.
* @param inName the file name
* @return a pom artifact
*/
@@ -359,7 +364,7 @@ public final class ProjectPomContext implements AutoCloseable {
/**
* A @{link {@link FileVisitor} which deletes files.
*/
- private class DeletingVisitor extends SimpleFileVisitor<Path> {
+ private final class DeletingVisitor extends SimpleFileVisitor<Path> {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
try {
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 636abea..f546e21 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/SigChecker.java
@@ -46,7 +46,7 @@ public class SigChecker extends BaseSigChecker {
* @param archive what to look at
* @return true if all was OK.
*/
- public boolean testSignatures(final ArchiveInputStream archive) {
+ public boolean testSignatures(final ArchiveInputStream<?> archive) {
int sigFails = 0;
try {
ArchiveEntry entry = null;
@@ -57,8 +57,7 @@ public class SigChecker extends BaseSigChecker {
}
if (entry.isDirectory()) {
continue;
- }
- else if (!entry.getName().endsWith(".jar")) {
+ } else if (!entry.getName().endsWith(".jar")) {
continue;
}
sigFails += checkSignature(entry.getName(), archive);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list