Author: brianf
Date: Sat Mar 17 19:37:34 2007
New Revision: 519524
URL: http://svn.apache.org/viewvc?view=rev&rev=519524
Log:
split the analyze goals, update site
Added:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
Modified:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/pom.xml
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/index.apt
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/usage.apt
Modified: maven/plugins/branches/maven-dependency-plugin-w-analyzer/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-w-analyzer/pom.xml?view=diff&rev=519524&r1=519523&r2=519524
==============================================================================
--- maven/plugins/branches/maven-dependency-plugin-w-analyzer/pom.xml (original)
+++ maven/plugins/branches/maven-dependency-plugin-w-analyzer/pom.xml Sat Mar
17 19:37:34 2007
@@ -168,7 +168,7 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-analyzer</artifactId>
- <version>1.0-alpha-1-SNAPSHOT</version>
+ <version>1.0-alpha-1</version>
</dependency>
</dependencies>
<!--reporting>
Added:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java?view=auto&rev=519524
==============================================================================
---
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
(added)
+++
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java
Sat Mar 17 19:37:34 2007
@@ -0,0 +1,243 @@
+package org.apache.maven.plugin.dependency;
+
+/*
+ * 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.
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.execution.RuntimeInformation;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * This mojo looks at the dependencies after final resolution and looks for
mismatches in your dependencyManagement section.
+ * In versions of maven prior to 2.0.6, it was possible to inherit versions
that didn't match your dependencyManagement. See <a
href="http://jira.codehaus.org/browse/MNG-1577">MNG-1577</a> for more info.
+ * Note: Because Maven 2.0.6 fixes the problems this mojo is meant to detect,
it will do nothing in versions of Maven greater than 2.0.5.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brian Fox</a>
+ * @version $Id: AnalyzeMojo.java 519377 2007-03-17 17:37:26Z brianf $
+ * @goal analyze-dep-mgt
+ * @requiresDependencyResolution test
+ * @since 2.0-alpha-3
+ */
+public class AnalyzeDepMgt
+ extends AbstractMojo
+{
+ // fields -----------------------------------------------------------------
+
+ /**
+ *
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * Fail the build if a problem is detected.
+ *
+ * @parameter expression="${mdep.analyze.failBuild}"
+ */
+ private boolean failBuild = false;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter
expression="${component.org.apache.maven.execution.RuntimeInformation}"
+ * @required
+ * @readonly
+ */
+ protected RuntimeInformation rti;
+
+ // Mojo methods -----------------------------------------------------------
+
+ /*
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ ArtifactVersion version = rti.getApplicationVersion();
+ ArtifactVersion checkVersion = new DefaultArtifactVersion( "2.0.6" );
+ if ( version.compareTo( checkVersion ) < 0 )
+ {
+ boolean result = checkDependencyManagement();
+ if ( result )
+ {
+ if ( this.failBuild )
+
+ {
+ throw new MojoExecutionException( "Found Dependency
errors." );
+ }
+ else
+ {
+ getLog().warn( "Potential problems found in Dependency
Management " );
+ }
+ }
+ }
+ }
+
+ // private methods --------------------------------------------------------
+
+ private boolean checkDependencyManagement()
+ throws MojoExecutionException
+ {
+ boolean foundMismatch = false;
+
+ getLog().info( "Found Resolved Dependency / DependencyManagement
mismatches:" );
+
+ List depMgtDependencies = null;
+ DependencyManagement depMgt = project.getDependencyManagement();
+ if ( depMgt != null )
+ {
+ depMgtDependencies = depMgt.getDependencies();
+ }
+
+ if ( depMgtDependencies != null && !depMgtDependencies.isEmpty() )
+ {
+ // put all the dependencies from depMgt into a map for quick lookup
+ Map map = new HashMap();
+ Iterator iter = depMgtDependencies.iterator();
+ while ( iter.hasNext() )
+ {
+ Dependency dependency = (Dependency) iter.next();
+ map.put( dependency.getManagementKey(), dependency );
+ }
+
+ Set allDependencies = project.getArtifacts();
+ iter = allDependencies.iterator();
+ while ( iter.hasNext() )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ // getLog().info( "a:"+getArtifactManagementKey( artifact ) );
+ // see if this artifact matches anything in the dependencyMgt
+ // list
+ Dependency dep = (Dependency) map.get(
getArtifactManagementKey( artifact ) );
+ if ( dep != null )
+ {
+ // getLog().info( "Compare:" + dep.getManagementKey()+"
+ // v:"+dep.getVersion()+"a:"+artifact.getVersion());
+ // ArtifactVersion depVersion = new
+ // DefaultArtifactVersion(dep.getVersion());
+ ArtifactVersion artifactVersion = new
DefaultArtifactVersion( artifact.getVersion() );
+
+ if ( !artifact.isSnapshot() && !dep.getVersion().equals(
artifact.getVersion() ) )
+
+ {
+ logMismatch( artifact, dep );
+ foundMismatch = true;
+ }
+ }
+ }
+ }
+ else
+ {
+ getLog().info( " Nothing in DepMgt." );
+ }
+
+ if ( !foundMismatch )
+ {
+ getLog().info( " None" );
+ }
+
+ return foundMismatch;
+ }
+
+ private void logMismatch( Artifact artifact, Dependency dependency )
+ throws MojoExecutionException
+ {
+ if ( artifact == null || dependency == null )
+ {
+ throw new MojoExecutionException( "Invalid params: Artifact:" +
artifact + " Dependency:" + dependency );
+ }
+
+ getLog().info( "\tDependency: " + dependency.getManagementKey() );
+ getLog().info( "\t\tDepMgt : " + artifact.getVersion() );
+ getLog().info( "\t\tResolved: " + dependency.getVersion() );
+ }
+
+ private String getArtifactManagementKey( Artifact artifact )
+ {
+ return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
artifact.getType()
+ + ( !StringUtils.isEmpty( artifact.getClassifier() ) ? ":" +
artifact.getClassifier() : "" );
+ }
+
+ /**
+ * @return the failBuild
+ */
+ public boolean isFailBuild()
+ {
+ return this.failBuild;
+ }
+
+ /**
+ * @param theFailBuild
+ * the failBuild to set
+ */
+ public void setFailBuild( boolean theFailBuild )
+ {
+ this.failBuild = theFailBuild;
+ }
+
+ /**
+ * @return the project
+ */
+ public MavenProject getProject()
+ {
+ return this.project;
+ }
+
+ /**
+ * @param theProject
+ * the project to set
+ */
+ public void setProject( MavenProject theProject )
+ {
+ this.project = theProject;
+ }
+
+ /**
+ * @return the rti
+ */
+ public RuntimeInformation getRti()
+ {
+ return this.rti;
+ }
+
+ /**
+ * @param theRti the rti to set
+ */
+ public void setRti( RuntimeInformation theRti )
+ {
+ this.rti = theRti;
+ }
+}
Modified:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java?view=diff&rev=519524&r1=519523&r2=519524
==============================================================================
---
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java
(original)
+++
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java
Sat Mar 17 19:37:34 2007
@@ -19,17 +19,11 @@
* under the License.
*/
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -37,16 +31,16 @@
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer;
import
org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException;
-import org.codehaus.plexus.util.StringUtils;
/**
- *
+ * This goal analyzes your project's dependencies and lists dependencies that
should be declared, but are not, and dependencies that are declared but unused.
+ * It also executes the analyze-dep-mgt goal.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Mark Hobson</a>
* @version $Id$
* @goal analyze
* @requiresDependencyResolution test
- *
+ * @execute phase="test-compile"
* @since 2.0-alpha-3
*/
public class AnalyzeMojo
@@ -64,23 +58,9 @@
private MavenProject project;
/**
- * Check for dependency / dependencyMgt conflicts
- *
- * @parameter expression="${mdep.checkDepMgt}"
- */
- private boolean checkDependencyMgt = true;
-
- /**
- * Check dependency conflicts
- *
- * @parameter expression="${mdep.checkDependencies}"
- */
- private boolean checkDependencies = false;
-
- /**
* Fail Build on problem
*
- * @parameter expression="${mdep.failBuild}"
+ * @parameter expression="${mdep.analyze.failBuild}"
*/
private boolean failBuild = false;
@@ -92,6 +72,15 @@
* @readonly
*/
private ProjectDependencyAnalyzer analyzer;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter
expression="${component.org.apache.maven.execution.RuntimeInformation}"
+ * @required
+ * @readonly
+ */
+ protected RuntimeInformation rti;
// Mojo methods -----------------------------------------------------------
@@ -101,21 +90,21 @@
public void execute()
throws MojoExecutionException, MojoFailureException
{
- boolean result = false;
- if ( this.checkDependencies )
- {
- result = checkDependencies();
- }
-
- if ( this.checkDependencyMgt )
- {
- result = checkDependencyManagement();
- }
+ boolean result = checkDependencies();
if ( result && this.failBuild )
{
- throw new MojoExecutionException( "Found errors." );
+ throw new MojoExecutionException( "Found Dependency errors." );
}
+
+ //now do AnalyzeDepMgt (put this in a lifecycle later)
+ AnalyzeDepMgt adm = new AnalyzeDepMgt();
+ adm.setLog( getLog() );
+ adm.setProject( this.project );
+ adm.setFailBuild( this.failBuild );
+ adm.setPluginContext( this.getPluginContext() );
+ adm.setRti( rti );
+ adm.execute();
}
// private methods --------------------------------------------------------
@@ -134,11 +123,20 @@
getLog().info( "Used undeclared dependencies:" );
- logArtifacts( analysis.getUsedUndeclaredArtifacts() );
+ Set usedUndeclared = analysis.getUsedUndeclaredArtifacts();
+ logArtifacts( usedUndeclared );
getLog().info( "Unused declared dependencies:" );
- logArtifacts( analysis.getUnusedDeclaredArtifacts() );
+ Set unusedDeclared = analysis.getUnusedDeclaredArtifacts();
+ logArtifacts( unusedDeclared );
+
+ if ((usedUndeclared != null && !usedUndeclared.isEmpty())
+ || unusedDeclared!=null && !unusedDeclared.isEmpty())
+ {
+ getLog().warn( "Potential problems discovered." );
+ result = true;
+ }
}
catch ( ProjectDependencyAnalyzerException exception )
{
@@ -148,70 +146,6 @@
return result;
}
- private boolean checkDependencyManagement()
- throws MojoExecutionException
- {
- boolean foundMismatch = false;
-
- getLog().info( "Found Resolved Dependency / DependencyManagement
mismatches:" );
-
- List depMgtDependencies = null;
- DependencyManagement depMgt = project.getDependencyManagement();
- if ( depMgt != null )
- {
- depMgtDependencies = depMgt.getDependencies();
- }
-
- if ( depMgtDependencies != null && !depMgtDependencies.isEmpty() )
- {
- // put all the dependencies from depMgt into a map for quick lookup
- Map map = new HashMap();
- Iterator iter = depMgtDependencies.iterator();
- while ( iter.hasNext() )
- {
- Dependency dependency = (Dependency) iter.next();
- map.put( dependency.getManagementKey(), dependency );
- }
-
- Set allDependencies = project.getArtifacts();
- iter = allDependencies.iterator();
- while ( iter.hasNext() )
- {
- Artifact artifact = (Artifact) iter.next();
- // getLog().info( "a:"+getArtifactManagementKey( artifact ) );
- // see if this artifact matches anything in the dependencyMgt
- // list
- Dependency dep = (Dependency) map.get(
getArtifactManagementKey( artifact ) );
- if ( dep != null )
- {
- // getLog().info( "Compare:" + dep.getManagementKey()+"
- // v:"+dep.getVersion()+"a:"+artifact.getVersion());
- // ArtifactVersion depVersion = new
- // DefaultArtifactVersion(dep.getVersion());
- ArtifactVersion artifactVersion = new
DefaultArtifactVersion( artifact.getVersion() );
-
- if ( !artifact.isSnapshot() && !dep.getVersion().equals(
artifact.getVersion() ) )
-
- {
- logMismatch( artifact, dep );
- foundMismatch = true;
- }
- }
- }
- }
- else
- {
- getLog().info( " Nothing in DepMgt." );
- }
-
- if ( !foundMismatch )
- {
- getLog().info( " None" );
- }
-
- return foundMismatch;
- }
-
private void logArtifacts( Set artifacts )
{
if ( artifacts.isEmpty() )
@@ -228,23 +162,4 @@
}
}
}
-
- private void logMismatch( Artifact artifact, Dependency dependency )
- throws MojoExecutionException
- {
- if ( artifact == null || dependency == null )
- {
- throw new MojoExecutionException( "Invalid params: Artifact:" +
artifact + " Dependency:" + dependency );
- }
-
- getLog().info("\tDependency: " + dependency.getManagementKey());
- getLog().info( "\t\tDepMgt : " + artifact.getVersion());
- getLog().info( "\t\tResolved: " + dependency.getVersion() );
- }
-
- private String getArtifactManagementKey( Artifact artifact )
- {
- return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
artifact.getType()
- + ( !StringUtils.isEmpty( artifact.getClassifier() ) ? ":" +
artifact.getClassifier() : "" );
- }
-}
+ }
Modified:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/index.apt
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/index.apt?view=diff&rev=519524&r1=519523&r2=519524
==============================================================================
---
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/index.apt
(original)
+++
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/index.apt
Sat Mar 17 19:37:34 2007
@@ -67,9 +67,9 @@
*{{{build-classpath-mojo.html}dependency:build-classpath}} tells
Maven to output the path of the dependencies from the local repository in a
classpath format to be used in java -cp
- ~~*{{{analyze-mojo.html}dependency:analyze}} analyzes your project's
dependencies and lists dependencies that should be declared, but are not, and
dependencies that are declared but unused.
- *Coming soon in 2.0-alpha-3: dependency:analyze analyzes your project's
dependencies and lists dependencies that should be declared, but are not, and
dependencies that are declared but unused.
-
+ *{{{analyze-mojo.html}dependency:analyze}} analyzes your project's
dependencies and lists dependencies that should be declared, but are not, and
dependencies that are declared but unused.
+
+ *{{{analyze-dep-mgt-mojo.html}dependency:analyze-dep-mgt}} analyzes your
projects dependencies and lists mismatches between resolved dependencies and
those listed in your dependencyManagement section.
[]
* Usage
Modified:
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/usage.apt
URL:
http://svn.apache.org/viewvc/maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/usage.apt?view=diff&rev=519524&r1=519523&r2=519524
==============================================================================
---
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/usage.apt
(original)
+++
maven/plugins/branches/maven-dependency-plugin-w-analyzer/src/site/apt/usage.apt
Sat Mar 17 19:37:34 2007
@@ -538,13 +538,13 @@
* The <<<dependency:analyze>>> mojo
- Coming soon in 2.0-alpha-3:
This mojo can be executed from the command line:
+---+
mvn dependency:analyze
+---+
+ This mojo also performs the checks described in the analyze-dep-mht
section.
Sample output:
+---+
@@ -567,4 +567,36 @@
[INFO] None
+---+
+* The <<<dependency:analyze-dep-mgt>>> mojo
+
+ This mojo looks at the dependencies after final resolution and looks
for mismatches in your dependencyManagement section.
+ In versions of maven prior to 2.0.6, it was possible to inherit
versions that didn't match your dependencyManagement. See
{{{http://jira.codehaus.org/browse/MNG-1577}MNG-1577}} for more info.
+
+ If this mojo detects issues, you should attempt to resolve the
discrepancies before upgrading to 2.0.6 to avoid any surprises. This can be
done by upgrading or downgrading the version in dependencyManagement to match
what is actually
+ being included at runtime, or you can specify a dependency in your
project to override what is being included. You can check the results by
rerunning this mojo.
+ If you decide to override by using a dependency, be sure to note it so
you can remove it later after upgrading to 2.0.6. You could also use the
dependency:analyze mojo to uncover this unused direct dependency.
+
+ Note: Because Maven 2.0.6 fixes the problems this mojo is meant to
detect, it will do nothing in versions of Maven greater than 2.0.5.
+
+ This mojo can be executed from the command line:
+
++---+
+mvn dependency:analyze-dep-mgt
++---+
+
+ Sample output:
+
++---+
+[INFO] Found Resolved Dependency / DependencyManagement mismatches:
+[INFO] Dependency: commons-lang:commons-lang:jar
+[INFO] DepMgt : 1.0
+[INFO] Resolved: 2.3
+[INFO] Dependency: commons-digester:commons-digester:jar
+[INFO] DepMgt : 1.6
+[INFO] Resolved: 1.7
+[INFO] Dependency: javax.servlet:servlet-api:jar
+[INFO] DepMgt : 2.3
+[INFO] Resolved: 2.4
+[WARNING] Potential problems found in Dependency Management
++---+