Drop module "ktm" scripts and support java source roots in "xml" modules
Drop kotlin.modules package from runtime Move adapted classes into compiler Unsupport files with "ktm" extension Delete code for loading module scripts Drop tests for module scripts Separate section for java source roots in xml script generator/parser
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.modules
|
||||
|
||||
public trait Module {
|
||||
public fun getModuleName(): String
|
||||
|
||||
public fun getOutputDirectory(): String
|
||||
|
||||
public fun getSourceFiles(): List<String>
|
||||
|
||||
public fun getClasspathRoots(): List<String>
|
||||
|
||||
public fun getAnnotationsRoots(): List<String>
|
||||
|
||||
public fun getJavaSourceRoots(): List<String>
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.modules
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public class ModuleBuilder(private val name: String, private val outputDir: String) : Module {
|
||||
private val sourceFiles = ArrayList<String>()
|
||||
private val classpathRoots = ArrayList<String>()
|
||||
private val javaSourceRoots = ArrayList<String>()
|
||||
private val annotationsRoots = ArrayList<String>()
|
||||
|
||||
public fun addSourceFiles(pattern: String) {
|
||||
sourceFiles.add(pattern)
|
||||
}
|
||||
|
||||
public fun addClasspathEntry(name: String) {
|
||||
classpathRoots.add(name)
|
||||
}
|
||||
|
||||
public fun addAnnotationsPathEntry(name: String) {
|
||||
annotationsRoots.add(name)
|
||||
}
|
||||
|
||||
public fun addJavaSourceRoot(name: String) {
|
||||
javaSourceRoots.add(name)
|
||||
}
|
||||
|
||||
override fun getOutputDirectory(): String = outputDir
|
||||
override fun getJavaSourceRoots(): List<String> = javaSourceRoots
|
||||
override fun getSourceFiles(): List<String> = sourceFiles
|
||||
override fun getClasspathRoots(): List<String> = classpathRoots
|
||||
override fun getAnnotationsRoots(): List<String> = annotationsRoots
|
||||
override fun getModuleName(): String = name
|
||||
}
|
||||
|
||||
-1
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.modules;
|
||||
|
||||
import kotlin.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
+5
-2
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.cli.common.modules;
|
||||
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import kotlin.modules.Module;
|
||||
import kotlin.modules.ModuleBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
|
||||
@@ -44,6 +42,7 @@ public class ModuleXmlParser {
|
||||
public static final String NAME = "name";
|
||||
public static final String OUTPUT_DIR = "outputDir";
|
||||
public static final String SOURCES = "sources";
|
||||
public static final String JAVA_SOURCE_ROOTS = "javaSourceRoots";
|
||||
public static final String PATH = "path";
|
||||
public static final String CLASSPATH = "classpath";
|
||||
public static final String EXTERNAL_ANNOTATIONS = "externalAnnotations";
|
||||
@@ -162,6 +161,10 @@ public class ModuleXmlParser {
|
||||
String path = getAttribute(attributes, PATH, qName);
|
||||
moduleBuilder.addAnnotationsPathEntry(path);
|
||||
}
|
||||
else if (JAVA_SOURCE_ROOTS.equalsIgnoreCase(qName)) {
|
||||
String path = getAttribute(attributes, PATH, qName);
|
||||
moduleBuilder.addJavaSourceRoot(path);
|
||||
}
|
||||
else {
|
||||
throw createError(qName);
|
||||
}
|
||||
|
||||
@@ -166,8 +166,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
|
||||
if (arguments.module != null) {
|
||||
MessageCollector sanitizedCollector = new FilteringMessageCollector(messageCollector, in(CompilerMessageSeverity.VERBOSE));
|
||||
ModuleScriptData moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(
|
||||
paths, arguments.module, sanitizedCollector);
|
||||
ModuleScriptData moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector);
|
||||
|
||||
if (outputDir != null) {
|
||||
messageCollector.report(CompilerMessageSeverity.WARNING,
|
||||
|
||||
+1
-111
@@ -18,9 +18,7 @@ package org.jetbrains.kotlin.cli.jvm.compiler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
@@ -32,23 +30,14 @@ import com.intellij.psi.PsiManager;
|
||||
import kotlin.Function1;
|
||||
import kotlin.Unit;
|
||||
import kotlin.io.IoPackage;
|
||||
import kotlin.modules.AllModules;
|
||||
import kotlin.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleScriptData;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser;
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory;
|
||||
import org.jetbrains.kotlin.codegen.GeneratedClassLoader;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||
@@ -56,11 +45,6 @@ import org.jetbrains.kotlin.utils.PathUtil;
|
||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -68,23 +52,17 @@ import java.util.jar.*;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR;
|
||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJvmClasspathRoot;
|
||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJvmClasspathRoots;
|
||||
import static org.jetbrains.kotlin.config.ConfigPackage.addKotlinSourceRoot;
|
||||
|
||||
public class CompileEnvironmentUtil {
|
||||
|
||||
@NotNull
|
||||
public static ModuleScriptData loadModuleDescriptions(KotlinPaths paths, String moduleDefinitionFile, MessageCollector messageCollector) {
|
||||
public static ModuleScriptData loadModuleDescriptions(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 ModuleScriptData.EMPTY;
|
||||
}
|
||||
String extension = FileUtilRt.getExtension(moduleDefinitionFile);
|
||||
if ("ktm".equalsIgnoreCase(extension)) {
|
||||
return loadModuleScript(paths, moduleDefinitionFile, messageCollector);
|
||||
}
|
||||
if ("xml".equalsIgnoreCase(extension)) {
|
||||
return ModuleXmlParser.parseModuleScript(moduleDefinitionFile, messageCollector);
|
||||
}
|
||||
@@ -92,84 +70,6 @@ public class CompileEnvironmentUtil {
|
||||
return ModuleScriptData.EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ModuleScriptData loadModuleScript(KotlinPaths paths, String moduleScriptFile, MessageCollector messageCollector) {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
File runtimePath = paths.getRuntimePath();
|
||||
if (runtimePath.exists()) {
|
||||
addJvmClasspathRoot(configuration, runtimePath);
|
||||
}
|
||||
addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRoots());
|
||||
|
||||
File jdkAnnotationsPath = paths.getJdkAnnotationsPath();
|
||||
if (jdkAnnotationsPath.exists()) {
|
||||
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
|
||||
}
|
||||
addKotlinSourceRoot(configuration, moduleScriptFile);
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
List<Module> modules;
|
||||
|
||||
Disposable disposable = Disposer.newDisposable();
|
||||
try {
|
||||
KotlinCoreEnvironment scriptEnvironment =
|
||||
KotlinCoreEnvironment.createForProduction(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(scriptEnvironment);
|
||||
if (generationState == null) {
|
||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " analyze failed:\n" +
|
||||
loadModuleScriptText(moduleScriptFile));
|
||||
}
|
||||
|
||||
modules = runDefineModules(paths, generationState.getFactory());
|
||||
}
|
||||
finally {
|
||||
Disposer.dispose(disposable);
|
||||
}
|
||||
|
||||
if (modules == null) {
|
||||
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " compilation failed");
|
||||
}
|
||||
|
||||
if (modules.isEmpty()) {
|
||||
throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile);
|
||||
}
|
||||
return new ModuleScriptData(modules);
|
||||
}
|
||||
|
||||
private static List<Module> runDefineModules(KotlinPaths paths, ClassFileFactory factory) {
|
||||
File stdlibJar = paths.getRuntimePath();
|
||||
GeneratedClassLoader loader;
|
||||
if (stdlibJar.exists()) {
|
||||
try {
|
||||
loader = new GeneratedClassLoader(factory, new URLClassLoader(new URL[]{stdlibJar.toURI().toURL()},
|
||||
AllModules.class.getClassLoader()));
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
loader = new GeneratedClassLoader(factory, KotlinToJVMBytecodeCompiler.class.getClassLoader());
|
||||
}
|
||||
try {
|
||||
Class<?> packageClass = loader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
|
||||
Method method = packageClass.getDeclaredMethod("project");
|
||||
|
||||
method.setAccessible(true);
|
||||
method.invoke(null);
|
||||
|
||||
List<Module> answer = new ArrayList<Module>(AllModules.INSTANCE$.get());
|
||||
AllModules.INSTANCE$.get().clear();
|
||||
return answer;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ModuleExecutionException(e);
|
||||
}
|
||||
finally {
|
||||
loader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: includeRuntime should be not a flag but a path to runtime
|
||||
private static void doWriteToJar(ClassFileFactory outputFiles, OutputStream fos, @Nullable FqName mainClass, boolean includeRuntime) {
|
||||
try {
|
||||
@@ -237,16 +137,6 @@ public class CompileEnvironmentUtil {
|
||||
}
|
||||
}
|
||||
|
||||
// Used for debug output only
|
||||
private static String loadModuleScriptText(String moduleScriptFile) {
|
||||
try {
|
||||
return FileUtil.loadFile(new File(moduleScriptFile));
|
||||
}
|
||||
catch (IOException e) {
|
||||
return "Can't load module script text:\n" + OutputMessageUtil.renderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> getJetFiles(
|
||||
@NotNull final Project project,
|
||||
|
||||
+8
-5
@@ -24,8 +24,6 @@ import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.Unit;
|
||||
import kotlin.modules.AllModules;
|
||||
import kotlin.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -35,6 +33,7 @@ import org.jetbrains.kotlin.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.kotlin.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.modules.Module;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.codegen.*;
|
||||
@@ -67,8 +66,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJvmClasspathRoot;
|
||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.getJvmClasspathRoots;
|
||||
import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.*;
|
||||
import static org.jetbrains.kotlin.config.ConfigPackage.addKotlinSourceRoots;
|
||||
|
||||
public class KotlinToJVMBytecodeCompiler {
|
||||
@@ -173,6 +171,10 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
for (Module module : chunk) {
|
||||
addKotlinSourceRoots(configuration, getAbsolutePaths(directory, module));
|
||||
|
||||
for (String javaSourceRoot : module.getJavaSourceRoots()) {
|
||||
addJavaSourceRoot(configuration, new File(javaSourceRoot));
|
||||
}
|
||||
|
||||
for (String classpathRoot : module.getClasspathRoots()) {
|
||||
addJvmClasspathRoot(configuration, new File(classpathRoot));
|
||||
}
|
||||
@@ -270,9 +272,10 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
for (File file : getJvmClasspathRoots(configuration)) {
|
||||
classPaths.add(file.toURI().toURL());
|
||||
}
|
||||
//noinspection UnnecessaryFullyQualifiedName
|
||||
classLoader = new GeneratedClassLoader(state.getFactory(),
|
||||
new URLClassLoader(classPaths.toArray(new URL[classPaths.size()]),
|
||||
AllModules.class.getClassLoader())
|
||||
kotlin.KotlinPackage.class.getClassLoader())
|
||||
);
|
||||
|
||||
FqName nameForScript = ScriptNameUtil.classNameForScript(environment.getSourceFiles().get(0).getScript());
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import kotlin.modules.*
|
||||
|
||||
fun project() {
|
||||
module("smoke", ".") {
|
||||
sources += "Smoke.kt"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Return code: 0
|
||||
@@ -1,5 +0,0 @@
|
||||
package Smoke
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print("${args[0]}|${args[1]}|${args[2]}")
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import kotlin.modules.*
|
||||
|
||||
fun project() {
|
||||
module("smoke", ".") {
|
||||
sources += "Smoke.kt"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
OUT:
|
||||
1|2|3
|
||||
Return code: 0
|
||||
@@ -82,15 +82,6 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileAndRunModule() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.ktm", "-d", jar));
|
||||
String classpath = jar + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath();
|
||||
runJava("Smoke.run", "-cp", classpath, "Smoke.SmokePackage", "1", "2", "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationFailed() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
@@ -35,43 +35,6 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
public class CompileEnvironmentTest extends TestCase {
|
||||
public void testSmokeWithCompilerJar() throws IOException {
|
||||
File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
|
||||
|
||||
try {
|
||||
File stdlib = ForTestCompileRuntime.runtimeJarForTests();
|
||||
File jdkAnnotations = JetTestUtils.getJdkAnnotationsJar();
|
||||
File resultJar = new File(tempDir, "result.jar");
|
||||
ExitCode rv = new K2JVMCompiler().exec(
|
||||
System.out,
|
||||
"-module", JetTestUtils.getTestDataPathBase() + "/compiler/smoke/Smoke.ktm",
|
||||
"-d", resultJar.getAbsolutePath(),
|
||||
"-no-stdlib",
|
||||
"-classpath", stdlib.getAbsolutePath(),
|
||||
"-no-jdk-annotations",
|
||||
"-annotations", jdkAnnotations.getAbsolutePath()
|
||||
);
|
||||
Assert.assertEquals("compilation completed with non-zero code", ExitCode.OK, rv);
|
||||
FileInputStream fileInputStream = new FileInputStream(resultJar);
|
||||
try {
|
||||
JarInputStream is = new JarInputStream(fileInputStream);
|
||||
try {
|
||||
List<String> entries = listEntries(is);
|
||||
assertTrue(entries.contains("Smoke/" + PackageClassUtils.getPackageClassName(new FqName("Smoke")) + ".class"));
|
||||
assertEquals(2, entries.size());
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fileInputStream.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSmokeWithCompilerOutput() throws IOException {
|
||||
File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
|
||||
@@ -96,16 +59,4 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
FileUtil.delete(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> listEntries(JarInputStream is) throws IOException {
|
||||
List<String> entries = new ArrayList<String>();
|
||||
while (true) {
|
||||
JarEntry jarEntry = is.getNextJarEntry();
|
||||
if (jarEntry == null) {
|
||||
break;
|
||||
}
|
||||
entries.add(jarEntry.getName());
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.modules.xml;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer;
|
||||
import org.jetbrains.kotlin.cli.common.modules.Module;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleScriptData;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
|
||||
@@ -24,6 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JetFileFactory extends FileTypeFactory {
|
||||
@Override
|
||||
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
|
||||
consumer.consume(JetFileType.INSTANCE, "kt;kts;ktm");
|
||||
consumer.consume(JetFileType.INSTANCE, "kt;kts");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,23 +67,19 @@ public class KotlinModuleXmlBuilder {
|
||||
p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>");
|
||||
}
|
||||
|
||||
if (!javaSourceRoots.isEmpty()) {
|
||||
processClassPathSection("Java source roots", javaSourceRoots, directoriesToFilterOut);
|
||||
}
|
||||
|
||||
processClassPathSection("Classpath", classpathRoots, directoriesToFilterOut);
|
||||
processJavaSourceRoots(javaSourceRoots);
|
||||
processClasspath(classpathRoots, directoriesToFilterOut);
|
||||
processAnnotationRoots(annotationRoots);
|
||||
|
||||
closeTag(p, MODULE);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void processClassPathSection(
|
||||
@NotNull String sectionDescription,
|
||||
private void processClasspath(
|
||||
@NotNull Collection<File> files,
|
||||
@NotNull Set<File> directoriesToFilterOut
|
||||
) {
|
||||
p.println("<!-- ", sectionDescription, " -->");
|
||||
p.println("<!-- Classpath -->");
|
||||
for (File file : files) {
|
||||
boolean isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.ENABLED;
|
||||
if (isOutput) {
|
||||
@@ -111,6 +107,13 @@ public class KotlinModuleXmlBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private void processJavaSourceRoots(@NotNull List<File> files) {
|
||||
p.println("<!-- Java source roots -->");
|
||||
for (File file : files) {
|
||||
p.println("<", JAVA_SOURCE_ROOTS, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
|
||||
}
|
||||
}
|
||||
|
||||
public CharSequence asText() {
|
||||
if (!done) {
|
||||
closeTag(p, MODULES);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package kotlin.modules
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public object AllModules : ThreadLocal<ArrayList<Module>>() {
|
||||
override fun initialValue() = ArrayList<Module>()
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package kotlin.modules
|
||||
|
||||
public trait Module {
|
||||
public fun getModuleName(): String
|
||||
|
||||
public fun getOutputDirectory(): String
|
||||
|
||||
public fun getSourceFiles(): List<String>
|
||||
|
||||
public fun getClasspathRoots(): List<String>
|
||||
|
||||
public fun getAnnotationsRoots(): List<String>
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package kotlin.modules
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public fun module(name: String, outputDir: String, callback: ModuleBuilder.() -> Unit) {
|
||||
val builder = ModuleBuilder(name, outputDir)
|
||||
builder.callback()
|
||||
AllModules.get()?.add(builder)
|
||||
}
|
||||
|
||||
public class SourcesBuilder(private val parent: ModuleBuilder) {
|
||||
public fun plusAssign(pattern: String) {
|
||||
parent.addSourceFiles(pattern)
|
||||
}
|
||||
}
|
||||
|
||||
public class ClasspathBuilder(private val parent: ModuleBuilder) {
|
||||
public fun plusAssign(name: String) {
|
||||
parent.addClasspathEntry(name)
|
||||
}
|
||||
}
|
||||
|
||||
public class AnnotationsPathBuilder(private val parent: ModuleBuilder) {
|
||||
public fun plusAssign(name: String) {
|
||||
parent.addAnnotationsPathEntry(name)
|
||||
}
|
||||
}
|
||||
|
||||
public open class ModuleBuilder(private val name: String, private val outputDir: String) : Module {
|
||||
// http://youtrack.jetbrains.net/issue/KT-904
|
||||
private val sourceFiles0 = ArrayList<String>()
|
||||
private val classpathRoots0 = ArrayList<String>()
|
||||
private val annotationsRoots0 = ArrayList<String>()
|
||||
|
||||
public val sources: SourcesBuilder
|
||||
get() = SourcesBuilder(this)
|
||||
|
||||
public val classpath: ClasspathBuilder
|
||||
get() = ClasspathBuilder(this)
|
||||
|
||||
public val annotationsPath: AnnotationsPathBuilder
|
||||
get() = AnnotationsPathBuilder(this)
|
||||
|
||||
public fun addSourceFiles(pattern: String) {
|
||||
sourceFiles0.add(pattern)
|
||||
}
|
||||
|
||||
public fun addClasspathEntry(name: String) {
|
||||
classpathRoots0.add(name)
|
||||
}
|
||||
|
||||
public fun addAnnotationsPathEntry(name: String) {
|
||||
annotationsRoots0.add(name)
|
||||
}
|
||||
|
||||
public override fun getOutputDirectory(): String = outputDir
|
||||
public override fun getSourceFiles(): List<String> = sourceFiles0
|
||||
public override fun getClasspathRoots(): List<String> = classpathRoots0
|
||||
public override fun getAnnotationsRoots(): List<String> = annotationsRoots0
|
||||
public override fun getModuleName(): String = name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user