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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -29,15 +30,15 @@ public class KotlinModuleScriptGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface DependencyProcessor {
|
public interface DependencyProcessor {
|
||||||
void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<String> paths);
|
void processClassPathSection(@NotNull String sectionDescription, @NotNull Collection<File> files);
|
||||||
void processAnnotationRoots(@NotNull List<String> paths);
|
void processAnnotationRoots(@NotNull List<File> files);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence generateModuleScript(String moduleName,
|
public static CharSequence generateModuleScript(String moduleName,
|
||||||
DependencyProvider dependencyProvider,
|
DependencyProvider dependencyProvider,
|
||||||
List<String> sourceFilePaths,
|
List<File> sourceFiles,
|
||||||
boolean tests,
|
boolean tests,
|
||||||
final Set<String> directoriesToFilterOut) {
|
final Set<File> directoriesToFilterOut) {
|
||||||
final StringBuilder script = new StringBuilder();
|
final StringBuilder script = new StringBuilder();
|
||||||
|
|
||||||
if (tests) {
|
if (tests) {
|
||||||
@@ -51,31 +52,31 @@ public class KotlinModuleScriptGenerator {
|
|||||||
script.append("fun project() {\n");
|
script.append("fun project() {\n");
|
||||||
script.append(" module(\"" + moduleName + "\") {\n");
|
script.append(" module(\"" + moduleName + "\") {\n");
|
||||||
|
|
||||||
for (String sourceFile : sourceFilePaths) {
|
for (File sourceFile : sourceFiles) {
|
||||||
script.append(" sources += \"" + sourceFile + "\"\n");
|
script.append(" sources += \"" + sourceFile.getPath() + "\"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyProvider.processClassPath(new DependencyProcessor() {
|
dependencyProvider.processClassPath(new DependencyProcessor() {
|
||||||
@Override
|
@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");
|
script.append(" // " + sectionDescription + "\n");
|
||||||
for (String path : paths) {
|
for (File file : files) {
|
||||||
if (directoriesToFilterOut.contains(path)) {
|
if (directoriesToFilterOut.contains(file)) {
|
||||||
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
|
// 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
|
// 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.
|
// 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(" // Output directory, commented out\n");
|
||||||
script.append(" // ");
|
script.append(" // ");
|
||||||
}
|
}
|
||||||
script.append(" classpath += \"" + path + "\"\n");
|
script.append(" classpath += \"" + file.getPath() + "\"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processAnnotationRoots(@NotNull List<String> paths) {
|
public void processAnnotationRoots(@NotNull List<File> files) {
|
||||||
script.append(" // External annotations\n");
|
script.append(" // External annotations\n");
|
||||||
for (String path : paths) {
|
for (File file : files) {
|
||||||
script.append(" annotationsPath += \"").append(path).append("\"\n");
|
script.append(" annotationsPath += \"").append(file.getPath()).append("\"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -141,21 +141,21 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
Module module,
|
Module module,
|
||||||
boolean tests, VirtualFile mainOutput, File outputDir
|
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());
|
ModuleChunk chunk = new ModuleChunk((CompileContextEx)compileContext, moduleChunk, Collections.<Module, List<VirtualFile>>emptyMap());
|
||||||
String moduleName = moduleChunk.getNodes().iterator().next().getName();
|
String moduleName = moduleChunk.getNodes().iterator().next().getName();
|
||||||
String outputDirectoryForTests = path(compileContext.getModuleOutputDirectoryForTests(module));
|
File outputDirectoryForTests = ioFile(compileContext.getModuleOutputDirectoryForTests(module));
|
||||||
String moduleOutputDirectory = path(compileContext.getModuleOutputDirectory(module));
|
File moduleOutputDirectory = ioFile(compileContext.getModuleOutputDirectory(module));
|
||||||
|
|
||||||
// Filter the output we are writing to
|
// Filter the output we are writing to
|
||||||
Set<String> outputDirectoriesToFilter = ContainerUtil.newHashSet(outputDirectoryForTests);
|
Set<File> outputDirectoriesToFilter = ContainerUtil.newHashSet(outputDirectoryForTests);
|
||||||
if (!tests) {
|
if (!tests) {
|
||||||
outputDirectoriesToFilter.add(moduleOutputDirectory);
|
outputDirectoriesToFilter.add(moduleOutputDirectory);
|
||||||
}
|
}
|
||||||
CharSequence script = KotlinModuleScriptGenerator.generateModuleScript(
|
CharSequence script = KotlinModuleScriptGenerator.generateModuleScript(
|
||||||
moduleName,
|
moduleName,
|
||||||
getDependencyProvider(chunk, tests, mainOutput),
|
getDependencyProvider(chunk, tests, mainOutput),
|
||||||
sourceFilePaths,
|
sourceFiles,
|
||||||
tests,
|
tests,
|
||||||
outputDirectoriesToFilter
|
outputDirectoriesToFilter
|
||||||
);
|
);
|
||||||
@@ -180,16 +180,16 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
@Override
|
@Override
|
||||||
public void processClassPath(@NotNull KotlinModuleScriptGenerator.DependencyProcessor processor) {
|
public void processClassPath(@NotNull KotlinModuleScriptGenerator.DependencyProcessor processor) {
|
||||||
// TODO: have a bootclasspath in script API
|
// 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
|
// 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) {
|
if (tests && mainOutputPath != null) {
|
||||||
processor.processClassPathSection("Main output", Arrays.asList(path(mainOutputPath)));
|
processor.processClassPathSection("Main output", Arrays.asList(ioFile(mainOutputPath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
processor.processAnnotationRoots(getAnnotationRootPaths(chunk));
|
processor.processAnnotationRoots(getAnnotationRootPaths(chunk));
|
||||||
@@ -197,25 +197,29 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getAnnotationRootPaths(ModuleChunk chunk) {
|
private static List<File> getAnnotationRootPaths(ModuleChunk chunk) {
|
||||||
List<String> annotationPaths = ContainerUtil.newArrayList();
|
List<File> annotationPaths = ContainerUtil.newArrayList();
|
||||||
for (Module module : chunk.getModules()) {
|
for (Module module : chunk.getModules()) {
|
||||||
for (VirtualFile file : OrderEnumerator.orderEntries(module).roots(AnnotationOrderRootType.getInstance()).getRoots()) {
|
for (VirtualFile file : OrderEnumerator.orderEntries(module).roots(AnnotationOrderRootType.getInstance()).getRoots()) {
|
||||||
annotationPaths.add(path(file));
|
annotationPaths.add(ioFile(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return annotationPaths;
|
return annotationPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<String> paths(Collection<VirtualFile> files) {
|
private static Collection<File> ioFiles(Collection<VirtualFile> files) {
|
||||||
return ContainerUtil.map(files, new Function<VirtualFile, String>() {
|
return ContainerUtil.map(files, new Function<VirtualFile, File>() {
|
||||||
@Override
|
@Override
|
||||||
public String fun(VirtualFile file) {
|
public File fun(VirtualFile file) {
|
||||||
return path(file);
|
return ioFile(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File ioFile(VirtualFile file) {
|
||||||
|
return new File(path(file));
|
||||||
|
}
|
||||||
|
|
||||||
private static String path(VirtualFile root) {
|
private static String path(VirtualFile root) {
|
||||||
String path = root.getPath();
|
String path = root.getPath();
|
||||||
if (path.endsWith("!/")) {
|
if (path.endsWith("!/")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user