Skip to content

Commit

Permalink
Improve debug for bad maven artifacts
Browse files Browse the repository at this point in the history
Currently if a dependency fails to be wrapped the user gets a quite
vague error message that don'T give a hint where the problem originates
and how to possibly solve it.

This now do the following:
- name the offender and the root artifact that require it
- add a hint to exclude the offending artifact
  • Loading branch information
laeubi committed Feb 7, 2025
1 parent 481f161 commit 4eff50e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies

String symbolicName;
String bundleVersion;
String debugString = asDebugString(mavenArtifact);
try {
File bundleLocation = mavenArtifact.getLocation();
BundleDescription bundleDescription = BundlesAction.createBundleDescription(bundleLocation);
Expand All @@ -196,12 +197,12 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
IInstallableUnit unit;
if (symbolicName == null) {
if (location.getMissingManifestStrategy() == MissingManifestStrategy.IGNORE) {
logger.info("Ignoring " + asDebugString(mavenArtifact)
logger.info("Ignoring " + debugString
+ " as it is not a bundle and MissingManifestStrategy is set to ignore for this location");
continue;
}
if (location.getMissingManifestStrategy() == MissingManifestStrategy.ERROR) {
throw new TargetDefinitionResolutionException("Artifact " + asDebugString(mavenArtifact)
throw new TargetDefinitionResolutionException("Artifact " + debugString
+ " is not a bundle and MissingManifestStrategy is set to error for this location");
}
try {
Expand All @@ -222,18 +223,23 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
.filter(msg -> msg.type() == ProcessingMessage.Type.ERROR).toList();
if (directErrors.isEmpty()) {
wrappedBundle.messages(true).map(ProcessingMessage::message)
.forEach(msg -> logger.warn(asDebugString(mavenArtifact) + ": " + msg));
.forEach(msg -> logger.warn(debugString + ": " + msg));
} else {
throw new RuntimeException(directErrors.stream().map(ProcessingMessage::message)
.collect(Collectors.joining(System.lineSeparator())));
String error = directErrors.stream().map(ProcessingMessage::message)
.collect(Collectors.joining(System.lineSeparator()));
String hint = String.format(
"You can exclude it by adding <exclude>%s</exclude> to your location",
debugString);
throw new RuntimeException(
String.format("Dependency %s of %s can not be wrapped: %s%s%s", debugString,
mavenDependency, error, System.lineSeparator().repeat(2), hint));
}
File file = wrappedBundle.getFile().get().toFile();
BundleDescription description = BundlesAction.createBundleDescription(file);
WrappedArtifact wrappedArtifact = new WrappedArtifact(file, mavenArtifact,
mavenArtifact.getClassifier(), description.getSymbolicName(),
description.getVersion().toString(), null);
logger.info(asDebugString(mavenArtifact)
+ " is wrapped as a bundle with bundle symbolic name "
logger.info(debugString + " is wrapped as a bundle with bundle symbolic name "
+ wrappedArtifact.getWrappedBsn());
logger.info(wrappedArtifact.getReferenceHint());
if (logger.isDebugEnabled()) {
Expand All @@ -252,7 +258,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
symbolicName = wrappedArtifact.getWrappedBsn();
bundleVersion = wrappedArtifact.getWrappedVersion();
} catch (Exception e) {
throw new TargetDefinitionResolutionException("Artifact " + asDebugString(mavenArtifact)
throw new TargetDefinitionResolutionException("Artifact " + debugString
+ " of location " + location + " could not be wrapped as a bundle", e);
}

Expand All @@ -261,13 +267,12 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
}
bundles.add(unit);
if (logger.isDebugEnabled()) {
logger.debug("MavenResolver: artifact " + asDebugString(mavenArtifact) + " at location "
+ bundleLocation + " resolves installable unit "
+ new VersionedId(unit.getId(), unit.getVersion()));
logger.debug("MavenResolver: artifact " + debugString + " at location " + bundleLocation
+ " resolves installable unit " + new VersionedId(unit.getId(), unit.getVersion()));
}
} catch (BundleException | IOException e) {
throw new TargetDefinitionResolutionException("Artifact " + asDebugString(mavenArtifact)
+ " of location " + location + " could not be read", e);
throw new TargetDefinitionResolutionException(
"Artifact " + debugString + " of location " + location + " could not be read", e);
}

if (includeSource) {
Expand Down Expand Up @@ -309,7 +314,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
}
}
} catch (DependencyResolutionException e) {
logger.warn("MavenResolver: source-artifact " + asDebugString(mavenArtifact)
logger.warn("MavenResolver: source-artifact " + debugString
+ ":sources cannot be resolved: " + e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public String toString() {
builder.append(getVersion());
builder.append(", ArtifactType = ");
builder.append(getArtifactType());
builder.append(", IncludeDependencyScope = ");
return builder.toString();
}

Expand Down

0 comments on commit 4eff50e

Please sign in to comment.