Skip to content

Commit

Permalink
scoverage#163 Fix deprecation warning from Gradle 7.1.1 about undecla…
Browse files Browse the repository at this point in the history
…red dependency between report task and test tasks outputs
  • Loading branch information
eyalroth committed Sep 4, 2021
1 parent 89b5341 commit 32233d0
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void checkAndAggregateAll() throws Exception {
private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "2_12/src/main/scala/org/hello/World2_12.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "2_13/src/main/scala/org/hello/World2_13.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World2_12.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World2_13.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public void report() throws Exception {

File reportDir = reportDir(projectDir().toPath().resolve(scalaVersion).toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/World" + scalaVersion + ".scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/World" + scalaVersion + ".scala.html").exists());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ private void assertAllReportFilesExist() {

private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "mixed_scala_java/src/main/scala/org/hello/WorldScala.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/WorldScala.scala.html").exists());
}

private void assertMixedScalaJavaReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("mixed_scala_java").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/WorldScala.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/WorldScala.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ private void assertAllReportFilesExist() {

private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "scala_only/src/main/scala/org/hello/WorldScalaOnly.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "mixed_scala_java/src/main/scala/org/hello/WorldScala.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/WorldScalaOnly.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/WorldScala.scala.html").exists());
}

private void assertScalaOnlyReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("scala_only").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/WorldScalaOnly.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/WorldScalaOnly.scala.html").exists());
}

private void assertMixedScalaJavaReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("mixed_scala_java").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/WorldScala.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/WorldScala.scala.html").exists());
}
}
14 changes: 7 additions & 7 deletions src/functionalTest/java/org/scoverage/ScalaMultiModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,35 +297,35 @@ private void assertAllReportFilesExist() {

private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "a/src/main/scala/org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "b/src/main/scala/org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "common/src/main/scala/org/hello/common/WorldCommon.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/common/WorldCommon.scala.html").exists());
}

private void assertRootReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
}

private void assertAReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("a").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/a/WorldA.scala.html").exists());
}

private void assertBReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("b").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/b/WorldB.scala.html").exists());
}

private void assertCommonReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("common").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/common/WorldCommon.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/common/WorldCommon.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,35 +294,35 @@ private void assertAllReportFilesExist() {

private void assertAggregationFilesExist() {

Assert.assertTrue(resolve(reportDir(), "a/src/main/scala/org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "b/src/main/scala/org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "common/src/main/scala/org/hello/common/WorldCommon.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/common/WorldCommon.scala.html").exists());
}

private void assertRootReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
}

private void assertAReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("a").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/a/WorldA.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/a/WorldA.scala.html").exists());
}

private void assertBReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("b").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/b/WorldB.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/b/WorldB.scala.html").exists());
}

