diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilderModuleScriptGenerator.java b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilderModuleScriptGenerator.java index 86f6dcdff95..5f3c1397d04 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilderModuleScriptGenerator.java +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilderModuleScriptGenerator.java @@ -39,9 +39,7 @@ import org.jetbrains.jps.model.module.JpsDependencyElement; import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsSdkDependency; import org.jetbrains.kotlin.config.IncrementalCompilation; -import org.jetbrains.kotlin.modules.KotlinModuleDescriptionBuilder; -import org.jetbrains.kotlin.modules.KotlinModuleDescriptionBuilderFactory; -import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilderFactory; +import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder; import java.io.File; import java.io.IOException; @@ -51,8 +49,6 @@ import static org.jetbrains.kotlin.jps.build.JpsUtils.getAllDependencies; public class KotlinBuilderModuleScriptGenerator { - public static final KotlinModuleDescriptionBuilderFactory FACTORY = KotlinModuleXmlBuilderFactory.INSTANCE; - @Nullable public static File generateModuleDescription( CompileContext context, @@ -60,7 +56,7 @@ public class KotlinBuilderModuleScriptGenerator { MultiMap sourceFiles, // ignored for non-incremental compilation boolean hasRemovedFiles ) throws IOException, ProjectBuildException { - KotlinModuleDescriptionBuilder builder = FACTORY.create(); + KotlinModuleXmlBuilder builder = new KotlinModuleXmlBuilder(); boolean noSources = true; diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilder.java b/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilder.java deleted file mode 100644 index 43722755430..00000000000 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilder.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.modules; - -import java.io.File; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -public interface KotlinModuleDescriptionBuilder { - KotlinModuleDescriptionBuilder addModule( - String moduleName, - String outputDir, - List sourceFiles, - List javaSourceRoots, - Collection classpathRoots, - List annotationRoots, - boolean tests, - Set directoriesToFilterOut - ); - - CharSequence asText(); -} diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilderFactory.java b/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilderFactory.java deleted file mode 100644 index 322c75dfbd0..00000000000 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleDescriptionBuilderFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.modules; - -public interface KotlinModuleDescriptionBuilderFactory { - KotlinModuleDescriptionBuilder create(); - String getFileExtension(); -} diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.java b/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.java new file mode 100644 index 00000000000..1584e1a7e34 --- /dev/null +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.java @@ -0,0 +1,135 @@ +/* + * 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.modules; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.config.IncrementalCompilation; +import org.jetbrains.kotlin.utils.Printer; + +import java.io.File; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; +import static com.intellij.openapi.util.text.StringUtil.escapeXml; +import static org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser.*; + +public class KotlinModuleXmlBuilder { + private final StringBuilder xml = new StringBuilder(); + private final Printer p = new Printer(xml); + private boolean done = false; + + public KotlinModuleXmlBuilder() { + openTag(p, MODULES); + } + + public KotlinModuleXmlBuilder addModule( + String moduleName, + String outputDir, + List sourceFiles, + List javaSourceRoots, + Collection classpathRoots, + List annotationRoots, + boolean tests, + Set directoriesToFilterOut + ) { + assert !done : "Already done"; + + if (tests) { + p.println(""); + } + else { + p.println(""); + } + + p.println("<", MODULE, " ", + NAME, "=\"", escapeXml(moduleName), "\" ", + OUTPUT_DIR, "=\"", getEscapedPath(new File(outputDir)), "\">" + ); + p.pushIndent(); + + for (File sourceFile : sourceFiles) { + p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>"); + } + + if (!javaSourceRoots.isEmpty()) { + processClassPathSection("Java source roots", javaSourceRoots, directoriesToFilterOut); + } + + processClassPathSection("Classpath", classpathRoots, directoriesToFilterOut); + processAnnotationRoots(annotationRoots); + + closeTag(p, MODULE); + return this; + } + + private void processClassPathSection( + @NotNull String sectionDescription, + @NotNull Collection files, + @NotNull Set directoriesToFilterOut + ) { + p.println(""); + for (File file : files) { + boolean isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.ENABLED; + if (isOutput) { + // 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. + p.println(""); + p.println(""); + } + } + } + + private void processAnnotationRoots(@NotNull List files) { + p.println(""); + for (File file : files) { + p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "=\"", getEscapedPath(file), "\"/>"); + } + } + + public CharSequence asText() { + if (!done) { + closeTag(p, MODULES); + done = true; + } + return xml; + } + + private static void openTag(Printer p, String tag) { + p.println("<" + tag + ">"); + p.pushIndent(); + } + + private static void closeTag(Printer p, String tag) { + p.popIndent(); + p.println(""); + } + + private static String getEscapedPath(File sourceFile) { + return escapeXml(toSystemIndependentName(sourceFile.getPath())); + } +} diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilderFactory.java b/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilderFactory.java deleted file mode 100644 index 8ecbca258c3..00000000000 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilderFactory.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.modules; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.config.IncrementalCompilation; -import org.jetbrains.kotlin.utils.Printer; - -import java.io.File; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; -import static com.intellij.openapi.util.text.StringUtil.escapeXml; -import static org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser.*; - -public class KotlinModuleXmlBuilderFactory implements KotlinModuleDescriptionBuilderFactory { - - public static final KotlinModuleXmlBuilderFactory INSTANCE = new KotlinModuleXmlBuilderFactory(); - - private KotlinModuleXmlBuilderFactory() {} - - @Override - public KotlinModuleDescriptionBuilder create() { - return new Builder(); - } - - @Override - public String getFileExtension() { - return "xml"; - } - - private static class Builder implements KotlinModuleDescriptionBuilder { - private final StringBuilder xml = new StringBuilder(); - private final Printer p = new Printer(xml); - private boolean done = false; - - public Builder() { - openTag(p, MODULES); - } - - @Override - public KotlinModuleDescriptionBuilder addModule( - String moduleName, - String outputDir, - List sourceFiles, - List javaSourceRoots, - Collection classpathRoots, - List annotationRoots, - boolean tests, - Set directoriesToFilterOut - ) { - assert !done : "Already done"; - - if (tests) { - p.println(""); - } - else { - p.println(""); - } - - p.println("<", MODULE, " ", - NAME, "=\"", escapeXml(moduleName), "\" ", - OUTPUT_DIR, "=\"", getEscapedPath(new File(outputDir)), "\">" - ); - p.pushIndent(); - - for (File sourceFile : sourceFiles) { - p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>"); - } - - if (!javaSourceRoots.isEmpty()) { - processClassPathSection("Java source roots", javaSourceRoots, directoriesToFilterOut); - } - - processClassPathSection("Classpath", classpathRoots, directoriesToFilterOut); - processAnnotationRoots(annotationRoots); - - closeTag(p, MODULE); - return this; - } - - private void processClassPathSection( - @NotNull String sectionDescription, - @NotNull Collection files, - @NotNull Set directoriesToFilterOut - ) { - p.println(""); - for (File file : files) { - boolean isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.ENABLED; - if (isOutput) { - // 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. - p.println(""); - p.println(""); - } - } - } - - private void processAnnotationRoots(@NotNull List files) { - p.println(""); - for (File file : files) { - p.println("<", EXTERNAL_ANNOTATIONS, " ", PATH, "=\"", getEscapedPath(file), "\"/>"); - } - } - - @Override - public CharSequence asText() { - if (!done) { - closeTag(p, MODULES); - done = true; - } - return xml; - } - } - - private static void openTag(Printer p, String tag) { - p.println("<" + tag + ">"); - p.pushIndent(); - } - - private static void closeTag(Printer p, String tag) { - p.popIndent(); - p.println(""); - } - - private static String getEscapedPath(File sourceFile) { - return escapeXml(toSystemIndependentName(sourceFile.getPath())); - } -} diff --git a/jps/jps-plugin/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt b/jps/jps-plugin/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt index 7652295c2f9..029347e5090 100644 --- a/jps/jps-plugin/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt +++ b/jps/jps-plugin/test/org/jetbrains/kotlin/jvm/compiler/ClasspathOrderTest.kt @@ -16,12 +16,12 @@ package org.jetbrains.kotlin.jvm.compiler -import org.jetbrains.kotlin.test.TestCaseWithTmpdir +import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder import org.jetbrains.kotlin.test.JetTestUtils import org.jetbrains.kotlin.test.MockLibraryUtil -import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilderFactory -import java.io.File +import org.jetbrains.kotlin.test.TestCaseWithTmpdir import org.jetbrains.kotlin.utils.PathUtil +import java.io.File /** * This test checks that Java classes from sources have higher priority in Kotlin resolution process than classes from binaries. @@ -38,7 +38,7 @@ public class ClasspathOrderTest : TestCaseWithTmpdir() { } public fun testClasspathOrderForModuleScriptBuild() { - val xmlContent = KotlinModuleXmlBuilderFactory.INSTANCE.create().addModule( + val xmlContent = KotlinModuleXmlBuilder().addModule( "name", File(tmpdir, "output").getAbsolutePath(), listOf(sourceDir), diff --git a/jps/jps-plugin/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java b/jps/jps-plugin/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java index e024e504827..61bba84e200 100644 --- a/jps/jps-plugin/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java +++ b/jps/jps-plugin/test/org/jetbrains/kotlin/modules/KotlinModuleXmlGeneratorTest.java @@ -25,7 +25,7 @@ import java.util.Collections; public class KotlinModuleXmlGeneratorTest extends TestCase { public void testBasic() throws Exception { - String actual = KotlinModuleXmlBuilderFactory.INSTANCE.create().addModule( + String actual = new KotlinModuleXmlBuilder().addModule( "name", "output", Arrays.asList(new File("s1"), new File("s2")), @@ -39,7 +39,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { } public void testFiltered() throws Exception { - String actual = KotlinModuleXmlBuilderFactory.INSTANCE.create().addModule( + String actual = new KotlinModuleXmlBuilder().addModule( "name", "output", Arrays.asList(new File("s1"), new File("s2")), @@ -53,7 +53,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase { } public void testMultiple() throws Exception { - KotlinModuleDescriptionBuilder builder = KotlinModuleXmlBuilderFactory.INSTANCE.create(); + KotlinModuleXmlBuilder builder = new KotlinModuleXmlBuilder(); builder.addModule( "name", "output",