summaryrefslogtreecommitdiff
path: root/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler')
-rw-r--r--plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleCompilingTestCase.java89
-rw-r--r--plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java132
-rw-r--r--plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceProcessingTest.java176
3 files changed, 397 insertions, 0 deletions
diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleCompilingTestCase.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleCompilingTestCase.java
new file mode 100644
index 000000000000..3b508c8cf289
--- /dev/null
+++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleCompilingTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.plugins.gradle.compiler;
+
+import com.intellij.compiler.artifacts.ArtifactsTestUtil;
+import com.intellij.openapi.application.AccessToken;
+import com.intellij.openapi.application.ReadAction;
+import com.intellij.openapi.compiler.CompileContext;
+import com.intellij.openapi.compiler.CompileTask;
+import com.intellij.openapi.compiler.CompilerManager;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.packaging.impl.artifacts.ArtifactUtil;
+import com.intellij.util.io.TestFileSystemItem;
+import org.jetbrains.plugins.gradle.config.GradleResourceCompilerConfigurationGenerator;
+import org.jetbrains.plugins.gradle.importing.GradleImportingTestCase;
+
+import java.io.File;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 7/21/2014
+ */
+public abstract class GradleCompilingTestCase extends GradleImportingTestCase {
+ @Override
+ protected void setUpInWriteAction() throws Exception {
+ super.setUpInWriteAction();
+ CompilerManager.getInstance(myProject).addBeforeTask(new CompileTask() {
+ @Override
+ public boolean execute(CompileContext context) {
+ AccessToken token = ReadAction.start();
+ try {
+ new GradleResourceCompilerConfigurationGenerator(myProject, context).generateBuildConfiguration();
+ }
+ finally {
+ token.finish();
+ }
+ return true;
+ }
+ });
+ }
+
+ protected void assertCopied(String path) {
+ assertTrue(new File(myProjectConfig.getParent().getPath(), path).exists());
+ }
+
+ protected void assertCopied(String path, String content) {
+ assertCopied(path);
+ assertSameLinesWithFile(new File(myProjectConfig.getParent().getPath(), path).getPath(), content);
+ }
+
+ protected void assertNotCopied(String path) {
+ assertFalse(new File(myProjectConfig.getParent().getPath(), path).exists());
+ }
+
+ @Override
+ protected void assertArtifactOutputPath(String artifactName, String expected) {
+ final String defaultArtifactOutputPath = ArtifactUtil.getDefaultArtifactOutputPath(artifactName, myProject);
+ assert defaultArtifactOutputPath != null;
+ final String basePath = FileUtil.toSystemIndependentName(new File(defaultArtifactOutputPath).getParent());
+ super.assertArtifactOutputPath(artifactName, basePath + expected);
+ }
+
+ protected void assertArtifactOutputFile(String artifactName, String path, String content) {
+ final String defaultArtifactOutputPath = ArtifactUtil.getDefaultArtifactOutputPath(artifactName, myProject);
+ assert defaultArtifactOutputPath != null;
+ final String basePath = FileUtil.toSystemIndependentName(new File(defaultArtifactOutputPath).getParent());
+ assertSameLinesWithFile(basePath + path, content);
+ }
+
+ protected void assertArtifactOutputFile(String artifactName, String path) {
+ final String defaultArtifactOutputPath = ArtifactUtil.getDefaultArtifactOutputPath(artifactName, myProject);
+ assert defaultArtifactOutputPath != null;
+ final String basePath = FileUtil.toSystemIndependentName(new File(defaultArtifactOutputPath).getParent());
+ assertExists(new File(basePath + path));
+ }
+}
diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java
new file mode 100644
index 000000000000..df9c6a879ac7
--- /dev/null
+++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.plugins.gradle.compiler;
+
+import org.junit.Test;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 7/21/2014
+ */
+@SuppressWarnings("JUnit4AnnotatedMethodInJUnit3TestCase")
+public class GradleResourceFilteringTest extends GradleCompilingTestCase {
+
+ @Test
+ public void testHeadFilter() throws Exception {
+ createProjectSubFile(
+ "src/main/resources/dir/file.txt", "1 Header\n" +
+ "2\n" +
+ "3 another text\n" +
+ "4\n" +
+ "5 another text \n" +
+ "6 another text @token@ another text\n" +
+ "7\n" +
+ "8 Footer");
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "import org.apache.tools.ant.filters.*\n" +
+ "processResources {\n" +
+ " filter(HeadFilter, lines:3, skip:2)\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("build/resources/main/dir/file.txt", "3 another text\n" +
+ "4\n" +
+ "5 another text \n");
+ }
+
+ @Test
+ public void testReplaceTokensFilter() throws Exception {
+ createProjectSubFile(
+ "src/main/resources/dir/file.txt", "1 Header\n" +
+ "2\n" +
+ "3 #token1#another text\n" +
+ "4\n" +
+ "5 another text \n" +
+ "6 another text #token2# another text\n" +
+ "7\n" +
+ "8 Footer");
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "import org.apache.tools.ant.filters.*\n" +
+ "processResources {\n" +
+ " filter(ReplaceTokens, tokens:[token1:'<11111>', token2:'<2222>'], beginToken: '#', endToken: '#')\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("build/resources/main/dir/file.txt", "1 Header\n" +
+ "2\n" +
+ "3 <11111>another text\n" +
+ "4\n" +
+ "5 another text \n" +
+ "6 another text <2222> another text\n" +
+ "7\n" +
+ "8 Footer");
+ }
+
+ @Test
+ public void testRenameFilter() throws Exception {
+ createProjectSubFile("src/main/resources/dir/file.txt");
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "import org.apache.tools.ant.filters.*\n" +
+ "processResources {\n" +
+ " rename 'file.txt', 'file001.txt'\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("build/resources/main/dir/file001.txt");
+ }
+
+ @Test
+ public void testFiltersChain() throws Exception {
+ createProjectSubFile(
+ "src/main/resources/dir/file.txt", "1 Header\n" +
+ "2\n" +
+ "3 another text@token1@\n" +
+ "4\n" +
+ "5 another text \n" +
+ "6 another text @token2@ another text\n" +
+ "7\n" +
+ "8 Footer");
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "import org.apache.tools.ant.filters.*\n" +
+ "processResources {\n" +
+ " filter(HeadFilter, lines:4, skip:2)\n" +
+ " filter(ReplaceTokens, tokens:[token1:'<11111>', token2:'<2222>'])\n" +
+ " rename 'file.txt', 'file001.txt'\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("build/resources/main/dir/file001.txt", "3 another text<11111>\n" +
+ "4\n" +
+ "5 another text \n" +
+ "6 another text <2222> another text");
+ }
+} \ No newline at end of file
diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceProcessingTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceProcessingTest.java
new file mode 100644
index 000000000000..873234425e30
--- /dev/null
+++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceProcessingTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.plugins.gradle.compiler;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 7/21/2014
+ */
+@SuppressWarnings("JUnit4AnnotatedMethodInJUnit3TestCase")
+public class GradleResourceProcessingTest extends GradleCompilingTestCase {
+
+ @Test
+ public void testBasicResourceCopying() throws Exception {
+ createProjectSubFile("src/main/resources/dir/file.properties");
+ createProjectSubFile("src/test/resources/dir/file-test.properties");
+ importProject(
+ "apply plugin: 'java'"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("build/resources/main/dir/file.properties");
+ assertCopied("build/resources/test/dir/file-test.properties");
+ }
+
+ @Test
+ public void testResourceProcessingWithIdeaGradlePluginCustomization() throws Exception {
+ createProjectSubFile("src/main/resources/dir/file.properties");
+ createProjectSubFile("src/test/resources/dir/file-test.properties");
+ importProject(
+ "apply plugin: 'java'\n" +
+ "apply plugin: 'idea'\n" +
+ "idea {\n" +
+ " module {\n" +
+ " inheritOutputDirs = false\n" +
+ " outputDir = file('muchBetterOutputDir')\n" +
+ " testOutputDir = file('muchBetterTestOutputDir')\n" +
+ " }\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopied("muchBetterOutputDir/dir/file.properties");
+ assertCopied("muchBetterTestOutputDir/dir/file-test.properties");
+ }
+
+ @Test
+ public void testIncludesAndExcludesInSourceSets() throws Exception {
+ createFilesForIncludesAndExcludesTest();
+
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "sourceSets {\n" +
+ " main {\n" +
+ " resources {\n" +
+ " include '**/*.yyy'\n" +
+ " include '**/*.xxx'\n" +
+ " exclude 'dir/*.yyy'\n" +
+ " exclude '*.xxx'\n" +
+ " }\n" +
+ " }\n" +
+ " test {\n" +
+ " resources {\n" +
+ " include '**/*.yyy'\n" +
+ " include '**/*.xxx'\n" +
+ " exclude 'dir/*.yyy'\n" +
+ " exclude '*.xxx'\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopiedResources();
+ }
+
+ @Test
+ public void testIncludesAndExcludesInAllSourceSets() throws Exception {
+ createFilesForIncludesAndExcludesTest();
+
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "sourceSets.all {\n" +
+ " resources {\n" +
+ " include '**/*.yyy'\n" +
+ " include '**/*.xxx'\n" +
+ " exclude 'dir/*.yyy'\n" +
+ " exclude '*.xxx'\n" +
+ " }\n" +
+ "}"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopiedResources();
+ }
+
+
+ @Test
+ public void testIncludesAndExcludesInResourcesTask() throws Exception {
+ createFilesForIncludesAndExcludesTest();
+
+ importProject(
+ "apply plugin: 'java'\n" +
+ "\n" +
+ "processResources {\n" +
+ " include '**/*.yyy'\n" +
+ " include '**/*.xxx'\n" +
+ " exclude 'dir/*.yyy'\n" +
+ " exclude '*.xxx'\n" +
+ "}\n" +
+ "\n" +
+ "processTestResources {\n" +
+ " include '**/*.yyy'\n" +
+ " include '**/*.xxx'\n" +
+ " exclude 'dir/*.yyy'\n" +
+ " exclude '*.xxx'\n" +
+ "}\n"
+ );
+ assertModules("project");
+ compileModules("project");
+
+ assertCopiedResources();
+ }
+
+ private void createFilesForIncludesAndExcludesTest() throws IOException {
+ createProjectSubFile("src/main/resources/dir/file.xxx");
+ createProjectSubFile("src/main/resources/dir/file.yyy");
+ createProjectSubFile("src/main/resources/file.xxx");
+ createProjectSubFile("src/main/resources/file.yyy");
+ createProjectSubFile("src/main/resources/file.zzz");
+
+ createProjectSubFile("src/test/resources/dir/file.xxx");
+ createProjectSubFile("src/test/resources/dir/file.yyy");
+ createProjectSubFile("src/test/resources/file.xxx");
+ createProjectSubFile("src/test/resources/file.yyy");
+ createProjectSubFile("src/test/resources/file.zzz");
+ }
+
+ private void assertCopiedResources() {
+ // assert production resources
+ assertCopied("build/resources/main/dir/file.xxx");
+ assertCopied("build/resources/main/file.yyy");
+ assertNotCopied("build/resources/main/dir/file.yyy");
+ assertNotCopied("build/resources/main/file.xxx");
+ assertNotCopied("build/resources/main/file.zzz");
+
+ // assert test resources
+ assertCopied("build/resources/test/dir/file.xxx");
+ assertCopied("build/resources/test/file.yyy");
+ assertNotCopied("build/resources/test/dir/file.yyy");
+ assertNotCopied("build/resources/test/file.xxx");
+ assertNotCopied("build/resources/test/file.zzz");
+ }
+}