Skip to content

Commit

Permalink
[MDEPLOY-265] Allow old alt*DeploymentRepository property format if d…
Browse files Browse the repository at this point in the history
…efault layout is used

The legacy format (<=2.x) of alt*DeploymentRepository is id::layout::url.
The new format (>= 3.x) of alt*DeploymentRepository is id::url which is
equivalent to id::default:url from the legacy format.

This change introduces backwards compatibility with 2.x by supporting
alt*DeploymentRepository values in the id::layout::url format if and only if
the layout is equal to "default".  The "default" layout is the most commonly
used layout, so this should maintain backwards compatibility with the large
majority of projects using the alt*DeploymentRepository properties.

* Usage of the legacy format with the "default" layout will result in a warning
  message being logged.
* Usage of the legacy format with layouts other than "default" will result in
  an exception being thrown.

This closes #15
  • Loading branch information
philsttr authored and michael-o committed Dec 24, 2020
1 parent 92d7e74 commit 02a055b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym

if ( "default".equals( layout ) )
{
throw new MojoFailureException( altDeploymentRepo,
"Invalid legacy syntax for repository.",
"Invalid legacy syntax for alternative repository. Use \"" + id + "::" + url + "\" instead."
);
getLog().warn( "Using legacy syntax for alternative repository. "
+ "Use \"" + id + "::" + url + "\" instead." );
repo = createDeploymentArtifactRepository( id, url );
}
else
{
Expand Down
29 changes: 8 additions & 21 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,10 @@ public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
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.");
}

assertEquals( repository,
mojo.getDeploymentRepository( pdr ) );

}

public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
Expand Down Expand Up @@ -640,7 +634,7 @@ public void testDefaultScmSvnAltDeploymentRepository()
DeployMojo mojo = spy( new DeployMojo() );

ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "scm:svn:http://localhost"
) ).thenReturn( repository );

project.setVersion( "1.0-SNAPSHOT" );
Expand All @@ -649,16 +643,9 @@ public void testDefaultScmSvnAltDeploymentRepository()
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.");
}

assertEquals( repository,
mojo.getDeploymentRepository( pdr ) );
}
public void testLegacyScmSvnAltDeploymentRepository()
throws Exception
Expand Down

0 comments on commit 02a055b

Please sign in to comment.