You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/03/23 05:43:54 UTC
[tomee-patch-plugin] 04/08: Log error if no artifacts match select
regex
This is an automated email from the ASF dual-hosted git repository.
dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-patch-plugin.git
commit 8729d529d4e30f10d7305c8a6f830e2bee795161
Author: David Blevins <da...@gmail.com>
AuthorDate: Mon Mar 22 18:33:39 2021 -0700
Log error if no artifacts match select regex
---
.../org/apache/tomee/patch/plugin/PatchMojo.java | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java b/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java
index 00afa53..d41ae88 100644
--- a/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java
+++ b/tomee-patch-plugin/src/main/java/org/apache/tomee/patch/plugin/PatchMojo.java
@@ -50,6 +50,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -259,9 +260,22 @@ public class PatchMojo extends AbstractMojo {
private List<Artifact> getPatchArtifacts() {
final Predicate<String> match = Pattern.compile(select).asPredicate();
- return Stream.of(getSourceArtifacts())
+ final Artifact[] available = getSourceArtifacts();
+
+ final List<Artifact> selected = Stream.of(available)
.filter(artifact -> match.test(artifact.getFile().getName()))
.collect(Collectors.toList());
+
+ if (selected.size() == 0) {
+ final String message = String.format("No artifacts matched expression '%s'. %s available artifacts:", select, available.length);
+ getLog().error(message);
+ Arrays.stream(available)
+ .map(artifact -> artifact.getFile().getName())
+ .forEach(s -> getLog().error(" - " + s));
+
+ throw new NoMatchingArtifactsException(select);
+ }
+ return selected;
}
private void compile(final File patchSourceDirectory, final List<File> jars) throws MojoExecutionException, CompilationFailureException {
@@ -452,4 +466,9 @@ public class PatchMojo extends AbstractMojo {
return artifactList.toArray(new Artifact[0]);
}
+ private static class NoMatchingArtifactsException extends RuntimeException {
+ public NoMatchingArtifactsException(final String select) {
+ super(String.format("No artifacts matched expression '%s'", select));
+ }
+ }
}