From 11d1e29e36a2104347c814ed4768399bf93a6e5f Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 29 May 2014 16:07:18 +0400 Subject: [PATCH] one test rewritten in Kotlin --- .idea/libraries/KotlinJavaRuntime.xml | 11 ++ build/.gitignore | 1 + build/gant.xml | 3 + jps/jps-builders/jps-builders.iml | 1 + .../src/org/jetbrains/jps/ProjectPaths.java | 4 + .../jps/builders/ModuleClasspathTest.groovy | 111 ------------------ .../jps/builders/ModuleClasspathTest.kt | 98 ++++++++++++++++ 7 files changed, 118 insertions(+), 111 deletions(-) create mode 100644 .idea/libraries/KotlinJavaRuntime.xml create mode 100644 build/.gitignore delete mode 100644 jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy create mode 100644 jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.kt diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 000000000000..1529a7e6fbf5 --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 000000000000..960e92af78c0 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +/kotlinc/ diff --git a/build/gant.xml b/build/gant.xml index 2ce6b235b5b1..ad3f08f8d587 100644 --- a/build/gant.xml +++ b/build/gant.xml @@ -12,6 +12,9 @@ + + + diff --git a/jps/jps-builders/jps-builders.iml b/jps/jps-builders/jps-builders.iml index 9dd56d591d6e..22e65e9607ee 100644 --- a/jps/jps-builders/jps-builders.iml +++ b/jps/jps-builders/jps-builders.iml @@ -37,6 +37,7 @@ + diff --git a/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java b/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java index 05c00b60770d..962f6d81cbe9 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java +++ b/jps/jps-builders/src/org/jetbrains/jps/ProjectPaths.java @@ -42,6 +42,7 @@ public class ProjectPaths { private ProjectPaths() { } + @NotNull public static Collection getCompilationClasspathFiles(ModuleChunk chunk, boolean includeTests, final boolean excludeMainModuleOutput, @@ -49,14 +50,17 @@ public class ProjectPaths { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(includeTests), excludeMainModuleOutput, ClasspathPart.WHOLE, exportedOnly); } + @NotNull public static Collection getPlatformCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(chunk.containsTests()), excludeMainModuleOutput, ClasspathPart.BEFORE_JDK, true); } + @NotNull public static Collection getCompilationClasspath(ModuleChunk chunk, boolean excludeMainModuleOutput) { return getClasspathFiles(chunk, JpsJavaClasspathKind.compile(chunk.containsTests()), excludeMainModuleOutput, ClasspathPart.AFTER_JDK, true); } + @NotNull private static Collection getClasspathFiles(ModuleChunk chunk, JpsJavaClasspathKind kind, final boolean excludeMainModuleOutput, diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy deleted file mode 100644 index 3431c457f3a8..000000000000 --- a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.groovy +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2000-2012 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.jps.builders - -import com.intellij.openapi.application.ex.PathManagerEx -import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.jps.ModuleChunk -import org.jetbrains.jps.ProjectPaths -import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType -import org.jetbrains.jps.incremental.ModuleBuildTarget -/** - * @author nik - */ -public class ModuleClasspathTest extends JpsBuildTestCase { - @Override - protected void setUp() { - super.setUp() - addJdk("1.6", "/jdk.jar") - addJdk("1.5", "/jdk15.jar") - loadProject("moduleClasspath/moduleClasspath.ipr") - } - - private String getProjectPath() { - return FileUtil.toSystemIndependentName(getTestDataRootPath()) + "/moduleClasspath/moduleClasspath.ipr" - } - - @Override - protected String getTestDataRootPath() { - char s = '/' - return FileUtil.toCanonicalPath(PathManagerEx.findFileUnderCommunityHome("jps/jps-builders/testData/output").absolutePath, s) - } - - public void testSimpleClasspath() { - assertClasspath('util', false, ["util/lib/exported.jar", "/jdk15.jar"]) - } - - public void testScopes() { - assertClasspath("test-util", false, - ["/jdk.jar", "test-util/lib/provided.jar"]) - assertClasspath("test-util", true, - ["/jdk.jar", "test-util/lib/provided.jar", "test-util/lib/test.jar", "out/production/test-util"]) - } - - public void testDepModules() { - assertClasspath("main", false, - ["util/lib/exported.jar", "out/production/util", "/jdk.jar", "main/lib/service.jar"]) - assertClasspath("main", true, - ["out/production/main", "util/lib/exported.jar", "out/test/util", "out/production/util", "/jdk.jar", - "out/test/test-util", "out/production/test-util", "main/lib/service.jar"]) - } - - public void testCompilationClasspath() { - ModuleChunk chunk = createChunk('main') - assertClasspath(["util/lib/exported.jar", "out/production/util", "/jdk.jar"], - getPathsList(ProjectPaths.getPlatformCompilationClasspath(chunk, true))) - assertClasspath(["main/lib/service.jar"], - getPathsList(ProjectPaths.getCompilationClasspath(chunk, true))) - } - - private def assertClasspath(String moduleName, boolean includeTests, List expected) { - ModuleChunk chunk = createChunk(moduleName) - final List classpath = getPathsList(new ProjectPaths().getCompilationClasspathFiles(chunk, includeTests, true, true)) - assertClasspath(expected, toSystemIndependentPaths(classpath)) - } - - private ModuleChunk createChunk(String moduleName) { - def module = myProject.modules.find {it.name == moduleName} - return new ModuleChunk([new ModuleBuildTarget(module, JavaModuleBuildTargetType.PRODUCTION)] as Set) - } - - private def assertClasspath(List expected, List classpath) { - String basePath = FileUtil.toSystemIndependentName(new File(getProjectPath()).parentFile.absolutePath) + "/" - List actual = toSystemIndependentPaths(classpath).collect { String path -> - path.startsWith(basePath) ? path.substring(basePath.length()) : path - } - assertEquals(expected.join("\n"), actual.join("\n")) - } - - private static List toSystemIndependentPaths(List classpath) { - final List result = new ArrayList() - for (String path: classpath) { - result.add(FileUtil.toSystemIndependentName(path)); - } - return result - } - - public static List getPathsList(Collection files) { - final List result = new ArrayList(); - for (File file : files) { - result.add(getCanonicalPath(file)); - } - return result; - } - private static String getCanonicalPath(File file) { - final String path = file.getPath(); - return path.contains(".")? FileUtil.toCanonicalPath(path) : FileUtil.toSystemIndependentName(path); - } -} diff --git a/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.kt b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.kt new file mode 100644 index 000000000000..21262499ca8d --- /dev/null +++ b/jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.kt @@ -0,0 +1,98 @@ +/* + * Copyright 2000-2014 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.jps.builders + +import com.intellij.openapi.application.ex.PathManagerEx +import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.io.FileUtil.* +import org.jetbrains.jps.ModuleChunk +import org.jetbrains.jps.ProjectPaths +import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType +import org.jetbrains.jps.incremental.ModuleBuildTarget +import java.io.File +import com.intellij.openapi.util.text.StringUtil +import org.junit.Assert +import java.util.Collections + +/** + * @author nik + */ +public class ModuleClasspathTest(): JpsBuildTestCase() { + override fun setUp() { + super.setUp() + addJdk("1.6", "/jdk.jar") + addJdk("1.5", "/jdk15.jar") + loadProject("moduleClasspath/moduleClasspath.ipr") + } + + private fun getProjectPath(): String { + return FileUtil.toSystemIndependentName(getTestDataRootPath()) + "/moduleClasspath/moduleClasspath.ipr" + } + + override fun getTestDataRootPath(): String { + return FileUtil.toCanonicalPath(PathManagerEx.findFileUnderCommunityHome("jps/jps-builders/testData/output")!!.getAbsolutePath(), '/')!! + } + + public fun testSimpleClasspath() { + assertClasspath("util", false, listOf("util/lib/exported.jar", "/jdk15.jar")) + } + + public fun testScopes() { + assertClasspath("test-util", false, listOf("/jdk.jar", "test-util/lib/provided.jar")) + assertClasspath("test-util", true, listOf("/jdk.jar", "test-util/lib/provided.jar", "test-util/lib/test.jar", "out/production/test-util")) + } + + public fun testDepModules() { + assertClasspath("main", false, listOf("util/lib/exported.jar", "out/production/util", "/jdk.jar", "main/lib/service.jar")) + assertClasspath("main", true, listOf("out/production/main", "util/lib/exported.jar", "out/test/util", "out/production/util", "/jdk.jar", "out/test/test-util", "out/production/test-util", "main/lib/service.jar")) + } + + public fun testCompilationClasspath() { + val chunk = createChunk("main") + assertClasspath(listOf("util/lib/exported.jar", "out/production/util", "/jdk.jar"), getPathsList(ProjectPaths.getPlatformCompilationClasspath(chunk, true))) + assertClasspath(listOf("main/lib/service.jar"), getPathsList(ProjectPaths.getCompilationClasspath(chunk, true))) + } + + private fun assertClasspath(moduleName: String, includeTests: Boolean, expected: List) { + val classpath = getPathsList(ProjectPaths.getCompilationClasspathFiles(createChunk(moduleName), includeTests, true, true)) + assertClasspath(expected, toSystemIndependentPaths(classpath)) + } + + private fun createChunk(moduleName: String): ModuleChunk { + val module = myProject!!.getModules().firstOrNull { it.getName() == moduleName } + return ModuleChunk(setOf(ModuleBuildTarget(module!!, JavaModuleBuildTargetType.PRODUCTION))) + } + + private fun assertClasspath(expected: List, classpath: List) { + val basePath = FileUtil.toSystemIndependentName(File(getProjectPath()).getParentFile()!!.getAbsolutePath()) + "/" + val actual = toSystemIndependentPaths(classpath).map { StringUtil.trimStart(it, basePath) } + Assert.assertEquals(expected.makeString("\n"), actual.makeString("\n")) + } + + private fun toSystemIndependentPaths(classpath: List): List { + return classpath.map(FileUtil::toSystemIndependentName) + } + + public fun getPathsList(files: Collection): List { + return files.map(::getCanonicalPath) + } +} + +private fun getCanonicalPath(file: File): String { + val path = file.getPath() + return if (path.contains(".")) FileUtil.toCanonicalPath(path)!! else FileUtil.toSystemIndependentName(path) +} +