From 45b1d9f9fd8567f557eca6774e8a0674a269ce9d Mon Sep 17 00:00:00 2001 From: caroso-de Date: Mon, 21 Feb 2022 21:35:19 +0100 Subject: [PATCH] #30 make contributions clearer in source code --- .../steps/checks/CheckDependencyVersions.java | 3 +- .../functions/GAVPatternToCoordinates.java | 54 ++++---- .../predicates/IsMatchingCoordinates.java | 124 +++++++++--------- .../GAVPatternToCoordinatesTest.java | 4 + .../predicates/IsMatchingCoordinatesTest.java | 4 + pom.xml | 18 ++- 6 files changed, 114 insertions(+), 93 deletions(-) rename plugin/src/main/java/{com/itemis => de/caroso}/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java (82%) rename plugin/src/main/java/{com/itemis => de/caroso}/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java (91%) diff --git a/plugin/src/main/java/com/itemis/maven/plugins/unleash/steps/checks/CheckDependencyVersions.java b/plugin/src/main/java/com/itemis/maven/plugins/unleash/steps/checks/CheckDependencyVersions.java index 7c8b5e6..0c64c39 100644 --- a/plugin/src/main/java/com/itemis/maven/plugins/unleash/steps/checks/CheckDependencyVersions.java +++ b/plugin/src/main/java/com/itemis/maven/plugins/unleash/steps/checks/CheckDependencyVersions.java @@ -39,9 +39,9 @@ import com.itemis.maven.plugins.unleash.util.functions.DependencyToCoordinates; import com.itemis.maven.plugins.unleash.util.functions.ProjectToCoordinates; import com.itemis.maven.plugins.unleash.util.functions.ProjectToString; -import com.itemis.maven.plugins.unleash.util.predicates.IsMatchingCoordinates; import com.itemis.maven.plugins.unleash.util.predicates.IsSnapshotDependency; +import de.caroso.maven.plugins.unleash.util.predicates.IsMatchingCoordinates; import edu.emory.mathcs.backport.java.util.Arrays; /** @@ -49,6 +49,7 @@ * would potentially lead to non-reproducible release artifacts. * * @author Stanley Hillner + * @author Carsten Rohde * @since 1.0.0 */ @ProcessingStep(id = "checkDependencies", description = "Checks that the project modules do not reference SNAPSHOT dependencies to avoid unreproducible release aritfacts.", requiresOnline = false) diff --git a/plugin/src/main/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java b/plugin/src/main/java/de/caroso/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java similarity index 82% rename from plugin/src/main/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java rename to plugin/src/main/java/de/caroso/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java index 6d098f9..194eb92 100644 --- a/plugin/src/main/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java +++ b/plugin/src/main/java/de/caroso/maven/plugins/unleash/util/functions/GAVPatternToCoordinates.java @@ -1,25 +1,29 @@ -/** - * (c) caroso-de 2022 - */ -package com.itemis.maven.plugins.unleash.util.functions; - -import com.google.common.base.Function; -import com.itemis.maven.aether.ArtifactCoordinates; - -public class GAVPatternToCoordinates implements Function { - - @Override - public ArtifactCoordinates apply(String gav) { - String[] tokens = gav.split(":"); - switch (tokens.length) { - case 1: - return new ArtifactCoordinates(tokens[0], null, null); - case 2: - return new ArtifactCoordinates(tokens[0], tokens[1], null); - case 3: - default: - return new ArtifactCoordinates(tokens[0], tokens[1], tokens[2]); - } - } - -} +/** + * (c) caroso-de 2022 + */ +package de.caroso.maven.plugins.unleash.util.functions; + +import com.google.common.base.Function; + +import com.itemis.maven.aether.ArtifactCoordinates; + +/** + * @author Carsten Rohde +*/ +public class GAVPatternToCoordinates implements Function { + + @Override + public ArtifactCoordinates apply(String gav) { + String[] tokens = gav.split(":"); + switch (tokens.length) { + case 1: + return new ArtifactCoordinates(tokens[0], null, null); + case 2: + return new ArtifactCoordinates(tokens[0], tokens[1], null); + case 3: + default: + return new ArtifactCoordinates(tokens[0], tokens[1], tokens[2]); + } + } + +} diff --git a/plugin/src/main/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java b/plugin/src/main/java/de/caroso/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java similarity index 91% rename from plugin/src/main/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java rename to plugin/src/main/java/de/caroso/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java index 923856a..694c001 100644 --- a/plugin/src/main/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java +++ b/plugin/src/main/java/de/caroso/maven/plugins/unleash/util/predicates/IsMatchingCoordinates.java @@ -1,60 +1,64 @@ -/** - * (c) caroso-de 2022 - */ -package com.itemis.maven.plugins.unleash.util.predicates; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import com.google.common.base.Objects; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.Sets; -import com.itemis.maven.aether.ArtifactCoordinates; -import com.itemis.maven.plugins.unleash.util.functions.GAVPatternToCoordinates; - -public class IsMatchingCoordinates implements Predicate { - - private final Set referencePatterns; - - public IsMatchingCoordinates(List someAllowedSnapshots) { - List allowedSnapshots = someAllowedSnapshots != null ? someAllowedSnapshots : new ArrayList<>(); - - referencePatterns = Sets.newHashSet(Collections2.transform(allowedSnapshots, new GAVPatternToCoordinates())); - } - - @Override - public boolean apply(ArtifactCoordinates coordinates) { - for (ArtifactCoordinates referencePattern : referencePatterns) { - if (matchesPattern(coordinates, referencePattern)) { - return true; - } - } - return false; - } - - private boolean matchesPattern(ArtifactCoordinates aCoordinates, ArtifactCoordinates aReferencePattern) { - String tReferenceGroupId = aReferencePattern.getGroupId(); - String tGroupId = aCoordinates.getGroupId(); - - String tReferenceArtifactId = aReferencePattern.getArtifactId(); - String tArtifactId = aCoordinates.getArtifactId(); - String tReferenceVersion = aReferencePattern.getVersion(); - String tVersion = aCoordinates.getVersion(); - - boolean tGroupIdMatches = wildcardOrLiteralMatch(tReferenceGroupId, tGroupId); - boolean tArtifactIdMatches = tReferenceArtifactId == null - || wildcardOrLiteralMatch(tReferenceArtifactId, tArtifactId); - boolean tVersionMatches = tVersion == null || wildcardOrLiteralMatch(tReferenceVersion, tVersion); - - return tGroupIdMatches && tArtifactIdMatches && tVersionMatches; - } - - private boolean wildcardOrLiteralMatch(String tLeft, String tRight) { - boolean atLeastOneIsNull = tLeft == null || tRight == null; - return atLeastOneIsNull || Objects.equal(tLeft, tRight) || Objects.equal(tLeft, "*") - || Objects.equal(tRight, "*"); - } - -} +/** + * (c) caroso-de 2022 + */ +package de.caroso.maven.plugins.unleash.util.predicates; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; +import com.google.common.collect.Sets; +import com.itemis.maven.aether.ArtifactCoordinates; + +import de.caroso.maven.plugins.unleash.util.functions.GAVPatternToCoordinates; + +/** + * @author Carsten Rohde +*/ +public class IsMatchingCoordinates implements Predicate { + + private final Set referencePatterns; + + public IsMatchingCoordinates(List someAllowedSnapshots) { + List allowedSnapshots = someAllowedSnapshots != null ? someAllowedSnapshots : new ArrayList<>(); + + referencePatterns = Sets.newHashSet(Collections2.transform(allowedSnapshots, new GAVPatternToCoordinates())); + } + + @Override + public boolean apply(ArtifactCoordinates coordinates) { + for (ArtifactCoordinates referencePattern : referencePatterns) { + if (matchesPattern(coordinates, referencePattern)) { + return true; + } + } + return false; + } + + private boolean matchesPattern(ArtifactCoordinates aCoordinates, ArtifactCoordinates aReferencePattern) { + String tReferenceGroupId = aReferencePattern.getGroupId(); + String tGroupId = aCoordinates.getGroupId(); + + String tReferenceArtifactId = aReferencePattern.getArtifactId(); + String tArtifactId = aCoordinates.getArtifactId(); + String tReferenceVersion = aReferencePattern.getVersion(); + String tVersion = aCoordinates.getVersion(); + + boolean tGroupIdMatches = wildcardOrLiteralMatch(tReferenceGroupId, tGroupId); + boolean tArtifactIdMatches = tReferenceArtifactId == null + || wildcardOrLiteralMatch(tReferenceArtifactId, tArtifactId); + boolean tVersionMatches = tVersion == null || wildcardOrLiteralMatch(tReferenceVersion, tVersion); + + return tGroupIdMatches && tArtifactIdMatches && tVersionMatches; + } + + private boolean wildcardOrLiteralMatch(String tLeft, String tRight) { + boolean atLeastOneIsNull = tLeft == null || tRight == null; + return atLeastOneIsNull || Objects.equal(tLeft, tRight) || Objects.equal(tLeft, "*") + || Objects.equal(tRight, "*"); + } + +} diff --git a/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinatesTest.java b/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinatesTest.java index 8be00a8..e9e3dfa 100644 --- a/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinatesTest.java +++ b/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/functions/GAVPatternToCoordinatesTest.java @@ -9,7 +9,11 @@ import com.itemis.maven.aether.ArtifactCoordinates; +import de.caroso.maven.plugins.unleash.util.functions.GAVPatternToCoordinates; +/** + * @author Carsten Rohde +*/ public class GAVPatternToCoordinatesTest { diff --git a/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinatesTest.java b/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinatesTest.java index 6b820d5..ff83583 100644 --- a/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinatesTest.java +++ b/plugin/src/test/java/com/itemis/maven/plugins/unleash/util/predicates/IsMatchingCoordinatesTest.java @@ -11,8 +11,12 @@ import com.itemis.maven.aether.ArtifactCoordinates; +import de.caroso.maven.plugins.unleash.util.predicates.IsMatchingCoordinates; import edu.emory.mathcs.backport.java.util.Arrays; +/** + * @author Carsten Rohde +*/ public class IsMatchingCoordinatesTest { @Test diff --git a/pom.xml b/pom.xml index 8104558..0f91e8f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,11 @@ 2.10.13-SNAPSHOT pom - An alternative release plugin for maven projects that tries to reduce the risk of failure during the release process as well as the number of builds and scm operations. This plugin shall provide a faster, more stable but also more customizable release process. + + An alternative release plugin for maven projects that tries to reduce the risk of failure during the release process as well as the number of builds and scm operations. This plugin shall provide a faster, more stable but also more customizable release process. + + + https://github.com/caroso-de/unleash-maven-plugin 2022 @@ -25,12 +29,6 @@ - - crohde - Carsten Rohde - caroso-de - https://github.com/caroso-de - shillner Stanley Hillner @@ -38,6 +36,12 @@ https://itemis.com/ 1 + + crohde + Carsten Rohde + caroso-de + https://github.com/caroso-de +