[MDEPLOY-279] Missing validation of altDeploymentRepository mojo parameter

This closes #12
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 5bc471d..ab0c72b 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -51,8 +51,9 @@
 public class DeployMojo
     extends AbstractDeployMojo
 {
+    private static final Pattern ALT_LEGACY_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+?)::(.+?)::(.+)" );
 
-    private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)" );
+    private static final Pattern 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
@@ -248,19 +249,48 @@
         {
             getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
 
-            Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
+            Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
 
-            if ( !matcher.matches() )
+            if ( matcher.matches() )
             {
-                throw new MojoFailureException( altDeploymentRepo, "Invalid syntax for repository.",
-                                                "Invalid syntax for alternative repository. Use \"id::url\"." );
+                String id = matcher.group( 1 ).trim();
+                String layout = matcher.group( 2 ).trim();
+                String url = matcher.group( 3 ).trim();
+
+                if ( "default".equals( layout ) )
+                {
+                    throw new MojoFailureException( altDeploymentRepo,
+                            "Invalid legacy syntax for repository.",
+                            "Invalid legacy syntax for alternative repository. Use \"" + id + "::" + url + "\" instead."
+                    );
+                }
+                else
+                {
+                    throw new MojoFailureException( altDeploymentRepo,
+                            "Invalid legacy syntax and layout for repository.",
+                            "Invalid legacy syntax and layout for alternative repository. Use \""
+                                    + id + "::" + url + "\" instead, and only default layout is supported."
+                    );
+                }
             }
             else
             {
-                String id = matcher.group( 1 ).trim();
-                String url = matcher.group( 2 ).trim();
+                matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
 
-                repo = createDeploymentArtifactRepository( id, url );
+                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 );
+                }
             }
         }
 
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 ee762ef..9a02b1c 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 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;
@@ -551,7 +552,141 @@
         
         FileUtils.deleteDirectory( sshFile );
     }
-    
+
+    public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
+        throws Exception
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
+        ) ).thenReturn( repository );
+
+        project.setVersion( "1.0-SNAPSHOT" );
+
+        ProjectDeployerRequest pdr =
+            new ProjectDeployerRequest()
+                .setProject( project )
+                .setAltDeploymentRepository( "altDeploymentRepository::default::http://localhost" );
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "Should throw: Invalid legacy syntax for repository." );
+        }
+        catch( MojoFailureException e )
+        {
+            assertEquals( e.getMessage(), "Invalid legacy syntax for repository.");
+            assertEquals( e.getLongMessage(), "Invalid legacy syntax for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead.");
+        }
+    }
+
+    public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
+        throws Exception
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
+        ) ).thenReturn( repository );
+
+        project.setVersion( "1.0-SNAPSHOT" );
+
+        ProjectDeployerRequest pdr =
+            new ProjectDeployerRequest()
+                .setProject( project )
+                .setAltDeploymentRepository( "altDeploymentRepository::legacy::http://localhost" );
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "Should throw: Invalid legacy syntax and layout for repository." );
+        }
+        catch( MojoFailureException e )
+        {
+            assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+            assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
+        }
+    }
+
+    public void testInsaneAltDeploymentRepository()
+            throws Exception
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
+        ) ).thenReturn( repository );
+
+        project.setVersion( "1.0-SNAPSHOT" );
+
+        ProjectDeployerRequest pdr =
+                new ProjectDeployerRequest()
+                        .setProject( project )
+                        .setAltDeploymentRepository( "altDeploymentRepository::hey::wow::foo::http://localhost" );
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "Should throw: Invalid legacy syntax and layout for repository." );
+        }
+        catch( MojoFailureException e )
+        {
+            assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+            assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
+        }
+    }
+
+    public void testDefaultScmSvnAltDeploymentRepository()
+            throws Exception
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
+        ) ).thenReturn( repository );
+
+        project.setVersion( "1.0-SNAPSHOT" );
+
+        ProjectDeployerRequest pdr =
+                new ProjectDeployerRequest()
+                        .setProject( project )
+                        .setAltDeploymentRepository( "altDeploymentRepository::default::scm:svn:http://localhost" );
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "Should throw: Invalid legacy syntax for repository." );
+        }
+        catch( MojoFailureException e )
+        {
+            assertEquals( e.getMessage(), "Invalid legacy syntax for repository.");
+            assertEquals( e.getLongMessage(), "Invalid legacy syntax for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead.");
+        }
+    }
+    public void testLegacyScmSvnAltDeploymentRepository()
+            throws Exception
+    {
+        DeployMojo mojo = spy( new DeployMojo() );
+
+        ArtifactRepository repository = mock( ArtifactRepository.class );
+        when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
+        ) ).thenReturn( repository );
+
+        project.setVersion( "1.0-SNAPSHOT" );
+
+        ProjectDeployerRequest pdr =
+                new ProjectDeployerRequest()
+                        .setProject( project )
+                        .setAltDeploymentRepository( "altDeploymentRepository::legacy::scm:svn:http://localhost" );
+        try
+        {
+            mojo.getDeploymentRepository( pdr );
+            fail( "Should throw: Invalid legacy syntax and layout for repository." );
+        }
+        catch( MojoFailureException e )
+        {
+            assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+            assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
+        }
+    }
+
     public void testAltSnapshotDeploymentRepository()
         throws Exception
     {