Skip to content

Commit

Permalink
set the jakartaPackages flag via a gradle property
Browse files Browse the repository at this point in the history
If the gradle property `conjure.java.jakartaPackages` is set to `true`,
then the corresponding flag will be set within the `java` options
container in `ConjureExtension` at the time the extension object is
created. This ensures that we can eagerly read the property value and
configure the extension early in the gradle lifecycle, before any
subprojects are configured, and the value will propagate correctly.

This change removes previously-added `afterEvaluate` calls in some
places.
  • Loading branch information
Brian Laub committed Jul 11, 2023
1 parent 269086d commit 3d5a6d9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import groovy.lang.DelegatesTo;
import java.util.HashMap;
import java.util.Map;
import org.gradle.api.Project;

public class ConjureExtension {

Expand All @@ -31,12 +32,16 @@ public class ConjureExtension {
private final GeneratorOptions pythonOptions = new GeneratorOptions();
private final Map<String, GeneratorOptions> genericOptions = new HashMap<>();

public ConjureExtension() {
public ConjureExtension(Project project) {
// Projects using sufficiently new gradle-conjure have jetbrains-annotations
// added by default. Conjure generators ignore unknown flags and will not be
// impacted if generators have not been updated.
// See https://github.com/palantir/conjure-java/pull/1884
javaOptions.addFlag("jetbrainsContractAnnotations");

if (Boolean.parseBoolean((String) project.findProperty("conjure.java.jakartaPackages"))) {
javaOptions.addFlag("jakartaPackages");
}
}

public final void typescript(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void apply(Project project) {
ConjureProductDependenciesExtension.EXTENSION_NAME,
ConjureProductDependenciesExtension.class,
project);
conjureExtension = project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class);
conjureExtension =
project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class, project);
SourceDirectorySet conjureSourceSet = createConjureSourceSet(project);
TaskProvider<Copy> copyConjureSourcesTask = createCopyConjureSourceTask(project, conjureSourceSet);
compileIrProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void apply(Project project) {
project.getPlugins().apply(JavaBasePlugin.class);

ConjureExtension extension =
project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class);
project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class, project);

Configuration conjureIrConfiguration = project.getConfigurations().create(CONJURE_CONFIGURATION);
TaskProvider<Copy> extractConjureIr = project.getTasks().register("extractConjureIr", Copy.class, task -> {
Expand All @@ -79,12 +79,11 @@ private static void setupSubprojects(
createGenerateTask(subproject, extension, extractJavaTask, extractConjureIr);
});

project.getChildProjects().forEach((_name, subproject) -> {
configureDependencies(subproject, extension);
});

project.afterEvaluate(_p -> {
project.getChildProjects().forEach((_name, subproject) -> {
// Configure subproject dependencies in after-evaluate to ensure
// extension the has been evaluated.
configureDependencies(subproject, extension);
});
// Validating that each subproject has a corresponding definition and vice versa.
// We do this in afterEvaluate to ensure the configuration is populated.
Set<String> apis = conjureIrConfiguration.getAllDependencies().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void apply(Project project) {
project.getConfigurations().maybeCreate(ConjurePlugin.CONJURE_GENERATORS_CONFIGURATION_NAME);

ConjureExtension extension =
project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class);
project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class, project);

TaskProvider<Task> generateConjure = project.getTasks().register("generateConjure", task -> {
task.setDescription("Generates code for all requested languages (for which there is a subproject) "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ private void setupConjureJavaProjects(
+ difference);
}

project.afterEvaluate(_p -> configs.forEach((suffix, config) -> setupDerivedJavaProject(
configs.forEach((suffix, config) -> setupDerivedJavaProject(
suffix,
project,
optionsSupplier,
compileConjure,
compileIrTask,
productDependencyExt,
extractJavaTask,
config)));
config));
}

private static Project setupDerivedJavaProject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,9 @@ class ConjurePluginTest extends IntegrationSpec {
}
}
""".stripIndent()
file('api/build.gradle') << '''
conjure {
java {
jakartaPackages = true
}
}
'''.stripIndent()
createFile('gradle.properties') << """
conjure.java.jakartaPackages=true
""".stripIndent()
updateSettings(prefix)

when:
Expand Down

0 comments on commit 3d5a6d9

Please sign in to comment.