Add prefix information for Java source root (KT-9167 in progress)
#KT-9167 In Progress
Original commit: c0739ef53c
This commit is contained in:
committed by
Nikolay Krasko
parent
bc29f06187
commit
048725c3f0
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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.jps.build
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
data class JvmSourceRoot(val file: File, val packagePrefix: String? = null)
|
||||||
+4
-3
@@ -127,13 +127,14 @@ public class KotlinBuilderModuleScriptGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<File> findSourceRoots(@NotNull CompileContext context, @NotNull ModuleBuildTarget target) {
|
private static List<JvmSourceRoot> findSourceRoots(@NotNull CompileContext context, @NotNull ModuleBuildTarget target) {
|
||||||
List<JavaSourceRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
|
List<JavaSourceRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
|
||||||
List<File> result = ContainerUtil.newArrayList();
|
List<JvmSourceRoot> result = ContainerUtil.newArrayList();
|
||||||
for (JavaSourceRootDescriptor root : roots) {
|
for (JavaSourceRootDescriptor root : roots) {
|
||||||
File file = root.getRootFile();
|
File file = root.getRootFile();
|
||||||
|
String prefix = root.getPackagePrefix();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
result.add(file);
|
result.add(new JvmSourceRoot(file, prefix.isEmpty() ? null : prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.modules;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||||
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
||||||
|
import org.jetbrains.kotlin.jps.build.JvmSourceRoot;
|
||||||
import org.jetbrains.kotlin.utils.Printer;
|
import org.jetbrains.kotlin.utils.Printer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -43,7 +44,7 @@ public class KotlinModuleXmlBuilder {
|
|||||||
String moduleName,
|
String moduleName,
|
||||||
String outputDir,
|
String outputDir,
|
||||||
List<File> sourceFiles,
|
List<File> sourceFiles,
|
||||||
List<File> javaSourceRoots,
|
List<JvmSourceRoot> javaSourceRoots,
|
||||||
Collection<File> classpathRoots,
|
Collection<File> classpathRoots,
|
||||||
JavaModuleBuildTargetType targetType,
|
JavaModuleBuildTargetType targetType,
|
||||||
Set<File> directoriesToFilterOut
|
Set<File> directoriesToFilterOut
|
||||||
@@ -100,10 +101,18 @@ public class KotlinModuleXmlBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processJavaSourceRoots(@NotNull List<File> files) {
|
private void processJavaSourceRoots(@NotNull List<JvmSourceRoot> roots) {
|
||||||
p.println("<!-- Java source roots -->");
|
p.println("<!-- Java source roots -->");
|
||||||
for (File file : files) {
|
for (JvmSourceRoot root : roots) {
|
||||||
p.println("<", JAVA_SOURCE_ROOTS, " ", PATH, "=\"", getEscapedPath(file), "\"/>");
|
p.print("<");
|
||||||
|
p.printWithNoIndent(JAVA_SOURCE_ROOTS, " ", PATH, "=\"", getEscapedPath(root.getFile()), "\"");
|
||||||
|
|
||||||
|
if (root.getPackagePrefix() != null) {
|
||||||
|
p.printWithNoIndent(" ", JAVA_SOURCE_PACKAGE_PREFIX, "=\"", root.getPackagePrefix(), "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
p.printWithNoIndent("/>");
|
||||||
|
p.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.jvm.compiler
|
package org.jetbrains.kotlin.jvm.compiler
|
||||||
|
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
||||||
|
import org.jetbrains.kotlin.jps.build.JvmSourceRoot
|
||||||
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||||
@@ -43,7 +44,7 @@ public class ClasspathOrderTest : TestCaseWithTmpdir() {
|
|||||||
"name",
|
"name",
|
||||||
File(tmpdir, "output").getAbsolutePath(),
|
File(tmpdir, "output").getAbsolutePath(),
|
||||||
listOf(sourceDir),
|
listOf(sourceDir),
|
||||||
listOf(sourceDir),
|
listOf(JvmSourceRoot(sourceDir)),
|
||||||
listOf(PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()),
|
listOf(PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION,
|
||||||
setOf()
|
setOf()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.modules;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||||
|
import org.jetbrains.kotlin.jps.build.JvmSourceRoot;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -30,7 +31,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
"name",
|
"name",
|
||||||
"output",
|
"output",
|
||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.singletonList(new File("java")),
|
Collections.singletonList(new JvmSourceRoot(new File("java"), null)),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION,
|
||||||
Collections.<File>emptySet()
|
Collections.<File>emptySet()
|
||||||
@@ -43,7 +44,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
"name",
|
"name",
|
||||||
"output",
|
"output",
|
||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.<File>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION,
|
||||||
Collections.singleton(new File("cp1"))
|
Collections.singleton(new File("cp1"))
|
||||||
@@ -57,7 +58,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
"name",
|
"name",
|
||||||
"output",
|
"output",
|
||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.<File>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION,
|
||||||
Collections.singleton(new File("cp1"))
|
Collections.singleton(new File("cp1"))
|
||||||
@@ -66,7 +67,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
"name2",
|
"name2",
|
||||||
"output2",
|
"output2",
|
||||||
Arrays.asList(new File("s12"), new File("s22")),
|
Arrays.asList(new File("s12"), new File("s22")),
|
||||||
Collections.<File>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp12"), new File("cp22")),
|
Arrays.asList(new File("cp12"), new File("cp22")),
|
||||||
JavaModuleBuildTargetType.TEST,
|
JavaModuleBuildTargetType.TEST,
|
||||||
Collections.singleton(new File("cp12"))
|
Collections.singleton(new File("cp12"))
|
||||||
|
|||||||
Reference in New Issue
Block a user