Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore optimization #898

Merged
merged 10 commits into from
May 2, 2022
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-898.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Restore perf optimization to reuse the same classloader for conjure
generators when using gradle 7.4.2
links:
- https://github.com/palantir/gradle-conjure/pull/898
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,48 @@

package com.palantir.gradle.conjure;

import com.palantir.gradle.conjure.ConjureRunnerResource.Params;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.services.BuildServiceSpec;
import org.gradle.util.GradleVersion;

final class GradleExecUtils {

static void exec(
Project project, String failedTo, File executable, List<String> unloggedArgs, List<String> loggedArgs) {
try (ConjureRunnerResource.ConjureRunner runner = ConjureRunnerResource.createNewRunner(executable)) {
runner.invoke(project, failedTo, unloggedArgs, loggedArgs);
} catch (IOException e) {
throw new RuntimeException(e);
if (gradleVersionHighEnough()) {
project.getGradle()
.getSharedServices()
.registerIfAbsent(
// Executable name must be the cache key, neither the spec parameters
// nor the class are taken into account for caching.
"conjure-runner-" + executable,
ConjureRunnerResource.class,
new Action<BuildServiceSpec<Params>>() {
@Override
public void execute(BuildServiceSpec<Params> spec) {
spec.getParameters().getExecutable().set(executable);
}
})
.get()
.invoke(project, failedTo, unloggedArgs, loggedArgs);
} else {
try (ConjureRunnerResource.ConjureRunner runner = ConjureRunnerResource.createNewRunner(executable)) {
runner.invoke(project, failedTo, unloggedArgs, loggedArgs);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

// See https://github.com/gradle/gradle/issues/17434
private static boolean gradleVersionHighEnough() {
return GradleVersion.current().compareTo(GradleVersion.version("7.4.2")) >= 0;
}

private GradleExecUtils() {}
}