mirror of https://github.com/apache/maven.git
PR: MNG-518
fix up validation git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@220318 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
64399eb8e3
commit
36d0a854e1
|
@ -438,10 +438,7 @@ public class DefaultMavenProjectBuilder
|
|||
project.setParentArtifact( parentArtifact );
|
||||
}
|
||||
|
||||
project.setRemoteArtifactRepositories( remoteRepositories );
|
||||
project.setDependencyArtifacts( createArtifacts( project.getDependencies() ) );
|
||||
project.setPluginArtifacts( createPluginArtifacts( project.getBuildPlugins() ) );
|
||||
|
||||
// Must validate before artifact construction to make sure dependencies are good
|
||||
ModelValidationResult validationResult = validator.validate( model );
|
||||
|
||||
if ( validationResult.getMessageCount() > 0 )
|
||||
|
@ -450,6 +447,10 @@ public class DefaultMavenProjectBuilder
|
|||
"\'.\n\n Reason(s):\n" + validationResult.render( " " ) );
|
||||
}
|
||||
|
||||
project.setRemoteArtifactRepositories( remoteRepositories );
|
||||
project.setDependencyArtifacts( createArtifacts( project.getDependencies() ) );
|
||||
project.setPluginArtifacts( createPluginArtifacts( project.getBuildPlugins() ) );
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,6 @@ public class MavenMetadataSource
|
|||
{
|
||||
Dependency d = (Dependency) i.next();
|
||||
|
||||
// TODO: validate
|
||||
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
||||
versionRange, d.getType(), d.getScope(),
|
||||
|
|
|
@ -18,8 +18,11 @@ package org.apache.maven.project.validation;
|
|||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.DependencyManagement;
|
||||
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 java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -61,6 +64,50 @@ public class DefaultModelValidator
|
|||
validateStringNotEmpty( "dependencies.dependency.version", result, d.getVersion() );
|
||||
}
|
||||
|
||||
DependencyManagement mgmt = model.getDependencyManagement();
|
||||
if ( mgmt != null )
|
||||
{
|
||||
for ( Iterator it = mgmt.getDependencies().iterator(); it.hasNext(); )
|
||||
{
|
||||
Dependency d = (Dependency) it.next();
|
||||
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.artifactId", result,
|
||||
d.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.groupId", result,
|
||||
d.getGroupId() );
|
||||
|
||||
validateStringNotEmpty( "dependencyManagement.dependencies.dependency.version", result,
|
||||
d.getVersion() );
|
||||
}
|
||||
}
|
||||
|
||||
Build build = model.getBuild();
|
||||
if ( build != null )
|
||||
{
|
||||
for ( Iterator it = build.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
Plugin p = (Plugin) it.next();
|
||||
|
||||
validateStringNotEmpty( "build.plugins.plugin.artifactId", result, p.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() );
|
||||
}
|
||||
}
|
||||
|
||||
Reporting reporting = model.getReporting();
|
||||
if ( reporting != null )
|
||||
{
|
||||
for ( Iterator it = reporting.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
ReportPlugin p = (ReportPlugin) it.next();
|
||||
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.artifactId", result, p.getArtifactId() );
|
||||
|
||||
validateStringNotEmpty( "reporting.plugins.plugin.groupId", result, p.getGroupId() );
|
||||
}
|
||||
}
|
||||
|
||||
forcePluginExecutionIdCollision( model, result );
|
||||
|
||||
return result;
|
||||
|
|
|
@ -85,6 +85,66 @@ public class DefaultModelValidatorTest
|
|||
assertEquals( "'version' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyArtifactId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-artifactId-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencies.dependency.artifactId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyGroupId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-groupId-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencies.dependency.groupId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyVersion()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-version-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencies.dependency.version' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyManagementArtifactId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-mgmt-artifactId-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencyManagement.dependencies.dependency.artifactId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyManagementGroupId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-mgmt-groupId-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencyManagement.dependencies.dependency.groupId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingDependencyManagementVersion()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-dependency-mgmt-version-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'dependencyManagement.dependencies.dependency.version' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
public void testMissingAll()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -101,6 +161,16 @@ public class DefaultModelValidatorTest
|
|||
// type is inherited from the super pom
|
||||
}
|
||||
|
||||
public void testMissingPluginArtifactId()
|
||||
throws Exception
|
||||
{
|
||||
ModelValidationResult result = validate( "missing-plugin-artifactId-pom.xml" );
|
||||
|
||||
assertEquals( 1, result.getMessageCount() );
|
||||
|
||||
assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getMessage( 0 ) );
|
||||
}
|
||||
|
||||
private ModelValidationResult validate( String testName )
|
||||
throws Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>groupId</groupId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>artifactId</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>groupId</groupId>
|
||||
<version>version</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>artifactId</artifactId>
|
||||
<version>version</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>artifactId</artifactId>
|
||||
<groupId>groupId</groupId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>artifactId</artifactId>
|
||||
<groupId>groupId</groupId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>foo</artifactId>
|
||||
<groupId>foo</groupId>
|
||||
<version>99.44</version>
|
||||
<packaging>bleh</packaging>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
Loading…
Reference in New Issue