diff -Nru maven-dependency-plugin-2.7/debian/changelog maven-dependency-plugin-2.8/debian/changelog --- maven-dependency-plugin-2.7/debian/changelog 2015-10-30 13:40:57.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/changelog 2015-12-09 11:56:54.000000000 +0000 @@ -1,3 +1,14 @@ +maven-dependency-plugin (2.8-1) unstable; urgency=medium + + * Team upload. + * New upstream release + - Refreshed the patch + - Tightened the dependency on libmaven-dependency-tree-java (>= 2.1) + * Build with the DH sequencer instead of CDBS + * Removed the javadoc package + + -- Emmanuel Bourg Wed, 09 Dec 2015 12:56:52 +0100 + maven-dependency-plugin (2.7-2) unstable; urgency=medium * Team upload. diff -Nru maven-dependency-plugin-2.7/debian/control maven-dependency-plugin-2.8/debian/control --- maven-dependency-plugin-2.7/debian/control 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/control 2015-12-09 11:55:54.000000000 +0000 @@ -3,26 +3,21 @@ Priority: optional Maintainer: Debian Java Maintainers Uploaders: Torsten Werner -Build-Depends: cdbs, debhelper (>= 9), default-jdk, maven-debian-helper (>= 1.4) -Build-Depends-Indep: default-jdk-doc, - junit, +Build-Depends: debhelper (>= 9), default-jdk, maven-debian-helper (>= 1.4) +Build-Depends-Indep: junit, libcommons-collections3-java, libmaven-common-artifact-filters-java, libmaven-dependency-analyzer-java (>= 1.4~), - libmaven-dependency-tree-java (>= 2.0~), + libmaven-dependency-tree-java (>= 2.1~), libmaven-file-management-java, - libmaven-javadoc-plugin-java, libmaven-plugin-testing-java, libmaven-plugin-tools-java, libmaven-reporting-impl-java, libmaven2-core-java, - libmaven2-core-java-doc, libplexus-archiver-java, libplexus-container-default-java, - libplexus-container-default-java-doc, libplexus-io-java, - libplexus-utils-java, - libplexus-utils-java-doc + libplexus-utils-java Standards-Version: 3.9.6 Vcs-Git: git://anonscm.debian.org/pkg-java/maven-dependency-plugin.git Vcs-Browser: http://anonscm.debian.org/cgit/pkg-java/maven-dependency-plugin.git @@ -32,7 +27,6 @@ Architecture: all Depends: ${maven:Depends}, ${misc:Depends} Recommends: ${maven:OptionalDepends} -Suggests: libmaven-dependency-plugin-java-doc Description: Maven Dependency Plugin Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, @@ -50,29 +44,3 @@ * Allowing transparent migration to new features . This plugin provides dependency manipulation (copy, unpack) and analysis. - -Package: libmaven-dependency-plugin-java-doc -Architecture: all -Section: doc -Depends: ${maven:DocDepends}, ${misc:Depends} -Recommends: ${maven:DocOptionalDepends} -Suggests: libmaven-dependency-plugin-java -Description: Documentation for Maven Dependency Plugin - Maven is a software project management and comprehension tool. Based on the - concept of a project object model (POM), Maven can manage a project's build, - reporting and documentation from a central piece of information. - . - Maven's primary goal is to allow a developer to comprehend the complete - state of a development effort in the shortest period of time. In order to - attain this goal there are several areas of concern that Maven attempts - to deal with: - . - * Making the build process easy - * Providing a uniform build system - * Providing quality project information - * Providing guidelines for best practices development - * Allowing transparent migration to new features - . - This plugin provides dependency manipulation (copy, unpack) and analysis. - . - This package contains the API documentation of libmaven-dependency-plugin-java. diff -Nru maven-dependency-plugin-2.7/debian/copyright maven-dependency-plugin-2.8/debian/copyright --- maven-dependency-plugin-2.7/debian/copyright 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/copyright 2015-12-09 11:57:37.000000000 +0000 @@ -6,7 +6,7 @@ Source: http://maven.apache.org/plugins/maven-dependency-plugin/ Files: * -Copyright: 2001-2009, The Apache Software Foundation. +Copyright: 2001-2013, The Apache Software Foundation. License: Apache-2.0 Files: debian/* diff -Nru maven-dependency-plugin-2.7/debian/libmaven-dependency-plugin-java-doc.doc-base.api maven-dependency-plugin-2.8/debian/libmaven-dependency-plugin-java-doc.doc-base.api --- maven-dependency-plugin-2.7/debian/libmaven-dependency-plugin-java-doc.doc-base.api 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/libmaven-dependency-plugin-java-doc.doc-base.api 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -Document: libmaven-dependency-plugin-java -Title: API Javadoc for Maven Dependency Plugin -Author: Maven Dependency Plugin developers -Abstract: This is the API Javadoc provided for the - libmaven-dependency-plugin-java library. -Section: Programming - -Format: HTML -Index: /usr/share/doc/libmaven-dependency-plugin-java/api/index.html -Files: /usr/share/doc/libmaven-dependency-plugin-java/api/* diff -Nru maven-dependency-plugin-2.7/debian/libmaven-dependency-plugin-java-doc.install maven-dependency-plugin-2.8/debian/libmaven-dependency-plugin-java-doc.install --- maven-dependency-plugin-2.7/debian/libmaven-dependency-plugin-java-doc.install 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/libmaven-dependency-plugin-java-doc.install 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -target/apidocs/* usr/share/doc/libmaven-dependency-plugin-java/api - diff -Nru maven-dependency-plugin-2.7/debian/patches/01-fix-plugin-annotations.patch maven-dependency-plugin-2.8/debian/patches/01-fix-plugin-annotations.patch --- maven-dependency-plugin-2.7/debian/patches/01-fix-plugin-annotations.patch 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/patches/01-fix-plugin-annotations.patch 2015-12-09 10:45:57.000000000 +0000 @@ -2,8 +2,8 @@ Author: Emmanuel Bourg Forwarded: not-needed Bug-Debian: https://bugs.debian.org/799003 ---- a/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java -+++ b/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java +--- a/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java ++++ b/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java @@ -55,7 +55,7 @@ /** * The Maven project to analyze. diff -Nru maven-dependency-plugin-2.7/debian/rules maven-dependency-plugin-2.8/debian/rules --- maven-dependency-plugin-2.7/debian/rules 2015-10-30 13:40:00.000000000 +0000 +++ maven-dependency-plugin-2.8/debian/rules 2015-12-09 10:43:31.000000000 +0000 @@ -1,9 +1,9 @@ #!/usr/bin/make -f -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/maven.mk +export JAVA_HOME := /usr/lib/jvm/default-java -JAVA_HOME := /usr/lib/jvm/default-java +%: + dh $@ --buildsystem=maven get-orig-source: - uscan --download-version $(DEB_UPSTREAM_VERSION) --force-download --rename + uscan --download-current-version --force-download --no-symlink diff -Nru maven-dependency-plugin-2.7/pom.xml maven-dependency-plugin-2.8/pom.xml --- maven-dependency-plugin-2.7/pom.xml 2013-03-07 19:17:49.000000000 +0000 +++ maven-dependency-plugin-2.8/pom.xml 2013-05-14 22:15:15.000000000 +0000 @@ -30,7 +30,7 @@ maven-dependency-plugin - 2.7 + 2.8 maven-plugin Maven Dependency Plugin @@ -41,14 +41,20 @@ - scm:svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-dependency-plugin-2.7 - scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-dependency-plugin-2.7 - http://svn.apache.org/viewvc/maven/plugins/tags/maven-dependency-plugin-2.7 + scm:svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-dependency-plugin-2.8 + scm:svn:https://svn.apache.org/repos/asf/maven/plugins/tags/maven-dependency-plugin-2.8 + http://svn.apache.org/viewvc/maven/plugins/tags/maven-dependency-plugin-2.8 JIRA http://jira.codehaus.org/browse/MDEP + + + apache.website + scm:svn:https://svn.apache.org/repos/infra/websites/production/maven/content/${maven.site.path} + + @@ -66,6 +72,9 @@ Andreas Kuhtz + + Holger Mense + @@ -73,6 +82,7 @@ 1.0 2.1 3.2 + plugins-archives/${project.artifactId}-LATEST @@ -173,7 +183,7 @@ org.apache.maven.shared maven-dependency-tree - 2.0 + 2.1 org.apache.maven.shared @@ -208,7 +218,6 @@ org.apache.maven.plugin-tools maven-plugin-annotations - ${mavenPluginPluginVersion} provided @@ -273,6 +282,12 @@ + + maven-release-plugin + + apache-release,rat,run-its + + @@ -311,12 +326,6 @@ org.apache.maven.plugins maven-invoker-plugin - true - ${project.build.directory}/it - setup - verify - ${project.build.directory}/local-repo - src/it/settings.xml clean process-sources @@ -350,18 +359,4 @@ - - - - plexus.snapshots - https://oss.sonatype.org/content/repositories/plexus-snapshots - - false - - - true - - - - diff -Nru maven-dependency-plugin-2.7/src/it/copy-dependencies/pom.xml maven-dependency-plugin-2.8/src/it/copy-dependencies/pom.xml --- maven-dependency-plugin-2.7/src/it/copy-dependencies/pom.xml 2012-07-24 20:57:11.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/copy-dependencies/pom.xml 2013-05-14 22:01:12.000000000 +0000 @@ -23,6 +23,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + org.apache + apache + 5 + + org.apache.maven.its.dependency test 1.0-SNAPSHOT @@ -51,6 +57,27 @@ 2.0.6 javadoc + + org.apache.maven + maven-settings + 2.0.6 + + + org.codehaus.plexus + plexus-interpolation + + + org.codehaus.plexus + plexus-container-default + + + + + org.apache.maven + maven-artifact + 2.0.6 + true + @@ -74,6 +101,7 @@ true ${project.build.directory}/it/copy-dep-test-1 + false @@ -100,6 +128,19 @@ ${project.build.directory}/it/copy-dep-test-3 + + repositoryLayout + + copy-dependencies + + + ${project.build.directory}/it/repositoryLayout + true + true + true + maven-parent + + diff -Nru maven-dependency-plugin-2.7/src/it/copy-dependencies/verify.bsh maven-dependency-plugin-2.8/src/it/copy-dependencies/verify.bsh --- maven-dependency-plugin-2.7/src/it/copy-dependencies/verify.bsh 2012-07-24 19:41:53.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/copy-dependencies/verify.bsh 2013-05-12 14:17:42.000000000 +0000 @@ -1,7 +1,37 @@ import java.io.*; -File libDir = new File( basedir, "target/it/copy-dep-test-1" ); +void checkExpected( File dir, String[] expectedFiles ) +{ + for ( String expectedFile : expectedFiles ) + { + File file = new File( dir, expectedFile ); + System.out.println( "Checking for existence of " + file ); + if ( !file.isFile() ) + { + throw new Exception( "Missing file " + file ); + } + } +} + +void checkExpected( File dir, String[] expectedFiles, String[] unexpectedFiles ) +{ + checkExpected( dir, expectedFiles ); + + for ( String unexpectedFile : unexpectedFiles ) + { + File file = new File( dir, unexpectedFile ); + System.out.println( "Checking for inexistence of " + file ); + if ( file.isFile() ) + { + throw new Exception( "Unexpected file " + file + " found" ); + } + } +} + +File baseOutput = new File( basedir, "target/it" ); + +// test-1 String[] expectedFiles = { "maven-model-2.0.6.jar", "maven-model-2.0.6.pom", @@ -9,56 +39,42 @@ "plexus-utils-1.4.1.pom", "maven-model-2.0.6-sources.jar", "maven-model-2.0.6-javadoc.jar", + "maven-artifact-2.0.6.jar", + "maven-artifact-2.0.6.pom", + "maven-settings-2.0.6.jar", + "maven-settings-2.0.6.pom" }; -for ( String expectedFile : expectedFiles ) -{ - File file = new File( libDir, expectedFile ); - System.out.println( "Checking for existence of " + file ); - if ( !file.isFile() ) - { - throw new Exception( "Missing file " + file ); - } -} +String [] unexpectedFiles = { + "plexus-interpolation-1.11.jar", + "plexus-interpolation-1.11.pom", + "plexus-plexus-container-default-1.0-alpha-9-stable-1.jar", + "plexus-plexus-container-default-1.0-alpha-9-stable-1.pom" +}; -libDir = new File( basedir, "target/it/copy-dep-test-2" ); +checkExpected( new File( baseOutput, "copy-dep-test-1" ), expectedFiles, unexpectedFiles ); + +// test-2 String [] expectedFiles2 = { "maven-model-2.0.6.jar", - "plexus-utils-1.4.1.jar", + "plexus-utils-1.4.1.jar" }; String [] unexpectedFiles2 = { "plexus-utils-1.4.1.pom", "maven-model-2.0.6.pom", "maven-model-2.0.6-sources.jar", - "maven-model-2.0.6-javadoc.jar", + "maven-model-2.0.6-javadoc.jar" }; -for ( String expectedFile : expectedFiles2 ) -{ - File file = new File( libDir, expectedFile ); - System.out.println( "Checking for existence of " + file ); - if ( !file.isFile() ) - { - throw new Exception( "Missing file " + file ); - } -} +checkExpected( new File( baseOutput, "copy-dep-test-2" ), expectedFiles2, unexpectedFiles2 ); -for ( String unexpectedFile : unexpectedFiles2 ) -{ - File file = new File( libDir, unexpectedFile ); - System.out.println( "Checking for existence of " + file ); - if ( file.isFile() ) - { - throw new Exception( "Unexpected file " + file + " found" ); - } -} -libDir = new File( basedir, "target/it/copy-dep-test-3" ); +// test-3 String [] expectedFiles3 = { - "maven-model-2.0.6-sources.jar", + "maven-model-2.0.6-sources.jar" }; String [] unexpectedFiles3 = { @@ -66,28 +82,34 @@ "maven-model-2.0.6.pom", "maven-model-2.0.6-javadoc.jar", "maven-model-2.0.6.jar", - "plexus-utils-1.4.1.jar", + "plexus-utils-1.4.1.jar" }; -for ( String expectedFile : expectedFiles3 ) -{ - File file = new File( libDir, expectedFile ); - System.out.println( "Checking for existence of " + file ); - if ( !file.isFile() ) - { - throw new Exception( "Missing file " + file ); - } -} +checkExpected( new File( baseOutput, "copy-dep-test-3" ), expectedFiles3, unexpectedFiles3 ); -for ( String unexpectedFile : unexpectedFiles3 ) -{ - File file = new File( libDir, unexpectedFile ); - System.out.println( "Checking for existence of " + file ); - if ( file.isFile() ) - { - throw new Exception( "Unexpected file " + file + " found" ); - } -} +// repositoryLayout +String [] expectedFiles4 = { + "org/apache/maven/maven-model/maven-metadata-local.xml", + "org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.jar", + "org/apache/maven/maven-model/2.0.6/maven-model-2.0.6.pom", + "org/apache/maven/maven-model/2.0.6/maven-model-2.0.6-sources.jar", + "org/apache/maven/maven-model/2.0.6/maven-model-2.0.6-javadoc.jar", + "org/codehaus/plexus/plexus-utils/maven-metadata-local.xml", + "org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.jar", + "org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.pom", + "org/apache/apache/5/apache-5.pom", // parent pom + "org/apache/maven/maven/2.0.6/maven-2.0.6.pom", // parent of maven-model + "org/apache/apache/3/apache-3.pom", // parent of parent of maven + "org/codehaus/plexus/plexus/1.0.11/plexus-1.0.11.pom" // parent of plexus-utils +}; + +String [] unexpectedFiles4 = { + "plexus-utils-1.4.1.pom", + "maven-model-2.0.6.pom", + "org/apache/maven/maven-parent/5/maven-parent-5.pom", // parent of maven, excluded by artifactId +}; + +checkExpected( new File( baseOutput, "repositoryLayout" ), expectedFiles4, unexpectedFiles4 ); return true; diff -Nru maven-dependency-plugin-2.7/src/it/purge-local-repository-reresolve/invoker.properties maven-dependency-plugin-2.8/src/it/purge-local-repository-reresolve/invoker.properties --- maven-dependency-plugin-2.7/src/it/purge-local-repository-reresolve/invoker.properties 2012-10-29 18:03:24.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/purge-local-repository-reresolve/invoker.properties 2013-05-03 17:37:20.000000000 +0000 @@ -1,3 +1,3 @@ invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:resolve ${project.groupId}:${project.artifactId}:${project.version}:purge-local-repository # [MNG-5366] Does not work in Maven 3.0.4 due to the resolveAlways operation not correctly forcing a new download -invoker.maven.version = !3.0.4 +invoker.maven.version = !3.0.4,!3.0.5 diff -Nru maven-dependency-plugin-2.7/src/it/purge-local-repository-version-range/invoker.properties maven-dependency-plugin-2.8/src/it/purge-local-repository-version-range/invoker.properties --- maven-dependency-plugin-2.7/src/it/purge-local-repository-version-range/invoker.properties 2012-10-29 18:03:24.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/purge-local-repository-version-range/invoker.properties 2013-05-03 17:37:20.000000000 +0000 @@ -1,3 +1,3 @@ invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:purge-local-repository # [MNG-5366] Does not work in Maven 3.0.4 due to the resolveAlways operation not correctly forcing a new download -invoker.maven.version = !3.0.4 +invoker.maven.version = !3.0.4,!3.0.5 diff -Nru maven-dependency-plugin-2.7/src/it/tree-includes/expected.txt maven-dependency-plugin-2.8/src/it/tree-includes/expected.txt --- maven-dependency-plugin-2.7/src/it/tree-includes/expected.txt 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-includes/expected.txt 2013-05-10 23:05:28.000000000 +0000 @@ -0,0 +1,4 @@ +org.apache.maven.its.dependency:test:jar:1.0-SNAPSHOT +\- org.apache.maven:maven-project:jar:2.0.6:compile + \- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile + \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile diff -Nru maven-dependency-plugin-2.7/src/it/tree-includes/invoker.properties maven-dependency-plugin-2.8/src/it/tree-includes/invoker.properties --- maven-dependency-plugin-2.7/src/it/tree-includes/invoker.properties 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-includes/invoker.properties 2013-05-10 23:05:28.000000000 +0000 @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:tree diff -Nru maven-dependency-plugin-2.7/src/it/tree-includes/pom.xml maven-dependency-plugin-2.8/src/it/tree-includes/pom.xml --- maven-dependency-plugin-2.7/src/it/tree-includes/pom.xml 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-includes/pom.xml 2013-05-10 23:05:28.000000000 +0000 @@ -0,0 +1,47 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + dependency:tree -Dincludes + + Test dependency:tree -Dincludes=... + + + + UTF-8 + + + + + org.apache.maven + maven-project + 2.0.6 + + + + diff -Nru maven-dependency-plugin-2.7/src/it/tree-includes/test.properties maven-dependency-plugin-2.8/src/it/tree-includes/test.properties --- maven-dependency-plugin-2.7/src/it/tree-includes/test.properties 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-includes/test.properties 2013-05-10 23:05:28.000000000 +0000 @@ -0,0 +1,2 @@ +outputFile = target/tree.txt +includes = :wagon* \ No newline at end of file diff -Nru maven-dependency-plugin-2.7/src/it/tree-includes/verify.bsh maven-dependency-plugin-2.8/src/it/tree-includes/verify.bsh --- maven-dependency-plugin-2.7/src/it/tree-includes/verify.bsh 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-includes/verify.bsh 2013-05-10 23:05:28.000000000 +0000 @@ -0,0 +1,18 @@ +import java.io.*; + +import org.codehaus.plexus.util.*; + +String actual = FileUtils.fileRead( new File( basedir, "target/tree.txt" ) ); +String expected = FileUtils.fileRead( new File( basedir, "expected.txt" ) ); + +actual = actual.replaceAll( "[\n\r]+", "\n" ); +expected = expected.replaceAll( "[\n\r]+", "\n" ); + +System.out.println( "Checking dependency tree..." ); + +if ( !actual.equals( expected ) ) +{ + throw new Exception( "Unexpected dependency tree" ); +} + +return true; diff -Nru maven-dependency-plugin-2.7/src/it/tree-verbose/expected.txt maven-dependency-plugin-2.8/src/it/tree-verbose/expected.txt --- maven-dependency-plugin-2.7/src/it/tree-verbose/expected.txt 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-verbose/expected.txt 2013-05-02 22:43:06.000000000 +0000 @@ -0,0 +1,84 @@ +org.apache.maven.its.dependency:tree-verbose:jar:1.0-SNAPSHOT ++- org.apache.maven:maven-project:jar:2.0.6:compile +| +- org.apache.maven:maven-settings:jar:2.0.6:compile +| | +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.6; scope managed from compile; omitted for duplicate) +| | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate) +| | \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate) +| +- (org.apache.maven:maven-profile:jar:2.0.6:compile - omitted for conflict with 2.0.4) +| +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.4; scope managed from compile; omitted for conflict with 2.0.7) +| +- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile +| | +- org.apache.maven:maven-repository-metadata:jar:2.0.6:compile +| | | \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate) +| | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate) +| | +- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate) +| | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile +| | \- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for conflict with 1.4.1) +| +- org.apache.maven:maven-plugin-registry:jar:2.0.6:compile +| | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate) +| | \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate) +| +- org.codehaus.plexus:plexus-utils:jar:1.4.1:compile +| \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile +| +- junit:junit:jar:3.8.1:compile +| +- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for conflict with 1.4.1) +| \- classworlds:classworlds:jar:1.1-alpha-2:compile ++- org.apache.maven:maven-profile:jar:2.0.4:test (scope not updated to compile) +| +- (org.apache.maven:maven-model:jar:2.0.5:test - version managed from 2.0.4; scope managed from compile; omitted for duplicate) +| +- (org.codehaus.plexus:plexus-utils:jar:1.1:test - omitted for conflict with 1.4.1) +| \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:test - omitted for conflict with 1.0-alpha-9-stable-1) ++- org.apache.maven:maven-model:jar:2.0.7:runtime +| \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:runtime - omitted for duplicate) +\- org.apache.xmlgraphics:batik-bridge:jar:1.7:compile + +- org.apache.xmlgraphics:batik-anim:jar:1.7:compile + | +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-dom:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-parser:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-anim:jar:1.7:compile - omitted for cycle) + | +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + | +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate) + | \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile + | \- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-css:jar:1.7:compile + | +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + | +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate) + | \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-dom:jar:1.7:compile + | +- (org.apache.xmlgraphics:batik-css:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-xml:jar:1.7:compile - omitted for duplicate) + | +- (xalan:xalan:jar:2.6.0:compile - omitted for duplicate) + | +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate) + | \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-ext:jar:1.7:compile + | \- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate) + +- (org.apache.xmlgraphics:batik-bridge:jar:1.7:compile - omitted for cycle) + +- org.apache.xmlgraphics:batik-gvt:jar:1.7:compile + | \- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-parser:jar:1.7:compile + | +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + | \- (org.apache.xmlgraphics:batik-xml:jar:1.7:compile - omitted for duplicate) + +- (org.apache.xmlgraphics:batik-bridge:jar:1.7:compile - omitted for cycle) + +- org.apache.xmlgraphics:batik-script:jar:1.7:compile + +- org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile + | +- (org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile - omitted for cycle) + | +- (org.apache.xmlgraphics:batik-anim:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-awt-util:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-css:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-dom:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-ext:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-parser:jar:1.7:compile - omitted for duplicate) + | +- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + | +- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for duplicate) + | \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate) + +- org.apache.xmlgraphics:batik-util:jar:1.7:compile + +- org.apache.xmlgraphics:batik-xml:jar:1.7:compile + | \- (org.apache.xmlgraphics:batik-util:jar:1.7:compile - omitted for duplicate) + +- xalan:xalan:jar:2.6.0:compile + | \- (xml-apis:xml-apis:jar:1.0.b2:compile - omitted for conflict with 1.3.04) + +- xml-apis:xml-apis:jar:1.3.04:compile + \- xml-apis:xml-apis-ext:jar:1.3.04:compile diff -Nru maven-dependency-plugin-2.7/src/it/tree-verbose/invoker.properties maven-dependency-plugin-2.8/src/it/tree-verbose/invoker.properties --- maven-dependency-plugin-2.7/src/it/tree-verbose/invoker.properties 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-verbose/invoker.properties 2013-05-02 22:43:06.000000000 +0000 @@ -0,0 +1 @@ +invoker.goals = clean dependency:tree diff -Nru maven-dependency-plugin-2.7/src/it/tree-verbose/pom.xml maven-dependency-plugin-2.8/src/it/tree-verbose/pom.xml --- maven-dependency-plugin-2.7/src/it/tree-verbose/pom.xml 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-verbose/pom.xml 2013-05-02 22:43:06.000000000 +0000 @@ -0,0 +1,96 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + tree-verbose + 1.0-SNAPSHOT + + VerboseTest + + Test verbose dependency:tree with actual Maven version. + + + + UTF-8 + + + + + + org.apache.maven + maven-model + 2.0.5 + test + + + + + + + org.apache.maven + maven-project + 2.0.6 + + + org.apache.maven + maven-artifact + + + + + org.apache.maven + maven-profile + 2.0.4 + test + + + org.apache.maven + maven-model + 2.0.7 + runtime + + + org.apache.xmlgraphics + batik-bridge + 1.7 + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + target/tree.txt + true + + + + + + diff -Nru maven-dependency-plugin-2.7/src/it/tree-verbose/verify.bsh maven-dependency-plugin-2.8/src/it/tree-verbose/verify.bsh --- maven-dependency-plugin-2.7/src/it/tree-verbose/verify.bsh 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/it/tree-verbose/verify.bsh 2013-05-02 22:43:06.000000000 +0000 @@ -0,0 +1,18 @@ +import java.io.*; + +import org.codehaus.plexus.util.*; + +String actual = FileUtils.fileRead( new File( basedir, "target/tree.txt" ) ); +String expected = FileUtils.fileRead( new File( basedir, "expected.txt" ) ); + +actual = actual.replaceAll( "[\n\r]+", "\n" ); +expected = expected.replaceAll( "[\n\r]+", "\n" ); + +System.out.println( "Checking dependency tree..." ); + +if ( !actual.equals( expected ) ) +{ + throw new Exception( "Unexpected dependency tree" ); +} + +return true; diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractAnalyzeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractAnalyzeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractAnalyzeMojo.java 2013-02-28 20:41:08.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractAnalyzeMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,388 +0,0 @@ -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.io.File; -import java.io.StringWriter; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -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.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; - -/** - * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused - * and declared. - * - * @author Mark Hobson - * @version $Id: AbstractAnalyzeMojo.java 1451330 2013-02-28 20:41:08Z rfscholte $ - * @since 2.0-alpha-5 - */ -public abstract class AbstractAnalyzeMojo - extends AbstractMojo - implements Contextualizable -{ - // fields ----------------------------------------------------------------- - - /** - * The plexus context to look-up the right {@link ProjectDependencyAnalyzer} implementation depending on the mojo - * configuration. - */ - private Context context; - - /** - * The Maven project to analyze. - */ - @Component - private MavenProject project; - - /** - * Specify the project dependency analyzer to use (plexus component role-hint). - * By default, maven-dependency-analyzer is used. - * - * To use this, you must declare a dependency for this plugin that contains the code for the - * analyzer. The analyzer must have a declared Plexus role name, and you specify the role name - * here. - * - * @since 2.2 - */ - @Parameter( property = "analyzer", defaultValue = "default" ) - private String analyzer; - - /** - * Whether to fail the build if a dependency warning is found. - */ - @Parameter( property = "failOnWarning", defaultValue = "false" ) - private boolean failOnWarning; - - /** - * Output used dependencies. - */ - @Parameter( property = "verbose", defaultValue = "false" ) - private boolean verbose; - - /** - * Ignore Runtime/Provided/Test/System scopes for unused dependency analysis. - */ - @Parameter( property = "ignoreNonCompile", defaultValue = "false" ) - private boolean ignoreNonCompile; - - /** - * Output the xml for the missing dependencies (used but not declared). - * - * @since 2.0-alpha-5 - */ - @Parameter( property = "outputXML", defaultValue = "false" ) - private boolean outputXML; - - /** - * Output scriptable values for the missing dependencies (used but not declared). - * - * @since 2.0-alpha-5 - */ - @Parameter( property = "scriptableOutput", defaultValue = "false" ) - private boolean scriptableOutput; - - /** - * Flag to use for scriptable output. - * - * @since 2.0-alpha-5 - */ - @Parameter( property = "scriptableFlag", defaultValue = "$$$%%%" ) - private String scriptableFlag; - - /** - * Flag to use for scriptable output - * - * @since 2.0-alpha-5 - */ - @Parameter( defaultValue = "${basedir}", readonly = true ) - private File baseDir; - - /** - * Target folder - * - * @since 2.0-alpha-5 - */ - @Parameter( defaultValue = "${project.build.directory}", readonly = true ) - private File outputDirectory; - - /** - * Force dependencies as used, to override incomplete result caused by bytecode-level analysis. - * Dependency format is groupId:artifactId. - * - * @since 2.6 - */ - @Parameter - private String[] usedDependencies; - - /** - * Skip plugin execution completely. - * - * @since 2.7 - */ - @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) - private boolean skip; - - // Mojo methods ----------------------------------------------------------- - - /* - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( isSkip() ) - { - getLog().info( "Skipping plugin execution" ); - return; - } - - if ( "pom".equals( project.getPackaging() ) ) - { - getLog().info( "Skipping pom project" ); - return; - } - - if ( outputDirectory == null || !outputDirectory.exists() ) - { - getLog().info( "Skipping project with no build directory" ); - return; - } - - boolean warning = checkDependencies(); - - if ( warning && failOnWarning ) - { - throw new MojoExecutionException( "Dependency problems found" ); - } - } - - protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer() - throws MojoExecutionException - { - - final String role = ProjectDependencyAnalyzer.ROLE; - final String roleHint = analyzer; - - try - { - final PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - - return (ProjectDependencyAnalyzer) container.lookup( role, roleHint ); - } - catch ( Exception exception ) - { - throw new MojoExecutionException( - "Failed to instantiate ProjectDependencyAnalyser with role " + role + " / role-hint " + roleHint, - exception ); - } - } - - public void contextualize( Context context ) - throws ContextException - { - this.context = context; - } - - public boolean isSkip() - { - return skip; - } - - public void setSkip( boolean skip ) - { - this.skip = skip; - } - - // private methods -------------------------------------------------------- - - private boolean checkDependencies() - throws MojoExecutionException - { - ProjectDependencyAnalysis analysis; - try - { - analysis = createProjectDependencyAnalyzer().analyze( project ); - - if ( usedDependencies != null ) - { - analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies ); - } - } - catch ( ProjectDependencyAnalyzerException exception ) - { - throw new MojoExecutionException( "Cannot analyze dependencies", exception ); - } - - if ( ignoreNonCompile ) - { - analysis = analysis.ignoreNonCompile(); - } - - Set usedDeclared = analysis.getUsedDeclaredArtifacts(); - Set usedUndeclared = analysis.getUsedUndeclaredArtifacts(); - Set unusedDeclared = analysis.getUnusedDeclaredArtifacts(); - - if ( ( !verbose || usedDeclared.isEmpty() ) && usedUndeclared.isEmpty() && unusedDeclared.isEmpty() ) - { - getLog().info( "No dependency problems found" ); - return false; - } - - if ( verbose && !usedDeclared.isEmpty() ) - { - getLog().info( "Used declared dependencies found:" ); - - logArtifacts( analysis.getUsedDeclaredArtifacts(), false ); - } - - if ( !usedUndeclared.isEmpty() ) - { - getLog().warn( "Used undeclared dependencies found:" ); - - logArtifacts( usedUndeclared, true ); - } - - if ( !unusedDeclared.isEmpty() ) - { - getLog().warn( "Unused declared dependencies found:" ); - - logArtifacts( unusedDeclared, true ); - } - - if ( outputXML ) - { - writeDependencyXML( usedUndeclared ); - } - - if ( scriptableOutput ) - { - writeScriptableOutput( usedUndeclared ); - } - - return !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty(); - } - - private void logArtifacts( Set artifacts, boolean warn ) - { - if ( artifacts.isEmpty() ) - { - getLog().info( " None" ); - } - else - { - for ( Artifact artifact : artifacts ) - { - // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 - artifact.isSnapshot(); - - if ( warn ) - { - getLog().warn( " " + artifact ); - } - else - { - getLog().info( " " + artifact ); - } - - } - } - } - - private void writeDependencyXML( Set artifacts ) - { - if ( !artifacts.isEmpty() ) - { - getLog().info( "Add the following to your pom to correct the missing dependencies: " ); - - StringWriter out = new StringWriter(); - PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( out ); - - for ( Artifact artifact : artifacts ) - { - // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 - artifact.isSnapshot(); - - writer.startElement( "dependency" ); - writer.startElement( "groupId" ); - writer.writeText( artifact.getGroupId() ); - writer.endElement(); - writer.startElement( "artifactId" ); - writer.writeText( artifact.getArtifactId() ); - writer.endElement(); - writer.startElement( "version" ); - writer.writeText( artifact.getBaseVersion() ); - if ( !StringUtils.isBlank( artifact.getClassifier() ) ) - { - writer.startElement( "classifier" ); - writer.writeText( artifact.getClassifier() ); - writer.endElement(); - } - writer.endElement(); - - if ( !Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) - { - writer.startElement( "scope" ); - writer.writeText( artifact.getScope() ); - writer.endElement(); - } - writer.endElement(); - } - - getLog().info( "\n" + out.getBuffer() ); - } - } - - private void writeScriptableOutput( Set artifacts ) - { - if ( !artifacts.isEmpty() ) - { - getLog().info( "Missing dependencies: " ); - String pomFile = baseDir.getAbsolutePath() + File.separatorChar + "pom.xml"; - StringBuilder buf = new StringBuilder(); - - for ( Artifact artifact : artifacts ) - { - // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 - artifact.isSnapshot(); - - buf.append( scriptableFlag + ":" + pomFile + ":" + artifact.getDependencyConflictId() + ":" - + artifact.getClassifier() + ":" + artifact.getBaseVersion() + ":" + artifact.getScope() - + "\n" ); - } - getLog().info( "\n" + buf ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java 2012-10-21 22:53:48.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,402 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.resolvers.ArtifactsResolver; -import org.apache.maven.plugin.dependency.utils.resolvers.DefaultArtifactsResolver; -import org.apache.maven.plugin.dependency.utils.translators.ArtifactTranslator; -import org.apache.maven.plugin.dependency.utils.translators.ClassifierTypeTranslator; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; -import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; -import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; -import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter; -import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; -import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; -import org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter; -import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; -import org.apache.maven.shared.artifact.filter.collection.TypeFilter; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.util.HashSet; -import java.util.Set; - -/** - * Class that encapsulates the plugin parameters, and contains methods that - * handle dependency filtering - * - * @author Brian Fox - * @version $Id: AbstractDependencyFilterMojo.java 1400737 2012-10-21 22:53:48Z hboutemy $ - * @see org.apache.maven.plugin.dependency.AbstractDependencyMojo - */ -public abstract class AbstractDependencyFilterMojo - extends AbstractDependencyMojo -{ - /** - * If we should exclude transitive dependencies - * - * @since 2.0 - */ - @Parameter( property = "excludeTransitive", defaultValue = "false" ) - protected boolean excludeTransitive; - - /** - * Comma Separated list of Types to include. Empty String indicates include - * everything (default). - * - * @since 2.0 - */ - @Parameter( property = "includeTypes", defaultValue = "" ) - protected String includeTypes; - - /** - * Comma Separated list of Types to exclude. Empty String indicates don't - * exclude anything (default). - * - * @since 2.0 - */ - @Parameter( property = "excludeTypes", defaultValue = "" ) - protected String excludeTypes; - - /** - * Scope to include. An Empty string indicates all scopes (default). - * - * @since 2.0 - */ - @Parameter( property = "includeScope", defaultValue = "" ) - protected String includeScope; - - /** - * Scope to exclude. An Empty string indicates no scopes (default). - * - * @since 2.0 - */ - @Parameter( property = "excludeScope", defaultValue = "" ) - protected String excludeScope; - - /** - * Comma Separated list of Classifiers to include. Empty String indicates - * include everything (default). - * - * @since 2.0 - */ - @Parameter( property = "includeClassifiers", defaultValue = "" ) - protected String includeClassifiers; - - /** - * Comma Separated list of Classifiers to exclude. Empty String indicates - * don't exclude anything (default). - * - * @since 2.0 - */ - @Parameter( property = "excludeClassifiers", defaultValue = "" ) - protected String excludeClassifiers; - - /** - * Specify classifier to look for. Example: sources - * - * @since 2.0 - */ - @Parameter( property = "classifier", defaultValue = "" ) - protected String classifier; - - /** - * Specify type to look for when constructing artifact based on classifier. - * Example: java-source,jar,war - * - * @since 2.0 - */ - @Parameter( property = "type", defaultValue = "" ) - protected String type; - - /** - * Comma separated list of Artifact names to exclude. - * - * @since 2.0 - */ - @Parameter( property = "excludeArtifactIds", defaultValue = "" ) - protected String excludeArtifactIds; - - /** - * Comma separated list of Artifact names to include. - * - * @since 2.0 - */ - @Parameter( property = "includeArtifactIds", defaultValue = "" ) - protected String includeArtifactIds; - - /** - * Comma separated list of GroupId Names to exclude. - * - * @since 2.0 - */ - @Parameter( property = "excludeGroupIds", defaultValue = "" ) - protected String excludeGroupIds; - - /** - * Comma separated list of GroupIds to include. - * - * @since 2.0 - */ - @Parameter( property = "includeGroupIds", defaultValue = "" ) - protected String includeGroupIds; - - /** - * Directory to store flag files - * - * @since 2.0 - */ - @Parameter( property = "markersDirectory", - defaultValue = "${project.build.directory}/dependency-maven-plugin-markers" ) - protected File markersDirectory; - - /** - * Overwrite release artifacts - * - * @since 1.0 - */ - @Parameter( property = "overWriteReleases", defaultValue = "false" ) - protected boolean overWriteReleases; - - /** - * Overwrite snapshot artifacts - * - * @since 1.0 - */ - @Parameter( property = "overWriteSnapshots", defaultValue = "false" ) - protected boolean overWriteSnapshots; - - /** - * Overwrite artifacts that don't exist or are older than the source. - * - * @since 2.0 - */ - @Parameter( property = "overWriteIfNewer", defaultValue = "true" ) - protected boolean overWriteIfNewer; - - /** - * Prepend the groupId during copy. - * - * @since 2.2 - */ - @Parameter( property = "mdep.prependGroupId", defaultValue = "false" ) - protected boolean prependGroupId = false; - - /** - * Return an {@link ArtifactsFilter} indicating which artifacts must be filtered out. - * - * @return an {@link ArtifactsFilter} indicating which artifacts must be filtered out. - */ - protected abstract ArtifactsFilter getMarkedArtifactFilter(); - - /** - * Retrieves dependencies, either direct only or all including transitive. - * - * @return A HashSet of artifacts - * @throws MojoExecutionException - */ - protected Set getResolvedDependencies( boolean stopOnFailure ) - throws MojoExecutionException - - { - DependencyStatusSets status = getDependencySets( stopOnFailure ); - - return status.getResolvedDependencies(); - } - - /** - * Method creates filters and filters the projects dependencies. This method - * also transforms the dependencies if classifier is set. The dependencies - * are filtered in least specific to most specific order - * - * @param stopOnFailure - * @return DependencyStatusSets - Bean of TreeSets that contains information - * on the projects dependencies - * @throws MojoExecutionException - */ - protected DependencyStatusSets getDependencySets( boolean stopOnFailure ) - throws MojoExecutionException - { - // add filters in well known order, least specific to most specific - FilterArtifacts filter = new FilterArtifacts(); - - filter.addFilter( new ProjectTransitivityFilter( project.getDependencyArtifacts(), this.excludeTransitive ) ); - - filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ), - DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) ); - - filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ), - DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) ); - - filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ), - DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) ); - - filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ), - DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) ); - - filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ), - DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) ); - - // start with all artifacts. - @SuppressWarnings( "unchecked" ) Set artifacts = project.getArtifacts(); - - // perform filtering - try - { - artifacts = filter.filter( artifacts ); - } - catch ( ArtifactFilterException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - - // transform artifacts if classifier is set - DependencyStatusSets status = null; - if ( StringUtils.isNotEmpty( classifier ) ) - { - status = getClassifierTranslatedDependencies( artifacts, stopOnFailure ); - } - else - { - status = filterMarkedDependencies( artifacts ); - } - - return status; - } - - /** - * Transform artifacts - * - * @param artifacts - * @param stopOnFailure - * @return DependencyStatusSets - Bean of TreeSets that contains information - * on the projects dependencies - * @throws MojoExecutionException - */ - protected DependencyStatusSets getClassifierTranslatedDependencies( Set artifacts, boolean stopOnFailure ) - throws MojoExecutionException - { - Set unResolvedArtifacts = new HashSet(); - Set resolvedArtifacts = artifacts; - DependencyStatusSets status = new DependencyStatusSets(); - - // possibly translate artifacts into a new set of artifacts based on the - // classifier and type - // if this did something, we need to resolve the new artifacts - if ( StringUtils.isNotEmpty( classifier ) ) - { - ArtifactTranslator translator = new ClassifierTypeTranslator( this.classifier, this.type, this.factory ); - artifacts = translator.translate( artifacts, getLog() ); - - status = filterMarkedDependencies( artifacts ); - - // the unskipped artifacts are in the resolved set. - artifacts = status.getResolvedDependencies(); - - // resolve the rest of the artifacts - ArtifactsResolver artifactsResolver = - new DefaultArtifactsResolver( this.resolver, this.getLocal(), this.remoteRepos, stopOnFailure ); - resolvedArtifacts = artifactsResolver.resolve( artifacts, getLog() ); - - // calculate the artifacts not resolved. - unResolvedArtifacts.addAll( artifacts ); - unResolvedArtifacts.removeAll( resolvedArtifacts ); - } - - // return a bean of all 3 sets. - status.setResolvedDependencies( resolvedArtifacts ); - status.setUnResolvedDependencies( unResolvedArtifacts ); - - return status; - } - - /** - * Filter the marked dependencies - * - * @param artifacts - * @return - * @throws MojoExecutionException - */ - protected DependencyStatusSets filterMarkedDependencies( Set artifacts ) - throws MojoExecutionException - { - // remove files that have markers already - FilterArtifacts filter = new FilterArtifacts(); - filter.clearFilters(); - filter.addFilter( getMarkedArtifactFilter() ); - - Set unMarkedArtifacts; - try - { - unMarkedArtifacts = filter.filter( artifacts ); - } - catch ( ArtifactFilterException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - - // calculate the skipped artifacts - Set skippedArtifacts = new HashSet(); - skippedArtifacts.addAll( artifacts ); - skippedArtifacts.removeAll( unMarkedArtifacts ); - - return new DependencyStatusSets( unMarkedArtifacts, null, skippedArtifacts ); - } - - /** - * @return Returns the markersDirectory. - */ - public File getMarkersDirectory() - { - return this.markersDirectory; - } - - /** - * @param theMarkersDirectory The markersDirectory to set. - */ - public void setMarkersDirectory( File theMarkersDirectory ) - { - this.markersDirectory = theMarkersDirectory; - } - - // TODO: Set marker files. - - /** - * @return true, if the groupId should be prepended to the filename. - */ - public boolean isPrependGroupId() - { - return prependGroupId; - } - - /** - * @param prependGroupId - - * true if the groupId must be prepended during the copy. - */ - public void setPrependGroupId( boolean prependGroupId ) - { - this.prependGroupId = prependGroupId; - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java 2013-03-07 19:09:58.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -123,7 +123,7 @@ /** * Contains the full list of projects in the reactor. */ - @Parameter( defaultValue = "${reactorProjects}" ) + @Parameter( defaultValue = "${reactorProjects}", readonly = true ) protected List reactorProjects; /** @@ -132,7 +132,7 @@ * @since 2.0 */ @Parameter( property = "silent", defaultValue = "false" ) - public boolean silent; + protected boolean silent; /** * Output absolute filename for resolved artifacts @@ -212,12 +212,11 @@ protected void copyFile( File artifact, File destFile ) throws MojoExecutionException { - Log theLog = this.getLog(); try { - theLog.info( - "Copying " + ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName() ) - + " to " + destFile ); + getLog().info( "Copying " + + ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() + : artifact.getName() ) + " to " + destFile ); if ( artifact.isDirectory() ) { @@ -282,7 +281,7 @@ unArchiver.setUseJvmChmod( useJvmChmod ); - unArchiver.setIgnorePermissions( this.ignorePermissions ); + unArchiver.setIgnorePermissions( ignorePermissions ); unArchiver.setSourceFile( file ); @@ -402,7 +401,7 @@ /** * @return Returns the resolver. */ - public org.apache.maven.artifact.resolver.ArtifactResolver getResolver() + public ArtifactResolver getResolver() { return this.resolver; } diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java 2012-07-04 13:28:33.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractFromDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,220 +0,0 @@ -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 org.apache.maven.plugins.annotations.Parameter; - -import java.io.File; - -/** - * Abstract Parent class used by mojos that get Artifact information from the - * project dependencies. - * - * @author Brian Fox - * @version $Id: AbstractFromDependenciesMojo.java 1357251 2012-07-04 13:28:33Z olamy $ - */ -public abstract class AbstractFromDependenciesMojo - extends AbstractDependencyFilterMojo -{ - - /** - * Strip artifact version during copy - */ - @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) - protected boolean stripVersion = false; - - /** - * Default location used for mojo unless overridden in ArtifactItem - * - * @since 1.0 - */ - @Parameter( property = "outputDirectory", defaultValue = "${project.build.directory}/dependency" ) - protected File outputDirectory; - - /** - * Place each artifact in the same directory layout as a default repository. - *
example: /outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar - * - * @since 2.0-alpha-2 - */ - @Parameter( property = "mdep.useRepositoryLayout", defaultValue = "false" ) - protected boolean useRepositoryLayout; - - /** - * Also copy the pom of each artifact. - * - * @since 2.0 - */ - @Parameter( property = "mdep.copyPom", defaultValue = "false" ) - protected boolean copyPom = true; - - /** - * Place each type of file in a separate subdirectory. (example - * /outputDirectory/runtime /outputDirectory/provided etc) - * - * @since 2.2 - */ - @Parameter( property = "mdep.useSubDirectoryPerScope", defaultValue = "false" ) - protected boolean useSubDirectoryPerScope; - - /** - * Place each type of file in a separate subdirectory. (example - * /outputDirectory/jars /outputDirectory/wars etc) - * - * @since 2.0-alpha-1 - */ - @Parameter( property = "mdep.useSubDirectoryPerType", defaultValue = "false" ) - protected boolean useSubDirectoryPerType; - - /** - * Place each file in a separate subdirectory. (example - * /outputDirectory/junit-3.8.1-jar) - * - * @since 2.0-alpha-1 - */ - @Parameter( property = "mdep.useSubDirectoryPerArtifact", defaultValue = "false" ) - protected boolean useSubDirectoryPerArtifact; - - /** - * This only applies if the classifier parameter is used. - * - * @since 2.0-alpha-2 - */ - @Parameter( property = "mdep.failOnMissingClassifierArtifact", defaultValue = "false" ) - protected boolean failOnMissingClassifierArtifact = true; - - /** - * @return Returns the outputDirectory. - */ - public File getOutputDirectory() - { - return this.outputDirectory; - } - - /** - * @param theOutputDirectory The outputDirectory to set. - */ - public void setOutputDirectory( File theOutputDirectory ) - { - this.outputDirectory = theOutputDirectory; - } - - /** - * @return Returns the useSubDirectoryPerArtifact. - */ - public boolean isUseSubDirectoryPerArtifact() - { - return this.useSubDirectoryPerArtifact; - } - - /** - * @param theUseSubDirectoryPerArtifact The useSubDirectoryPerArtifact to set. - */ - public void setUseSubDirectoryPerArtifact( boolean theUseSubDirectoryPerArtifact ) - { - this.useSubDirectoryPerArtifact = theUseSubDirectoryPerArtifact; - } - - /** - * @return Returns the useSubDirectoryPerScope - */ - public boolean isUseSubDirectoryPerScope() - { - return this.useSubDirectoryPerScope; - } - - /** - * @param theUseSubDirectoryPerScope The useSubDirectoryPerScope to set. - */ - public void setUseSubDirectoryPerScope( boolean theUseSubDirectoryPerScope ) - { - this.useSubDirectoryPerScope = theUseSubDirectoryPerScope; - } - - /** - * @return Returns the useSubDirectoryPerType. - */ - public boolean isUseSubDirectoryPerType() - { - return this.useSubDirectoryPerType; - } - - /** - * @param theUseSubDirectoryPerType The useSubDirectoryPerType to set. - */ - public void setUseSubDirectoryPerType( boolean theUseSubDirectoryPerType ) - { - this.useSubDirectoryPerType = theUseSubDirectoryPerType; - } - - public boolean isFailOnMissingClassifierArtifact() - { - return failOnMissingClassifierArtifact; - } - - public void setFailOnMissingClassifierArtifact( boolean failOnMissingClassifierArtifact ) - { - this.failOnMissingClassifierArtifact = failOnMissingClassifierArtifact; - } - - public boolean isStripVersion() - { - return stripVersion; - } - - public void setStripVersion( boolean stripVersion ) - { - this.stripVersion = stripVersion; - } - - /** - * @return true, if dependencies must be planted in a repository layout - */ - public boolean isUseRepositoryLayout() - { - return useRepositoryLayout; - } - - /** - * @param useRepositoryLayout - - * true if dependencies must be planted in a repository layout - */ - public void setUseRepositoryLayout( boolean useRepositoryLayout ) - { - this.useRepositoryLayout = useRepositoryLayout; - } - - /** - * @return true, if the pom of each artifact must be copied - */ - public boolean isCopyPom() - { - return this.copyPom; - } - - /** - * @param copyPom - true if the pom of each artifact must be copied - */ - public void setCopyPom( boolean copyPom ) - { - this.copyPom = copyPom; - } - -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java 2013-02-20 19:02:48.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AbstractResolveMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,181 +0,0 @@ -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.io.File; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; -import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter; -import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; -import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; -import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; -import org.apache.maven.shared.artifact.filter.collection.TypeFilter; - -/** - * @author Brian Fox - * @version $Id: AbstractResolveMojo.java 1448351 2013-02-20 19:02:48Z jdcasey $ - */ -public abstract class AbstractResolveMojo - extends AbstractDependencyFilterMojo -{ - /** - * Project builder -- builds a model from a pom.xml - */ - @Component - protected MavenProjectBuilder mavenProjectBuilder; - - /** - * If specified, this parameter will cause the dependencies to be written to the path specified, instead of writing - * to the console. - * - * @since 2.0 - */ - @Parameter( property = "outputFile" ) - protected File outputFile; - - /** - * This method resolves the dependency artifacts from the project. - * - * @param theProject - * The POM. - * @return resolved set of dependency artifacts. - * - * @throws ArtifactResolutionException - * @throws ArtifactNotFoundException - * @throws InvalidDependencyVersionException - */ - - /** - * Whether to append outputs into the output file or overwrite it. - * - * @since 2.2 - */ - @Parameter( property = "appendOutput", defaultValue = "false" ) - protected boolean appendOutput; - - /** - * Don't resolve plugins that are in the current reactor. - * Only works for plugins at the moment. - * - * @since 2.7 - */ - @Parameter( property = "excludeReactor", defaultValue = "true" ) - protected boolean excludeReactor; - - protected FilterArtifacts getPluginArtifactsFilter() - { - if ( excludeReactor ) - { - final StringBuilder exAids = new StringBuilder(); - if ( this.excludeArtifactIds != null ) - { - exAids.append( this.excludeArtifactIds ); - } - - for ( final MavenProject rp : reactorProjects ) - { - if ( !"maven-plugin".equals( rp.getPackaging() ) ) - { - continue; - } - - if ( exAids.length() > 0 ) - { - exAids.append( "," ); - } - - exAids.append( rp.getArtifactId() ); - } - - this.excludeArtifactIds = exAids.toString(); - } - - final FilterArtifacts filter = new FilterArtifacts(); - - filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ), - DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) ); - - filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ), - DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) ); - - filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ), - DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) ); - - filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ), - DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) ); - - filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ), - DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) ); - - return filter; - } - - protected Set resolveDependencyArtifacts( final MavenProject theProject ) - throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException - { - final Set artifacts = - theProject.createArtifacts( this.factory, Artifact.SCOPE_TEST, - new ScopeArtifactFilter( Artifact.SCOPE_TEST ) ); - - for ( final Artifact artifact : artifacts ) - { - // resolve the new artifact - this.resolver.resolve( artifact, this.remoteRepos, this.getLocal() ); - } - return artifacts; - } - - /** - * This method resolves all transitive dependencies of an artifact. - * - * @param artifact the artifact used to retrieve dependencies - * @return resolved set of dependencies - * @throws ArtifactResolutionException - * @throws ArtifactNotFoundException - * @throws ProjectBuildingException - * @throws InvalidDependencyVersionException - * - */ - protected Set resolveArtifactDependencies( final Artifact artifact ) - throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException, - InvalidDependencyVersionException - { - final Artifact pomArtifact = - this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", - "pom" ); - - final MavenProject pomProject = - mavenProjectBuilder.buildFromRepository( pomArtifact, this.remoteRepos, this.getLocal() ); - - return resolveDependencyArtifacts( pomProject ); - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AbstractAnalyzeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AbstractAnalyzeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AbstractAnalyzeMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AbstractAnalyzeMojo.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,388 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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.io.File; +import java.io.StringWriter; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +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.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; + +/** + * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused + * and declared. + * + * @author Mark Hobson + * @version $Id: AbstractAnalyzeMojo.java 1481550 2013-05-12 13:10:48Z hboutemy $ + * @since 2.0-alpha-5 + */ +public abstract class AbstractAnalyzeMojo + extends AbstractMojo + implements Contextualizable +{ + // fields ----------------------------------------------------------------- + + /** + * The plexus context to look-up the right {@link ProjectDependencyAnalyzer} implementation depending on the mojo + * configuration. + */ + private Context context; + + /** + * The Maven project to analyze. + */ + @Component + private MavenProject project; + + /** + * Specify the project dependency analyzer to use (plexus component role-hint). + * By default, maven-dependency-analyzer is used. + * + * To use this, you must declare a dependency for this plugin that contains the code for the + * analyzer. The analyzer must have a declared Plexus role name, and you specify the role name + * here. + * + * @since 2.2 + */ + @Parameter( property = "analyzer", defaultValue = "default" ) + private String analyzer; + + /** + * Whether to fail the build if a dependency warning is found. + */ + @Parameter( property = "failOnWarning", defaultValue = "false" ) + private boolean failOnWarning; + + /** + * Output used dependencies. + */ + @Parameter( property = "verbose", defaultValue = "false" ) + private boolean verbose; + + /** + * Ignore Runtime/Provided/Test/System scopes for unused dependency analysis. + */ + @Parameter( property = "ignoreNonCompile", defaultValue = "false" ) + private boolean ignoreNonCompile; + + /** + * Output the xml for the missing dependencies (used but not declared). + * + * @since 2.0-alpha-5 + */ + @Parameter( property = "outputXML", defaultValue = "false" ) + private boolean outputXML; + + /** + * Output scriptable values for the missing dependencies (used but not declared). + * + * @since 2.0-alpha-5 + */ + @Parameter( property = "scriptableOutput", defaultValue = "false" ) + private boolean scriptableOutput; + + /** + * Flag to use for scriptable output. + * + * @since 2.0-alpha-5 + */ + @Parameter( property = "scriptableFlag", defaultValue = "$$$%%%" ) + private String scriptableFlag; + + /** + * Flag to use for scriptable output + * + * @since 2.0-alpha-5 + */ + @Parameter( defaultValue = "${basedir}", readonly = true ) + private File baseDir; + + /** + * Target folder + * + * @since 2.0-alpha-5 + */ + @Parameter( defaultValue = "${project.build.directory}", readonly = true ) + private File outputDirectory; + + /** + * Force dependencies as used, to override incomplete result caused by bytecode-level analysis. + * Dependency format is groupId:artifactId. + * + * @since 2.6 + */ + @Parameter + private String[] usedDependencies; + + /** + * Skip plugin execution completely. + * + * @since 2.7 + */ + @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) + private boolean skip; + + // Mojo methods ----------------------------------------------------------- + + /* + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( isSkip() ) + { + getLog().info( "Skipping plugin execution" ); + return; + } + + if ( "pom".equals( project.getPackaging() ) ) + { + getLog().info( "Skipping pom project" ); + return; + } + + if ( outputDirectory == null || !outputDirectory.exists() ) + { + getLog().info( "Skipping project with no build directory" ); + return; + } + + boolean warning = checkDependencies(); + + if ( warning && failOnWarning ) + { + throw new MojoExecutionException( "Dependency problems found" ); + } + } + + protected ProjectDependencyAnalyzer createProjectDependencyAnalyzer() + throws MojoExecutionException + { + + final String role = ProjectDependencyAnalyzer.ROLE; + final String roleHint = analyzer; + + try + { + final PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + + return (ProjectDependencyAnalyzer) container.lookup( role, roleHint ); + } + catch ( Exception exception ) + { + throw new MojoExecutionException( + "Failed to instantiate ProjectDependencyAnalyser with role " + role + " / role-hint " + roleHint, + exception ); + } + } + + public void contextualize( Context context ) + throws ContextException + { + this.context = context; + } + + public boolean isSkip() + { + return skip; + } + + public void setSkip( boolean skip ) + { + this.skip = skip; + } + + // private methods -------------------------------------------------------- + + private boolean checkDependencies() + throws MojoExecutionException + { + ProjectDependencyAnalysis analysis; + try + { + analysis = createProjectDependencyAnalyzer().analyze( project ); + + if ( usedDependencies != null ) + { + analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies ); + } + } + catch ( ProjectDependencyAnalyzerException exception ) + { + throw new MojoExecutionException( "Cannot analyze dependencies", exception ); + } + + if ( ignoreNonCompile ) + { + analysis = analysis.ignoreNonCompile(); + } + + Set usedDeclared = analysis.getUsedDeclaredArtifacts(); + Set usedUndeclared = analysis.getUsedUndeclaredArtifacts(); + Set unusedDeclared = analysis.getUnusedDeclaredArtifacts(); + + if ( ( !verbose || usedDeclared.isEmpty() ) && usedUndeclared.isEmpty() && unusedDeclared.isEmpty() ) + { + getLog().info( "No dependency problems found" ); + return false; + } + + if ( verbose && !usedDeclared.isEmpty() ) + { + getLog().info( "Used declared dependencies found:" ); + + logArtifacts( analysis.getUsedDeclaredArtifacts(), false ); + } + + if ( !usedUndeclared.isEmpty() ) + { + getLog().warn( "Used undeclared dependencies found:" ); + + logArtifacts( usedUndeclared, true ); + } + + if ( !unusedDeclared.isEmpty() ) + { + getLog().warn( "Unused declared dependencies found:" ); + + logArtifacts( unusedDeclared, true ); + } + + if ( outputXML ) + { + writeDependencyXML( usedUndeclared ); + } + + if ( scriptableOutput ) + { + writeScriptableOutput( usedUndeclared ); + } + + return !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty(); + } + + private void logArtifacts( Set artifacts, boolean warn ) + { + if ( artifacts.isEmpty() ) + { + getLog().info( " None" ); + } + else + { + for ( Artifact artifact : artifacts ) + { + // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 + artifact.isSnapshot(); + + if ( warn ) + { + getLog().warn( " " + artifact ); + } + else + { + getLog().info( " " + artifact ); + } + + } + } + } + + private void writeDependencyXML( Set artifacts ) + { + if ( !artifacts.isEmpty() ) + { + getLog().info( "Add the following to your pom to correct the missing dependencies: " ); + + StringWriter out = new StringWriter(); + PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( out ); + + for ( Artifact artifact : artifacts ) + { + // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 + artifact.isSnapshot(); + + writer.startElement( "dependency" ); + writer.startElement( "groupId" ); + writer.writeText( artifact.getGroupId() ); + writer.endElement(); + writer.startElement( "artifactId" ); + writer.writeText( artifact.getArtifactId() ); + writer.endElement(); + writer.startElement( "version" ); + writer.writeText( artifact.getBaseVersion() ); + if ( !StringUtils.isBlank( artifact.getClassifier() ) ) + { + writer.startElement( "classifier" ); + writer.writeText( artifact.getClassifier() ); + writer.endElement(); + } + writer.endElement(); + + if ( !Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) ) + { + writer.startElement( "scope" ); + writer.writeText( artifact.getScope() ); + writer.endElement(); + } + writer.endElement(); + } + + getLog().info( "\n" + out.getBuffer() ); + } + } + + private void writeScriptableOutput( Set artifacts ) + { + if ( !artifacts.isEmpty() ) + { + getLog().info( "Missing dependencies: " ); + String pomFile = baseDir.getAbsolutePath() + File.separatorChar + "pom.xml"; + StringBuilder buf = new StringBuilder(); + + for ( Artifact artifact : artifacts ) + { + // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961 + artifact.isSnapshot(); + + buf.append( scriptableFlag + ":" + pomFile + ":" + artifact.getDependencyConflictId() + ":" + + artifact.getClassifier() + ":" + artifact.getBaseVersion() + ":" + artifact.getScope() + + "\n" ); + } + getLog().info( "\n" + buf ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDepMgt.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDepMgt.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDepMgt.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDepMgt.java 2013-05-12 13:25:34.000000000 +0000 @@ -0,0 +1,373 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Exclusion; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * 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 MNG-1577 for more info. + * This mojo is also useful for just detecting projects that override the + * dependencyManagement directly. Set ignoreDirect to false to detect these + * otherwise normal conditions. + * + * @author Brian Fox + * @version $Id: AnalyzeDepMgt.java 1481553 2013-05-12 13:25:34Z hboutemy $ + * @since 2.0-alpha-3 + */ +@Mojo( name = "analyze-dep-mgt", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +public class AnalyzeDepMgt + extends AbstractMojo +{ + // fields ----------------------------------------------------------------- + + /** + * + */ + @Component + private MavenProject project; + + /** + * Fail the build if a problem is detected. + */ + @Parameter( property = "mdep.analyze.failBuild", defaultValue = "false" ) + private boolean failBuild = false; + + /** + * Ignore Direct Dependency Overrides of dependencyManagement section. + */ + @Parameter( property = "mdep.analyze.ignore.direct", defaultValue = "true" ) + private boolean ignoreDirect = true; + + /** + * Skip plugin execution completely. + * + * @since 2.7 + */ + @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) + private boolean skip; + + // Mojo methods ----------------------------------------------------------- + + /* + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( isSkip() ) + { + getLog().info( "Skipping plugin execution" ); + return; + } + + boolean result = checkDependencyManagement(); + if ( result ) + { + if ( this.failBuild ) + + { + throw new MojoExecutionException( "Found Dependency errors." ); + } + else + { + getLog().warn( "Potential problems found in Dependency Management " ); + } + } + } + + /** + * Does the work of checking the DependencyManagement Section. + * + * @return true if errors are found. + * @throws MojoExecutionException + */ + private boolean checkDependencyManagement() + throws MojoExecutionException + { + boolean foundError = 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 depMgtMap = new HashMap(); + Map exclusions = new HashMap(); + for ( Dependency depMgtDependency : depMgtDependencies ) + { + depMgtMap.put( depMgtDependency.getManagementKey(), depMgtDependency ); + + // now put all the exclusions into a map for quick lookup + exclusions.putAll( addExclusions( depMgtDependency.getExclusions() ) ); + } + + // get dependencies for the project (including transitive) + @SuppressWarnings( "unchecked" ) Set allDependencyArtifacts = + new HashSet( project.getArtifacts() ); + + // don't warn if a dependency that is directly listed overrides + // depMgt. That's ok. + if ( this.ignoreDirect ) + { + getLog().info( "\tIgnoring Direct Dependencies." ); + @SuppressWarnings( "unchecked" ) Set directDependencies = project.getDependencyArtifacts(); + allDependencyArtifacts.removeAll( directDependencies ); + } + + // log exclusion errors + List exclusionErrors = getExclusionErrors( exclusions, allDependencyArtifacts ); + for ( Artifact exclusion : exclusionErrors ) + { + getLog().info( StringUtils.stripEnd( getArtifactManagementKey( exclusion ), ":" ) + + " was excluded in DepMgt, but version " + exclusion.getVersion() + + " has been found in the dependency tree." ); + foundError = true; + } + + // find and log version mismatches + Map mismatch = getMismatch( depMgtMap, allDependencyArtifacts ); + for ( Map.Entry entry : mismatch.entrySet() ) + { + logMismatch( entry.getKey(), entry.getValue() ); + foundError = true; + } + if ( !foundError ) + { + getLog().info( " None" ); + } + } + else + { + getLog().info( " Nothing in DepMgt." ); + } + + return foundError; + } + + /** + * Returns a map of the exclusions using the Dependency ManagementKey as the + * keyset. + * + * @param exclusionList to be added to the map. + * @return a map of the exclusions using the Dependency ManagementKey as the + * keyset. + */ + public Map addExclusions( List exclusionList ) + { + Map exclusions = new HashMap(); + if ( exclusionList != null ) + { + for ( Exclusion exclusion : exclusionList ) + { + exclusions.put( getExclusionKey( exclusion ), exclusion ); + } + } + return exclusions; + } + + /** + * Returns a List of the artifacts that should have been excluded, but were + * found in the dependency tree. + * + * @param exclusions a map of the DependencyManagement exclusions, with the + * ManagementKey as the key and Dependency as the value. + * @param allDependencyArtifacts resolved artifacts to be compared. + * @return list of artifacts that should have been excluded. + */ + public List getExclusionErrors( Map exclusions, Set allDependencyArtifacts ) + { + List list = new ArrayList(); + + for ( Artifact artifact : allDependencyArtifacts ) + { + if ( exclusions.containsKey( getExclusionKey( artifact ) ) ) + { + list.add( artifact ); + } + } + + return list; + } + + public String getExclusionKey( Artifact artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId(); + } + + public String getExclusionKey( Exclusion ex ) + { + return ex.getGroupId() + ":" + ex.getArtifactId(); + } + + /** + * Calculate the mismatches between the DependencyManagement and resolved + * artifacts + * + * @param depMgtMap contains the Dependency.GetManagementKey as the keyset for + * quick lookup. + * @param allDependencyArtifacts contains the set of all artifacts to compare. + * @return a map containing the resolved artifact as the key and the listed + * dependency as the value. + */ + public Map getMismatch( Map depMgtMap, + Set allDependencyArtifacts ) + { + Map mismatchMap = new HashMap(); + + for ( Artifact dependencyArtifact : allDependencyArtifacts ) + { + Dependency depFromDepMgt = depMgtMap.get( getArtifactManagementKey( dependencyArtifact ) ); + if ( depFromDepMgt != null ) + { + //workaround for MNG-2961 + dependencyArtifact.isSnapshot(); + + if ( !depFromDepMgt.getVersion().equals( dependencyArtifact.getBaseVersion() ) ) + { + mismatchMap.put( dependencyArtifact, depFromDepMgt ); + } + } + } + return mismatchMap; + } + + /** + * This function displays the log to the screen showing the versions and + * information about the artifacts that don't match. + * + * @param dependencyArtifact the artifact that was resolved. + * @param dependencyFromDepMgt the dependency listed in the DependencyManagement section. + * @throws MojoExecutionException + */ + public void logMismatch( Artifact dependencyArtifact, Dependency dependencyFromDepMgt ) + throws MojoExecutionException + { + if ( dependencyArtifact == null || dependencyFromDepMgt == null ) + { + throw new MojoExecutionException( + "Invalid params: Artifact:" + dependencyArtifact + " Dependency:" + dependencyFromDepMgt ); + } + + getLog().info( "\tDependency: " + StringUtils.stripEnd( dependencyFromDepMgt.getManagementKey(), ":" ) ); + getLog().info( "\t\tDepMgt : " + dependencyFromDepMgt.getVersion() ); + getLog().info( "\t\tResolved: " + dependencyArtifact.getBaseVersion() ); + } + + /** + * This function returns a string comparable with Dependency.GetManagementKey. + * + * @param artifact to gen the key for + * @return a string in the form: groupId:ArtifactId:Type[:Classifier] + */ + public String getArtifactManagementKey( Artifact artifact ) + { + return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ( ( + artifact.getClassifier() != null ) ? ":" + 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 ignoreDirect + */ + public boolean isIgnoreDirect() + { + return this.ignoreDirect; + } + + /** + * @param theIgnoreDirect the ignoreDirect to set + */ + public void setIgnoreDirect( boolean theIgnoreDirect ) + { + this.ignoreDirect = theIgnoreDirect; + } + + public boolean isSkip() + { + return skip; + } + + public void setSkip( boolean skip ) + { + this.skip = skip; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDuplicateMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDuplicateMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDuplicateMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeDuplicateMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -0,0 +1,181 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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 org.apache.commons.collections.CollectionUtils; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; + +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * Analyzes the <dependencies/> and <dependencyManagement/> tags in the + * pom.xml and determines the duplicate declared dependencies. + * + * @author Vincent Siveton + * @version $Id: AnalyzeDuplicateMojo.java 1481553 2013-05-12 13:25:34Z hboutemy $ + */ +@Mojo( name = "analyze-duplicate", aggregator = false, threadSafe = true ) +public class AnalyzeDuplicateMojo + extends AbstractMojo +{ + /** + * Skip plugin execution completely. + * + * @since 2.7 + */ + @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) + private boolean skip; + + /** + * The Maven project to analyze. + */ + @Component + private MavenProject project; + + /** + * {@inheritDoc} + */ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( isSkip() ) + { + getLog().info( "Skipping plugin execution" ); + return; + } + + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + Model model = null; + Reader reader = null; + try + { + reader = ReaderFactory.newXmlReader( project.getFile() ); + model = pomReader.read( reader ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "IOException: " + e.getMessage(), e ); + } + finally + { + IOUtil.close( reader ); + } + + Set duplicateDependencies = new HashSet(); + if ( model.getDependencies() != null ) + { + duplicateDependencies = findDuplicateDependencies( model.getDependencies() ); + } + + Set duplicateDependenciesManagement = new HashSet(); + if ( model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null ) + { + duplicateDependenciesManagement = + findDuplicateDependencies( model.getDependencyManagement().getDependencies() ); + } + + if ( getLog().isInfoEnabled() ) + { + StringBuilder sb = new StringBuilder(); + + if ( !duplicateDependencies.isEmpty() ) + { + sb.append( "List of duplicate dependencies defined in in your pom.xml:\n" ); + for ( Iterator it = duplicateDependencies.iterator(); it.hasNext(); ) + { + String dup = it.next(); + + sb.append( "\to " + dup ); + if ( it.hasNext() ) + { + sb.append( "\n" ); + } + } + } + + if ( !duplicateDependenciesManagement.isEmpty() ) + { + if ( sb.length() > 0 ) + { + sb.append( "\n" ); + } + sb.append( + "List of duplicate dependencies defined in in " + "your pom.xml:\n" ); + for ( Iterator it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) + { + String dup = it.next(); + + sb.append( "\to " + dup ); + if ( it.hasNext() ) + { + sb.append( "\n" ); + } + } + } + + if ( sb.length() > 0 ) + { + getLog().info( sb.toString() ); + } + else + { + getLog().info( "No duplicate dependencies found in or in " ); + } + } + } + + private Set findDuplicateDependencies( List modelDependencies ) + { + List modelDependencies2 = new ArrayList(); + for ( Dependency dep : modelDependencies ) + { + modelDependencies2.add( dep.getManagementKey() ); + } + + return new HashSet( + CollectionUtils.disjunction( modelDependencies2, new HashSet( modelDependencies2 ) ) ); + } + + public boolean isSkip() + { + return skip; + } + + public void setSkip( boolean skip ) + { + this.skip = skip; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeMojo.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,47 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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 org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused + * and declared. This goal is intended to be used standalone, thus it always executes the test-compile + * phase - use the dependency:analyze-only goal instead when participating in the build lifecycle. + * + *

By default, maven-dependency-analyzer is + * used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any + * analyzer can be plugged in through analyzer parameter.

+ * + * @author Mark Hobson + * @version $Id: AnalyzeMojo.java 1481550 2013-05-12 13:10:48Z hboutemy $ + * @see AnalyzeOnlyMojo + * @since 2.0-alpha-3 + */ +@Mojo( name = "analyze", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +@Execute( phase = LifecyclePhase.TEST_COMPILE ) +public class AnalyzeMojo + extends AbstractAnalyzeMojo +{ + // subclassed to provide annotations +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeOnlyMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeOnlyMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeOnlyMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeOnlyMojo.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,47 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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 org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused + * and declared. This goal is intended to be used in the build lifecycle, thus it assumes that the + * test-compile phase has been executed - use the dependency:analyze goal instead when + * running standalone. + * + *

By default, maven-dependency-analyzer is + * used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any + * analyzer can be plugged in through analyzer parameter.

+ * + * @author Mark Hobson + * @version $Id: AnalyzeOnlyMojo.java 1481550 2013-05-12 13:10:48Z hboutemy $ + * @see AnalyzeMojo + * @since 2.0 + */ +@Mojo( name = "analyze-only", requiresDependencyResolution = ResolutionScope.TEST, + defaultPhase = LifecyclePhase.VERIFY, threadSafe = true ) +public class AnalyzeOnlyMojo + extends AbstractAnalyzeMojo +{ + // subclassed to provide annotations +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -0,0 +1,236 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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 org.apache.maven.doxia.sink.Sink; +import org.apache.maven.doxia.siterenderer.Renderer; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.MavenReportException; +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 java.io.File; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Analyzes the dependencies of this project and produces a report that summarizes which are: used and declared; used + * and undeclared; unused and declared. + * + * @version $Id: AnalyzeReportMojo.java 1481553 2013-05-12 13:25:34Z hboutemy $ + * @since 2.0-alpha-5 + */ +@Mojo( name = "analyze-report", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +@Execute( phase = LifecyclePhase.TEST_COMPILE ) +public class AnalyzeReportMojo + extends AbstractMavenReport +{ + // fields ----------------------------------------------------------------- + + /** + * The Maven project to analyze. + */ + @Component + private MavenProject project; + + /** + * The Maven project dependency analyzer to use. + */ + @Component + private ProjectDependencyAnalyzer analyzer; + + /** + * + */ + @Component + private Renderer siteRenderer; + + /** + * Target folder + * + * @since 2.0-alpha-5 + */ + @Parameter( defaultValue = "${project.build.directory}", readonly = true ) + private File outputDirectory; + + /** + * Ignore Runtime/Provided/Test/System scopes for unused dependency analysis + * @since 2.2 + */ + @Parameter( property = "ignoreNonCompile", defaultValue = "false" ) + private boolean ignoreNonCompile; + + /** + * Force dependencies as used, to override incomplete result caused by bytecode-level analysis. + * Dependency format is groupId:artifactId. + * + * @since 2.6 + */ + @Parameter + private String[] usedDependencies; + + /** + * Skip plugin execution completely. + * + * @since 2.7 + */ + @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) + private boolean skip; + + // Mojo methods ----------------------------------------------------------- + + /* + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void executeReport( Locale locale ) + throws MavenReportException + { + if ( isSkip() ) + { + getLog().info( "Skipping plugin execution" ); + return; + } + + // Step 0: Checking pom availability + if ( "pom".equals( project.getPackaging() ) ) + { + getLog().info( "Skipping pom project" ); + return; + } + + if ( outputDirectory == null || !outputDirectory.exists() ) + { + getLog().info( "Skipping project with no Target directory" ); + return; + } + + // Step 1: Analyze the project + ProjectDependencyAnalysis analysis = null; + try + { + analysis = analyzer.analyze( project ); + + if ( usedDependencies != null ) + { + analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies ); + } + } + catch ( ProjectDependencyAnalyzerException exception ) + { + throw new MavenReportException( "Cannot analyze dependencies", exception ); + } + + //remove everything that's not in the compile scope + if ( ignoreNonCompile ) + { + analysis = analysis.ignoreNonCompile(); + } + + // Step 2: Create sink and bundle + Sink sink = getSink(); + ResourceBundle bundle = getBundle( locale ); + + // Step 3: Generate the report + AnalyzeReportView analyzethis = new AnalyzeReportView(); + analyzethis.generateReport( analysis, sink, bundle ); + } + + // MavenReport methods ---------------------------------------------------- + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getOutputName() + */ + public String getOutputName() + { + return "dependency-analysis"; + } + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getName(java.util.Locale) + */ + public String getName( Locale locale ) + { + return getBundle( locale ).getString( "analyze.report.name" ); + } + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getDescription(java.util.Locale) + */ + public String getDescription( Locale locale ) + { + return getBundle( locale ).getString( "analyze.report.description" ); + } + + // AbstractMavenReport methods -------------------------------------------- + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getProject() + */ + protected MavenProject getProject() + { + return project; + } + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() + */ + protected String getOutputDirectory() + { + getLog().info( outputDirectory.toString() ); + + return outputDirectory.toString(); + } + + /* + * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() + */ + protected Renderer getSiteRenderer() + { + return siteRenderer; + } + + // protected methods ------------------------------------------------------ + + /** + * @param locale the current locale + */ + protected ResourceBundle getBundle( Locale locale ) + { + return ResourceBundle.getBundle( "analyze-report", locale, this.getClass().getClassLoader() ); + } + + public boolean isSkip() + { + return skip; + } + + public void setSkip( boolean skip ) + { + this.skip = skip; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportView.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportView.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportView.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/analyze/AnalyzeReportView.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,206 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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.Iterator; +import java.util.ResourceBundle; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.doxia.sink.Sink; +import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis; + +/** + * This is the view part of the analyze-report mojo. It generates the HTML report for the project website. The HTML + * output is same as the CLI output. + */ +public class AnalyzeReportView +{ + /** + * Generates the HTML report. + */ + public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, ResourceBundle bundle ) + { + sink.head(); + sink.title(); + sink.text( bundle.getString( "analyze.report.header" ) ); + sink.title_(); + sink.head_(); + sink.body(); + + // Generate title + sink.section1(); + sink.sectionTitle1(); + sink.text( bundle.getString( "analyze.report.mainTitle" ) ); + sink.sectionTitle1_(); + + // Generate Used Declared dependencies: + sink.section2(); + sink.sectionTitle2(); + sink.text( bundle.getString( "analyze.report.UsedDeclaredDependencies" ) ); + sink.sectionTitle2_(); + if ( analysis.getUsedDeclaredArtifacts().isEmpty() ) + { + sink.paragraph(); + sink.text( bundle.getString( "analyze.report.noDependency" ) ); + sink.paragraph_(); + sink.horizontalRule(); + } + else + { + generateDependenciesTable( sink, analysis.getUsedDeclaredArtifacts().iterator() ); + } + sink.section2_(); + + // Generate Used Undeclared dependencies: + sink.section2(); + sink.sectionTitle2(); + sink.text( bundle.getString( "analyze.report.UsedUndeclaredDependencies" ) ); + sink.sectionTitle2_(); + if ( analysis.getUsedUndeclaredArtifacts().isEmpty() ) + { + sink.paragraph(); + sink.text( bundle.getString( "analyze.report.noDependency" ) ); + sink.paragraph_(); + sink.horizontalRule(); + } + else + { + generateDependenciesTable( sink, analysis.getUsedUndeclaredArtifacts().iterator() ); + } + sink.section2_(); + + // Generate Unused declared dependencies: + sink.section2(); + sink.sectionTitle2(); + sink.text( bundle.getString( "analyze.report.UnusedDeclaredDependencies" ) ); + sink.sectionTitle2_(); + if ( analysis.getUnusedDeclaredArtifacts().isEmpty() ) + { + sink.paragraph(); + sink.text( bundle.getString( "analyze.report.noDependency" ) ); + sink.paragraph_(); + sink.horizontalRule(); + } + else + { + generateDependenciesTable( sink, analysis.getUnusedDeclaredArtifacts().iterator() ); + } + sink.section2_(); + + sink.section1_(); + + // Closing the report + sink.body_(); + sink.flush(); + sink.close(); + } + + /** + * Generate a table for the given dependencies iterator. + */ + public void generateDependenciesTable( Sink sink, Iterator iter ) + { + sink.table(); + + sink.tableRow(); + sink.tableCell(); + sink.bold(); + sink.text( "GroupId" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "ArtifactId" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "Version" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "Scope" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "Classifier" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "Type" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableCell(); + sink.bold(); + sink.text( "Optional" ); + sink.bold_(); + sink.tableCell_(); + + sink.tableRow_(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + + sink.tableRow(); + sink.tableCell(); + sink.text( artifact.getGroupId() ); + sink.tableCell_(); + sink.tableCell(); + sink.text( artifact.getArtifactId() ); + sink.tableCell_(); + sink.tableCell(); + sink.text( artifact.getVersion() ); + sink.tableCell_(); + sink.tableCell(); + sink.text( artifact.getScope() ); + sink.tableCell_(); + sink.tableCell(); + sink.text( artifact.getClassifier() ); + sink.tableCell_(); + sink.tableCell(); + sink.text( artifact.getType() ); + sink.tableCell_(); + sink.tableCell(); + if ( artifact.isOptional() ) + { + sink.text( "" ); + } + else + { + sink.text( "false" ); + } + + sink.tableCell_(); + sink.tableRow_(); + } + + sink.table_(); + sink.horizontalRule(); + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDepMgt.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,373 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Exclusion; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.StringUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * 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 MNG-1577 for more info. - * This mojo is also useful for just detecting projects that override the - * dependencyManagement directly. Set ignoreDirect to false to detect these - * otherwise normal conditions. - * - * @author Brian Fox - * @version $Id: AnalyzeDepMgt.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 2.0-alpha-3 - */ -@Mojo( name = "analyze-dep-mgt", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) -public class AnalyzeDepMgt - extends AbstractMojo -{ - // fields ----------------------------------------------------------------- - - /** - * - */ - @Component - private MavenProject project; - - /** - * Fail the build if a problem is detected. - */ - @Parameter( property = "mdep.analyze.failBuild", defaultValue = "false" ) - private boolean failBuild = false; - - /** - * Ignore Direct Dependency Overrides of dependencyManagement section. - */ - @Parameter( property = "mdep.analyze.ignore.direct", defaultValue = "true" ) - private boolean ignoreDirect = true; - - /** - * Skip plugin execution completely. - * - * @since 2.7 - */ - @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) - private boolean skip; - - // Mojo methods ----------------------------------------------------------- - - /* - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( isSkip() ) - { - getLog().info( "Skipping plugin execution" ); - return; - } - - boolean result = checkDependencyManagement(); - if ( result ) - { - if ( this.failBuild ) - - { - throw new MojoExecutionException( "Found Dependency errors." ); - } - else - { - getLog().warn( "Potential problems found in Dependency Management " ); - } - } - } - - /** - * Does the work of checking the DependencyManagement Section. - * - * @return true if errors are found. - * @throws MojoExecutionException - */ - private boolean checkDependencyManagement() - throws MojoExecutionException - { - boolean foundError = 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 depMgtMap = new HashMap(); - Map exclusions = new HashMap(); - for ( Dependency depMgtDependency : depMgtDependencies ) - { - depMgtMap.put( depMgtDependency.getManagementKey(), depMgtDependency ); - - // now put all the exclusions into a map for quick lookup - exclusions.putAll( addExclusions( depMgtDependency.getExclusions() ) ); - } - - // get dependencies for the project (including transitive) - @SuppressWarnings( "unchecked" ) Set allDependencyArtifacts = - new HashSet( project.getArtifacts() ); - - // don't warn if a dependency that is directly listed overrides - // depMgt. That's ok. - if ( this.ignoreDirect ) - { - getLog().info( "\tIgnoring Direct Dependencies." ); - @SuppressWarnings( "unchecked" ) Set directDependencies = project.getDependencyArtifacts(); - allDependencyArtifacts.removeAll( directDependencies ); - } - - // log exclusion errors - List exclusionErrors = getExclusionErrors( exclusions, allDependencyArtifacts ); - for ( Artifact exclusion : exclusionErrors ) - { - getLog().info( StringUtils.stripEnd( getArtifactManagementKey( exclusion ), ":" ) - + " was excluded in DepMgt, but version " + exclusion.getVersion() - + " has been found in the dependency tree." ); - foundError = true; - } - - // find and log version mismatches - Map mismatch = getMismatch( depMgtMap, allDependencyArtifacts ); - for ( Map.Entry entry : mismatch.entrySet() ) - { - logMismatch( entry.getKey(), entry.getValue() ); - foundError = true; - } - if ( !foundError ) - { - getLog().info( " None" ); - } - } - else - { - getLog().info( " Nothing in DepMgt." ); - } - - return foundError; - } - - /** - * Returns a map of the exclusions using the Dependency ManagementKey as the - * keyset. - * - * @param exclusionList to be added to the map. - * @return a map of the exclusions using the Dependency ManagementKey as the - * keyset. - */ - public Map addExclusions( List exclusionList ) - { - Map exclusions = new HashMap(); - if ( exclusionList != null ) - { - for ( Exclusion exclusion : exclusionList ) - { - exclusions.put( getExclusionKey( exclusion ), exclusion ); - } - } - return exclusions; - } - - /** - * Returns a List of the artifacts that should have been excluded, but were - * found in the dependency tree. - * - * @param exclusions a map of the DependencyManagement exclusions, with the - * ManagementKey as the key and Dependency as the value. - * @param allDependencyArtifacts resolved artifacts to be compared. - * @return list of artifacts that should have been excluded. - */ - public List getExclusionErrors( Map exclusions, Set allDependencyArtifacts ) - { - List list = new ArrayList(); - - for ( Artifact artifact : allDependencyArtifacts ) - { - if ( exclusions.containsKey( getExclusionKey( artifact ) ) ) - { - list.add( artifact ); - } - } - - return list; - } - - public String getExclusionKey( Artifact artifact ) - { - return artifact.getGroupId() + ":" + artifact.getArtifactId(); - } - - public String getExclusionKey( Exclusion ex ) - { - return ex.getGroupId() + ":" + ex.getArtifactId(); - } - - /** - * Calculate the mismatches between the DependencyManagement and resolved - * artifacts - * - * @param depMgtMap contains the Dependency.GetManagementKey as the keyset for - * quick lookup. - * @param allDependencyArtifacts contains the set of all artifacts to compare. - * @return a map containing the resolved artifact as the key and the listed - * dependency as the value. - */ - public Map getMismatch( Map depMgtMap, - Set allDependencyArtifacts ) - { - Map mismatchMap = new HashMap(); - - for ( Artifact dependencyArtifact : allDependencyArtifacts ) - { - Dependency depFromDepMgt = depMgtMap.get( getArtifactManagementKey( dependencyArtifact ) ); - if ( depFromDepMgt != null ) - { - //workaround for MNG-2961 - dependencyArtifact.isSnapshot(); - - if ( !depFromDepMgt.getVersion().equals( dependencyArtifact.getBaseVersion() ) ) - { - mismatchMap.put( dependencyArtifact, depFromDepMgt ); - } - } - } - return mismatchMap; - } - - /** - * This function displays the log to the screen showing the versions and - * information about the artifacts that don't match. - * - * @param dependencyArtifact the artifact that was resolved. - * @param dependencyFromDepMgt the dependency listed in the DependencyManagement section. - * @throws MojoExecutionException - */ - public void logMismatch( Artifact dependencyArtifact, Dependency dependencyFromDepMgt ) - throws MojoExecutionException - { - if ( dependencyArtifact == null || dependencyFromDepMgt == null ) - { - throw new MojoExecutionException( - "Invalid params: Artifact:" + dependencyArtifact + " Dependency:" + dependencyFromDepMgt ); - } - - getLog().info( "\tDependency: " + StringUtils.stripEnd( dependencyFromDepMgt.getManagementKey(), ":" ) ); - getLog().info( "\t\tDepMgt : " + dependencyFromDepMgt.getVersion() ); - getLog().info( "\t\tResolved: " + dependencyArtifact.getBaseVersion() ); - } - - /** - * This function returns a string comparable with Dependency.GetManagementKey. - * - * @param artifact to gen the key for - * @return a string in the form: groupId:ArtifactId:Type[:Classifier] - */ - public String getArtifactManagementKey( Artifact artifact ) - { - return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ( ( - artifact.getClassifier() != null ) ? ":" + 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 ignoreDirect - */ - public boolean isIgnoreDirect() - { - return this.ignoreDirect; - } - - /** - * @param theIgnoreDirect the ignoreDirect to set - */ - public void setIgnoreDirect( boolean theIgnoreDirect ) - { - this.ignoreDirect = theIgnoreDirect; - } - - public boolean isSkip() - { - return skip; -} - - public void setSkip( boolean skip ) - { - this.skip = skip; - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDuplicateMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDuplicateMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDuplicateMojo.java 2013-02-28 20:41:08.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeDuplicateMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,181 +0,0 @@ -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 org.apache.commons.collections.CollectionUtils; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; - -import java.io.Reader; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * Analyzes the <dependencies/> and <dependencyManagement/> tags in the - * pom.xml and determines the duplicate declared dependencies. - * - * @author Vincent Siveton - * @version $Id: AnalyzeDuplicateMojo.java 1451330 2013-02-28 20:41:08Z rfscholte $ - */ -@Mojo( name = "analyze-duplicate", aggregator = false, threadSafe = true ) -public class AnalyzeDuplicateMojo - extends AbstractMojo -{ - /** - * Skip plugin execution completely. - * - * @since 2.7 - */ - @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) - private boolean skip; - - /** - * The Maven project to analyze. - */ - @Component - private MavenProject project; - - /** - * {@inheritDoc} - */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( isSkip() ) - { - getLog().info( "Skipping plugin execution" ); - return; - } - - MavenXpp3Reader pomReader = new MavenXpp3Reader(); - Model model = null; - Reader reader = null; - try - { - reader = ReaderFactory.newXmlReader( project.getFile() ); - model = pomReader.read( reader ); - } - catch ( Exception e ) - { - throw new MojoExecutionException( "IOException: " + e.getMessage(), e ); - } - finally - { - IOUtil.close( reader ); - } - - Set duplicateDependencies = new HashSet(); - if ( model.getDependencies() != null ) - { - duplicateDependencies = findDuplicateDependencies( model.getDependencies() ); - } - - Set duplicateDependenciesManagement = new HashSet(); - if ( model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null ) - { - duplicateDependenciesManagement = - findDuplicateDependencies( model.getDependencyManagement().getDependencies() ); - } - - if ( getLog().isInfoEnabled() ) - { - StringBuilder sb = new StringBuilder(); - - if ( !duplicateDependencies.isEmpty() ) - { - sb.append( "List of duplicate dependencies defined in in your pom.xml:\n" ); - for ( Iterator it = duplicateDependencies.iterator(); it.hasNext(); ) - { - String dup = it.next(); - - sb.append( "\to " + dup ); - if ( it.hasNext() ) - { - sb.append( "\n" ); - } - } - } - - if ( !duplicateDependenciesManagement.isEmpty() ) - { - if ( sb.length() > 0 ) - { - sb.append( "\n" ); - } - sb.append( - "List of duplicate dependencies defined in in " + "your pom.xml:\n" ); - for ( Iterator it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) - { - String dup = it.next(); - - sb.append( "\to " + dup ); - if ( it.hasNext() ) - { - sb.append( "\n" ); - } - } - } - - if ( sb.length() > 0 ) - { - getLog().info( sb.toString() ); - } - else - { - getLog().info( "No duplicate dependencies found in or in " ); - } - } - } - - private Set findDuplicateDependencies( List modelDependencies ) - { - List modelDependencies2 = new ArrayList(); - for ( Dependency dep : modelDependencies ) - { - modelDependencies2.add( dep.getManagementKey() ); - } - - return new HashSet( - CollectionUtils.disjunction( modelDependencies2, new HashSet( modelDependencies2 ) ) ); - } - - public boolean isSkip() - { - return skip; -} - - public void setSkip( boolean skip ) - { - this.skip = skip; - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java 2012-10-21 23:05:22.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -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 org.apache.maven.plugins.annotations.Execute; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.ResolutionScope; - -/** - * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused - * and declared. This goal is intended to be used standalone, thus it always executes the test-compile - * phase - use the dependency:analyze-only goal instead when participating in the build lifecycle. - * - *

By default, maven-dependency-analyzer is - * used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any - * analyzer can be plugged in through analyzer parameter.

- * - * @author Mark Hobson - * @version $Id: AnalyzeMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $ - * @see AnalyzeOnlyMojo - * @since 2.0-alpha-3 - */ -@Mojo( name = "analyze", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) -@Execute( phase = LifecyclePhase.TEST_COMPILE ) -public class AnalyzeMojo - extends AbstractAnalyzeMojo -{ - // subclassed to provide annotations -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeOnlyMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeOnlyMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeOnlyMojo.java 2012-10-21 23:05:22.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeOnlyMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -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 org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.ResolutionScope; - -/** - * Analyzes the dependencies of this project and determines which are: used and declared; used and undeclared; unused - * and declared. This goal is intended to be used in the build lifecycle, thus it assumes that the - * test-compile phase has been executed - use the dependency:analyze goal instead when - * running standalone. - * - *

By default, maven-dependency-analyzer is - * used to perform the analysis, with limitations due to the fact that it works at bytecode level, but any - * analyzer can be plugged in through analyzer parameter.

- * - * @author Mark Hobson - * @version $Id: AnalyzeOnlyMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $ - * @see AnalyzeMojo - * @since 2.0 - */ -@Mojo( name = "analyze-only", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.VERIFY, threadSafe = true ) -public class AnalyzeOnlyMojo - extends AbstractAnalyzeMojo -{ - // subclassed to provide annotations -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,237 +0,0 @@ -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 org.apache.maven.doxia.sink.Sink; -import org.apache.maven.doxia.siterenderer.Renderer; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Execute; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; -import org.apache.maven.reporting.AbstractMavenReport; -import org.apache.maven.reporting.MavenReportException; -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 java.io.File; -import java.util.Locale; -import java.util.ResourceBundle; - -/** - * Analyzes the dependencies of this project and produces a report that summarizes which are: used and declared; used - * and undeclared; unused and declared. - * - * @version $Id: AnalyzeReportMojo.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 2.0-alpha-5 - */ -@Mojo( name = "analyze-report", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) -@Execute( phase = LifecyclePhase.TEST_COMPILE ) -public class AnalyzeReportMojo - extends AbstractMavenReport -{ - // fields ----------------------------------------------------------------- - - /** - * The Maven project to analyze. - */ - @Component - private MavenProject project; - - /** - * The Maven project dependency analyzer to use. - */ - @Component - private ProjectDependencyAnalyzer analyzer; - - /** - * - */ - @Component - private Renderer siteRenderer; - - /** - * Target folder - * - * @since 2.0-alpha-5 - */ - @Parameter( defaultValue = "${project.build.directory}", readonly = true ) - private File outputDirectory; - - /** - * Ignore Runtime/Provided/Test/System scopes for unused dependency analysis - * @since 2.2 - */ - @Parameter( property = "ignoreNonCompile", defaultValue = "false" ) - private boolean ignoreNonCompile; - - /** - * Force dependencies as used, to override incomplete result caused by bytecode-level analysis. - * Dependency format is groupId:artifactId. - * - * @since 2.6 - */ - @Parameter - private String[] usedDependencies; - - /** - * Skip plugin execution completely. - * - * @since 2.7 - */ - @Parameter( property = "mdep.analyze.skip", defaultValue = "false" ) - private boolean skip; - - // Mojo methods ----------------------------------------------------------- - - /* - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void executeReport( Locale locale ) - throws MavenReportException - { - if ( isSkip() ) - { - getLog().info( "Skipping plugin execution" ); - return; - } - - // Step 0: Checking pom availability - if ( "pom".equals( project.getPackaging() ) ) - { - getLog().info( "Skipping pom project" ); - return; - } - - if ( outputDirectory == null || !outputDirectory.exists() ) - { - getLog().info( "Skipping project with no Target directory" ); - return; - } - - // Step 1: Analyze the project - ProjectDependencyAnalysis analysis = null; - try - { - analysis = analyzer.analyze( project ); - - if ( usedDependencies != null ) - { - analysis = analysis.forceDeclaredDependenciesUsage( usedDependencies ); - } - } - catch ( ProjectDependencyAnalyzerException exception ) - { - throw new MavenReportException( "Cannot analyze dependencies", exception ); - } - - //remove everything that's not in the compile scope - if ( ignoreNonCompile ) - { - analysis = analysis.ignoreNonCompile(); - } - - // Step 2: Create sink and bundle - Sink sink = getSink(); - ResourceBundle bundle = getBundle( locale ); - - // Step 3: Generate the report - AnalyzeReportView analyzethis = new AnalyzeReportView(); - analyzethis.generateReport( analysis, sink, bundle ); - } - - // MavenReport methods ---------------------------------------------------- - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getOutputName() - */ - public String getOutputName() - { - return "dependency-analysis"; - } - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getName(java.util.Locale) - */ - public String getName( Locale locale ) - { - return getBundle( locale ).getString( "analyze.report.name" ); - } - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getDescription(java.util.Locale) - */ - public String getDescription( Locale locale ) - { - return getBundle( locale ).getString( "analyze.report.description" ); - } - - // AbstractMavenReport methods -------------------------------------------- - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getProject() - */ - protected MavenProject getProject() - { - return project; - } - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() - */ - protected String getOutputDirectory() - { - getLog().info( outputDirectory.toString() ); - - return outputDirectory.toString(); - } - - /* - * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() - */ - protected Renderer getSiteRenderer() - { - return siteRenderer; - } - - // protected methods ------------------------------------------------------ - - /** - * @param locale the current locale - */ - protected ResourceBundle getBundle( Locale locale ) - { - return ResourceBundle.getBundle( "analyze-report", locale, this.getClass().getClassLoader() ); - } - - public boolean isSkip() - { - return skip; -} - - public void setSkip( boolean skip ) - { - this.skip = skip; - } - -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportView.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportView.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportView.java 2012-10-21 08:55:13.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/AnalyzeReportView.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,206 +0,0 @@ -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.Iterator; -import java.util.ResourceBundle; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.doxia.sink.Sink; -import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis; - -/** - * This is the view part of the analyze-report mojo. It generates the HTML report for the project website. The HTML - * output is same as the CLI output. - */ -public class AnalyzeReportView -{ - /** - * Generates the HTML report. - */ - public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, ResourceBundle bundle ) - { - sink.head(); - sink.title(); - sink.text( bundle.getString( "analyze.report.header" ) ); - sink.title_(); - sink.head_(); - sink.body(); - - // Generate title - sink.section1(); - sink.sectionTitle1(); - sink.text( bundle.getString( "analyze.report.mainTitle" ) ); - sink.sectionTitle1_(); - - // Generate Used Declared dependencies: - sink.section2(); - sink.sectionTitle2(); - sink.text( bundle.getString( "analyze.report.UsedDeclaredDependencies" ) ); - sink.sectionTitle2_(); - if ( analysis.getUsedDeclaredArtifacts().isEmpty() ) - { - sink.paragraph(); - sink.text( bundle.getString( "analyze.report.noDependency" ) ); - sink.paragraph_(); - sink.horizontalRule(); - } - else - { - generateDependenciesTable( sink, analysis.getUsedDeclaredArtifacts().iterator() ); - } - sink.section2_(); - - // Generate Used Undeclared dependencies: - sink.section2(); - sink.sectionTitle2(); - sink.text( bundle.getString( "analyze.report.UsedUndeclaredDependencies" ) ); - sink.sectionTitle2_(); - if ( analysis.getUsedUndeclaredArtifacts().isEmpty() ) - { - sink.paragraph(); - sink.text( bundle.getString( "analyze.report.noDependency" ) ); - sink.paragraph_(); - sink.horizontalRule(); - } - else - { - generateDependenciesTable( sink, analysis.getUsedUndeclaredArtifacts().iterator() ); - } - sink.section2_(); - - // Generate Unused declared dependencies: - sink.section2(); - sink.sectionTitle2(); - sink.text( bundle.getString( "analyze.report.UnusedDeclaredDependencies" ) ); - sink.sectionTitle2_(); - if ( analysis.getUnusedDeclaredArtifacts().isEmpty() ) - { - sink.paragraph(); - sink.text( bundle.getString( "analyze.report.noDependency" ) ); - sink.paragraph_(); - sink.horizontalRule(); - } - else - { - generateDependenciesTable( sink, analysis.getUnusedDeclaredArtifacts().iterator() ); - } - sink.section2_(); - - sink.section1_(); - - // Closing the report - sink.body_(); - sink.flush(); - sink.close(); - } - - /** - * Generate a table for the given dependencies iterator. - */ - public void generateDependenciesTable( Sink sink, Iterator iter ) - { - sink.table(); - - sink.tableRow(); - sink.tableCell(); - sink.bold(); - sink.text( "GroupId" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "ArtifactId" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "Version" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "Scope" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "Classifier" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "Type" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableCell(); - sink.bold(); - sink.text( "Optional" ); - sink.bold_(); - sink.tableCell_(); - - sink.tableRow_(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - - sink.tableRow(); - sink.tableCell(); - sink.text( artifact.getGroupId() ); - sink.tableCell_(); - sink.tableCell(); - sink.text( artifact.getArtifactId() ); - sink.tableCell_(); - sink.tableCell(); - sink.text( artifact.getVersion() ); - sink.tableCell_(); - sink.tableCell(); - sink.text( artifact.getScope() ); - sink.tableCell_(); - sink.tableCell(); - sink.text( artifact.getClassifier() ); - sink.tableCell_(); - sink.tableCell(); - sink.text( artifact.getType() ); - sink.tableCell_(); - sink.tableCell(); - if ( artifact.isOptional() ) - { - sink.text( "" ); - } - else - { - sink.text( "false" ); - } - - sink.tableCell_(); - sink.tableRow_(); - } - - sink.table_(); - sink.horizontalRule(); - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/BuildClasspathMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,571 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProjectHelper; -import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * This goal will output a classpath string of dependencies from the local repository to a file or log. - * - * @author ankostis - * @version $Id: BuildClasspathMojo.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 2.0-alpha-2 - */ -@Mojo( name = "build-classpath", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) -public class BuildClasspathMojo - extends AbstractDependencyFilterMojo - implements Comparator -{ - - /** - * Strip artifact version during copy (only works if prefix is set) - */ - @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) - private boolean stripVersion = false; - - /** - * The prefix to prepend on each dependent artifact. If undefined, the paths refer to the actual files store in the - * local repository (the stripVersion parameter does nothing then). - */ - @Parameter( property = "mdep.prefix" ) - private String prefix; - - /** - * The file to write the classpath string. If undefined, it just prints the classpath as [INFO]. - * This parameter is deprecated. Use outputFile instead. - * - * @since 2.0 - * @deprecated use outputFile instead - */ - @Parameter( property = "mdep.cpFile" ) - private File cpFile; - - /** - * A property to set to the content of the classpath string. - */ - @Parameter( property = "mdep.outputProperty" ) - private String outputProperty; - - /** - * The file to write the classpath string. If undefined, it just prints the classpath as [INFO]. - */ - @Parameter( property = "mdep.outputFile" ) - private File outputFile; - - /** - * If 'true', it skips the up-to-date-check, and always regenerates the classpath file. - */ - @Parameter( property = "mdep.regenerateFile", defaultValue = "false" ) - private boolean regenerateFile; - - /** - * Override the char used between the paths. This field is initialized to contain the first character of the value - * of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows - * systems it is '\'. The default is File.separator - * - * @since 2.0 - */ - @Parameter( property = "mdep.fileSeparator", defaultValue = "" ) - private String fileSeparator; - - /** - * Override the char used between path folders. The system-dependent path-separator character. This field is - * initialized to contain the first character of the value of the system property path.separator. This character is - * used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; - * on Microsoft Windows systems it is ';'. - * - * @since 2.0 - */ - @Parameter( property = "mdep.pathSeparator", defaultValue = "" ) - private String pathSeparator; - - /** - * Replace the absolute path to the local repo with this property. This field is ignored it prefix is declared. The - * value will be forced to "${M2_REPO}" if no value is provided AND the attach flag is true. - * - * @since 2.0 - */ - @Parameter( property = "mdep.localRepoProperty", defaultValue = "" ) - private String localRepoProperty; - - /** - * Attach the classpath file to the main artifact so it can be installed and deployed. - * - * @since 2.0 - */ - @Parameter( defaultValue = "false" ) - boolean attach; - - /** - * Write out the classpath in a format compatible with filtering (classpath=xxxxx) - * - * @since 2.0 - */ - @Parameter( property = "mdep.outputFilterFile", defaultValue = "false" ) - boolean outputFilterFile; - - /** - * Either append the artifact's baseVersion or uniqueVersion to the filename. - * Will only be used if {@link #isStripVersion()} is {@code false}. - * @since 2.6 - */ - @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" ) - protected boolean useBaseVersion = true; - - /** - * Maven ProjectHelper - */ - @Component - private MavenProjectHelper projectHelper; - - boolean isFileSepSet = true; - - boolean isPathSepSet = true; - - /** - * Main entry into mojo. Gets the list of dependencies and iterates through calling copyArtifact. - * - * @throws MojoExecutionException with a message if an error occurs. - * @see #getDependencies - * @see #copyArtifact(Artifact, boolean) - */ - protected void doExecute() - throws MojoExecutionException - { - - if ( cpFile != null ) - { - getLog().warn( "The parameter cpFile is deprecated. Use outputFile instead." ); - this.outputFile = cpFile; - } - - // initialize the separators. - isFileSepSet = StringUtils.isNotEmpty( fileSeparator ); - isPathSepSet = StringUtils.isNotEmpty( pathSeparator ); - - //don't allow them to have absolute paths when they attach. - if ( attach && StringUtils.isEmpty( localRepoProperty ) ) - { - localRepoProperty = "${M2_REPO}"; - } - - Set artifacts = getResolvedDependencies( true ); - - if ( artifacts == null || artifacts.isEmpty() ) - { - getLog().info( "No dependencies found." ); - } - - List artList = new ArrayList( artifacts ); - - StringBuilder sb = new StringBuilder(); - Iterator i = artList.iterator(); - - if ( i.hasNext() ) - { - appendArtifactPath( i.next(), sb ); - - while ( i.hasNext() ) - { - sb.append( isPathSepSet ? this.pathSeparator : File.pathSeparator ); - appendArtifactPath( (Artifact) i.next(), sb ); - } - } - - String cpString = sb.toString(); - - // if file separator is set, I need to replace the default one from all - // the file paths that were pulled from the artifacts - if ( isFileSepSet ) - { - // Escape file separators to be used as literal strings - final String pattern = Pattern.quote( File.separator ); - final String replacement = Matcher.quoteReplacement( fileSeparator ); - cpString = cpString.replaceAll( pattern, replacement ); - } - - //make the string valid for filtering - if ( outputFilterFile ) - { - cpString = "classpath=" + cpString; - } - - if ( outputProperty != null ) - { - project.getProperties().setProperty( outputProperty, cpString ); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( outputProperty + " = " + cpString ); - } - } - else if ( outputFile == null ) - { - getLog().info( "Dependencies classpath:\n" + cpString ); - } - else - { - if ( regenerateFile || !isUpdToDate( cpString ) ) - { - storeClasspathFile( cpString, outputFile ); - } - else - { - this.getLog().info( "Skipped writing classpath file '" + outputFile + "'. No changes found." ); - } - } - if ( attach ) - { - attachFile( cpString ); - } - } - - protected void attachFile( String cpString ) - throws MojoExecutionException - { - File attachedFile = new File( project.getBuild().getDirectory(), "classpath" ); - storeClasspathFile( cpString, attachedFile ); - - projectHelper.attachArtifact( project, attachedFile, "classpath" ); - } - - /** - * Appends the artifact path into the specified StringBuilder. - * - * @param art - * @param sb - */ - protected void appendArtifactPath( Artifact art, StringBuilder sb ) - { - if ( prefix == null ) - { - String file = art.getFile().getPath(); - // substitute the property for the local repo path to make the classpath file portable. - if ( StringUtils.isNotEmpty( localRepoProperty ) ) - { - file = StringUtils.replace( file, getLocal().getBasedir(), localRepoProperty ); - } - sb.append( file ); - } - else - { - // TODO: add param for prepending groupId and version. - sb.append( prefix ); - sb.append( File.separator ); - sb.append( DependencyUtil.getFormattedFileName( art, this.stripVersion, this.prependGroupId, this.useBaseVersion ) ); - } - } - - /** - * Checks that new classpath differs from that found inside the old classpathFile. - * - * @param cpString - * @return true if the specified classpath equals to that found inside the file, false otherwise (including when - * file does not exists but new classpath does). - */ - private boolean isUpdToDate( String cpString ) - { - try - { - String oldCp = readClasspathFile(); - return ( cpString == oldCp || ( cpString != null && cpString.equals( oldCp ) ) ); - } - catch ( Exception ex ) - { - this.getLog().warn( - "Error while reading old classpath file '" + outputFile + "' for up-to-date check: " + ex ); - - return false; - } - } - - /** - * It stores the specified string into that file. - * - * @param cpString the string to be written into the file. - * @throws MojoExecutionException - */ - private void storeClasspathFile( String cpString, File out ) - throws MojoExecutionException - { - //make sure the parent path exists. - out.getParentFile().mkdirs(); - - Writer w = null; - try - { - w = new BufferedWriter( new FileWriter( out ) ); - w.write( cpString ); - getLog().info( "Wrote classpath file '" + out + "'." ); - } - catch ( IOException ex ) - { - throw new MojoExecutionException( "Error while writting to classpath file '" + out + "': " + ex.toString(), - ex ); - } - finally - { - IOUtil.close( w ); - } - } - - /** - * Reads into a string the file specified by the mojo param 'outputFile'. Assumes, the instance variable - * 'outputFile' is not null. - * - * @return the string contained in the classpathFile, if exists, or null otherwise. - * @throws MojoExecutionException - */ - protected String readClasspathFile() - throws IOException - { - if ( outputFile == null ) - { - throw new IllegalArgumentException( - "The outputFile parameter cannot be null if the file is intended to be read." ); - } - - if ( !outputFile.isFile() ) - { - return null; - } - StringBuilder sb = new StringBuilder(); - BufferedReader r = null; - - try - { - r = new BufferedReader( new FileReader( outputFile ) ); - String l; - while ( ( l = r.readLine() ) != null ) - { - sb.append( l ); - } - - return sb.toString(); - } - finally - { - IOUtil.close( r ); - } - } - - /** - * Compares artifacts lexicographically, using pattern [group_id][artifact_id][version]. - * - * @param art1 first object - * @param art2 second object - * @return the value 0 if the argument string is equal to this string; a value less than - * 0 if this string is lexicographically less than the string argument; and a value greater - * than 0 if this string is lexicographically greater than the string argument. - */ - public int compare( Artifact art1, Artifact art2 ) - { - if ( art1 == art2 ) - { - return 0; - } - else if ( art1 == null ) - { - return -1; - } - else if ( art2 == null ) - { - return +1; - } - - String s1 = art1.getGroupId() + art1.getArtifactId() + art1.getVersion(); - String s2 = art2.getGroupId() + art2.getArtifactId() + art2.getVersion(); - - return s1.compareTo( s2 ); - } - - protected ArtifactsFilter getMarkedArtifactFilter() - { - return null; - } - - /** - * @return the outputFile - */ - public File getCpFile() - { - return this.outputFile; - } - - /** - * @param theCpFile the outputFile to set - */ - public void setCpFile( File theCpFile ) - { - this.outputFile = theCpFile; - } - - /** - * @return the outputProperty - */ - public String getOutputProperty() - { - return this.outputProperty; - } - - /** - * @param theOutputProperty the outputProperty to set - */ - public void setOutputProperty( String theOutputProperty ) - { - this.outputProperty = theOutputProperty; - } - - /** - * @return the fileSeparator - */ - public String getFileSeparator() - { - return this.fileSeparator; - } - - /** - * @param theFileSeparator the fileSeparator to set - */ - public void setFileSeparator( String theFileSeparator ) - { - this.fileSeparator = theFileSeparator; - } - - /** - * @return the pathSeparator - */ - public String getPathSeparator() - { - return this.pathSeparator; - } - - /** - * @param thePathSeparator the pathSeparator to set - */ - public void setPathSeparator( String thePathSeparator ) - { - this.pathSeparator = thePathSeparator; - } - - /** - * @return the prefix - */ - public String getPrefix() - { - return this.prefix; - } - - /** - * @param thePrefix the prefix to set - */ - public void setPrefix( String thePrefix ) - { - this.prefix = thePrefix; - } - - /** - * @return the regenerateFile - */ - public boolean isRegenerateFile() - { - return this.regenerateFile; - } - - /** - * @param theRegenerateFile the regenerateFile to set - */ - public void setRegenerateFile( boolean theRegenerateFile ) - { - this.regenerateFile = theRegenerateFile; - } - - /** - * @return the stripVersion - */ - public boolean isStripVersion() - { - return this.stripVersion; - } - - /** - * @param theStripVersion the stripVersion to set - */ - public void setStripVersion( boolean theStripVersion ) - { - this.stripVersion = theStripVersion; - } - - public String getLocalRepoProperty() - { - return localRepoProperty; - } - - public void setLocalRepoProperty( String localRepoProperty ) - { - this.localRepoProperty = localRepoProperty; - } - - public boolean isFileSepSet() - { - return isFileSepSet; - } - - public void setFileSepSet( boolean isFileSepSet ) - { - this.isFileSepSet = isFileSepSet; - } - - public boolean isPathSepSet() - { - return isPathSepSet; - } - - public void setPathSepSet( boolean isPathSepSet ) - { - this.isPathSepSet = isPathSepSet; - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,260 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.installer.ArtifactInstallationException; -import org.apache.maven.artifact.installer.ArtifactInstaller; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.filters.DestFileFilter; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.Map; -import java.util.Set; - -/** - * Goal that copies the project dependencies from the repository to a defined - * location. - * - * @author Brian Fox - * @version $Id: CopyDependenciesMojo.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 1.0 - */ -@Mojo( name = "copy-dependencies", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true ) -public class CopyDependenciesMojo - extends AbstractFromDependenciesMojo -{ - /** - * - */ - @Component - protected ArtifactInstaller installer; - - /** - * - */ - @Component - protected ArtifactRepositoryFactory repositoryFactory; - - /** - * - */ - @Component( role = ArtifactRepositoryLayout.class ) - private Map repositoryLayouts; - - - /** - * Either append the artifact's baseVersion or uniqueVersion to the filename. - * Will only be used if {@link #isStripVersion()} is {@code false}. - * @since 2.6 - */ - @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" ) - protected boolean useBaseVersion = true; - - /** - * Main entry into mojo. Gets the list of dependencies and iterates through - * calling copyArtifact. - * - * @throws MojoExecutionException with a message if an error occurs. - * @see #getDependencies - * @see #copyArtifact(Artifact, boolean) - */ - protected void doExecute() - throws MojoExecutionException - { - DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact ); - Set artifacts = dss.getResolvedDependencies(); - - if ( !useRepositoryLayout ) - { - for ( Artifact artifact : artifacts ) - { - copyArtifact( artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion ); - } - } - else - { - try - { - ArtifactRepository targetRepository = - repositoryFactory.createDeploymentArtifactRepository( "local", - outputDirectory.toURL().toExternalForm(), - repositoryLayouts.get( "default" ), - false /* uniqueVersion */); - for ( Artifact artifact : artifacts ) - { - installArtifact( artifact, targetRepository ); - } - } - catch ( MalformedURLException e ) - { - throw new MojoExecutionException( "Could not create outputDirectory repository", e ); - } - } - - Set skippedArtifacts = dss.getSkippedDependencies(); - for ( Artifact artifact : skippedArtifacts ) - { - getLog().info( artifact.getFile().getName() + " already exists in destination." ); - } - - if ( isCopyPom() ) - { - copyPoms( getOutputDirectory(), artifacts, this.stripVersion ); - copyPoms( getOutputDirectory(), skippedArtifacts, - this.stripVersion ); // Artifacts that already exist may not already have poms. - } - } - - private void installArtifact( Artifact artifact, ArtifactRepository targetRepository ) - { - try - { - if ( "pom".equals( artifact.getType() ) ) - { - installer.install( artifact.getFile(), artifact, targetRepository ); - installBaseSnapshot( artifact, targetRepository ); - } - else - { - installer.install( artifact.getFile(), artifact, targetRepository ); - installBaseSnapshot( artifact, targetRepository ); - - if ( isCopyPom() ) - { - Artifact pomArtifact = getResolvedPomArtifact( artifact ); - if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() ) - { - installer.install( pomArtifact.getFile(), pomArtifact, targetRepository ); - installBaseSnapshot( pomArtifact, targetRepository ); - } - } - } - } - catch ( ArtifactInstallationException e ) - { - getLog().info( e.getMessage() ); - } - } - - private void installBaseSnapshot( Artifact artifact, ArtifactRepository targetRepository ) - throws ArtifactInstallationException - { - if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion() ) ) - { - Artifact baseArtifact = - this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), - artifact.getScope(), artifact.getType() ); - installer.install( artifact.getFile(), baseArtifact, targetRepository ); - } - } - - /** - * Copies the Artifact after building the destination file name if - * overridden. This method also checks if the classifier is set and adds it - * to the destination file name if needed. - * - * @param artifact representing the object to be copied. - * @param removeVersion specifies if the version should be removed from the file name - * when copying. - * @param prependGroupId specifies if the groupId should be prepend to the file while copying. - * @param useBaseVersion specifies if the baseVersion of the artifact should be used instead of the version. - * @throws MojoExecutionException with a message if an error occurs. - * @see DependencyUtil#copyFile(File, File, Log) - * @see DependencyUtil#getFormattedFileName(Artifact, boolean) - */ - protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId, - boolean useBaseVersion ) throws MojoExecutionException - { - - String destFileName = DependencyUtil.getFormattedFileName( artifact, removeVersion, prependGroupId, - useBaseVersion ); - - File destDir; - destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, - useSubDirectoryPerArtifact, useRepositoryLayout, - stripVersion, outputDirectory, artifact ); - File destFile = new File( destDir, destFileName ); - - copyFile( artifact.getFile(), destFile ); - } - - /** - * Copy the pom files associated with the artifacts. - */ - public void copyPoms( File destDir, Set artifacts, boolean removeVersion ) - throws MojoExecutionException - - { - for ( Artifact artifact : artifacts ) - { - Artifact pomArtifact = getResolvedPomArtifact( artifact ); - - // Copy the pom - if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() ) - { - File pomDestFile = new File( destDir, DependencyUtil.getFormattedFileName( pomArtifact, removeVersion, - prependGroupId, useBaseVersion ) ); - if ( !pomDestFile.exists() ) - { - copyFile( pomArtifact.getFile(), pomDestFile ); - } - } - } - } - - protected Artifact getResolvedPomArtifact( Artifact artifact ) - { - Artifact pomArtifact = - this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", - "pom" ); - // Resolve the pom artifact using repos - try - { - this.resolver.resolve( pomArtifact, this.remoteRepos, this.getLocal() ); - } - catch ( Exception e ) - { - getLog().info( e.getMessage() ); - } - return pomArtifact; - } - - protected ArtifactsFilter getMarkedArtifactFilter() - { - return new DestFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer, - this.useSubDirectoryPerArtifact, this.useSubDirectoryPerType, - this.useSubDirectoryPerScope, this.useRepositoryLayout, this.stripVersion, - this.outputDirectory ); - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java 2013-05-12 13:39:04.000000000 +0000 @@ -20,7 +20,6 @@ */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; @@ -49,14 +48,14 @@ * ArtifactItems * * @author Brian Fox - * @version $Id: AbstractFromConfigurationMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: AbstractFromConfigurationMojo.java 1481555 2013-05-12 13:39:04Z hboutemy $ * @see ArtifactItem */ public abstract class AbstractFromConfigurationMojo extends AbstractDependencyMojo { /** - * Default location used for mojo unless overridden in ArtifactItem + * Default output location used for mojo, unless overridden in ArtifactItem. * * @since 1.0 */ @@ -88,12 +87,6 @@ private boolean overWriteIfNewer; /** - * To search for artifacts within the reactor and ensure consistent behaviour between Maven 2 and Maven 3. - */ - @Parameter( defaultValue = "${reactorProjects}", readonly = true, required = true ) - protected List reactorProjects; - - /** * Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier, * outputDirectory, destFileName and overWrite.) See Usage for details. * @@ -122,9 +115,6 @@ */ private ArtifactRepository overrideLocalRepository; - @Component - private ArtifactFactory artifactFactory; - abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ); // artifactItems is filled by either field injection or by setArtifact() @@ -154,6 +144,8 @@ boolean removeVersion = processArtifactItemsRequest.isRemoveVersion(), prependGroupId = processArtifactItemsRequest.isPrependGroupId(), useBaseVersion = processArtifactItemsRequest.isUseBaseVersion(); + + boolean removeClassifier = processArtifactItemsRequest.isRemoveClassifier(); if ( artifactItems == null || artifactItems.size() < 1 ) { @@ -180,8 +172,9 @@ if ( StringUtils.isEmpty( artifactItem.getDestFileName() ) ) { - artifactItem.setDestFileName( - DependencyUtil.getFormattedFileName( artifactItem.getArtifact(), removeVersion, prependGroupId, useBaseVersion ) ); + artifactItem.setDestFileName( DependencyUtil.getFormattedFileName( artifactItem.getArtifact(), + removeVersion, prependGroupId, + useBaseVersion, removeClassifier ) ); } try @@ -559,8 +552,8 @@ } Artifact toUnpack = classifier == null - ? artifactFactory.createBuildArtifact( groupId, artifactId, version, packaging ) - : artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier ); + ? factory.createBuildArtifact( groupId, artifactId, version, packaging ) + : factory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier ); setArtifactItems( Collections.singletonList( new ArtifactItem( toUnpack ) ) ); } diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java 2013-02-12 21:55:34.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java 2013-05-12 09:40:09.000000000 +0000 @@ -31,7 +31,7 @@ * * @since 1.0 * @author Brian Fox - * @version $Id: ArtifactItem.java 1445407 2013-02-12 21:55:34Z olamy $ + * @version $Id: ArtifactItem.java 1481501 2013-05-12 09:40:09Z hboutemy $ */ public class ArtifactItem { @@ -349,7 +349,7 @@ /** * @return Returns a comma separated list of excluded items */ - public String getExcludes () + public String getExcludes() { return DependencyUtil.cleanToBeTokenizedString( this.excludes ); } @@ -373,7 +373,7 @@ /** * @param includes A comma separated list of items to include i.e. **\/*.xml, **\/*.properties */ - public void setIncludes ( String includes ) + public void setIncludes( String includes ) { this.includes = includes; } diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java 2013-05-14 22:12:46.000000000 +0000 @@ -34,7 +34,7 @@ * Goal that copies a list of artifacts from the repository to defined locations. * * @author Brian Fox - * @version $Id: CopyMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: CopyMojo.java 1482623 2013-05-14 22:12:46Z hboutemy $ * @since 1.0 */ @Mojo( name = "copy", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true ) @@ -49,6 +49,12 @@ private boolean stripVersion = false; /** + * Strip artifact classifier during copy + */ + @Parameter( property = "mdep.stripClassifier", defaultValue = "false" ) + private boolean stripClassifier = false; + + /** * Prepend artifact groupId during copy * @since 2.7 */ @@ -71,6 +77,18 @@ private String artifact; /** + * not used in this goal + */ + @Parameter + protected boolean useJvmChmod = true; + + /** + * not used in this goal + */ + @Parameter + protected boolean ignorePermissions; + + /** * Main entry into mojo. This method gets the ArtifactItems and iterates through each one passing it to * copyArtifact. * @@ -85,7 +103,7 @@ verifyRequirements(); List theArtifactItems = getProcessedArtifactItems( - new ProcessArtifactItemsRequest( this.stripVersion, this.prependGroupId, this.useBaseVersion ) ); + new ProcessArtifactItemsRequest( this.stripVersion, this.prependGroupId, this.useBaseVersion, this.stripClassifier ) ); for ( ArtifactItem artifactItem : theArtifactItems ) { if ( artifactItem.isNeedsProcessing() ) @@ -138,6 +156,22 @@ { this.stripVersion = stripVersion; } + + /** + * @return Returns the stripClassifier. + */ + public boolean isStripClassifier() + { + return this.stripClassifier; + } + + /** + * @param stripClassifier The stripClassifier to set. + */ + public void setStripClassifier( boolean stripClassifier ) + { + this.stripClassifier = stripClassifier; + } /** * @param useBaseVersion The useBaseVersion to set. diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ProcessArtifactItemsRequest.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ProcessArtifactItemsRequest.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ProcessArtifactItemsRequest.java 2013-02-12 21:56:38.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ProcessArtifactItemsRequest.java 2013-05-12 14:03:49.000000000 +0000 @@ -1,4 +1,5 @@ package org.apache.maven.plugin.dependency.fromConfiguration; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -29,6 +30,11 @@ */ private boolean removeVersion; + /** + * remove the classifier from the filename. + */ + private boolean removeClassifier; + /** * prepend the groupId to the filename. */ @@ -44,11 +50,12 @@ // no op } - public ProcessArtifactItemsRequest( boolean removeVersion, boolean prependGroupId, boolean useBaseVersion ) + public ProcessArtifactItemsRequest( boolean removeVersion, boolean prependGroupId, boolean useBaseVersion, boolean removeClassifier ) { this.removeVersion = removeVersion; this.prependGroupId = prependGroupId; this.useBaseVersion = useBaseVersion; + this.removeClassifier = removeClassifier; } public boolean isRemoveVersion() @@ -61,6 +68,17 @@ this.removeVersion = removeVersion; } + public boolean isRemoveClassifier() + { + return removeClassifier; + } + + public void setRemoveClassifier( boolean removeClassifier ) + { + this.removeClassifier = removeClassifier; + } + + public ProcessArtifactItemsRequest removeVersion( boolean removeVersion ) { this.removeVersion = removeVersion; diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java 2013-05-12 14:03:49.000000000 +0000 @@ -37,11 +37,11 @@ * Goal that retrieves a list of artifacts from the repository and unpacks them in a defined location. * * @author Brian Fox - * @version $Id: UnpackMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: UnpackMojo.java 1481560 2013-05-12 14:03:49Z hboutemy $ * @since 1.0 */ @Mojo( name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true ) -public final class UnpackMojo +public class UnpackMojo extends AbstractFromConfigurationMojo { @@ -142,7 +142,7 @@ throws MojoExecutionException { List items = - super.getProcessedArtifactItems( new ProcessArtifactItemsRequest( removeVersion, false, false ) ); + super.getProcessedArtifactItems( new ProcessArtifactItemsRequest( removeVersion, false, false, false ) ); for ( ArtifactItem artifactItem : items ) { if ( StringUtils.isEmpty( artifactItem.getIncludes() ) ) diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractDependencyFilterMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractDependencyFilterMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractDependencyFilterMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractDependencyFilterMojo.java 2013-05-13 21:27:02.000000000 +0000 @@ -0,0 +1,487 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojo; +import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.resolvers.ArtifactsResolver; +import org.apache.maven.plugin.dependency.utils.resolvers.DefaultArtifactsResolver; +import org.apache.maven.plugin.dependency.utils.translators.ArtifactTranslator; +import org.apache.maven.plugin.dependency.utils.translators.ClassifierTypeTranslator; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; +import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; +import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; +import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter; +import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; +import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; +import org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; +import org.apache.maven.shared.artifact.filter.collection.TypeFilter; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +/** + * Class that encapsulates the plugin parameters, and contains methods that + * handle dependency filtering + * + * @author Brian Fox + * @version $Id: AbstractDependencyFilterMojo.java 1482112 2013-05-13 21:27:02Z hboutemy $ + * @see org.apache.maven.plugin.dependency.AbstractDependencyMojo + */ +public abstract class AbstractDependencyFilterMojo + extends AbstractDependencyMojo +{ + /** + * Overwrite release artifacts + * + * @since 1.0 + */ + @Parameter( property = "overWriteReleases", defaultValue = "false" ) + protected boolean overWriteReleases; + + /** + * Overwrite snapshot artifacts + * + * @since 1.0 + */ + @Parameter( property = "overWriteSnapshots", defaultValue = "false" ) + protected boolean overWriteSnapshots; + + /** + * Overwrite artifacts that don't exist or are older than the source. + * + * @since 2.0 + */ + @Parameter( property = "overWriteIfNewer", defaultValue = "true" ) + protected boolean overWriteIfNewer; + + /** + * If we should exclude transitive dependencies + * + * @since 2.0 + */ + @Parameter( property = "excludeTransitive", defaultValue = "false" ) + protected boolean excludeTransitive; + + /** + * Comma Separated list of Types to include. Empty String indicates include + * everything (default). + * + * @since 2.0 + */ + @Parameter( property = "includeTypes", defaultValue = "" ) + protected String includeTypes; + + /** + * Comma Separated list of Types to exclude. Empty String indicates don't + * exclude anything (default). + * + * @since 2.0 + */ + @Parameter( property = "excludeTypes", defaultValue = "" ) + protected String excludeTypes; + + /** + * Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as + * Maven sees them, not as specified in the pom. In summary: + *
    + *
  • runtime scope gives runtime and compile dependencies,
  • + *
  • compile scope gives compile, provided, and system dependencies,
  • + *
  • test (default) scope gives all dependencies,
  • + *
  • provided scope just gives provided dependencies,
  • + *
  • system scope just gives system dependencies.
  • + *
+ * + * @since 2.0 + */ + @Parameter( property = "includeScope", defaultValue = "" ) + protected String includeScope; + + /** + * Scope to exclude. An Empty string indicates no scopes (default). + * + * @since 2.0 + */ + @Parameter( property = "excludeScope", defaultValue = "" ) + protected String excludeScope; + + /** + * Comma Separated list of Classifiers to include. Empty String indicates + * include everything (default). + * + * @since 2.0 + */ + @Parameter( property = "includeClassifiers", defaultValue = "" ) + protected String includeClassifiers; + + /** + * Comma Separated list of Classifiers to exclude. Empty String indicates + * don't exclude anything (default). + * + * @since 2.0 + */ + @Parameter( property = "excludeClassifiers", defaultValue = "" ) + protected String excludeClassifiers; + + /** + * Specify classifier to look for. Example: sources + * + * @since 2.0 + */ + @Parameter( property = "classifier", defaultValue = "" ) + protected String classifier; + + /** + * Specify type to look for when constructing artifact based on classifier. + * Example: java-source,jar,war + * + * @since 2.0 + */ + @Parameter( property = "type", defaultValue = "" ) + protected String type; + + /** + * Comma separated list of Artifact names to exclude. + * + * @since 2.0 + */ + @Parameter( property = "excludeArtifactIds", defaultValue = "" ) + protected String excludeArtifactIds; + + /** + * Comma separated list of Artifact names to include. + * + * @since 2.0 + */ + @Parameter( property = "includeArtifactIds", defaultValue = "" ) + protected String includeArtifactIds; + + /** + * Comma separated list of GroupId Names to exclude. + * + * @since 2.0 + */ + @Parameter( property = "excludeGroupIds", defaultValue = "" ) + protected String excludeGroupIds; + + /** + * Comma separated list of GroupIds to include. + * + * @since 2.0 + */ + @Parameter( property = "includeGroupIds", defaultValue = "" ) + protected String includeGroupIds; + + /** + * Directory to store flag files + * + * @since 2.0 + */ + @Parameter( property = "markersDirectory", + defaultValue = "${project.build.directory}/dependency-maven-plugin-markers" ) + protected File markersDirectory; + + /** + * Prepend the groupId during copy. + * + * @since 2.2 + */ + @Parameter( property = "mdep.prependGroupId", defaultValue = "false" ) + protected boolean prependGroupId = false; + + @Component + MavenProjectBuilder projectBuilder; + + /** + * Return an {@link ArtifactsFilter} indicating which artifacts must be filtered out. + * + * @return an {@link ArtifactsFilter} indicating which artifacts must be filtered out. + */ + protected abstract ArtifactsFilter getMarkedArtifactFilter(); + + /** + * Retrieves dependencies, either direct only or all including transitive. + * + * @return A HashSet of artifacts + * @throws MojoExecutionException + */ + protected Set getResolvedDependencies( boolean stopOnFailure ) + throws MojoExecutionException + + { + DependencyStatusSets status = getDependencySets( stopOnFailure ); + + return status.getResolvedDependencies(); + } + + protected DependencyStatusSets getDependencySets( boolean stopOnFailure ) + throws MojoExecutionException + { + return getDependencySets( stopOnFailure, false ); + } + + /** + * Method creates filters and filters the projects dependencies. This method + * also transforms the dependencies if classifier is set. The dependencies + * are filtered in least specific to most specific order + * + * @param stopOnFailure + * @return DependencyStatusSets - Bean of TreeSets that contains information + * on the projects dependencies + * @throws MojoExecutionException + */ + protected DependencyStatusSets getDependencySets( boolean stopOnFailure, boolean includeParents ) + throws MojoExecutionException + { + // add filters in well known order, least specific to most specific + FilterArtifacts filter = new FilterArtifacts(); + + filter.addFilter( new ProjectTransitivityFilter( project.getDependencyArtifacts(), this.excludeTransitive ) ); + + filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ), + DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) ); + + filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ), + DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) ); + + filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ), + DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) ); + + filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ), + DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) ); + + filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ), + DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) ); + + // start with all artifacts. + @SuppressWarnings( "unchecked" ) Set artifacts = project.getArtifacts(); + + if ( includeParents ) + { + // add dependencies parents + for ( Artifact dep : new ArrayList( artifacts ) ) + { + addParentArtifacts( buildProjectFromArtifact( dep ), artifacts ); + } + + // add current project parent + addParentArtifacts( project, artifacts ); + } + + // perform filtering + try + { + artifacts = filter.filter( artifacts ); + } + catch ( ArtifactFilterException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + // transform artifacts if classifier is set + DependencyStatusSets status = null; + if ( StringUtils.isNotEmpty( classifier ) ) + { + status = getClassifierTranslatedDependencies( artifacts, stopOnFailure ); + } + else + { + status = filterMarkedDependencies( artifacts ); + } + + return status; + } + + private MavenProject buildProjectFromArtifact( Artifact artifact ) + throws MojoExecutionException + { + try + { + return projectBuilder.buildFromRepository( artifact, remoteRepos, getLocal() ); + } + catch ( ProjectBuildingException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + + private void addParentArtifacts( MavenProject project, Set artifacts ) + throws MojoExecutionException + { + while ( project.hasParent() ) + { + project = project.getParent(); + + if ( project.getArtifact() == null ) + { + // Maven 2.x bug + Artifact artifact = + factory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), + project.getPackaging() ); + project.setArtifact( artifact ); + } + + if ( !artifacts.add( project.getArtifact() ) ) + { + // artifact already in the set + break; + } + try + { + resolver.resolve( project.getArtifact(), this.remoteRepos, this.getLocal() ); + } + catch ( ArtifactResolutionException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( ArtifactNotFoundException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + } + /** + * Transform artifacts + * + * @param artifacts + * @param stopOnFailure + * @return DependencyStatusSets - Bean of TreeSets that contains information + * on the projects dependencies + * @throws MojoExecutionException + */ + protected DependencyStatusSets getClassifierTranslatedDependencies( Set artifacts, boolean stopOnFailure ) + throws MojoExecutionException + { + Set unResolvedArtifacts = new HashSet(); + Set resolvedArtifacts = artifacts; + DependencyStatusSets status = new DependencyStatusSets(); + + // possibly translate artifacts into a new set of artifacts based on the + // classifier and type + // if this did something, we need to resolve the new artifacts + if ( StringUtils.isNotEmpty( classifier ) ) + { + ArtifactTranslator translator = new ClassifierTypeTranslator( this.classifier, this.type, this.factory ); + artifacts = translator.translate( artifacts, getLog() ); + + status = filterMarkedDependencies( artifacts ); + + // the unskipped artifacts are in the resolved set. + artifacts = status.getResolvedDependencies(); + + // resolve the rest of the artifacts + ArtifactsResolver artifactsResolver = + new DefaultArtifactsResolver( this.resolver, this.getLocal(), this.remoteRepos, stopOnFailure ); + resolvedArtifacts = artifactsResolver.resolve( artifacts, getLog() ); + + // calculate the artifacts not resolved. + unResolvedArtifacts.addAll( artifacts ); + unResolvedArtifacts.removeAll( resolvedArtifacts ); + } + + // return a bean of all 3 sets. + status.setResolvedDependencies( resolvedArtifacts ); + status.setUnResolvedDependencies( unResolvedArtifacts ); + + return status; + } + + /** + * Filter the marked dependencies + * + * @param artifacts + * @return + * @throws MojoExecutionException + */ + protected DependencyStatusSets filterMarkedDependencies( Set artifacts ) + throws MojoExecutionException + { + // remove files that have markers already + FilterArtifacts filter = new FilterArtifacts(); + filter.clearFilters(); + filter.addFilter( getMarkedArtifactFilter() ); + + Set unMarkedArtifacts; + try + { + unMarkedArtifacts = filter.filter( artifacts ); + } + catch ( ArtifactFilterException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + + // calculate the skipped artifacts + Set skippedArtifacts = new HashSet(); + skippedArtifacts.addAll( artifacts ); + skippedArtifacts.removeAll( unMarkedArtifacts ); + + return new DependencyStatusSets( unMarkedArtifacts, null, skippedArtifacts ); + } + + /** + * @return Returns the markersDirectory. + */ + public File getMarkersDirectory() + { + return this.markersDirectory; + } + + /** + * @param theMarkersDirectory The markersDirectory to set. + */ + public void setMarkersDirectory( File theMarkersDirectory ) + { + this.markersDirectory = theMarkersDirectory; + } + + // TODO: Set marker files. + + /** + * @return true, if the groupId should be prepended to the filename. + */ + public boolean isPrependGroupId() + { + return prependGroupId; + } + + /** + * @param prependGroupId - + * true if the groupId must be prepended during the copy. + */ + public void setPrependGroupId( boolean prependGroupId ) + { + this.prependGroupId = prependGroupId; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractFromDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractFromDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractFromDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/AbstractFromDependenciesMojo.java 2013-05-12 09:40:09.000000000 +0000 @@ -0,0 +1,200 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +/** + * Abstract Parent class used by mojos that get Artifact information from the + * project dependencies. + * + * @author Brian Fox + * @version $Id: AbstractFromDependenciesMojo.java 1481501 2013-05-12 09:40:09Z hboutemy $ + */ +public abstract class AbstractFromDependenciesMojo + extends AbstractDependencyFilterMojo +{ + /** + * Output location. + * + * @since 1.0 + */ + @Parameter( property = "outputDirectory", defaultValue = "${project.build.directory}/dependency" ) + protected File outputDirectory; + + /** + * Strip artifact version during copy + */ + @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) + protected boolean stripVersion = false; + + /** + * Strip artifact classifier during copy + */ + @Parameter( property = "mdep.stripClassifier", defaultValue = "false" ) + protected boolean stripClassifier = false; + + /** + * Place each artifact in the same directory layout as a default repository. + *
example: /outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar + * + * @since 2.0-alpha-2 + */ + @Parameter( property = "mdep.useRepositoryLayout", defaultValue = "false" ) + protected boolean useRepositoryLayout; + + /** + * Place each type of file in a separate subdirectory. (example + * /outputDirectory/runtime /outputDirectory/provided etc) + * + * @since 2.2 + */ + @Parameter( property = "mdep.useSubDirectoryPerScope", defaultValue = "false" ) + protected boolean useSubDirectoryPerScope; + + /** + * Place each type of file in a separate subdirectory. (example + * /outputDirectory/jars /outputDirectory/wars etc) + * + * @since 2.0-alpha-1 + */ + @Parameter( property = "mdep.useSubDirectoryPerType", defaultValue = "false" ) + protected boolean useSubDirectoryPerType; + + /** + * Place each file in a separate subdirectory. (example + * /outputDirectory/junit-3.8.1-jar) + * + * @since 2.0-alpha-1 + */ + @Parameter( property = "mdep.useSubDirectoryPerArtifact", defaultValue = "false" ) + protected boolean useSubDirectoryPerArtifact; + + /** + * This only applies if the classifier parameter is used. + * + * @since 2.0-alpha-2 + */ + @Parameter( property = "mdep.failOnMissingClassifierArtifact", defaultValue = "false" ) + protected boolean failOnMissingClassifierArtifact = true; + + /** + * @return Returns the outputDirectory. + */ + public File getOutputDirectory() + { + return this.outputDirectory; + } + + /** + * @param theOutputDirectory The outputDirectory to set. + */ + public void setOutputDirectory( File theOutputDirectory ) + { + this.outputDirectory = theOutputDirectory; + } + + /** + * @return Returns the useSubDirectoryPerArtifact. + */ + public boolean isUseSubDirectoryPerArtifact() + { + return this.useSubDirectoryPerArtifact; + } + + /** + * @param theUseSubDirectoryPerArtifact The useSubDirectoryPerArtifact to set. + */ + public void setUseSubDirectoryPerArtifact( boolean theUseSubDirectoryPerArtifact ) + { + this.useSubDirectoryPerArtifact = theUseSubDirectoryPerArtifact; + } + + /** + * @return Returns the useSubDirectoryPerScope + */ + public boolean isUseSubDirectoryPerScope() + { + return this.useSubDirectoryPerScope; + } + + /** + * @param theUseSubDirectoryPerScope The useSubDirectoryPerScope to set. + */ + public void setUseSubDirectoryPerScope( boolean theUseSubDirectoryPerScope ) + { + this.useSubDirectoryPerScope = theUseSubDirectoryPerScope; + } + + /** + * @return Returns the useSubDirectoryPerType. + */ + public boolean isUseSubDirectoryPerType() + { + return this.useSubDirectoryPerType; + } + + /** + * @param theUseSubDirectoryPerType The useSubDirectoryPerType to set. + */ + public void setUseSubDirectoryPerType( boolean theUseSubDirectoryPerType ) + { + this.useSubDirectoryPerType = theUseSubDirectoryPerType; + } + + public boolean isFailOnMissingClassifierArtifact() + { + return failOnMissingClassifierArtifact; + } + + public void setFailOnMissingClassifierArtifact( boolean failOnMissingClassifierArtifact ) + { + this.failOnMissingClassifierArtifact = failOnMissingClassifierArtifact; + } + + public boolean isStripVersion() + { + return stripVersion; + } + + public void setStripVersion( boolean stripVersion ) + { + this.stripVersion = stripVersion; + } + + /** + * @return true, if dependencies must be planted in a repository layout + */ + public boolean isUseRepositoryLayout() + { + return useRepositoryLayout; + } + + /** + * @param useRepositoryLayout - + * true if dependencies must be planted in a repository layout + */ + public void setUseRepositoryLayout( boolean useRepositoryLayout ) + { + this.useRepositoryLayout = useRepositoryLayout; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/BuildClasspathMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/BuildClasspathMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/BuildClasspathMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/BuildClasspathMojo.java 2013-05-14 22:12:46.000000000 +0000 @@ -0,0 +1,589 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * This goal will output a classpath string of dependencies from the local repository to a file or log. + * + * @author ankostis + * @version $Id: BuildClasspathMojo.java 1482623 2013-05-14 22:12:46Z hboutemy $ + * @since 2.0-alpha-2 + */ +@Mojo( name = "build-classpath", requiresDependencyResolution = ResolutionScope.TEST, + defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) +public class BuildClasspathMojo + extends AbstractDependencyFilterMojo + implements Comparator +{ + + /** + * Strip artifact version during copy (only works if prefix is set) + */ + @Parameter( property = "mdep.stripVersion", defaultValue = "false" ) + private boolean stripVersion = false; + + /** + * Strip artifact classifier during copy (only works if prefix is set) + */ + @Parameter( property = "mdep.stripClassifier", defaultValue = "false" ) + private boolean stripClassifier = false; + + /** + * The prefix to prepend on each dependent artifact. If undefined, the paths refer to the actual files store in the + * local repository (the stripVersion parameter does nothing then). + */ + @Parameter( property = "mdep.prefix" ) + private String prefix; + + /** + * The file to write the classpath string. If undefined, it just prints the classpath as [INFO]. + * This parameter is deprecated. Use outputFile instead. + * + * @since 2.0 + * @deprecated use outputFile instead + */ + @Parameter( property = "mdep.cpFile" ) + private File cpFile; + + /** + * A property to set to the content of the classpath string. + */ + @Parameter( property = "mdep.outputProperty" ) + private String outputProperty; + + /** + * The file to write the classpath string. If undefined, it just prints the classpath as [INFO]. + */ + @Parameter( property = "mdep.outputFile" ) + private File outputFile; + + /** + * If 'true', it skips the up-to-date-check, and always regenerates the classpath file. + */ + @Parameter( property = "mdep.regenerateFile", defaultValue = "false" ) + private boolean regenerateFile; + + /** + * Override the char used between the paths. This field is initialized to contain the first character of the value + * of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows + * systems it is '\'. The default is File.separator + * + * @since 2.0 + */ + @Parameter( property = "mdep.fileSeparator", defaultValue = "" ) + private String fileSeparator; + + /** + * Override the char used between path folders. The system-dependent path-separator character. This field is + * initialized to contain the first character of the value of the system property path.separator. This character is + * used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; + * on Microsoft Windows systems it is ';'. + * + * @since 2.0 + */ + @Parameter( property = "mdep.pathSeparator", defaultValue = "" ) + private String pathSeparator; + + /** + * Replace the absolute path to the local repo with this property. This field is ignored it prefix is declared. The + * value will be forced to "${M2_REPO}" if no value is provided AND the attach flag is true. + * + * @since 2.0 + */ + @Parameter( property = "mdep.localRepoProperty", defaultValue = "" ) + private String localRepoProperty; + + /** + * Attach the classpath file to the main artifact so it can be installed and deployed. + * + * @since 2.0 + */ + @Parameter( defaultValue = "false" ) + boolean attach; + + /** + * Write out the classpath in a format compatible with filtering (classpath=xxxxx) + * + * @since 2.0 + */ + @Parameter( property = "mdep.outputFilterFile", defaultValue = "false" ) + boolean outputFilterFile; + + /** + * Either append the artifact's baseVersion or uniqueVersion to the filename. + * Will only be used if {@link #isStripVersion()} is {@code false}. + * @since 2.6 + */ + @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" ) + protected boolean useBaseVersion = true; + + /** + * Maven ProjectHelper + */ + @Component + private MavenProjectHelper projectHelper; + + /** + * not used in this goal + */ + @Parameter + protected boolean useJvmChmod = true; + + /** + * not used in this goal + */ + @Parameter + protected boolean ignorePermissions; + + boolean isFileSepSet = true; + + boolean isPathSepSet = true; + + /** + * Main entry into mojo. Gets the list of dependencies and iterates through calling copyArtifact. + * + * @throws MojoExecutionException with a message if an error occurs. + * @see #getDependencies + * @see #copyArtifact(Artifact, boolean) + */ + protected void doExecute() + throws MojoExecutionException + { + + if ( cpFile != null ) + { + getLog().warn( "The parameter cpFile is deprecated. Use outputFile instead." ); + this.outputFile = cpFile; + } + + // initialize the separators. + isFileSepSet = StringUtils.isNotEmpty( fileSeparator ); + isPathSepSet = StringUtils.isNotEmpty( pathSeparator ); + + //don't allow them to have absolute paths when they attach. + if ( attach && StringUtils.isEmpty( localRepoProperty ) ) + { + localRepoProperty = "${M2_REPO}"; + } + + Set artifacts = getResolvedDependencies( true ); + + if ( artifacts == null || artifacts.isEmpty() ) + { + getLog().info( "No dependencies found." ); + } + + List artList = new ArrayList( artifacts ); + + StringBuilder sb = new StringBuilder(); + Iterator i = artList.iterator(); + + if ( i.hasNext() ) + { + appendArtifactPath( i.next(), sb ); + + while ( i.hasNext() ) + { + sb.append( isPathSepSet ? this.pathSeparator : File.pathSeparator ); + appendArtifactPath( (Artifact) i.next(), sb ); + } + } + + String cpString = sb.toString(); + + // if file separator is set, I need to replace the default one from all + // the file paths that were pulled from the artifacts + if ( isFileSepSet ) + { + // Escape file separators to be used as literal strings + final String pattern = Pattern.quote( File.separator ); + final String replacement = Matcher.quoteReplacement( fileSeparator ); + cpString = cpString.replaceAll( pattern, replacement ); + } + + //make the string valid for filtering + if ( outputFilterFile ) + { + cpString = "classpath=" + cpString; + } + + if ( outputProperty != null ) + { + project.getProperties().setProperty( outputProperty, cpString ); + if ( getLog().isDebugEnabled() ) + { + getLog().debug( outputProperty + " = " + cpString ); + } + } + else if ( outputFile == null ) + { + getLog().info( "Dependencies classpath:\n" + cpString ); + } + else + { + if ( regenerateFile || !isUpdToDate( cpString ) ) + { + storeClasspathFile( cpString, outputFile ); + } + else + { + this.getLog().info( "Skipped writing classpath file '" + outputFile + "'. No changes found." ); + } + } + if ( attach ) + { + attachFile( cpString ); + } + } + + protected void attachFile( String cpString ) + throws MojoExecutionException + { + File attachedFile = new File( project.getBuild().getDirectory(), "classpath" ); + storeClasspathFile( cpString, attachedFile ); + + projectHelper.attachArtifact( project, attachedFile, "classpath" ); + } + + /** + * Appends the artifact path into the specified StringBuilder. + * + * @param art + * @param sb + */ + protected void appendArtifactPath( Artifact art, StringBuilder sb ) + { + if ( prefix == null ) + { + String file = art.getFile().getPath(); + // substitute the property for the local repo path to make the classpath file portable. + if ( StringUtils.isNotEmpty( localRepoProperty ) ) + { + file = StringUtils.replace( file, getLocal().getBasedir(), localRepoProperty ); + } + sb.append( file ); + } + else + { + // TODO: add param for prepending groupId and version. + sb.append( prefix ); + sb.append( File.separator ); + sb.append( DependencyUtil.getFormattedFileName( art, this.stripVersion, this.prependGroupId, this.useBaseVersion, this.stripClassifier ) ); + } + } + + /** + * Checks that new classpath differs from that found inside the old classpathFile. + * + * @param cpString + * @return true if the specified classpath equals to that found inside the file, false otherwise (including when + * file does not exists but new classpath does). + */ + private boolean isUpdToDate( String cpString ) + { + try + { + String oldCp = readClasspathFile(); + return ( cpString == oldCp || ( cpString != null && cpString.equals( oldCp ) ) ); + } + catch ( Exception ex ) + { + this.getLog().warn( + "Error while reading old classpath file '" + outputFile + "' for up-to-date check: " + ex ); + + return false; + } + } + + /** + * It stores the specified string into that file. + * + * @param cpString the string to be written into the file. + * @throws MojoExecutionException + */ + private void storeClasspathFile( String cpString, File out ) + throws MojoExecutionException + { + //make sure the parent path exists. + out.getParentFile().mkdirs(); + + Writer w = null; + try + { + w = new BufferedWriter( new FileWriter( out ) ); + w.write( cpString ); + getLog().info( "Wrote classpath file '" + out + "'." ); + } + catch ( IOException ex ) + { + throw new MojoExecutionException( "Error while writting to classpath file '" + out + "': " + ex.toString(), + ex ); + } + finally + { + IOUtil.close( w ); + } + } + + /** + * Reads into a string the file specified by the mojo param 'outputFile'. Assumes, the instance variable + * 'outputFile' is not null. + * + * @return the string contained in the classpathFile, if exists, or null otherwise. + * @throws MojoExecutionException + */ + protected String readClasspathFile() + throws IOException + { + if ( outputFile == null ) + { + throw new IllegalArgumentException( + "The outputFile parameter cannot be null if the file is intended to be read." ); + } + + if ( !outputFile.isFile() ) + { + return null; + } + StringBuilder sb = new StringBuilder(); + BufferedReader r = null; + + try + { + r = new BufferedReader( new FileReader( outputFile ) ); + String l; + while ( ( l = r.readLine() ) != null ) + { + sb.append( l ); + } + + return sb.toString(); + } + finally + { + IOUtil.close( r ); + } + } + + /** + * Compares artifacts lexicographically, using pattern [group_id][artifact_id][version]. + * + * @param art1 first object + * @param art2 second object + * @return the value 0 if the argument string is equal to this string; a value less than + * 0 if this string is lexicographically less than the string argument; and a value greater + * than 0 if this string is lexicographically greater than the string argument. + */ + public int compare( Artifact art1, Artifact art2 ) + { + if ( art1 == art2 ) + { + return 0; + } + else if ( art1 == null ) + { + return -1; + } + else if ( art2 == null ) + { + return +1; + } + + String s1 = art1.getGroupId() + art1.getArtifactId() + art1.getVersion(); + String s2 = art2.getGroupId() + art2.getArtifactId() + art2.getVersion(); + + return s1.compareTo( s2 ); + } + + protected ArtifactsFilter getMarkedArtifactFilter() + { + return null; + } + + /** + * @return the outputFile + */ + public File getCpFile() + { + return this.outputFile; + } + + /** + * @param theCpFile the outputFile to set + */ + public void setCpFile( File theCpFile ) + { + this.outputFile = theCpFile; + } + + /** + * @return the outputProperty + */ + public String getOutputProperty() + { + return this.outputProperty; + } + + /** + * @param theOutputProperty the outputProperty to set + */ + public void setOutputProperty( String theOutputProperty ) + { + this.outputProperty = theOutputProperty; + } + + /** + * @return the fileSeparator + */ + public String getFileSeparator() + { + return this.fileSeparator; + } + + /** + * @param theFileSeparator the fileSeparator to set + */ + public void setFileSeparator( String theFileSeparator ) + { + this.fileSeparator = theFileSeparator; + } + + /** + * @return the pathSeparator + */ + public String getPathSeparator() + { + return this.pathSeparator; + } + + /** + * @param thePathSeparator the pathSeparator to set + */ + public void setPathSeparator( String thePathSeparator ) + { + this.pathSeparator = thePathSeparator; + } + + /** + * @return the prefix + */ + public String getPrefix() + { + return this.prefix; + } + + /** + * @param thePrefix the prefix to set + */ + public void setPrefix( String thePrefix ) + { + this.prefix = thePrefix; + } + + /** + * @return the regenerateFile + */ + public boolean isRegenerateFile() + { + return this.regenerateFile; + } + + /** + * @param theRegenerateFile the regenerateFile to set + */ + public void setRegenerateFile( boolean theRegenerateFile ) + { + this.regenerateFile = theRegenerateFile; + } + + /** + * @return the stripVersion + */ + public boolean isStripVersion() + { + return this.stripVersion; + } + + /** + * @param theStripVersion the stripVersion to set + */ + public void setStripVersion( boolean theStripVersion ) + { + this.stripVersion = theStripVersion; + } + + public String getLocalRepoProperty() + { + return localRepoProperty; + } + + public void setLocalRepoProperty( String localRepoProperty ) + { + this.localRepoProperty = localRepoProperty; + } + + public boolean isFileSepSet() + { + return isFileSepSet; + } + + public void setFileSepSet( boolean isFileSepSet ) + { + this.isFileSepSet = isFileSepSet; + } + + public boolean isPathSepSet() + { + return isPathSepSet; + } + + public void setPathSepSet( boolean isPathSepSet ) + { + this.isPathSepSet = isPathSepSet; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/CopyDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/CopyDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/CopyDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/CopyDependenciesMojo.java 2013-05-14 22:12:46.000000000 +0000 @@ -0,0 +1,344 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.filters.DestFileFilter; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Map; +import java.util.Set; + +/** + * Goal that copies the project dependencies from the repository to a defined + * location. + * + * @author Brian Fox + * @version $Id: CopyDependenciesMojo.java 1482623 2013-05-14 22:12:46Z hboutemy $ + * @since 1.0 + */ +@Mojo( name = "copy-dependencies", requiresDependencyResolution = ResolutionScope.TEST, + defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true ) +public class CopyDependenciesMojo + extends AbstractFromDependenciesMojo +{ + /** + * Also copy the pom of each artifact. + * + * @since 2.0 + */ + @Parameter( property = "mdep.copyPom", defaultValue = "false" ) + protected boolean copyPom = true; + + /** + * + */ + @Component + protected ArtifactInstaller installer; + + /** + * + */ + @Component + protected ArtifactRepositoryFactory repositoryFactory; + + /** + * + */ + @Component( role = ArtifactRepositoryLayout.class ) + private Map repositoryLayouts; + + + /** + * Either append the artifact's baseVersion or uniqueVersion to the filename. + * Will only be used if {@link #isStripVersion()} is {@code false}. + * @since 2.6 + */ + @Parameter( property = "mdep.useBaseVersion", defaultValue = "true" ) + protected boolean useBaseVersion = true; + + /** + * Add parent poms to the list of copied dependencies (both current project pom parents and dependencies parents). + * @since 2.8 + */ + @Parameter( defaultValue = "false" ) + protected boolean addParentPoms; + + /** + * not used in this goal + */ + @Parameter + protected boolean useJvmChmod = true; + + /** + * not used in this goal + */ + @Parameter + protected boolean ignorePermissions; + + /** + * Main entry into mojo. Gets the list of dependencies and iterates through + * calling copyArtifact. + * + * @throws MojoExecutionException with a message if an error occurs. + * @see #getDependencies + * @see #copyArtifact(Artifact, boolean) + */ + protected void doExecute() + throws MojoExecutionException + { + DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact, addParentPoms ); + Set artifacts = dss.getResolvedDependencies(); + + if ( !useRepositoryLayout ) + { + for ( Artifact artifact : artifacts ) + { + copyArtifact( artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, + this.stripClassifier ); + } + } + else + { + try + { + ArtifactRepository targetRepository = + repositoryFactory.createDeploymentArtifactRepository( "local", + outputDirectory.toURL().toExternalForm(), + repositoryLayouts.get( "default" ), + false /* uniqueVersion */ ); + for ( Artifact artifact : artifacts ) + { + installArtifact( artifact, targetRepository ); + } + } + catch ( MalformedURLException e ) + { + throw new MojoExecutionException( "Could not create outputDirectory repository", e ); + } + } + + Set skippedArtifacts = dss.getSkippedDependencies(); + for ( Artifact artifact : skippedArtifacts ) + { + getLog().info( artifact.getFile().getName() + " already exists in destination." ); + } + + if ( isCopyPom() && !useRepositoryLayout ) + { + copyPoms( getOutputDirectory(), artifacts, this.stripVersion ); + copyPoms( getOutputDirectory(), skippedArtifacts, + this.stripVersion, this.stripClassifier ); // Artifacts that already exist may not yet have poms + } + } + + /** + * install the artifact and the corresponding pom if copyPoms=true + * + * @param artifact + * @param targetRepository + */ + private void installArtifact( Artifact artifact, ArtifactRepository targetRepository ) + { + try + { + if ( "pom".equals( artifact.getType() ) ) + { + installer.install( artifact.getFile(), artifact, targetRepository ); + installBaseSnapshot( artifact, targetRepository ); + } + else + { + installer.install( artifact.getFile(), artifact, targetRepository ); + installBaseSnapshot( artifact, targetRepository ); + + if ( isCopyPom() ) + { + Artifact pomArtifact = getResolvedPomArtifact( artifact ); + if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() ) + { + installer.install( pomArtifact.getFile(), pomArtifact, targetRepository ); + installBaseSnapshot( pomArtifact, targetRepository ); + } + } + } + } + catch ( ArtifactInstallationException e ) + { + getLog().warn( "unable to install " + artifact, e ); + } + } + + private void installBaseSnapshot( Artifact artifact, ArtifactRepository targetRepository ) + throws ArtifactInstallationException + { + if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion() ) ) + { + Artifact baseArtifact = + this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), + artifact.getScope(), artifact.getType() ); + installer.install( artifact.getFile(), baseArtifact, targetRepository ); + } + } + + /** + * Copies the Artifact after building the destination file name if + * overridden. This method also checks if the classifier is set and adds it + * to the destination file name if needed. + * + * @param artifact representing the object to be copied. + * @param removeVersion specifies if the version should be removed from the file name + * when copying. + * @param prependGroupId specifies if the groupId should be prepend to the file while copying. + * @param useBaseVersion specifies if the baseVersion of the artifact should be used instead of the version. + * @throws MojoExecutionException with a message if an error occurs. + * @see DependencyUtil#copyFile(File, File, Log) + * @see DependencyUtil#getFormattedFileName(Artifact, boolean) + */ + protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId, + boolean useBaseVersion ) + throws MojoExecutionException + { + copyArtifact( artifact, removeVersion, prependGroupId, useBaseVersion, false ); + } + + /** + * Copies the Artifact after building the destination file name if + * overridden. This method also checks if the classifier is set and adds it + * to the destination file name if needed. + * + * @param artifact representing the object to be copied. + * @param removeVersion specifies if the version should be removed from the file name + * when copying. + * @param prependGroupId specifies if the groupId should be prepend to the file while copying. + * @param useBaseVersion specifies if the baseVersion of the artifact should be used instead of the version. + * @param removeClassifier specifies if the classifier should be removed from the file name when copying. + * @throws MojoExecutionException with a message if an error occurs. + * @see DependencyUtil#copyFile(File, File, Log) + * @see DependencyUtil#getFormattedFileName(Artifact, boolean) + */ + protected void copyArtifact( Artifact artifact, boolean removeVersion, boolean prependGroupId, + boolean useBaseVersion, boolean removeClassifier ) + throws MojoExecutionException + { + + String destFileName = DependencyUtil.getFormattedFileName( artifact, removeVersion, prependGroupId, + useBaseVersion, removeClassifier ); + + File destDir; + destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, + useSubDirectoryPerArtifact, useRepositoryLayout, + stripVersion, outputDirectory, artifact ); + File destFile = new File( destDir, destFileName ); + + copyFile( artifact.getFile(), destFile ); + } + + /** + * Copy the pom files associated with the artifacts. + */ + public void copyPoms( File destDir, Set artifacts, boolean removeVersion ) + throws MojoExecutionException + + { + copyPoms( destDir, artifacts, removeVersion, false ); + } + + /** + * Copy the pom files associated with the artifacts. + */ + public void copyPoms( File destDir, Set artifacts, boolean removeVersion, boolean removeClassifier ) + throws MojoExecutionException + + { + for ( Artifact artifact : artifacts ) + { + Artifact pomArtifact = getResolvedPomArtifact( artifact ); + + // Copy the pom + if ( pomArtifact.getFile() != null && pomArtifact.getFile().exists() ) + { + File pomDestFile = + new File( destDir, DependencyUtil.getFormattedFileName( pomArtifact, removeVersion, prependGroupId, + useBaseVersion, removeClassifier ) ); + if ( !pomDestFile.exists() ) + { + copyFile( pomArtifact.getFile(), pomDestFile ); + } + } + } + } + + protected Artifact getResolvedPomArtifact( Artifact artifact ) + { + Artifact pomArtifact = + this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", + "pom" ); + // Resolve the pom artifact using repos + try + { + this.resolver.resolve( pomArtifact, this.remoteRepos, this.getLocal() ); + } + catch ( Exception e ) + { + getLog().info( e.getMessage() ); + } + return pomArtifact; + } + + protected ArtifactsFilter getMarkedArtifactFilter() + { + return new DestFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer, + this.useSubDirectoryPerArtifact, this.useSubDirectoryPerType, + this.useSubDirectoryPerScope, this.useRepositoryLayout, this.stripVersion, + this.outputDirectory ); + } + + /** + * @return true, if the pom of each artifact must be copied + */ + public boolean isCopyPom() + { + return this.copyPom; + } + + /** + * @param copyPom - true if the pom of each artifact must be copied + */ + public void setCopyPom( boolean copyPom ) + { + this.copyPom = copyPom; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/UnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/UnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/UnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/fromDependencies/UnpackDependenciesMojo.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,141 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter; +import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; + +import java.io.File; + +/** + * Goal that unpacks the project dependencies from the repository to a defined + * location. + * + * @author Brian Fox + * @version $Id: UnpackDependenciesMojo.java 1481497 2013-05-12 09:10:35Z hboutemy $ + * @since 1.0 + */ +@Mojo( name = "unpack-dependencies", requiresDependencyResolution = ResolutionScope.TEST, + defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true ) +public class UnpackDependenciesMojo + extends AbstractFromDependenciesMojo +{ + /** + * A comma separated list of file patterns to include when unpacking the + * artifact. i.e. **\/*.xml,**\/*.properties + * NOTE: Excludes patterns override the includes. + * (component code = return isIncluded( name ) AND !isExcluded( name );) + * + * @since 2.0 + */ + @Parameter( property = "mdep.unpack.includes" ) + private String includes; + + /** + * A comma separated list of file patterns to exclude when unpacking the + * artifact. i.e. **\/*.xml,**\/*.properties + * NOTE: Excludes patterns override the includes. + * (component code = return isIncluded( name ) AND !isExcluded( name );) + * + * @since 2.0 + */ + @Parameter( property = "mdep.unpack.excludes" ) + private String excludes; + + /** + * Main entry into mojo. This method gets the dependencies and iterates + * through each one passing it to DependencyUtil.unpackFile(). + * + * @throws MojoExecutionException with a message if an error occurs. + * @see #getDependencies + * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager, + * Log) + */ + protected void doExecute() + throws MojoExecutionException + { + DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact ); + + for ( Artifact artifact : dss.getResolvedDependencies() ) + { + File destDir; + destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, + useSubDirectoryPerArtifact, useRepositoryLayout, + stripVersion, outputDirectory, artifact ); + unpack( artifact, destDir, getIncludes(), getExcludes() ); + DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory ); + handler.setMarker(); + } + + for ( Artifact artifact : dss.getSkippedDependencies() ) + { + getLog().info( artifact.getFile().getName() + " already exists in destination." ); + } + } + + protected ArtifactsFilter getMarkedArtifactFilter() + { + return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer, + new DefaultFileMarkerHandler( this.markersDirectory ) ); + } + + /** + * @return Returns a comma separated list of excluded items + */ + public String getExcludes() + { + return DependencyUtil.cleanToBeTokenizedString( this.excludes ); + } + + /** + * @param excludes A comma separated list of items to exclude + * i.e. **\/*.xml, **\/*.properties + */ + public void setExcludes( String excludes ) + { + this.excludes = excludes; + } + + /** + * @return Returns a comma separated list of included items + */ + public String getIncludes() + { + return DependencyUtil.cleanToBeTokenizedString( this.includes ); + } + + /** + * @param includes A comma separated list of items to include + * i.e. **\/*.xml, **\/*.properties + */ + public void setIncludes( String includes ) + { + this.includes = includes; + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java 2013-02-28 20:41:08.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java 2013-05-12 12:37:19.000000000 +0000 @@ -48,7 +48,7 @@ import java.util.regex.Pattern; /** - * Downloads a single artifact transitively from the specified remote repositories. Caveat: will always check the + * Resolves a single artifact, eventually transitively, from the specified remote repositories. Caveat: will always check the * central repository defined in the super pom. You could use a mirror entry in your settings.xml */ @Mojo( name = "get", requiresProject = false, threadSafe = true ) @@ -158,6 +158,7 @@ * The destination file or directory to copy the artifact to, if other than the local repository * * @since 2.4 + * @deprecated if you need to copy the resolved artifact, use dependency:copy */ @Parameter( property = "dest" ) private String destination; @@ -262,11 +263,13 @@ { if ( transitive ) { + getLog().info( "Resolving " + toDownload + " with transitive dependencies" ); artifactResolver.resolveTransitively( Collections.singleton( toDownload ), dummyOriginatingArtifact, repoList, localRepository, source ); } else { + getLog().info( "Resolving " + toDownload ); artifactResolver.resolve( toDownload, repoList, localRepository ); } } @@ -277,12 +280,17 @@ if ( destination != null ) { + getLog().warn( "destination/dest parameter is deprecated: it will disappear in future version." ); + File src = toDownload.getFile(); File dest = new File( destination ); - if ( getLog().isInfoEnabled() ) + + getLog().info( "Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath() ); + if ( transitive ) { - getLog().info( "Copying " + src.getAbsolutePath() + " to " + dest.getAbsolutePath() ); + getLog().warn( "Notice transitive dependencies won't be copied." ); } + try { if ( dest.isDirectory() ) diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/ListMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/ListMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/ListMojo.java 2012-10-21 23:05:22.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/ListMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -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 org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.ResolutionScope; - -/** - * Displays the list of dependencies for this project. - * - * @author Mark Hobson - * @version $Id: ListMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $ - * @since 2.0-alpha-5 - */ -@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) -public class ListMojo - extends ResolveDependenciesMojo -{ - // alias for dependency:resolve -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java 2013-02-28 20:41:08.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/PropertiesMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -37,7 +37,7 @@ * groupId:artifactId:type:[classifier] form and contains the path to the resolved artifact. * * @author Paul Gier - * @version $Id: PropertiesMojo.java 1451330 2013-02-28 20:41:08Z rfscholte $ + * @version $Id: PropertiesMojo.java 1481553 2013-05-12 13:25:34Z hboutemy $ * @since 2.2 */ @Mojo( name = "properties", requiresDependencyResolution = ResolutionScope.TEST, @@ -91,7 +91,7 @@ public boolean isSkip() { return skip; -} + } public void setSkip( boolean skip ) { diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/PurgeLocalRepositoryMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/PurgeLocalRepositoryMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/PurgeLocalRepositoryMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/PurgeLocalRepositoryMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -54,7 +54,7 @@ * Remove the project dependencies from the local repository, and optionally re-resolve them. * * @author jdcasey - * @version $Id: PurgeLocalRepositoryMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: PurgeLocalRepositoryMojo.java 1481553 2013-05-12 13:25:34Z hboutemy $ * @since 2.0 */ @Mojo( name = "purge-local-repository", threadSafe = true ) @@ -674,7 +674,7 @@ public boolean isSkip() { return skip; -} + } public void setSkip( boolean skip ) { diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/AbstractResolveMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/AbstractResolveMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/AbstractResolveMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/AbstractResolveMojo.java 2013-05-14 22:12:46.000000000 +0000 @@ -0,0 +1,194 @@ +package org.apache.maven.plugin.dependency.resolvers; + +/* + * 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.io.File; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugin.dependency.fromDependencies.AbstractDependencyFilterMojo; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter; +import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter; +import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; +import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; +import org.apache.maven.shared.artifact.filter.collection.TypeFilter; + +/** + * @author Brian Fox + * @version $Id: AbstractResolveMojo.java 1482623 2013-05-14 22:12:46Z hboutemy $ + */ +public abstract class AbstractResolveMojo + extends AbstractDependencyFilterMojo +{ + /** + * Project builder -- builds a model from a pom.xml + */ + @Component + protected MavenProjectBuilder mavenProjectBuilder; + + /** + * If specified, this parameter will cause the dependencies to be written to the path specified, instead of writing + * to the console. + * + * @since 2.0 + */ + @Parameter( property = "outputFile" ) + protected File outputFile; + + /** + * This method resolves the dependency artifacts from the project. + * + * @param theProject + * The POM. + * @return resolved set of dependency artifacts. + * + * @throws ArtifactResolutionException + * @throws ArtifactNotFoundException + * @throws InvalidDependencyVersionException + */ + + /** + * Whether to append outputs into the output file or overwrite it. + * + * @since 2.2 + */ + @Parameter( property = "appendOutput", defaultValue = "false" ) + protected boolean appendOutput; + + /** + * Don't resolve plugins that are in the current reactor. + * Only works for plugins at the moment. + * + * @since 2.7 + */ + @Parameter( property = "excludeReactor", defaultValue = "true" ) + protected boolean excludeReactor; + + /** + * not used in this goal + */ + @Parameter + protected boolean useJvmChmod = true; + + /** + * not used in this goal + */ + @Parameter + protected boolean ignorePermissions; + + protected FilterArtifacts getPluginArtifactsFilter() + { + if ( excludeReactor ) + { + final StringBuilder exAids = new StringBuilder(); + if ( this.excludeArtifactIds != null ) + { + exAids.append( this.excludeArtifactIds ); + } + + for ( final MavenProject rp : reactorProjects ) + { + if ( !"maven-plugin".equals( rp.getPackaging() ) ) + { + continue; + } + + if ( exAids.length() > 0 ) + { + exAids.append( "," ); + } + + exAids.append( rp.getArtifactId() ); + } + + this.excludeArtifactIds = exAids.toString(); + } + + final FilterArtifacts filter = new FilterArtifacts(); + + filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ), + DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) ); + + filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ), + DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) ); + + filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ), + DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) ); + + filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ), + DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) ); + + filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ), + DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) ); + + return filter; + } + + protected Set resolveDependencyArtifacts( final MavenProject theProject ) + throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException + { + final Set artifacts = + theProject.createArtifacts( this.factory, Artifact.SCOPE_TEST, + new ScopeArtifactFilter( Artifact.SCOPE_TEST ) ); + + for ( final Artifact artifact : artifacts ) + { + // resolve the new artifact + this.resolver.resolve( artifact, this.remoteRepos, this.getLocal() ); + } + return artifacts; + } + + /** + * This method resolves all transitive dependencies of an artifact. + * + * @param artifact the artifact used to retrieve dependencies + * @return resolved set of dependencies + * @throws ArtifactResolutionException + * @throws ArtifactNotFoundException + * @throws ProjectBuildingException + * @throws InvalidDependencyVersionException + * + */ + protected Set resolveArtifactDependencies( final Artifact artifact ) + throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException, + InvalidDependencyVersionException + { + final Artifact pomArtifact = + this.factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", + "pom" ); + + final MavenProject pomProject = + mavenProjectBuilder.buildFromRepository( pomArtifact, this.remoteRepos, this.getLocal() ); + + return resolveDependencyArtifacts( pomProject ); + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/GoOfflineMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/GoOfflineMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/GoOfflineMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/GoOfflineMojo.java 2013-05-12 13:07:02.000000000 +0000 @@ -21,7 +21,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.AbstractResolveMojo; import org.apache.maven.plugin.dependency.utils.DependencyUtil; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.Mojo; @@ -35,7 +34,7 @@ * and their dependencies. * * @author Brian Fox - * @version $Id: GoOfflineMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: GoOfflineMojo.java 1481548 2013-05-12 13:07:02Z hboutemy $ * @since 2.0 */ @Mojo( name = "go-offline", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ListMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ListMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ListMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ListMojo.java 2013-05-12 08:36:57.000000000 +0000 @@ -0,0 +1,37 @@ +package org.apache.maven.plugin.dependency.resolvers; + +/* + * 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 org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.ResolutionScope; + +/** + * Displays the list of dependencies for this project. + * + * @author Mark Hobson + * @version $Id: ListMojo.java 1481489 2013-05-12 08:36:57Z hboutemy $ + * @since 2.0-alpha-5 + */ +@Mojo( name = "list", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +public class ListMojo + extends ResolveDependenciesMojo +{ + // alias for dependency:resolve +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependenciesMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolveDependenciesMojo.java 2013-05-14 22:08:15.000000000 +0000 @@ -20,7 +20,6 @@ */ import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.AbstractResolveMojo; import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; import org.apache.maven.plugin.dependency.utils.DependencyUtil; import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter; @@ -37,7 +36,7 @@ * Goal that resolves the project dependencies from the repository. * * @author Brian Fox - * @version $Id: ResolveDependenciesMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: ResolveDependenciesMojo.java 1482616 2013-05-14 22:08:15Z hboutemy $ * @since 2.0 */ @Mojo( name = "resolve", requiresDependencyResolution = ResolutionScope.TEST, @@ -60,6 +59,23 @@ DependencyStatusSets results; /** + * Sort the output list of resolved artifacts alphabetically. + * The default ordering matches the classpath order. + * + * @since 2.8 + */ + @Parameter( property = "sort", defaultValue = "false" ) + boolean sort; + + /** + * Include parent poms in the dependency resolution list. + * + * @since 2.8 + */ + @Parameter( property = "includeParents", defaultValue = "false" ) + boolean includeParents; + + /** * Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version. * * @throws MojoExecutionException with a message if an error occurs. @@ -68,9 +84,9 @@ throws MojoExecutionException { // get sets of dependencies - results = this.getDependencySets( false ); + results = this.getDependencySets( false, includeParents ); - String output = results.getOutput( outputAbsoluteArtifactFilename, outputScope ); + String output = results.getOutput( outputAbsoluteArtifactFilename, outputScope, sort ); try { if ( outputFile == null ) diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/resolvers/ResolvePluginsMojo.java 2013-05-12 13:25:34.000000000 +0000 @@ -31,7 +31,6 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.AbstractResolveMojo; import org.apache.maven.plugin.dependency.utils.DependencyUtil; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -47,7 +46,7 @@ * Goal that resolves all project plugins and reports and their dependencies. * * @author Brian Fox - * @version $Id: ResolvePluginsMojo.java 1451088 2013-02-28 04:22:41Z brianf $ + * @version $Id: ResolvePluginsMojo.java 1481553 2013-05-12 13:25:34Z hboutemy $ * @since 2.0 */ @Mojo( name = "resolve-plugins", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) @@ -95,8 +94,7 @@ String logStr = "Plugin Resolved: " + DependencyUtil.getFormattedFileName( plugin, false ); if ( !silent ) { - this.getLog() - .info( logStr ); + this.getLog().info( logStr ); } if ( outputWriter != null ) @@ -114,8 +112,7 @@ if ( !silent ) { - this.getLog() - .info( logStr ); + this.getLog().info( logStr ); } if ( outputWriter != null ) diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/AbstractSerializingVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/AbstractSerializingVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/AbstractSerializingVisitor.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/AbstractSerializingVisitor.java 2013-05-12 13:14:31.000000000 +0000 @@ -0,0 +1,57 @@ +package org.apache.maven.plugin.dependency.tree ; + +/* + * 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.io.PrintWriter; +import java.io.Writer; + +/** + * Abstract class for visitors performing serialization. + * + * @author Jerome Creignou + */ +public abstract class AbstractSerializingVisitor +{ + + /** + * The writer to serialize to. + */ + protected final PrintWriter writer; + + /** + * Constructor. + *

+ * Build a new AbstractSerializingDependencyNodeVisitor with the writer to serialize to. + *

+ * + * @param writer the writer to serialize to. + */ + public AbstractSerializingVisitor( Writer writer ) + { + if ( writer instanceof PrintWriter ) + { + this.writer = (PrintWriter) writer; + } + else + { + this.writer = new PrintWriter( writer, true ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/DOTDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/DOTDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/DOTDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/DOTDependencyNodeVisitor.java 2013-05-12 13:14:31.000000000 +0000 @@ -0,0 +1,91 @@ +package org.apache.maven.plugin.dependency.tree; + +/* + * 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 org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; + +import java.io.Writer; +import java.util.List; + +/** + * A dependency node visitor that serializes visited nodes to DOT format + * http://en.wikipedia.org/wiki/DOT_language + * + * @author Pi Song + * @since 2.1 + */ +public class DOTDependencyNodeVisitor + extends AbstractSerializingVisitor + implements DependencyNodeVisitor +{ + + /** + * Constructor. + * + * @param writer the writer to write to. + */ + public DOTDependencyNodeVisitor( Writer writer ) + { + super( writer ); + } + + + /** + * {@inheritDoc} + */ + public boolean visit( DependencyNode node ) + { + if ( node.getParent() == null || node.getParent() == node ) + { + writer.write( "digraph \"" + node.toNodeString() + "\" { \n" ); + } + + // Generate "currentNode -> Child" lines + + List children = node.getChildren(); + + for ( DependencyNode child : children ) + { + StringBuilder sb = new StringBuilder(); + sb.append( "\t\"" ); + sb.append( node.toNodeString() ); + sb.append( "\" -> \"" ); + sb.append( child.toNodeString() ); + sb.append( "\" ; " ); + writer.println( sb.toString() ); + } + + return true; + } + + /** + * {@inheritDoc} + */ + public boolean endVisit( DependencyNode node ) + { + if ( node.getParent() == null || node.getParent() == node ) + { + writer.write( " } " ); + } + return true; + } + +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/GraphmlDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/GraphmlDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/GraphmlDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/GraphmlDependencyNodeVisitor.java 2013-05-12 13:14:31.000000000 +0000 @@ -0,0 +1,123 @@ +package org.apache.maven.plugin.dependency.tree ; + +/* + * 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.io.Writer; + +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; + +/** + * A dependency node visitor that serializes visited nodes to a writer using the graphml format. + * {@link http://graphml.graphdrawing.org/} + * + * @author Jerome Creignou + * @since 2.1 + */ +public class GraphmlDependencyNodeVisitor + extends AbstractSerializingVisitor + implements DependencyNodeVisitor +{ + + /** + * Graphml xml file header. Define Schema and root element. We also define 2 key as meta data. + */ + private static final String GRAPHML_HEADER = + " " + + "\n" + + " \n" + + " \n" + + "\n"; + + /** + * Graphml xml file footer. + */ + private static final String GRAPHML_FOOTER = ""; + + /** + * Constructor. + * + * @param writer the writer to write to. + */ + public GraphmlDependencyNodeVisitor( Writer writer ) + { + super( writer ); + } + + /** + * {@inheritDoc} + */ + public boolean endVisit( DependencyNode node ) + { + if ( node.getParent() == null || node.getParent() == node ) + { + writer.write( GRAPHML_FOOTER ); + } + else + { + DependencyNode p = node.getParent(); + writer.print( "" ); + if ( node.getArtifact().getScope() != null ) + { + // add Edge label + writer.print( "" + node.getArtifact().getScope() + + "" ); + } + writer.println( "" ); + } + return true; + } + + /** + * {@inheritDoc} + */ + public boolean visit( DependencyNode node ) + { + if ( node.getParent() == null || node.getParent() == node ) + { + writer.write( GRAPHML_HEADER ); + } + // write node + writer.print( "" ); + // add node label + writer.print( "" + node.toNodeString() + + "" ); + writer.println( "" ); + return true; + } + + /** + * Generate a unique id from a DependencyNode. + *

+ * Current implementation is rather simple and uses hashcode. + *

+ * + * @param node the DependencyNode to use. + * @return the unique id. + */ + private static String generateId( DependencyNode node ) + { + return String.valueOf( node.hashCode() ); + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/TGFDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/TGFDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/TGFDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/TGFDependencyNodeVisitor.java 2013-05-12 13:14:31.000000000 +0000 @@ -0,0 +1,158 @@ +package org.apache.maven.plugin.dependency.tree ; + +/* + * 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.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; + +/** + * A dependency node visitor that serializes visited nodes to a writer using the TGF format. + * + * http://en.wikipedia.org/wiki/Trivial_Graph_Format + * + * @author Jerome Creignou + * @since 2.1 + */ +public class TGFDependencyNodeVisitor + extends AbstractSerializingVisitor + implements DependencyNodeVisitor +{ + + /** + * Utiity class to write an Edge. + * + * @author Jerome Creignou + */ + static final class EdgeAppender + { + /** + * Edge start. + */ + private DependencyNode from; + + /** + * Edge end. + */ + private DependencyNode to; + + /** + * Edge label. (optional) + */ + private String label; + + /** + * Build a new EdgeAppender. + * + * @param from edge start. + * @param to edge end + * @param label optional label. + */ + public EdgeAppender( DependencyNode from, DependencyNode to, String label ) + { + super(); + this.from = from; + this.to = to; + this.label = label; + } + + /** + * build a string representing the edge. + */ + public String toString() + { + StringBuilder result = new StringBuilder( generateId( from ) ); + result.append( ' ' ).append( generateId( to ) ); + if ( label != null ) + { + result.append( ' ' ).append( label ); + } + return result.toString(); + } + + } + + /** + * List of edges. + */ + private List edges = new ArrayList(); + + /** + * Constructor. + * + * @param writer the writer to write to. + */ + public TGFDependencyNodeVisitor( Writer writer ) + { + super( writer ); + } + + /** + * {@inheritDoc} + */ + public boolean endVisit( DependencyNode node ) + { + if ( node.getParent() == null || node.getParent() == node ) + { + // dump edges on last node endVisit + writer.println( "#" ); + for ( EdgeAppender edge : edges ) + { + writer.println( edge.toString() ); + } + } + else + { + DependencyNode p = node.getParent(); + // using scope as edge label. + edges.add( new EdgeAppender( p, node, node.getArtifact().getScope() ) ); + } + return true; + } + + /** + * {@inheritDoc} + */ + public boolean visit( DependencyNode node ) + { + // write node + writer.write( generateId( node ) ); + writer.write( " " ); + writer.println( node.toNodeString() ); + return true; + } + + /** + * Generate a unique id from a DependencyNode. + *

+ * Current implementation is rather simple and uses hashcode. + *

+ * + * @param node the DependencyNode to use. + * @return the unique id. + */ + private static String generateId( DependencyNode node ) + { + return String.valueOf( node.hashCode() ); + } +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/TreeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/TreeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/tree/TreeMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/tree/TreeMojo.java 2013-05-12 13:39:04.000000000 +0000 @@ -0,0 +1,604 @@ +package org.apache.maven.plugin.dependency.tree; + +/* + * 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 org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.Restriction; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; +import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter; +import org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter; +import org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter; +import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter; +import org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor.GraphTokens; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.TreeTokens; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Displays the dependency tree for this project. + * + * @author Mark Hobson + * @version $Id: TreeMojo.java 1481555 2013-05-12 13:39:04Z hboutemy $ + * @since 2.0-alpha-5 + */ +@Mojo( name = "tree", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +public class TreeMojo + extends AbstractMojo +{ + // fields ----------------------------------------------------------------- + + /** + * The Maven project. + */ + @Component + private MavenProject project; + + /** + * The dependency tree builder to use. + */ + @Component( hint = "default" ) + private DependencyGraphBuilder dependencyGraphBuilder; + + /** + * The dependency tree builder to use for verbose output. + */ + @Component + private DependencyTreeBuilder dependencyTreeBuilder; + + /** + * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of + * writing to the console. + * + * @deprecated use outputFile instead. + */ + @Parameter( property = "output" ) + private File output; + + /** + * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of + * writing to the console. + * + * @since 2.0-alpha-5 + */ + @Parameter( property = "outputFile" ) + private File outputFile; + + /** + * If specified, this parameter will cause the dependency tree to be written using the specified format. Currently + * supported format are: text, dot, graphml and tgf. + *

+ * These formats can be plotted to image files. An example of how to plot a dot file using + * pygraphviz can be found here. + * + * @since 2.2 + */ + @Parameter( property = "outputType", defaultValue = "text" ) + private String outputType; + + /** + * The scope to filter by when resolving the dependency tree, or null to include dependencies from + * all scopes. Note that this feature does not currently work due to MNG-3236. + * + * @see MNG-3236 + * @since 2.0-alpha-5 + */ + @Parameter( property = "scope" ) + private String scope; + + /** + * Whether to include omitted nodes in the serialized dependency tree. + * + * @since 2.0-alpha-6 + */ + @Parameter( property = "verbose", defaultValue = "false" ) + private boolean verbose; + + /** + * The token set name to use when outputting the dependency tree. Possible values are whitespace, + * standard or extended, which use whitespace, standard (ie ASCII) or extended + * character sets respectively. + * + * @since 2.0-alpha-6 + */ + @Parameter( property = "tokens", defaultValue = "standard" ) + private String tokens; + + /** + * A comma-separated list of artifacts to filter the serialized dependency tree by, or null not to + * filter the dependency tree. The filter syntax is: + * + *

+     * [groupId]:[artifactId]:[type]:[version]
+     * 
+ * + * where each pattern segment is optional and supports full and partial * wildcards. An empty pattern + * segment is treated as an implicit wildcard. + *

For example, org.apache.* will match all artifacts whose group id starts with + * org.apache., and :::*-SNAPSHOT will match all snapshot artifacts.

+ * + * @see StrictPatternIncludesArtifactFilter + * @since 2.0-alpha-6 + */ + @Parameter( property = "includes" ) + private String includes; + + /** + * A comma-separated list of artifacts to filter from the serialized dependency tree, or null not to + * filter any artifacts from the dependency tree. The filter syntax is: + * + *
+     * [groupId]:[artifactId]:[type]:[version]
+     * 
+ * + * where each pattern segment is optional and supports full and partial * wildcards. An empty pattern + * segment is treated as an implicit wildcard. + *

For example, org.apache.* will match all artifacts whose group id starts with + * org.apache., and :::*-SNAPSHOT will match all snapshot artifacts.

+ * + * @see StrictPatternExcludesArtifactFilter + * @since 2.0-alpha-6 + */ + @Parameter( property = "excludes" ) + private String excludes; + + /** + * The computed dependency tree root node of the Maven project. + */ + private DependencyNode rootNode; + + /** + * Whether to append outputs into the output file or overwrite it. + * + * @since 2.2 + */ + @Parameter( property = "appendOutput", defaultValue = "false" ) + private boolean appendOutput; + + /** + * Skip plugin execution completely. + * + * @since 2.7 + */ + @Parameter( property = "skip", defaultValue = "false" ) + private boolean skip; + + @Parameter( defaultValue = "${localRepository}", readonly = true ) + private ArtifactRepository localRepository; + + // Mojo methods ----------------------------------------------------------- + + /* + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( isSkip() ) + { + getLog().info( "Skipping plugin execution" ); + return; + } + + if ( output != null ) + { + getLog().warn( "The parameter output is deprecated. Use outputFile instead." ); + this.outputFile = output; + } + + try + { + String dependencyTreeString = null; + + // TODO: note that filter does not get applied due to MNG-3236 + + ArtifactFilter artifactFilter = createResolvingArtifactFilter(); + + if ( verbose ) + { + // verbose mode force Maven 2 dependency tree component use + dependencyTreeString = + serializeVerboseDependencyTree( dependencyTreeBuilder.buildDependencyTree( project, + localRepository, + artifactFilter ) ); + } + else + { + // non-verbose mode use dependency graph component, which gives consistent results with Maven version + // running + rootNode = dependencyGraphBuilder.buildDependencyGraph( project, artifactFilter ); + + dependencyTreeString = serializeDependencyTree( rootNode ); + } + + if ( outputFile != null ) + { + DependencyUtil.write( dependencyTreeString, outputFile, this.appendOutput, getLog() ); + + getLog().info( "Wrote dependency tree to: " + outputFile ); + } + else + { + DependencyUtil.log( dependencyTreeString, getLog() ); + } + } + catch ( DependencyGraphBuilderException exception ) + { + throw new MojoExecutionException( "Cannot build project dependency graph", exception ); + } + catch ( DependencyTreeBuilderException exception ) + { + throw new MojoExecutionException( "Cannot build project dependency tree", exception ); + } + catch ( IOException exception ) + { + throw new MojoExecutionException( "Cannot serialise project dependency graph", exception ); + } + } + + // public methods --------------------------------------------------------- + + /** + * Gets the Maven project used by this mojo. + * + * @return the Maven project + */ + public MavenProject getProject() + { + return project; + } + + /** + * Gets the computed dependency graph root node for the Maven project. + * + * @return the dependency tree root node + */ + public DependencyNode getDependencyGraph() + { + return rootNode; + } + + public boolean isSkip() + { + return skip; + } + + public void setSkip( boolean skip ) + { + this.skip = skip; + } + + // private methods -------------------------------------------------------- + + /** + * Gets the artifact filter to use when resolving the dependency tree. + * + * @return the artifact filter + */ + private ArtifactFilter createResolvingArtifactFilter() + { + ArtifactFilter filter; + + // filter scope + if ( scope != null ) + { + getLog().debug( "+ Resolving dependency tree for scope '" + scope + "'" ); + + filter = new ScopeArtifactFilter( scope ); + } + else + { + filter = null; + } + + return filter; + } + + /** + * Serializes the specified dependency tree to a string. + * + * @param rootNode the dependency tree root node to serialize + * @return the serialized dependency tree + */ + private String serializeDependencyTree( DependencyNode rootNode ) + { + StringWriter writer = new StringWriter(); + + DependencyNodeVisitor visitor = getSerializingDependencyNodeVisitor( writer ); + + // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only + visitor = new BuildingDependencyNodeVisitor( visitor ); + + DependencyNodeFilter filter = createDependencyNodeFilter(); + + if ( filter != null ) + { + CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor(); + DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor( collectingVisitor, filter ); + rootNode.accept( firstPassVisitor ); + + DependencyNodeFilter secondPassFilter = + new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() ); + visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter ); + } + + rootNode.accept( visitor ); + + return writer.toString(); + } + + /** + * Serializes the specified dependency tree to a string. + * + * @param rootNode the dependency tree root node to serialize + * @return the serialized dependency tree + */ + private String serializeVerboseDependencyTree( org.apache.maven.shared.dependency.tree.DependencyNode rootNode ) + { + StringWriter writer = new StringWriter(); + + org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor visitor = + new org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor( writer, + toTreeTokens( tokens ) ); + + // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only + visitor = new org.apache.maven.shared.dependency.tree.traversal.BuildingDependencyNodeVisitor( visitor ); + + org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter filter = createVerboseDependencyNodeFilter(); + + if ( filter != null ) + { + org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor collectingVisitor = + new org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor(); + org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor firstPassVisitor = + new org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor( collectingVisitor, + filter ); + rootNode.accept( firstPassVisitor ); + + org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter secondPassFilter = + new org.apache.maven.shared.dependency.tree.filter.AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() ); + visitor = + new org.apache.maven.shared.dependency.tree.traversal.FilteringDependencyNodeVisitor( visitor, + secondPassFilter ); + } + + rootNode.accept( visitor ); + + return writer.toString(); + } + + public DependencyNodeVisitor getSerializingDependencyNodeVisitor( Writer writer ) + { + if ( "graphml".equals( outputType ) ) + { + return new GraphmlDependencyNodeVisitor( writer ); + } + else if ( "tgf".equals( outputType ) ) + { + return new TGFDependencyNodeVisitor( writer ); + } + else if ( "dot".equals( outputType ) ) + { + return new DOTDependencyNodeVisitor( writer ); + } + else + { + return new SerializingDependencyNodeVisitor( writer, toGraphTokens( tokens ) ); + } + } + + /** + * Gets the graph tokens instance for the specified name. + * + * @param tokens the graph tokens name + * @return the GraphTokens instance + */ + private GraphTokens toGraphTokens( String tokens ) + { + GraphTokens graphTokens; + + if ( "whitespace".equals( tokens ) ) + { + getLog().debug( "+ Using whitespace tree tokens" ); + + graphTokens = SerializingDependencyNodeVisitor.WHITESPACE_TOKENS; + } + else if ( "extended".equals( tokens ) ) + { + getLog().debug( "+ Using extended tree tokens" ); + + graphTokens = SerializingDependencyNodeVisitor.EXTENDED_TOKENS; + } + else + { + graphTokens = SerializingDependencyNodeVisitor.STANDARD_TOKENS; + } + + return graphTokens; + } + + /** + * Gets the tree tokens instance for the specified name. + * + * @param tokens the tree tokens name + * @return the TreeTokens instance + */ + private TreeTokens toTreeTokens( String tokens ) + { + TreeTokens treeTokens; + + if ( "whitespace".equals( tokens ) ) + { + getLog().debug( "+ Using whitespace tree tokens" ); + + treeTokens = + org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.WHITESPACE_TOKENS; + } + else if ( "extended".equals( tokens ) ) + { + getLog().debug( "+ Using extended tree tokens" ); + + treeTokens = + org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.EXTENDED_TOKENS; + } + else + { + treeTokens = + org.apache.maven.shared.dependency.tree.traversal.SerializingDependencyNodeVisitor.STANDARD_TOKENS; + } + + return treeTokens; + } + + /** + * Gets the dependency node filter to use when serializing the dependency graph. + * + * @return the dependency node filter, or null if none required + */ + private DependencyNodeFilter createDependencyNodeFilter() + { + List filters = new ArrayList(); + + // filter includes + if ( includes != null ) + { + List patterns = Arrays.asList( includes.split( "," ) ); + + getLog().debug( "+ Filtering dependency tree by artifact include patterns: " + patterns ); + + ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter( patterns ); + filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) ); + } + + // filter excludes + if ( excludes != null ) + { + List patterns = Arrays.asList( excludes.split( "," ) ); + + getLog().debug( "+ Filtering dependency tree by artifact exclude patterns: " + patterns ); + + ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter( patterns ); + filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) ); + } + + return filters.isEmpty() ? null : new AndDependencyNodeFilter( filters ); + } + + /** + * Gets the dependency node filter to use when serializing the dependency tree. + * + * @return the dependency node filter, or null if none required + */ + private org.apache.maven.shared.dependency.tree.filter.DependencyNodeFilter createVerboseDependencyNodeFilter() + { + List filters = + new ArrayList(); + + // filter includes + if ( includes != null ) + { + List patterns = Arrays.asList( includes.split( "," ) ); + + getLog().debug( "+ Filtering dependency tree by artifact include patterns: " + patterns ); + + ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter( patterns ); + filters.add( new org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter( + artifactFilter ) ); + } + + // filter excludes + if ( excludes != null ) + { + List patterns = Arrays.asList( excludes.split( "," ) ); + + getLog().debug( "+ Filtering dependency tree by artifact exclude patterns: " + patterns ); + + ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter( patterns ); + filters.add( new org.apache.maven.shared.dependency.tree.filter.ArtifactDependencyNodeFilter( + artifactFilter ) ); + } + + return filters.isEmpty() ? null + : new org.apache.maven.shared.dependency.tree.filter.AndDependencyNodeFilter( filters ); + } + + //following is required because the version handling in maven code + //doesn't work properly. I ripped it out of the enforcer rules. + + + /** + * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default + * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == + * "[2.0.4,)" + * + * @param allowedRange range of allowed versions. + * @param theVersion the version to be checked. + * @return true if the version is contained by the range. + */ + public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion ) + { + ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); + if ( recommendedVersion == null ) + { + @SuppressWarnings( "unchecked" ) + List restrictions = allowedRange.getRestrictions(); + for ( Restriction restriction : restrictions ) + { + if ( restriction.containsVersion( theVersion ) ) + { + return true; + } + } + } + + // only singular versions ever have a recommendedVersion + return recommendedVersion.compareTo( theVersion ) <= 0; + } + +} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/TreeMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,456 +0,0 @@ -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 org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.Restriction; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.dependency.treeSerializers.DOTDependencyNodeVisitor; -import org.apache.maven.plugin.dependency.treeSerializers.GraphmlDependencyNodeVisitor; -import org.apache.maven.plugin.dependency.treeSerializers.TGFDependencyNodeVisitor; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; -import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; -import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; -import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; -import org.apache.maven.shared.dependency.graph.DependencyNode; -import org.apache.maven.shared.dependency.graph.filter.AncestorOrSelfDependencyNodeFilter; -import org.apache.maven.shared.dependency.graph.filter.AndDependencyNodeFilter; -import org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter; -import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter; -import org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor; -import org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor; -import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; -import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor; -import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor; -import org.apache.maven.shared.dependency.graph.traversal.SerializingDependencyNodeVisitor.TreeTokens; - -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Displays the dependency tree for this project. - * - * @author Mark Hobson - * @version $Id: TreeMojo.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 2.0-alpha-5 - */ -@Mojo( name = "tree", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) -public class TreeMojo - extends AbstractMojo -{ - // fields ----------------------------------------------------------------- - - /** - * The Maven project. - */ - @Component - private MavenProject project; - - /** - * The dependency tree builder to use. - */ - @Component( hint = "default" ) - private DependencyGraphBuilder dependencyGraphBuilder; - - /** - * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of - * writing to the console. - * - * @deprecated use outputFile instead. - */ - @Parameter( property = "output" ) - private File output; - - /** - * If specified, this parameter will cause the dependency tree to be written to the path specified, instead of - * writing to the console. - * - * @since 2.0-alpha-5 - */ - @Parameter( property = "outputFile" ) - private File outputFile; - - /** - * If specified, this parameter will cause the dependency tree to be written using the specified format. Currently - * supported format are text, dot, graphml and tgf. - *

- * These formats can be plotted to image files. An example of how to plot a dot file using - * pygraphviz can be found here - * - * @since 2.2 - */ - @Parameter( property = "outputType", defaultValue = "text" ) - private String outputType; - - /** - * The scope to filter by when resolving the dependency tree, or null to include dependencies from - * all scopes. Note that this feature does not currently work due to MNG-3236. - * - * @see MNG-3236 - * @since 2.0-alpha-5 - */ - @Parameter( property = "scope" ) - private String scope; - - /** - * Whether to include omitted nodes in the serialized dependency tree. - * - * @since 2.0-alpha-6 - * @deprecated in 2.5 - */ - @Parameter( property = "verbose", defaultValue = "false" ) - private boolean verbose; - - /** - * The token set name to use when outputting the dependency tree. Possible values are whitespace, - * standard or extended, which use whitespace, standard or extended ASCII sets - * respectively. - * - * @since 2.0-alpha-6 - */ - @Parameter( property = "tokens", defaultValue = "standard" ) - private String tokens; - - /** - * A comma-separated list of artifacts to filter the serialized dependency tree by, or null not to - * filter the dependency tree. The artifact syntax is defined by StrictPatternIncludesArtifactFilter. - * - * @see StrictPatternIncludesArtifactFilter - * @since 2.0-alpha-6 - */ - @Parameter( property = "includes" ) - private String includes; - - /** - * A comma-separated list of artifacts to filter from the serialized dependency tree, or null not to - * filter any artifacts from the dependency tree. The artifact syntax is defined by - * StrictPatternExcludesArtifactFilter. - * - * @see StrictPatternExcludesArtifactFilter - * @since 2.0-alpha-6 - */ - @Parameter( property = "excludes" ) - private String excludes; - - /** - * The computed dependency tree root node of the Maven project. - */ - private DependencyNode rootNode; - - /** - * Whether to append outputs into the output file or overwrite it. - * - * @since 2.2 - */ - @Parameter( property = "appendOutput", defaultValue = "false" ) - private boolean appendOutput; - - /** - * Skip plugin execution completely. - * - * @since 2.7 - */ - @Parameter( property = "skip", defaultValue = "false" ) - private boolean skip; - - - // Mojo methods ----------------------------------------------------------- - - /* - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( isSkip() ) - { - getLog().info( "Skipping plugin execution" ); - return; - } - - if ( output != null ) - { - getLog().warn( "The parameter output is deprecated. Use outputFile instead." ); - this.outputFile = output; - } - - ArtifactFilter artifactFilter = createResolvingArtifactFilter(); - - try - { - // TODO: note that filter does not get applied due to MNG-3236 - - rootNode = dependencyGraphBuilder.buildDependencyGraph( project, artifactFilter ); - - String dependencyTreeString = serializeDependencyTree( rootNode ); - - if ( outputFile != null ) - { - DependencyUtil.write( dependencyTreeString, outputFile, this.appendOutput, getLog() ); - - getLog().info( "Wrote dependency tree to: " + outputFile ); - } - else - { - DependencyUtil.log( dependencyTreeString, getLog() ); - } - } - catch ( DependencyGraphBuilderException exception ) - { - throw new MojoExecutionException( "Cannot build project dependency graph", exception ); - } - catch ( IOException exception ) - { - throw new MojoExecutionException( "Cannot serialise project dependency graph", exception ); - } - } - - // public methods --------------------------------------------------------- - - /** - * Gets the Maven project used by this mojo. - * - * @return the Maven project - */ - public MavenProject getProject() - { - return project; - } - - /** - * Gets the computed dependency graph root node for the Maven project. - * - * @return the dependency tree root node - */ - public DependencyNode getDependencyGraph() - { - return rootNode; - } - - public boolean isSkip() - { - return skip; - } - - public void setSkip( boolean skip ) - { - this.skip = skip; - } - - // private methods -------------------------------------------------------- - - /** - * Gets the artifact filter to use when resolving the dependency tree. - * - * @return the artifact filter - */ - private ArtifactFilter createResolvingArtifactFilter() - { - ArtifactFilter filter; - - // filter scope - if ( scope != null ) - { - getLog().debug( "+ Resolving dependency tree for scope '" + scope + "'" ); - - filter = new ScopeArtifactFilter( scope ); - } - else - { - filter = null; - } - - return filter; - } - - /** - * Serializes the specified dependency tree to a string. - * - * @param rootNode the dependency tree root node to serialize - * @return the serialized dependency tree - */ - private String serializeDependencyTree( DependencyNode rootNode ) - { - StringWriter writer = new StringWriter(); - - DependencyNodeVisitor visitor = getSerializingDependencyNodeVisitor( writer ); - - // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only - visitor = new BuildingDependencyNodeVisitor( visitor ); - - DependencyNodeFilter filter = createDependencyNodeFilter(); - - if ( filter != null ) - { - CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor(); - DependencyNodeVisitor firstPassVisitor = new FilteringDependencyNodeVisitor( collectingVisitor, filter ); - rootNode.accept( firstPassVisitor ); - - DependencyNodeFilter secondPassFilter = - new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() ); - visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter ); - } - - rootNode.accept( visitor ); - - return writer.toString(); - } - - public DependencyNodeVisitor getSerializingDependencyNodeVisitor( Writer writer ) - { - if ( "graphml".equals( outputType ) ) - { - return new GraphmlDependencyNodeVisitor( writer ); - } - else if ( "tgf".equals( outputType ) ) - { - return new TGFDependencyNodeVisitor( writer ); - } - else if ( "dot".equals( outputType ) ) - { - return new DOTDependencyNodeVisitor( writer ); - } - else - { - return new SerializingDependencyNodeVisitor( writer, toTreeTokens( tokens ) ); - } - } - - /** - * Gets the tree tokens instance for the specified name. - * - * @param tokens the tree tokens name - * @return the TreeTokens instance - */ - private TreeTokens toTreeTokens( String tokens ) - { - TreeTokens treeTokens; - - if ( "whitespace".equals( tokens ) ) - { - getLog().debug( "+ Using whitespace tree tokens" ); - - treeTokens = SerializingDependencyNodeVisitor.WHITESPACE_TOKENS; - } - else if ( "extended".equals( tokens ) ) - { - getLog().debug( "+ Using extended tree tokens" ); - - treeTokens = SerializingDependencyNodeVisitor.EXTENDED_TOKENS; - } - else - { - treeTokens = SerializingDependencyNodeVisitor.STANDARD_TOKENS; - } - - return treeTokens; - } - - /** - * Gets the dependency node filter to use when serializing the dependency tree. - * - * @return the dependency node filter, or null if none required - */ - private DependencyNodeFilter createDependencyNodeFilter() - { - List filters = new ArrayList(); - - // filter node states - /*if ( !verbose ) - { - getLog().debug( "+ Filtering omitted nodes from dependency tree" ); - - filters.add( StateDependencyNodeFilter.INCLUDED ); - }*/ - - // filter includes - if ( includes != null ) - { - List patterns = Arrays.asList( includes.split( "," ) ); - - getLog().debug( "+ Filtering dependency tree by artifact include patterns: " + patterns ); - - ArtifactFilter artifactFilter = new StrictPatternIncludesArtifactFilter( patterns ); - filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) ); - } - - // filter excludes - if ( excludes != null ) - { - List patterns = Arrays.asList( excludes.split( "," ) ); - - getLog().debug( "+ Filtering dependency tree by artifact exclude patterns: " + patterns ); - - ArtifactFilter artifactFilter = new StrictPatternExcludesArtifactFilter( patterns ); - filters.add( new ArtifactDependencyNodeFilter( artifactFilter ) ); - } - - return filters.isEmpty() ? null : new AndDependencyNodeFilter( filters ); - } - - //following is required because the version handling in maven code - //doesn't work properly. I ripped it out of the enforcer rules. - - - /** - * Copied from Artifact.VersionRange. This is tweaked to handle singular ranges properly. Currently the default - * containsVersion method assumes a singular version means allow everything. This method assumes that "2.0.4" == - * "[2.0.4,)" - * - * @param allowedRange range of allowed versions. - * @param theVersion the version to be checked. - * @return true if the version is contained by the range. - */ - public static boolean containsVersion( VersionRange allowedRange, ArtifactVersion theVersion ) - { - ArtifactVersion recommendedVersion = allowedRange.getRecommendedVersion(); - if ( recommendedVersion == null ) - { - @SuppressWarnings ("unchecked") List restrictions = allowedRange.getRestrictions(); - for ( Restriction restriction : restrictions ) - { - if ( restriction.containsVersion( theVersion ) ) - { - return true; - } - } - } - - // only singular versions ever have a recommendedVersion - return recommendedVersion.compareTo( theVersion ) <= 0; - } - -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/AbstractSerializingVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/AbstractSerializingVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/AbstractSerializingVisitor.java 2009-02-16 13:38:32.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/AbstractSerializingVisitor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -package org.apache.maven.plugin.dependency.treeSerializers ; - -/* - * 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.io.PrintWriter; -import java.io.Writer; - -/** - * Abstract class for visitors performing serialization. - * - * @author Jerome Creignou - */ -public abstract class AbstractSerializingVisitor -{ - - /** - * The writer to serialize to. - */ - protected final PrintWriter writer; - - /** - * Constructor. - *

- * Build a new AbstractSerializingDependencyNodeVisitor with the writer to serialize to. - *

- * - * @param writer the writer to serialize to. - */ - public AbstractSerializingVisitor( Writer writer ) - { - if ( writer instanceof PrintWriter ) - { - this.writer = (PrintWriter) writer; - } - else - { - this.writer = new PrintWriter( writer, true ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/DOTDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/DOTDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/DOTDependencyNodeVisitor.java 2012-09-13 13:53:19.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/DOTDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,91 +0,0 @@ -package org.apache.maven.plugin.dependency.treeSerializers; - -/* - * 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 org.apache.maven.shared.dependency.graph.DependencyNode; -import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; - -import java.io.Writer; -import java.util.List; - -/** - * A dependency node visitor that serializes visited nodes to DOT format - * http://en.wikipedia.org/wiki/DOT_language - * - * @author Pi Song - * @since 2.1 - */ -public class DOTDependencyNodeVisitor - extends AbstractSerializingVisitor - implements DependencyNodeVisitor -{ - - /** - * Constructor. - * - * @param writer the writer to write to. - */ - public DOTDependencyNodeVisitor( Writer writer ) - { - super( writer ); - } - - - /** - * {@inheritDoc} - */ - public boolean visit( DependencyNode node ) - { - if ( node.getParent() == null || node.getParent() == node ) - { - writer.write( "digraph \"" + node.toNodeString() + "\" { \n" ); - } - - // Generate "currentNode -> Child" lines - - List children = node.getChildren(); - - for ( DependencyNode child : children ) - { - StringBuilder sb = new StringBuilder(); - sb.append( "\t\"" ); - sb.append( node.toNodeString() ); - sb.append( "\" -> \"" ); - sb.append( child.toNodeString() ); - sb.append( "\" ; " ); - writer.println( sb.toString() ); - } - - return true; - } - - /** - * {@inheritDoc} - */ - public boolean endVisit( DependencyNode node ) - { - if ( node.getParent() == null || node.getParent() == node ) - { - writer.write( " } " ); - } - return true; - } - -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/GraphmlDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/GraphmlDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/GraphmlDependencyNodeVisitor.java 2012-07-24 20:24:01.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/GraphmlDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,123 +0,0 @@ -package org.apache.maven.plugin.dependency.treeSerializers ; - -/* - * 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.io.Writer; - -import org.apache.maven.shared.dependency.graph.DependencyNode; -import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; - -/** - * A dependency node visitor that serializes visited nodes to a writer using the graphml format. - * {@link http://graphml.graphdrawing.org/} - * - * @author Jerome Creignou - * @since 2.1 - */ -public class GraphmlDependencyNodeVisitor - extends AbstractSerializingVisitor - implements DependencyNodeVisitor -{ - - /** - * Graphml xml file header. Define Schema and root element. We also define 2 key as meta data. - */ - private static final String GRAPHML_HEADER = - " " - + "\n" - + " \n" - + " \n" - + "\n"; - - /** - * Graphml xml file footer. - */ - private static final String GRAPHML_FOOTER = ""; - - /** - * Constructor. - * - * @param writer the writer to write to. - */ - public GraphmlDependencyNodeVisitor( Writer writer ) - { - super( writer ); - } - - /** - * {@inheritDoc} - */ - public boolean endVisit( DependencyNode node ) - { - if ( node.getParent() == null || node.getParent() == node ) - { - writer.write( GRAPHML_FOOTER ); - } - else - { - DependencyNode p = node.getParent(); - writer.print( "" ); - if ( node.getArtifact().getScope() != null ) - { - // add Edge label - writer.print( "" + node.getArtifact().getScope() - + "" ); - } - writer.println( "" ); - } - return true; - } - - /** - * {@inheritDoc} - */ - public boolean visit( DependencyNode node ) - { - if ( node.getParent() == null || node.getParent() == node ) - { - writer.write( GRAPHML_HEADER ); - } - // write node - writer.print( "" ); - // add node label - writer.print( "" + node.toNodeString() - + "" ); - writer.println( "" ); - return true; - } - - /** - * Generate a unique id from a DependencyNode. - *

- * Current implementation is rather simple and uses hashcode. - *

- * - * @param node the DependencyNode to use. - * @return the unique id. - */ - private static String generateId( DependencyNode node ) - { - return String.valueOf( node.hashCode() ); - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/TGFDependencyNodeVisitor.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/TGFDependencyNodeVisitor.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/TGFDependencyNodeVisitor.java 2012-09-13 13:53:19.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/treeSerializers/TGFDependencyNodeVisitor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,158 +0,0 @@ -package org.apache.maven.plugin.dependency.treeSerializers ; - -/* - * 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.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.shared.dependency.graph.DependencyNode; -import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; - -/** - * A dependency node visitor that serializes visited nodes to a writer using the TGF format. - * - * http://en.wikipedia.org/wiki/Trivial_Graph_Format - * - * @author Jerome Creignou - * @since 2.1 - */ -public class TGFDependencyNodeVisitor - extends AbstractSerializingVisitor - implements DependencyNodeVisitor -{ - - /** - * Utiity class to write an Edge. - * - * @author Jerome Creignou - */ - static final class EdgeAppender - { - /** - * Edge start. - */ - private DependencyNode from; - - /** - * Edge end. - */ - private DependencyNode to; - - /** - * Edge label. (optional) - */ - private String label; - - /** - * Build a new EdgeAppender. - * - * @param from edge start. - * @param to edge end - * @param label optional label. - */ - public EdgeAppender( DependencyNode from, DependencyNode to, String label ) - { - super(); - this.from = from; - this.to = to; - this.label = label; - } - - /** - * build a string representing the edge. - */ - public String toString() - { - StringBuilder result = new StringBuilder( generateId( from ) ); - result.append( ' ' ).append( generateId( to ) ); - if ( label != null ) - { - result.append( ' ' ).append( label ); - } - return result.toString(); - } - - } - - /** - * List of edges. - */ - private List edges = new ArrayList(); - - /** - * Constructor. - * - * @param writer the writer to write to. - */ - public TGFDependencyNodeVisitor( Writer writer ) - { - super( writer ); - } - - /** - * {@inheritDoc} - */ - public boolean endVisit( DependencyNode node ) - { - if ( node.getParent() == null || node.getParent() == node ) - { - // dump edges on last node endVisit - writer.println( "#" ); - for ( EdgeAppender edge : edges ) - { - writer.println( edge.toString() ); - } - } - else - { - DependencyNode p = node.getParent(); - // using scope as edge label. - edges.add( new EdgeAppender( p, node, node.getArtifact().getScope() ) ); - } - return true; - } - - /** - * {@inheritDoc} - */ - public boolean visit( DependencyNode node ) - { - // write node - writer.write( generateId( node ) ); - writer.write( " " ); - writer.println( node.toNodeString() ); - return true; - } - - /** - * Generate a unique id from a DependencyNode. - *

- * Current implementation is rather simple and uses hashcode. - *

- * - * @param node the DependencyNode to use. - * @return the unique id. - */ - private static String generateId( DependencyNode node ) - { - return String.valueOf( node.hashCode() ); - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/UnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,141 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; - -import java.io.File; - -/** - * Goal that unpacks the project dependencies from the repository to a defined - * location. - * - * @author Brian Fox - * @version $Id: UnpackDependenciesMojo.java 1451088 2013-02-28 04:22:41Z brianf $ - * @since 1.0 - */ -@Mojo( name = "unpack-dependencies", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true ) -public class UnpackDependenciesMojo - extends AbstractFromDependenciesMojo -{ - /** - * A comma separated list of file patterns to include when unpacking the - * artifact. i.e. **\/*.xml,**\/*.properties - * NOTE: Excludes patterns override the includes. - * (component code = return isIncluded( name ) AND !isExcluded( name );) - * - * @since 2.0 - */ - @Parameter( property = "mdep.unpack.includes" ) - private String includes; - - /** - * A comma separated list of file patterns to exclude when unpacking the - * artifact. i.e. **\/*.xml,**\/*.properties - * NOTE: Excludes patterns override the includes. - * (component code = return isIncluded( name ) AND !isExcluded( name );) - * - * @since 2.0 - */ - @Parameter( property = "mdep.unpack.excludes" ) - private String excludes; - - /** - * Main entry into mojo. This method gets the dependencies and iterates - * through each one passing it to DependencyUtil.unpackFile(). - * - * @throws MojoExecutionException with a message if an error occurs. - * @see #getDependencies - * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager, - * Log) - */ - protected void doExecute() - throws MojoExecutionException - { - DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact ); - - for ( Artifact artifact : dss.getResolvedDependencies() ) - { - File destDir; - destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, - useSubDirectoryPerArtifact, useRepositoryLayout, - stripVersion, outputDirectory, artifact ); - unpack( artifact, destDir, getIncludes(), getExcludes() ); - DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory ); - handler.setMarker(); - } - - for ( Artifact artifact : dss.getSkippedDependencies() ) - { - getLog().info( artifact.getFile().getName() + " already exists in destination." ); - } - } - - protected ArtifactsFilter getMarkedArtifactFilter() - { - return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer, - new DefaultFileMarkerHandler( this.markersDirectory ) ); - } - - /** - * @return Returns a comma separated list of excluded items - */ - public String getExcludes() - { - return DependencyUtil.cleanToBeTokenizedString( this.excludes ); - } - - /** - * @param excludes A comma separated list of items to exclude - * i.e. **\/*.xml, **\/*.properties - */ - public void setExcludes( String excludes ) - { - this.excludes = excludes; - } - - /** - * @return Returns a comma separated list of included items - */ - public String getIncludes() - { - return DependencyUtil.cleanToBeTokenizedString( this.includes ); - } - - /** - * @param includes A comma separated list of items to include - * i.e. **\/*.xml, **\/*.properties - */ - public void setIncludes( String includes ) - { - this.includes = includes; - } -} diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyStatusSets.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyStatusSets.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyStatusSets.java 2012-09-13 13:53:19.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyStatusSets.java 2013-05-13 20:06:08.000000000 +0000 @@ -23,14 +23,17 @@ * */ +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; /** * @author Brian Fox - * @version $Id: DependencyStatusSets.java 1384337 2012-09-13 13:53:19Z olamy $ + * @version $Id: DependencyStatusSets.java 1482068 2013-05-13 20:06:08Z pgier $ */ public class DependencyStatusSets { @@ -141,6 +144,11 @@ public String getOutput( boolean outputAbsoluteArtifactFilename, boolean outputScope ) { + return getOutput(outputAbsoluteArtifactFilename, outputScope, false); + } + + public String getOutput( boolean outputAbsoluteArtifactFilename, boolean outputScope, boolean sort ) + { StringBuilder sb = new StringBuilder(); sb.append( "\n" ); sb.append( "The following files have been resolved:\n" ); @@ -150,27 +158,7 @@ } else { - for ( Artifact artifact : resolvedDependencies ) - { - String artifactFilename = null; - if ( outputAbsoluteArtifactFilename ) - { - try - { - // we want to print the absolute file name here - artifactFilename = artifact.getFile().getAbsoluteFile().getPath(); - } - catch ( NullPointerException e ) - { - // ignore the null pointer, we'll output a null string - artifactFilename = null; - } - } - - String id = outputScope ? artifact.toString() : artifact.getId(); - - sb.append( " " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) + "\n" ); - } + sb.append( buildArtifactListOutput( resolvedDependencies, outputAbsoluteArtifactFilename, outputScope, sort ) ); } if ( this.skippedDependencies != null && !this.skippedDependencies.isEmpty() ) @@ -179,10 +167,7 @@ sb.append( "The following files were skipped:\n" ); Set skippedDependencies = new LinkedHashSet(); skippedDependencies.addAll( this.skippedDependencies ); - for ( Artifact artifact : skippedDependencies ) - { - sb.append( " " + artifact.getId() + "\n" ); - } + sb.append( buildArtifactListOutput( skippedDependencies, outputAbsoluteArtifactFilename, outputScope, sort ) ); } if ( this.unResolvedDependencies != null && !this.unResolvedDependencies.isEmpty() ) @@ -191,13 +176,46 @@ sb.append( "The following files have NOT been resolved:\n" ); Set unResolvedDependencies = new LinkedHashSet(); unResolvedDependencies.addAll( this.unResolvedDependencies ); - for ( Artifact artifact : unResolvedDependencies ) - { - sb.append( " " + artifact.getId() + "\n" ); - } + sb.append( buildArtifactListOutput( unResolvedDependencies, outputAbsoluteArtifactFilename, outputScope, sort ) ); } sb.append( "\n" ); return sb.toString(); } + + private StringBuilder buildArtifactListOutput(Set artifacts, boolean outputAbsoluteArtifactFilename, boolean outputScope, boolean sort ) + { + StringBuilder sb = new StringBuilder(); + List artifactStringList = new ArrayList(); + for ( Artifact artifact : artifacts ) + { + String artifactFilename = null; + if ( outputAbsoluteArtifactFilename ) + { + try + { + // we want to print the absolute file name here + artifactFilename = artifact.getFile().getAbsoluteFile().getPath(); + } + catch ( NullPointerException e ) + { + // ignore the null pointer, we'll output a null string + artifactFilename = null; + } + } + + String id = outputScope ? artifact.toString() : artifact.getId(); + + artifactStringList.add( " " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) + "\n" ); + } + if ( sort ) + { + Collections.sort( artifactStringList ); + } + for (String artifactString : artifactStringList) + { + sb.append( artifactString ); + } + return sb; + } } diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java 2012-10-16 22:23:33.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/DependencyUtil.java 2013-05-12 14:01:17.000000000 +0000 @@ -34,7 +34,7 @@ * Utility class with static helper methods * * @author Brian Fox - * @version $Id: DependencyUtil.java 1399024 2012-10-16 22:23:33Z hboutemy $ + * @version $Id: DependencyUtil.java 1481559 2013-05-12 14:01:17Z hboutemy $ */ public final class DependencyUtil { @@ -90,8 +90,33 @@ * @return Formatted file name in the format * [groupId].artifactId-[version]-[classifier].[type] */ + public static String getFormattedFileName( Artifact artifact, boolean removeVersion, boolean prependGroupId, + boolean useBaseVersion ) + { + return getFormattedFileName( artifact, removeVersion, prependGroupId, useBaseVersion, false ); + } + + /** + * Builds the file name. If removeVersion is set, then the file name must be + * reconstructed from the groupId (if prependGroupId is true) artifactId, + * Classifier (if used) and Type. + * Otherwise, this method returns the artifact file name. + * + * @param artifact + * File to be formatted. + * @param removeVersion + * Specifies if the version should be removed from the file name. + * @param prependGroupId + * Specifies if the groupId should be prepended to the file name. + * @param useBaseVersion + * Specifies if the baseVersion of the artifact should be used instead of the version. + * @param removeClassifier + * Specifies if the classifier of the artifact should be remved from the file name. + * @return Formatted file name in the format + * [groupId].artifactId-[version]-[classifier].[type] + */ public static String getFormattedFileName( Artifact artifact, boolean removeVersion, boolean prependGroupId, - boolean useBaseVersion ) + boolean useBaseVersion, boolean removeClassifier ) { StringBuilder destFileName = new StringBuilder(); @@ -119,7 +144,7 @@ String classifierString = ""; - if ( StringUtils.isNotEmpty( artifact.getClassifier() ) ) + if ( !removeClassifier && StringUtils.isNotEmpty( artifact.getClassifier() ) ) { classifierString = "-" + artifact.getClassifier(); } @@ -129,7 +154,7 @@ return destFileName.toString(); } - + /** * Formats the outputDirectory based on type. * @@ -181,30 +206,27 @@ sb.append( artifact.getArtifactId() ); + if ( !removeVersion ) + { + sb.append( "-" ); + sb.append( artifact.getVersion() ); + } + if ( StringUtils.isNotEmpty( artifact.getClassifier() ) ) { sb.append( "-" ); sb.append( artifact.getClassifier() ); } - if ( !removeVersion ) + // if the classifier and type are the same (sources), then don't + // repeat. + // avoids names like foo-sources-sources + if ( !StringUtils.equals( artifact.getClassifier(), artifact.getType() ) ) { sb.append( "-" ); - sb.append( artifact.getVersion() ); - sb.append( "-" ); sb.append( artifact.getType() ); } - else - { - // if the classifier and type are the same (sources), then don't - // repeat. - // avoids names like foo-sources-sources - if ( !StringUtils.equals( artifact.getClassifier(), artifact.getType() ) ) - { - sb.append( "-" ); - sb.append( artifact.getType() ); - } - } + return sb.toString(); } diff -Nru maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java --- maven-dependency-plugin-2.7/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java 2012-07-30 20:32:05.000000000 +0000 +++ maven-dependency-plugin-2.8/src/main/java/org/apache/maven/plugin/dependency/utils/filters/DestFileFilter.java 2013-04-02 10:28:02.000000000 +0000 @@ -32,7 +32,7 @@ /** * @author Brian Fox - * @version $Id: DestFileFilter.java 1367274 2012-07-30 20:32:05Z hboutemy $ + * @version $Id: DestFileFilter.java 1463473 2013-04-02 10:28:02Z olamy $ */ public class DestFileFilter extends AbstractArtifactsFilter @@ -53,6 +53,8 @@ private boolean useRepositoryLayout; private boolean removeVersion; + + private boolean removeClassifier; private File outputFileDirectory; @@ -66,6 +68,7 @@ useSubDirectoryPerType = false; useSubDirectoryPerScope = false; removeVersion = false; + removeClassifier = false; } public DestFileFilter( boolean overWriteReleases, boolean overWriteSnapshots, boolean overWriteIfNewer, @@ -190,6 +193,23 @@ { this.removeVersion = removeVersion; } + + /** + * @return Returns the removeClassifier. + */ + public boolean isRemoveClassifier() + { + return this.removeClassifier; + } + + /** + * @param removeClassifier + * The removeClassifier to set. + */ + public void setRemoveClassifier( boolean removeClassifier ) + { + this.removeClassifier = removeClassifier; + } /** * @return Returns the useSubDirectoryPerArtifact. diff -Nru maven-dependency-plugin-2.7/src/site/apt/index.apt maven-dependency-plugin-2.8/src/site/apt/index.apt --- maven-dependency-plugin-2.7/src/site/apt/index.apt 2012-11-22 12:45:44.000000000 +0000 +++ maven-dependency-plugin-2.8/src/site/apt/index.apt 2013-05-12 12:37:19.000000000 +0000 @@ -61,7 +61,7 @@ optionally transitive dependencies and copies them to a specified location, stripping the version if desired. This goal can also be run from the command line. - *{{{./get-mojo.html}dependency:get}} downloads a single artifact transitively from a specified remote repository. + *{{{./get-mojo.html}dependency:get}} resolves a single artifact, eventually transitively, from a specified remote repository. *{{{./go-offline-mojo.html}dependency:go-offline}} tells Maven to resolve everything this project is dependent on (dependencies, plugins, reports) in preparation for going offline. diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java 2008-12-21 22:56:51.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java 2013-05-12 09:10:35.000000000 +0000 @@ -22,6 +22,10 @@ import java.io.File; import java.io.IOException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.fromDependencies.AbstractDependencyFilterMojo; import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; import org.apache.maven.plugin.testing.AbstractMojoTestCase; @@ -75,4 +79,19 @@ stubFactory = null; } + protected void setResolver( AbstractDependencyMojo mojo, ArtifactResolver resolver ) + { + mojo.resolver = resolver; + } + + protected void setSilent( AbstractDependencyMojo mojo, boolean silent ) + { + mojo.silent = silent; + } + + protected void copyFile( AbstractDependencyMojo mojo, File artifact, File destFile ) + throws MojoExecutionException + { + mojo.copyFile( artifact, destFile ); + } } diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDepMgt.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDepMgt.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDepMgt.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDepMgt.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,250 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Exclusion; +import org.apache.maven.plugin.dependency.analyze.AnalyzeDepMgt; +import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; +import org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub; +import org.apache.maven.project.MavenProject; + +public class TestAnalyzeDepMgt + extends TestCase +{ + + AnalyzeDepMgt mojo; + + DependencyArtifactStubFactory stubFactory; + + Dependency exclusion; + + Exclusion ex; + + Artifact exclusionArtifact; + + DependencyManagement depMgt; + DependencyManagement depMgtNoExclusions; + protected void setUp() + throws Exception + { + + mojo = new AnalyzeDepMgt(); + MavenProject project = new DependencyProjectStub(); + + stubFactory = new DependencyArtifactStubFactory( new File( "" ), false ); + + Set allArtifacts = stubFactory.getMixedArtifacts(); + Set directArtifacts = stubFactory.getClassifiedArtifacts(); + + + exclusionArtifact = stubFactory.getReleaseArtifact(); + directArtifacts.add( exclusionArtifact ); + ex = new Exclusion(); + ex.setArtifactId( exclusionArtifact.getArtifactId() ); + ex.setGroupId( exclusionArtifact.getGroupId() ); + + exclusion = new Dependency(); + exclusion.setArtifactId( exclusionArtifact.getArtifactId() ); + exclusion.setGroupId( exclusionArtifact.getGroupId() ); + exclusion.setType( exclusionArtifact.getType() ); + exclusion.setClassifier( "" ); + exclusion.setVersion( "3.0" ); + + exclusion.addExclusion( ex ); + List list = new ArrayList(); + list.add( exclusion ); + + depMgt = new DependencyManagement(); + depMgt.setDependencies( list ); + + + project.setArtifacts( allArtifacts ); + project.setDependencyArtifacts( directArtifacts ); + + mojo.setProject( project ); + + } + + public void testGetManagementKey() + throws IOException + { + Dependency dep = new Dependency(); + dep.setArtifactId( "artifact" ); + dep.setClassifier( "class" ); + dep.setGroupId( "group" ); + dep.setType( "type" ); + + // version isn't used in the key, it can be different + dep.setVersion( "1.1" ); + + Artifact artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", + "class" ); + + // basic case ok + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + + // now change each one and make sure it fails, then set it back and make + // sure it's ok before + // testing the next one + dep.setType( "t" ); + assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); + + dep.setType( "type" ); + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + + dep.setArtifactId( "a" ); + assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); + + dep.setArtifactId( "artifact" ); + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + + dep.setClassifier( "c" ); + assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); + + dep.setClassifier( "class" ); + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + + dep.setGroupId( "g" ); + assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); + + dep.setGroupId( "group" ); + dep.setClassifier( null ); + artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", null ); + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + + dep.setClassifier( "" ); + artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", "" ); + assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); + } + + public void testAddExclusions() + { + + assertEquals( 0, mojo.addExclusions( null ).size() ); + + List list = new ArrayList(); + list.add( ex ); + Map map = mojo.addExclusions( list ); + + assertEquals( 1,map.size() ); + assertTrue( map.containsKey( mojo.getExclusionKey( ex ) ) ); + assertSame( ex, map.get( mojo.getExclusionKey( ex ) ) ); + } + + public void testGetExclusionErrors() + { + List list = new ArrayList(); + list.add( ex ); + + // already tested this method so I can trust it. + Map map = mojo.addExclusions( list ); + + List l = mojo.getExclusionErrors( map, mojo.getProject().getArtifacts() ); + + assertEquals( 1, l.size() ); + + assertEquals( mojo.getExclusionKey( ex ), mojo.getExclusionKey(( Artifact) l.get( 0 ) ) ); + } + + public void testGetMismatch() + throws IOException + { + Map depMgtMap = new HashMap(); + + depMgtMap.put( exclusion.getManagementKey(), exclusion ); + + Map results = mojo.getMismatch( depMgtMap, mojo.getProject().getArtifacts() ); + + assertEquals( 1, results.size() ); + // the release artifact is used to create the exclusion + assertTrue( results.containsKey( stubFactory.getReleaseArtifact() ) ); + assertSame( exclusion, results.get( stubFactory.getReleaseArtifact() ) ); + } + + public void testMojo() throws IOException + { + mojo.setIgnoreDirect( false ); + try + { + // test with nothing in depMgt + mojo.execute(); + } + catch ( Exception e ) + { + e.printStackTrace(); + fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); + } + + try + { + DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); + project.setDependencyManagement( depMgt ); + // test with exclusion + mojo.execute(); + } + catch ( Exception e ) + { + e.printStackTrace(); + fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); + } + + try + { + DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); + project.setDependencyManagement( depMgt ); + // test with exclusion + mojo.setFailBuild( true ); + mojo.execute(); + fail( "Expected exception to fail the build." ); + } + catch ( Exception e ) + { + System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); + } + + try + { + DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); + project.setDependencyManagement( depMgt ); + // test with exclusion + mojo.setFailBuild( true ); + mojo.setIgnoreDirect( true ); + mojo.execute(); + } + catch ( Exception e ) + { + e.printStackTrace(); + fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDuplicateMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDuplicateMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDuplicateMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/analyze/TestAnalyzeDuplicateMojo.java 2013-05-12 13:10:48.000000000 +0000 @@ -0,0 +1,224 @@ +package org.apache.maven.plugin.dependency.analyze; + +/* + * 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.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.analyze.AnalyzeDuplicateMojo; +import org.apache.maven.plugin.logging.Log; + +/** + * @author Vincent Siveton + * @version $Id: TestAnalyzeDuplicateMojo.java 1481550 2013-05-12 13:10:48Z hboutemy $ + */ +public class TestAnalyzeDuplicateMojo + extends AbstractDependencyMojoTestCase +{ + public void testDuplicate() + throws Exception + { + File testPom = + new File( getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config.xml" ); + AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo( "analyze-duplicate", testPom ); + assertNotNull( mojo ); + DuplicateLog log = new DuplicateLog(); + mojo.setLog( log ); + mojo.execute(); + + assertTrue( log.getContent().indexOf( + "List of duplicate dependencies defined in in " + + "your pom.xml" ) != -1 ); + assertTrue( log.getContent().indexOf( "junit:junit:jar" ) != -1 ); + } + + public void testDuplicate2() + throws Exception + { + File testPom = + new File( getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config2.xml" ); + AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo( "analyze-duplicate", testPom ); + assertNotNull( mojo ); + DuplicateLog log = new DuplicateLog(); + mojo.setLog( log ); + mojo.execute(); + + assertTrue( log.getContent().indexOf( + "List of duplicate dependencies defined in in " + + "your pom.xml" ) != -1 ); + assertTrue( log.getContent().indexOf( "junit:junit:jar" ) != -1 ); + } + + class DuplicateLog + implements Log + { + StringBuilder sb = new StringBuilder(); + + /** {@inheritDoc} */ + public void debug( CharSequence content ) + { + print( "debug", content ); + } + + /** {@inheritDoc} */ + public void debug( CharSequence content, Throwable error ) + { + print( "debug", content, error ); + } + + /** {@inheritDoc} */ + public void debug( Throwable error ) + { + print( "debug", error ); + } + + /** {@inheritDoc} */ + public void info( CharSequence content ) + { + print( "info", content ); + } + + /** {@inheritDoc} */ + public void info( CharSequence content, Throwable error ) + { + print( "info", content, error ); + } + + /** {@inheritDoc} */ + public void info( Throwable error ) + { + print( "info", error ); + } + + /** {@inheritDoc} */ + public void warn( CharSequence content ) + { + print( "warn", content ); + } + + /** {@inheritDoc} */ + public void warn( CharSequence content, Throwable error ) + { + print( "warn", content, error ); + } + + /** {@inheritDoc} */ + public void warn( Throwable error ) + { + print( "warn", error ); + } + + /** {@inheritDoc} */ + public void error( CharSequence content ) + { + System.err.println( "[error] " + content.toString() ); + } + + /** {@inheritDoc} */ + public void error( CharSequence content, Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() ); + } + + /** + * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable) + */ + public void error( Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.err.println( "[error] " + sWriter.toString() ); + } + + /** + * @see org.apache.maven.plugin.logging.Log#isDebugEnabled() + */ + public boolean isDebugEnabled() + { + // TODO: Not sure how best to set these for this implementation... + return false; + } + + /** + * @see org.apache.maven.plugin.logging.Log#isInfoEnabled() + */ + public boolean isInfoEnabled() + { + return true; + } + + /** + * @see org.apache.maven.plugin.logging.Log#isWarnEnabled() + */ + public boolean isWarnEnabled() + { + return true; + } + + /** + * @see org.apache.maven.plugin.logging.Log#isErrorEnabled() + */ + public boolean isErrorEnabled() + { + return true; + } + + private void print( String prefix, CharSequence content ) + { + sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n" ); + } + + private void print( String prefix, Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + sb.append( "[" + prefix + "] " ).append( sWriter.toString() ).append( "\n" ); + } + + private void print( String prefix, CharSequence content, Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n\n" ) + .append( sWriter.toString() ).append( "\n" ); + } + + protected String getContent() + { + return sb.toString(); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java 2013-02-12 21:56:22.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java 2013-05-12 08:45:09.000000000 +0000 @@ -54,7 +54,7 @@ File testPom = new File( getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml" ); mojo = (CopyMojo) lookupMojo( "copy", testPom ); mojo.setOutputDirectory( new File( this.testDir, "outputDirectory" ) ); - mojo.silent = true; + setSilent( mojo, true ); assertNotNull( mojo ); assertNotNull( mojo.getProject() ); @@ -70,7 +70,7 @@ public ArtifactItem getSingleArtifactItem( boolean removeVersion, boolean useBaseVersion ) throws MojoExecutionException { - List list = mojo.getProcessedArtifactItems(new ProcessArtifactItemsRequest( removeVersion, false, useBaseVersion )); + List list = mojo.getProcessedArtifactItems(new ProcessArtifactItemsRequest( removeVersion, false, useBaseVersion, false )); return list.get( 0 ); } @@ -118,6 +118,7 @@ assertFalse( themojo.isStripVersion() ); assertFalse( themojo.isSkip() ); + assertFalse( themojo.isStripClassifier() ); } public void testCopyFile() @@ -217,6 +218,22 @@ assertFilesExist( list, true ); } + public void testCopyStripClassifierSetInMojo() + throws Exception + { + List list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() ); + ArtifactItem item = (ArtifactItem) list.get( 0 ); + item.setOutputDirectory( new File( mojo.getOutputDirectory(), "testOverride" ) ); + mojo.setStripClassifier( true ); + + mojo.setArtifactItems( list ); + + mojo.execute(); + assertEquals( DependencyUtil.getFormattedFileName( item.getArtifact(), false, false, false, true ), item.getDestFileName() ); + + assertFilesExist( list, true ); + } + public void testNonClassifierStrip() throws Exception { @@ -535,7 +552,7 @@ { try { - mojo.getProcessedArtifactItems( new ProcessArtifactItemsRequest( false, false, false ) ); + mojo.getProcessedArtifactItems( new ProcessArtifactItemsRequest( false, false, false, false ) ); fail( "Expected Exception" ); } catch ( MojoExecutionException e ) diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java 2013-05-12 08:29:11.000000000 +0000 @@ -0,0 +1,317 @@ +package org.apache.maven.plugin.dependency.fromConfiguration; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; +import org.apache.maven.plugin.dependency.fromConfiguration.UnpackMojo; +import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; +import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; +import org.apache.maven.plugin.testing.stubs.StubArtifactCollector; +import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class TestIncludeExcludeUnpackMojo + extends AbstractDependencyMojoTestCase +{ + private final String PACKED_FILE = "test.zip"; + + private final String UNPACKED_FILE_PREFIX = "test"; + + private final String UNPACKED_FILE_SUFFIX = ".txt"; + + private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE; + + UnpackMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "unpack", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml" ); + mojo = (UnpackMojo) lookupMojo( "unpack", testPom ); + mojo.setOutputDirectory( new File( this.testDir, "outputDirectory" ) ); + // mojo.silent = true; + + // it needs to get the archivermanager + //stubFactory.setUnpackableFile( mojo.getArchiverManager() ); + // i'm using one file repeatedly to archive so I can test the name + // programmatically. + stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + PACKED_FILE_PATH ) ); + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + List list = new ArrayList( 1 ); + list.add( item ); + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + + mojo.setArchiverManager( (ArchiverManager) lookup( ArchiverManager.ROLE ) ); + + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); + mojo.setMarkersDirectory( new File( this.testDir, "markers" ) ); + mojo.setArtifactCollector( new StubArtifactCollector() ); + mojo.setArtifactItems( list ); + } + + protected void tearDown() + { + super.tearDown(); + + mojo = null; + System.gc(); + } + + public void assertMarkerFiles( Collection items, boolean exist ) + { + for ( ArtifactItem item : items ) + { + assertMarkerFile( exist, item ); + } + } + + public void assertMarkerFile( boolean val, ArtifactItem item ) + { + UnpackFileMarkerHandler handle = new UnpackFileMarkerHandler( item, mojo.getMarkersDirectory() ); + try + { + assertEquals( val, handle.isMarkerSet() ); + } + catch ( MojoExecutionException e ) + { + fail( e.getLongMessage() ); + } + } + + private void assertUnpacked( boolean unpacked, String fileName ) + { + File destFile = new File( mojo.getOutputDirectory().getAbsolutePath(), fileName ); + assertEquals( unpacked, destFile.exists() ); + } + + /** + * This test will validate that only the 1 and 11 files get unpacked + * + * @throws Exception + */ + public void testUnpackIncludesManyFiles() + throws Exception + { + mojo.setIncludes( "**/*1" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify only the 2 file gets unpacked + * + * @throws Exception + */ + public void testUnpackIncludesSingleFile() + throws Exception + { + mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify all files get unpacked + * + * @throws Exception + */ + public void testUnpackIncludesAllFiles() + throws Exception + { + mojo.setIncludes( "**/*" ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will validate that only the 2 and 3 files get unpacked + * + * @throws Exception + */ + public void testUnpackExcludesManyFiles() + throws Exception + { + mojo.setExcludes( "**/*1" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify only the 1, 11 & 3 files get unpacked + * + * @throws Exception + */ + public void testUnpackExcludesSingleFile() + throws Exception + { + mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify no files get unpacked + * + * @throws Exception + */ + public void testUnpackExcludesAllFiles() + throws Exception + { + mojo.setExcludes( "**/*" ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testNoIncludeExcludes() + throws Exception + { + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testIncludeArtifactItemOverride() + throws Exception + { + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setIncludes( "**/*" ); + List list = new ArrayList( 1 ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testExcludeArtifactItemOverride() + throws Exception + { + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setExcludes( "**/*" ); + List list = new ArrayList( 1 ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testIncludeArtifactItemMultipleMarker() + throws Exception + { + List list = new ArrayList(); + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setOverWrite( "false" ); + item.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + list.add( item ); + item = stubFactory.getArtifactItem( artifact ); + item.setOverWrite( "false" ); + item.setIncludes( "**/test3" + UNPACKED_FILE_SUFFIX ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + assertMarkerFiles( mojo.getArtifactItems(), true ); + } + + public void testIncludeArtifactItemMultipleExecutions() + throws Exception + { + List list = new ArrayList(); + Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); + ArtifactItem item = stubFactory.getArtifactItem( artifact ); + item.setOverWrite( "false" ); + item.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + list.add( item ); + item = stubFactory.getArtifactItem( artifact ); + item.setOverWrite( "false" ); + item.setIncludes( "**/test3" + UNPACKED_FILE_SUFFIX ); + list.add( item ); + mojo.setArtifactItems( list ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + assertMarkerFiles( mojo.getArtifactItems(), true ); + + // Now run again and make sure the extracted files haven't gotten overwritten + File destFile2 = + new File( mojo.getOutputDirectory().getAbsolutePath(), UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + File destFile3 = + new File( mojo.getOutputDirectory().getAbsolutePath(), UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + destFile2.setLastModified( time ); + destFile3.setLastModified( time ); + assertEquals( time, destFile2.lastModified() ); + assertEquals( time, destFile3.lastModified() ); + Thread.sleep( 100 ); + mojo.execute(); + assertEquals( time, destFile2.lastModified() ); + assertEquals( time, destFile3.lastModified() ); + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java 2012-10-12 18:28:52.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java 2013-05-12 08:45:09.000000000 +0000 @@ -59,7 +59,7 @@ mojo = (UnpackMojo) lookupMojo( "unpack", testPom ); mojo.setOutputDirectory( new File( this.testDir, "outputDirectory" ) ); mojo.setMarkersDirectory( new File( this.testDir, "markers" ) ); - mojo.silent = true; + setSilent( mojo, true ); assertNotNull( mojo ); assertNotNull( mojo.getProject() ); @@ -500,7 +500,7 @@ { final long now = System.currentTimeMillis(); - mojo.silent = false; + setSilent( mojo, false ); stubFactory.setCreateFiles( true ); Artifact artifact = stubFactory.getSnapshotArtifact(); assertTrue( artifact.getFile().setLastModified( now - 20000 ) ); diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestBuildClasspathMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestBuildClasspathMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestBuildClasspathMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestBuildClasspathMojo.java 2013-05-12 13:05:29.000000000 +0000 @@ -0,0 +1,174 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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.io.File; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.BuildClasspathMojo; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; +import org.apache.maven.project.MavenProject; + +public class TestBuildClasspathMojo + extends AbstractDependencyMojoTestCase +{ + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "build-classpath", true ); + } + + /** + * tests the proper discovery and configuration of the mojo + * + * @throws Exception + */ + public void testEnvironment() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml" ); + BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo( "build-classpath", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + // mojo.silent = true; + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + + mojo.execute(); + String file = null; + try + { + file = mojo.readClasspathFile(); + + fail( "Expected an illegal Argument Exception" ); + } + catch ( IllegalArgumentException e ) + { + // expected to catch this. + } + + mojo.setCpFile( new File( testDir, "buildClasspath.txt" ) ); + mojo.execute(); + + file = mojo.readClasspathFile(); + assertNotNull( file ); + assertTrue( file.length() > 0 ); + + assertTrue( file.indexOf( File.pathSeparator ) >= 0 ); + assertTrue( file.indexOf( File.separator ) >= 0 ); + + String fileSep = "#####"; + String pathSep = "%%%%%"; + + mojo.setFileSeparator( fileSep ); + mojo.setPathSeparator( pathSep ); + mojo.execute(); + + file = mojo.readClasspathFile(); + assertNotNull( file ); + assertTrue( file.length() > 0 ); + + assertFalse( file.indexOf( File.pathSeparator ) >= 0 ); + assertFalse( file.indexOf( File.separator ) >= 0 ); + assertTrue( file.indexOf( fileSep ) >= 0 ); + assertTrue( file.indexOf( pathSep ) >= 0 ); + + String propertyValue = project.getProperties().getProperty( "outputProperty" ); + assertNull( propertyValue ); + mojo.setOutputProperty( "outputProperty" ); + mojo.execute(); + propertyValue = project.getProperties().getProperty( "outputProperty" ); + assertNotNull( propertyValue ); + + } + + public void testPath() throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml" ); + BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo( "build-classpath", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + + ArtifactRepository local = new StubArtifactRepository( stubFactory.getWorkingDir().getPath() ); + mojo.setLocal( local ); + + Artifact artifact = stubFactory.getReleaseArtifact(); + + + StringBuilder sb = new StringBuilder(); + mojo.setPrefix( null ); + mojo.setStripVersion( false ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals( artifact.getFile().getPath(), sb.toString() ); + + mojo.setLocalRepoProperty( "$M2_REPO" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals( "$M2_REPO" + File.separator + artifact.getFile().getName(), sb.toString() ); + + mojo.setLocalRepoProperty( "%M2_REPO%" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals( "%M2_REPO%" + File.separator + artifact.getFile().getName(), sb.toString() ); + + mojo.setLocalRepoProperty( "%M2_REPO%" ); + sb.setLength( 0 ); + mojo.setPrependGroupId( true ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("If prefix is null, prependGroupId has no impact ", "%M2_REPO%"+File.separator + + DependencyUtil.getFormattedFileName( artifact, false, false ), sb.toString()); + + mojo.setLocalRepoProperty( "" ); + mojo.setPrefix( "prefix" ); + sb.setLength( 0 ); + mojo.setPrependGroupId( true ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("prefix"+File.separator+DependencyUtil.getFormattedFileName( artifact, false, true ), + sb.toString()); + mojo.setPrependGroupId( false ); + + mojo.setLocalRepoProperty( "" ); + mojo.setPrefix( "prefix" ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals("prefix"+File.separator+artifact.getFile().getName(),sb.toString()); + + mojo.setPrefix( "prefix" ); + mojo.setStripVersion( true ); + sb.setLength( 0 ); + mojo.appendArtifactPath( artifact, sb ); + assertEquals( "prefix" + File.separator + DependencyUtil.getFormattedFileName( artifact, true ), sb.toString() ); + + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo2.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo2.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo2.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo2.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,380 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.artifact.transform.SnapshotTransformation; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.CopyDependenciesMojo; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +public class TestCopyDependenciesMojo2 + extends AbstractDependencyMojoTestCase +{ + + CopyDependenciesMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "copy-dependencies", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" ); + mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom ); + mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); + // mojo.silent = true; + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + mojo.markersDirectory = new File( this.testDir, "markers" ); + + } + + public void assertNoMarkerFile( Artifact artifact ) + { + DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); + try + { + assertFalse( handle.isMarkerSet() ); + } + catch ( MojoExecutionException e ) + { + fail( e.getLongMessage() ); + } + + } + + public void testCopyDependenciesMojoIncludeCompileScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "compile"; + + mojo.execute(); + + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( saf.include( artifact ), file.exists() ); + } + } + + public void testCopyDependenciesMojoIncludeTestScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "test"; + + mojo.execute(); + + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( saf.include( artifact ), file.exists() ); + } + } + + public void testCopyDependenciesMojoIncludeRuntimeScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "runtime"; + + mojo.execute(); + + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( saf.include( artifact ), file.exists() ); + } + } + + public void testCopyDependenciesMojoIncludeprovidedScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "provided"; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ), file.exists() ); + } + } + + public void testCopyDependenciesMojoIncludesystemScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "system"; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ), file.exists() ); + } + } + + public void testSubPerArtifact() + throws Exception + { + mojo.useSubDirectoryPerArtifact = true; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testSubPerArtifactAndType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerType = true; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testSubPerArtifactAndScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerScope = true; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, false, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testRepositoryLayout() + throws Exception + { + String baseVersion = "2.0-SNAPSHOT"; + String groupId = "testGroupId"; + String artifactId = "expanded-snapshot"; + + Artifact expandedSnapshot = createExpandedVersionArtifact( baseVersion, + groupId, + artifactId, + "compile", + "jar", + null); + + mojo.getProject().getArtifacts().add( expandedSnapshot ); + mojo.getProject().getDependencyArtifacts().add( expandedSnapshot ); + + Artifact pomExpandedSnapshot = createExpandedVersionArtifact( baseVersion, + groupId, + artifactId, + "compile", + "pom", + null); + mojo.getProject().getArtifacts().add( pomExpandedSnapshot ); + mojo.getProject().getDependencyArtifacts().add( pomExpandedSnapshot ); + + mojo.useRepositoryLayout = true; + mojo.execute(); + + File outputDirectory = mojo.outputDirectory; + ArtifactRepository targetRepository = mojo.repositoryFactory.createDeploymentArtifactRepository( + "local", + outputDirectory.toURL().toExternalForm(), + new DefaultRepositoryLayout(), + false ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + assertArtifactExists( artifact, targetRepository ); + + if ( ! artifact.getBaseVersion().equals( artifact.getVersion() ) ) + { + Artifact baseArtifact = + mojo.getFactory().createArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getBaseVersion(), artifact.getScope(), + artifact.getType() ); + assertArtifactExists( baseArtifact, targetRepository ); + } + + } + } + + private Artifact createExpandedVersionArtifact( String baseVersion, + String groupId, + String artifactId, + String scope, + String type, + String classifier ) + throws IOException + { + Artifact expandedSnapshot = this.stubFactory.createArtifact( groupId, artifactId, baseVersion, scope, type, classifier ); + + SnapshotTransformation tr = new SnapshotTransformation(); + Snapshot snapshot = new Snapshot(); + snapshot.setTimestamp( tr.getDeploymentTimestamp() ); + snapshot.setBuildNumber( 1 ); + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( expandedSnapshot, snapshot ); + String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber(); + expandedSnapshot.setResolvedVersion( StringUtils.replace( baseVersion, Artifact.SNAPSHOT_VERSION, newVersion ) ); + expandedSnapshot.addMetadata( metadata ); + return expandedSnapshot; + } + + private void assertArtifactExists( Artifact artifact, ArtifactRepository targetRepository ) { + File file = new File( targetRepository.getBasedir(), + targetRepository.getLayout().pathOf( artifact ) ); + assertTrue( file.exists() ); + + Collection metas = artifact.getMetadataList(); + for ( ArtifactMetadata meta : metas ) + { + File metaFile = new File( targetRepository.getBasedir(), + targetRepository.getLayout().pathOfLocalRepositoryMetadata( meta, targetRepository) ); + assertTrue( metaFile.exists() ); + } + } + + public void testSubPerArtifactRemoveVersion() + throws Exception + { + mojo.useSubDirectoryPerArtifact = true; + mojo.stripVersion = true; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, true ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testSubPerArtifactAndTypeRemoveVersion() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerType = true; + mojo.stripVersion = true; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, true ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestCopyDependenciesMojo.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,794 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.plugin.MojoFailureException; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.CopyDependenciesMojo; +import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; +import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; +import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +public class TestCopyDependenciesMojo + extends AbstractDependencyMojoTestCase +{ + + CopyDependenciesMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "copy-dependencies", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" ); + mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom ); + mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); + // mojo.silent = true; + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + mojo.markersDirectory = new File( this.testDir, "markers" ); + + } + + public void assertNoMarkerFile( Artifact artifact ) + { + DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); + try + { + assertFalse( handle.isMarkerSet() ); + } + catch ( MojoExecutionException e ) + { + fail( e.getLongMessage() ); + } + + } + + public void testCopyFile() + throws MojoExecutionException, IOException + { + File src = File.createTempFile( "copy", null ); + + File dest = new File( mojo.outputDirectory, "toMe.jar" ); + + assertFalse( dest.exists() ); + + copyFile( mojo, src, dest ); + assertTrue( dest.exists() ); + } + + /** + * tests the proper discovery and configuration of the mojo + * + * @throws Exception + */ + public void testMojo() + throws Exception + { + mojo.execute(); + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + + // there should be no markers for the copy mojo + assertNoMarkerFile( artifact ); + } + } + + public void testStripVersion() + throws Exception + { + mojo.stripVersion = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, true ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + } + } + + public void testStripClassifier() + throws Exception + { + mojo.stripClassifier = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false, false, false, true ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + } + } + + + public void testUseBaseVersion() + throws Exception + { + mojo.useBaseVersion = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false, false, true ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + } + } + + public void testNoTransitive() + throws Exception + { + mojo.excludeTransitive = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getDependencyArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + } + } + + public void testExcludeType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeTypes = "jar"; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), !file.exists() ); + } + } + + public void testIncludeType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + + mojo.includeTypes = "jar"; + mojo.excludeTypes = "jar"; + //shouldn't get anything. + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertFalse( file.exists() ); + } + + mojo.excludeTypes = ""; + mojo.execute(); + + artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), file.exists() ); + } + } + + + public void testExcludeArtifactId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getArtifactArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeArtifactIds = "one"; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getArtifactId().equals( "one" ), !file.exists() ); + } + } + + public void testIncludeArtifactId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getArtifactArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + + mojo.includeArtifactIds = "one"; + mojo.excludeArtifactIds = "one"; + //shouldn't get anything + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertFalse( file.exists() ); + } + + mojo.excludeArtifactIds = ""; + mojo.execute(); + + artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getArtifactId().equals( "one" ), file.exists() ); + } + } + + public void testIncludeGroupId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getGroupIdArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeGroupIds = "one"; + mojo.excludeGroupIds = "one"; + //shouldn't get anything + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertFalse( file.exists() ); + } + + mojo.excludeGroupIds = ""; + mojo.execute(); + + artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getGroupId().equals( "one" ), file.exists() ); + } + + } + + public void testExcludeGroupId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getGroupIdArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeGroupIds = "one"; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( artifact.getGroupId().equals( "one" ), !file.exists() ); + } + } + public void testExcludeMultipleGroupIds() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getGroupIdArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeGroupIds = "one,two"; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( artifact.getGroupId().equals( "one" ) || artifact.getGroupId().equals( "two" ), !file.exists() ); + } + } + + public void testExcludeClassifier() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getClassifiedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeClassifiers = "one"; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getClassifier().equals( "one" ), !file.exists() ); + } + } + + public void testIncludeClassifier() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getClassifiedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + + mojo.includeClassifiers = "one"; + mojo.excludeClassifiers = "one"; + //shouldn't get anything + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertFalse( file.exists() ); + } + + mojo.excludeClassifiers = ""; + mojo.execute(); + + artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getClassifier().equals( "one" ), file.exists() ); + } + + } + + public void testSubPerType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerType = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File folder = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, mojo.outputDirectory, + artifact ); + File file = new File( folder, fileName ); + assertTrue( file.exists() ); + } + } + + public void testCDMClassifier() + throws Exception + { + dotestClassifierType( "jdk14", null ); + } + + public void testCDMType() + throws Exception + { + dotestClassifierType( null, "sources" ); + } + + public void testCDMClassifierType() + throws Exception + { + dotestClassifierType( "jdk14", "sources" ); + } + + public void dotestClassifierType( String testClassifier, String testType ) + throws Exception + { + mojo.classifier = testClassifier; + mojo.type = testType; + + // init classifier things + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String useClassifier = artifact.getClassifier(); + String useType = artifact.getType(); + + if ( StringUtils.isNotEmpty( testClassifier ) ) + { + useClassifier = "-" + testClassifier; + // type is only used if classifier is used. + if ( StringUtils.isNotEmpty( testType ) ) + { + useType = testType; + } + } + String fileName = artifact.getArtifactId() + "-" + artifact.getVersion() + useClassifier + "." + useType; + File file = new File( mojo.outputDirectory, fileName ); + + if ( !file.exists() ) + { + fail( "Can't find:" + file.getAbsolutePath() ); + } + + // there should be no markers for the copy mojo + assertNoMarkerFile( artifact ); + } + } + + public void testArtifactNotFound() + throws Exception + { + dotestArtifactExceptions( false, true ); + } + + public void testArtifactResolutionException() + throws Exception + { + dotestArtifactExceptions( true, false ); + } + + public void dotestArtifactExceptions( boolean are, boolean anfe ) + throws Exception + { + mojo.classifier = "jdk"; + mojo.type = "java-sources"; + + // init classifier things + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + setResolver( mojo, new StubArtifactResolver( null, are, anfe ) ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + try + { + mojo.execute(); + fail( "ExpectedException" ); + } + catch ( MojoExecutionException e ) + { + + } + } + + /* + * public void testOverwrite() { stubFactory.setCreateFiles( false ); + * Artifact artifact = stubFactory.createArtifact( "test", "artifact", "1.0" ); + * + * File testFile = new File( getBasedir() + File.separatorChar + + * "target/test-classes/unit/copy-dependencies-test/test.zip" ); } + */ + + public void testDontOverWriteRelease() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact release = stubFactory.getReleaseArtifact(); + release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( release ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteIfNewer = false; + + mojo.execute(); + + File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) ); + + Thread.sleep( 100 ); + // round up to the next second + long time = System.currentTimeMillis() + 1000; + time = time - ( time % 1000 ); + copiedFile.setLastModified( time ); + Thread.sleep( 100 ); + + mojo.execute(); + + assertEquals( time, copiedFile.lastModified() ); + } + + public void testOverWriteRelease() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact release = stubFactory.getReleaseArtifact(); + release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( release ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = true; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) ); + + Thread.sleep( 100 ); + // round down to the last second + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + copiedFile.setLastModified( time ); + // wait at least a second for filesystems that only record to the + // nearest second. + Thread.sleep( 1000 ); + + mojo.execute(); + + assertTrue( time < copiedFile.lastModified() ); + } + + public void testDontOverWriteSnap() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact snap = stubFactory.getSnapshotArtifact(); + snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( snap ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = false; + mojo.overWriteSnapshots = false; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) ); + + Thread.sleep( 100 ); + // round up to the next second + long time = System.currentTimeMillis() + 1000; + time = time - ( time % 1000 ); + copiedFile.setLastModified( time ); + Thread.sleep( 100 ); + + mojo.execute(); + + assertEquals( time, copiedFile.lastModified() ); + } + + public void testOverWriteSnap() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact snap = stubFactory.getSnapshotArtifact(); + snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( snap ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = false; + mojo.overWriteSnapshots = true; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) ); + + Thread.sleep( 100 ); + // round down to the last second + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + copiedFile.setLastModified( time ); + // wait at least a second for filesystems that only record to the + // nearest second. + Thread.sleep( 1000 ); + + mojo.execute(); + + assertTrue( time < copiedFile.lastModified() ); + } + + public void testGetDependencies() + throws MojoExecutionException + { + assertEquals( mojo.getResolvedDependencies( true ).toString(), mojo.getDependencySets( true ) + .getResolvedDependencies().toString() ); + } + + public void testExcludeProvidedScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "provided"; + // mojo.silent = false; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getScope().equals( "provided" ), !file.exists() ); + file.delete(); + assertFalse( file.exists() ); + } + + } + + public void testExcludeSystemScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "system"; + // mojo.silent = false; + + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + assertEquals( artifact.getScope().equals( "system" ), !file.exists() ); + file.delete(); + assertFalse( file.exists() ); + } + + } + + public void testExcludeCompileScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "compile"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( !saf.include( artifact ), file.exists() ); + } + } + + public void testExcludeTestScope() + throws IOException, MojoFailureException + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "test"; + + try + { + mojo.execute(); + fail( "expected an exception" ); + } + catch ( MojoExecutionException e ) + { + + } + + } + + public void testExcludeRuntimeScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "runtime"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName ); + + assertEquals( !saf.include( artifact ), file.exists() ); + } + } + + public void testCopyPom() + throws Exception + { + mojo.setCopyPom( true ); + mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + Set set = new HashSet(); + set.add( stubFactory.createArtifact( "org.apache.maven", "maven-artifact", "2.0.7", Artifact.SCOPE_COMPILE ) ); + mojo.getProject().setArtifacts( set ); + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false ); + File file = new File( mojo.outputDirectory, fileName.substring( 0, fileName.length() - 4 ) + ".pom" ); + assertTrue( file.exists() ); + } + } + + public void testPrependGroupId() + throws Exception + { + mojo.prependGroupId = true; + mojo.execute(); + + Set artifacts = mojo.getProject().getArtifacts(); + for ( Artifact artifact : artifacts ) + { + String fileName = DependencyUtil.getFormattedFileName( artifact, false, true ); + File file = new File( mojo.outputDirectory, fileName ); + assertTrue( file.exists() ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,186 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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.io.File; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.UnpackDependenciesMojo; +import org.apache.maven.project.MavenProject; + +public class TestIncludeExcludeUnpackDependenciesMojo + extends AbstractDependencyMojoTestCase +{ + private final String PACKED_FILE = "test.zip"; + + private final String UNPACKED_FILE_PREFIX = "test"; + private final String UNPACKED_FILE_SUFFIX = ".txt"; + + private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE; + + UnpackDependenciesMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "unpack-dependencies", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); + mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); + mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); + // mojo.silent = true; + + // it needs to get the archivermanager + //stubFactory.setUnpackableFile( mojo.getArchiverManager() ); + // i'm using one file repeatedly to archive so I can test the name + // programmatically. + stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + PACKED_FILE_PATH ) ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + mojo.markersDirectory = new File( this.testDir, "markers" ); + + } + + protected void tearDown() + { + super.tearDown(); + + mojo = null; + System.gc(); + } + + private void assertUnpacked( boolean unpacked, String fileName ) + { + File destFile = new File( mojo.getOutputDirectory().getAbsolutePath(), fileName ); + assertEquals( unpacked, destFile.exists() ); + } + + /** + * This test will validate that only the 1 and 11 files get unpacked + * @throws Exception + */ + public void testUnpackIncludesManyFiles() + throws Exception + { + mojo.setIncludes( "**/*1" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify only the 2 file gets unpacked + * @throws Exception + */ + public void testUnpackIncludesSingleFile() + throws Exception + { + mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify all files get unpacked + * @throws Exception + */ + public void testUnpackIncludesAllFiles() + throws Exception + { + mojo.setIncludes( "**/*" ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will validate that only the 2 and 3 files get unpacked + * @throws Exception + */ + public void testUnpackExcludesManyFiles() + throws Exception + { + mojo.setExcludes( "**/*1" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify only the 1, 11 & 3 files get unpacked + * @throws Exception + */ + public void testUnpackExcludesSingleFile() + throws Exception + { + mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + /** + * This test will verify no files get unpacked + * @throws Exception + */ + public void testUnpackExcludesAllFiles() + throws Exception + { + mojo.setExcludes( "**/*" ); + mojo.execute(); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } + + public void testNoIncludeExcludes() + throws Exception + { + mojo.execute(); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); + assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo2.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo2.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo2.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo2.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,257 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.plugin.MojoFailureException; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.UnpackDependenciesMojo; +import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +public class TestUnpackDependenciesMojo2 + extends AbstractDependencyMojoTestCase +{ + + private final String UNPACKABLE_FILE = "test.txt"; + + private final String UNPACKABLE_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + UNPACKABLE_FILE; + + UnpackDependenciesMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "unpack-dependencies", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); + mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); + mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); + mojo.setUseJvmChmod( true ); + // mojo.silent = true; + + // it needs to get the archivermanager + stubFactory.setUnpackableFile( mojo.getArchiverManager() ); + // i'm using one file repeatedly to archive so I can test the name + // programmatically. + stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH ) ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + mojo.markersDirectory = new File( this.testDir, "markers" ); + + } + + protected void tearDown() + { + super.tearDown(); + + mojo = null; + System.gc(); + } + + public File getUnpackedFile( Artifact artifact ) + { + File destDir = DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), + mojo.isUseSubDirectoryPerType(), + mojo.isUseSubDirectoryPerArtifact(), + mojo.useRepositoryLayout, mojo.stripVersion, + mojo.getOutputDirectory(), artifact ); + File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); + assertTrue( unpacked.exists() ); + return unpacked; + } + + public void testDontOverWriteRelease() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact release = stubFactory.getReleaseArtifact(); + release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( release ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteIfNewer = false; + + mojo.execute(); + + assertUnpacked( release, false ); + } + + public void testOverWriteRelease() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact release = stubFactory.getReleaseArtifact(); + release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( release ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = true; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + assertUnpacked( release, true ); + } + + public void testDontOverWriteSnap() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact snap = stubFactory.getSnapshotArtifact(); + snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( snap ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = false; + mojo.overWriteSnapshots = false; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + assertUnpacked( snap, false ); + } + + public void testOverWriteSnap() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact snap = stubFactory.getSnapshotArtifact(); + snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( snap ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = false; + mojo.overWriteSnapshots = true; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + assertUnpacked( snap, true ); + + } + + public void testOverWriteIfNewer() + throws MojoExecutionException, InterruptedException, IOException, MojoFailureException + { + + Set artifacts = new HashSet(); + Artifact snap = stubFactory.getSnapshotArtifact(); + snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); + + artifacts.add( snap ); + + mojo.getProject().setArtifacts( artifacts ); + mojo.getProject().setDependencyArtifacts( artifacts ); + + mojo.overWriteReleases = false; + mojo.overWriteSnapshots = false; + mojo.overWriteIfNewer = false; + + mojo.execute(); + + File unpackedFile = getUnpackedFile( snap ); + + // round down to the last second + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + // set source to be newer and dest to be a known value. + snap.getFile().setLastModified( time + 3000 ); + unpackedFile.setLastModified( time ); + // wait at least a second for filesystems that only record to the + // nearest second. + Thread.sleep( 1000 ); + + assertEquals( time, unpackedFile.lastModified() ); + mojo.execute(); + System.gc(); + // make sure it didn't overwrite + assertEquals( time, unpackedFile.lastModified() ); + + mojo.overWriteIfNewer = true; + + mojo.execute(); + + assertTrue( time != unpackedFile.lastModified() ); + + System.gc(); + } + + public void assertUnpacked( Artifact artifact, boolean overWrite ) + throws InterruptedException, MojoExecutionException, MojoFailureException + { + File unpackedFile = getUnpackedFile( artifact ); + + Thread.sleep( 100 ); + // round down to the last second + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + unpackedFile.setLastModified( time ); + // wait at least a second for filesystems that only record to the + // nearest second. + Thread.sleep( 1000 ); + + assertEquals( time, unpackedFile.lastModified() ); + mojo.execute(); + + if ( overWrite ) + { + assertTrue( time != unpackedFile.lastModified() ); + } + else + { + assertEquals( time, unpackedFile.lastModified() ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/fromDependencies/TestUnpackDependenciesMojo.java 2013-05-12 09:10:35.000000000 +0000 @@ -0,0 +1,680 @@ +package org.apache.maven.plugin.dependency.fromDependencies; + +/* + * 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 org.apache.maven.plugin.MojoFailureException; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.fromDependencies.UnpackDependenciesMojo; +import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; +import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; +import org.apache.maven.plugin.dependency.utils.DependencyUtil; +import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; +import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; +import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class TestUnpackDependenciesMojo + extends AbstractDependencyMojoTestCase +{ + + private final String UNPACKABLE_FILE = "test.txt"; + + private final String UNPACKABLE_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + UNPACKABLE_FILE; + + UnpackDependenciesMojo mojo; + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "unpack-dependencies", true ); + + File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); + mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); + mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); + mojo.setUseJvmChmod( true ); + // mojo.silent = true; + + // it needs to get the archivermanager + stubFactory.setUnpackableFile( mojo.getArchiverManager() ); + // i'm using one file repeatedly to archive so I can test the name + // programmatically. + stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH ) ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + mojo.markersDirectory = new File( this.testDir, "markers" ); + + } + + protected void tearDown() + { + super.tearDown(); + + mojo = null; + System.gc(); + } + + public void assertUnpacked( Artifact artifact ) + { + assertUnpacked( true, artifact ); + } + + public void assertUnpacked( boolean val, Artifact artifact ) + { + File folder = + DependencyUtil.getFormattedOutputDirectory( mojo.useSubDirectoryPerScope, mojo.useSubDirectoryPerType, + mojo.useSubDirectoryPerArtifact, mojo.useRepositoryLayout, + mojo.stripVersion, mojo.outputDirectory, artifact ); + + File destFile = new File( folder, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); + + assertEquals( val, destFile.exists() ); + assertMarkerFile( val, artifact ); + } + + public void assertMarkerFile( boolean val, Artifact artifact ) + { + DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); + try + { + assertEquals( val, handle.isMarkerSet() ); + } + catch ( MojoExecutionException e ) + { + fail( e.getLongMessage() ); + } + } + + public void testMojo() + throws Exception + { + mojo.execute(); + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testNoTransitive() + throws Exception + { + mojo.excludeTransitive = true; + mojo.execute(); + Iterator iter = mojo.getProject().getDependencyArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testExcludeType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArchiveArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeTypes = "jar"; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + + assertUnpacked( !artifact.getType().equalsIgnoreCase( "jar" ), artifact ); + } + } + + public void testExcludeProvidedScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "provided"; + // mojo.silent = false; + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !artifact.getScope().equals( "provided" ), artifact ); + } + + } + + public void testExcludeSystemScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "system"; + // mojo.silent = false; + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !artifact.getScope().equals( "system" ), artifact ); + } + + } + + public void testExcludeCompileScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "compile"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !saf.include( artifact ), artifact ); + } + } + + public void testExcludeTestScope() + throws IOException, MojoFailureException + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "test"; + + try + { + mojo.execute(); + fail( "expected an exception" ); + } + catch ( MojoExecutionException e ) + { + + } + + } + + public void testExcludeRuntimeScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeScope = "runtime"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !saf.include( artifact ), artifact ); + } + } + + public void testIncludeType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArchiveArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + + mojo.includeTypes = "jar"; + mojo.excludeTypes = "jar"; + //shouldn't get anything + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + + assertUnpacked( false, artifact ); + } + + mojo.excludeTypes = ""; + mojo.execute(); + + iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + + assertUnpacked( artifact.getType().equalsIgnoreCase( "jar" ), artifact ); + } + } + + public void testSubPerType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArchiveArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerType = true; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testSubPerArtifact() + throws Exception + { + mojo.useSubDirectoryPerArtifact = true; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testSubPerArtifactAndType() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArchiveArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerType = true; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testSubPerArtifactRemoveVersion() + throws Exception + { + mojo.useSubDirectoryPerArtifact = true; + mojo.stripVersion = true; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testSubPerArtifactAndTypeRemoveVersion() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getTypedArchiveArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.useSubDirectoryPerArtifact = true; + mojo.useSubDirectoryPerType = true; + mojo.stripVersion = true; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact ); + } + } + + public void testIncludeCompileScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "compile"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( saf.include( artifact ), artifact ); + } + } + + public void testIncludeTestScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "test"; + + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( saf.include( artifact ), artifact ); + } + } + + public void testIncludeRuntimeScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "runtime"; + mojo.execute(); + ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( saf.include( artifact ), artifact ); + } + } + + public void testIncludeprovidedScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "provided"; + + mojo.execute(); + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ), artifact ); + } + } + + public void testIncludesystemScope() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeScope = "system"; + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ), artifact ); + } + } + + public void testIncludeArtifactId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getArtifactArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + + mojo.includeArtifactIds = "one"; + mojo.excludeArtifactIds = "one"; + //shouldn't get anything + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( false, artifact ); + } + mojo.excludeArtifactIds = ""; + mojo.execute(); + + iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( artifact.getArtifactId().equals( "one" ), artifact ); + } + + } + + public void testExcludeArtifactId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getArtifactArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeArtifactIds = "one"; + mojo.execute(); + + // test - get all direct dependencies and verify that they exist if they + // do not have a classifier of "one" + // then delete the file and at the end, verify the folder is empty. + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !artifact.getArtifactId().equals( "one" ), artifact ); + } + } + + public void testExcludeGroupId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getGroupIdArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.excludeGroupIds = "one"; + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + assertUnpacked( !artifact.getGroupId().equals( "one" ), artifact ); + } + } + + public void testIncludeGroupId() + throws Exception + { + mojo.getProject().setArtifacts( stubFactory.getGroupIdArtifacts() ); + mojo.getProject().setDependencyArtifacts( new HashSet() ); + mojo.includeGroupIds = "one"; + mojo.excludeGroupIds = "one"; + //shouldn't get anything + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + // Testing with artifact id because group id is not in filename + assertUnpacked( false, artifact ); + } + + mojo.excludeGroupIds = ""; + mojo.execute(); + + iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + // Testing with artifact id because group id is not in filename + assertUnpacked( artifact.getGroupId().equals( "one" ), artifact ); + } + + } + + public void testCDMClassifier() + throws Exception + { + dotestClassifierType( "jdk14", null ); + } + + public void testCDMType() + throws Exception + { + dotestClassifierType( null, "zip" ); + } + + public void testCDMClassifierType() + throws Exception + { + dotestClassifierType( "jdk14", "war" ); + } + + public void dotestClassifierType( String testClassifier, String testType ) + throws Exception + { + mojo.classifier = testClassifier; + mojo.type = testType; + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + mojo.execute(); + + Iterator iter = mojo.getProject().getArtifacts().iterator(); + while ( iter.hasNext() ) + { + Artifact artifact = iter.next(); + + String useClassifier = artifact.getClassifier(); + String useType = artifact.getType(); + + if ( StringUtils.isNotEmpty( testClassifier ) ) + { + useClassifier = testClassifier; + // type is only used if classifier is used. + if ( StringUtils.isNotEmpty( testType ) ) + { + useType = testType; + } + } + Artifact unpacked = + stubFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), + Artifact.SCOPE_COMPILE, useType, useClassifier ); + assertUnpacked( unpacked ); + } + } + + public void testArtifactNotFound() + throws Exception + { + dotestArtifactExceptions( false, true ); + } + + public void testArtifactResolutionException() + throws Exception + { + dotestArtifactExceptions( true, false ); + } + + public void dotestArtifactExceptions( boolean are, boolean anfe ) + throws Exception + { + mojo.classifier = "jdk"; + mojo.type = "java-sources"; + // init classifier things + mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); + mojo.setResolver( new StubArtifactResolver( null, are, anfe ) ); + mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); + + try + { + mojo.execute(); + fail( "ExpectedException" ); + } + catch ( MojoExecutionException e ) + { + } + } + + public File getUnpackedFile( Artifact artifact ) + { + File destDir = DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), + mojo.isUseSubDirectoryPerType(), + mojo.isUseSubDirectoryPerArtifact(), + mojo.useRepositoryLayout, mojo.stripVersion, + mojo.getOutputDirectory(), artifact ); + File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); + assertTrue( unpacked.exists() ); + return unpacked; + } + + public DefaultFileMarkerHandler getUnpackedMarkerHandler( Artifact artifact ) + { + return new DefaultFileMarkerHandler( artifact, mojo.getMarkersDirectory() ); + } + + + public void assertUnpacked( Artifact artifact, boolean overWrite ) + throws InterruptedException, MojoExecutionException, MojoFailureException + { + File unpackedFile = getUnpackedFile( artifact ); + + Thread.sleep( 100 ); + // round down to the last second + long time = System.currentTimeMillis(); + time = time - ( time % 1000 ); + unpackedFile.setLastModified( time ); + // wait at least a second for filesystems that only record to the + // nearest second. + Thread.sleep( 1000 ); + + assertEquals( time, unpackedFile.lastModified() ); + mojo.execute(); + + if ( overWrite ) + { + assertTrue( time != unpackedFile.lastModified() ); + } + else + { + assertEquals( time, unpackedFile.lastModified() ); + } + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/resolvers/TestResolveMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/resolvers/TestResolveMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/resolvers/TestResolveMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/resolvers/TestResolveMojo.java 2013-05-12 08:45:09.000000000 +0000 @@ -0,0 +1,88 @@ +package org.apache.maven.plugin.dependency.resolvers; + +/* + * 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.io.File; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo; +import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; +import org.apache.maven.plugin.testing.SilentLog; +import org.apache.maven.project.MavenProject; + +public class TestResolveMojo + extends AbstractDependencyMojoTestCase +{ + + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "markers", false ); + } + + /** + * tests the proper discovery and configuration of the mojo + * + * @throws Exception + */ + public void testresolveTestEnvironment() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" ); + ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + + setSilent( mojo, true ); + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + + mojo.execute(); + DependencyStatusSets results = mojo.getResults(); + assertNotNull( results ); + assertEquals( artifacts.size(), results.getResolvedDependencies().size() ); + + setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE ); + + mojo.execute(); + results = mojo.getResults(); + assertNotNull( results ); + assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() ); + } + + public void testSilent() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" ); + ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom ); + setSilent( mojo, false ); + + assertFalse( mojo.getLog() instanceof SilentLog ); + } // TODO: Test skipping artifacts. +} \ No newline at end of file diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java 2011-03-13 00:17:39.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDepMgt.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,249 +0,0 @@ -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.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Exclusion; -import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; -import org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub; -import org.apache.maven.project.MavenProject; - -public class TestAnalyzeDepMgt - extends TestCase -{ - - AnalyzeDepMgt mojo; - - DependencyArtifactStubFactory stubFactory; - - Dependency exclusion; - - Exclusion ex; - - Artifact exclusionArtifact; - - DependencyManagement depMgt; - DependencyManagement depMgtNoExclusions; - protected void setUp() - throws Exception - { - - mojo = new AnalyzeDepMgt(); - MavenProject project = new DependencyProjectStub(); - - stubFactory = new DependencyArtifactStubFactory( new File( "" ), false ); - - Set allArtifacts = stubFactory.getMixedArtifacts(); - Set directArtifacts = stubFactory.getClassifiedArtifacts(); - - - exclusionArtifact = stubFactory.getReleaseArtifact(); - directArtifacts.add( exclusionArtifact ); - ex = new Exclusion(); - ex.setArtifactId( exclusionArtifact.getArtifactId() ); - ex.setGroupId( exclusionArtifact.getGroupId() ); - - exclusion = new Dependency(); - exclusion.setArtifactId( exclusionArtifact.getArtifactId() ); - exclusion.setGroupId( exclusionArtifact.getGroupId() ); - exclusion.setType( exclusionArtifact.getType() ); - exclusion.setClassifier( "" ); - exclusion.setVersion( "3.0" ); - - exclusion.addExclusion( ex ); - List list = new ArrayList(); - list.add( exclusion ); - - depMgt = new DependencyManagement(); - depMgt.setDependencies( list ); - - - project.setArtifacts( allArtifacts ); - project.setDependencyArtifacts( directArtifacts ); - - mojo.setProject( project ); - - } - - public void testGetManagementKey() - throws IOException - { - Dependency dep = new Dependency(); - dep.setArtifactId( "artifact" ); - dep.setClassifier( "class" ); - dep.setGroupId( "group" ); - dep.setType( "type" ); - - // version isn't used in the key, it can be different - dep.setVersion( "1.1" ); - - Artifact artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", - "class" ); - - // basic case ok - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - - // now change each one and make sure it fails, then set it back and make - // sure it's ok before - // testing the next one - dep.setType( "t" ); - assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); - - dep.setType( "type" ); - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - - dep.setArtifactId( "a" ); - assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); - - dep.setArtifactId( "artifact" ); - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - - dep.setClassifier( "c" ); - assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); - - dep.setClassifier( "class" ); - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - - dep.setGroupId( "g" ); - assertFalse( dep.getManagementKey().equals( mojo.getArtifactManagementKey( artifact ) ) ); - - dep.setGroupId( "group" ); - dep.setClassifier( null ); - artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", null ); - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - - dep.setClassifier( "" ); - artifact = stubFactory.createArtifact( "group", "artifact", "1.0", Artifact.SCOPE_COMPILE, "type", "" ); - assertEquals( dep.getManagementKey(), mojo.getArtifactManagementKey( artifact ) ); - } - - public void testAddExclusions() - { - - assertEquals( 0, mojo.addExclusions( null ).size() ); - - List list = new ArrayList(); - list.add( ex ); - Map map = mojo.addExclusions( list ); - - assertEquals( 1,map.size() ); - assertTrue( map.containsKey( mojo.getExclusionKey( ex ) ) ); - assertSame( ex, map.get( mojo.getExclusionKey( ex ) ) ); - } - - public void testGetExclusionErrors() - { - List list = new ArrayList(); - list.add( ex ); - - // already tested this method so I can trust it. - Map map = mojo.addExclusions( list ); - - List l = mojo.getExclusionErrors( map, mojo.getProject().getArtifacts() ); - - assertEquals( 1, l.size() ); - - assertEquals( mojo.getExclusionKey( ex ), mojo.getExclusionKey(( Artifact) l.get( 0 ) ) ); - } - - public void testGetMismatch() - throws IOException - { - Map depMgtMap = new HashMap(); - - depMgtMap.put( exclusion.getManagementKey(), exclusion ); - - Map results = mojo.getMismatch( depMgtMap, mojo.getProject().getArtifacts() ); - - assertEquals( 1, results.size() ); - // the release artifact is used to create the exclusion - assertTrue( results.containsKey( stubFactory.getReleaseArtifact() ) ); - assertSame( exclusion, results.get( stubFactory.getReleaseArtifact() ) ); - } - - public void testMojo() throws IOException - { - mojo.setIgnoreDirect( false ); - try - { - // test with nothing in depMgt - mojo.execute(); - } - catch ( Exception e ) - { - e.printStackTrace(); - fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); - } - - try - { - DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); - project.setDependencyManagement( depMgt ); - // test with exclusion - mojo.execute(); - } - catch ( Exception e ) - { - e.printStackTrace(); - fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); - } - - try - { - DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); - project.setDependencyManagement( depMgt ); - // test with exclusion - mojo.setFailBuild( true ); - mojo.execute(); - fail( "Expected exception to fail the build." ); - } - catch ( Exception e ) - { - System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() ); - } - - try - { - DependencyProjectStub project = (DependencyProjectStub) mojo.getProject(); - project.setDependencyManagement( depMgt ); - // test with exclusion - mojo.setFailBuild( true ); - mojo.setIgnoreDirect( true ); - mojo.execute(); - } - catch ( Exception e ) - { - e.printStackTrace(); - fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDuplicateMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDuplicateMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDuplicateMojo.java 2012-09-13 13:53:19.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestAnalyzeDuplicateMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,222 +0,0 @@ -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.io.File; -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.maven.plugin.logging.Log; - -/** - * @author Vincent Siveton - * @version $Id: TestAnalyzeDuplicateMojo.java 1384337 2012-09-13 13:53:19Z olamy $ - */ -public class TestAnalyzeDuplicateMojo - extends AbstractDependencyMojoTestCase -{ - public void testDuplicate() - throws Exception - { - File testPom = - new File( getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config.xml" ); - AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo( "analyze-duplicate", testPom ); - assertNotNull( mojo ); - DuplicateLog log = new DuplicateLog(); - mojo.setLog( log ); - mojo.execute(); - - assertTrue( log.getContent().indexOf( - "List of duplicate dependencies defined in in " - + "your pom.xml" ) != -1 ); - assertTrue( log.getContent().indexOf( "junit:junit:jar" ) != -1 ); - } - - public void testDuplicate2() - throws Exception - { - File testPom = - new File( getBasedir(), "target/test-classes/unit/duplicate-dependencies/plugin-config2.xml" ); - AnalyzeDuplicateMojo mojo = (AnalyzeDuplicateMojo) lookupMojo( "analyze-duplicate", testPom ); - assertNotNull( mojo ); - DuplicateLog log = new DuplicateLog(); - mojo.setLog( log ); - mojo.execute(); - - assertTrue( log.getContent().indexOf( - "List of duplicate dependencies defined in in " - + "your pom.xml" ) != -1 ); - assertTrue( log.getContent().indexOf( "junit:junit:jar" ) != -1 ); - } - - class DuplicateLog - implements Log - { - StringBuilder sb = new StringBuilder(); - - /** {@inheritDoc} */ - public void debug( CharSequence content ) - { - print( "debug", content ); - } - - /** {@inheritDoc} */ - public void debug( CharSequence content, Throwable error ) - { - print( "debug", content, error ); - } - - /** {@inheritDoc} */ - public void debug( Throwable error ) - { - print( "debug", error ); - } - - /** {@inheritDoc} */ - public void info( CharSequence content ) - { - print( "info", content ); - } - - /** {@inheritDoc} */ - public void info( CharSequence content, Throwable error ) - { - print( "info", content, error ); - } - - /** {@inheritDoc} */ - public void info( Throwable error ) - { - print( "info", error ); - } - - /** {@inheritDoc} */ - public void warn( CharSequence content ) - { - print( "warn", content ); - } - - /** {@inheritDoc} */ - public void warn( CharSequence content, Throwable error ) - { - print( "warn", content, error ); - } - - /** {@inheritDoc} */ - public void warn( Throwable error ) - { - print( "warn", error ); - } - - /** {@inheritDoc} */ - public void error( CharSequence content ) - { - System.err.println( "[error] " + content.toString() ); - } - - /** {@inheritDoc} */ - public void error( CharSequence content, Throwable error ) - { - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter( sWriter ); - - error.printStackTrace( pWriter ); - - System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() ); - } - - /** - * @see org.apache.maven.plugin.logging.Log#error(java.lang.Throwable) - */ - public void error( Throwable error ) - { - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter( sWriter ); - - error.printStackTrace( pWriter ); - - System.err.println( "[error] " + sWriter.toString() ); - } - - /** - * @see org.apache.maven.plugin.logging.Log#isDebugEnabled() - */ - public boolean isDebugEnabled() - { - // TODO: Not sure how best to set these for this implementation... - return false; - } - - /** - * @see org.apache.maven.plugin.logging.Log#isInfoEnabled() - */ - public boolean isInfoEnabled() - { - return true; - } - - /** - * @see org.apache.maven.plugin.logging.Log#isWarnEnabled() - */ - public boolean isWarnEnabled() - { - return true; - } - - /** - * @see org.apache.maven.plugin.logging.Log#isErrorEnabled() - */ - public boolean isErrorEnabled() - { - return true; - } - - private void print( String prefix, CharSequence content ) - { - sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n" ); - } - - private void print( String prefix, Throwable error ) - { - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter( sWriter ); - - error.printStackTrace( pWriter ); - - sb.append( "[" + prefix + "] " ).append( sWriter.toString() ).append( "\n" ); - } - - private void print( String prefix, CharSequence content, Throwable error ) - { - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter( sWriter ); - - error.printStackTrace( pWriter ); - - sb.append( "[" + prefix + "] " ).append( content.toString() ).append( "\n\n" ) - .append( sWriter.toString() ).append( "\n" ); - } - - protected String getContent() - { - return sb.toString(); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java 2013-02-04 14:31:24.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestBuildClasspathMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,172 +0,0 @@ -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.io.File; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; -import org.apache.maven.project.MavenProject; - -public class TestBuildClasspathMojo - extends AbstractDependencyMojoTestCase -{ - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "build-classpath", true ); - } - - /** - * tests the proper discovery and configuration of the mojo - * - * @throws Exception - */ - public void testEnvironment() - throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml" ); - BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo( "build-classpath", testPom ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - // mojo.silent = true; - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - - mojo.execute(); - String file = null; - try - { - file = mojo.readClasspathFile(); - - fail( "Expected an illegal Argument Exception" ); - } - catch ( IllegalArgumentException e ) - { - // expected to catch this. - } - - mojo.setCpFile( new File( testDir, "buildClasspath.txt" ) ); - mojo.execute(); - - file = mojo.readClasspathFile(); - assertNotNull( file ); - assertTrue( file.length() > 0 ); - - assertTrue( file.indexOf( File.pathSeparator ) >= 0 ); - assertTrue( file.indexOf( File.separator ) >= 0 ); - - String fileSep = "#####"; - String pathSep = "%%%%%"; - - mojo.setFileSeparator( fileSep ); - mojo.setPathSeparator( pathSep ); - mojo.execute(); - - file = mojo.readClasspathFile(); - assertNotNull( file ); - assertTrue( file.length() > 0 ); - - assertFalse( file.indexOf( File.pathSeparator ) >= 0 ); - assertFalse( file.indexOf( File.separator ) >= 0 ); - assertTrue( file.indexOf( fileSep ) >= 0 ); - assertTrue( file.indexOf( pathSep ) >= 0 ); - - String propertyValue = project.getProperties().getProperty( "outputProperty" ); - assertNull( propertyValue ); - mojo.setOutputProperty( "outputProperty" ); - mojo.execute(); - propertyValue = project.getProperties().getProperty( "outputProperty" ); - assertNotNull( propertyValue ); - - } - - public void testPath() throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/build-classpath-test/plugin-config.xml" ); - BuildClasspathMojo mojo = (BuildClasspathMojo) lookupMojo( "build-classpath", testPom ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - - ArtifactRepository local = new StubArtifactRepository( stubFactory.getWorkingDir().getPath() ); - mojo.setLocal( local ); - - Artifact artifact = stubFactory.getReleaseArtifact(); - - - StringBuilder sb = new StringBuilder(); - mojo.setPrefix( null ); - mojo.setStripVersion( false ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals( artifact.getFile().getPath(), sb.toString() ); - - mojo.setLocalRepoProperty( "$M2_REPO" ); - sb.setLength( 0 ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals( "$M2_REPO" + File.separator + artifact.getFile().getName(), sb.toString() ); - - mojo.setLocalRepoProperty( "%M2_REPO%" ); - sb.setLength( 0 ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals( "%M2_REPO%" + File.separator + artifact.getFile().getName(), sb.toString() ); - - mojo.setLocalRepoProperty( "%M2_REPO%" ); - sb.setLength( 0 ); - mojo.setPrependGroupId( true ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals("If prefix is null, prependGroupId has no impact ", "%M2_REPO%"+File.separator - + DependencyUtil.getFormattedFileName( artifact, false, false ), sb.toString()); - - mojo.setLocalRepoProperty( "" ); - mojo.setPrefix( "prefix" ); - sb.setLength( 0 ); - mojo.setPrependGroupId( true ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals("prefix"+File.separator+DependencyUtil.getFormattedFileName( artifact, false, true ), - sb.toString()); - mojo.setPrependGroupId( false ); - - mojo.setLocalRepoProperty( "" ); - mojo.setPrefix( "prefix" ); - sb.setLength( 0 ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals("prefix"+File.separator+artifact.getFile().getName(),sb.toString()); - - mojo.setPrefix( "prefix" ); - mojo.setStripVersion( true ); - sb.setLength( 0 ); - mojo.appendArtifactPath( artifact, sb ); - assertEquals( "prefix" + File.separator + DependencyUtil.getFormattedFileName( artifact, true ), sb.toString() ); - - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo2.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo2.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo2.java 2012-10-16 22:36:04.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo2.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,379 +0,0 @@ -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.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.artifact.transform.SnapshotTransformation; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.StringUtils; - -public class TestCopyDependenciesMojo2 - extends AbstractDependencyMojoTestCase -{ - - CopyDependenciesMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "copy-dependencies", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" ); - mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom ); - mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); - // mojo.silent = true; - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - mojo.markersDirectory = new File( this.testDir, "markers" ); - - } - - public void assertNoMarkerFile( Artifact artifact ) - { - DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); - try - { - assertFalse( handle.isMarkerSet() ); - } - catch ( MojoExecutionException e ) - { - fail( e.getLongMessage() ); - } - - } - - public void testCopyDependenciesMojoIncludeCompileScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "compile"; - - mojo.execute(); - - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( saf.include( artifact ), file.exists() ); - } - } - - public void testCopyDependenciesMojoIncludeTestScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "test"; - - mojo.execute(); - - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( saf.include( artifact ), file.exists() ); - } - } - - public void testCopyDependenciesMojoIncludeRuntimeScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "runtime"; - - mojo.execute(); - - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( saf.include( artifact ), file.exists() ); - } - } - - public void testCopyDependenciesMojoIncludeprovidedScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "provided"; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ), file.exists() ); - } - } - - public void testCopyDependenciesMojoIncludesystemScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "system"; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ), file.exists() ); - } - } - - public void testSubPerArtifact() - throws Exception - { - mojo.useSubDirectoryPerArtifact = true; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - - public void testSubPerArtifactAndType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerArtifact = true; - mojo.useSubDirectoryPerType = true; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - - public void testSubPerArtifactAndScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerArtifact = true; - mojo.useSubDirectoryPerScope = true; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( true, false, true, false, false, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - - public void testRepositoryLayout() - throws Exception - { - String baseVersion = "2.0-SNAPSHOT"; - String groupId = "testGroupId"; - String artifactId = "expanded-snapshot"; - - Artifact expandedSnapshot = createExpandedVersionArtifact( baseVersion, - groupId, - artifactId, - "compile", - "jar", - null); - - mojo.project.getArtifacts().add( expandedSnapshot ); - mojo.project.getDependencyArtifacts().add( expandedSnapshot ); - - Artifact pomExpandedSnapshot = createExpandedVersionArtifact( baseVersion, - groupId, - artifactId, - "compile", - "pom", - null); - mojo.project.getArtifacts().add( pomExpandedSnapshot ); - mojo.project.getDependencyArtifacts().add( pomExpandedSnapshot ); - - mojo.useRepositoryLayout = true; - mojo.execute(); - - File outputDirectory = mojo.outputDirectory; - ArtifactRepository targetRepository = mojo.repositoryFactory.createDeploymentArtifactRepository( - "local", - outputDirectory.toURL().toExternalForm(), - new DefaultRepositoryLayout(), - false ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - assertArtifactExists( artifact, targetRepository ); - - if ( ! artifact.getBaseVersion().equals( artifact.getVersion() ) ) - { - Artifact baseArtifact = mojo.factory.createArtifact( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getBaseVersion(), - artifact.getScope(), - artifact.getType() ); - assertArtifactExists( baseArtifact, targetRepository ); - } - - } - } - - private Artifact createExpandedVersionArtifact( String baseVersion, - String groupId, - String artifactId, - String scope, - String type, - String classifier ) - throws IOException - { - Artifact expandedSnapshot = this.stubFactory.createArtifact( groupId, artifactId, baseVersion, scope, type, classifier ); - - SnapshotTransformation tr = new SnapshotTransformation(); - Snapshot snapshot = new Snapshot(); - snapshot.setTimestamp( tr.getDeploymentTimestamp() ); - snapshot.setBuildNumber( 1 ); - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( expandedSnapshot, snapshot ); - String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber(); - expandedSnapshot.setResolvedVersion( StringUtils.replace( baseVersion, Artifact.SNAPSHOT_VERSION, newVersion ) ); - expandedSnapshot.addMetadata( metadata ); - return expandedSnapshot; - } - - private void assertArtifactExists( Artifact artifact, ArtifactRepository targetRepository ) { - File file = new File( targetRepository.getBasedir(), - targetRepository.getLayout().pathOf( artifact ) ); - assertTrue( file.exists() ); - - Collection metas = artifact.getMetadataList(); - for ( ArtifactMetadata meta : metas ) - { - File metaFile = new File( targetRepository.getBasedir(), - targetRepository.getLayout().pathOfLocalRepositoryMetadata( meta, targetRepository) ); - assertTrue( metaFile.exists() ); - } - } - - public void testSubPerArtifactRemoveVersion() - throws Exception - { - mojo.useSubDirectoryPerArtifact = true; - mojo.stripVersion = true; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, true ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - - public void testSubPerArtifactAndTypeRemoveVersion() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerArtifact = true; - mojo.useSubDirectoryPerType = true; - mojo.stripVersion = true; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, true ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,776 +0,0 @@ -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 org.apache.maven.plugin.MojoFailureException; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; -import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.StringUtils; - -public class TestCopyDependenciesMojo - extends AbstractDependencyMojoTestCase -{ - - CopyDependenciesMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "copy-dependencies", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" ); - mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom ); - mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); - // mojo.silent = true; - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - mojo.markersDirectory = new File( this.testDir, "markers" ); - - } - - public void assertNoMarkerFile( Artifact artifact ) - { - DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); - try - { - assertFalse( handle.isMarkerSet() ); - } - catch ( MojoExecutionException e ) - { - fail( e.getLongMessage() ); - } - - } - - public void testCopyFile() - throws MojoExecutionException, IOException - { - File src = File.createTempFile( "copy", null ); - - File dest = new File( mojo.outputDirectory, "toMe.jar" ); - - assertFalse( dest.exists() ); - - mojo.copyFile( src, dest ); - assertTrue( dest.exists() ); - } - - /** - * tests the proper discovery and configuration of the mojo - * - * @throws Exception - */ - public void testMojo() - throws Exception - { - mojo.execute(); - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertTrue( file.exists() ); - - // there should be no markers for the copy mojo - assertNoMarkerFile( artifact ); - } - } - - public void testStripVersion() - throws Exception - { - mojo.stripVersion = true; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, true ); - File file = new File( mojo.outputDirectory, fileName ); - assertTrue( file.exists() ); - } - } - - public void testUseBaseVersion() - throws Exception - { - mojo.useBaseVersion = true; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false, false, true ); - File file = new File( mojo.outputDirectory, fileName ); - assertTrue( file.exists() ); - } - } - - public void testNoTransitive() - throws Exception - { - mojo.excludeTransitive = true; - mojo.execute(); - - Set artifacts = mojo.project.getDependencyArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertTrue( file.exists() ); - } - } - - public void testExcludeType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeTypes = "jar"; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), !file.exists() ); - } - } - - public void testIncludeType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - - mojo.includeTypes = "jar"; - mojo.excludeTypes = "jar"; - //shouldn't get anything. - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertFalse( file.exists() ); - } - - mojo.excludeTypes = ""; - mojo.execute(); - - artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), file.exists() ); - } - } - - - public void testExcludeArtifactId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeArtifactIds = "one"; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getArtifactId().equals( "one" ), !file.exists() ); - } - } - - public void testIncludeArtifactId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - - mojo.includeArtifactIds = "one"; - mojo.excludeArtifactIds = "one"; - //shouldn't get anything - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertFalse( file.exists() ); - } - - mojo.excludeArtifactIds = ""; - mojo.execute(); - - artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getArtifactId().equals( "one" ), file.exists() ); - } - } - - public void testIncludeGroupId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeGroupIds = "one"; - mojo.excludeGroupIds = "one"; - //shouldn't get anything - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertFalse( file.exists() ); - } - - mojo.excludeGroupIds = ""; - mojo.execute(); - - artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getGroupId().equals( "one" ), file.exists() ); - } - - } - - public void testExcludeGroupId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeGroupIds = "one"; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( artifact.getGroupId().equals( "one" ), !file.exists() ); - } - } - public void testExcludeMultipleGroupIds() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeGroupIds = "one,two"; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( artifact.getGroupId().equals( "one" ) || artifact.getGroupId().equals( "two" ), !file.exists() ); - } - } - - public void testExcludeClassifier() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getClassifiedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeClassifiers = "one"; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getClassifier().equals( "one" ), !file.exists() ); - } - } - - public void testIncludeClassifier() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getClassifiedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - - mojo.includeClassifiers = "one"; - mojo.excludeClassifiers = "one"; - //shouldn't get anything - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertFalse( file.exists() ); - } - - mojo.excludeClassifiers = ""; - mojo.execute(); - - artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getClassifier().equals( "one" ), file.exists() ); - } - - } - - public void testSubPerType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerType = true; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File folder = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, mojo.outputDirectory, - artifact ); - File file = new File( folder, fileName ); - assertTrue( file.exists() ); - } - } - - public void testCDMClassifier() - throws Exception - { - dotestClassifierType( "jdk14", null ); - } - - public void testCDMType() - throws Exception - { - dotestClassifierType( null, "sources" ); - } - - public void testCDMClassifierType() - throws Exception - { - dotestClassifierType( "jdk14", "sources" ); - } - - public void dotestClassifierType( String testClassifier, String testType ) - throws Exception - { - mojo.classifier = testClassifier; - mojo.type = testType; - - // init classifier things - mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); - mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); - mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String useClassifier = artifact.getClassifier(); - String useType = artifact.getType(); - - if ( StringUtils.isNotEmpty( testClassifier ) ) - { - useClassifier = "-" + testClassifier; - // type is only used if classifier is used. - if ( StringUtils.isNotEmpty( testType ) ) - { - useType = testType; - } - } - String fileName = artifact.getArtifactId() + "-" + artifact.getVersion() + useClassifier + "." + useType; - File file = new File( mojo.outputDirectory, fileName ); - - if ( !file.exists() ) - { - fail( "Can't find:" + file.getAbsolutePath() ); - } - - // there should be no markers for the copy mojo - assertNoMarkerFile( artifact ); - } - } - - public void testArtifactNotFound() - throws Exception - { - dotestArtifactExceptions( false, true ); - } - - public void testArtifactResolutionException() - throws Exception - { - dotestArtifactExceptions( true, false ); - } - - public void dotestArtifactExceptions( boolean are, boolean anfe ) - throws Exception - { - mojo.classifier = "jdk"; - mojo.type = "java-sources"; - - // init classifier things - mojo.factory = DependencyTestUtils.getArtifactFactory(); - mojo.resolver = new StubArtifactResolver( null, are, anfe ); - mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); - - try - { - mojo.execute(); - fail( "ExpectedException" ); - } - catch ( MojoExecutionException e ) - { - - } - } - - /* - * public void testOverwrite() { stubFactory.setCreateFiles( false ); - * Artifact artifact = stubFactory.createArtifact( "test", "artifact", "1.0" ); - * - * File testFile = new File( getBasedir() + File.separatorChar + - * "target/test-classes/unit/copy-dependencies-test/test.zip" ); } - */ - - public void testDontOverWriteRelease() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact release = stubFactory.getReleaseArtifact(); - release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( release ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteIfNewer = false; - - mojo.execute(); - - File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) ); - - Thread.sleep( 100 ); - // round up to the next second - long time = System.currentTimeMillis() + 1000; - time = time - ( time % 1000 ); - copiedFile.setLastModified( time ); - Thread.sleep( 100 ); - - mojo.execute(); - - assertEquals( time, copiedFile.lastModified() ); - } - - public void testOverWriteRelease() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact release = stubFactory.getReleaseArtifact(); - release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( release ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = true; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) ); - - Thread.sleep( 100 ); - // round down to the last second - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - copiedFile.setLastModified( time ); - // wait at least a second for filesystems that only record to the - // nearest second. - Thread.sleep( 1000 ); - - mojo.execute(); - - assertTrue( time < copiedFile.lastModified() ); - } - - public void testDontOverWriteSnap() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact snap = stubFactory.getSnapshotArtifact(); - snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( snap ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = false; - mojo.overWriteSnapshots = false; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) ); - - Thread.sleep( 100 ); - // round up to the next second - long time = System.currentTimeMillis() + 1000; - time = time - ( time % 1000 ); - copiedFile.setLastModified( time ); - Thread.sleep( 100 ); - - mojo.execute(); - - assertEquals( time, copiedFile.lastModified() ); - } - - public void testOverWriteSnap() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact snap = stubFactory.getSnapshotArtifact(); - snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( snap ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = false; - mojo.overWriteSnapshots = true; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) ); - - Thread.sleep( 100 ); - // round down to the last second - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - copiedFile.setLastModified( time ); - // wait at least a second for filesystems that only record to the - // nearest second. - Thread.sleep( 1000 ); - - mojo.execute(); - - assertTrue( time < copiedFile.lastModified() ); - } - - public void testGetDependencies() - throws MojoExecutionException - { - assertEquals( mojo.getResolvedDependencies( true ).toString(), mojo.getDependencySets( true ) - .getResolvedDependencies().toString() ); - } - - public void testExcludeProvidedScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "provided"; - // mojo.silent = false; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getScope().equals( "provided" ), !file.exists() ); - file.delete(); - assertFalse( file.exists() ); - } - - } - - public void testExcludeSystemScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "system"; - // mojo.silent = false; - - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - assertEquals( artifact.getScope().equals( "system" ), !file.exists() ); - file.delete(); - assertFalse( file.exists() ); - } - - } - - public void testExcludeCompileScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "compile"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( !saf.include( artifact ), file.exists() ); - } - } - - public void testExcludeTestScope() - throws IOException, MojoFailureException - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "test"; - - try - { - mojo.execute(); - fail( "expected an exception" ); - } - catch ( MojoExecutionException e ) - { - - } - - } - - public void testExcludeRuntimeScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "runtime"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName ); - - assertEquals( !saf.include( artifact ), file.exists() ); - } - } - - public void testCopyPom() - throws Exception - { - mojo.setCopyPom( true ); - mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); - mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); - - Set set = new HashSet(); - set.add( stubFactory.createArtifact( "org.apache.maven", "maven-artifact", "2.0.7", Artifact.SCOPE_COMPILE ) ); - mojo.project.setArtifacts( set ); - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false ); - File file = new File( mojo.outputDirectory, fileName.substring( 0, fileName.length() - 4 ) + ".pom" ); - assertTrue( file.exists() ); - } - } - - public void testPrependGroupId() - throws Exception - { - mojo.prependGroupId = true; - mojo.execute(); - - Set artifacts = mojo.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - String fileName = DependencyUtil.getFormattedFileName( artifact, false, true ); - File file = new File( mojo.outputDirectory, fileName ); - assertTrue( file.exists() ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java 2011-03-13 00:17:39.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,184 +0,0 @@ -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.io.File; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.project.MavenProject; - -public class TestIncludeExcludeUnpackDependenciesMojo - extends AbstractDependencyMojoTestCase -{ - private final String PACKED_FILE = "test.zip"; - - private final String UNPACKED_FILE_PREFIX = "test"; - private final String UNPACKED_FILE_SUFFIX = ".txt"; - - private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE; - - UnpackDependenciesMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "unpack-dependencies", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); - mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); - mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); - // mojo.silent = true; - - // it needs to get the archivermanager - //stubFactory.setUnpackableFile( mojo.getArchiverManager() ); - // i'm using one file repeatedly to archive so I can test the name - // programmatically. - stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + PACKED_FILE_PATH ) ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - mojo.markersDirectory = new File( this.testDir, "markers" ); - - } - - protected void tearDown() - { - super.tearDown(); - - mojo = null; - System.gc(); - } - - private void assertUnpacked( boolean unpacked, String fileName ) - { - File destFile = new File( mojo.getOutputDirectory().getAbsolutePath(), fileName ); - assertEquals( unpacked, destFile.exists() ); - } - - /** - * This test will validate that only the 1 and 11 files get unpacked - * @throws Exception - */ - public void testUnpackIncludesManyFiles() - throws Exception - { - mojo.setIncludes( "**/*1" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify only the 2 file gets unpacked - * @throws Exception - */ - public void testUnpackIncludesSingleFile() - throws Exception - { - mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify all files get unpacked - * @throws Exception - */ - public void testUnpackIncludesAllFiles() - throws Exception - { - mojo.setIncludes( "**/*" ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will validate that only the 2 and 3 files get unpacked - * @throws Exception - */ - public void testUnpackExcludesManyFiles() - throws Exception - { - mojo.setExcludes( "**/*1" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify only the 1, 11 & 3 files get unpacked - * @throws Exception - */ - public void testUnpackExcludesSingleFile() - throws Exception - { - mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify no files get unpacked - * @throws Exception - */ - public void testUnpackExcludesAllFiles() - throws Exception - { - mojo.setExcludes( "**/*" ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - public void testNoIncludeExcludes() - throws Exception - { - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java 2012-07-04 13:28:33.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestIncludeExcludeUnpackMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,316 +0,0 @@ -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 org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; -import org.apache.maven.plugin.dependency.fromConfiguration.UnpackMojo; -import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; -import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; -import org.apache.maven.plugin.testing.stubs.StubArtifactCollector; -import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; -import org.codehaus.plexus.archiver.manager.ArchiverManager; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class TestIncludeExcludeUnpackMojo - extends AbstractDependencyMojoTestCase -{ - private final String PACKED_FILE = "test.zip"; - - private final String UNPACKED_FILE_PREFIX = "test"; - - private final String UNPACKED_FILE_SUFFIX = ".txt"; - - private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE; - - UnpackMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "unpack", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml" ); - mojo = (UnpackMojo) lookupMojo( "unpack", testPom ); - mojo.setOutputDirectory( new File( this.testDir, "outputDirectory" ) ); - // mojo.silent = true; - - // it needs to get the archivermanager - //stubFactory.setUnpackableFile( mojo.getArchiverManager() ); - // i'm using one file repeatedly to archive so I can test the name - // programmatically. - stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + PACKED_FILE_PATH ) ); - Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); - ArtifactItem item = stubFactory.getArtifactItem( artifact ); - List list = new ArrayList( 1 ); - list.add( item ); - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - - mojo.setArchiverManager( (ArchiverManager) lookup( ArchiverManager.ROLE ) ); - - mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); - mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) ); - mojo.setMarkersDirectory( new File( this.testDir, "markers" ) ); - mojo.setArtifactCollector( new StubArtifactCollector() ); - mojo.setArtifactItems( list ); - } - - protected void tearDown() - { - super.tearDown(); - - mojo = null; - System.gc(); - } - - public void assertMarkerFiles( Collection items, boolean exist ) - { - for ( ArtifactItem item : items ) - { - assertMarkerFile( exist, item ); - } - } - - public void assertMarkerFile( boolean val, ArtifactItem item ) - { - UnpackFileMarkerHandler handle = new UnpackFileMarkerHandler( item, mojo.getMarkersDirectory() ); - try - { - assertEquals( val, handle.isMarkerSet() ); - } - catch ( MojoExecutionException e ) - { - fail( e.getLongMessage() ); - } - } - - private void assertUnpacked( boolean unpacked, String fileName ) - { - File destFile = new File( mojo.getOutputDirectory().getAbsolutePath(), fileName ); - assertEquals( unpacked, destFile.exists() ); - } - - /** - * This test will validate that only the 1 and 11 files get unpacked - * - * @throws Exception - */ - public void testUnpackIncludesManyFiles() - throws Exception - { - mojo.setIncludes( "**/*1" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify only the 2 file gets unpacked - * - * @throws Exception - */ - public void testUnpackIncludesSingleFile() - throws Exception - { - mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify all files get unpacked - * - * @throws Exception - */ - public void testUnpackIncludesAllFiles() - throws Exception - { - mojo.setIncludes( "**/*" ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will validate that only the 2 and 3 files get unpacked - * - * @throws Exception - */ - public void testUnpackExcludesManyFiles() - throws Exception - { - mojo.setExcludes( "**/*1" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify only the 1, 11 & 3 files get unpacked - * - * @throws Exception - */ - public void testUnpackExcludesSingleFile() - throws Exception - { - mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - /** - * This test will verify no files get unpacked - * - * @throws Exception - */ - public void testUnpackExcludesAllFiles() - throws Exception - { - mojo.setExcludes( "**/*" ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - public void testNoIncludeExcludes() - throws Exception - { - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - public void testIncludeArtifactItemOverride() - throws Exception - { - Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); - ArtifactItem item = stubFactory.getArtifactItem( artifact ); - item.setIncludes( "**/*" ); - List list = new ArrayList( 1 ); - list.add( item ); - mojo.setArtifactItems( list ); - mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - public void testExcludeArtifactItemOverride() - throws Exception - { - Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); - ArtifactItem item = stubFactory.getArtifactItem( artifact ); - item.setExcludes( "**/*" ); - List list = new ArrayList( 1 ); - list.add( item ); - mojo.setArtifactItems( list ); - mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - } - - public void testIncludeArtifactItemMultipleMarker() - throws Exception - { - List list = new ArrayList(); - Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); - ArtifactItem item = stubFactory.getArtifactItem( artifact ); - item.setOverWrite( "false" ); - item.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - list.add( item ); - item = stubFactory.getArtifactItem( artifact ); - item.setOverWrite( "false" ); - item.setIncludes( "**/test3" + UNPACKED_FILE_SUFFIX ); - list.add( item ); - mojo.setArtifactItems( list ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - assertMarkerFiles( mojo.getArtifactItems(), true ); - } - - public void testIncludeArtifactItemMultipleExecutions() - throws Exception - { - List list = new ArrayList(); - Artifact artifact = stubFactory.createArtifact( "test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null ); - ArtifactItem item = stubFactory.getArtifactItem( artifact ); - item.setOverWrite( "false" ); - item.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX ); - list.add( item ); - item = stubFactory.getArtifactItem( artifact ); - item.setOverWrite( "false" ); - item.setIncludes( "**/test3" + UNPACKED_FILE_SUFFIX ); - list.add( item ); - mojo.setArtifactItems( list ); - mojo.execute(); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - assertMarkerFiles( mojo.getArtifactItems(), true ); - - // Now run again and make sure the extracted files haven't gotten overwritten - File destFile2 = - new File( mojo.getOutputDirectory().getAbsolutePath(), UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX ); - File destFile3 = - new File( mojo.getOutputDirectory().getAbsolutePath(), UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX ); - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - destFile2.setLastModified( time ); - destFile3.setLastModified( time ); - assertEquals( time, destFile2.lastModified() ); - assertEquals( time, destFile3.lastModified() ); - Thread.sleep( 100 ); - mojo.execute(); - assertEquals( time, destFile2.lastModified() ); - assertEquals( time, destFile3.lastModified() ); - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java 2011-03-13 00:17:39.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -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.io.File; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo; -import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; -import org.apache.maven.plugin.testing.SilentLog; -import org.apache.maven.project.MavenProject; - -public class TestResolveMojo - extends AbstractDependencyMojoTestCase -{ - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "markers", false ); - } - - /** - * tests the proper discovery and configuration of the mojo - * - * @throws Exception - */ - public void testresolveTestEnvironment() - throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" ); - ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - mojo.silent = true; - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - - mojo.execute(); - DependencyStatusSets results = mojo.getResults(); - assertNotNull( results ); - assertEquals( artifacts.size(), results.getResolvedDependencies().size() ); - - setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE ); - - mojo.execute(); - results = mojo.getResults(); - assertNotNull( results ); - assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() ); - } - - public void testSilent() - throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" ); - ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom ); - mojo.silent = false; - - assertFalse( mojo.getLog() instanceof SilentLog ); - } // TODO: Test skipping artifacts. -} \ No newline at end of file diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestSkip.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestSkip.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestSkip.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestSkip.java 2013-05-12 07:41:46.000000000 +0000 @@ -32,131 +32,130 @@ public void testSkipAnalyze() throws Exception { - doTest("analyze"); + doTest( "analyze" ); } public void testSkipAnalyzeDepMgt() throws Exception { - doTest("analyze-dep-mgt"); + doTest( "analyze-dep-mgt" ); } public void testSkipAnalyzeOnly() throws Exception { - doTest("analyze-only"); + doTest( "analyze-only" ); } public void testSkipAnalyzeReport() throws Exception { - doSpecialTest("analyze-report"); + doSpecialTest( "analyze-report" ); } public void testSkipAnalyzeDuplicate() throws Exception { - doTest("analyze-duplicate"); + doTest( "analyze-duplicate" ); } public void testSkipBuildClasspath() throws Exception { - doTest("build-classpath"); + doTest( "build-classpath" ); } public void testSkipCopy() throws Exception { - doTest("copy"); + doTest( "copy" ); } public void testSkipCopyDependencies() throws Exception { - doTest("copy-dependencies"); + doTest( "copy-dependencies" ); } public void testSkipGet() throws Exception { - doSpecialTest("get"); + doSpecialTest( "get" ); } public void testSkipGoOffline() throws Exception { - doTest("go-offline"); + doTest( "go-offline" ); } public void testSkipList() throws Exception { - doTest("list"); + doTest( "list" ); } public void testSkipProperties() throws Exception { - doTest("properties"); + doTest( "properties" ); } public void testSkipPurgeLocalRepository() throws Exception { - doTest("purge-local-repository"); + doTest( "purge-local-repository" ); } public void testSkipResolve() throws Exception { - doTest("resolve"); + doTest( "resolve" ); } public void testSkipResolvePlugins() throws Exception { - doTest("resolve-plugins"); + doTest( "resolve-plugins" ); } public void testSkipSources() throws Exception { - doTest("sources"); + doTest( "sources" ); } public void testSkipTree() throws Exception { - doTest("tree"); + doTest( "tree" ); } public void testSkipUnpack() throws Exception { - doTest("unpack"); + doTest( "unpack" ); } public void testSkipUnpackDependencies() throws Exception { - doTest("unpack-dependencies"); + doTest( "unpack-dependencies" ); } - - protected void doTest(String mojoName) + protected void doTest( String mojoName ) throws Exception { - doConfigTest(mojoName, "plugin-config.xml"); + doConfigTest( mojoName, "plugin-config.xml" ); } - protected void doSpecialTest(String mojoName) + protected void doSpecialTest( String mojoName ) throws Exception { - doConfigTest(mojoName, "plugin-" + mojoName + "-config.xml"); + doConfigTest( mojoName, "plugin-" + mojoName + "-config.xml" ); } - private void doConfigTest(String mojoName, String configFile) + private void doConfigTest( String mojoName, String configFile ) throws Exception { File testPom = diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestTreeMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestTreeMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestTreeMojo.java 2012-07-24 20:24:01.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestTreeMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,231 +0,0 @@ -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.io.File; -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.Set; -import java.util.List; -import java.util.ArrayList; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.dependency.graph.DependencyNode; - -/** - * Tests TreeMojo. - * - * @author Mark Hobson - * @version $Id: TestTreeMojo.java 1365269 2012-07-24 20:24:01Z hboutemy $ - * @since 2.0 - */ -public class TestTreeMojo - extends AbstractDependencyMojoTestCase -{ - // TestCase methods ------------------------------------------------------- - - /* - * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp() - */ - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "tree", false ); - } - - // tests ------------------------------------------------------------------ - - public void testVoid() - { - // TODO: tests disabled during MDEP-339 work, to be reactivated - } - - /** - * Tests the proper discovery and configuration of the mojo. - * - * @throws Exception - */ - public void _testTreeTestEnvironment() - throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml" ); - TreeMojo mojo = (TreeMojo) lookupMojo( "tree", testPom ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - project.setArtifact( this.stubFactory.createArtifact( "testGroupId", "project", "1.0" ) ); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - - mojo.execute(); - - DependencyNode rootNode = mojo.getDependencyGraph(); - assertNodeEquals( "testGroupId:project:jar:1.0:compile", rootNode ); - assertEquals( 2, rootNode.getChildren().size() ); - assertChildNodeEquals( "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile", rootNode, 0 ); - assertChildNodeEquals( "testGroupId:release:jar:1.0:compile", rootNode, 1 ); - } - - /** - * Test the DOT format serialization - * - * @throws Exception - */ - public void _testTreeDotSerializing() - throws Exception - { - List contents = runTreeMojo( "tree1.dot", "dot" ); - assertTrue( findString( contents, "digraph \"testGroupId:project:jar:1.0:compile\" {" ) ); - assertTrue( findString( contents, - "\"testGroupId:project:jar:1.0:compile\" -> \"testGroupId:snapshot:jar:2.0-SNAPSHOT:compile\"" ) ); - assertTrue( findString( contents, - "\"testGroupId:project:jar:1.0:compile\" -> \"testGroupId:release:jar:1.0:compile\"" ) ); - } - - /** - * Test the GraphML format serialization - * - * @throws Exception - */ - public void _testTreeGraphMLSerializing() - throws Exception - { - List contents = runTreeMojo( "tree1.graphml", "graphml" ); - - assertTrue( findString( contents, "" ) ); - assertTrue( findString( contents, "testGroupId:project:jar:1.0:compile" ) ); - assertTrue( findString( contents, "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile" ) ); - assertTrue( findString( contents, "testGroupId:release:jar:1.0:compile" ) ); - assertTrue( findString( contents, "" ) ); - assertTrue( findString( contents, "" ) ); - } - - /** - * Test the TGF format serialization - * - * @throws Exception - */ - public void _testTreeTGFSerializing() - throws Exception - { - List contents = runTreeMojo( "tree1.tgf", "tgf" ); - assertTrue( findString( contents, "testGroupId:project:jar:1.0:compile" ) ); - assertTrue( findString( contents, "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile" ) ); - assertTrue( findString( contents, "testGroupId:release:jar:1.0:compile" ) ); - } - - /** - * Help finding content in the given list of string - * @param outputFile - * @param format - * @return list of strings in the output file - */ - private List runTreeMojo( String outputFile, String format ) - throws Exception - { - File testPom = new File( getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml" ); - String outputFileName = testDir.getAbsolutePath() + outputFile; - TreeMojo mojo = (TreeMojo) lookupMojo( "tree", testPom ); - setVariableValueToObject( mojo, "outputType", format ); - setVariableValueToObject( mojo, "outputFile", new File( outputFileName ) ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - project.setArtifact( this.stubFactory.createArtifact( "testGroupId", "project", "1.0" ) ); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - - mojo.execute(); - - BufferedReader fp1 = new BufferedReader( new FileReader( outputFileName ) ); - List contents = new ArrayList(); - - String line = null; - while ( ( line = fp1.readLine() ) != null ) - { - contents.add( line ); - } - fp1.close(); - - return contents ; - } - - /** - * Help finding content in the given list of string - * @param contents - * @param str - */ - private boolean findString( List contents, String str ) - { - for ( String line : contents ) - { - if ( line.indexOf( str ) != -1 ) - { - // if match then return here - return true; - } - } - - // in case no match for the whole list - return false; - } - - // private methods -------------------------------------------------------- - - private void assertChildNodeEquals( String expectedNode, DependencyNode actualParentNode, int actualChildIndex ) - { - DependencyNode actualNode = (DependencyNode) actualParentNode.getChildren().get( actualChildIndex ); - - assertNodeEquals( expectedNode, actualNode ); - } - - private void assertNodeEquals( String expectedNode, DependencyNode actualNode ) - { - String[] tokens = expectedNode.split( ":" ); - - assertNodeEquals( tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], actualNode ); - } - - private void assertNodeEquals( String expectedGroupId, String expectedArtifactId, String expectedType, - String expectedVersion, String expectedScope, DependencyNode actualNode ) - { - Artifact actualArtifact = actualNode.getArtifact(); - - assertEquals( "group id", expectedGroupId, actualArtifact.getGroupId() ); - assertEquals( "artifact id", expectedArtifactId, actualArtifact.getArtifactId() ); - assertEquals( "type", expectedType, actualArtifact.getType() ); - assertEquals( "version", expectedVersion, actualArtifact.getVersion() ); - assertEquals( "scope", expectedScope, actualArtifact.getScope() ); - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo2.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo2.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo2.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo2.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,255 +0,0 @@ -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 org.apache.maven.plugin.MojoFailureException; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -public class TestUnpackDependenciesMojo2 - extends AbstractDependencyMojoTestCase -{ - - private final String UNPACKABLE_FILE = "test.txt"; - - private final String UNPACKABLE_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + UNPACKABLE_FILE; - - UnpackDependenciesMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "unpack-dependencies", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); - mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); - mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); - mojo.useJvmChmod = true; - // mojo.silent = true; - - // it needs to get the archivermanager - stubFactory.setUnpackableFile( mojo.getArchiverManager() ); - // i'm using one file repeatedly to archive so I can test the name - // programmatically. - stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH ) ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - mojo.markersDirectory = new File( this.testDir, "markers" ); - - } - - protected void tearDown() - { - super.tearDown(); - - mojo = null; - System.gc(); - } - - public File getUnpackedFile( Artifact artifact ) - { - File destDir = DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), - mojo.isUseSubDirectoryPerType(), - mojo.isUseSubDirectoryPerArtifact(), - mojo.useRepositoryLayout, mojo.stripVersion, - mojo.getOutputDirectory(), artifact ); - File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); - assertTrue( unpacked.exists() ); - return unpacked; - } - - public void testDontOverWriteRelease() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact release = stubFactory.getReleaseArtifact(); - release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( release ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteIfNewer = false; - - mojo.execute(); - - assertUnpacked( release, false ); - } - - public void testOverWriteRelease() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact release = stubFactory.getReleaseArtifact(); - release.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( release ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = true; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - assertUnpacked( release, true ); - } - - public void testDontOverWriteSnap() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact snap = stubFactory.getSnapshotArtifact(); - snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( snap ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = false; - mojo.overWriteSnapshots = false; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - assertUnpacked( snap, false ); - } - - public void testOverWriteSnap() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact snap = stubFactory.getSnapshotArtifact(); - snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( snap ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = false; - mojo.overWriteSnapshots = true; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - assertUnpacked( snap, true ); - - } - - public void testOverWriteIfNewer() - throws MojoExecutionException, InterruptedException, IOException, MojoFailureException - { - - Set artifacts = new HashSet(); - Artifact snap = stubFactory.getSnapshotArtifact(); - snap.getFile().setLastModified( System.currentTimeMillis() - 2000 ); - - artifacts.add( snap ); - - mojo.project.setArtifacts( artifacts ); - mojo.project.setDependencyArtifacts( artifacts ); - - mojo.overWriteReleases = false; - mojo.overWriteSnapshots = false; - mojo.overWriteIfNewer = false; - - mojo.execute(); - - File unpackedFile = getUnpackedFile( snap ); - - // round down to the last second - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - // set source to be newer and dest to be a known value. - snap.getFile().setLastModified( time + 3000 ); - unpackedFile.setLastModified( time ); - // wait at least a second for filesystems that only record to the - // nearest second. - Thread.sleep( 1000 ); - - assertEquals( time, unpackedFile.lastModified() ); - mojo.execute(); - System.gc(); - // make sure it didn't overwrite - assertEquals( time, unpackedFile.lastModified() ); - - mojo.overWriteIfNewer = true; - - mojo.execute(); - - assertTrue( time != unpackedFile.lastModified() ); - - System.gc(); - } - - public void assertUnpacked( Artifact artifact, boolean overWrite ) - throws InterruptedException, MojoExecutionException, MojoFailureException - { - File unpackedFile = getUnpackedFile( artifact ); - - Thread.sleep( 100 ); - // round down to the last second - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - unpackedFile.setLastModified( time ); - // wait at least a second for filesystems that only record to the - // nearest second. - Thread.sleep( 1000 ); - - assertEquals( time, unpackedFile.lastModified() ); - mojo.execute(); - - if ( overWrite ) - { - assertTrue( time != unpackedFile.lastModified() ); - } - else - { - assertEquals( time, unpackedFile.lastModified() ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,678 +0,0 @@ -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 org.apache.maven.plugin.MojoFailureException; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory; -import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils; -import org.apache.maven.plugin.dependency.utils.DependencyUtil; -import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; -import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public class TestUnpackDependenciesMojo - extends AbstractDependencyMojoTestCase -{ - - private final String UNPACKABLE_FILE = "test.txt"; - - private final String UNPACKABLE_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + UNPACKABLE_FILE; - - UnpackDependenciesMojo mojo; - - protected void setUp() - throws Exception - { - // required for mojo lookups to work - super.setUp( "unpack-dependencies", true ); - - File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml" ); - mojo = (UnpackDependenciesMojo) lookupMojo( "unpack-dependencies", testPom ); - mojo.outputDirectory = new File( this.testDir, "outputDirectory" ); - mojo.useJvmChmod = true; - // mojo.silent = true; - - // it needs to get the archivermanager - stubFactory.setUnpackableFile( mojo.getArchiverManager() ); - // i'm using one file repeatedly to archive so I can test the name - // programmatically. - stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH ) ); - - assertNotNull( mojo ); - assertNotNull( mojo.getProject() ); - MavenProject project = mojo.getProject(); - - Set artifacts = this.stubFactory.getScopedArtifacts(); - Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); - artifacts.addAll( directArtifacts ); - - project.setArtifacts( artifacts ); - project.setDependencyArtifacts( directArtifacts ); - mojo.markersDirectory = new File( this.testDir, "markers" ); - - } - - protected void tearDown() - { - super.tearDown(); - - mojo = null; - System.gc(); - } - - public void assertUnpacked( Artifact artifact ) - { - assertUnpacked( true, artifact ); - } - - public void assertUnpacked( boolean val, Artifact artifact ) - { - File folder = - DependencyUtil.getFormattedOutputDirectory( mojo.useSubDirectoryPerScope, mojo.useSubDirectoryPerType, - mojo.useSubDirectoryPerArtifact, mojo.useRepositoryLayout, - mojo.stripVersion, mojo.outputDirectory, artifact ); - - File destFile = new File( folder, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); - - assertEquals( val, destFile.exists() ); - assertMarkerFile( val, artifact ); - } - - public void assertMarkerFile( boolean val, Artifact artifact ) - { - DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory ); - try - { - assertEquals( val, handle.isMarkerSet() ); - } - catch ( MojoExecutionException e ) - { - fail( e.getLongMessage() ); - } - } - - public void testMojo() - throws Exception - { - mojo.execute(); - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testNoTransitive() - throws Exception - { - mojo.excludeTransitive = true; - mojo.execute(); - Iterator iter = mojo.project.getDependencyArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testExcludeType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArchiveArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeTypes = "jar"; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - - assertUnpacked( !artifact.getType().equalsIgnoreCase( "jar" ), artifact ); - } - } - - public void testExcludeProvidedScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "provided"; - // mojo.silent = false; - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !artifact.getScope().equals( "provided" ), artifact ); - } - - } - - public void testExcludeSystemScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "system"; - // mojo.silent = false; - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !artifact.getScope().equals( "system" ), artifact ); - } - - } - - public void testExcludeCompileScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "compile"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !saf.include( artifact ), artifact ); - } - } - - public void testExcludeTestScope() - throws IOException, MojoFailureException - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "test"; - - try - { - mojo.execute(); - fail( "expected an exception" ); - } - catch ( MojoExecutionException e ) - { - - } - - } - - public void testExcludeRuntimeScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeScope = "runtime"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope ); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !saf.include( artifact ), artifact ); - } - } - - public void testIncludeType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArchiveArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - - mojo.includeTypes = "jar"; - mojo.excludeTypes = "jar"; - //shouldn't get anything - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - - assertUnpacked( false, artifact ); - } - - mojo.excludeTypes = ""; - mojo.execute(); - - iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - - assertUnpacked( artifact.getType().equalsIgnoreCase( "jar" ), artifact ); - } - } - - public void testSubPerType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArchiveArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerType = true; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testSubPerArtifact() - throws Exception - { - mojo.useSubDirectoryPerArtifact = true; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testSubPerArtifactAndType() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArchiveArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerArtifact = true; - mojo.useSubDirectoryPerType = true; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testSubPerArtifactRemoveVersion() - throws Exception - { - mojo.useSubDirectoryPerArtifact = true; - mojo.stripVersion = true; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testSubPerArtifactAndTypeRemoveVersion() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getTypedArchiveArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.useSubDirectoryPerArtifact = true; - mojo.useSubDirectoryPerType = true; - mojo.stripVersion = true; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact ); - } - } - - public void testIncludeCompileScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "compile"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( saf.include( artifact ), artifact ); - } - } - - public void testIncludeTestScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "test"; - - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( saf.include( artifact ), artifact ); - } - } - - public void testIncludeRuntimeScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "runtime"; - mojo.execute(); - ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope ); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( saf.include( artifact ), artifact ); - } - } - - public void testIncludeprovidedScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "provided"; - - mojo.execute(); - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ), artifact ); - } - } - - public void testIncludesystemScope() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getScopedArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeScope = "system"; - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ), artifact ); - } - } - - public void testIncludeArtifactId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - - mojo.includeArtifactIds = "one"; - mojo.excludeArtifactIds = "one"; - //shouldn't get anything - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( false, artifact ); - } - mojo.excludeArtifactIds = ""; - mojo.execute(); - - iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( artifact.getArtifactId().equals( "one" ), artifact ); - } - - } - - public void testExcludeArtifactId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeArtifactIds = "one"; - mojo.execute(); - - // test - get all direct dependencies and verify that they exist if they - // do not have a classifier of "one" - // then delete the file and at the end, verify the folder is empty. - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !artifact.getArtifactId().equals( "one" ), artifact ); - } - } - - public void testExcludeGroupId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.excludeGroupIds = "one"; - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - assertUnpacked( !artifact.getGroupId().equals( "one" ), artifact ); - } - } - - public void testIncludeGroupId() - throws Exception - { - mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() ); - mojo.project.setDependencyArtifacts( new HashSet() ); - mojo.includeGroupIds = "one"; - mojo.excludeGroupIds = "one"; - //shouldn't get anything - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - // Testing with artifact id because group id is not in filename - assertUnpacked( false, artifact ); - } - - mojo.excludeGroupIds = ""; - mojo.execute(); - - iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - // Testing with artifact id because group id is not in filename - assertUnpacked( artifact.getGroupId().equals( "one" ), artifact ); - } - - } - - public void testCDMClassifier() - throws Exception - { - dotestClassifierType( "jdk14", null ); - } - - public void testCDMType() - throws Exception - { - dotestClassifierType( null, "zip" ); - } - - public void testCDMClassifierType() - throws Exception - { - dotestClassifierType( "jdk14", "war" ); - } - - public void dotestClassifierType( String testClassifier, String testType ) - throws Exception - { - mojo.classifier = testClassifier; - mojo.type = testType; - mojo.factory = DependencyTestUtils.getArtifactFactory(); - mojo.resolver = new StubArtifactResolver( stubFactory, false, false ); - mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); - - mojo.execute(); - - Iterator iter = mojo.project.getArtifacts().iterator(); - while ( iter.hasNext() ) - { - Artifact artifact = iter.next(); - - String useClassifier = artifact.getClassifier(); - String useType = artifact.getType(); - - if ( StringUtils.isNotEmpty( testClassifier ) ) - { - useClassifier = testClassifier; - // type is only used if classifier is used. - if ( StringUtils.isNotEmpty( testType ) ) - { - useType = testType; - } - } - Artifact unpacked = - stubFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), - Artifact.SCOPE_COMPILE, useType, useClassifier ); - assertUnpacked( unpacked ); - } - } - - public void testArtifactNotFound() - throws Exception - { - dotestArtifactExceptions( false, true ); - } - - public void testArtifactResolutionException() - throws Exception - { - dotestArtifactExceptions( true, false ); - } - - public void dotestArtifactExceptions( boolean are, boolean anfe ) - throws Exception - { - mojo.classifier = "jdk"; - mojo.type = "java-sources"; - // init classifier things - mojo.setFactory( DependencyTestUtils.getArtifactFactory() ); - mojo.setResolver( new StubArtifactResolver( null, are, anfe ) ); - mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) ); - - try - { - mojo.execute(); - fail( "ExpectedException" ); - } - catch ( MojoExecutionException e ) - { - } - } - - public File getUnpackedFile( Artifact artifact ) - { - File destDir = DependencyUtil.getFormattedOutputDirectory( mojo.isUseSubDirectoryPerScope(), - mojo.isUseSubDirectoryPerType(), - mojo.isUseSubDirectoryPerArtifact(), - mojo.useRepositoryLayout, mojo.stripVersion, - mojo.getOutputDirectory(), artifact ); - File unpacked = new File( destDir, DependencyArtifactStubFactory.getUnpackableFileName( artifact ) ); - assertTrue( unpacked.exists() ); - return unpacked; - } - - public DefaultFileMarkerHandler getUnpackedMarkerHandler( Artifact artifact ) - { - return new DefaultFileMarkerHandler( artifact, mojo.getMarkersDirectory() ); - } - - - public void assertUnpacked( Artifact artifact, boolean overWrite ) - throws InterruptedException, MojoExecutionException, MojoFailureException - { - File unpackedFile = getUnpackedFile( artifact ); - - Thread.sleep( 100 ); - // round down to the last second - long time = System.currentTimeMillis(); - time = time - ( time % 1000 ); - unpackedFile.setLastModified( time ); - // wait at least a second for filesystems that only record to the - // nearest second. - Thread.sleep( 1000 ); - - assertEquals( time, unpackedFile.lastModified() ); - mojo.execute(); - - if ( overWrite ) - { - assertTrue( time != unpackedFile.lastModified() ); - } - else - { - assertEquals( time, unpackedFile.lastModified() ); - } - } -} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/tree/TestTreeMojo.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/tree/TestTreeMojo.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/tree/TestTreeMojo.java 1970-01-01 00:00:00.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/tree/TestTreeMojo.java 2013-05-12 13:14:31.000000000 +0000 @@ -0,0 +1,233 @@ +package org.apache.maven.plugin.dependency.tree; + +/* + * 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.io.File; +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.Set; +import java.util.List; +import java.util.ArrayList; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase; +import org.apache.maven.plugin.dependency.tree.TreeMojo; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.graph.DependencyNode; + +/** + * Tests TreeMojo. + * + * @author Mark Hobson + * @version $Id: TestTreeMojo.java 1481552 2013-05-12 13:14:31Z hboutemy $ + * @since 2.0 + */ +public class TestTreeMojo + extends AbstractDependencyMojoTestCase +{ + // TestCase methods ------------------------------------------------------- + + /* + * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp() + */ + protected void setUp() + throws Exception + { + // required for mojo lookups to work + super.setUp( "tree", false ); + } + + // tests ------------------------------------------------------------------ + + public void testVoid() + { + // TODO: tests disabled during MDEP-339 work, to be reactivated + } + + /** + * Tests the proper discovery and configuration of the mojo. + * + * @throws Exception + */ + public void _testTreeTestEnvironment() + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml" ); + TreeMojo mojo = (TreeMojo) lookupMojo( "tree", testPom ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + project.setArtifact( this.stubFactory.createArtifact( "testGroupId", "project", "1.0" ) ); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + + mojo.execute(); + + DependencyNode rootNode = mojo.getDependencyGraph(); + assertNodeEquals( "testGroupId:project:jar:1.0:compile", rootNode ); + assertEquals( 2, rootNode.getChildren().size() ); + assertChildNodeEquals( "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile", rootNode, 0 ); + assertChildNodeEquals( "testGroupId:release:jar:1.0:compile", rootNode, 1 ); + } + + /** + * Test the DOT format serialization + * + * @throws Exception + */ + public void _testTreeDotSerializing() + throws Exception + { + List contents = runTreeMojo( "tree1.dot", "dot" ); + assertTrue( findString( contents, "digraph \"testGroupId:project:jar:1.0:compile\" {" ) ); + assertTrue( findString( contents, + "\"testGroupId:project:jar:1.0:compile\" -> \"testGroupId:snapshot:jar:2.0-SNAPSHOT:compile\"" ) ); + assertTrue( findString( contents, + "\"testGroupId:project:jar:1.0:compile\" -> \"testGroupId:release:jar:1.0:compile\"" ) ); + } + + /** + * Test the GraphML format serialization + * + * @throws Exception + */ + public void _testTreeGraphMLSerializing() + throws Exception + { + List contents = runTreeMojo( "tree1.graphml", "graphml" ); + + assertTrue( findString( contents, "" ) ); + assertTrue( findString( contents, "testGroupId:project:jar:1.0:compile" ) ); + assertTrue( findString( contents, "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile" ) ); + assertTrue( findString( contents, "testGroupId:release:jar:1.0:compile" ) ); + assertTrue( findString( contents, "" ) ); + assertTrue( findString( contents, "" ) ); + } + + /** + * Test the TGF format serialization + * + * @throws Exception + */ + public void _testTreeTGFSerializing() + throws Exception + { + List contents = runTreeMojo( "tree1.tgf", "tgf" ); + assertTrue( findString( contents, "testGroupId:project:jar:1.0:compile" ) ); + assertTrue( findString( contents, "testGroupId:snapshot:jar:2.0-SNAPSHOT:compile" ) ); + assertTrue( findString( contents, "testGroupId:release:jar:1.0:compile" ) ); + } + + /** + * Help finding content in the given list of string + * @param outputFile + * @param format + * @return list of strings in the output file + */ + private List runTreeMojo( String outputFile, String format ) + throws Exception + { + File testPom = new File( getBasedir(), "target/test-classes/unit/tree-test/plugin-config.xml" ); + String outputFileName = testDir.getAbsolutePath() + outputFile; + TreeMojo mojo = (TreeMojo) lookupMojo( "tree", testPom ); + setVariableValueToObject( mojo, "outputType", format ); + setVariableValueToObject( mojo, "outputFile", new File( outputFileName ) ); + + assertNotNull( mojo ); + assertNotNull( mojo.getProject() ); + MavenProject project = mojo.getProject(); + project.setArtifact( this.stubFactory.createArtifact( "testGroupId", "project", "1.0" ) ); + + Set artifacts = this.stubFactory.getScopedArtifacts(); + Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts(); + artifacts.addAll( directArtifacts ); + + project.setArtifacts( artifacts ); + project.setDependencyArtifacts( directArtifacts ); + + mojo.execute(); + + BufferedReader fp1 = new BufferedReader( new FileReader( outputFileName ) ); + List contents = new ArrayList(); + + String line = null; + while ( ( line = fp1.readLine() ) != null ) + { + contents.add( line ); + } + fp1.close(); + + return contents ; + } + + /** + * Help finding content in the given list of string + * @param contents + * @param str + */ + private boolean findString( List contents, String str ) + { + for ( String line : contents ) + { + if ( line.indexOf( str ) != -1 ) + { + // if match then return here + return true; + } + } + + // in case no match for the whole list + return false; + } + + // private methods -------------------------------------------------------- + + private void assertChildNodeEquals( String expectedNode, DependencyNode actualParentNode, int actualChildIndex ) + { + DependencyNode actualNode = (DependencyNode) actualParentNode.getChildren().get( actualChildIndex ); + + assertNodeEquals( expectedNode, actualNode ); + } + + private void assertNodeEquals( String expectedNode, DependencyNode actualNode ) + { + String[] tokens = expectedNode.split( ":" ); + + assertNodeEquals( tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], actualNode ); + } + + private void assertNodeEquals( String expectedGroupId, String expectedArtifactId, String expectedType, + String expectedVersion, String expectedScope, DependencyNode actualNode ) + { + Artifact actualArtifact = actualNode.getArtifact(); + + assertEquals( "group id", expectedGroupId, actualArtifact.getGroupId() ); + assertEquals( "artifact id", expectedArtifactId, actualArtifact.getArtifactId() ); + assertEquals( "type", expectedType, actualArtifact.getType() ); + assertEquals( "version", expectedVersion, actualArtifact.getVersion() ); + assertEquals( "scope", expectedScope, actualArtifact.getScope() ); + } +} diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java 2011-03-27 15:51:44.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestDestFileFilter.java 2013-04-02 10:28:02.000000000 +0000 @@ -76,16 +76,23 @@ } public File createFile( Artifact artifact, boolean useSubDirectoryPerArtifact, boolean useSubDirectoryPerType, - boolean removeVersion ) + boolean removeVersion) throws IOException { + return createFile(artifact, useSubDirectoryPerArtifact, useSubDirectoryPerType, removeVersion, false); + } + + public File createFile(Artifact artifact, boolean useSubDirectoryPerArtifact, boolean useSubDirectoryPerType, + boolean removeVersion, boolean removeClassifier) + throws IOException + { File destFolder = - DependencyUtil.getFormattedOutputDirectory( false, useSubDirectoryPerType, useSubDirectoryPerArtifact, - false, false, outputFolder, artifact ); - File destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, removeVersion ) ); + DependencyUtil.getFormattedOutputDirectory(false, useSubDirectoryPerType, useSubDirectoryPerArtifact, + false, false, outputFolder, artifact); + File destFile = new File(destFolder, DependencyUtil.getFormattedFileName(artifact, removeVersion, false, false, removeClassifier)); destFile.getParentFile().mkdirs(); - assertTrue( destFile.createNewFile() ); + assertTrue(destFile.createNewFile()); return destFile; } @@ -132,6 +139,21 @@ assertTrue( filter.isArtifactIncluded( artifact ) ); } + public void testDestFileStripClassifier() + throws IOException, ArtifactFilterException + { + DestFileFilter filter = new DestFileFilter(outputFolder); + Artifact artifact = fact.getSnapshotArtifact(); + filter.setRemoveClassifier(true); + + assertTrue(filter.isArtifactIncluded(artifact)); + createFile(artifact, false, false, false, true); + assertFalse(filter.isArtifactIncluded(artifact)); + + filter.setOverWriteSnapshots(true); + assertTrue(filter.isArtifactIncluded(artifact)); + } + public void testDestFileSubPerArtifact() throws IOException, ArtifactFilterException { diff -Nru maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java --- maven-dependency-plugin-2.7/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java 2012-10-16 22:25:26.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/java/org/apache/maven/plugin/dependency/utils/TestDependencyUtil.java 2013-05-12 14:01:17.000000000 +0000 @@ -118,7 +118,7 @@ assertTrue( expectedResult.equalsIgnoreCase( name.getAbsolutePath() ) ); name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, folder, artifact ); - expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-sources-1.1-jar"; + expectedResult = folder.getAbsolutePath() + File.separatorChar + "one-1.1-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, true, folder, artifact ); @@ -127,7 +127,7 @@ name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, false, folder, artifact ); expectedResult = folder.getAbsolutePath() + File.separatorChar + "jars" + File.separatorChar - + "one-sources-1.1-jar"; + + "one-1.1-sources-jar"; assertEquals( expectedResult, name.getAbsolutePath() ); name = DependencyUtil.getFormattedOutputDirectory( false, true, true, false, true, folder, artifact ); @@ -186,7 +186,7 @@ assertEquals( expectedResult, name.getAbsolutePath() ); name = DependencyUtil.getFormattedOutputDirectory( false, false, true, false, false, folder, sources ); - expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-sources-1.1-SNAPSHOT-sources"; + expectedResult = folder.getAbsolutePath() + File.separatorChar + "two-1.1-SNAPSHOT-sources"; assertEquals( expectedResult, name.getAbsolutePath() ); } @@ -244,13 +244,16 @@ name = DependencyUtil.getFormattedFileName( artifact, true ); expectedResult = "two-sources.jar"; assertEquals( expectedResult, name ); - + + name = DependencyUtil.getFormattedFileName(artifact, false, false, false, true); + expectedResult = "two-1.1-SNAPSHOT.jar"; + assertEquals( expectedResult, name ); + ah = new DefaultArtifactHandlerStub( "war", null ); artifact = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false ); name = DependencyUtil.getFormattedFileName( artifact, true ); expectedResult = "two.war"; assertEquals( expectedResult, name ); - } public void testFileNameClassifierWithFile() @@ -271,10 +274,14 @@ String expectedResult = "two-1.1-SNAPSHOT-sources.war"; assertEquals( expectedResult, name ); + name = DependencyUtil.getFormattedFileName( artifact, false, false, false, true ); + expectedResult = "two-1.1-SNAPSHOT.war"; + assertEquals( expectedResult, name ); + name = DependencyUtil.getFormattedFileName( artifact, true ); expectedResult = "two-sources.war"; assertEquals( expectedResult, name ); - + artifact = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false ); name = DependencyUtil.getFormattedFileName( artifact, true ); expectedResult = "two.war"; diff -Nru maven-dependency-plugin-2.7/src/test/resources/unit/skip-test/plugin-analyze-report-config.xml maven-dependency-plugin-2.8/src/test/resources/unit/skip-test/plugin-analyze-report-config.xml --- maven-dependency-plugin-2.7/src/test/resources/unit/skip-test/plugin-analyze-report-config.xml 2013-02-28 04:22:41.000000000 +0000 +++ maven-dependency-plugin-2.8/src/test/resources/unit/skip-test/plugin-analyze-report-config.xml 2013-05-12 07:46:11.000000000 +0000 @@ -38,7 +38,7 @@ true - /some/folder + target/unit-tests/skip-test