From aeff7f2f27d29bf115091928270d44ad80a5faf6 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 12 Sep 2017 09:22:33 +0200 Subject: [PATCH] [KARAF-4417] Display a summary for the verify goal --- .../org/apache/karaf/tooling/VerifyMojo.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java index 5ed7522e58b..3d008c9d8c2 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java @@ -37,6 +37,7 @@ import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -331,20 +332,23 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException { for (String fmk : framework) { properties.put("feature.framework." + fmk, fmk); } - List failures = new ArrayList<>(); + Set successes = new LinkedHashSet<>(); + Set ignored = new LinkedHashSet<>(); + Map failures = new LinkedHashMap<>(); for (Feature feature : featuresToTest) { + String id = feature.getId(); try { - String id = feature.getName() + "/" + feature.getVersion(); verifyResolution(new CustomDownloadManager(resolver, executor), repositories, Collections.singleton(id), properties); + successes.add(id); getLog().info("Verification of feature " + id + " succeeded"); } catch (Exception e) { - if (e.getCause() instanceof ResolutionException) { + if (e.getCause() instanceof ResolutionException || !getLog().isDebugEnabled()) { getLog().warn(e.getMessage()); } else { getLog().warn(e); } - failures.add(e); + failures.put(id, e); if ("first".equals(fail)) { throw e; } @@ -353,9 +357,11 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException { Set ids = new LinkedHashSet<>(); ids.add(feature.getId()); ids.addAll(cond.getCondition()); + String cid = String.join("+", ids); try { verifyResolution(manager, repositories, ids, properties); - getLog().info("Verification of feature " + ids + " succeeded"); + successes.add(cid); + getLog().info("Verification of feature " + cid + " succeeded"); } catch (Exception e) { if (ignoreMissingConditions && e.getCause() instanceof ResolutionException) { boolean ignore = true; @@ -366,25 +372,31 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException { && cond.getCondition().contains(req.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE).toString())); } if (ignore) { - getLog().warn("Feature resolution failed for " + ids + ignored.add(cid); + getLog().warn("Feature resolution failed for " + cid + "\nMessage: " + e.getCause().getMessage()); continue; } } - if (e.getCause() instanceof ResolutionException) { + if (e.getCause() instanceof ResolutionException || !getLog().isDebugEnabled()) { getLog().warn(e.getMessage()); } else { getLog().warn(e); } - failures.add(e); + failures.put(cid, e); if ("first".equals(fail)) { throw e; } } } } + int nb = successes.size() + ignored.size() + failures.size(); + getLog().info("Features verified: " + nb + ", failures: " + failures.size() + ", ignored: " + ignored.size()); + if (!failures.isEmpty()) { + getLog().info("Failures: " + String.join(", ", failures.keySet())); + } if ("end".equals(fail) && !failures.isEmpty()) { - throw new MojoExecutionException("Verification failures", new MultiException("Verification failures", failures)); + throw new MojoExecutionException("Verification failures", new MultiException("Verification failures", new ArrayList<>(failures.values()))); } }