Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug for bad maven artifacts #4697

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading