From 99cd1c8122698b29d44f438f0c03600154125440 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Tue, 6 Dec 2022 12:01:41 -0500 Subject: [PATCH 1/3] extractIr task dependencies --- .../ConjureJavaLocalCodegenPlugin.java | 23 ++++----- .../gradle/conjure/ExtractConjureIrTask.java | 49 +++++++++++++++++++ 2 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java diff --git a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java index 8266fa087..a6999e879 100644 --- a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java +++ b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java @@ -31,22 +31,19 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.JavaBasePlugin; import org.gradle.api.plugins.JavaLibraryPlugin; import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.TaskProvider; public final class ConjureJavaLocalCodegenPlugin implements Plugin { private static final ObjectMapper OBJECT_MAPPER = ObjectMappers.newClientObjectMapper(); private static final String CONJURE_CONFIGURATION = "conjure"; - private static final Pattern DEFINITION_NAME = - Pattern.compile("(.*)-([0-9]+\\.[0-9]+\\.[0-9]+(?:-rc[0-9]+)?(?:-[0-9]+-g[a-f0-9]+)?)(\\.conjure)?\\.json"); @Override public void apply(Project project) { @@ -56,11 +53,10 @@ public void apply(Project project) { project.getExtensions().create(ConjureExtension.EXTENSION_NAME, ConjureExtension.class); Configuration conjureIrConfiguration = project.getConfigurations().create(CONJURE_CONFIGURATION); - TaskProvider extractConjureIr = project.getTasks().register("extractConjureIr", Copy.class, task -> { - task.rename(DEFINITION_NAME, "$1.conjure.json"); - task.from(conjureIrConfiguration); - task.into(project.getLayout().getBuildDirectory().dir("conjure-ir")); - }); + TaskProvider extractConjureIr = project.getTasks() + .register("extractConjureIr", ExtractConjureIrTask.class, task -> { + task.getIrConfiguration().set(conjureIrConfiguration); + }); TaskProvider extractJavaTask = ExtractConjurePlugin.applyConjureJava(project); @@ -71,7 +67,7 @@ private static void setupSubprojects( Project project, ConjureExtension extension, TaskProvider extractJavaTask, - TaskProvider extractConjureIr, + TaskProvider extractConjureIr, Configuration conjureIrConfiguration) { // Validating that each subproject has a corresponding definition and vice versa. @@ -106,7 +102,7 @@ private static void createGenerateTask( Project project, ConjureExtension extension, TaskProvider extractJavaTask, - TaskProvider extractConjureIr) { + TaskProvider extractConjureIr) { ConjurePlugin.ignoreFromCheckUnusedDependencies(project); ConjurePlugin.addGeneratedToMainSourceSet(project); @@ -117,8 +113,9 @@ private static void createGenerateTask( TaskProvider generateGitIgnore = ConjurePlugin.createWriteGitignoreTask( project, "gitignoreConjure", project.getProjectDir(), ConjurePlugin.JAVA_GITIGNORE_CONTENTS); - Provider conjureIrFile = extractConjureIr.map( - irTask -> new File(irTask.getDestinationDir(), project.getName() + ".conjure.json")); + Provider conjureIrFile = extractConjureIr + .flatMap(task -> task.getConjureIr().file(project.getName() + ".conjure.json")) + .map(RegularFile::getAsFile); project.getExtensions() .getByType(RecommendedProductDependenciesExtension.class) diff --git a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java new file mode 100644 index 000000000..7c7ddecf9 --- /dev/null +++ b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java @@ -0,0 +1,49 @@ +/* + * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.gradle.conjure; + +import java.util.regex.Pattern; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.Directory; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.OutputDirectory; +import org.gradle.api.tasks.Sync; + +public abstract class ExtractConjureIrTask extends Sync { + + private static final Pattern DEFINITION_NAME = + Pattern.compile("(.*)-([0-9]+\\.[0-9]+\\.[0-9]+(?:-rc[0-9]+)?(?:-[0-9]+-g[a-f0-9]+)?)(\\.conjure)?\\.json"); + + public ExtractConjureIrTask() { + rename(DEFINITION_NAME, "$1.conjure.json"); + from(getIrConfiguration()); + Provider outputDirectory = + getProject().getLayout().getBuildDirectory().dir("conjure-ir"); + into(outputDirectory); + getConjureIr().set(outputDirectory); + } + + /** Configuration used to resolve IR. */ + @Input + public abstract Property getIrConfiguration(); + + @OutputDirectory + public abstract DirectoryProperty getConjureIr(); +} From 07b873725cdde3a1c08077ca978ad7ebb278b36b Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Tue, 6 Dec 2022 17:16:06 +0000 Subject: [PATCH 2/3] Add generated changelog entries --- changelog/@unreleased/pr-1128.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-1128.v2.yml diff --git a/changelog/@unreleased/pr-1128.v2.yml b/changelog/@unreleased/pr-1128.v2.yml new file mode 100644 index 000000000..53068c773 --- /dev/null +++ b/changelog/@unreleased/pr-1128.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: extractIr task dependencies are configured correctly + links: + - https://github.com/palantir/gradle-conjure/pull/1128 From cacb3bbe013a96c2fc784eaa8c1da4f9aeeed98d Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Tue, 13 Dec 2022 13:33:07 -0500 Subject: [PATCH 3/3] feedback + RegularFile --- .../gradle/conjure/ConjureJavaLocalCodegenPlugin.java | 10 ++++------ .../palantir/gradle/conjure/ExtractConjureIrTask.java | 9 +++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java index a6999e879..db6836d9a 100644 --- a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java +++ b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ConjureJavaLocalCodegenPlugin.java @@ -25,7 +25,6 @@ import com.palantir.gradle.dist.RecommendedProductDependenciesExtension; import com.palantir.gradle.dist.RecommendedProductDependenciesPlugin; import com.palantir.logsafe.exceptions.SafeRuntimeException; -import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.HashMap; @@ -113,9 +112,8 @@ private static void createGenerateTask( TaskProvider generateGitIgnore = ConjurePlugin.createWriteGitignoreTask( project, "gitignoreConjure", project.getProjectDir(), ConjurePlugin.JAVA_GITIGNORE_CONTENTS); - Provider conjureIrFile = extractConjureIr - .flatMap(task -> task.getConjureIr().file(project.getName() + ".conjure.json")) - .map(RegularFile::getAsFile); + Provider conjureIrFile = + extractConjureIr.flatMap(task -> task.getConjureIr().file(project.getName() + ".conjure.json")); project.getExtensions() .getByType(RecommendedProductDependenciesExtension.class) @@ -153,10 +151,10 @@ private static String sanitizePackageName(String group) { return group.replaceAll("-", ""); } - private static Set extractProductDependencies(File irFile) { + private static Set extractProductDependencies(RegularFile irFile) { try { MinimalConjureDefinition conjureDefinition = - OBJECT_MAPPER.readValue(irFile, MinimalConjureDefinition.class); + OBJECT_MAPPER.readValue(irFile.getAsFile(), MinimalConjureDefinition.class); return conjureDefinition .extensions() .map(MinimalConjureDefinition.Extensions::productDependencies) diff --git a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java index 7c7ddecf9..2a21e1bd4 100644 --- a/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java +++ b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java @@ -18,10 +18,8 @@ import java.util.regex.Pattern; import org.gradle.api.artifacts.Configuration; -import org.gradle.api.file.Directory; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.provider.Property; -import org.gradle.api.provider.Provider; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.OutputDirectory; import org.gradle.api.tasks.Sync; @@ -34,10 +32,9 @@ public abstract class ExtractConjureIrTask extends Sync { public ExtractConjureIrTask() { rename(DEFINITION_NAME, "$1.conjure.json"); from(getIrConfiguration()); - Provider outputDirectory = - getProject().getLayout().getBuildDirectory().dir("conjure-ir"); - into(outputDirectory); - getConjureIr().set(outputDirectory); + getConjureIr().set(getProject().getLayout().getBuildDirectory().dir("conjure-ir")); + getConjureIr().disallowChanges(); + into(getConjureIr()); } /** Configuration used to resolve IR. */