private void assertCommonReportFilesExist() {

File reportDir = reportDir(projectDir().toPath().resolve("common").toFile());
Assert.assertTrue(resolve(reportDir, "index.html").exists());
Assert.assertTrue(resolve(reportDir, "src/main/scala/org/hello/common/WorldCommon.scala.html").exists());
Assert.assertTrue(resolve(reportDir, "org/hello/common/WorldCommon.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void reportScoverageWithExcludedClasses() throws Exception {
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Expand Down Expand Up @@ -125,7 +125,7 @@ public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() thro
"-PexcludedFile=.*", "-P" + ScoveragePlugin.getSCOVERAGE_COMPILE_ONLY_PROPERTY());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Expand All @@ -136,6 +136,6 @@ public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() thro
private void assertReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public void checkScoverage() throws Exception {
private void assertReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void reportScoverageWithExcludedClasses() throws Exception {
result.assertTaskDoesntExist(ScoveragePlugin.getAGGREGATE_NAME());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Expand Down Expand Up @@ -143,7 +143,7 @@ public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() thro
"-PexcludedFile=.*", "-P" + ScoveragePlugin.getSCOVERAGE_COMPILE_ONLY_PROPERTY());

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertFalse(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertFalse(resolve(reportDir(), "org/hello/World.scala.html").exists());
assertCoverage(100.0); // coverage is 100 since no classes are covered

// compiled class should exist in the default classes directory, but not in scoverage
Expand All @@ -155,6 +155,6 @@ public void reportScoverageWithoutNormalCompilationAndWithExcludedClasses() thro
private void assertReportFilesExist() {

Assert.assertTrue(resolve(reportDir(), "index.html").exists());
Assert.assertTrue(resolve(reportDir(), "src/main/scala/org/hello/World.scala.html").exists());
Assert.assertTrue(resolve(reportDir(), "org/hello/World.scala.html").exists());
}
}
11 changes: 10 additions & 1 deletion src/main/groovy/org/scoverage/ScoverageAggregate.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package org.scoverage

import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.TaskAction
import scoverage.report.CoverageAggregator

import static org.gradle.api.tasks.PathSensitivity.RELATIVE

class ScoverageAggregate extends DefaultTask {

@Nested
ScoverageRunner runner

@InputFiles
@PathSensitive(RELATIVE)
final Property<FileCollection> sources = project.objects.property(FileCollection)

@OutputDirectory
final Property<File> reportDir = project.objects.property(File)

Expand Down Expand Up @@ -52,7 +61,7 @@ class ScoverageAggregate extends DefaultTask {

if (coverage.nonEmpty()) {
new ScoverageWriter(project.logger).write(
project.projectDir,
sources.get().getFiles(),
reportDir.get(),
coverage.get(),
sourceEncoding.get(),
Expand Down
5 changes: 0 additions & 5 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class ScoverageExtension {
final Property<File> dataDir
/** a directory to write final output to */
final Property<File> reportDir
/** sources to highlight */
final Property<File> sources
/** range positioning for highlighting */
final Property<Boolean> highlighting
/** regex for each excluded package */
Expand Down Expand Up @@ -61,9 +59,6 @@ class ScoverageExtension {

scoverageScalaVersion = project.objects.property(String)

sources = project.objects.property(File)
sources.set(project.projectDir)

dataDir = project.objects.property(File)
dataDir.set(new File(project.buildDir, 'scoverage'))

Expand Down
8 changes: 7 additions & 1 deletion src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
group = 'verification'
runner = scoverageRunner
reportDir = taskReportDir
sources = extension.sources
sources = originalSourceSet.scala.getSourceDirectories()
dataDir = extension.dataDir
sourceEncoding.set(detectedSourceEncoding)
coverageOutputCobertura = extension.coverageOutputCobertura
Expand All @@ -143,6 +143,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
group = 'verification'
runner = scoverageRunner
reportDir = extension.reportDir
sources = originalSourceSet.scala.getSourceDirectories()
dirsToAggregateFrom = dataDirs
sourceEncoding.set(detectedSourceEncoding)
deleteReportsOnAggregation = false
Expand Down Expand Up @@ -299,6 +300,10 @@ class ScoveragePlugin implements Plugin<PluginAware> {
}
}
def allReportTasks = childReportTasks + globalReportTask.get()
def allSources = project.objects.fileCollection()
allReportTasks.each {
allSources = allSources.plus(it.sources.get())
}
def aggregationTask = project.tasks.create(AGGREGATE_NAME, ScoverageAggregate) {
def dataDirs = allReportTasks.findResults { it.dirsToAggregateFrom.get() }.flatten()
onlyIf {
Expand All @@ -308,6 +313,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
group = 'verification'
runner = scoverageRunner
reportDir = extension.reportDir
sources = allSources
sourceEncoding.set(detectedSourceEncoding)
dirsToAggregateFrom = dataDirs
deleteReportsOnAggregation = extension.deleteReportsOnAggregation
Expand Down
8 changes: 5 additions & 3 deletions src/main/groovy/org/scoverage/ScoverageReport.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.scoverage

import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
Expand All @@ -23,9 +25,9 @@ class ScoverageReport extends DefaultTask {
@PathSensitive(RELATIVE)
final Property<File> dataDir = project.objects.property(File)

@InputDirectory
@InputFiles
@PathSensitive(RELATIVE)
final Property<File> sources = project.objects.property(File)
final Property<FileCollection> sources = project.objects.property(FileCollection)

@OutputDirectory
final Property<File> reportDir = project.objects.property(File)
Expand Down Expand Up @@ -54,7 +56,7 @@ class ScoverageReport extends DefaultTask {
project.logger.info("[scoverage] Could not find coverage file, skipping...")
} else {
new ScoverageWriter(project.logger).write(
sources.get(),
sources.get().getFiles(),
reportDir.get(),
coverage.get(),
sourceEncoding.get(),
Expand Down
Loading

0 comments on commit 32233d0

Please sign in to comment.