Provide better traces with invalid URLs 76/72476/1
authorStephen Kitt <skitt@redhat.com>
Thu, 26 Apr 2018 09:44:14 +0000 (11:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 30 May 2018 10:54:06 +0000 (12:54 +0200)
When a feature or bundle contains an invalid URL (or missing URL), the
resulting plugin error is rather inscrutable. This attempts to improve
the situation by indicating which feature is at fault.

Change-Id: If235349f5dcc6a73e5f77a97123feae43bc2eef2
Signed-off-by: Stephen Kitt <skitt@redhat.com>
(cherry picked from commit 158af99fbc1a3aa904a3f92852d51eb5c3c7ecb9)

karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java

index d196caefad0ccca8062348613900728a386c1acc..797efc5db8a91a3f06bf93f7e371c7e4fcd7081c 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.karaf.features.internal.model.ConfigFile;
 import org.apache.karaf.features.internal.model.Feature;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.ops4j.pax.url.mvn.internal.Parser;
@@ -191,7 +192,12 @@ public final class FeatureUtil {
     public static Set<String> bundlesToCoords(final List<Bundle> bundles) throws MalformedURLException {
         Set<String> result = new LinkedHashSet<>();
         for (Bundle bundle : bundles) {
-            result.add(toCoord(new URL(bundle.getLocation())));
+            try {
+                result.add(toCoord(new URL(bundle.getLocation())));
+            } catch (MalformedURLException e) {
+                LOG.error("Invalid URL {}", bundle.getLocation(), e);
+                throw e;
+            }
         }
         LOG.trace("bundlesToCoords({}) returns {}", bundles, result);
         return result;
@@ -202,16 +208,25 @@ public final class FeatureUtil {
      *
      * @param features The feature.
      * @return The artifact coordinates.
-     * @throws MalformedURLException if a URL is malformed.
+     * @throws MojoExecutionException if an error occurs during processing.
      */
-    public static Set<String> featuresToCoords(final Features features) throws MalformedURLException {
+    public static Set<String> featuresToCoords(final Features features) throws MojoExecutionException {
         Set<String> result = new LinkedHashSet<>();
         if (features.getRepository() != null) {
-            result.addAll(featuresRepositoryToCoords(features));
+            try {
+                result.addAll(featuresRepositoryToCoords(features));
+            } catch (MalformedURLException e) {
+                throw new MojoExecutionException("Feature " + features.getName() + " has an invalid repository URL", e);
+            }
         }
         if (features.getFeature() != null) {
             for (Feature feature : features.getFeature()) {
-                result.addAll(featureToCoords(feature));
+                try {
+                    result.addAll(featureToCoords(feature));
+                } catch (MalformedURLException e) {
+                    throw new MojoExecutionException("Feature " + feature.getName() + " in " + features.getName()
+                            + " contains an invalid or missing URL", e);
+                }
             }
         }
         LOG.trace("featuresToCoords({}) returns {}", features.getName(), result);
@@ -224,9 +239,9 @@ public final class FeatureUtil {
      *
      * @param features The features.
      * @return The artifact coordinates.
-     * @throws MalformedURLException if a URL is malformed.
+     * @throws MojoExecutionException if an error occurs during processing.
      */
-    public static Set<String> featuresToCoords(final Set<Features> features) throws MalformedURLException {
+    public static Set<String> featuresToCoords(final Set<Features> features) throws MojoExecutionException {
         Set<String> result = new LinkedHashSet<>();
         for (Features feature : features) {
             result.addAll(featuresToCoords(feature));