diff --git a/pgp-keys-map.list b/pgp-keys-map.list index 447edf8..2f4da1b 100644 --- a/pgp-keys-map.list +++ b/pgp-keys-map.list @@ -16,6 +16,7 @@ # under the License. commons-io:commons-io = 0x2DB4F1EF0FA761ECC4EA935C86FDC7E2A11262CB +javax.inject:javax.inject = noSig org.apiguardian:apiguardian-api = 0xFF6E2C001948C5F2F38B0CC385911F425EC61B51 org.junit.jupiter:junit-jupiter-api = 0xFF6E2C001948C5F2F38B0CC385911F425EC61B51 org.junit.jupiter:junit-jupiter-engine = 0xFF6E2C001948C5F2F38B0CC385911F425EC61B51 @@ -27,14 +28,12 @@ org.opentest4j:opentest4j = 0xFF6E2C001948C5F2F38B0CC385911F425EC61B51 net.bytebuddy:byte-buddy = 0xB4AC8CDC141AF0AE468D16921DA784CCB5C46DD5 org.assertj:assertj-core = 0xBE685132AFD2740D9095F9040CC0B712FEE75827 org.apache.maven.resolver = 0x522CA055B326A636D833EF6A0551FD3684FCBBB7 -org.apache.maven.shared:maven-artifact-transfer = 0x6A814B1F869C2BBEAB7CB7271A2A1C94BDE89688 -org.apache.maven.shared:maven-common-artifact-filters = 0xB02137D875D833D9B23392ECAE5A7FB608A0221C org.apache.maven.shared:maven-invoker = 0x84789D24DF77A32433CE1F079EB80E92EB2135B1 -org.apache.maven.shared:maven-shared-utils = 0x82C9EC0E52C47A936A849E0113D979595E6D01E1 +org.codehaus.plexus:plexus-cipher = 0x6A814B1F869C2BBEAB7CB7271A2A1C94BDE89688 org.codehaus.plexus:plexus-classworlds = 0xB91AB7D2121DC6B0A61AA182D7742D58455ECC7C org.codehaus.plexus:plexus-component-annotations = 0xFA77DCFEF2EE6EB2DEBEDD2C012579464D01C06A org.codehaus.plexus:plexus-utils = 0xF254B35617DC255D9344BCFA873A8E86B4372146 +org.codehaus.plexus:plexus-sec-dispatcher = 0x2BE13D052E9AA567D657D9791FD507154FB9BA39 org.hamcrest:hamcrest = 0xE3A9F95079E84CE201F7CF60BEDE11EAF1164480 org.hamcrest:hamcrest-core = 0xE3A9F95079E84CE201F7CF60BEDE11EAF1164480 org.slf4j:slf4j-api = 0x475F3B8E59E6E63AA78067482C7B12F2A511E325 -org.sonatype.sisu = 0xBA926F64CA647B6D853A38672E2010F8A7FF4A41 diff --git a/pom.xml b/pom.xml index 437a9d6..1dd3e5a 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ under the License. 3.9.6 + 1.9.18 8 2023-05-03T01:33:44Z @ @@ -91,12 +92,6 @@ under the License. ${mavenVersion} provided - - org.apache.maven - maven-artifact - ${mavenVersion} - provided - org.apache.maven maven-model @@ -110,9 +105,9 @@ under the License. provided - org.apache.maven - maven-settings - ${mavenVersion} + org.apache.maven.resolver + maven-resolver-api + ${resolverVersion} provided @@ -120,16 +115,16 @@ under the License. maven-plugin-annotations provided - - org.apache.maven.shared - maven-artifact-transfer - 0.13.1 - org.codehaus.plexus plexus-utils 3.5.1 + + org.codehaus.plexus + plexus-sec-dispatcher + 2.0 + org.assertj diff --git a/src/main/java/org/apache/maven/plugins/gpg/AscArtifactMetadata.java b/src/main/java/org/apache/maven/plugins/gpg/AscArtifactMetadata.java deleted file mode 100644 index 605eb2d..0000000 --- a/src/main/java/org/apache/maven/plugins/gpg/AscArtifactMetadata.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.maven.plugins.gpg; - -import java.io.File; -import java.io.IOException; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.AbstractArtifactMetadata; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; -import org.codehaus.plexus.util.FileUtils; - -/** - * @author dkulp - * - */ -public class AscArtifactMetadata extends AbstractArtifactMetadata - implements org.apache.maven.shared.transfer.metadata.ArtifactMetadata { - - private final File file; - - private final boolean isPom; - - public AscArtifactMetadata(Artifact artifact, File file, boolean isPom) { - super(artifact); - this.file = file; - this.isPom = isPom; - } - - @Override - public String getBaseVersion() { - return artifact.getBaseVersion(); - } - - @Override - public Object getKey() { - return "gpg signature " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() - + ":" + artifact.getClassifier() + (isPom ? ":pom" : ""); - } - - private String getFilename() { - StringBuilder buf = new StringBuilder(128); - buf.append(getArtifactId()); - buf.append("-").append(artifact.getVersion()); - if (isPom) { - buf.append(".pom"); - } else { - if (artifact.getClassifier() != null && !"".equals(artifact.getClassifier())) { - buf.append("-").append(artifact.getClassifier()); - } - buf.append(".").append(artifact.getArtifactHandler().getExtension()); - } - buf.append(".asc"); - return buf.toString(); - } - - @Override - public String getLocalFilename(ArtifactRepository repository) { - return getFilename(); - } - - @Override - public String getRemoteFilename() { - return getFilename(); - } - - @Override - public void merge(ArtifactMetadata metadata) { - merge((AscArtifactMetadata) metadata); - } - - @Override - public void merge(org.apache.maven.repository.legacy.metadata.ArtifactMetadata metadata) { - merge((AscArtifactMetadata) metadata); - } - - private void merge(AscArtifactMetadata metadata) { - if (!metadata.file.equals(file)) { - throw new IllegalStateException("Cannot add two different pieces of metadata for: " + getKey()); - } - } - - @Override - public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactRepository remoteRepository) - throws RepositoryMetadataStoreException { - File destination = new File( - localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata(this, remoteRepository)); - - try { - FileUtils.copyFile(file, destination); - } catch (IOException e) { - throw new RepositoryMetadataStoreException("Error copying ASC to the local repository.", e); - } - } - - @Override - public boolean storedInArtifactVersionDirectory() { - return true; - } - - @Override - public String toString() { - return getFilename(); - } - - @Override - public File getFile() { - return file; - } -} diff --git a/src/main/java/org/apache/maven/plugins/gpg/AttachedSignedArtifact.java b/src/main/java/org/apache/maven/plugins/gpg/AttachedSignedArtifact.java deleted file mode 100644 index 4749e6f..0000000 --- a/src/main/java/org/apache/maven/plugins/gpg/AttachedSignedArtifact.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.maven.plugins.gpg; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.apache.maven.artifact.versioning.VersionRange; - -/** - * A wrapper class for attached artifacts which have a GPG signature. Needed as attached artifacts in general do not - * have metadata. - */ -public class AttachedSignedArtifact implements Artifact { - private final Artifact delegate; - - private final AscArtifactMetadata signature; - - public AttachedSignedArtifact(Artifact delegate, AscArtifactMetadata signature) { - this.delegate = delegate; - this.signature = signature; - } - - @Override - public void setArtifactId(String artifactId) { - delegate.setArtifactId(artifactId); - } - - @Override - public List getAvailableVersions() { - return delegate.getAvailableVersions(); - } - - @Override - public void setAvailableVersions(List availableVersions) { - delegate.setAvailableVersions(availableVersions); - } - - @Override - public String getBaseVersion() { - return delegate.getBaseVersion(); - } - - @Override - public void setBaseVersion(String baseVersion) { - delegate.setBaseVersion(baseVersion); - } - - @Override - public String getDownloadUrl() { - return delegate.getDownloadUrl(); - } - - @Override - public void setDownloadUrl(String downloadUrl) { - delegate.setDownloadUrl(downloadUrl); - } - - @Override - public void setGroupId(String groupId) { - delegate.setGroupId(groupId); - } - - @Override - public ArtifactRepository getRepository() { - return delegate.getRepository(); - } - - @Override - public void setRepository(ArtifactRepository repository) { - delegate.setRepository(repository); - } - - @Override - public String getScope() { - return delegate.getScope(); - } - - @Override - public void setScope(String scope) { - delegate.setScope(scope); - } - - @Override - public String getVersion() { - return delegate.getVersion(); - } - - @Override - public void setVersion(String version) { - delegate.setVersion(version); - } - - @Override - public VersionRange getVersionRange() { - return delegate.getVersionRange(); - } - - @Override - public void setVersionRange(VersionRange range) { - delegate.setVersionRange(range); - } - - @Override - public boolean isRelease() { - return delegate.isRelease(); - } - - @Override - public void setRelease(boolean release) { - delegate.setRelease(release); - } - - @Override - public boolean isSnapshot() { - return delegate.isSnapshot(); - } - - @Override - public void addMetadata(ArtifactMetadata metadata) { - delegate.addMetadata(metadata); - } - - @Override - public String getClassifier() { - return delegate.getClassifier(); - } - - @Override - public boolean hasClassifier() { - return delegate.hasClassifier(); - } - - @Override - public String getGroupId() { - return delegate.getGroupId(); - } - - @Override - public String getArtifactId() { - return delegate.getArtifactId(); - } - - @Override - public String getType() { - return delegate.getType(); - } - - @Override - public void setFile(File file) { - delegate.setFile(file); - } - - @Override - public File getFile() { - return delegate.getFile(); - } - - @Override - public String getId() { - return delegate.getId(); - } - - @Override - public String getDependencyConflictId() { - return delegate.getDependencyConflictId(); - } - - @Override - public String toString() { - return delegate.toString(); - } - - @Override - public int hashCode() { - return delegate.hashCode(); - } - - @Override - public boolean equals(Object o) { - return delegate.equals(o); - } - - @Override - public void updateVersion(String version, ArtifactRepository localRepository) { - delegate.updateVersion(version, localRepository); - } - - @Override - public ArtifactFilter getDependencyFilter() { - return delegate.getDependencyFilter(); - } - - @Override - public void setDependencyFilter(ArtifactFilter artifactFilter) { - delegate.setDependencyFilter(artifactFilter); - } - - @Override - public ArtifactHandler getArtifactHandler() { - return delegate.getArtifactHandler(); - } - - @Override - public List getDependencyTrail() { - return delegate.getDependencyTrail(); - } - - @Override - public void setDependencyTrail(List dependencyTrail) { - delegate.setDependencyTrail(dependencyTrail); - } - - @Override - public void selectVersion(String version) { - delegate.selectVersion(version); - } - - @Override - public void setResolved(boolean resolved) { - delegate.setResolved(resolved); - } - - @Override - public boolean isResolved() { - return delegate.isResolved(); - } - - @Override - public void setResolvedVersion(String version) { - delegate.setResolvedVersion(version); - } - - @Override - public void setArtifactHandler(ArtifactHandler artifactHandler) { - delegate.setArtifactHandler(artifactHandler); - } - - @Override - public boolean isOptional() { - return delegate.isOptional(); - } - - @Override - public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException { - return delegate.getSelectedVersion(); - } - - @Override - public boolean isSelectedVersionKnown() throws OverConstrainedVersionException { - return delegate.isSelectedVersionKnown(); - } - - @Override - public void setOptional(boolean optional) { - delegate.setOptional(optional); - } - - @Override - public Collection getMetadataList() { - List result = new ArrayList<>(delegate.getMetadataList()); - - for (ArtifactMetadata metadata : result) { - if (signature.getKey().equals(metadata.getKey())) { - // already signed - return result; - } - } - - result.add(signature); - - return result; - } - - @Override - public int compareTo(Artifact o) { - return delegate.compareTo(o); - } -} diff --git a/src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java b/src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java index e8b7a62..8fce44f 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java @@ -66,7 +66,7 @@ public class GpgSignAttachedMojo extends AbstractGpgMojo { /** * The maven project. */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) + @Component protected MavenProject project; /** diff --git a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java index e2a151c..f32f389 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java @@ -25,16 +25,10 @@ import java.io.Writer; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.MavenArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; @@ -52,16 +46,17 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.project.artifact.ProjectArtifactMetadata; -import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer; -import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.deployment.DeploymentException; +import org.eclipse.aether.repository.RemoteRepository; /** * Signs artifacts and installs the artifact in the remote repository. @@ -159,50 +154,6 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo { @Parameter(property = "repositoryLayout", defaultValue = "default") private String repositoryLayout; - /** - */ - @Component - private ArtifactDeployer deployer; - - /** - */ - @Parameter(defaultValue = "${localRepository}", required = true, readonly = true) - private ArtifactRepository localRepository; - - /** - * Component used to create an artifact - */ - @Component - private ArtifactFactory artifactFactory; - - /** - * The component used to validate the user-supplied artifact coordinates. - */ - @Component - private ModelValidator modelValidator; - - /** - * The default Maven project created when building the plugin - * - * @since 1.3 - */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; - - /** - * @since 3.0.0 - */ - @Parameter(defaultValue = "${session}", readonly = true, required = true) - private MavenSession session; - - /** - * Used for attaching the source and javadoc jars to the project. - * - * @since 1.3 - */ - @Component - private MavenProjectHelper projectHelper; - /** * The bundled API docs for the artifact. * @@ -228,14 +179,6 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo { @Parameter(property = "retryFailedDeploymentCount", defaultValue = "1") private int retryFailedDeploymentCount; - /** - * Parameter used to update the metadata to make the artifact as release. - * - * @since 1.3 - */ - @Parameter(property = "updateReleaseInfo", defaultValue = "false") - protected boolean updateReleaseInfo; - /** * A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in * the number of entries in {@link #files} or {@link #classifiers}, then an error will be raised. @@ -257,6 +200,37 @@ public class SignAndDeployFileMojo extends AbstractGpgMojo { @Parameter(property = "files") private String files; + /** + */ + @Component + private RepositorySystem repositorySystem; + + /** + * The component used to validate the user-supplied artifact coordinates. + */ + @Component + private ModelValidator modelValidator; + + /** + * The default Maven project created when building the plugin + * + * @since 1.3 + */ + @Component + private MavenProject project; + + /** + * @since 3.0.0 + */ + @Component + private MavenSession session; + + /** + * @since 3.2.0 + */ + @Component + private ArtifactHandlerManager artifactHandlerManager; + private void initProperties() throws MojoExecutionException { // Process the supplied POM (if there is one) if (pomFile != null) { @@ -274,10 +248,6 @@ private void initProperties() throws MojoExecutionException { @Override public void execute() throws MojoExecutionException, MojoFailureException { - AbstractGpgSigner signer = newSigner(null); - signer.setOutputDirectory(ascDirectory); - signer.setBaseDirectory(new File("").getAbsoluteFile()); - if (offline) { throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode"); } @@ -290,56 +260,50 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException(file.getPath() + " not found."); } - ArtifactRepository deploymentRepository = createDeploymentArtifactRepository(repositoryId, url); - - if (StringUtils.isEmpty(deploymentRepository.getProtocol())) { - throw new MojoFailureException("No transfer protocol found."); - } - - Artifact artifact = - artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier); - - if (file.equals(getLocalRepoFile(artifact))) { + RemoteRepository deploymentRepository = new RemoteRepository.Builder(repositoryId, "default", url).build(); + + // create artifacts + List artifacts = new ArrayList<>(); + + // main artifact + ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(packaging); + Artifact main = new DefaultArtifact( + groupId, + artifactId, + classifier == null || classifier.trim().isEmpty() ? handler.getClassifier() : classifier, + handler.getExtension(), + version) + .setFile(file); + + File localRepoFile = new File( + session.getRepositorySession().getLocalRepository().getBasedir(), + session.getRepositorySession().getLocalRepositoryManager().getPathForLocalArtifact(main)); + if (file.equals(localRepoFile)) { throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file); } - artifact.setFile(file); - - File fileSig = signer.generateSignatureForArtifact(file); - ArtifactMetadata metadata = new AscArtifactMetadata(artifact, fileSig, false); - artifact.addMetadata(metadata); + artifacts.add(main); if (!"pom".equals(packaging)) { if (pomFile == null && generatePom) { pomFile = generatePomFile(); } if (pomFile != null) { - metadata = new ProjectArtifactMetadata(artifact, pomFile); - artifact.addMetadata(metadata); - - fileSig = signer.generateSignatureForArtifact(pomFile); - metadata = new AscArtifactMetadata(artifact, fileSig, true); - artifact.addMetadata(metadata); + artifacts.add( + new DefaultArtifact(main.getGroupId(), main.getArtifactId(), null, "pom", main.getVersion()) + .setFile(pomFile)); } } - if (updateReleaseInfo) { - artifact.setRelease(true); - } - - project.setArtifact(artifact); - - try { - deploy(artifact, deploymentRepository); - } catch (ArtifactDeployerException e) { - throw new MojoExecutionException(e.getMessage(), e); - } - if (sources != null) { - projectHelper.attachArtifact(project, "jar", "sources", sources); + artifacts.add( + new DefaultArtifact(main.getGroupId(), main.getArtifactId(), "sources", "jar", main.getVersion()) + .setFile(sources)); } if (javadoc != null) { - projectHelper.attachArtifact(project, "jar", "javadoc", javadoc); + artifacts.add( + new DefaultArtifact(main.getGroupId(), main.getArtifactId(), "javadoc", "jar", main.getVersion()) + .setFile(javadoc)); } if (files != null) { @@ -349,55 +313,38 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (classifiers == null) { throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'"); } - int filesLength = StringUtils.countMatches(files, ","); - int typesLength = StringUtils.countMatches(types, ","); - int classifiersLength = StringUtils.countMatches(classifiers, ","); - if (typesLength != filesLength) { + String[] files = this.files.split(",", -1); + String[] types = this.types.split(",", -1); + String[] classifiers = this.classifiers.split(",", -1); + if (types.length != files.length) { throw new MojoExecutionException("You must specify the same number of entries in 'files' and " - + "'types' (respectively " + filesLength + " and " + typesLength + " entries )"); + + "'types' (respectively " + files.length + " and " + types.length + " entries )"); } - if (classifiersLength != filesLength) { + if (classifiers.length != files.length) { throw new MojoExecutionException("You must specify the same number of entries in 'files' and " - + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )"); + + "'classifiers' (respectively " + files.length + " and " + classifiers.length + " entries )"); } - int fi = 0; - int ti = 0; - int ci = 0; - for (int i = 0; i <= filesLength; i++) { - int nfi = files.indexOf(',', fi); - if (nfi == -1) { - nfi = files.length(); - } - int nti = types.indexOf(',', ti); - if (nti == -1) { - nti = types.length(); - } - int nci = classifiers.indexOf(',', ci); - if (nci == -1) { - nci = classifiers.length(); - } - File file = new File(files.substring(fi, nfi)); + for (int i = 0; i < files.length; i++) { + File file = new File(files[i]); if (!file.isFile()) { // try relative to the project basedir just in case - file = new File(project.getBasedir(), files.substring(fi, nfi)); + file = new File(project.getBasedir(), files[i]); } if (file.isFile()) { - if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) { - projectHelper.attachArtifact( - project, types.substring(ti, nti).trim(), file); + Artifact artifact; + String ext = + artifactHandlerManager.getArtifactHandler(types[i]).getExtension(); + if (StringUtils.isWhitespace(classifiers[i])) { + artifact = new DefaultArtifact( + main.getGroupId(), main.getArtifactId(), null, ext, main.getVersion()); } else { - projectHelper.attachArtifact( - project, - types.substring(ti, nti).trim(), - classifiers.substring(ci, nci).trim(), - file); + artifact = new DefaultArtifact( + main.getGroupId(), main.getArtifactId(), classifiers[i], ext, main.getVersion()); } + artifacts.add(artifact.setFile(file)); } else { throw new MojoExecutionException("Specified side artifact " + file + " does not exist"); } - fi = nfi + 1; - ti = nti + 1; - ci = nci + 1; } } else { if (types != null) { @@ -408,28 +355,30 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } - for (Artifact attached : project.getAttachedArtifacts()) { - fileSig = signer.generateSignatureForArtifact(attached.getFile()); - attached = new AttachedSignedArtifact(attached, new AscArtifactMetadata(attached, fileSig, false)); - try { - deploy(attached, deploymentRepository); - } catch (ArtifactDeployerException e) { - throw new MojoExecutionException( - "Error deploying attached artifact " + attached.getFile() + ": " + e.getMessage(), e); - } + // sign all + AbstractGpgSigner signer = newSigner(null); + signer.setOutputDirectory(ascDirectory); + signer.setBaseDirectory(new File("").getAbsoluteFile()); + + ArrayList signatures = new ArrayList<>(); + for (Artifact a : artifacts) { + signatures.add(new DefaultArtifact( + a.getGroupId(), + a.getArtifactId(), + a.getClassifier(), + a.getExtension() + AbstractGpgSigner.SIGNATURE_EXTENSION, + a.getVersion()) + .setFile(signer.generateSignatureForArtifact(a.getFile()))); } - } + artifacts.addAll(signatures); - /** - * Gets the path of the specified artifact within the local repository. Note that the returned path need not exist - * (yet). - * - * @param artifact The artifact whose local repo path should be determined, must not be null. - * @return The absolute path to the artifact when installed, never null. - */ - private File getLocalRepoFile(Artifact artifact) { - String path = localRepository.pathOf(artifact); - return new File(localRepository.getBasedir(), path); + // deploy all + try { + deploy(deploymentRepository, artifacts); + } catch (DeploymentException e) { + throw new MojoExecutionException( + "Error deploying attached artifacts " + artifacts + ": " + e.getMessage(), e); + } } /** @@ -469,8 +418,7 @@ private void processModel(Model model) { */ private Model readModel(File pomFile) throws MojoExecutionException { try (Reader reader = ReaderFactory.newXmlReader(pomFile)) { - final Model model = new MavenXpp3Reader().read(reader); - return model; + return new MavenXpp3Reader().read(reader); } catch (FileNotFoundException e) { throw new MojoExecutionException("POM not found " + pomFile, e); } catch (IOException e) { @@ -552,15 +500,13 @@ private Model generateModel() { /** * Deploy an artifact from a particular file. * - * @param artifact the artifact definition * @param deploymentRepository the repository to deploy to - * @throws ArtifactDeployerException if an error occurred deploying the artifact + * @param artifacts the artifacts definition + * @throws DeploymentException if an error occurred deploying the artifact */ - protected void deploy(Artifact artifact, ArtifactRepository deploymentRepository) throws ArtifactDeployerException { - final ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest(); - + protected void deploy(RemoteRepository deploymentRepository, List artifacts) throws DeploymentException { int retryFailedDeploymentCount = Math.max(1, Math.min(10, this.retryFailedDeploymentCount)); - ArtifactDeployerException exception = null; + DeploymentException exception = null; for (int count = 0; count < retryFailedDeploymentCount; count++) { try { if (count > 0) { @@ -568,15 +514,14 @@ protected void deploy(Artifact artifact, ArtifactRepository deploymentRepository getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCount); // CHECKSTYLE_ON: LineLength } - deployer.deploy(buildingRequest, deploymentRepository, Collections.singletonList(artifact)); + DeployRequest deployRequest = new DeployRequest(); + deployRequest.setRepository(deploymentRepository); + deployRequest.setArtifacts(artifacts); - for (Object o : artifact.getMetadataList()) { - ArtifactMetadata metadata = (ArtifactMetadata) o; - getLog().info("Metadata[" + metadata.getKey() + "].filename = " + metadata.getRemoteFilename()); - } + repositorySystem.deploy(session.getRepositorySession(), deployRequest); exception = null; break; - } catch (ArtifactDeployerException e) { + } catch (DeploymentException e) { if (count + 1 < retryFailedDeploymentCount) { getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage()); getLog().debug(e); @@ -591,11 +536,6 @@ protected void deploy(Artifact artifact, ArtifactRepository deploymentRepository } } - protected ArtifactRepository createDeploymentArtifactRepository(String id, String url) { - return new MavenArtifactRepository( - id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy()); - } - private static class SimpleModelProblemCollector implements ModelProblemCollector { private final List result;