From e9d695030fa498019f439bb7ad4ecdceb4253c51 Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:15:02 +0100 Subject: [PATCH 01/10] Try to fix the build --- .../PrintCoveragePluginTest.groovy | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index f4f24e9..f88be0f 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -13,17 +13,17 @@ class PrintCoveragePluginTest extends Specification { final static String[] SUPPORTED_GRADLE_VERSIONS = ['4.10', '4.10.1', '4.10.2', '5.0', '4.10.3', '5.1', '5.1.1'] - @Rule - final TemporaryFolder testProjectDir = new TemporaryFolder() + TemporaryFolder temporaryFolder File buildFile File reportFile def setup() { - testProjectDir.create() - buildFile = testProjectDir.newFile('build.gradle') - reportFile = testProjectDir + temporaryFolder = new TemporaryFolder() + temporaryFolder.create() + buildFile = temporaryFolder.newFile('build.gradle') + reportFile = temporaryFolder .newFolder('build', 'reports', 'jacoco', 'test') .toPath() .resolve('jacocoTestReport.xml') @@ -41,7 +41,7 @@ class PrintCoveragePluginTest extends Specification { when: GradleRunner.create() .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) + .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() .build() @@ -66,7 +66,7 @@ class PrintCoveragePluginTest extends Specification { when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) + .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() .build() @@ -96,13 +96,13 @@ class PrintCoveragePluginTest extends Specification { testCompile 'junit:junit:4.12' } """ - File classFile = testProjectDir + File classFile = temporaryFolder .newFolder('src', 'main', 'java', 'sample') .toPath() .resolve('Calculator.java') .toFile() classFile << new File("src/test/resources/Calculator.java").text - File junitFile = testProjectDir + File junitFile = temporaryFolder .newFolder('src', 'test', 'java', 'sample') .toPath() .resolve('CalculatorTest.java') @@ -112,7 +112,7 @@ class PrintCoveragePluginTest extends Specification { when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) + .withProjectDir(temporaryFolder.root) .withArguments('build', 'printCoverage') .withPluginClasspath() .build() @@ -138,7 +138,7 @@ class PrintCoveragePluginTest extends Specification { when: def result = GradleRunner.create() .withGradleVersion(gradleVersion) - .withProjectDir(testProjectDir.root) + .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() .buildAndFail() @@ -166,7 +166,7 @@ class PrintCoveragePluginTest extends Specification { reportFile << new File("src/test/resources/jacocoTestReport.xml").text def result = GradleRunner.create() - .withProjectDir(testProjectDir.root) + .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() .build() From 040dbd509625ee45b85a5a91661b8c5bee8ad963 Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:26:01 +0100 Subject: [PATCH 02/10] Try without forking new processes --- .../de/jansauer/printcoverage/PrintCoveragePluginTest.groovy | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index f88be0f..c798db9 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -44,6 +44,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .withDebug(true) .build() then: @@ -69,6 +70,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .withDebug(true) .build() then: @@ -115,6 +117,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('build', 'printCoverage') .withPluginClasspath() + .withDebug(true) .build() then: @@ -141,6 +144,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .withDebug(true) .buildAndFail() then: @@ -169,6 +173,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .withDebug(true) .build() result.output.contains("Coverage: ${coverage}") From e2b60a93a66b460306f90fc030f499469ff8ae36 Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:37:04 +0100 Subject: [PATCH 03/10] Save reports --- .circleci/config.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ca57b3..eea49b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,17 @@ jobs: - store_artifacts: path: build/libs destination: ./ + - store_artifacts: + path: build/reports + destination: ./ + - run: + name: Save test results + command: | + mkdir -p ~/junit/ + find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/junit/ \; + when: always + - store_test_results: + path: ~/junit - run: name: Publish code coverage to codecov.io command: bash <(curl -s https://codecov.io/bash) From 299a6fc5ee060a87690318632946eeaf17b2f99a Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:44:08 +0100 Subject: [PATCH 04/10] Disable the gradle daemon --- .circleci/config.yml | 2 +- .../printcoverage/PrintCoveragePluginTest.groovy | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index eea49b2..9b9ace5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ jobs: key: gradle-{{ checksum "build.gradle" }} - run: name: Run gradle build tasks - command: ./gradlew clean build codeCoverageReport + command: ./gradlew clean build codeCoverageReport --no-daemon - save_cache: paths: - ~/.gradle diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index c798db9..df03650 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -42,9 +42,8 @@ class PrintCoveragePluginTest extends Specification { GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage') + .withArguments('printCoverage', '--no-daemon') .withPluginClasspath() - .withDebug(true) .build() then: @@ -68,9 +67,8 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage') + .withArguments('printCoverage', '--no-daemon') .withPluginClasspath() - .withDebug(true) .build() then: @@ -115,9 +113,8 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('build', 'printCoverage') + .withArguments('build', 'printCoverage', '--no-daemon') .withPluginClasspath() - .withDebug(true) .build() then: @@ -142,9 +139,8 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage') + .withArguments('printCoverage', '--no-daemon') .withPluginClasspath() - .withDebug(true) .buildAndFail() then: @@ -171,9 +167,8 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage') + .withArguments('printCoverage', '--no-daemon') .withPluginClasspath() - .withDebug(true) .build() result.output.contains("Coverage: ${coverage}") From ff15a4b4c1e216c30f2ac14381e338a400d6ea04 Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:48:19 +0100 Subject: [PATCH 05/10] Disable the gradle daemon via env variable --- .circleci/config.yml | 2 ++ .../printcoverage/PrintCoveragePluginTest.groovy | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b9ace5..a002fdf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,8 @@ jobs: build: docker: - image: circleci/openjdk:11-jdk + environment: + GRADLE_OPTS: -Dorg.gradle.daemon=false steps: - checkout - restore_cache: diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index df03650..f88be0f 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -42,7 +42,7 @@ class PrintCoveragePluginTest extends Specification { GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage', '--no-daemon') + .withArguments('printCoverage') .withPluginClasspath() .build() @@ -67,7 +67,7 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage', '--no-daemon') + .withArguments('printCoverage') .withPluginClasspath() .build() @@ -113,7 +113,7 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('build', 'printCoverage', '--no-daemon') + .withArguments('build', 'printCoverage') .withPluginClasspath() .build() @@ -139,7 +139,7 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withGradleVersion(gradleVersion) .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage', '--no-daemon') + .withArguments('printCoverage') .withPluginClasspath() .buildAndFail() @@ -167,7 +167,7 @@ class PrintCoveragePluginTest extends Specification { def result = GradleRunner.create() .withProjectDir(temporaryFolder.root) - .withArguments('printCoverage', '--no-daemon') + .withArguments('printCoverage') .withPluginClasspath() .build() From b10a5e87d130b0a8bab88c195e566cf0b87fd7ed Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 18:53:51 +0100 Subject: [PATCH 06/10] Try to reserve less memory --- .circleci/config.yml | 2 +- gradle.properties | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 gradle.properties diff --git a/.circleci/config.yml b/.circleci/config.yml index a002fdf..e7d161a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: key: gradle-{{ checksum "build.gradle" }} - run: name: Run gradle build tasks - command: ./gradlew clean build codeCoverageReport --no-daemon + command: ./gradlew clean build codeCoverageReport - save_cache: paths: - ~/.gradle diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..668a80c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.daemon=true +org.gradle.caching=true +org.gradle.jvmargs=-Xmx512m -Xms256m \ No newline at end of file From 37edf9eba2cc706f5dbe0aae95631f07156fe25e Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 19:04:44 +0100 Subject: [PATCH 07/10] Try less memory for the test runner gradle jvm --- gradle.properties | 3 --- .../jansauer/printcoverage/PrintCoveragePluginTest.groovy | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 668a80c..e69de29 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +0,0 @@ -org.gradle.daemon=true -org.gradle.caching=true -org.gradle.jvmargs=-Xmx512m -Xms256m \ No newline at end of file diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index f88be0f..b63e05f 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -15,6 +15,8 @@ class PrintCoveragePluginTest extends Specification { TemporaryFolder temporaryFolder + File propertiesFile + File buildFile File reportFile @@ -22,12 +24,17 @@ class PrintCoveragePluginTest extends Specification { def setup() { temporaryFolder = new TemporaryFolder() temporaryFolder.create() + propertiesFile = temporaryFolder.newFile('gradle.properties') buildFile = temporaryFolder.newFile('build.gradle') reportFile = temporaryFolder .newFolder('build', 'reports', 'jacoco', 'test') .toPath() .resolve('jacocoTestReport.xml') .toFile() + propertiesFile << """ + org.gradle.daemon=false + org.gradle.jvmargs=-Xmx512m -Xms256m + """ } def "should fail if the jacoco plugin is missing"() { From fb5d3951d7f62d66f840fe2d473be92853661056 Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 19:16:27 +0100 Subject: [PATCH 08/10] Forward output --- gradle.properties | 0 .../printcoverage/PrintCoveragePluginTest.groovy | 13 +++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) delete mode 100644 gradle.properties diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index b63e05f..6b49188 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -25,16 +25,16 @@ class PrintCoveragePluginTest extends Specification { temporaryFolder = new TemporaryFolder() temporaryFolder.create() propertiesFile = temporaryFolder.newFile('gradle.properties') + propertiesFile << """ + org.gradle.daemon=false + org.gradle.jvmargs=-Xmx512m -Xms256m + """ buildFile = temporaryFolder.newFile('build.gradle') reportFile = temporaryFolder .newFolder('build', 'reports', 'jacoco', 'test') .toPath() .resolve('jacocoTestReport.xml') .toFile() - propertiesFile << """ - org.gradle.daemon=false - org.gradle.jvmargs=-Xmx512m -Xms256m - """ } def "should fail if the jacoco plugin is missing"() { @@ -51,6 +51,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .forwardOutput() .build() then: @@ -76,6 +77,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .forwardOutput() .build() then: @@ -122,6 +124,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('build', 'printCoverage') .withPluginClasspath() + .forwardOutput() .build() then: @@ -148,6 +151,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .forwardOutput() .buildAndFail() then: @@ -176,6 +180,7 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() + .forwardOutput() .build() result.output.contains("Coverage: ${coverage}") From bc78412eaa7fd3ce861562efb36e04c33f65639f Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 19:58:54 +0100 Subject: [PATCH 09/10] Use separate tests --- .../PrintCoveragePluginTest.groovy | 66 +++++++++++++++++-- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy index 6b49188..d60a71f 100644 --- a/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy +++ b/src/test/groovy/de/jansauer/printcoverage/PrintCoveragePluginTest.groovy @@ -51,7 +51,6 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() - .forwardOutput() .build() then: @@ -77,7 +76,6 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() - .forwardOutput() .build() then: @@ -124,7 +122,6 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('build', 'printCoverage') .withPluginClasspath() - .forwardOutput() .build() then: @@ -132,10 +129,67 @@ class PrintCoveragePluginTest extends Specification { result.task(":printCoverage").outcome == SUCCESS where: - // gradleVersion << SUPPORTED_GRADLE_VERSIONS TODO: Fix testing real code with gradle 4.x - gradleVersion << [/*'4.10', '4.10.1', '4.10.2',*/ '5.0', /*'4.10.3',*/ '5.1', '5.1.1'] + gradleVersion << SUPPORTED_GRADLE_VERSIONS.findAll { !(it =~ /4\.*/) } } + def "should print from a example class with tests with gradle 4.x"() { + given: + buildFile << """ + plugins { + id 'java' + id 'jacoco' + id 'de.jansauer.printcoverage' + } + + repositories { + mavenCentral() + } + + dependencies { + testCompile 'junit:junit:4.12' + } + + // default version does not work with jdk11 + // https://github.com/vaskoz/core-java9-impatient/issues/11 + // https://github.com/jacoco/jacoco/releases/tag/v0.8.2 + jacoco { + toolVersion = "0.8.2" + } + """ + File classFile = temporaryFolder + .newFolder('src', 'main', 'java', 'sample') + .toPath() + .resolve('Calculator.java') + .toFile() + classFile << new File("src/test/resources/Calculator.java").text + File junitFile = temporaryFolder + .newFolder('src', 'test', 'java', 'sample') + .toPath() + .resolve('CalculatorTest.java') + .toFile() + junitFile << new File("src/test/resources/CalculatorTest.java").text + + when: + def result = GradleRunner.create() + .withGradleVersion(gradleVersion) + .withProjectDir(temporaryFolder.root) + .withArguments('build', 'printCoverage') + .withPluginClasspath() + .build() + + then: + result.output.contains('Coverage: 79.49%') + result.task(":printCoverage").outcome == SUCCESS + + where: + gradleVersion << SUPPORTED_GRADLE_VERSIONS.findAll { it =~ /4\.*/ } + } + + + + + + def "should fail if jacoco test report is missing"() { given: buildFile << """ @@ -151,7 +205,6 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() - .forwardOutput() .buildAndFail() then: @@ -180,7 +233,6 @@ class PrintCoveragePluginTest extends Specification { .withProjectDir(temporaryFolder.root) .withArguments('printCoverage') .withPluginClasspath() - .forwardOutput() .build() result.output.contains("Coverage: ${coverage}") From 15d0d254255fa6caa69af19429fb31dee5c3ae5b Mon Sep 17 00:00:00 2001 From: Jan Sauer Date: Sun, 3 Feb 2019 20:04:44 +0100 Subject: [PATCH 10/10] Cleanup artifacts --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e7d161a..62dac2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,10 +23,10 @@ jobs: - build - store_artifacts: path: build/libs - destination: ./ + destination: libs - store_artifacts: path: build/reports - destination: ./ + destination: reports - run: name: Save test results command: |