Skip to content

Commit

Permalink
[MNG-5871] refactoring: improved empty urls handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Oct 31, 2015
1 parent 406a46f commit 2f7daef
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.merge.MavenModelMerger;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;

/**
* Handles inheritance of model values.
Expand Down Expand Up @@ -136,7 +137,7 @@ protected String extrapolateChildUrl( String parentUrl, Map<Object, Object> cont
Object artifactId = context.get( ARTIFACT_ID );
Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT );

if ( artifactId != null && childPathAdjustment != null )
if ( artifactId != null && childPathAdjustment != null && StringUtils.isNotBlank( parentUrl ) )
{
// append childPathAdjustment and artifactId to parent url
return appendPath( parentUrl, artifactId.toString(), childPathAdjustment.toString() );
Expand All @@ -161,7 +162,7 @@ private String appendPath( String parentUrl, String childPath, String pathAdjust

private void concatPath( StringBuilder url, String path )
{
if ( url.length() > 0 && path.length() > 0 )
if ( path.length() > 0 )
{
boolean initialUrlEndsWithSlash = url.charAt( url.length() - 1 ) == '/';
boolean pathStartsWithSlash = path.charAt( 0 ) == '/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void testFlatTrickyUrls()
public void testWithEmptyUrl()
throws Exception
{
testInheritance( "empty", false );
testInheritance( "empty-urls", false );
}

public void testInheritance( String baseName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ under the License.
<artifactId>empty</artifactId>
<version>1</version>
</parent>
<groupId>inheritance</groupId>
<groupId>inheritance</groupId>
<artifactId>child</artifactId>
<version>1</version>
<url></url>
<scm>
<connection>scm:my-scm:http://domain.org/base/child</connection>
<developerConnection>scm:my-scm:https://domain.org/base/child/</developerConnection>
<connection></connection>
<developerConnection></developerConnection>
<url></url>
</scm>
</scm>
<distributionManagement>
<site>
<url></url>
</site>
</distributionManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ under the License.
</modules>
<url></url>
<scm>
<connection>scm:my-scm:http://domain.org/base</connection>
<developerConnection>scm:my-scm:https://domain.org/base/</developerConnection>
<connection> </connection>
<developerConnection> </developerConnection>
<url></url>
</scm>
<distributionManagement>
<site>
<url></url>
</site>
</distributionManagement>
</project>

0 comments on commit 2f7daef

Please sign in to comment.