diff --git a/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTestCase.java b/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTestCase.java index 8c5d57d4293..0e58632ba7c 100644 --- a/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTestCase.java +++ b/jps-plugin/test/org/jetbrains/jet/jps/build/KotlinJpsBuildTestCase.java @@ -36,6 +36,9 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { private static final String PROJECT_NAME = "kotlinProject"; private static final String JDK_NAME = "IDEA_JDK"; + private static final String[] EXCLUDE_FILES = { "Excluded.class", "YetAnotherExcluded.class" }; + private static final String[] NOTHING = {}; + @Override public void setUp() throws Exception { super.setUp(); @@ -74,34 +77,88 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { public void testKotlinProject() { doTest(); - assertOutputDeletedPackageInModule("kotlinProject", "src/test1.kt", "_DefaultPackage"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/test1.kt", "_DefaultPackage"); } public void testExcludeFolderInSourceRoot() { doTest(); JpsModule module = myProject.getModules().get(0); - assertFileExistsInOutput(module, "Foo.class"); + assertFilesExistInOutput(module, "Foo.class"); + assertFilesNotExistInOutput(module, EXCLUDE_FILES); - assertOutputDeletedInModule("kotlinProject", "src/foo.kt", "Foo"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/foo.kt", "Foo"); } public void testExcludeModuleFolderInSourceRootOfAnotherModule() { doTest(); for (JpsModule module : myProject.getModules()) { - assertFileExistsInOutput(module, "Foo.class"); + assertFilesExistInOutput(module, "Foo.class"); } - assertOutputDeletedInModule("kotlinProject", "src/foo.kt", "Foo"); - assertOutputDeletedInModule("module2", "src/module2/src/foo.kt", "Foo"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/foo.kt", "Foo"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "module2", "src/module2/src/foo.kt", "Foo"); + } + + public void testExcludeFileUsingCompilerSettings() { + doTest(); + + JpsModule module = myProject.getModules().get(0); + assertFilesExistInOutput(module, "Foo.class", "Bar.class"); + assertFilesNotExistInOutput(module, EXCLUDE_FILES); + + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/foo.kt", "Foo"); + checkExcludesNotAffectedToOutput("kotlinProject", "src/Excluded.kt", "src/dir/YetAnotherExcluded.kt"); + } + + public void testExcludeFolderNonRecursivelyUsingCompilerSettings() { + doTest(); + + JpsModule module = myProject.getModules().get(0); + assertFilesExistInOutput(module, "Foo.class", "Bar.class"); + assertFilesNotExistInOutput(module, EXCLUDE_FILES); + + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/foo.kt", "Foo"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/dir/subdir/bar.kt", "Bar"); + checkExcludesNotAffectedToOutput("kotlinProject", "src/dir/Excluded.kt", "src/dir/subdir/YetAnotherExcluded.kt"); + } + + public void testExcludeFolderRecursivelyUsingCompilerSettings() { + doTest(); + + JpsModule module = myProject.getModules().get(0); + assertFilesExistInOutput(module, "Foo.class", "Bar.class"); + assertFilesNotExistInOutput(module, EXCLUDE_FILES); + + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/foo.kt", "Foo"); + checkExcludesNotAffectedToOutput("kotlinProject", + "src/exclude/Excluded.kt", "src/exclude/YetAnotherExcluded.kt", + "src/exclude/subdir/Excluded.kt", "src/exclude/subdir/YetAnotherExcluded.kt"); + } + + public void testManyFiles() { + doTest(); + + JpsModule module = myProject.getModules().get(0); + assertFilesExistInOutput(module, "foo/FooPackage.class", "boo/BooPackage.class", "foo/Bar.class"); + + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/main.kt", "foo.FooPackage"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/boo.kt", "boo.BooPackage"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/Bar.kt", "foo.Bar", "foo.FooPackage"); + + checkPackageDeletedFromOutputWhen(Operation.DELETE, "kotlinProject", "src/main.kt", "foo.FooPackage"); + assertFilesNotExistInOutput(module, "foo/FooPackage.class"); + + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/boo.kt", "boo.BooPackage"); + checkClassesDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/Bar.kt", "foo.Bar"); } public void testKotlinProjectTwoFilesInOnePackage() { doTest(); - assertOutputDeletedPackageInModule("kotlinProject", "src/test1.kt", "_DefaultPackage"); - assertOutputDeletedPackageInModule("kotlinProject", "src/test2.kt", "_DefaultPackage"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/test1.kt", "_DefaultPackage"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/test2.kt", "_DefaultPackage"); } public void testKotlinJavaProject() { @@ -139,16 +196,16 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { // Check that outputs are located properly for (JpsModule module : myProject.getModules()) { if (module.getName().equals("module2")) { - assertFileExistsInOutput(module, "kt1/Kt1Package.class"); + assertFilesExistInOutput(module, "kt1/Kt1Package.class"); } if (module.getName().equals("kotlinProject")) { - assertFileExistsInOutput(module, "kt2/Kt2Package.class"); + assertFilesExistInOutput(module, "kt2/Kt2Package.class"); } } result.assertSuccessful(); - assertOutputDeletedPackageInModule("kotlinProject", "src/kt2.kt", "kt2.Kt2Package"); - assertOutputDeletedPackageInModule("module2", "module2/src/kt1.kt", "kt1.Kt1Package"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "kotlinProject", "src/kt2.kt", "kt2.Kt2Package"); + checkPackageDeletedFromOutputWhen(Operation.CHANGE, "module2", "module2/src/kt1.kt", "kt1.Kt1Package"); } public void testReexportedDependency() { @@ -163,16 +220,35 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { makeAll().assertSuccessful(); } - private static void assertFileExistsInOutput(JpsModule module, String relativePath) { + private static void assertFilesExistInOutput(JpsModule module, String... relativePaths) { String outputUrl = JpsJavaExtensionService.getInstance().getOutputUrl(module, false); assertNotNull(outputUrl); File outputDir = new File(JpsPathUtil.urlToPath(outputUrl)); - File outputFile = new File(outputDir, relativePath); - assertTrue("Output not written: " + - outputFile.getAbsolutePath() + - "\n Directory contents: \n" + - dirContents(outputFile.getParentFile()), - outputFile.exists()); + for (String path : relativePaths) { + File outputFile = new File(outputDir, path); + assertTrue("Output not written: " + + outputFile.getAbsolutePath() + + "\n Directory contents: \n" + + dirContents(outputFile.getParentFile()), + outputFile.exists()); + } + } + + private void checkExcludesNotAffectedToOutput(String module, String... excludeRelativePaths) { + for (String path : excludeRelativePaths) { + checkClassesDeletedFromOutputWhen(Operation.CHANGE, module, path, NOTHING); + } + } + + private static void assertFilesNotExistInOutput(JpsModule module, String... relativePaths) { + String outputUrl = JpsJavaExtensionService.getInstance().getOutputUrl(module, false); + assertNotNull(outputUrl); + File outputDir = new File(JpsPathUtil.urlToPath(outputUrl)); + for (String path : relativePaths) { + File outputFile = new File(outputDir, path); + assertFalse("Output directory \"" + outputFile.getAbsolutePath() + "\" contains \"" + path + "\"", + outputFile.exists()); + } } private static String dirContents(File dir) { @@ -187,30 +263,51 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { return builder.toString(); } - private void assertOutputDeletedPackageInModule(String moduleName, String sourceFileName, String packageClassFqNames) { + private void checkPackageDeletedFromOutputWhen( + Operation operation, + String moduleName, + String sourceFileName, + String packageClassFqNamesToDelete + ) { File file = new File(workDir, sourceFileName); - String[] packageClasses = { packageClassFqNames, getInternalNameForPackagePartClass(file, packageClassFqNames) }; + String[] packageClasses = { packageClassFqNamesToDelete, getInternalNameForPackagePartClass(file, packageClassFqNamesToDelete) }; - assertOutputDeletedInModule(moduleName, sourceFileName, packageClasses); + checkClassesDeletedFromOutputWhen(operation, moduleName, sourceFileName, packageClasses); } - private void assertOutputDeletedInModule(final String moduleName, String sourceFileName, String... classFqNames) { - String[] paths = ContainerUtil.map2Array(classFqNames, String.class, new Function() { + private void checkClassesDeletedFromOutputWhen( + Operation operation, + final String moduleName, + String sourceFileName, + String... classFqNamesToDelete + ) { + String[] paths = ContainerUtil.map2Array(classFqNamesToDelete, String.class, new Function() { @Override public String fun(String classFqName) { return outputPathInModuleByClassFqName(moduleName, classFqName); } }); - assertOutputDeleted(sourceFileName, paths); + checkFilesDeletedFromOutputWhen(operation, sourceFileName, paths); } - private void assertOutputDeleted(String sourceFileName, String... paths) { + private void checkFilesDeletedFromOutputWhen(Operation operation, String sourceFileName, String... pathsToDelete) { File file = new File(workDir, sourceFileName); - change(file.getAbsolutePath()); + + if (operation == Operation.CHANGE) { + change(file.getAbsolutePath()); + } + else if(operation == Operation.DELETE) { + assertTrue("Can not delete file \"" + file.getAbsolutePath() + "\"", + file.delete()); + } + else { + fail("Unknown operation"); + } + makeAll().assertSuccessful(); - assertDeleted(paths); + assertDeleted(pathsToDelete); } private static String outputPathInModuleByClassFqName(String moduleName, String classFqName) { @@ -228,4 +325,8 @@ public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase { }; return NamespaceCodegen.getNamespacePartType(new FqName(packageClassFqName), fakeVirtualFile).getInternalName(); } + + private static enum Operation { + CHANGE, DELETE + } } diff --git a/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.iml b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.iml new file mode 100644 index 00000000000..0c4fb67a3d4 --- /dev/null +++ b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.ipr b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.ipr new file mode 100644 index 00000000000..da39ecb6ab2 --- /dev/null +++ b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/kotlinProject.ipr @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/Excluded.kt b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/Excluded.kt new file mode 100644 index 00000000000..06d7528e228 --- /dev/null +++ b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/Excluded.kt @@ -0,0 +1 @@ +class Excluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/YetAnotherExcluded.kt b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/YetAnotherExcluded.kt new file mode 100644 index 00000000000..4b5f5c0c428 --- /dev/null +++ b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/YetAnotherExcluded.kt @@ -0,0 +1 @@ +class YetAnotherExcluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/bar.kt b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/bar.kt new file mode 100644 index 00000000000..4a643c4dde8 --- /dev/null +++ b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/dir/bar.kt @@ -0,0 +1 @@ +class Bar \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderInSourceRoot/src/exclude/foo.kt b/jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/foo.kt similarity index 100% rename from jps-plugin/testData/ExcludeFolderInSourceRoot/src/exclude/foo.kt rename to jps-plugin/testData/ExcludeFileUsingCompilerSettings/src/foo.kt diff --git a/jps-plugin/testData/ExcludeFolderInSourceRoot/src/exclude/Excluded.kt b/jps-plugin/testData/ExcludeFolderInSourceRoot/src/exclude/Excluded.kt new file mode 100644 index 00000000000..06d7528e228 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderInSourceRoot/src/exclude/Excluded.kt @@ -0,0 +1 @@ +class Excluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.iml b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.iml new file mode 100644 index 00000000000..0c4fb67a3d4 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.ipr b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.ipr new file mode 100644 index 00000000000..852485b023c --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/kotlinProject.ipr @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/Excluded.kt b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/Excluded.kt new file mode 100644 index 00000000000..06d7528e228 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/Excluded.kt @@ -0,0 +1 @@ +class Excluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/YetAnotherExcluded.kt b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/YetAnotherExcluded.kt new file mode 100644 index 00000000000..4b5f5c0c428 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/YetAnotherExcluded.kt @@ -0,0 +1 @@ +class YetAnotherExcluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/bar.kt b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/bar.kt new file mode 100644 index 00000000000..4a643c4dde8 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/dir/subdir/bar.kt @@ -0,0 +1 @@ +class Bar \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/foo.kt b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/foo.kt new file mode 100644 index 00000000000..43c42f1453b --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderNonRecursivelyUsingCompilerSettings/src/foo.kt @@ -0,0 +1 @@ +class Foo \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.iml b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.iml new file mode 100644 index 00000000000..0c4fb67a3d4 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.ipr b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.ipr new file mode 100644 index 00000000000..9b497ed5475 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/kotlinProject.ipr @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/bar.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/bar.kt new file mode 100644 index 00000000000..4a643c4dde8 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/bar.kt @@ -0,0 +1 @@ +class Bar \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/Excluded.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/Excluded.kt new file mode 100644 index 00000000000..06d7528e228 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/Excluded.kt @@ -0,0 +1 @@ +class Excluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/YetAnotherExcluded.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/YetAnotherExcluded.kt new file mode 100644 index 00000000000..4b5f5c0c428 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/YetAnotherExcluded.kt @@ -0,0 +1 @@ +class YetAnotherExcluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/Excluded.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/Excluded.kt new file mode 100644 index 00000000000..06d7528e228 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/Excluded.kt @@ -0,0 +1 @@ +class Excluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/YetAnotherExcluded.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/YetAnotherExcluded.kt new file mode 100644 index 00000000000..4b5f5c0c428 --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/exclude/subdir/YetAnotherExcluded.kt @@ -0,0 +1 @@ +class YetAnotherExcluded \ No newline at end of file diff --git a/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/foo.kt b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/foo.kt new file mode 100644 index 00000000000..43c42f1453b --- /dev/null +++ b/jps-plugin/testData/ExcludeFolderRecursivelyUsingCompilerSettings/src/foo.kt @@ -0,0 +1 @@ +class Foo \ No newline at end of file diff --git a/jps-plugin/testData/ManyFiles/kotlinProject.iml b/jps-plugin/testData/ManyFiles/kotlinProject.iml new file mode 100644 index 00000000000..0c4fb67a3d4 --- /dev/null +++ b/jps-plugin/testData/ManyFiles/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps-plugin/testData/ManyFiles/kotlinProject.ipr b/jps-plugin/testData/ManyFiles/kotlinProject.ipr new file mode 100644 index 00000000000..8226e21ade3 --- /dev/null +++ b/jps-plugin/testData/ManyFiles/kotlinProject.ipr @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/jps-plugin/testData/ManyFiles/src/Bar.kt b/jps-plugin/testData/ManyFiles/src/Bar.kt new file mode 100644 index 00000000000..2c990ada4c7 --- /dev/null +++ b/jps-plugin/testData/ManyFiles/src/Bar.kt @@ -0,0 +1,3 @@ +package foo + +class Bar diff --git a/jps-plugin/testData/ManyFiles/src/boo.kt b/jps-plugin/testData/ManyFiles/src/boo.kt new file mode 100644 index 00000000000..e9a050624da --- /dev/null +++ b/jps-plugin/testData/ManyFiles/src/boo.kt @@ -0,0 +1,6 @@ +package boo + +import foo.Bar + +fun boo(bar: Bar) { +} diff --git a/jps-plugin/testData/ManyFiles/src/main.kt b/jps-plugin/testData/ManyFiles/src/main.kt new file mode 100644 index 00000000000..cfcbc18690b --- /dev/null +++ b/jps-plugin/testData/ManyFiles/src/main.kt @@ -0,0 +1,8 @@ +package foo + +import boo.boo + +fun main(args: Array) { + val bar = Bar() + boo(bar) +}