From: Stephen Kitt Date: Thu, 26 Apr 2018 09:44:14 +0000 (+0200) Subject: Provide better traces with invalid URLs X-Git-Tag: v3.1.2~20 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=01f7c5c53a5c943a0a15ef6fe556e8766e6bf296;p=odlparent.git Provide better traces with invalid URLs 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 (cherry picked from commit 158af99fbc1a3aa904a3f92852d51eb5c3c7ecb9) --- diff --git a/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java b/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java index d196caefa..797efc5db 100644 --- a/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java +++ b/karaf-plugin/src/main/java/org/opendaylight/odlparent/FeatureUtil.java @@ -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 bundlesToCoords(final List bundles) throws MalformedURLException { Set 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 featuresToCoords(final Features features) throws MalformedURLException { + public static Set featuresToCoords(final Features features) throws MojoExecutionException { Set 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 featuresToCoords(final Set features) throws MalformedURLException { + public static Set featuresToCoords(final Set features) throws MojoExecutionException { Set result = new LinkedHashSet<>(); for (Features feature : features) { result.addAll(featuresToCoords(feature));