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 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..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,28 +25,24 @@ 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; 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 +52,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 +66,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 +101,7 @@ private static void createGenerateTask( Project project, ConjureExtension extension, TaskProvider extractJavaTask, - TaskProvider extractConjureIr) { + TaskProvider extractConjureIr) { ConjurePlugin.ignoreFromCheckUnusedDependencies(project); ConjurePlugin.addGeneratedToMainSourceSet(project); @@ -117,8 +112,8 @@ 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")); project.getExtensions() .getByType(RecommendedProductDependenciesExtension.class) @@ -156,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 new file mode 100644 index 000000000..2a21e1bd4 --- /dev/null +++ b/gradle-conjure/src/main/java/com/palantir/gradle/conjure/ExtractConjureIrTask.java @@ -0,0 +1,46 @@ +/* + * (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.DirectoryProperty; +import org.gradle.api.provider.Property; +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()); + getConjureIr().set(getProject().getLayout().getBuildDirectory().dir("conjure-ir")); + getConjureIr().disallowChanges(); + into(getConjureIr()); + } + + /** Configuration used to resolve IR. */ + @Input + public abstract Property getIrConfiguration(); + + @OutputDirectory + public abstract DirectoryProperty getConjureIr(); +}