remove abstraction which is no longer needed

Original commit: 20fbb814e4
This commit is contained in:
Dmitry Jemerov
2015-03-24 17:45:57 +01:00
committed by Evgeny Gerashchenko
parent 117ecaa011
commit 3f59b7a6db
7 changed files with 144 additions and 226 deletions
@@ -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<ModuleBuildTarget, File> sourceFiles, // ignored for non-incremental compilation
boolean hasRemovedFiles
) throws IOException, ProjectBuildException {
KotlinModuleDescriptionBuilder builder = FACTORY.create();
KotlinModuleXmlBuilder builder = new KotlinModuleXmlBuilder();
boolean noSources = true;
@@ -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<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
Set<File> directoriesToFilterOut
);
CharSequence asText();
}
@@ -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();
}
@@ -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<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
Set<File> directoriesToFilterOut
) {
assert !done : "Already done";
if (tests) {
p.println("<!-- Module script for tests -->");
}
else {
p.println("<!-- Module script for production -->");
}
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<File> files,
@NotNull Set<File> directoriesToFilterOut
) {
p.println("<!-- ", sectionDescription, " -->");
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("<!-- Output directory, commented out -->");
p.println("<!-- ");
p.pushIndent();
}
p.println("<", CLASSPATH, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
if (isOutput) {
p.popIndent();
p.println("-->");
}
}
}
private void processAnnotationRoots(@NotNull List<File> files) {
p.println("<!-- External annotations -->");
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("</" + tag + ">");
}
private static String getEscapedPath(File sourceFile) {
return escapeXml(toSystemIndependentName(sourceFile.getPath()));
}
}
@@ -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<File> sourceFiles,
List<File> javaSourceRoots,
Collection<File> classpathRoots,
List<File> annotationRoots,
boolean tests,
Set<File> directoriesToFilterOut
) {
assert !done : "Already done";
if (tests) {
p.println("<!-- Module script for tests -->");
}
else {
p.println("<!-- Module script for production -->");
}
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<File> files,
@NotNull Set<File> directoriesToFilterOut
) {
p.println("<!-- ", sectionDescription, " -->");
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("<!-- Output directory, commented out -->");
p.println("<!-- ");
p.pushIndent();
}
p.println("<", CLASSPATH, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
if (isOutput) {
p.popIndent();
p.println("-->");
}
}
}
private void processAnnotationRoots(@NotNull List<File> files) {
p.println("<!-- External annotations -->");
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("</" + tag + ">");
}
private static String getEscapedPath(File sourceFile) {
return escapeXml(toSystemIndependentName(sourceFile.getPath()));
}
}
@@ -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),
@@ -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",