mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-07 16:56:12 +02:00
Use build-results file for root project dirs
Instead of using a separate mechanism and init script, reuse the information captured in the build-results file.
This commit is contained in:
parent
e234151ec9
commit
e644288a42
6 changed files with 8 additions and 145 deletions
|
@ -1,10 +0,0 @@
|
|||
import org.gradle.util.GradleVersion
|
||||
|
||||
// Only run against root build. Do not run against included builds.
|
||||
def isTopLevelBuild = gradle.getParent() == null
|
||||
// Only record configuration-cache entries for Gradle 7+
|
||||
def isAtLeastGradle7 = GradleVersion.current() >= GradleVersion.version('7.0')
|
||||
|
||||
if (isTopLevelBuild && isAtLeastGradle7) {
|
||||
apply from: 'project-root-capture.plugin.groovy'
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
|
||||
/*
|
||||
* Capture the build root directory for each executed Gradle build.
|
||||
* This is used to save/restore configuration-cache files, so:
|
||||
* - The implementation only makes sense if it's config-cache compatible
|
||||
* - We only need to support Gradle 7+
|
||||
*/
|
||||
|
||||
import org.gradle.tooling.events.*
|
||||
|
||||
settingsEvaluated { settings ->
|
||||
def rootDir = settings.rootDir.absolutePath
|
||||
def rootListLocation = new File(System.getenv("RUNNER_TEMP"), "project-roots.txt").absolutePath
|
||||
|
||||
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-projectRootTracker", ProjectTracker, { spec ->
|
||||
spec.getParameters().getRootDir().set(rootDir);
|
||||
spec.getParameters().getRootListLocation().set(rootListLocation);
|
||||
})
|
||||
|
||||
gradle.services.get(BuildEventsListenerRegistry).onTaskCompletion(projectTracker)
|
||||
}
|
||||
|
||||
abstract class ProjectTracker implements BuildService<ProjectTracker.Params>, OperationCompletionListener, AutoCloseable {
|
||||
interface Params extends BuildServiceParameters {
|
||||
Property<String> getRootDir();
|
||||
Property<String> getRootListLocation();
|
||||
}
|
||||
|
||||
public void onFinish(FinishEvent finishEvent) {}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
def rootDir = getParameters().getRootDir().get()
|
||||
def rootDirEntry = rootDir + '\n'
|
||||
def rootListFile = new File(getParameters().getRootListLocation().get())
|
||||
if (!rootListFile.exists() || !rootListFile.text.contains(rootDirEntry)) {
|
||||
rootListFile << rootDirEntry
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue