Migrating script generation onto java.io.File
This commit is contained in:
+14
-13
@@ -18,6 +18,7 @@ package org.jetbrains.jet.compiler.runner;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -29,15 +30,15 @@ public class KotlinModuleScriptGenerator {
|
||||
}
|
||||
|
||||
public interface DependencyProcessor {
|
||||
void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<String> paths);
|
||||
void processAnnotationRoots(@NotNull List<String> paths);
|
||||
void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files);
|
||||
void processAnnotationRoots(@NotNull List<File> files);
|
||||
}
|
||||
|
||||
public static CharSequence generateModuleScript(String moduleName,
|
||||
DependencyProvider dependencyProvider,
|
||||
List<String> sourceFilePaths,
|
||||
List<File> sourceFiles,
|
||||
boolean tests,
|
||||
final Set<String> directoriesToFilterOut) {
|
||||
final Set<File> directoriesToFilterOut) {
|
||||
final StringBuilder script = new StringBuilder();
|
||||
|
||||
if (tests) {
|
||||
@@ -51,31 +52,31 @@ public class KotlinModuleScriptGenerator {
|
||||
script.append("fun project() {\n");
|
||||
script.append(" module(\"" + moduleName + "\") {\n");
|
||||
|
||||
for (String sourceFile : sourceFilePaths) {
|
||||
script.append(" sources += \"" + sourceFile + "\"\n");
|
||||
for (File sourceFile : sourceFiles) {
|
||||
script.append(" sources += \"" + sourceFile.getPath() + "\"\n");
|
||||
}
|
||||
|
||||
dependencyProvider.processClassPath(new DependencyProcessor() {
|
||||
@Override
|
||||
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<String> paths) {
|
||||
public void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files) {
|
||||
script.append(" // " + sectionDescription + "\n");
|
||||
for (String path : paths) {
|
||||
if (directoriesToFilterOut.contains(path)) {
|
||||
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 += \"" + path + "\"\n");
|
||||
script.append(" classpath += \"" + file.getPath() + "\"\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processAnnotationRoots(@NotNull List<String> paths) {
|
||||
public void processAnnotationRoots(@NotNull List<File> files) {
|
||||
script.append(" // External annotations\n");
|
||||
for (String path : paths) {
|
||||
script.append(" annotationsPath += \"").append(path).append("\"\n");
|
||||
for (File file : files) {
|
||||
script.append(" annotationsPath += \"").append(file.getPath()).append("\"\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -141,21 +141,21 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
Module module,
|
||||
boolean tests, VirtualFile mainOutput, File outputDir
|
||||
) {
|
||||
ArrayList<String> sourceFilePaths = ContainerUtil.newArrayList(paths(files));
|
||||
List<File> sourceFiles = ContainerUtil.newArrayList(ioFiles(files));
|
||||
ModuleChunk chunk = new ModuleChunk((CompileContextEx)compileContext, moduleChunk, Collections.<Module, List<VirtualFile>>emptyMap());
|
||||
String moduleName = moduleChunk.getNodes().iterator().next().getName();
|
||||
String outputDirectoryForTests = path(compileContext.getModuleOutputDirectoryForTests(module));
|
||||
String moduleOutputDirectory = path(compileContext.getModuleOutputDirectory(module));
|
||||
File outputDirectoryForTests = ioFile(compileContext.getModuleOutputDirectoryForTests(module));
|
||||
File moduleOutputDirectory = ioFile(compileContext.getModuleOutputDirectory(module));
|
||||
|
||||
// Filter the output we are writing to
|
||||
Set<String> outputDirectoriesToFilter = ContainerUtil.newHashSet(outputDirectoryForTests);
|
||||
Set<File> outputDirectoriesToFilter = ContainerUtil.newHashSet(outputDirectoryForTests);
|
||||
if (!tests) {
|
||||
outputDirectoriesToFilter.add(moduleOutputDirectory);
|
||||
}
|
||||
CharSequence script = KotlinModuleScriptGenerator.generateModuleScript(
|
||||
moduleName,
|
||||
getDependencyProvider(chunk, tests, mainOutput),
|
||||
sourceFilePaths,
|
||||
sourceFiles,
|
||||
tests,
|
||||
outputDirectoriesToFilter
|
||||
);
|
||||
@@ -180,16 +180,16 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
@Override
|
||||
public void processClassPath(@NotNull KotlinModuleScriptGenerator.DependencyProcessor processor) {
|
||||
// TODO: have a bootclasspath in script API
|
||||
processor.processClassPathSection("Boot classpath", paths(chunk.getCompilationBootClasspathFiles()));
|
||||
processor.processClassPathSection("Boot classpath", ioFiles(chunk.getCompilationBootClasspathFiles()));
|
||||
|
||||
processor.processClassPathSection("Compilation classpath", paths(chunk.getCompilationClasspathFiles()));
|
||||
processor.processClassPathSection("Compilation classpath", ioFiles(chunk.getCompilationClasspathFiles()));
|
||||
|
||||
// This is for java files in same roots
|
||||
processor.processClassPathSection("Java classpath (for Java sources)", paths(Arrays.asList(chunk.getSourceRoots())));
|
||||
processor.processClassPathSection("Java classpath (for Java sources)", ioFiles(Arrays.asList(chunk.getSourceRoots())));
|
||||
|
||||
|
||||
if (tests && mainOutputPath != null) {
|
||||
processor.processClassPathSection("Main output", Arrays.asList(path(mainOutputPath)));
|
||||
processor.processClassPathSection("Main output", Arrays.asList(ioFile(mainOutputPath)));
|
||||
}
|
||||
|
||||
processor.processAnnotationRoots(getAnnotationRootPaths(chunk));
|
||||
@@ -197,25 +197,29 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
};
|
||||
}
|
||||
|
||||
private static List<String> getAnnotationRootPaths(ModuleChunk chunk) {
|
||||
List<String> annotationPaths = ContainerUtil.newArrayList();
|
||||
private static List<File> getAnnotationRootPaths(ModuleChunk chunk) {
|
||||
List<File> annotationPaths = ContainerUtil.newArrayList();
|
||||
for (Module module : chunk.getModules()) {
|
||||
for (VirtualFile file : OrderEnumerator.orderEntries(module).roots(AnnotationOrderRootType.getInstance()).getRoots()) {
|
||||
annotationPaths.add(path(file));
|
||||
annotationPaths.add(ioFile(file));
|
||||
}
|
||||
}
|
||||
return annotationPaths;
|
||||
}
|
||||
|
||||
private static Collection<String> paths(Collection<VirtualFile> files) {
|
||||
return ContainerUtil.map(files, new Function<VirtualFile, String>() {
|
||||
private static Collection<File> ioFiles(Collection<VirtualFile> files) {
|
||||
return ContainerUtil.map(files, new Function<VirtualFile, File>() {
|
||||
@Override
|
||||
public String fun(VirtualFile file) {
|
||||
return path(file);
|
||||
public File fun(VirtualFile file) {
|
||||
return ioFile(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static File ioFile(VirtualFile file) {
|
||||
return new File(path(file));
|
||||
}
|
||||
|
||||
private static String path(VirtualFile root) {
|
||||
String path = root.getPath();
|
||||
if (path.endsWith("!/")) {
|
||||
|
||||
Reference in New Issue
Block a user