[MNG-5871] refactoring: improved empty urls handling
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
index fd1c07f..6cf4760 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
@@ -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.
@@ -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() );
@@ -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 ) == '/';
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
index 60f860f..e477fde 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
@@ -140,7 +140,7 @@ public void testFlatTrickyUrls()
public void testWithEmptyUrl()
throws Exception
{
- testInheritance( "empty", false );
+ testInheritance( "empty-urls", false );
}
public void testInheritance( String baseName )
diff --git a/maven-model-builder/src/test/resources/poms/inheritance/empty-child.xml b/maven-model-builder/src/test/resources/poms/inheritance/empty-urls-child.xml
similarity index 100%
rename from maven-model-builder/src/test/resources/poms/inheritance/empty-child.xml
rename to maven-model-builder/src/test/resources/poms/inheritance/empty-urls-child.xml
diff --git a/maven-model-builder/src/test/resources/poms/inheritance/empty-expected.xml b/maven-model-builder/src/test/resources/poms/inheritance/empty-urls-expected.xml
similarity index 85%
rename from maven-model-builder/src/test/resources/poms/inheritance/empty-expected.xml
rename to maven-model-builder/src/test/resources/poms/inheritance/empty-urls-expected.xml
index eac914a..317aec8 100644
--- a/maven-model-builder/src/test/resources/poms/inheritance/empty-expected.xml
+++ b/maven-model-builder/src/test/resources/poms/inheritance/empty-urls-expected.xml
@@ -27,13 +27,18 @@
<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>
\ No newline at end of file
diff --git a/maven-model-builder/src/test/resources/poms/inheritance/empty-parent.xml b/maven-model-builder/src/test/resources/poms/inheritance/empty-urls-parent.xml
similarity index 87%
rename from maven-model-builder/src/test/resources/poms/inheritance/empty-parent.xml
rename to maven-model-builder/src/test/resources/poms/inheritance/empty-urls-parent.xml
index 8e94403..ab2bea7 100644
--- a/maven-model-builder/src/test/resources/poms/inheritance/empty-parent.xml
+++ b/maven-model-builder/src/test/resources/poms/inheritance/empty-urls-parent.xml
@@ -30,8 +30,13 @@
</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>
\ No newline at end of file