From 4eff50e42105c17b4f71ffa28ae2d58b9adc43b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 7 Feb 2025 18:12:39 +0100 Subject: [PATCH] Improve debug for bad maven artifacts 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 --- .../MavenTargetDefinitionContent.java | 33 +++++++++++-------- .../targetplatform/TargetDefinitionFile.java | 1 - 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java index f393b8fb4d..05ade02bcf 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/MavenTargetDefinitionContent.java @@ -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); @@ -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 { @@ -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 %s 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()) { @@ -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); } @@ -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) { @@ -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); } } diff --git a/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java b/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java index a026bbb9d2..99eba1b0a7 100644 --- a/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java +++ b/tycho-targetplatform/src/main/java/org/eclipse/tycho/targetplatform/TargetDefinitionFile.java @@ -242,7 +242,6 @@ public String toString() { builder.append(getVersion()); builder.append(", ArtifactType = "); builder.append(getArtifactType()); - builder.append(", IncludeDependencyScope = "); return builder.toString(); }