-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issues/150: Support Gradle's Configuration Cache
- Loading branch information
Showing
9 changed files
with
167 additions
and
76 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
skippy-gradle/src/main/java/io/skippy/gradle/CachableProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.skippy.gradle; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.SourceSetContainer; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A sub-set of relevant {@link Project} properties that are compatible with Gradle's Configuration Cache. | ||
*/ | ||
class CachableProperties { | ||
|
||
final boolean sourceSetContainerAvailable; | ||
final List<File> classesDirs; | ||
final SkippyPluginExtension skippyPluginExtension; | ||
final Path projectDir; | ||
final Path buildDir; | ||
|
||
private CachableProperties(boolean sourceSetContainerAvailable, List<File> classesDirs, SkippyPluginExtension skippyExtension, Path projectDir, Path buildDir) { | ||
this.sourceSetContainerAvailable = sourceSetContainerAvailable; | ||
this.classesDirs = classesDirs; | ||
this.skippyPluginExtension = skippyExtension; | ||
this.projectDir = projectDir; | ||
this.buildDir = buildDir; | ||
} | ||
|
||
static CachableProperties from(Project project) { | ||
var sourceSetContainer = project.getExtensions().findByType(SourceSetContainer.class); | ||
// new ArrayList<>() is a workaround for https://github.com/gradle/gradle/issues/26942 | ||
var classesDirs = new ArrayList<>(sourceSetContainer.stream().flatMap(sourceSet -> sourceSet.getOutput().getClassesDirs().getFiles().stream()).toList()); | ||
var skippyExtension = project.getExtensions().getByType(SkippyPluginExtension.class); | ||
var projectDir = project.getProjectDir().toPath(); | ||
var buildDir = project.getLayout().getBuildDirectory().getAsFile().get().toPath(); | ||
return new CachableProperties(sourceSetContainer != null, classesDirs, skippyExtension, projectDir, buildDir); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
skippy-gradle/src/main/java/io/skippy/gradle/TestFailedListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.skippy.gradle; | ||
|
||
import org.gradle.api.tasks.testing.TestDescriptor; | ||
import org.gradle.api.tasks.testing.TestListener; | ||
import org.gradle.api.tasks.testing.TestResult; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
class TestFailedListener implements TestListener { | ||
final List<TestDescriptor> failedTests = new ArrayList<>(); | ||
|
||
@Override | ||
public void beforeSuite(TestDescriptor testDescriptor) { | ||
} | ||
|
||
@Override | ||
public void afterSuite(TestDescriptor testDescriptor, TestResult testResult) { | ||
} | ||
|
||
@Override | ||
public void beforeTest(TestDescriptor testDescriptor) { | ||
} | ||
|
||
@Override | ||
public void afterTest(TestDescriptor testDescriptor, TestResult testResult) { | ||
if (testResult.getResultType() == TestResult.ResultType.FAILURE) { | ||
failedTests.add(testDescriptor); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
skippy-gradle/src/main/java/io/skippy/gradle/TestResultService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.skippy.gradle; | ||
|
||
import org.gradle.api.services.BuildService; | ||
import org.gradle.api.services.BuildServiceParameters; | ||
import org.gradle.api.tasks.testing.TestDescriptor; | ||
import org.gradle.api.tasks.testing.TestResult; | ||
|
||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
abstract class TestResultService implements BuildService<BuildServiceParameters.None> { | ||
|
||
final List<TestDescriptor> failedTests = new ArrayList<>(); | ||
|
||
@Inject | ||
public TestResultService() { | ||
} | ||
|
||
void afterTest(TestDescriptor testDescriptor, TestResult testResult) { | ||
if (testResult.getResultType() == TestResult.ResultType.FAILURE) { | ||
failedTests.add(testDescriptor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters