diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/IvyPublicationExtractor.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/IvyPublicationExtractor.java index 450f4c9..cfe15e6 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/IvyPublicationExtractor.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/IvyPublicationExtractor.java @@ -18,7 +18,6 @@ import java.util.Set; import static org.jfrog.gradle.plugin.artifactory.utils.PublicationUtils.addArtifactInfoToDeployDetails; -import static org.jfrog.gradle.plugin.artifactory.utils.PublicationUtils.createArtifactBuilder; public class IvyPublicationExtractor extends PublicationExtractor { @@ -95,10 +94,7 @@ private File extractIvyDescriptor(IvyPublication publication, Map if (!ivyFile.exists()) { return null; } - DeployDetails.Builder builder = createArtifactBuilder(ivyFile, publication.getName()); - PublishArtifactInfo artifactInfo = new PublishArtifactInfo( - publication.getModule(), "xml", "ivy", null, extraInfo, ivyFile); - addArtifactToDeployDetails(publication, builder, artifactInfo); + buildAndPublishArtifactWithSignatures(ivyFile, publication, publication.getModule(), "xml", "ivy", null, extraInfo); return ivyFile; } @@ -132,11 +128,7 @@ private void extractIvyArtifacts(File ivyFile, IvyPublication publication, Map { @@ -76,10 +75,7 @@ private void extractMavenDescriptor(MavenPublication publication) { if (!pomFile.exists()) { return; } - DeployDetails.Builder builder = createArtifactBuilder(pomFile, publication.getName()); - PublishArtifactInfo artifactInfo = new PublishArtifactInfo( - publication.getArtifactId(), "pom", "pom", null, pomFile); - addArtifactToDeployDetails(publication, builder, artifactInfo); + buildAndPublishArtifactWithSignatures(pomFile, publication, publication.getArtifactId(), "pom", "pom", null, null); } /** @@ -112,11 +108,6 @@ private void extractMavenArtifacts(MavenPublication publication) { private void createPublishArtifactInfoAndAddToDeployDetails(MavenArtifact artifact, MavenPublication publication) { File file = artifact.getFile(); - DeployDetails.Builder builder = createArtifactBuilder(file, publication.getName()); - PublishArtifactInfo artifactInfo = new PublishArtifactInfo( - publication.getArtifactId(), artifact.getExtension(), - artifact.getExtension(), artifact.getClassifier(), - file); - addArtifactToDeployDetails(publication, builder, artifactInfo); + buildAndPublishArtifactWithSignatures(file, publication, publication.getArtifactId(), artifact.getExtension(), artifact.getExtension(), artifact.getClassifier(), null); } } diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/PublicationExtractor.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/PublicationExtractor.java index d061562..557ae9f 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/PublicationExtractor.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/publication/PublicationExtractor.java @@ -2,16 +2,21 @@ import org.gradle.api.publish.Publication; import org.gradle.api.publish.tasks.GenerateModuleMetadata; +import org.gradle.plugins.signing.Sign; import org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails; import org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo; import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask; +import javax.xml.namespace.QName; import java.io.File; +import java.util.Map; import static org.jfrog.gradle.plugin.artifactory.utils.PublicationUtils.createArtifactBuilder; public abstract class PublicationExtractor { protected ArtifactoryTask artifactoryTask; + // Signature types supported by the Signing plugin. + private final String[] SIGNATURE_EXTENSIONS = {"asc", "sig"}; public PublicationExtractor(ArtifactoryTask artifactoryTask) { this.artifactoryTask = artifactoryTask; @@ -65,12 +70,60 @@ public void extractModuleInfo() { continue; } - DeployDetails.Builder builder = createArtifactBuilder(moduleMetadata, generateModuleMetadata.getPublication().get().getName()); - //noinspection unchecked ActualPublication actualPublication = (ActualPublication) publication; - PublishArtifactInfo artifactInfo = new PublishArtifactInfo(getPublicationArtifactId(actualPublication), "module", "module", null, moduleMetadata); - addArtifactToDeployDetails(actualPublication, builder, artifactInfo); + buildAndPublishArtifactWithSignatures(moduleMetadata, actualPublication, getPublicationArtifactId(actualPublication), "module", "module", null, null); + } + } + + /** + * Build and publish the artifact and add it to deploy details. + * If the Signing plugin was used, do the same to the artifact's signatures. + * + * @param file - The file to publish + * @param publication - The publication to extract details from + * @param artifactId - The artifact ID + * @param artifactExtension - The artifact extension + * @param artifactType - The artifact type + * @param artifactClassifier - The artifact classifier + * @param extraInfo - Extra information to add to the deploy details + */ + protected void buildAndPublishArtifactWithSignatures(File file, ActualPublication publication, String artifactId, String artifactExtension, String artifactType, String artifactClassifier, Map extraInfo) { + buildAndPublishArtifact(file, publication, artifactId, artifactExtension, artifactType, artifactClassifier, extraInfo); + if (!isSignTaskExists()) { + return; + } + for (String signatureExtension : SIGNATURE_EXTENSIONS) { + File signatureFile = new File(file.getAbsolutePath() + "." + signatureExtension); + if (!signatureFile.exists()) { + continue; + } + buildAndPublishArtifact(signatureFile, publication, artifactId, artifactType + "." + signatureExtension, artifactType + "." + signatureExtension, artifactClassifier, extraInfo); } } + + /** + * Build and publish the artifact and add it to deploy details. + * + * @param file - The file to publish + * @param publication - The publication to extract details from + * @param artifactId - The artifact ID + * @param artifactExtension - The artifact extension + * @param artifactType - The artifact type + * @param artifactClassifier - The artifact classifier + * @param extraInfo - Extra information to add to the deploy details + */ + private void buildAndPublishArtifact(File file, ActualPublication publication, String artifactId, String artifactExtension, String artifactType, String artifactClassifier, Map extraInfo) { + DeployDetails.Builder builder = createArtifactBuilder(file, publication.getName()); + PublishArtifactInfo artifactInfo = new PublishArtifactInfo( + artifactId, artifactExtension, artifactType, artifactClassifier, extraInfo, file); + addArtifactToDeployDetails(publication, builder, artifactInfo); + } + + /** + * @return true if the Signing plugin was used in the project + */ + private boolean isSignTaskExists() { + return !artifactoryTask.getProject().getTasks().withType(Sign.class).isEmpty(); + } } diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java index 53d880b..400dd6a 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java @@ -17,6 +17,7 @@ import org.gradle.api.publish.tasks.GenerateModuleMetadata; import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.*; +import org.gradle.plugins.signing.Sign; import org.jfrog.build.api.builder.ModuleType; import org.jfrog.build.api.multiMap.Multimap; import org.jfrog.build.api.multiMap.SetMultimap; @@ -195,6 +196,7 @@ public void moduleType(String moduleType) { * Extract the publications arguments for the task and make sure this task dependsOn the specified publications tasks. */ private void checkDependsOnArtifactsToPublish() { + createDependencyOnSigningTask(); extractPublications(); if (!hasPublications()) { if (publishPublicationsSpecified) { @@ -211,6 +213,10 @@ private void checkDependsOnArtifactsToPublish() { createDependencyOnModuleMetadata(); } + private void createDependencyOnSigningTask() { + dependsOn(getProject().getTasks().withType(Sign.class)); + } + /** * Extract the given publications arguments, process each entry, validate the argument and fetch its matching Publication */