Modules.xml: add Java sources right after Kotlin sources
Java sources should appear before classpath dependencies because they should have higher priority if the same symbol is located in the module source and in the classpath. This is so because by default module source has the highest priority in IDEA except the JDK. Ideally this will be handled later by full support of modules in the compiler
This commit is contained in:
+1
@@ -27,6 +27,7 @@ public interface KotlinModuleDescriptionBuilder {
|
||||
String outputDir,
|
||||
DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
List<File> javaSourceRoots,
|
||||
boolean tests,
|
||||
Set<File> directoriesToFilterOut
|
||||
);
|
||||
|
||||
+9
-2
@@ -56,6 +56,7 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
|
||||
String outputDir,
|
||||
DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
List<File> javaSourceRoots,
|
||||
boolean tests,
|
||||
final Set<File> directoriesToFilterOut
|
||||
) {
|
||||
@@ -74,7 +75,7 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
|
||||
script.append(" sources += \"" + toSystemIndependentName(sourceFile.getPath()) + "\"\n");
|
||||
}
|
||||
|
||||
dependencyProvider.processClassPath(new DependencyProcessor() {
|
||||
DependencyProcessor processor = new DependencyProcessor() {
|
||||
@Override
|
||||
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files) {
|
||||
script.append(" // " + sectionDescription + "\n");
|
||||
@@ -97,7 +98,13 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
|
||||
script.append(" annotationsPath += \"").append(toSystemIndependentName(file.getPath())).append("\"\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!javaSourceRoots.isEmpty()) {
|
||||
processor.processClassPathSection("Java source roots", javaSourceRoots);
|
||||
}
|
||||
|
||||
dependencyProvider.processClassPath(processor);
|
||||
|
||||
script.append(" }\n");
|
||||
return this;
|
||||
|
||||
+10
-3
@@ -60,6 +60,7 @@ public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBui
|
||||
String outputDir,
|
||||
DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
List<File> javaSourceRoots,
|
||||
boolean tests,
|
||||
final Set<File> directoriesToFilterOut
|
||||
) {
|
||||
@@ -82,7 +83,7 @@ public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBui
|
||||
p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>");
|
||||
}
|
||||
|
||||
dependencyProvider.processClassPath(new DependencyProcessor() {
|
||||
DependencyProcessor processor = new DependencyProcessor() {
|
||||
@Override
|
||||
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files) {
|
||||
p.println("<!-- ", sectionDescription, " -->");
|
||||
@@ -110,10 +111,16 @@ public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBui
|
||||
public void processAnnotationRoots(@NotNull List<File> files) {
|
||||
p.println("<!-- External annotations -->");
|
||||
for (File file : files) {
|
||||
p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "= \"", getEscapedPath(file), "\"/>");
|
||||
p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!javaSourceRoots.isEmpty()) {
|
||||
processor.processClassPathSection("Java source roots", javaSourceRoots);
|
||||
}
|
||||
|
||||
dependencyProvider.processClassPath(processor);
|
||||
|
||||
closeTag(p, MODULE);
|
||||
return this;
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<module name="name" outputDir="output">
|
||||
<sources path="s1"/>
|
||||
<sources path="s2"/>
|
||||
<!-- Java source roots -->
|
||||
<classpath path="java"/>
|
||||
<!-- External annotations -->
|
||||
<externalAnnotations path= "a1/f1"/>
|
||||
<externalAnnotations path= "a2"/>
|
||||
<externalAnnotations path="a1/f1"/>
|
||||
<externalAnnotations path="a2"/>
|
||||
<!-- s1 -->
|
||||
<classpath path="cp1"/>
|
||||
<classpath path="cp2"/>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<sources path="s1"/>
|
||||
<sources path="s2"/>
|
||||
<!-- External annotations -->
|
||||
<externalAnnotations path= "a1/f1"/>
|
||||
<externalAnnotations path= "a2"/>
|
||||
<externalAnnotations path="a1/f1"/>
|
||||
<externalAnnotations path="a2"/>
|
||||
<!-- s1 -->
|
||||
<!-- Output directory, commented out -->
|
||||
<!--
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<sources path="s1"/>
|
||||
<sources path="s2"/>
|
||||
<!-- External annotations -->
|
||||
<externalAnnotations path= "a1/f1"/>
|
||||
<externalAnnotations path= "a2"/>
|
||||
<externalAnnotations path="a1/f1"/>
|
||||
<externalAnnotations path="a2"/>
|
||||
<!-- s1 -->
|
||||
<!-- Output directory, commented out -->
|
||||
<!--
|
||||
@@ -18,8 +18,8 @@
|
||||
<sources path="s12"/>
|
||||
<sources path="s22"/>
|
||||
<!-- External annotations -->
|
||||
<externalAnnotations path= "a12/f12"/>
|
||||
<externalAnnotations path= "a22"/>
|
||||
<externalAnnotations path="a12/f12"/>
|
||||
<externalAnnotations path="a22"/>
|
||||
<!-- s12 -->
|
||||
<!-- Output directory, commented out -->
|
||||
<!--
|
||||
|
||||
@@ -37,8 +37,10 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
}
|
||||
},
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.singletonList(new File("java")),
|
||||
false,
|
||||
Collections.<File>emptySet()).asText().toString();
|
||||
Collections.<File>emptySet()
|
||||
).asText().toString();
|
||||
JetTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/basic.xml"), actual);
|
||||
}
|
||||
|
||||
@@ -54,8 +56,10 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
}
|
||||
},
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.<File>emptyList(),
|
||||
false,
|
||||
Collections.singleton(new File("cp1"))).asText().toString();
|
||||
Collections.singleton(new File("cp1"))
|
||||
).asText().toString();
|
||||
JetTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/filtered.xml"), actual);
|
||||
}
|
||||
|
||||
@@ -72,8 +76,10 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
}
|
||||
},
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.<File>emptyList(),
|
||||
false,
|
||||
Collections.singleton(new File("cp1")));
|
||||
Collections.singleton(new File("cp1"))
|
||||
);
|
||||
builder.addModule(
|
||||
"name2",
|
||||
"output2",
|
||||
@@ -85,8 +91,10 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
}
|
||||
},
|
||||
Arrays.asList(new File("s12"), new File("s22")),
|
||||
Collections.<File>emptyList(),
|
||||
true,
|
||||
Collections.singleton(new File("cp12")));
|
||||
Collections.singleton(new File("cp12"))
|
||||
);
|
||||
String actual = builder.asText().toString();
|
||||
JetTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/multiple.xml"), actual);
|
||||
}
|
||||
|
||||
+5
-5
@@ -89,8 +89,9 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
builder.addModule(
|
||||
target.getId(),
|
||||
outputDir.getAbsolutePath(),
|
||||
getKotlinModuleDependencies(context, target),
|
||||
getKotlinModuleDependencies(target),
|
||||
moduleSources,
|
||||
findSourceRoots(context, target),
|
||||
target.isTests(),
|
||||
// this excludes the output directories from the class path, to be removed for true incremental compilation
|
||||
outputDirs
|
||||
@@ -115,12 +116,11 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
private static DependencyProvider getKotlinModuleDependencies(final CompileContext context, final ModuleBuildTarget target) {
|
||||
private static DependencyProvider getKotlinModuleDependencies(final ModuleBuildTarget target) {
|
||||
return new DependencyProvider() {
|
||||
@Override
|
||||
public void processClassPath(@NotNull DependencyProcessor processor) {
|
||||
processor.processClassPathSection("Classpath", findClassPathRoots(target));
|
||||
processor.processClassPathSection("Java Source Roots", findSourceRoots(context, target));
|
||||
processor.processAnnotationRoots(findAnnotationRoots(target));
|
||||
}
|
||||
};
|
||||
@@ -132,9 +132,9 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<File> findSourceRoots(@NotNull CompileContext context, @NotNull ModuleBuildTarget target) {
|
||||
private static List<File> findSourceRoots(@NotNull CompileContext context, @NotNull ModuleBuildTarget target) {
|
||||
List<JavaSourceRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
|
||||
Collection<File> result = ContainerUtil.newArrayList();
|
||||
List<File> result = ContainerUtil.newArrayList();
|
||||
for (JavaSourceRootDescriptor root : roots) {
|
||||
File file = root.getRootFile();
|
||||
if (file.exists()) {
|
||||
|
||||
Reference in New Issue
Block a user