trigger module rebuild for newly-added module-info.java (IDEA-182378)

This commit is contained in:
Eugene Zhuravlev
2017-11-22 16:31:32 +01:00
parent 2581208c8b
commit 4d365d26cc
7 changed files with 48 additions and 1 deletions
@@ -0,0 +1,11 @@
Compiling files:
moduleA/src/module-info.java
End of files
Cleaning output files:
out/production/A/module-info.class
out/production/A/ppp/Main.class
End of files
Compiling files:
moduleA/src/module-info.java
moduleA/src/ppp/Main.java
End of files
@@ -0,0 +1,7 @@
package ppp;
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
}
}
@@ -710,7 +710,10 @@ public class Mappings {
}
void affectModule(ModuleRepr m, final Collection<File> affectedFiles) {
final Collection<File> depFiles = myClassToSourceFile.get(m.name);
Collection<File> depFiles = myMappings != null? myMappings.myClassToSourceFile.get(m.name) : null;
if (depFiles == null) {
depFiles = myClassToSourceFile.get(m.name);
}
if (depFiles != null) {
debug("Affecting module ", m.name);
affectedFiles.addAll(depFiles);
@@ -2350,6 +2353,9 @@ public class Mappings {
for (ModuleRepr moduleRepr : modulesDiff.added()) {
myDelta.addChangedClass(moduleRepr.name); // need this for integrate
// after module has been added, the whole target should be rebuilt
// because necessary 'require' directives may be missing from the newly added module-info file
myFuture.affectModule(moduleRepr, myAffectedFiles);
}
for (ModuleRepr removedModule : modulesDiff.removed()) {
@@ -30,6 +30,13 @@ public class Java9Test extends IncrementalTestCase {
return super.shouldRunTest();
}
public void testModuleInfoAdded() {
// expected result: the whole target is recompiled after the module-info.java file was newly added
// because necessary 'require' directives may be missing from the newly added module-info file
final BuildResult buildResult = doTest();
buildResult.assertSuccessful();
}
public void testRemoveModuleRequires() {
final BuildResult buildResult = doTest();
buildResult.assertFailed();
@@ -51,6 +51,7 @@ import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.java.*;
import org.jetbrains.jps.model.java.compiler.JavaCompilers;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration;
import org.jetbrains.jps.model.java.impl.JavaModuleIndexImpl;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.library.JpsTypedLibrary;
import org.jetbrains.jps.model.library.sdk.JpsSdk;
@@ -366,6 +367,13 @@ public abstract class JpsBuildTestCase extends UsefulTestCase {
catch (RebuildRequestedException | IOException e) {
throw new RuntimeException(e);
}
finally {
// the following code models module index reload after each make session
final JavaModuleIndex moduleIndex = JpsJavaExtensionService.getInstance().getJavaModuleIndex(descriptor.getProject(), descriptor.dataManager.getDataPaths().getDataStorageRoot());
if (moduleIndex instanceof JavaModuleIndexImpl) {
((JavaModuleIndexImpl)moduleIndex).dropCache();
}
}
return result;
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jps.model.ex.JpsElementBase;
import org.jetbrains.jps.model.java.JavaModuleIndex;
import org.jetbrains.jps.model.java.JavaSourceRootType;
@@ -132,4 +133,9 @@ public class JavaModuleIndexImpl extends JpsElementBase<JavaModuleIndexImpl> imp
}
return new JavaModuleIndexImpl(mapping);
}
@TestOnly
public void dropCache() {
myMapping.clear();
}
}