-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration filter to narrow deployment
Adds a -df -deployFilterfile configuration that is a file path to load for telling the MavenRepositoryDeployer which GAVs to deploy (i.e. filter in). This file contains a groupId:artifactId:version:ext (patterns supported) per line, and is loaded into memory as a Set<Gav>. It implements the Object.equals method on Gav and matcher support, so that we can compare GAVs in order to know what to deploy. Only artifact references that exist in the file will be deployed. If the filter file is not specified, or doesnt exist, we do not filter at all. The matching logic is made to be multi-threaded, in case the filter file is large. References: #81 Signed-off-by: Samuel Dacanay <sam.dacanay@chainguard.dev>
- Loading branch information
Showing
12 changed files
with
529 additions
and
2 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
24 changes: 24 additions & 0 deletions
24
maven-repository-provisioner/src/main/java/com/simpligility/maven/GavMatcher.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.simpligility.maven; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.function.Supplier; | ||
|
||
public class GavMatcher implements Callable<Boolean>, Supplier<Boolean> { | ||
private final Gav gav; | ||
private final GavPattern pattern; | ||
|
||
public GavMatcher(Gav gav, GavPattern pattern) { | ||
this.gav = gav; | ||
this.pattern = pattern; | ||
} | ||
|
||
@Override | ||
public Boolean call() { | ||
return pattern.matches(gav); | ||
} | ||
|
||
@Override | ||
public Boolean get() { | ||
return call(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
maven-repository-provisioner/src/main/java/com/simpligility/maven/GavPattern.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.simpligility.maven; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class GavPattern { | ||
private final Pattern pattern; | ||
|
||
public GavPattern(Pattern pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
public boolean matches(Gav gav) { | ||
if (gav == null) { | ||
return false; | ||
} | ||
String gavString = | ||
gav.getGroupId() + ":" + gav.getArtifactId() + ":" + gav.getVersion() + ":" + gav.getPackaging(); | ||
return pattern.matcher(gavString).matches(); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...tory-provisioner/src/main/java/com/simpligility/maven/provisioner/GavMatcherExecutor.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.simpligility.maven.provisioner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import com.simpligility.maven.Gav; | ||
import com.simpligility.maven.GavMatcher; | ||
import com.simpligility.maven.GavPattern; | ||
|
||
public class GavMatcherExecutor implements AutoCloseable { | ||
private final ExecutorService executorService; | ||
|
||
public GavMatcherExecutor(int threadPoolSize) { | ||
this.executorService = Executors.newFixedThreadPool(threadPoolSize); | ||
} | ||
|
||
public List<CompletableFuture<Boolean>> evaluateGav(Gav gav, Set<GavPattern> patterns) { | ||
List<CompletableFuture<Boolean>> futures = new ArrayList<>(); | ||
for (GavPattern pattern : patterns) { | ||
CompletableFuture<Boolean> future = | ||
CompletableFuture.supplyAsync(new GavMatcher(gav, pattern), executorService); | ||
futures.add(future); | ||
} | ||
return futures; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
executorService.shutdown(); | ||
} | ||
} |
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
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
62 changes: 62 additions & 0 deletions
62
maven-repository-provisioner/src/test/java/com/simpligility/maven/GavMatcherTest.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.simpligility.maven; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class GavMatcherTest { | ||
|
||
@Test | ||
public void testCall_MatchingPattern() throws ExecutionException, InterruptedException { | ||
GavPattern pattern = new GavPattern(Pattern.compile("org\\.apache\\.maven\\.resolver:.*:.*:.*")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
GavMatcher matcher = new GavMatcher(gav, pattern); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
Future<Boolean> result = executor.submit(matcher); | ||
assertTrue(result.get()); | ||
executor.shutdown(); | ||
} | ||
|
||
@Test | ||
public void testCall_NonMatchingPattern() throws ExecutionException, InterruptedException { | ||
GavPattern pattern = new GavPattern(Pattern.compile("com\\.simpligility:.*:.*:.*")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
GavMatcher matcher = new GavMatcher(gav, pattern); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
Future<Boolean> result = executor.submit(matcher); | ||
assertFalse(result.get()); | ||
executor.shutdown(); | ||
} | ||
|
||
@Test | ||
public void testCall_EmptyPattern() throws ExecutionException, InterruptedException { | ||
GavPattern pattern = new GavPattern(Pattern.compile("")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
GavMatcher matcher = new GavMatcher(gav, pattern); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
Future<Boolean> result = executor.submit(matcher); | ||
assertFalse(result.get()); | ||
executor.shutdown(); | ||
} | ||
|
||
@Test | ||
public void testCall_NullGav() throws ExecutionException, InterruptedException { | ||
GavPattern pattern = new GavPattern(Pattern.compile("org\\.apache\\.maven\\.resolver:.*:.*:.*")); | ||
GavMatcher matcher = new GavMatcher(null, pattern); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
Future<Boolean> result = executor.submit(matcher); | ||
assertFalse(result.get()); | ||
executor.shutdown(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
maven-repository-provisioner/src/test/java/com/simpligility/maven/GavPatternTest.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.simpligility.maven; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class GavPatternTest { | ||
|
||
@Test | ||
public void testMatches_ValidPattern() { | ||
GavPattern pattern = new GavPattern(Pattern.compile("org\\.apache\\.maven\\.resolver:.*:.*:.*")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
assertTrue(pattern.matches(gav)); | ||
} | ||
|
||
@Test | ||
public void testMatches_InvalidPattern() { | ||
GavPattern pattern = new GavPattern(Pattern.compile("com\\.simpligility:.*:.*:.*")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
assertFalse(pattern.matches(gav)); | ||
} | ||
|
||
@Test | ||
public void testMatches_EmptyPattern() { | ||
GavPattern pattern = new GavPattern(Pattern.compile("")); | ||
Gav gav = new Gav("org.apache.maven.resolver", "artifactId", "version", "jar"); | ||
assertFalse(pattern.matches(gav)); | ||
} | ||
|
||
@Test | ||
public void testMatches_NullGav() { | ||
GavPattern pattern = new GavPattern(Pattern.compile("org\\.apache\\.maven\\.resolver:.*:.*:.*")); | ||
assertFalse(pattern.matches(null)); | ||
} | ||
} |
Oops, something went wrong.