mirror of https://github.com/apache/maven.git
validate repositories in the POM
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
245d512c4a
commit
3ad9ca72c5
|
@ -24,6 +24,7 @@ import org.apache.maven.model.Model;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.Repository;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
@ -71,7 +72,8 @@ public class DefaultModelValidator
|
|||
}
|
||||
else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
{
|
||||
result.addMessage( "For dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||
result.addMessage(
|
||||
"For dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,11 +92,13 @@ public class DefaultModelValidator
|
|||
|
||||
if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isEmpty( d.getSystemPath() ) )
|
||||
{
|
||||
result.addMessage( "For managed dependency " + d + ": system-scoped dependency must specify systemPath." );
|
||||
result.addMessage(
|
||||
"For managed dependency " + d + ": system-scoped dependency must specify systemPath." );
|
||||
}
|
||||
else if ( !Artifact.SCOPE_SYSTEM.equals( d.getScope() ) && StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
{
|
||||
result.addMessage( "For managed dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||
result.addMessage(
|
||||
"For managed dependency " + d + ": only dependency with system scope can specify systemPath." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,11 +129,27 @@ public class DefaultModelValidator
|
|||
}
|
||||
}
|
||||
|
||||
validateRepositories( result, model.getRepositories(), "repositories.repository" );
|
||||
|
||||
validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" );
|
||||
|
||||
forcePluginExecutionIdCollision( model, result );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void validateRepositories( ModelValidationResult result, List repositories, String prefix )
|
||||
{
|
||||
for ( Iterator it = repositories.iterator(); it.hasNext(); )
|
||||
{
|
||||
Repository repository = (Repository) it.next();
|
||||
|
||||
validateStringNotEmpty( prefix + ".id", result, repository.getId() );
|
||||
|
||||
validateStringNotEmpty( prefix + ".url", result, repository.getUrl() );
|
||||
}
|
||||
}
|
||||
|
||||
private void forcePluginExecutionIdCollision( Model model, ModelValidationResult result )
|
||||
{
|
||||
Build build = model.getBuild();
|
||||
|
@ -194,7 +214,8 @@ public class DefaultModelValidator
|
|||
* <li><code>string.length > 0</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateSubElementStringNotEmpty( Object subElementInstance, String fieldName, ModelValidationResult result, String string )
|
||||
private boolean validateSubElementStringNotEmpty( Object subElementInstance, String fieldName,
|
||||
ModelValidationResult result, String string )
|
||||
{
|
||||
if ( !validateSubElementNotNull( subElementInstance, fieldName, result, string ) )
|
||||
{
|
||||
|
@ -237,7 +258,8 @@ public class DefaultModelValidator
|
|||
* <li><code>string != null</code>
|
||||
* </ul>
|
||||
*/
|
||||
private boolean validateSubElementNotNull( Object subElementInstance, String fieldName, ModelValidationResult result, Object object )
|
||||
private boolean validateSubElementNotNull( Object subElementInstance, String fieldName,
|
||||
ModelValidationResult result, Object object )
|
||||
{
|
||||
if ( object != null )
|
||||
{
|
||||
|
|
|
@ -122,7 +122,8 @@ public class DefaultModelValidatorTest
|
|||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertTrue( result.getMessage( 0 ).indexOf( "'dependencyManagement.dependencies.dependency.artifactId' is missing." ) > -1 );
|
||||
assertTrue( result.getMessage( 0 ).indexOf(
|
||||
"'dependencyManagement.dependencies.dependency.artifactId' is missing." ) > -1 );
|
||||
}
|
||||
|
||||
public void testMissingDependencyManagementGroupId()
|
||||
|
@ -132,7 +133,8 @@ public class DefaultModelValidatorTest
|
|||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertTrue( result.getMessage( 0 ).indexOf( "'dependencyManagement.dependencies.dependency.groupId' is missing." ) > -1 );
|
||||
assertTrue( result.getMessage( 0 ).indexOf(
|
||||
"'dependencyManagement.dependencies.dependency.groupId' is missing." ) > -1 );
|
||||
}
|
||||
|
||||
public void testMissingAll()
|
||||
|
@ -161,6 +163,22 @@ public class DefaultModelValidatorTest
|
|||
assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingRepositoryId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-repository-id-pom.xml" );
|
||||
|
||||
assertEquals( 4, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'repositories.repository.id' is missing.", result.getMessage( 0 ) );
|
||||
|
||||
assertEquals( "'repositories.repository.url' is missing.", result.getMessage( 1 ) );
|
||||
|
||||
assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getMessage( 2 ) );
|
||||
|
||||
assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) );
|
||||
}
|
||||
|
||||
private ModelValidationResult validate( String testName )
|
||||
throws Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
Loading…
Reference in New Issue