[MTOMCAT-196] Add the possiblilty to search warRunDepencies and extraDependcies throug the dependencyManagement
git-svn-id: https://svn.apache.org/repos/asf/tomcat/maven-plugin/trunk@1539226 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java b/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
index 8ef29dc..900773b 100644
--- a/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
+++ b/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
@@ -389,11 +389,23 @@
{
for ( Dependency dependency : extraDependencies )
{
+ String version = dependency.getVersion();
+ if ( StringUtils.isEmpty( version ) )
+ {
+ version = findArtifactVersion( dependency );
+ }
+
+ if ( StringUtils.isEmpty( version ) )
+ {
+ throw new MojoExecutionException(
+ "Dependency '" + dependency.getGroupId() + "':'" + dependency.getArtifactId()
+ + "' does not have version specified" );
+ }
+
// String groupId, String artifactId, String version, String scope, String type
Artifact artifact =
- artifactFactory.createArtifact( dependency.getGroupId(), dependency.getArtifactId(),
- dependency.getVersion(), dependency.getScope(),
- dependency.getType() );
+ artifactFactory.createArtifact( dependency.getGroupId(), dependency.getArtifactId(), version,
+ dependency.getScope(), dependency.getType() );
artifactResolver.resolve( artifact, this.remoteRepos, this.local );
JarFile jarFile = new JarFile( artifact.getFile() );
@@ -482,6 +494,35 @@
}
}
+ protected String findArtifactVersion( Dependency dependency )
+ {
+ // search in project.dependencies
+ for ( Dependency projectDependency : (List<Dependency>) this.project.getDependencies() )
+ {
+ if ( sameDependencyWithoutVersion( dependency, projectDependency ) )
+ {
+ return projectDependency.getVersion();
+ }
+ }
+
+ // search in project.dependencies
+ for ( Dependency projectDependency : (List<Dependency>) this.project.getDependencyManagement().getDependencies() )
+ {
+ if ( sameDependencyWithoutVersion( dependency, projectDependency ) )
+ {
+ return projectDependency.getVersion();
+ }
+ }
+
+ return null;
+ }
+
+ protected boolean sameDependencyWithoutVersion( Dependency that, Dependency dependency )
+ {
+ return StringUtils.equals( that.getGroupId(), dependency.getGroupId() ) && StringUtils.equals(
+ that.getArtifactId(), dependency.getArtifactId() );
+ }
+
protected void copyDirectoryContentIntoArchive( File sourceFolder, String destinationPath,
ArchiveOutputStream archiveOutputStream )
throws IOException