From 949b9e87cda09805e6f5264b936de78dd78538de Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Wed, 1 Mar 2023 16:53:23 -0800 Subject: [PATCH] Look in class directory for diagnostic manifests --- build.gradle | 2 +- .../service/DiagnosticsManifestPlugin.java | 36 +++++-------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/build.gradle b/build.gradle index 96ab72d3d..9196049eb 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ apply plugin: 'com.palantir.jdks.latest' allprojects { apply plugin: 'com.palantir.java-format' apply plugin: 'com.palantir.jakarta-package-alignment' - version System.env.CIRCLE_TAG ?: gitVersion() + version '10.0.0' group 'com.palantir.sls-packaging' repositories { diff --git a/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/DiagnosticsManifestPlugin.java b/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/DiagnosticsManifestPlugin.java index 714358f97..c9f536fef 100644 --- a/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/DiagnosticsManifestPlugin.java +++ b/gradle-sls-packaging/src/main/java/com/palantir/gradle/dist/service/DiagnosticsManifestPlugin.java @@ -17,7 +17,6 @@ package com.palantir.gradle.dist.service; import com.palantir.gradle.dist.artifacts.ExtractFileFromJar; -import com.palantir.gradle.dist.artifacts.SelectSingleFile; import com.palantir.gradle.dist.tasks.CreateManifestTask; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -38,7 +37,7 @@ public final class DiagnosticsManifestPlugin implements Plugin { static final String mergeDiagnosticsJson = "mergeDiagnosticsJson"; private static final String FILE_TO_EXTRACT = "sls-manifest/diagnostics.json"; - private static final String MY_ATTRIBUTE = "extracted-" + FILE_TO_EXTRACT; + private static final String DIAGNOSTICS = "sls-diagnostics"; /** * This plugin uses a few slightly 'advanced' gradle features: @@ -58,18 +57,17 @@ public final class DiagnosticsManifestPlugin implements Plugin { @Override @SuppressWarnings("RawTypes") public void apply(Project project) { - configureExternalDependencyTransform(project); - configureProjectDependencyTransform(project); + configureJarTransform(project); Configuration consumableRuntimeConfiguration = createConsumableRuntimeConfiguration(project); ArtifactView attributeSpecificArtifactView = consumableRuntimeConfiguration .getIncoming() .artifactView(v -> { - v.getAttributes().attribute(artifactType, MY_ATTRIBUTE); + v.getAttributes().attribute(artifactType, DIAGNOSTICS); v.getAttributes() .attribute( LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, - project.getObjects().named(LibraryElements.class, MY_ATTRIBUTE)); + project.getObjects().named(LibraryElements.class, DIAGNOSTICS)); }); TaskProvider mergeDiagnosticsTask = project.getTasks() @@ -95,13 +93,15 @@ public void apply(Project project) { }); } - private static void configureExternalDependencyTransform(Project project) { + private static void configureJarTransform(Project project) { project.getDependencies().registerTransform(ExtractFileFromJar.class, details -> { details.getParameters().getPathToExtract().set(FILE_TO_EXTRACT); details.getFrom().attribute(artifactType, ArtifactTypeDefinition.JAR_TYPE); - details.getTo().attribute(artifactType, MY_ATTRIBUTE); + details.getTo().attribute(artifactType, DIAGNOSTICS); + // It's not strictly necessary to define a mapping for the 'org.gradle.libraryelements' attribute, + // but it looks a bit weird for something to still be marked as a 'jar' when it's clearly not. details.getFrom() .attribute( LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, @@ -109,25 +109,7 @@ private static void configureExternalDependencyTransform(Project project) { details.getTo() .attribute( LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, - project.getObjects().named(LibraryElements.class, MY_ATTRIBUTE)); - }); - } - - private static void configureProjectDependencyTransform(Project project) { - project.getDependencies().registerTransform(SelectSingleFile.class, details -> { - details.getParameters().getPathToExtract().set(FILE_TO_EXTRACT); - - details.getFrom().attribute(artifactType, ArtifactTypeDefinition.JVM_RESOURCES_DIRECTORY); - details.getTo().attribute(artifactType, MY_ATTRIBUTE); - - details.getFrom() - .attribute( - LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, - project.getObjects().named(LibraryElements.class, LibraryElements.RESOURCES)); - details.getTo() - .attribute( - LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, - project.getObjects().named(LibraryElements.class, MY_ATTRIBUTE)); + project.getObjects().named(LibraryElements.class, DIAGNOSTICS)); }); }