forked from shillner/unleash-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#30 make contributions clearer in source code
- Loading branch information
Showing
6 changed files
with
114 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,16 +39,17 @@ | |
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; | ||
|
||
/** | ||
* Checks that none of the project modules has SNAPSHOT dependencies since this | ||
* would potentially lead to non-reproducible release artifacts. | ||
* | ||
* @author <a href="mailto:[email protected]">Stanley Hillner</a> | ||
* @author <a href="mailto:[email protected]">Carsten Rohde</a> | ||
* @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) | ||
|
54 changes: 29 additions & 25 deletions
54
...il/functions/GAVPatternToCoordinates.java → ...il/functions/GAVPatternToCoordinates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, ArtifactCoordinates> { | ||
|
||
@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 <a href="mailto:[email protected]">Carsten Rohde</a> | ||
*/ | ||
public class GAVPatternToCoordinates implements Function<String, ArtifactCoordinates> { | ||
|
||
@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]); | ||
} | ||
} | ||
|
||
} |
124 changes: 64 additions & 60 deletions
124
...til/predicates/IsMatchingCoordinates.java → ...til/predicates/IsMatchingCoordinates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ArtifactCoordinates> { | ||
|
||
private final Set<ArtifactCoordinates> referencePatterns; | ||
|
||
public IsMatchingCoordinates(List<String> someAllowedSnapshots) { | ||
List<String> 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 <a href="mailto:[email protected]">Carsten Rohde</a> | ||
*/ | ||
public class IsMatchingCoordinates implements Predicate<ArtifactCoordinates> { | ||
|
||
private final Set<ArtifactCoordinates> referencePatterns; | ||
|
||
public IsMatchingCoordinates(List<String> someAllowedSnapshots) { | ||
List<String> 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, "*"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,11 @@ | |
|
||
import com.itemis.maven.aether.ArtifactCoordinates; | ||
|
||
import de.caroso.maven.plugins.unleash.util.functions.GAVPatternToCoordinates; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Carsten Rohde</a> | ||
*/ | ||
public class GAVPatternToCoordinatesTest { | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <a href="mailto:[email protected]">Carsten Rohde</a> | ||
*/ | ||
public class IsMatchingCoordinatesTest { | ||
|
||
@Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters