Simplify code in module script/xml generation

Pass classpath and annotation roots explicitly instead of wrapped in a callback
This commit is contained in:
Alexander Udalov
2015-01-22 17:16:06 +03:00
parent fa2116040e
commit 3ea59117ac
8 changed files with 97 additions and 134 deletions
@@ -25,21 +25,13 @@ public interface KotlinModuleDescriptionBuilder {
KotlinModuleDescriptionBuilder addModule(
String moduleName,
String outputDir,
DependencyProvider dependencyProvider,
List<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
Set<File> directoriesToFilterOut
);
CharSequence asText();
interface DependencyProvider {
void processClassPath(DependencyProcessor processor);
}
interface DependencyProcessor {
void processClassPathSection(String sectionDescription, Collection<File> files);
void processAnnotationRoots(List<File> files);
}
}
@@ -54,11 +54,12 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
public KotlinModuleDescriptionBuilder addModule(
String moduleName,
String outputDir,
DependencyProvider dependencyProvider,
List<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
final Set<File> directoriesToFilterOut
Set<File> directoriesToFilterOut
) {
assert !done : "Already done";
@@ -75,41 +76,42 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
script.append(" sources += \"" + toSystemIndependentName(sourceFile.getPath()) + "\"\n");
}
DependencyProcessor processor = new DependencyProcessor() {
@Override
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files) {
script.append(" // " + sectionDescription + "\n");
for (File file : files) {
if (directoriesToFilterOut.contains(file)) {
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
// removed in the sources, it may still be there in binaries. Thus, we delete these entries from the classpath.
script.append(" // Output directory, commented out\n");
script.append(" // ");
}
script.append(" classpath += \"" + toSystemIndependentName(file.getPath()) + "\"\n");
}
}
@Override
public void processAnnotationRoots(@NotNull List<File> files) {
script.append(" // External annotations\n");
for (File file : files) {
script.append(" annotationsPath += \"").append(toSystemIndependentName(file.getPath())).append("\"\n");
}
}
};
if (!javaSourceRoots.isEmpty()) {
processor.processClassPathSection("Java source roots", javaSourceRoots);
processClassPathSection("Java source roots", javaSourceRoots, directoriesToFilterOut);
}
dependencyProvider.processClassPath(processor);
processClassPathSection("Classpath", classpathRoots, directoriesToFilterOut);
processAnnotationRoots(annotationRoots);
script.append(" }\n");
return this;
}
private void processClassPathSection(
@NotNull String sectionDescription,
@NotNull Collection<File> files,
@NotNull Set<File> directoriesToFilterOut
) {
script.append(" // " + sectionDescription + "\n");
for (File file : files) {
if (directoriesToFilterOut.contains(file)) {
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
// removed in the sources, it may still be there in binaries. Thus, we delete these entries from the classpath.
script.append(" // Output directory, commented out\n");
script.append(" // ");
}
script.append(" classpath += \"" + toSystemIndependentName(file.getPath()) + "\"\n");
}
}
private void processAnnotationRoots(@NotNull List<File> files) {
script.append(" // External annotations\n");
for (File file : files) {
script.append(" annotationsPath += \"").append(toSystemIndependentName(file.getPath())).append("\"\n");
}
}
@Override
public CharSequence asText() {
if (!done) {
@@ -120,5 +122,4 @@ public class KotlinModuleScriptBuilderFactory implements KotlinModuleDescription
return script;
}
}
}
@@ -58,11 +58,12 @@ public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBui
public KotlinModuleDescriptionBuilder addModule(
String moduleName,
String outputDir,
DependencyProvider dependencyProvider,
List<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
final Set<File> directoriesToFilterOut
Set<File> directoriesToFilterOut
) {
assert !done : "Already done";
@@ -83,49 +84,50 @@ public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBui
p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>");
}
DependencyProcessor processor = new DependencyProcessor() {
@Override
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files) {
p.println("<!-- ", sectionDescription, " -->");
for (File file : files) {
boolean isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.ENABLED;
if (isOutput) {
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
// removed in the sources, it may still be there in binaries. Thus, we delete these entries from the classpath.
p.println("<!-- Output directory, commented out -->");
p.println("<!-- ");
p.pushIndent();
}
p.println("<", CLASSPATH, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
if (isOutput) {
p.popIndent();
p.println("-->");
}
}
}
@Override
public void processAnnotationRoots(@NotNull List<File> files) {
p.println("<!-- External annotations -->");
for (File file : files) {
p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
}
}
};
if (!javaSourceRoots.isEmpty()) {
processor.processClassPathSection("Java source roots", javaSourceRoots);
processClassPathSection("Java source roots", javaSourceRoots, directoriesToFilterOut);
}
dependencyProvider.processClassPath(processor);
processClassPathSection("Classpath", classpathRoots, directoriesToFilterOut);
processAnnotationRoots(annotationRoots);
closeTag(p, MODULE);
return this;
}
private void processClassPathSection(
@NotNull String sectionDescription,
@NotNull Collection<File> files,
@NotNull Set<File> directoriesToFilterOut
) {
p.println("<!-- ", sectionDescription, " -->");
for (File file : files) {
boolean isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.ENABLED;
if (isOutput) {
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
// removed in the sources, it may still be there in binaries. Thus, we delete these entries from the classpath.
p.println("<!-- Output directory, commented out -->");
p.println("<!-- ");
p.pushIndent();
}
p.println("<", CLASSPATH, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
if (isOutput) {
p.popIndent();
p.println("-->");
}
}
}
private void processAnnotationRoots(@NotNull List<File> files) {
p.println("<!-- External annotations -->");
for (File file : files) {
p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
}
}
@Override
public CharSequence asText() {
if (!done) {