maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject [maven-deploy-plugin] 01/01: [MDEPLOY-244] - maven deploy plugin 3.0.0-M1 breaks RPM deploys
Date Sun, 17 Mar 2019 10:58:17 GMT
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch MDEPLOY-244
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git

commit 7ecefab6938bc9610ca25ee03a1c2b4fc1ec2801
Author: Karl Heinz Marbaise <khmarbaise@apache.org>
AuthorDate: Sat Oct 13 13:05:55 2018 +0200

    [MDEPLOY-244] - maven deploy plugin 3.0.0-M1 breaks RPM deploys
---
 .../apache/maven/plugins/deploy/DeployMojo.java    | 59 +++++++++++++++++-----
 src/site/apt/index.apt.vm                          |  2 +-
 .../maven/plugins/deploy/DeployMojoTest.java       | 29 +++++++++++
 3 files changed, 75 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index 5953d6e..51f79f4 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -55,6 +55,8 @@ public class DeployMojo
 
     private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)"
);
 
+    private static final Pattern OLD_ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)"
);
+
     /**
      * When building with multiple threads, reaching the last project doesn't have to mean
that all projects are ready
      * to be deployed
@@ -85,7 +87,6 @@ public class DeployMojo
     /**
      * Specifies an alternative repository to which the project artifacts should be deployed
( other than those
      * specified in &lt;distributionManagement&gt; ). <br/>
-     * Format: <code>id::url</code>
      * <dl>
      * <dt>id</dt>
      * <dd>The id can be used to pick up the correct credentials from the settings.xml</dd>
@@ -140,6 +141,8 @@ public class DeployMojo
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
+        checkParameterForOldRepositorySyntax();
+
         boolean addedDeployRequest = false;
         if ( skip )
         {
@@ -194,7 +197,7 @@ public class DeployMojo
     }
 
     private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository
repo )
-        throws MojoFailureException, MojoExecutionException
+        throws MojoExecutionException
     {
         try
         {
@@ -211,16 +214,13 @@ public class DeployMojo
 
     }
 
-    ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
-
-        throws MojoExecutionException, MojoFailureException
+    private String getAlternateDeploymentRepository(ProjectDeployerRequest pdr)
     {
-        MavenProject project = pdr.getProject();
         String altDeploymentRepository = pdr.getAltDeploymentRepository();
         String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
         String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
 
-        ArtifactRepository repo = null;
+        MavenProject project = pdr.getProject();
 
         String altDeploymentRepo;
         if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository
!= null )
@@ -235,25 +235,33 @@ public class DeployMojo
         {
             altDeploymentRepo = altDeploymentRepository;
         }
+        return altDeploymentRepo;
+    }
 
+    private ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
+
+        throws MojoExecutionException, MojoFailureException
+    {
+        MavenProject project = pdr.getProject();
+
+        String altDeploymentRepo = getAlternateDeploymentRepository(pdr);
+
+        ArtifactRepository repo = null;
         if ( altDeploymentRepo != null )
         {
             getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
 
             Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
-
             if ( !matcher.matches() )
             {
                 throw new MojoFailureException( altDeploymentRepo, "Invalid syntax for repository.",
                                                 "Invalid syntax for alternative repository.
Use \"id::url\"." );
             }
-            else
-            {
-                String id = matcher.group( 1 ).trim();
-                String url = matcher.group( 2 ).trim();
 
-                repo = createDeploymentArtifactRepository( id, url );
-            }
+            String id = matcher.group( 1 ).trim();
+            String url = matcher.group( 2 ).trim();
+
+            repo = createDeploymentArtifactRepository( id, url );
         }
 
         if ( repo == null )
@@ -272,4 +280,27 @@ public class DeployMojo
         return repo;
     }
 
+    private void checkParameterForOldRepositorySyntax() throws MojoFailureException {
+        checkForOldRepositorySyntax(altReleaseDeploymentRepository);
+        checkForOldRepositorySyntax(altDeploymentRepository);
+        checkForOldRepositorySyntax(altSnapshotDeploymentRepository);
+    }
+
+    private void checkForOldRepositorySyntax(String repository) throws MojoFailureException
{
+        if (repository != null)
+        {
+            if ( matchesOldSyntax( repository ) )
+            {
+                throw new MojoFailureException( repository,
+                        "The syntax for the alternative repository has been changed.",
+                        "Please use \"id::url\" instead of \"id::layout::url\"." );
+            }
+        }
+    }
+
+    private boolean matchesOldSyntax( String repo )
+    {
+        return OLD_ALT_REPO_SYNTAX_PATTERN.matcher( repo ).matches();
+    }
+
 }
diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm
index a23f6a0..2616c71 100644
--- a/src/site/apt/index.apt.vm
+++ b/src/site/apt/index.apt.vm
@@ -92,7 +92,7 @@ ${project.name}
 
   []
 
-  As of Maven 3, snapshot artifacts will always be deployed using a timestamped version.
+  As of Maven 3, snapshot artifacts will always be deployed using a time stamped version.
 
 * Usage
 
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 6c6f938..50dc2dc 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -32,6 +32,7 @@ import java.util.Properties;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.plugins.deploy.stubs.ArtifactDeployerStub;
@@ -43,6 +44,7 @@ import org.apache.maven.repository.internal.MavenRepositorySystemSession;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
 import org.codehaus.plexus.util.FileUtils;
 import org.junit.Ignore;
+import org.junit.Test;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -589,7 +591,34 @@ public class DeployMojoTest
         assertEquals( repository,
                       mojo.getDeploymentRepository( pdr ));
     }
+
+
     
+    public void testWrongOldRepositoryformatForDeploymentRepository()
+        throws MojoExecutionException, MojoFailureException
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository",
+                                                       "http://localhost" ) ).thenReturn(
repository );
+
+        project.setVersion( "1.0" );
+
+        ProjectDeployerRequest pdr =
+            new ProjectDeployerRequest().setProject( project ).setAltDeploymentRepository(
"altDeploymentRepository::layout::http://localhost" );
+
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "We have expected an MojoFailureException" );
+        }
+        catch ( MojoFailureException e )
+        {
+            // Intentionally empty.
+        }
+    }
+
     private void addFileToList( File file, List<String> fileList )
     {
         if( !file.isDirectory() )


Mime
View raw message