Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java7
-rw-r--r--org.eclipse.jdt.core/buildnotes_jdt-core.html2
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java23
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java55
4 files changed, 48 insertions, 39 deletions
diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java
index 003ee124da..8030ea16e5 100644
--- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java
+++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java
@@ -67,9 +67,12 @@ public class ExecutionTests extends Tests {
incrementalBuild(projectPath);
expectingOnlyProblemsFor(helloPath);
executeClass(projectPath, "p1.Hello", "",
- "Unresolved compilation problem: \n" +
+ "java.lang.Error: Unresolved compilation problem: \n" +
" Syntax error on token \"}\", \"++\", \"--\" expected\n" +
- "\r\n"
+ "\r\n"+
+ " at java.lang.reflect.Constructor.newInstance(Native Method)\r\n" +
+ " at p1.Hello.main(Hello.java:5)\r\n" +
+ "Exception in thread \"main\" "
);
}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index 1c106b6366..0853fe8b61 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -19,6 +19,8 @@ What's new in this drop</h2>
</ul>
<h3>Problem Reports Fixed</h3>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=21606">21606</a>
+ImageBuilder deletes & adds rather than overwriting
<h3>Problem Reports Closed</h3>
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=21556">21556</a>
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
index b2df367f36..09fe0f1122 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
@@ -381,10 +381,8 @@ protected void updateProblemsFor(String sourceLocation, CompilationResult result
}
protected char[] writeClassFile(ClassFile classFile, boolean isSecondaryType) throws CoreException {
- // Before writing out the class file, compare it to the previous file
- // If structural changes occured then add dependent source files
String fileName = new String(classFile.fileName()); // the qualified type name "p1/p2/A"
- IPath filePath = new Path(fileName);
+ IPath filePath = new Path(fileName);
IContainer container = outputFolder;
if (filePath.segmentCount() > 1) {
container = getOutputFolder(filePath.removeLastSegments(1));
@@ -392,21 +390,16 @@ protected char[] writeClassFile(ClassFile classFile, boolean isSecondaryType) th
}
IFile file = container.getFile(filePath.addFileExtension(JavaBuilder.CLASS_EXTENSION));
- byte[] bytes = classFile.getBytes();
- if (writeClassFileCheck(file, fileName, bytes, isSecondaryType)) {
- if (JavaBuilder.DEBUG)
- System.out.println("Writing class file " + file.getName());//$NON-NLS-1$
- file.create(new ByteArrayInputStream(bytes), IResource.FORCE, null);
- file.setDerived(true);
- } else if (JavaBuilder.DEBUG) {
- System.out.println("Skipped over unchanged class file " + file.getName());//$NON-NLS-1$
- }
+ writeClassFileBytes(classFile.getBytes(), file, fileName, isSecondaryType);
// answer the name of the class file as in Y or Y$M
return filePath.lastSegment().toCharArray();
}
-protected boolean writeClassFileCheck(IFile file, String fileName, byte[] bytes, boolean isSecondaryType) throws CoreException {
- // In Incremental mode, compare the bytes against the previous file for structural changes
- return true;
+protected void writeClassFileBytes(byte[] bytes, IFile file, String qualifiedFileName, boolean isSecondaryType) throws CoreException {
+ // Default implementation just writes out the bytes for the new class file...
+ if (JavaBuilder.DEBUG)
+ System.out.println("Writing new class file " + file.getName());//$NON-NLS-1$
+ file.create(new ByteArrayInputStream(bytes), IResource.FORCE, null);
+ file.setDerived(true);
}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
index d775251f2d..84a685a57f 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java
@@ -19,6 +19,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.*;
import org.eclipse.jdt.internal.compiler.util.CharOperation;
import org.eclipse.jdt.internal.core.Util;
+import java.io.*;
import java.util.*;
/**
@@ -453,6 +454,27 @@ protected void finishedWith(String sourceLocation, CompilationResult result, cha
super.finishedWith(sourceLocation, result, mainTypeName, definedTypeNames, duplicateTypeNames);
}
+protected boolean isClassFileChanged(IFile file, String fileName, byte[] newBytes) throws CoreException {
+ try {
+ byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
+ notEqual : if (newBytes.length == oldBytes.length) {
+ for (int i = newBytes.length; --i >= 0;)
+ if (newBytes[i] != oldBytes[i]) break notEqual;
+ return false; // bytes are identical so skip them
+ }
+ ClassFileReader reader = new ClassFileReader(oldBytes, file.getLocation().toString().toCharArray());
+ // ignore local types since they're only visible inside a single method
+ if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
+ if (JavaBuilder.DEBUG)
+ System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
+ addDependentsOf(new Path(fileName), true);
+ }
+ } catch (ClassFormatException e) {
+ addDependentsOf(new Path(fileName), true);
+ }
+ return true;
+}
+
protected void removeClassFile(IPath typePath) throws CoreException {
if (typePath.lastSegment().indexOf('$') == -1) { // is not a nested type
newState.removeTypeLocation(typePath.toString());
@@ -501,33 +523,22 @@ protected void updateProblemsFor(String sourceLocation, CompilationResult result
storeProblemsFor(resource, problems);
}
-protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes, boolean isSecondaryType) throws CoreException {
+protected void writeClassFileBytes(byte[] bytes, IFile file, String qualifiedFileName, boolean isSecondaryType) throws CoreException {
// Before writing out the class file, compare it to the previous file
// If structural changes occured then add dependent source files
if (file.exists()) {
- try {
- byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
- notEqual : if (newBytes.length == oldBytes.length) {
- for (int i = newBytes.length; --i >= 0;)
- if (newBytes[i] != oldBytes[i]) break notEqual;
- return false; // bytes are identical so skip them
- }
- ClassFileReader reader = new ClassFileReader(oldBytes, file.getLocation().toString().toCharArray());
- // ignore local types since they're only visible inside a single method
- if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
- if (JavaBuilder.DEBUG)
- System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
- addDependentsOf(new Path(fileName), true);
- }
- } catch (ClassFormatException e) {
- addDependentsOf(new Path(fileName), true);
+ if (isClassFileChanged(file, qualifiedFileName, bytes)) {
+ if (JavaBuilder.DEBUG)
+ System.out.println("Writing changed class file " + file.getName());//$NON-NLS-1$
+ file.setContents(new ByteArrayInputStream(bytes), true, false, null);
+ } else if (JavaBuilder.DEBUG) {
+ System.out.println("Skipped over unchanged class file " + file.getName());//$NON-NLS-1$
}
-
- file.delete(IResource.FORCE, null);
- } else if (isSecondaryType) {
- addDependentsOf(new Path(fileName), true); // new secondary type
+ } else {
+ if (isSecondaryType)
+ addDependentsOf(new Path(qualifiedFileName), true); // new secondary type
+ super.writeClassFileBytes(bytes, file, qualifiedFileName, isSecondaryType);
}
- return true;
}
public String toString() {

Back to the top