You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/12/01 13:21:50 UTC
[maven-gpg-plugin] 01/03: [MGPG-69] Drop Maven 2 support (require
Maven 3)
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MGPG-69
in repository https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git
commit 797fc51b6f2c61b6cbfb497cfd309de58274dc17
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Oct 25 17:14:36 2019 +0200
[MGPG-69] Drop Maven 2 support (require Maven 3)
---
pom.xml | 24 +++-
.../maven/plugin/gpg/AscArtifactMetadata.java | 28 ++++-
.../maven/plugin/gpg/AttachedSignedArtifact.java | 7 --
.../maven/plugin/gpg/SignAndDeployFileMojo.java | 127 +++++++++++++--------
4 files changed, 122 insertions(+), 64 deletions(-)
diff --git a/pom.xml b/pom.xml
index e0a5919..cfddea8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,7 +62,7 @@ under the License.
</distributionManagement>
<properties>
- <mavenVersion>2.2.1</mavenVersion>
+ <mavenVersion>3.0</mavenVersion>
<javaVersion>7</javaVersion>
</properties>
@@ -74,7 +74,7 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-project</artifactId>
+ <artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
@@ -84,12 +84,17 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-repository-metadata</artifactId>
+ <artifactId>maven-model</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
+ <artifactId>maven-model-builder</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
@@ -98,6 +103,11 @@ under the License.
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-artifact-transfer</artifactId>
+ <version>0.11.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.1.0</version>
@@ -114,6 +124,12 @@ under the License.
<version>4.12</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/java/org/apache/maven/plugin/gpg/AscArtifactMetadata.java b/src/main/java/org/apache/maven/plugin/gpg/AscArtifactMetadata.java
index c4b95b5..118b58c 100644
--- a/src/main/java/org/apache/maven/plugin/gpg/AscArtifactMetadata.java
+++ b/src/main/java/org/apache/maven/plugin/gpg/AscArtifactMetadata.java
@@ -34,12 +34,12 @@ import org.codehaus.plexus.util.FileUtils;
*
*/
public class AscArtifactMetadata
- extends AbstractArtifactMetadata
+ extends AbstractArtifactMetadata implements org.apache.maven.shared.transfer.metadata.ArtifactMetadata
{
- File file;
+ private final File file;
- boolean isPom;
+ private final boolean isPom;
public AscArtifactMetadata( Artifact artifact, File file, boolean isPom )
{
@@ -97,11 +97,21 @@ public class AscArtifactMetadata
@Override
public void merge( ArtifactMetadata metadata )
{
- AscArtifactMetadata m = (AscArtifactMetadata) metadata;
- if ( !m.file.equals( file ) )
+ 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
@@ -134,4 +144,10 @@ public class AscArtifactMetadata
return getFilename();
}
+ @Override
+ public File getFile()
+ {
+ return file;
+ }
+
}
diff --git a/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java b/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java
index 964e16f..072bf2a 100644
--- a/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java
+++ b/src/main/java/org/apache/maven/plugin/gpg/AttachedSignedArtifact.java
@@ -358,11 +358,4 @@ public class AttachedSignedArtifact
{
return delegate.compareTo( o );
}
-
- @Override
- public ArtifactMetadata getMetadata( Class<?> metadataClass )
- {
- // TODO Auto-generated method stub
- return delegate.getMetadata( metadataClass );
- }
}
diff --git a/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java
index 9b0838e..3d67fd5 100644
--- a/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugin/gpg/SignAndDeployFileMojo.java
@@ -24,21 +24,29 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.Map;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.deployer.ArtifactDeployer;
-import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
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.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+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.execution.MavenSession;
+import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
+import org.apache.maven.model.building.DefaultModelBuildingRequest;
+import org.apache.maven.model.building.ModelBuildingRequest;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblem.Severity;
+import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.apache.maven.model.validation.ModelValidator;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
@@ -46,9 +54,10 @@ 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.project.validation.ModelValidationResult;
-import org.apache.maven.project.validation.ModelValidator;
+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;
@@ -134,12 +143,6 @@ public class SignAndDeployFileMojo
private boolean generatePom;
/**
- * Whether to deploy snapshots with a unique version or not.
- */
- @Parameter( property = "uniqueVersion", defaultValue = "true" )
- private boolean uniqueVersion;
-
- /**
* URL where the artifact will be deployed. <br/>
* ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
*/
@@ -170,24 +173,12 @@ public class SignAndDeployFileMojo
private ArtifactRepository localRepository;
/**
- * Map that contains the layouts.
- */
- @Component( role = ArtifactRepositoryLayout.class )
- private Map<String, ArtifactRepositoryLayout> repositoryLayouts;
-
- /**
* Component used to create an artifact
*/
@Component
private ArtifactFactory artifactFactory;
/**
- * Component used to create a repository
- */
- @Component
- private ArtifactRepositoryFactory repositoryFactory;
-
- /**
* The component used to validate the user-supplied artifact coordinates.
*/
@Component
@@ -202,6 +193,12 @@ public class SignAndDeployFileMojo
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
@@ -304,14 +301,8 @@ public class SignAndDeployFileMojo
throw new MojoFailureException( file.getPath() + " not found." );
}
- ArtifactRepositoryLayout layout = repositoryLayouts.get( repositoryLayout );
- if ( layout == null )
- {
- throw new MojoFailureException( "Invalid repository layout: " + repositoryLayout );
- }
-
- ArtifactRepository deploymentRepository =
- repositoryFactory.createDeploymentArtifactRepository( repositoryId, url, layout, uniqueVersion );
+
+ ArtifactRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
if ( StringUtils.isEmpty( deploymentRepository.getProtocol() ) )
{
@@ -325,6 +316,7 @@ public class SignAndDeployFileMojo
{
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 );
@@ -356,9 +348,9 @@ public class SignAndDeployFileMojo
try
{
- deploy( file, artifact, deploymentRepository, localRepository );
+ deploy( artifact, deploymentRepository );
}
- catch ( ArtifactDeploymentException e )
+ catch ( ArtifactDeployerException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
@@ -465,9 +457,9 @@ public class SignAndDeployFileMojo
attached = new AttachedSignedArtifact( attached, new AscArtifactMetadata( attached, fileSig, false ) );
try
{
- deploy( attached.getFile(), attached, deploymentRepository, localRepository );
+ deploy( attached, deploymentRepository );
}
- catch ( ArtifactDeploymentException e )
+ catch ( ArtifactDeployerException e )
{
throw new MojoExecutionException( "Error deploying attached artifact " + attached.getFile() + ": "
+ e.getMessage(), e );
@@ -592,12 +584,23 @@ public class SignAndDeployFileMojo
{
Model model = generateModel();
- ModelValidationResult result = modelValidator.validate( model );
+ ModelBuildingRequest request = new DefaultModelBuildingRequest()
+ .setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
+
+ List<String> result = new ArrayList<>();
+
+ SimpleModelProblemCollector problemCollector = new SimpleModelProblemCollector( result );
+
+ modelValidator.validateEffectiveModel( model, request, problemCollector );
- if ( result.getMessageCount() > 0 )
+ if ( !result.isEmpty() )
{
- throw new MojoFailureException( "The artifact information is incomplete or not valid:\n"
- + result.render( " " ) );
+ StringBuilder msg = new StringBuilder( "The artifact information is incomplete or not valid:\n" );
+ for ( String e : result )
+ {
+ msg.append( " - " + e + '\n' );
+ }
+ throw new MojoFailureException( msg.toString() );
}
}
@@ -631,12 +634,14 @@ public class SignAndDeployFileMojo
* @param localRepository the local repository to install into
* @throws ArtifactDeploymentException if an error occurred deploying the artifact
*/
- protected void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository,
- ArtifactRepository localRepository )
- throws ArtifactDeploymentException
+ protected void deploy( Artifact artifact,
+ ArtifactRepository deploymentRepository )
+ throws ArtifactDeployerException
{
+ final ProjectBuildingRequest buildingRequest = session.getProjectBuildingRequest();
+
int retryFailedDeploymentCount = Math.max( 1, Math.min( 10, this.retryFailedDeploymentCount ) );
- ArtifactDeploymentException exception = null;
+ ArtifactDeployerException exception = null;
for ( int count = 0; count < retryFailedDeploymentCount; count++ )
{
try
@@ -647,7 +652,8 @@ public class SignAndDeployFileMojo
getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of " + retryFailedDeploymentCount );
// CHECKSTYLE_ON: LineLength
}
- deployer.deploy( source, artifact, deploymentRepository, localRepository );
+ deployer.deploy( buildingRequest, deploymentRepository, Collections.singletonList( artifact ) );
+
for ( Object o : artifact.getMetadataList() )
{
ArtifactMetadata metadata = (ArtifactMetadata) o;
@@ -656,7 +662,7 @@ public class SignAndDeployFileMojo
exception = null;
break;
}
- catch ( ArtifactDeploymentException e )
+ catch ( ArtifactDeployerException e )
{
if ( count + 1 < retryFailedDeploymentCount )
{
@@ -674,4 +680,31 @@ public class SignAndDeployFileMojo
throw exception;
}
}
+
+ 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<String> result;
+
+ SimpleModelProblemCollector( List<String> result )
+ {
+ this.result = result;
+ }
+
+ public void add( Severity severity, String message, InputLocation location, Exception cause )
+ {
+ if ( !ModelProblem.Severity.WARNING.equals( severity ) )
+ {
+ result.add( message );
+ }
+ }
+
+ }
}