From c54202821e8edfcb7213a4f45fd20a318d4b8016 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 7 Dec 2005 00:42:46 +0000 Subject: [PATCH] PR: MNG-1471 Submitted By: Edwin Punzalan Reviewed By: John Casey Applied patch, with small logic fix. This patch will validate that if a systemPath is specified for a dependency, it is absolute. It's possible to use expressions in this path, but by the time it's validated in this step, those expressions will have been resolved. My change was to add the same validation to managed dependencies. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@354635 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index df1e04ec4d..c1fc59b5de 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -29,6 +29,7 @@ import org.apache.maven.model.Repository; import org.apache.maven.model.Resource; import org.codehaus.plexus.util.StringUtils; +import java.io.File; import java.util.Iterator; import java.util.List; @@ -86,11 +87,24 @@ public class DefaultModelValidator validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion(), dependencySourceHint( d ) ); - if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isEmpty( d.getSystemPath() ) ) + if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) { - result.addMessage( "For dependency " + d + ": system-scoped dependency must specify systemPath." ); + String systemPath = d.getSystemPath(); + + if ( StringUtils.isEmpty( systemPath ) ) + { + result.addMessage( "For dependency " + d + ": system-scoped dependency must specify systemPath." ); + } + else + { + if ( ! new File( systemPath ).isAbsolute() ) + { + result.addMessage( "For dependency " + d + ": system-scoped dependency must " + + "specify an absolute path systemPath." ); + } + } } - else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) ) + else if ( StringUtils.isNotEmpty( d.getSystemPath() ) ) { result.addMessage( "For dependency " + d + ": only dependency with system scope can specify systemPath." ); @@ -110,12 +124,24 @@ public class DefaultModelValidator validateSubElementStringNotEmpty( d, "dependencyManagement.dependencies.dependency.groupId", result, d.getGroupId() ); - if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isEmpty( d.getSystemPath() ) ) + if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) { - result.addMessage( - "For managed dependency " + d + ": system-scoped dependency must specify systemPath." ); + String systemPath = d.getSystemPath(); + + if ( StringUtils.isEmpty( systemPath ) ) + { + result.addMessage( "For managed dependency " + d + ": system-scoped dependency must specify systemPath." ); + } + else + { + if ( ! new File( systemPath ).isAbsolute() ) + { + result.addMessage( "For managed dependency " + d + ": system-scoped dependency must " + + "specify an absolute path systemPath." ); + } + } } - else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) ) + else if ( StringUtils.isNotEmpty( d.getSystemPath() ) ) { result.addMessage( "For managed dependency " + d + ": only dependency with system scope can specify systemPath." );