do not schedule unnecessary recompilation on duplicate-class check;

fix data loss in classToSourceFile mapping after moving top-level class from one file to another file
This commit is contained in:
Eugene Zhuravlev
2014-11-25 15:51:22 +01:00
parent 800dc9e422
commit 4d13fc7826
15 changed files with 116 additions and 2 deletions
@@ -0,0 +1,12 @@
Cleaning output files:
out/production/moveClassToAnotherRoot/pkg/A.class
End of files
Compiling files:
src2/pkg/A.java
End of files
Cleaning output files:
out/production/moveClassToAnotherRoot/pkg/Client.class
End of files
Compiling files:
src/pkg/Client.java
End of files
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectResources">
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA jdk" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/moveClassToAnotherRoot.iml" filepath="$PROJECT_DIR$/moveClassToAnotherRoot.iml" />
</modules>
</component>
</project>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src2" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA jdk" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="common" />
</component>
</module>
@@ -0,0 +1,4 @@
package pkg;
public class A {
public static void foo() {}
}
@@ -0,0 +1,6 @@
package pkg;
public class Client {
public static void main(String[] args) {
A.foo();
}
}
@@ -0,0 +1,4 @@
package pkg;
public class A {
public static void foo() {}
}
@@ -0,0 +1,9 @@
Cleaning output files:
out/production/MoveToplevelClassToAnotherFile/pkg/A.class
out/production/MoveToplevelClassToAnotherFile/pkg/B.class
out/production/MoveToplevelClassToAnotherFile/pkg/Local.class
End of files
Compiling files:
src/pkg/A.java
src/pkg/B.java
End of files
@@ -0,0 +1,9 @@
package pkg;
public class A {
}
class Local {
}
@@ -0,0 +1,5 @@
package pkg;
public class A {
}
@@ -0,0 +1,5 @@
package pkg;
public class B {
}
@@ -0,0 +1,9 @@
package pkg;
public class B {
}
class Local {
}
@@ -237,8 +237,15 @@ public class Mappings {
private void runPostPasses() {
final Set<Pair<ClassRepr, File>> deleted = myDeletedClasses;
if (deleted != null) {
final TIntHashSet added = new TIntHashSet();
for (ClassRepr aClass : myAddedClasses) {
added.add(aClass.name);
}
for (Pair<ClassRepr, File> pair : deleted) {
myChangedClasses.remove(pair.first.name);
final int deletedClassName = pair.first.name;
if (!added.contains(deletedClassName)) {
myChangedClasses.remove(deletedClassName);
}
}
}
for (Runnable pass = myPostPasses.poll(); pass != null; pass = myPostPasses.poll()) {
@@ -1864,7 +1871,7 @@ public class Mappings {
final Collection<File> currentSources = myClassToSourceFile.get(c.name);
final File currentlyMappedTo = currentSources != null && currentSources.size() == 1? currentSources.iterator().next() : null;
// only check, if exactly one file is mapped
if (currentlyMappedTo != null && !FileUtil.filesEqual(currentlyMappedTo, srcFile) && currentlyMappedTo.exists() && myFilter.belongsToCurrentTargetChunk(currentlyMappedTo)) {
if (currentlyMappedTo != null && !myCompiledFiles.contains(currentlyMappedTo) && !FileUtil.filesEqual(currentlyMappedTo, srcFile) && currentlyMappedTo.exists() && myFilter.belongsToCurrentTargetChunk(currentlyMappedTo)) {
// Same classes from different source files.
// Schedule for recompilation both to make possible 'duplicate sources' error evident
debug("Scheduling for recompilation duplicated sources: ", currentlyMappedTo.getPath() + "; " + srcFile.getPath());
@@ -150,4 +150,12 @@ public class CommonTest extends IncrementalTestCase {
doTestBuild(1).assertSuccessful();
}
public void testMoveToplevelClassToAnotherFile() throws Exception {
doTest();
}
public void testMoveClassToAnotherRoot() throws Exception {
doTest();
}
}