Search in sources :

Example 1 with WorkerExecutor

use of org.gradle.workers.WorkerExecutor in project gradle by gradle.

the class NoIsolationWorkerFactory method getWorker.

@Override
public BuildOperationAwareWorker getWorker(WorkerRequirement workerRequirement) {
    final WorkerExecutor workerExecutor = this.workerExecutor;
    final ClassLoader contextClassLoader = ((FixedClassLoaderWorkerRequirement) workerRequirement).getContextClassLoader();
    return new AbstractWorker(buildOperationExecutor) {

        @Override
        public DefaultWorkResult execute(IsolatedParametersActionExecutionSpec<?> spec, BuildOperationRef parentBuildOperation) {
            return executeWrappedInBuildOperation(spec, parentBuildOperation, workSpec -> {
                DefaultWorkResult result;
                try {
                    result = ClassLoaderUtils.executeInClassloader(contextClassLoader, new Factory<DefaultWorkResult>() {

                        @Nullable
                        @Override
                        public DefaultWorkResult create() {
                            return workerServer.execute(specFactory.newSimpleSpec(workSpec));
                        }
                    });
                } finally {
                    // TODO the async work tracker should wait for children of an operation to finish first.
                    // It should not be necessary to call it here.
                    workerExecutor.await();
                }
                return result;
            });
        }
    };
}
Also used : BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) WorkerExecutor(org.gradle.workers.WorkerExecutor) InstantiatorFactory(org.gradle.internal.instantiation.InstantiatorFactory) Factory(org.gradle.internal.Factory)

Example 2 with WorkerExecutor

use of org.gradle.workers.WorkerExecutor in project gradle by gradle.

the class Download method run.

@TaskAction
void run() {
    WorkerExecutor workerExecutor = getWorkerExecutor();
    ObjectFactory objectFactory = getObjectFactory();
// Use the executor and factory ...
}
Also used : WorkerExecutor(org.gradle.workers.WorkerExecutor) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with WorkerExecutor

use of org.gradle.workers.WorkerExecutor in project curiostack by curioswitch.

the class UploadCodeCovCacheTask method exec.

@TaskAction
public void exec() {
    if (!getCodeCovReportFile().exists()) {
        // UploadToCodeCovTask failed, skip uploading the cache.
        return;
    }
    ExternalExecUtil.exec(getProject(), workerExecutor, exec -> {
        final List<String> coverageFiles;
        try (var lines = Files.lines(getCodeCovReportFile().toPath())) {
            coverageFiles = lines.filter(line -> line.startsWith("# path=")).map(line -> line.substring("# path=".length())).filter(filename -> Files.exists(getProject().file(filename).toPath())).map(line -> "./" + line).collect(toImmutableList());
        } catch (IOException e) {
            throw new UncheckedIOException("Could not read coverage report dump", e);
        }
        var toolManager = DownloadedToolManager.get(getProject());
        String gsutil = new PlatformHelper().getOs() == OperatingSystem.WINDOWS ? "gsutil.cmd" : "gsutil";
        exec.executable("bash");
        exec.args("-c", "tar -cpzf - " + String.join(" ", coverageFiles) + " | " + gsutil + " cp - " + dest.get());
        toolManager.addAllToPath(exec);
    });
}
Also used : Files(java.nio.file.Files) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) ExternalExecUtil(org.curioswitch.gradle.helpers.exec.ExternalExecUtil) IOException(java.io.IOException) File(java.io.File) UncheckedIOException(java.io.UncheckedIOException) Inject(javax.inject.Inject) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) Provider(org.gradle.api.provider.Provider) WorkerExecutor(org.gradle.workers.WorkerExecutor) DownloadedToolManager(org.curioswitch.gradle.tooldownloader.DownloadedToolManager) Property(org.gradle.api.provider.Property) InputFile(org.gradle.api.tasks.InputFile) DefaultTask(org.gradle.api.DefaultTask) OperatingSystem(org.curioswitch.gradle.helpers.platform.OperatingSystem) Input(org.gradle.api.tasks.Input) PlatformHelper(org.curioswitch.gradle.helpers.platform.PlatformHelper) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

WorkerExecutor (org.gradle.workers.WorkerExecutor)3 TaskAction (org.gradle.api.tasks.TaskAction)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 List (java.util.List)1 Inject (javax.inject.Inject)1 ExternalExecUtil (org.curioswitch.gradle.helpers.exec.ExternalExecUtil)1 OperatingSystem (org.curioswitch.gradle.helpers.platform.OperatingSystem)1 PlatformHelper (org.curioswitch.gradle.helpers.platform.PlatformHelper)1 DownloadedToolManager (org.curioswitch.gradle.tooldownloader.DownloadedToolManager)1 DefaultTask (org.gradle.api.DefaultTask)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 Property (org.gradle.api.provider.Property)1 Provider (org.gradle.api.provider.Provider)1 Input (org.gradle.api.tasks.Input)1 InputFile (org.gradle.api.tasks.InputFile)1 Factory (org.gradle.internal.Factory)1