Skip to content

Commit

Permalink
#30 make contributions clearer in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
caroso-de committed Feb 21, 2022
1 parent 8949e4d commit 45b1d9f
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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]);
}
}

}
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, "*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<version>2.10.13-SNAPSHOT</version>
<packaging>pom</packaging>

<description>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.</description>
<description>
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.
</description>


<url>https://github.com/caroso-de/unleash-maven-plugin</url>
<inceptionYear>2022</inceptionYear>

Expand All @@ -25,19 +29,19 @@
</licenses>

<developers>
<developer>
<id>crohde</id>
<name>Carsten Rohde</name>
<organization>caroso-de</organization>
<organizationUrl>https://github.com/caroso-de</organizationUrl>
</developer>
<developer>
<id>shillner</id>
<name>Stanley Hillner</name>
<organization>itemis AG</organization>
<organizationUrl>https://itemis.com/</organizationUrl>
<timezone>1</timezone>
</developer>
<developer>
<id>crohde</id>
<name>Carsten Rohde</name>
<organization>caroso-de</organization>
<organizationUrl>https://github.com/caroso-de</organizationUrl>
</developer>
</developers>

<scm>
Expand Down

0 comments on commit 45b1d9f

Please sign in to comment.