diff --git a/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/MavenBundleWrapper.java b/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/MavenBundleWrapper.java index ce2374ceb9..3f8e97dc15 100644 --- a/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/MavenBundleWrapper.java +++ b/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/MavenBundleWrapper.java @@ -141,10 +141,7 @@ public boolean visitEnter(DependencyNode n) { Map visited = new HashMap<>(); WrappedBundle wrappedNode = getWrappedNode(node, instructionsLookup, visited); for (WrappedBundle wrap : visited.values()) { - Jar jar = wrap.getJar(); - if (jar != null) { - jar.close(); - } + wrap.getJar().ifPresent(jar -> jar.close()); } return wrappedNode; } @@ -200,6 +197,7 @@ private static WrappedBundle getWrappedNode(DependencyNode node, if (cached == null) { List messages = new ArrayList<>(); wrapArtifactFile.getParentFile().mkdirs(); + boolean hasErrors = false; try (Analyzer analyzer = new Analyzer(analyzerJar);) { analyzer.setProperty("mvnGroupId", artifact.getGroupId()); analyzer.setProperty("mvnArtifactId", artifact.getArtifactId()); @@ -213,7 +211,7 @@ private static WrappedBundle getWrappedNode(DependencyNode node, analyzer.setProperty(property, trimValue); } for (WrappedBundle dep : depends) { - Jar depJar = dep.getJar(); + Jar depJar = dep.getJar().orElse(null); if (depJar == null) { messages.add(new ProcessingMessage(artifact, Type.WARN, "Dependency " + dep.getNode().getDependency() + " was ignored!")); @@ -230,14 +228,21 @@ private static WrappedBundle getWrappedNode(DependencyNode node, continue; } messages.add(new ProcessingMessage(artifact, Type.ERROR, err)); + hasErrors = true; } for (String warn : analyzer.getWarnings()) { messages.add(new ProcessingMessage(artifact, Type.WARN, warn)); } } - wrapArtifactFile.setLastModified(originalFile.lastModified()); - visited.put(node, wrappedNode = new WrappedBundle(node, depends, key, wrapArtifactFile.toPath(), - new Jar(wrapArtifactFile), messages)); + if (hasErrors) { + Files.deleteIfExists(wrapArtifactFile.toPath()); + visited.put(node, wrappedNode = new WrappedBundle(node, depends, key, null, null, messages)); + } else { + Files.setLastModifiedTime(wrapArtifactFile.toPath(), + Files.getLastModifiedTime(originalFile.toPath())); + visited.put(node, wrappedNode = new WrappedBundle(node, depends, key, wrapArtifactFile.toPath(), + new Jar(wrapArtifactFile), messages)); + } } else { visited.put(node, wrappedNode = new WrappedBundle(node, depends, key, wrapArtifactFile.toPath(), new Jar(wrapArtifactFile), List.of())); @@ -301,7 +306,7 @@ public static boolean isOutdated(Path cacheFile, Path sourceFile) throws IOExcep if (Files.exists(cacheFile)) { FileTime sourceTimeStamp = Files.getLastModifiedTime(sourceFile); FileTime cacheTimeStamp = Files.getLastModifiedTime(cacheFile); - return sourceTimeStamp.compareTo(cacheTimeStamp) > 0; + return sourceTimeStamp.toMillis() > cacheTimeStamp.toMillis(); } return true; } diff --git a/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/WrappedBundle.java b/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/WrappedBundle.java index ed849c59d2..2175d9bd9c 100644 --- a/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/WrappedBundle.java +++ b/tycho-core/src/main/java/org/eclipse/m2e/pde/target/shared/WrappedBundle.java @@ -15,6 +15,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Stream; import org.eclipse.aether.graph.DependencyNode; @@ -26,8 +27,8 @@ public final class WrappedBundle { private final DependencyNode node; private final List depends; private final String instructionsKey; - private final Path file; - private final Jar jar; + private final Optional file; + private final Optional jar; private final List messages; WrappedBundle(DependencyNode node, List depends, String key, Path file, Jar jar, @@ -35,8 +36,8 @@ public final class WrappedBundle { this.node = node; this.depends = depends; this.instructionsKey = key; - this.file = file; - this.jar = jar; + this.file = Optional.ofNullable(file); + this.jar = Optional.ofNullable(jar); this.messages = messages; } @@ -44,7 +45,7 @@ String getInstructionsKey() { return instructionsKey; } - Jar getJar() { + Optional getJar() { return jar; } @@ -52,8 +53,12 @@ DependencyNode getNode() { return node; } - /** @return the location of the wrapped bundle's files */ - public Path getFile() { + /** + * + * @return an optional describing the wrapped bundle, or an empty optional if the bundle was not + * wrapped because of errors in the generation phase. + */ + public Optional getFile() { return file; } 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 9c74b24c1b..3427c5f389 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 @@ -226,7 +226,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies throw new RuntimeException(directErrors.stream().map(ProcessingMessage::message) .collect(Collectors.joining(System.lineSeparator()))); } - File file = wrappedBundle.getFile().toFile(); + File file = wrappedBundle.getFile().get().toFile(); BundleDescription description = BundlesAction.createBundleDescription(file); WrappedArtifact wrappedArtifact = new WrappedArtifact(file, mavenArtifact, mavenArtifact.getClassifier(), description.getSymbolicName(),