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

Make sure the last modified timestamp is set correctly #2714

Merged
merged 1 commit into from
Aug 20, 2023
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 @@ -141,10 +141,7 @@ public boolean visitEnter(DependencyNode n) {
Map<DependencyNode, WrappedBundle> 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;
}
Expand Down Expand Up @@ -200,6 +197,7 @@ private static WrappedBundle getWrappedNode(DependencyNode node,
if (cached == null) {
List<ProcessingMessage> 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());
Expand All @@ -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!"));
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,34 +27,38 @@ public final class WrappedBundle {
private final DependencyNode node;
private final List<WrappedBundle> depends;
private final String instructionsKey;
private final Path file;
private final Jar jar;
private final Optional<Path> file;
private final Optional<Jar> jar;
private final List<ProcessingMessage> messages;

WrappedBundle(DependencyNode node, List<WrappedBundle> depends, String key, Path file, Jar jar,
List<ProcessingMessage> messages) {
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;
}

String getInstructionsKey() {
return instructionsKey;
}

Jar getJar() {
Optional<Jar> getJar() {
return jar;
}

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<Path> getFile() {
return file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading