Fix for issue #2280; adds EmittedArtifact.getLastModified() which is used to set the mtime on files written to disk by the compiler.
The default implementation in the EmittedArtifact base class is concrete to avoid breaking changes and always returns the current time, which is consistent with the previous behavior.
Patch by: bobv
Review by: me
git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4250 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java b/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
index 96bc46b..6dc780f 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
@@ -53,6 +53,20 @@
throws UnableToCompleteException;
/**
+ * Returns the time, measured in milliseconds from the epoch, at which the
+ * Artifact was last modified. This will be used to set the last-modified
+ * timestamp on the files written to disk.
+ * <p>
+ * The default implementation always returns the current time. Subclasses
+ * should override this method to provide a type-appropriate value.
+ *
+ * @return the time at which the Artifact was last modified
+ */
+ public long getLastModified() {
+ return System.currentTimeMillis();
+ }
+
+ /**
* Returns the partial path within the output directory of the
* EmittedArtifact.
*/
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java b/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
index 5e93e34..dd9bafd 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/SyntheticArtifact.java
@@ -27,6 +27,7 @@
*/
public class SyntheticArtifact extends EmittedArtifact {
private final byte[] data;
+ private final long lastModified = System.currentTimeMillis();
SyntheticArtifact(Class<? extends Linker> linkerType, String partialPath,
byte[] data) {
@@ -40,4 +41,9 @@
throws UnableToCompleteException {
return new ByteArrayInputStream(data);
}
-}
\ No newline at end of file
+
+ @Override
+ public long getLastModified() {
+ return lastModified;
+ }
+}
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
index d520f33..c27a7af 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardGeneratedResource.java
@@ -20,30 +20,36 @@
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.GeneratedResource;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
/**
* The standard implementation of {@link GeneratedResource}.
*/
public class StandardGeneratedResource extends GeneratedResource {
- private final URL url;
+ private final File file;
public StandardGeneratedResource(Class<? extends Generator> generatorType,
- String partialPath, URL url) {
+ String partialPath, File file) {
super(StandardLinkerContext.class, generatorType, partialPath);
- this.url = url;
+ this.file = file;
}
@Override
public InputStream getContents(TreeLogger logger)
throws UnableToCompleteException {
try {
- return url.openStream();
+ return new FileInputStream(file);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Unable to open file", e);
throw new UnableToCompleteException();
}
}
+
+ @Override
+ public long getLastModified() {
+ return file.lastModified();
+ }
}
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
index 55518a5..04719cb 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
@@ -446,6 +446,7 @@
// assert !outFile.exists() : "Attempted to overwrite " +
// outFile.getPath();
Util.copy(artifactLogger, artifact.getContents(artifactLogger), outFile);
+ outFile.setLastModified(artifact.getLastModified());
}
}
diff --git a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardPublicResource.java b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardPublicResource.java
index 2a1a0bd..78431c3 100644
--- a/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardPublicResource.java
+++ b/dev/core/src/com/google/gwt/core/ext/linker/impl/StandardPublicResource.java
@@ -37,10 +37,13 @@
*/
private static final class SerializedPublicResource extends PublicResource {
private final byte[] data;
+ private final long lastModified;
- protected SerializedPublicResource(String partialPath, byte[] data) {
+ protected SerializedPublicResource(String partialPath, byte[] data,
+ long lastModified) {
super(StandardLinkerContext.class, partialPath);
this.data = data;
+ this.lastModified = lastModified;
}
@Override
@@ -48,6 +51,11 @@
throws UnableToCompleteException {
return new ByteArrayInputStream(data);
}
+
+ @Override
+ public long getLastModified() {
+ return lastModified;
+ }
}
private final Resource resource;
@@ -63,6 +71,11 @@
return resource.openContents();
}
+ @Override
+ public long getLastModified() {
+ return resource.getLastModified();
+ }
+
private Object writeReplace() {
if (resource instanceof Serializable) {
return this;
@@ -71,7 +84,8 @@
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Util.copy(resource.openContents(), baos);
- return new SerializedPublicResource(getPartialPath(), baos.toByteArray());
+ return new SerializedPublicResource(getPartialPath(), baos.toByteArray(),
+ getLastModified());
} catch (IOException e) {
throw new RuntimeException(e);
}