summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-05-03 14:54:11 (EDT)
committer pelder2007-05-03 14:54:11 (EDT)
commit518626889add7b1d9ab1369b252876ffe5c65fe1 (patch)
treebf6b6e6b7194a63c8788de6f076a789e177d6915
parent65efd4900bfacfec944d9602e3947f27c95cd532 (diff)
downloadorg.eclipse.jet-518626889add7b1d9ab1369b252876ffe5c65fe1.zip
org.eclipse.jet-518626889add7b1d9ab1369b252876ffe5c65fe1.tar.gz
org.eclipse.jet-518626889add7b1d9ab1369b252876ffe5c65fe1.tar.bz2
[163574] Only write compiler output if different from the existing output.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java
index da00516..51caa3d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/builder/WorkspaceCompiler.java
@@ -12,16 +12,19 @@
*
* </copyright>
*
- * $Id: WorkspaceCompiler.java,v 1.1 2007/04/04 14:59:33 pelder Exp $
+ * $Id: WorkspaceCompiler.java,v 1.2 2007/05/03 18:54:11 pelder Exp $
*/
package org.eclipse.jet.internal.builder;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -33,8 +36,10 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -236,7 +241,41 @@ public class WorkspaceCompiler implements IJETCompiler, ICompilerOutput, ITagLib
file.setCharset(encoding, new SubProgressMonitor(monitor, 1));
}
- file.setContents(new ByteArrayInputStream(contents.getBytes(file.getCharset())), true, false, new SubProgressMonitor(monitor, 1));
+ byte[] newBytes = contents.getBytes(file.getCharset());
+ // check if files exists
+ if(file.exists())
+ {
+ // get the old file...
+ boolean writeNewContents = true; // assume yes
+ try
+ {
+ InputStream inputStream = file.getContents();
+ byte [] oldBytes = new byte[inputStream.available()];
+ inputStream.read(oldBytes);
+ inputStream.close();
+ writeNewContents = !Arrays.equals(oldBytes, newBytes);
+ }
+ catch (IOException exception)
+ {
+ // continue, assuming that the content has changed.
+ }
+ if(!writeNewContents) {
+ return;
+ }
+ }
+
+ if(file.exists() && file.isReadOnly()) {
+ // play nicely with the team environment
+ // This call should get the files checked out from version control if the project is a 'team' project.
+ //
+ IStatus status = ResourcesPlugin.getWorkspace().validateEdit(new IFile [] { file }, null);
+ if (!status.isOK())
+ {
+ throw new CoreException(status);
+ }
+ }
+
+ file.setContents(new ByteArrayInputStream(newBytes), true, false, new SubProgressMonitor(monitor, 1));
file.setDerived(writeFilesAsDerived);
}
catch (UnsupportedEncodingException e)