-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the PidCollector to work with the configuration cache
by not relying on gradle.buildFinished simply writing the file instead Before it was using a separate i/o thread, joined when the build is finished to write the pid to a file, only to prevent i/o to interfere with the performance. Now it writes it as soon as it can in a simpler way. Even though the AsyncWriter usage make sense for e.g. GradleTracingPlugin which is writing quite a lot of stuff, it shouldn't change much for writing the pid number. This could be done with a BuildService listener but there isn't any way to get ProcessEnvironment in one yet so the pid would have to be captured at configuration time anyway. Signed-off-by: Paul Merlin <[email protected]>
- Loading branch information
Showing
2 changed files
with
5 additions
and
15 deletions.
There are no files selected for viewing
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
14 changes: 2 additions & 12 deletions
14
subprojects/build-operations/src/main/java/org/gradle/trace/pid/PidCollector.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 |
---|---|---|
@@ -1,25 +1,15 @@ | ||
package org.gradle.trace.pid; | ||
|
||
import org.gradle.BuildAdapter; | ||
import org.gradle.BuildResult; | ||
import org.gradle.api.internal.GradleInternal; | ||
import org.gradle.internal.nativeintegration.ProcessEnvironment; | ||
import org.gradle.trace.stream.AsyncWriter; | ||
import org.gradle.util.GFileUtils; | ||
|
||
import java.io.File; | ||
|
||
@SuppressWarnings("unused") | ||
public class PidCollector { | ||
public static void collect(GradleInternal gradle, File outFile) { | ||
ProcessEnvironment processEnvironment = gradle.getServices().get(ProcessEnvironment.class); | ||
AsyncWriter<Long> writer = new AsyncWriter<>(outFile, (l, w) -> w.print(l)); | ||
writer.append(processEnvironment.getPid()); | ||
writer.finished(); | ||
gradle.addBuildListener(new BuildAdapter(){ | ||
@Override | ||
public void buildFinished(BuildResult result) { | ||
writer.stop(); | ||
} | ||
}); | ||
GFileUtils.writeFile(processEnvironment.getPid().toString(), outFile); | ||
} | ||
} |