diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.groovy deleted file mode 100644 index 9eacec315..000000000 --- a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. - * - * 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 com.palantir.baseline - -import com.palantir.baseline.plugins.BaselineJavaCompilerDiagnostics -import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification - -class BaselineJavaCompilerDiagnosticsTest extends Specification { - - def testDefault() { - when: - def project = ProjectBuilder.builder().build() - project.buildscript { - repositories { - mavenCentral() - } - } - project.plugins.apply 'java' - project.plugins.apply BaselineJavaCompilerDiagnostics - project.evaluate() - - then: - JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) - List allJvmArgs = compileTask.options.allCompilerArgs - allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 - allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '10000' - allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 - allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '10000' - } - - def testOverridden() { - when: - def project = ProjectBuilder.builder().build() - project.buildscript { - repositories { - mavenCentral() - } - } - project.plugins.apply 'java' - project.tasks.withType(JavaCompile) { - options.compilerArgs += [ - '-Xmaxerrs', '1000' - ] - } - project.plugins.apply BaselineJavaCompilerDiagnostics - project.evaluate() - - then: - project.tasks.type - JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) - List allJvmArgs = compileTask.options.allCompilerArgs - allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 - allJvmArgs.get(allJvmArgs.indexOf("-Xmaxerrs") + 1) == '1000' - allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 - } -} diff --git a/gradle-baseline-java/src/test/java/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.java b/gradle-baseline-java/src/test/java/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.java new file mode 100644 index 000000000..a2ae0e345 --- /dev/null +++ b/gradle-baseline-java/src/test/java/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.java @@ -0,0 +1,104 @@ +/* + * (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. + * + * 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 com.palantir.baseline; + +import static com.palantir.gradle.testing.assertion.GradlePluginTestAssertions.assertThat; + +import com.palantir.gradle.testing.execution.GradleInvoker; +import com.palantir.gradle.testing.execution.InvocationResult; +import com.palantir.gradle.testing.junit.DisabledConfigurationCache; +import com.palantir.gradle.testing.junit.GradlePluginTests; +import com.palantir.gradle.testing.project.RootProject; +import org.junit.jupiter.api.Test; + +@GradlePluginTests +@DisabledConfigurationCache("ProjectBuilder-based test converted to integration test") +class BaselineJavaCompilerDiagnosticsTest { + + @Test + void test_default(GradleInvoker gradle, RootProject rootProject) { + rootProject.buildGradle().plugins().add("java"); + rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics"); + + rootProject.buildGradle().append(""" + repositories { + mavenCentral() + } + + tasks.withType(JavaCompile).configureEach { + doFirst { + logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs) + } + } + """); + + rootProject.mainSourceSet().java().writeClass(""" + package com.example; + + public class Main { + public static void main(String[] args) { + System.out.println("Hello World"); + } + } + """); + + InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully(); + + assertThat(result).output().as("Xmaxerrs should be set to 10000").contains("-Xmaxerrs", "10000"); + + assertThat(result).output().as("Xmaxwarns should be set to 10000").contains("-Xmaxwarns", "10000"); + } + + @Test + void test_overridden(GradleInvoker gradle, RootProject rootProject) { + rootProject.buildGradle().plugins().add("java"); + + rootProject.buildGradle().append(""" + repositories { + mavenCentral() + } + + tasks.named('compileJava', JavaCompile) { + options.compilerArgs += ['-Xmaxerrs', '1000'] + } + + tasks.withType(JavaCompile).configureEach { + doFirst { + logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs) + } + } + """); + + rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics"); + + rootProject.mainSourceSet().java().writeClass(""" + package com.example; + + public class Main { + public static void main(String[] args) { + System.out.println("Hello World"); + } + } + """); + + InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully(); + + assertThat(result).output().as("Xmaxerrs should be overridden to 1000").contains("-Xmaxerrs", "1000"); + + assertThat(result).output().as("Xmaxwarns should still be present").contains("-Xmaxwarns"); + } +} diff --git a/test-migration-notes/BaselineJavaCompilerDiagnosticsTest.html b/test-migration-notes/BaselineJavaCompilerDiagnosticsTest.html new file mode 100644 index 000000000..ce5dde2b6 --- /dev/null +++ b/test-migration-notes/BaselineJavaCompilerDiagnosticsTest.html @@ -0,0 +1,2202 @@ + + + + + Diff to HTML by rtfpessoa + + + + + + + + + + + + + +

Diff to HTML by rtfpessoa

+ +
+
+
+
+ + gradle-baseline-java/src/test/{groovy/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.groovy → java/com/palantir/baseline/BaselineJavaCompilerDiagnosticsTest.java} + RENAMED + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
@@ -14,65 +14,97 @@
+
+ 14 + +
+   + * limitations under the License. +
+
+ 15 + +
+   + */ +
+
+ 16 + +
+   +
+
+
+ 17 + +
+ - + package com.palantir.baseline +
+
+ 18 + +
+   +
+
+
+ 19 + +
+ - + import com.palantir.baseline.plugins.BaselineJavaCompilerDiagnostics +
+
+ 20 + +
+ - + import org.gradle.api.tasks.compile.JavaCompile +
+
+ 21 + +
+ - + import org.gradle.testfixtures.ProjectBuilder +
+
+ 22 + +
+ - + import spock.lang.Specification +
+
+ 23 + +
+   +
+
+
+ 24 + +
+ - + class BaselineJavaCompilerDiagnosticsTest extends Specification { +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 25 + +
+   +
+
+
+ 26 + +
+   + // ***DELINEATOR FOR REVIEW: testDefault +
+
+ 27 + +
+ - + def testDefault() { +
+
+ + +
+   +
+
+
+ 28 + +
+   + // ***DELINEATOR FOR REVIEW: when +
+
+ 29 + +
+ - + when: +
+
+ 30 + +
+ - + def project = ProjectBuilder.builder().build() +
+
+ 31 + +
+ - + project.buildscript { +
+
+ + +
+   +
+
+
+ 32 + +
+   + repositories { +
+
+ 33 + +
+   + mavenCentral() +
+
+ 34 + +
+   + } +
+
+ 35 + +
+ - + } +
+
+ 36 + +
+ - + project.plugins.apply 'java' +
+
+ 37 + +
+ - + project.plugins.apply BaselineJavaCompilerDiagnostics +
+
+ 38 + +
+ - + project.evaluate() +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 39 + +
+   +
+
+
+ 40 + +
+   + // ***DELINEATOR FOR REVIEW: then +
+
+ 41 + +
+ - + then: +
+
+ 42 + +
+ - + JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) +
+
+ 43 + +
+ - + List<String> allJvmArgs = compileTask.options.allCompilerArgs +
+
+ 44 + +
+ - + allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 +
+
+ 45 + +
+ - + allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '10000' +
+
+ 46 + +
+ - + allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 +
+
+ 47 + +
+ - + allJvmArgs.get(allJvmArgs.indexOf('-Xmaxerrs') + 1) == '10000' +
+
+ 48 + +
+   + } +
+
+ 49 + +
+   +
+
+
+ 50 + +
+   + // ***DELINEATOR FOR REVIEW: testOverridden +
+
+ 51 + +
+ - + def testOverridden() { +
+
+ + +
+   +
+
+
+ 52 + +
+   + // ***DELINEATOR FOR REVIEW: when +
+
+ 53 + +
+ - + when: +
+
+ 54 + +
+ - + def project = ProjectBuilder.builder().build() +
+
+ 55 + +
+ - + project.buildscript { +
+
+ 56 + +
+   + repositories { +
+
+ 57 + +
+   + mavenCentral() +
+
+ 58 + +
+   + } +
+
+ 59 + +
+ - + } +
+
+ 60 + +
+ - + project.plugins.apply 'java' +
+
+ 61 + +
+ - + project.tasks.withType(JavaCompile) { +
+
+ 62 + +
+ - + options.compilerArgs += [ +
+
+ 63 + +
+ - + '-Xmaxerrs', '1000' +
+
+ 64 + +
+ - + ] +
+
+ 65 + +
+ - + } +
+
+ 66 + +
+ - + project.plugins.apply BaselineJavaCompilerDiagnostics +
+
+ 67 + +
+ - + project.evaluate() +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 68 + +
+   +
+
+
+ 69 + +
+   + // ***DELINEATOR FOR REVIEW: then +
+
+ 70 + +
+ - + then: +
+
+ 71 + +
+ - + project.tasks.type +
+
+ 72 + +
+ - + JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) +
+
+ 73 + +
+ - + List<String> allJvmArgs = compileTask.options.allCompilerArgs +
+
+ 74 + +
+ - + allJvmArgs.stream().filter('-Xmaxerrs'::equals).count() == 1 +
+
+ 75 + +
+ - + allJvmArgs.get(allJvmArgs.indexOf("-Xmaxerrs") + 1) == '1000' +
+
+ 76 + +
+ - + allJvmArgs.stream().filter('-Xmaxwarns'::equals).count() == 1 +
+
+ 77 + +
+   + } +
+
+ 78 + +
+   + } +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
 
+
+ 14 + +
+   + * limitations under the License. +
+
+ 15 + +
+   + */ +
+
+ 16 + +
+   +
+
+
+ 17 + +
+ + + package com.palantir.baseline; +
+
+ 18 + +
+   +
+
+
+ 19 + +
+ + + import static com.palantir.gradle.testing.assertion.GradlePluginTestAssertions.assertThat; +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 20 + +
+   +
+
+
+ 21 + +
+ + + import com.palantir.gradle.testing.execution.GradleInvoker; +
+
+ 22 + +
+ + + import com.palantir.gradle.testing.execution.InvocationResult; +
+
+ 23 + +
+ + + import com.palantir.gradle.testing.junit.DisabledConfigurationCache; +
+
+ 24 + +
+ + + import com.palantir.gradle.testing.junit.GradlePluginTests; +
+
+ 25 + +
+ + + import com.palantir.gradle.testing.project.RootProject; +
+
+ 26 + +
+ + + import org.junit.jupiter.api.Test; +
+
+ 27 + +
+ + +
+
+
+ 28 + +
+ + + @GradlePluginTests +
+
+ 29 + +
+ + + @DisabledConfigurationCache("ProjectBuilder-based test converted to integration test") +
+
+ 30 + +
+ + + class BaselineJavaCompilerDiagnosticsTest { +
+
+ 31 + +
+   +
+
+
+ 32 + +
+   + // ***DELINEATOR FOR REVIEW: testDefault +
+
+ 33 + +
+ + + @Test +
+
+ 34 + +
+ + + void test_default(GradleInvoker gradle, RootProject rootProject) { +
+
+ 35 + +
+   + // ***DELINEATOR FOR REVIEW: when +
+
+ 36 + +
+ + + rootProject.buildGradle().plugins().add("java"); +
+
+ 37 + +
+ + + rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics"); +
+
+ 38 + +
+ + +
+
+
+ 39 + +
+ + + rootProject.buildGradle().append(""" +
+
+ 40 + +
+   + repositories { +
+
+ 41 + +
+   + mavenCentral() +
+
+ 42 + +
+   + } +
+
+ 43 + +
+ + +
+
+
+ 44 + +
+ + + tasks.withType(JavaCompile).configureEach { +
+
+ 45 + +
+ + + doFirst { +
+
+ 46 + +
+ + + logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs) +
+
+ 47 + +
+ + + } +
+
+ 48 + +
+ + + } +
+
+ 49 + +
+ + + """); +
+
+ 50 + +
+ + +
+
+
+ 51 + +
+ + + rootProject.mainSourceSet().java().writeClass(""" +
+
+ 52 + +
+ + + package com.example; +
+
+ 53 + +
+ + +
+
+
+ 54 + +
+ + + public class Main { +
+
+ 55 + +
+ + + public static void main(String[] args) { +
+
+ 56 + +
+ + + System.out.println("Hello World"); +
+
+ 57 + +
+ + + } +
+
+ 58 + +
+ + + } +
+
+ 59 + +
+ + + """); +
+
+ 60 + +
+   +
+
+
+ 61 + +
+   + // ***DELINEATOR FOR REVIEW: then +
+
+ 62 + +
+ + + InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully(); +
+
+ 63 + +
+ + +
+
+
+ 64 + +
+ + + assertThat(result).output().as("Xmaxerrs should be set to 10000").contains("-Xmaxerrs", "10000"); +
+
+ 65 + +
+ + +
+
+
+ 66 + +
+ + + assertThat(result).output().as("Xmaxwarns should be set to 10000").contains("-Xmaxwarns", "10000"); +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 67 + +
+   + } +
+
+ 68 + +
+   +
+
+
+ 69 + +
+   + // ***DELINEATOR FOR REVIEW: testOverridden +
+
+ 70 + +
+ + + @Test +
+
+ 71 + +
+ + + void test_overridden(GradleInvoker gradle, RootProject rootProject) { +
+
+ 72 + +
+   + // ***DELINEATOR FOR REVIEW: when +
+
+ 73 + +
+ + + rootProject.buildGradle().plugins().add("java"); +
+
+ 74 + +
+ + +
+
+
+ 75 + +
+ + + rootProject.buildGradle().append(""" +
+
+ 76 + +
+   + repositories { +
+
+ 77 + +
+   + mavenCentral() +
+
+ 78 + +
+   + } +
+
+ 79 + +
+ + +
+
+
+ 80 + +
+ + + tasks.named('compileJava', JavaCompile) { +
+
+ 81 + +
+ + + options.compilerArgs += ['-Xmaxerrs', '1000'] +
+
+ 82 + +
+ + + } +
+
+ 83 + +
+ + +
+
+
+ 84 + +
+ + + tasks.withType(JavaCompile).configureEach { +
+
+ 85 + +
+ + + doFirst { +
+
+ 86 + +
+ + + logger.lifecycle("allCompilerArgs: {}", options.allCompilerArgs) +
+
+ 87 + +
+ + + } +
+
+ 88 + +
+ + + } +
+
+ 89 + +
+ + + """); +
+
+ 90 + +
+ + +
+
+
+ 91 + +
+ + + rootProject.buildGradle().plugins().add("com.palantir.baseline-java-compiler-diagnostics"); +
+
+ 92 + +
+ + +
+
+
+ 93 + +
+ + + rootProject.mainSourceSet().java().writeClass(""" +
+
+ 94 + +
+ + + package com.example; +
+
+ 95 + +
+ + +
+
+
+ 96 + +
+ + + public class Main { +
+
+ 97 + +
+ + + public static void main(String[] args) { +
+
+ 98 + +
+ + + System.out.println("Hello World"); +
+
+ 99 + +
+ + + } +
+
+ 100 + +
+ + + } +
+
+ 101 + +
+ + + """); +
+
+ 102 + +
+   +
+
+
+ 103 + +
+   + // ***DELINEATOR FOR REVIEW: then +
+
+ 104 + +
+ + + InvocationResult result = gradle.withArgs("compileJava").buildsSuccessfully(); +
+
+ 105 + +
+ + +
+
+
+ 106 + +
+ + + assertThat(result).output().as("Xmaxerrs should be overridden to 1000").contains("-Xmaxerrs", "1000"); +
+
+ 107 + +
+ + +
+
+
+ 108 + +
+ + + assertThat(result).output().as("Xmaxwarns should still be present").contains("-Xmaxwarns"); +
+
+ + +
+   +
+
+
+ + +
+   +
+
+
+ 109 + +
+   + } +
+
+ 110 + +
+   + } +
+
+
+
+
+
+
+
+ +