Author: bentmann
Date: Mon Dec 27 17:19:32 2010
New Revision: 1053111
URL: http://svn.apache.org/viewvc?rev=1053111&view=rev
Log:
[MNG-4953] Issue a warning when a system-scope dependency refers to the project
basedir
Added:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
(with props)
Modified:
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/hard-coded-system-path.xml
Modified:
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=1053111&r1=1053110&r2=1053111&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
(original)
+++
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
Mon Dec 27 17:19:32 2010
@@ -345,7 +345,7 @@ public class DefaultModelValidator
}
private void validateRawDependencies( ModelProblemCollector problems,
List<Dependency> dependencies, String prefix,
- ModelBuildingRequest request )
+ ModelBuildingRequest request )
{
Severity errOn30 = getSeverity( request,
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
Severity errOn31 = getSeverity( request,
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
@@ -372,10 +372,19 @@ public class DefaultModelValidator
else if ( "system".equals( dependency.getScope() ) )
{
String sysPath = dependency.getSystemPath();
- if ( StringUtils.isNotEmpty( sysPath ) && !hasExpression(
sysPath ) )
+ if ( StringUtils.isNotEmpty( sysPath ) )
{
- addViolation( problems, Severity.WARNING, prefix +
".systemPath", key,
- "should use a variable instead of a
hard-coded path " + sysPath, dependency );
+ if ( !hasExpression( sysPath ) )
+ {
+ addViolation( problems, Severity.WARNING, prefix +
".systemPath", key,
+ "should use a variable instead of a
hard-coded path " + sysPath, dependency );
+ }
+ else if ( sysPath.contains( "${basedir}" ) ||
sysPath.contains( "${project.basedir}" ) )
+ {
+ addViolation( problems, Severity.WARNING, prefix +
".systemPath", key,
+ "should not point at files within the
project directory, " + sysPath
+ + " will be unresolvable by
dependent projects", dependency );
+ }
}
}
@@ -640,7 +649,7 @@ public class DefaultModelValidator
private boolean hasExpression( String value )
{
- return value != null && value.indexOf( "${" ) >= 0;
+ return value != null && value.contains( "${" );
}
private boolean validateStringNotEmpty( String fieldName,
ModelProblemCollector problems, Severity severity,
Modified:
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=1053111&r1=1053110&r2=1053111&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
(original)
+++
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
Mon Dec 27 17:19:32 2010
@@ -109,9 +109,9 @@ public class DefaultModelValidatorTest
private void assertViolations( SimpleProblemCollector result, int fatals,
int errors, int warnings )
{
- assertEquals( fatals, result.getFatals().size() );
- assertEquals( errors, result.getErrors().size() );
- assertEquals( warnings, result.getWarnings().size() );
+ assertEquals( String.valueOf( result.getFatals() ), fatals,
result.getFatals().size() );
+ assertEquals( String.valueOf( result.getErrors() ), errors,
result.getErrors().size() );
+ assertEquals( String.valueOf( result.getWarnings() ), warnings,
result.getWarnings().size() );
}
public void testMissingModelVersion()
@@ -591,4 +591,17 @@ public class DefaultModelValidatorTest
"'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls
must be empty" );
}
+ public void testSystemPathRefersToProjectBasedir()
+ throws Exception
+ {
+ SimpleProblemCollector result = validateRaw( "basedir-system-path.xml"
);
+
+ assertViolations( result, 0, 0, 2 );
+
+ assertContains( result.getWarnings().get( 0 ),
"'dependencies.dependency.systemPath' for test:a:jar "
+ + "should not point at files within the project directory" );
+ assertContains( result.getWarnings().get( 1 ),
"'dependencies.dependency.systemPath' for test:b:jar "
+ + "should not point at files within the project directory" );
+ }
+
}
Added:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml?rev=1053111&view=auto
==============================================================================
---
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
(added)
+++
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
Mon Dec 27 17:19:32 2010
@@ -0,0 +1,42 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>aid</artifactId>
+ <groupId>gid</groupId>
+ <version>0.1</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>test</groupId>
+ <artifactId>a</artifactId>
+ <version>0.2</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/a.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>test</groupId>
+ <artifactId>b</artifactId>
+ <version>0.1</version>
+ <scope>system</scope>
+ <systemPath>${project.basedir}/lib/b.jar</systemPath>
+ </dependency>
+ </dependencies>
+</project>
Propchange:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/basedir-system-path.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/hard-coded-system-path.xml
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/hard-coded-system-path.xml?rev=1053111&r1=1053110&r2=1053111&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/hard-coded-system-path.xml
(original)
+++
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/hard-coded-system-path.xml
Mon Dec 27 17:19:32 2010
@@ -36,7 +36,7 @@ under the License.
<artifactId>b</artifactId>
<version>0.1</version>
<scope>system</scope>
- <systemPath>${basedir}/lib/good.jar</systemPath>
+ <systemPath>${java.home}/lib/good.jar</systemPath>
</dependency>
</dependencies>
</project>