Writing incrementalCache attribute to <modules> element of xml module script
This commit is contained in:
-14
@@ -42,9 +42,6 @@ public interface ModuleDescription {
|
||||
@NotNull
|
||||
List<String> getAnnotationsRoots();
|
||||
|
||||
@Nullable
|
||||
String getIncrementalCacheDir();
|
||||
|
||||
class Impl implements ModuleDescription {
|
||||
|
||||
private String name;
|
||||
@@ -52,7 +49,6 @@ public interface ModuleDescription {
|
||||
private final List<String> sources = new SmartList<String>();
|
||||
private final List<String> classpath = new SmartList<String>();
|
||||
private final List<String> annotations = new SmartList<String>();
|
||||
private String incrementalCacheDir;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
@@ -74,10 +70,6 @@ public interface ModuleDescription {
|
||||
annotations.add(path);
|
||||
}
|
||||
|
||||
public void setIncrementalCacheDir(String incrementalCacheDir) {
|
||||
this.incrementalCacheDir = incrementalCacheDir;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
@@ -108,12 +100,6 @@ public interface ModuleDescription {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getIncrementalCacheDir() {
|
||||
return incrementalCacheDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name +
|
||||
|
||||
+15
-11
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.cli.common.modules;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -47,7 +48,10 @@ public class ModuleXmlParser {
|
||||
public static final String EXTERNAL_ANNOTATIONS = "externalAnnotations";
|
||||
|
||||
@NotNull
|
||||
public static List<ModuleDescription> parse(@NotNull String xmlFile, @NotNull MessageCollector messageCollector) {
|
||||
public static Pair<List<ModuleDescription>, String> parseModuleDescriptionsAndIncrementalCacheDir(
|
||||
@NotNull String xmlFile,
|
||||
@NotNull MessageCollector messageCollector
|
||||
) {
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
stream = new FileInputStream(xmlFile);
|
||||
@@ -56,7 +60,7 @@ public class ModuleXmlParser {
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
MessageCollectorUtil.reportException(messageCollector, e);
|
||||
return Collections.emptyList();
|
||||
return Pair.create(Collections.<ModuleDescription>emptyList(), null);
|
||||
}
|
||||
finally {
|
||||
StreamUtil.closeStream(stream);
|
||||
@@ -64,7 +68,8 @@ public class ModuleXmlParser {
|
||||
}
|
||||
|
||||
private final MessageCollector messageCollector;
|
||||
private final List<ModuleDescription> result = new SmartList<ModuleDescription>();
|
||||
private String incrementalCacheDir;
|
||||
private final List<ModuleDescription> descriptions = new SmartList<ModuleDescription>();
|
||||
private DefaultHandler currentState;
|
||||
|
||||
private ModuleXmlParser(@NotNull MessageCollector messageCollector) {
|
||||
@@ -75,7 +80,7 @@ public class ModuleXmlParser {
|
||||
this.currentState = currentState;
|
||||
}
|
||||
|
||||
private List<ModuleDescription> parse(@NotNull InputStream xml) {
|
||||
private Pair<List<ModuleDescription>, String> parse(@NotNull InputStream xml) {
|
||||
try {
|
||||
setCurrentState(initial);
|
||||
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
@@ -86,7 +91,7 @@ public class ModuleXmlParser {
|
||||
return currentState;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
return Pair.create(descriptions, incrementalCacheDir);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
MessageCollectorUtil.reportException(messageCollector, e);
|
||||
@@ -97,7 +102,7 @@ public class ModuleXmlParser {
|
||||
catch (IOException e) {
|
||||
MessageCollectorUtil.reportException(messageCollector, e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return Pair.create(Collections.<ModuleDescription>emptyList(), null);
|
||||
}
|
||||
|
||||
private final DefaultHandler initial = new DefaultHandler() {
|
||||
@@ -107,6 +112,7 @@ public class ModuleXmlParser {
|
||||
throw createError(qName);
|
||||
}
|
||||
|
||||
incrementalCacheDir = attributes.getValue(INCREMENTAL_CACHE);
|
||||
setCurrentState(insideModules);
|
||||
}
|
||||
};
|
||||
@@ -120,8 +126,7 @@ public class ModuleXmlParser {
|
||||
|
||||
setCurrentState(new InsideModule(
|
||||
getAttribute(attributes, NAME, qName),
|
||||
getAttribute(attributes, OUTPUT_DIR, qName),
|
||||
attributes.getValue(INCREMENTAL_CACHE)
|
||||
getAttribute(attributes, OUTPUT_DIR, qName)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -136,12 +141,11 @@ public class ModuleXmlParser {
|
||||
private class InsideModule extends DefaultHandler {
|
||||
|
||||
private final ModuleDescription.Impl moduleDescription;
|
||||
private InsideModule(String name, String outputDir, String incrementalCacheDir) {
|
||||
private InsideModule(String name, String outputDir) {
|
||||
this.moduleDescription = new ModuleDescription.Impl();
|
||||
this.moduleDescription.setName(name);
|
||||
this.moduleDescription.setOutputDir(outputDir);
|
||||
this.moduleDescription.setIncrementalCacheDir(incrementalCacheDir);
|
||||
result.add(moduleDescription);
|
||||
descriptions.add(moduleDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -125,7 +125,11 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
|
||||
if (arguments.module != null) {
|
||||
MessageCollector sanitizedCollector = new FilteringMessageCollector(messageCollector, in(CompilerMessageSeverity.VERBOSE));
|
||||
List<Module> modules = CompileEnvironmentUtil.loadModuleDescriptions(paths, arguments.module, sanitizedCollector);
|
||||
CompileEnvironmentUtil.ModuleScriptData moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(
|
||||
paths, arguments.module, sanitizedCollector);
|
||||
if (moduleScript.getIncrementalCacheDir() != null) {
|
||||
configuration.put(JVMConfigurationKeys.INCREMENTAL_CACHE_BASE_DIR, new File(moduleScript.getIncrementalCacheDir()));
|
||||
}
|
||||
|
||||
if (outputDir != null) {
|
||||
messageCollector.report(CompilerMessageSeverity.WARNING, "The '-output' option is ignored because '-module' is specified",
|
||||
@@ -133,7 +137,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
}
|
||||
|
||||
File directory = new File(arguments.module).getAbsoluteFile().getParentFile();
|
||||
KotlinToJVMBytecodeCompiler.compileModules(configuration, modules,
|
||||
KotlinToJVMBytecodeCompiler.compileModules(configuration, moduleScript.getModules(),
|
||||
directory, jar,
|
||||
arguments.includeRuntime);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
@@ -80,32 +81,38 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Module> loadModuleDescriptions(KotlinPaths paths, String moduleDefinitionFile, MessageCollector messageCollector) {
|
||||
public static ModuleScriptData loadModuleDescriptions(KotlinPaths paths, String moduleDefinitionFile, MessageCollector messageCollector) {
|
||||
File file = new File(moduleDefinitionFile);
|
||||
if (!file.exists()) {
|
||||
messageCollector.report(ERROR, "Module definition file does not exist: " + moduleDefinitionFile, NO_LOCATION);
|
||||
return Collections.emptyList();
|
||||
return new ModuleScriptData(Collections.<Module>emptyList(), null);
|
||||
}
|
||||
String extension = FileUtilRt.getExtension(moduleDefinitionFile);
|
||||
if ("ktm".equalsIgnoreCase(extension)) {
|
||||
return loadModuleScript(paths, moduleDefinitionFile, messageCollector);
|
||||
}
|
||||
if ("xml".equalsIgnoreCase(extension)) {
|
||||
return ContainerUtil.map(
|
||||
ModuleXmlParser.parse(moduleDefinitionFile, messageCollector),
|
||||
Pair<List<ModuleDescription>, String> moduleDescriptionsAndIncrementalCacheDir =
|
||||
ModuleXmlParser.parseModuleDescriptionsAndIncrementalCacheDir(moduleDefinitionFile, messageCollector);
|
||||
List<ModuleDescription> moduleDescriptions = moduleDescriptionsAndIncrementalCacheDir.first;
|
||||
String incrementalCacheDir = moduleDescriptionsAndIncrementalCacheDir.second;
|
||||
List<Module> modules = ContainerUtil.map(
|
||||
moduleDescriptions,
|
||||
new Function<ModuleDescription, Module>() {
|
||||
@Override
|
||||
public Module fun(ModuleDescription description) {
|
||||
return new DescriptionToModuleAdapter(description);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
return new ModuleScriptData(modules, incrementalCacheDir);
|
||||
}
|
||||
messageCollector.report(ERROR, "Unknown module definition type: " + moduleDefinitionFile, NO_LOCATION);
|
||||
return Collections.emptyList();
|
||||
return new ModuleScriptData(Collections.<Module>emptyList(), null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Module> loadModuleScript(KotlinPaths paths, String moduleScriptFile, MessageCollector messageCollector) {
|
||||
private static ModuleScriptData loadModuleScript(KotlinPaths paths, String moduleScriptFile, MessageCollector messageCollector) {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
File runtimePath = paths.getRuntimePath();
|
||||
if (runtimePath.exists()) {
|
||||
@@ -143,7 +150,7 @@ public class CompileEnvironmentUtil {
|
||||
if (modules.isEmpty()) {
|
||||
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
||||
}
|
||||
return modules;
|
||||
return new ModuleScriptData(modules, null);
|
||||
}
|
||||
|
||||
private static List<Module> runDefineModules(KotlinPaths paths, ClassFileFactory factory) {
|
||||
@@ -324,7 +331,30 @@ public class CompileEnvironmentUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
static class DescriptionToModuleAdapter implements Module {
|
||||
public static class ModuleScriptData {
|
||||
@Nullable
|
||||
private final String incrementalCacheDir;
|
||||
|
||||
@NotNull
|
||||
public List<Module> getModules() {
|
||||
return modules;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getIncrementalCacheDir() {
|
||||
return incrementalCacheDir;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final List<Module> modules;
|
||||
|
||||
ModuleScriptData(@NotNull List<Module> modules, @Nullable String incrementalCacheDir) {
|
||||
this.incrementalCacheDir = incrementalCacheDir;
|
||||
this.modules = modules;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DescriptionToModuleAdapter implements Module {
|
||||
private final ModuleDescription description;
|
||||
|
||||
public DescriptionToModuleAdapter(ModuleDescription description) {
|
||||
@@ -360,10 +390,5 @@ public class CompileEnvironmentUtil {
|
||||
public List<String> getAnnotationsRoots() {
|
||||
return description.getAnnotationsRoots();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getIncrementalCacheDir() {
|
||||
return description.getIncrementalCacheDir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,14 +169,6 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.add(JVMConfigurationKeys.MODULE_IDS, module.getModuleName());
|
||||
}
|
||||
|
||||
Module anyModule = chunk.get(0);
|
||||
if (anyModule instanceof CompileEnvironmentUtil.DescriptionToModuleAdapter) {
|
||||
String incrementalCacheDir = ((CompileEnvironmentUtil.DescriptionToModuleAdapter) anyModule).getIncrementalCacheDir();
|
||||
if (incrementalCacheDir != null) {
|
||||
configuration.put(JVMConfigurationKeys.INCREMENTAL_CACHE_BASE_DIR, new File(incrementalCacheDir));
|
||||
}
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user