Save target type in Kotlin Builder
This commit is contained in:
@@ -10,5 +10,6 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="library" exported="" name="cli-parser" level="project" />
|
||||
<orderEntry type="library" name="jps" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.cli.common.modules
|
||||
public interface Module {
|
||||
public fun getModuleName(): String
|
||||
|
||||
public fun getModuleType(): String
|
||||
|
||||
public fun getOutputDirectory(): String
|
||||
|
||||
public fun getSourceFiles(): List<String>
|
||||
|
||||
+6
-1
@@ -18,7 +18,11 @@ package org.jetbrains.kotlin.cli.common.modules
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public class ModuleBuilder(private val name: String, private val outputDir: String) : Module {
|
||||
public class ModuleBuilder(
|
||||
private val name: String,
|
||||
private val outputDir: String,
|
||||
private val type: String
|
||||
) : Module {
|
||||
private val sourceFiles = ArrayList<String>()
|
||||
private val classpathRoots = ArrayList<String>()
|
||||
private val javaSourceRoots = ArrayList<String>()
|
||||
@@ -46,5 +50,6 @@ public class ModuleBuilder(private val name: String, private val outputDir: Stri
|
||||
override fun getClasspathRoots(): List<String> = classpathRoots
|
||||
override fun getAnnotationsRoots(): List<String> = annotationsRoots
|
||||
override fun getModuleName(): String = name
|
||||
override fun getModuleType(): String = type
|
||||
}
|
||||
|
||||
|
||||
+17
-3
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.cli.common.modules;
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil;
|
||||
@@ -40,6 +41,7 @@ public class ModuleXmlParser {
|
||||
public static final String MODULES = "modules";
|
||||
public static final String MODULE = "module";
|
||||
public static final String NAME = "name";
|
||||
public static final String TYPE = "type";
|
||||
public static final String OUTPUT_DIR = "outputDir";
|
||||
public static final String SOURCES = "sources";
|
||||
public static final String JAVA_SOURCE_ROOTS = "javaSourceRoots";
|
||||
@@ -126,10 +128,22 @@ public class ModuleXmlParser {
|
||||
|
||||
setCurrentState(new InsideModule(
|
||||
getAttribute(attributes, NAME, qName),
|
||||
getAttribute(attributes, OUTPUT_DIR, qName)
|
||||
getAttribute(attributes, OUTPUT_DIR, qName),
|
||||
getType(attributes, qName)
|
||||
));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getType(@NotNull Attributes attributes, @NotNull String tag) {
|
||||
String value = attributes.getValue(TYPE);
|
||||
|
||||
assert value != null &&
|
||||
(JavaModuleBuildTargetType.PRODUCTION.getTypeId().equals(value) ||
|
||||
JavaModuleBuildTargetType.TEST.getTypeId().equals(value)): "Unknown value of module type: " + value;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, @NotNull String localName, @NotNull String qName) throws SAXException {
|
||||
if (MODULE.equalsIgnoreCase(qName) || MODULES.equalsIgnoreCase(qName)) {
|
||||
@@ -141,8 +155,8 @@ public class ModuleXmlParser {
|
||||
private class InsideModule extends DefaultHandler {
|
||||
|
||||
private final ModuleBuilder moduleBuilder;
|
||||
private InsideModule(String name, String outputDir) {
|
||||
this.moduleBuilder = new ModuleBuilder(name, outputDir);
|
||||
private InsideModule(String name, String outputDir, @NotNull String type) {
|
||||
this.moduleBuilder = new ModuleBuilder(name, outputDir, type);
|
||||
modules.add(moduleBuilder);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ public abstract class AbstractModuleXmlParserTest extends TestCase {
|
||||
|
||||
private static String moduleToString(@NotNull Module module) {
|
||||
return module.getModuleName() +
|
||||
"\n\ttype=" + module.getModuleType() +
|
||||
"\n\toutputDir=" + module.getOutputDirectory() +
|
||||
"\n\tsources=" + module.getSourceFiles() +
|
||||
"\n\tclasspath=" + module.getClasspathRoots() +
|
||||
|
||||
+5
-1
@@ -26,6 +26,8 @@ import kotlin.io.IoPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.ModuleChunk;
|
||||
import org.jetbrains.jps.builders.BuildTargetType;
|
||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||
import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor;
|
||||
import org.jetbrains.jps.builders.logging.ProjectBuilderLogger;
|
||||
import org.jetbrains.jps.incremental.CompileContext;
|
||||
@@ -82,6 +84,8 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
BuildTargetType<?> targetType = target.getTargetType();
|
||||
assert targetType instanceof JavaModuleBuildTargetType;
|
||||
builder.addModule(
|
||||
target.getId(),
|
||||
outputDir.getAbsolutePath(),
|
||||
@@ -89,7 +93,7 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
findSourceRoots(context, target),
|
||||
findClassPathRoots(target),
|
||||
findAnnotationRoots(target),
|
||||
target.isTests(),
|
||||
(JavaModuleBuildTargetType) targetType,
|
||||
// this excludes the output directories from the class path, to be removed for true incremental compilation
|
||||
outputDirs
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.modules;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
||||
import org.jetbrains.kotlin.utils.Printer;
|
||||
|
||||
@@ -45,12 +46,12 @@ public class KotlinModuleXmlBuilder {
|
||||
List<File> javaSourceRoots,
|
||||
Collection<File> classpathRoots,
|
||||
List<File> annotationRoots,
|
||||
boolean tests,
|
||||
JavaModuleBuildTargetType targetType,
|
||||
Set<File> directoriesToFilterOut
|
||||
) {
|
||||
assert !done : "Already done";
|
||||
|
||||
if (tests) {
|
||||
if (targetType.isTests()) {
|
||||
p.println("<!-- Module script for tests -->");
|
||||
}
|
||||
else {
|
||||
@@ -59,6 +60,7 @@ public class KotlinModuleXmlBuilder {
|
||||
|
||||
p.println("<", MODULE, " ",
|
||||
NAME, "=\"", escapeXml(moduleName), "\" ",
|
||||
TYPE, "=\"", escapeXml(targetType.getTypeId()), "\" ",
|
||||
OUTPUT_DIR, "=\"", getEscapedPath(new File(outputDir)), "\">"
|
||||
);
|
||||
p.pushIndent();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
||||
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||
@@ -45,7 +46,7 @@ public class ClasspathOrderTest : TestCaseWithTmpdir() {
|
||||
listOf(sourceDir),
|
||||
listOf(PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()),
|
||||
listOf(),
|
||||
false,
|
||||
JavaModuleBuildTargetType.PRODUCTION,
|
||||
setOf()
|
||||
).asText().toString()
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.modules;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -32,7 +33,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
Collections.singletonList(new File("java")),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
Arrays.asList(new File("a1/f1"), new File("a2")),
|
||||
false,
|
||||
JavaModuleBuildTargetType.PRODUCTION,
|
||||
Collections.<File>emptySet()
|
||||
).asText().toString();
|
||||
JetTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/basic.xml"), actual);
|
||||
@@ -46,7 +47,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
Collections.<File>emptyList(),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
Arrays.asList(new File("a1/f1"), new File("a2")),
|
||||
false,
|
||||
JavaModuleBuildTargetType.PRODUCTION,
|
||||
Collections.singleton(new File("cp1"))
|
||||
).asText().toString();
|
||||
JetTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/filtered.xml"), actual);
|
||||
@@ -61,7 +62,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
Collections.<File>emptyList(),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
Arrays.asList(new File("a1/f1"), new File("a2")),
|
||||
false,
|
||||
JavaModuleBuildTargetType.PRODUCTION,
|
||||
Collections.singleton(new File("cp1"))
|
||||
);
|
||||
builder.addModule(
|
||||
@@ -71,7 +72,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
Collections.<File>emptyList(),
|
||||
Arrays.asList(new File("cp12"), new File("cp22")),
|
||||
Arrays.asList(new File("a12/f12"), new File("a22")),
|
||||
true,
|
||||
JavaModuleBuildTargetType.TEST,
|
||||
Collections.singleton(new File("cp12"))
|
||||
);
|
||||
String actual = builder.asText().toString();
|
||||
|
||||
Reference in New Issue
Block a user