Moved out of sandbox to prepare for maven-dependency-plugin integration
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@518839 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..47916a2
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,378 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
\ No newline at end of file
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..b5dd759
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,9 @@
+Maven Dependency Plugin
+ Copyright 1999-2006 The Apache Software Foundation
+
+ This product includes software developed at
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Portions of this software utilize the Plexus Container, API, and
+ Components. Copyright the Codehaus. The original software is
+ available from http://plexus.codehaus.org/
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100755
index 0000000..f1704d8
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ * 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.
+ *
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>3</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-dependency-analyzer</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>Maven Dependency Analyzer</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.4</source>
+ <target>1.4</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ <resources>
+ <!-- Include super-pom defined main/resources
+ Removing this section will break the build.
+ Since we have defined a new build/resources
+ section for the Apache process LICENSE and NOTICE
+ files, this original default section is now
+ required. -->
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>3.0_RC1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.5</version>
+ </dependency>
+ <dependency>
+ <groupId>jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>1.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassAnalyzer.java
new file mode 100644
index 0000000..cb4cc2b
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassAnalyzer.java
@@ -0,0 +1,42 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.IOException;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public interface ClassAnalyzer
+{
+ // fields -----------------------------------------------------------------
+
+ String ROLE = ClassAnalyzer.class.getName();
+
+ // public methods ---------------------------------------------------------
+
+ Set analyze( URL url )
+ throws IOException;
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitor.java
new file mode 100644
index 0000000..7f37c0d
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitor.java
@@ -0,0 +1,33 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.InputStream;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public interface ClassFileVisitor
+{
+ void visitClass( String className, InputStream in );
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtils.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtils.java
new file mode 100644
index 0000000..65a2496
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtils.java
@@ -0,0 +1,149 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public final class ClassFileVisitorUtils
+{
+ // constants --------------------------------------------------------------
+
+ private static final String[] CLASS_INCLUDES = { "**/*.class" };
+
+ // constructors -----------------------------------------------------------
+
+ private ClassFileVisitorUtils()
+ {
+ // private constructor for utility class
+ }
+
+ // public methods ---------------------------------------------------------
+
+ public static void accept( URL url, ClassFileVisitor visitor )
+ throws IOException
+ {
+ if ( url.getPath().endsWith( ".jar" ) )
+ {
+ acceptJar( url, visitor );
+ }
+ else if ( url.getProtocol().equals( "file" ) )
+ {
+ try
+ {
+ File file = new File( new URI( url.toString() ).getPath() );
+
+ if ( file.isDirectory() )
+ {
+ acceptDirectory( file, visitor );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Cannot accept visitor on URL: " + url );
+ }
+ }
+ catch ( URISyntaxException exception )
+ {
+ IllegalArgumentException e = new IllegalArgumentException( "Cannot accept visitor on URL: " + url );
+ e.initCause( exception );
+ throw e;
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Cannot accept visitor on URL: " + url );
+ }
+ }
+
+ // private methods --------------------------------------------------------
+
+ private static void acceptJar( URL url, ClassFileVisitor visitor )
+ throws IOException
+ {
+ JarInputStream in = new JarInputStream( url.openStream() );
+
+ JarEntry entry = null;
+
+ while ( ( entry = in.getNextJarEntry() ) != null )
+ {
+ String name = entry.getName();
+
+ if ( name.endsWith( ".class" ) )
+ visitClass( name, in, visitor );
+ }
+
+ in.close();
+ }
+
+ private static void acceptDirectory( File directory, ClassFileVisitor visitor )
+ throws IOException
+ {
+ if ( !directory.isDirectory() )
+ throw new IllegalArgumentException( "File is not a directory" );
+
+ DirectoryScanner scanner = new DirectoryScanner();
+
+ scanner.setBasedir( directory );
+ scanner.setIncludes( CLASS_INCLUDES );
+
+ scanner.scan();
+
+ String[] paths = scanner.getIncludedFiles();
+
+ for ( int i = 0; i < paths.length; i++ )
+ {
+ String path = paths[i].replace( File.separatorChar, '/' );
+
+ File file = new File( directory, path );
+ FileInputStream in = new FileInputStream( file );
+
+ visitClass( path, in, visitor );
+
+ in.close();
+ }
+ }
+
+ private static void visitClass( String path, InputStream in, ClassFileVisitor visitor )
+ {
+ if ( !path.endsWith( ".class" ) )
+ throw new IllegalArgumentException( "Path is not a class" );
+
+ String className = path.substring( 0, path.length() - 6 );
+
+ className = className.replace( '/', '.' );
+
+ visitor.visitClass( className, in );
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitor.java
new file mode 100644
index 0000000..e2ee10b
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitor.java
@@ -0,0 +1,63 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class CollectorClassFileVisitor
+ implements ClassFileVisitor
+{
+ // fields -----------------------------------------------------------------
+
+ private final Set classes;
+
+ // constructors -----------------------------------------------------------
+
+ public CollectorClassFileVisitor()
+ {
+ classes = new HashSet();
+ }
+
+ // ClassFileVisitor methods -----------------------------------------------
+
+ /*
+ * @see org.apache.maven.shared.dependency.analyzer.ClassFileVisitor#visitClass(java.lang.String,
+ * java.io.InputStream)
+ */
+ public void visitClass( String className, InputStream in )
+ {
+ classes.add( className );
+ }
+
+ // public methods ---------------------------------------------------------
+
+ public Set getClasses()
+ {
+ return classes;
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzer.java
new file mode 100644
index 0000000..5f70ed8
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzer.java
@@ -0,0 +1,50 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.IOException;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.shared.dependency.analyzer.ClassAnalyzer"
+ */
+public class DefaultClassAnalyzer
+ implements ClassAnalyzer
+{
+ // ClassAnalyzer methods --------------------------------------------------
+
+ /*
+ * @see org.apache.maven.shared.dependency.analyzer.ClassAnalyzer#analyze(java.net.URL)
+ */
+ public Set analyze( URL url )
+ throws IOException
+ {
+ CollectorClassFileVisitor visitor = new CollectorClassFileVisitor();
+
+ ClassFileVisitorUtils.accept( url, visitor );
+
+ return visitor.getClasses();
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
new file mode 100644
index 0000000..12313e0
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
@@ -0,0 +1,163 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer"
+ */
+public class DefaultProjectDependencyAnalyzer
+ implements ProjectDependencyAnalyzer
+{
+ // fields -----------------------------------------------------------------
+
+ /**
+ * ClassAnalyzer
+ *
+ * @plexus.requirement
+ */
+ private ClassAnalyzer classAnalyzer;
+
+ /**
+ * DependencyAnalyzer
+ *
+ * @plexus.requirement
+ */
+ private DependencyAnalyzer dependencyAnalyzer;
+
+ // ProjectDependencyAnalyzer methods --------------------------------------
+
+ /*
+ * @see org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer#analyze(org.apache.maven.project.MavenProject)
+ */
+ public ProjectDependencyAnalysis analyze( MavenProject project )
+ throws ProjectDependencyAnalyzerException
+ {
+ try
+ {
+ Map artifactClassMap = buildArtifactClassMap( project );
+
+ Set dependencyClasses = buildDependencyClasses( project );
+
+ Set declaredArtifacts = project.getDependencyArtifacts();
+
+ Set usedArtifacts = new HashSet();
+
+ for ( Iterator dependencyIterator = dependencyClasses.iterator(); dependencyIterator.hasNext(); )
+ {
+ String className = (String) dependencyIterator.next();
+
+ Artifact artifact = findArtifactForClassName( artifactClassMap, className );
+
+ if ( artifact != null )
+ usedArtifacts.add( artifact );
+ }
+
+ Set usedDeclaredArtifacts = new HashSet( declaredArtifacts );
+ usedDeclaredArtifacts.retainAll( usedArtifacts );
+
+ Set usedUndeclaredArtifacts = new HashSet( usedArtifacts );
+ usedUndeclaredArtifacts.removeAll( declaredArtifacts );
+
+ Set unusedDeclaredArtifacts = new HashSet( declaredArtifacts );
+ unusedDeclaredArtifacts.removeAll( usedArtifacts );
+
+ return new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts,
+ unusedDeclaredArtifacts );
+ }
+ catch ( IOException exception )
+ {
+ throw new ProjectDependencyAnalyzerException( "Cannot analyze dependencies", exception );
+ }
+ }
+
+ // private methods --------------------------------------------------------
+
+ private Map buildArtifactClassMap( MavenProject project )
+ throws IOException
+ {
+ Map artifactClassMap = new HashMap();
+
+ Set dependencyArtifacts = project.getArtifacts();
+
+ for ( Iterator iterator = dependencyArtifacts.iterator(); iterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iterator.next();
+
+ File file = artifact.getFile();
+
+ if ( file != null )
+ {
+ URL url = file.toURL();
+
+ Set classes = classAnalyzer.analyze( url );
+
+ artifactClassMap.put( artifact, classes );
+ }
+ }
+
+ return artifactClassMap;
+ }
+
+ private Set buildDependencyClasses( MavenProject project )
+ throws IOException
+ {
+ String buildDirectory = project.getBuild().getDirectory();
+
+ URL buildDirectoryURL = new File( buildDirectory ).toURI().toURL();
+
+ return dependencyAnalyzer.analyze( buildDirectoryURL );
+ }
+
+ private Artifact findArtifactForClassName( Map artifactClassMap, String className )
+ {
+ for ( Iterator artifactIterator = artifactClassMap.keySet().iterator(); artifactIterator.hasNext(); )
+ {
+ Artifact artifact = (Artifact) artifactIterator.next();
+
+ Set artifactClassNames = (Set) artifactClassMap.get( artifact );
+
+ for ( Iterator classNameIterator = artifactClassNames.iterator(); classNameIterator.hasNext(); )
+ {
+ String artifactClassName = (String) classNameIterator.next();
+
+ if ( artifactClassName.equals( className ) )
+ return artifact;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/DependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/DependencyAnalyzer.java
new file mode 100644
index 0000000..1b6ee1d
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/DependencyAnalyzer.java
@@ -0,0 +1,42 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.IOException;
+import java.net.URL;
+import java.util.Set;
+
+/**
+ * DependencyAnalyzer
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public interface DependencyAnalyzer
+{
+ // fields -----------------------------------------------------------------
+
+ String ROLE = DependencyAnalyzer.class.getName();
+
+ // public methods ---------------------------------------------------------
+
+ Set analyze( URL url )
+ throws IOException;
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java
new file mode 100644
index 0000000..c8052a2
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java
@@ -0,0 +1,66 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.Set;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class ProjectDependencyAnalysis
+{
+ // fields -----------------------------------------------------------------
+
+ private final Set usedDeclaredArtifacts;
+
+ private final Set usedUndeclaredArtifacts;
+
+ private final Set unusedDeclaredArtifacts;
+
+ // constructors -----------------------------------------------------------
+
+ public ProjectDependencyAnalysis( Set usedDeclaredArtifacts, Set usedUndeclaredArtifacts,
+ Set unusedDeclaredArtifacts )
+ {
+ this.usedDeclaredArtifacts = usedDeclaredArtifacts;
+ this.usedUndeclaredArtifacts = usedUndeclaredArtifacts;
+ this.unusedDeclaredArtifacts = unusedDeclaredArtifacts;
+ }
+
+ // public methods ---------------------------------------------------------
+
+ public Set getUsedDeclaredArtifacts()
+ {
+ return usedDeclaredArtifacts;
+ }
+
+ public Set getUsedUndeclaredArtifacts()
+ {
+ return usedUndeclaredArtifacts;
+ }
+
+ public Set getUnusedDeclaredArtifacts()
+ {
+ return unusedDeclaredArtifacts;
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
new file mode 100644
index 0000000..a82d812
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
@@ -0,0 +1,40 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.project.MavenProject;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public interface ProjectDependencyAnalyzer
+{
+ // fields -----------------------------------------------------------------
+
+ String ROLE = ProjectDependencyAnalyzer.class.getName();
+
+ // public methods ---------------------------------------------------------
+
+ ProjectDependencyAnalysis analyze( MavenProject project )
+ throws ProjectDependencyAnalyzerException;
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerException.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerException.java
new file mode 100644
index 0000000..45e9de3
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerException.java
@@ -0,0 +1,49 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.
+ */
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class ProjectDependencyAnalyzerException
+ extends Exception
+{
+ // constants --------------------------------------------------------------
+
+ /**
+ * The serialisation unique ID.
+ */
+ private static final long serialVersionUID = -5954447543668196977L;
+
+ // constructors -----------------------------------------------------------
+
+ public ProjectDependencyAnalyzerException( String message )
+ {
+ super( message );
+ }
+
+ public ProjectDependencyAnalyzerException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ASMDependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ASMDependencyAnalyzer.java
new file mode 100644
index 0000000..c31501e
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ASMDependencyAnalyzer.java
@@ -0,0 +1,53 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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.IOException;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.maven.shared.dependency.analyzer.ClassFileVisitorUtils;
+import org.apache.maven.shared.dependency.analyzer.DependencyAnalyzer;
+
+/**
+ * ASMDependencyAnalyzer
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.shared.dependency.analyzer.DependencyAnalyzer"
+ */
+public class ASMDependencyAnalyzer
+ implements DependencyAnalyzer
+{
+ // DependencyAnalyzer methods ---------------------------------------------
+
+ /*
+ * @see org.apache.maven.shared.dependency.analyzer.DependencyAnalyzer#analyze(java.net.URL)
+ */
+ public Set analyze( URL url )
+ throws IOException
+ {
+ DependencyClassFileVisitor visitor = new DependencyClassFileVisitor();
+
+ ClassFileVisitorUtils.accept( url, visitor );
+
+ return visitor.getDependencies();
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java
new file mode 100644
index 0000000..98018f0
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyClassFileVisitor.java
@@ -0,0 +1,79 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.shared.dependency.analyzer.ClassFileVisitor;
+import org.objectweb.asm.ClassReader;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class DependencyClassFileVisitor
+ implements ClassFileVisitor
+{
+ // fields -----------------------------------------------------------------
+
+ private final Set dependencies;
+
+ // constructors -----------------------------------------------------------
+
+ public DependencyClassFileVisitor()
+ {
+ dependencies = new HashSet();
+ }
+
+ // ClassFileVisitor methods -----------------------------------------------
+
+ /*
+ * @see org.apache.maven.shared.dependency.analyzer.ClassFileVisitor#visitClass(java.lang.String,
+ * java.io.InputStream)
+ */
+ public void visitClass( String className, InputStream in )
+ {
+ try
+ {
+ ClassReader reader = new ClassReader( in );
+ DependencyVisitor visitor = new DependencyVisitor();
+
+ reader.accept( visitor, 0 );
+
+ dependencies.addAll( visitor.getClasses() );
+ }
+ catch ( IOException exception )
+ {
+ exception.printStackTrace();
+ }
+ }
+
+ // public methods ---------------------------------------------------------
+
+ public Set getDependencies()
+ {
+ return dependencies;
+ }
+}
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitor.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitor.java
new file mode 100644
index 0000000..18dae24
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitor.java
@@ -0,0 +1,585 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Attribute;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.signature.SignatureReader;
+import org.objectweb.asm.signature.SignatureVisitor;
+
+/**
+ * Inspired by <code>org.objectweb.asm.depend.DependencyVisitor</code> in the ASM dependencies example.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class DependencyVisitor
+ implements AnnotationVisitor, SignatureVisitor, ClassVisitor, FieldVisitor, MethodVisitor
+{
+ // fields -----------------------------------------------------------------
+
+ private final Set classes;
+
+ // constructors -----------------------------------------------------------
+
+ public DependencyVisitor()
+ {
+ classes = new HashSet();
+ }
+
+ // ClassVisitor methods ---------------------------------------------------
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String[])
+ */
+ public void visit( final int version, final int access, final String name, final String signature,
+ final String superName, final String[] interfaces )
+ {
+ if ( signature == null )
+ {
+ addName( superName );
+ addNames( interfaces );
+ }
+ else
+ {
+ addSignature( signature );
+ }
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, java.lang.String)
+ */
+ public void visitSource( final String source, final String debug )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void visitOuterClass( final String owner, final String name, final String desc )
+ {
+ // addName(owner);
+ // addMethodDesc(desc);
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean)
+ */
+ public AnnotationVisitor visitAnnotation( final String desc, final boolean visible )
+ {
+ addDesc( desc );
+
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute)
+ */
+ public void visitAttribute( final Attribute attr )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int)
+ */
+ public void visitInnerClass( final String name, final String outerName, final String innerName, final int access )
+ {
+ // addName( outerName);
+ // addName( innerName);
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.Object)
+ */
+ public FieldVisitor visitField( final int access, final String name, final String desc, final String signature,
+ final Object value )
+ {
+ if ( signature == null )
+ addDesc( desc );
+ else
+ addTypeSignature( signature );
+
+ if ( value instanceof Type )
+ addType( (Type) value );
+
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String[])
+ */
+ public MethodVisitor visitMethod( final int access, final String name, final String desc, final String signature,
+ final String[] exceptions )
+ {
+ if ( signature == null )
+ addMethodDesc( desc );
+ else
+ addSignature( signature );
+
+ addNames( exceptions );
+
+ return this;
+ }
+
+ // MethodVisitor methods --------------------------------------------------
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitAnnotationDefault()
+ */
+ public AnnotationVisitor visitAnnotationDefault()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitParameterAnnotation(int, java.lang.String, boolean)
+ */
+ public AnnotationVisitor visitParameterAnnotation( final int parameter, final String desc, final boolean visible )
+ {
+ addDesc( desc );
+
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitCode()
+ */
+ public void visitCode()
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitFrame(int, int, java.lang.Object[], int, java.lang.Object[])
+ */
+ public void visitFrame( final int type, final int nLocal, final Object[] local, final int nStack,
+ final Object[] stack )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitInsn(int)
+ */
+ public void visitInsn( final int opcode )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitIntInsn(int, int)
+ */
+ public void visitIntInsn( final int opcode, final int operand )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitVarInsn(int, int)
+ */
+ public void visitVarInsn( final int opcode, final int var )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitTypeInsn(int, java.lang.String)
+ */
+ public void visitTypeInsn( final int opcode, final String desc )
+ {
+ if ( desc.charAt( 0 ) == '[' )
+ addDesc( desc );
+ else
+ addName( desc );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitFieldInsn(int, java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void visitFieldInsn( final int opcode, final String owner, final String name, final String desc )
+ {
+ addName( owner );
+ addDesc( desc );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitMethodInsn(int, java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void visitMethodInsn( final int opcode, final String owner, final String name, final String desc )
+ {
+ addName( owner );
+ addMethodDesc( desc );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitJumpInsn(int, org.objectweb.asm.Label)
+ */
+ public void visitJumpInsn( final int opcode, final Label label )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitLabel(org.objectweb.asm.Label)
+ */
+ public void visitLabel( final Label label )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitLdcInsn(java.lang.Object)
+ */
+ public void visitLdcInsn( final Object cst )
+ {
+ if ( cst instanceof Type )
+ addType( (Type) cst );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitIincInsn(int, int)
+ */
+ public void visitIincInsn( final int var, final int increment )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitTableSwitchInsn(int, int, org.objectweb.asm.Label,
+ * org.objectweb.asm.Label[])
+ */
+ public void visitTableSwitchInsn( final int min, final int max, final Label dflt, final Label[] labels )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn(org.objectweb.asm.Label, int[],
+ * org.objectweb.asm.Label[])
+ */
+ public void visitLookupSwitchInsn( final Label dflt, final int[] keys, final Label[] labels )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn(java.lang.String, int)
+ */
+ public void visitMultiANewArrayInsn( final String desc, final int dims )
+ {
+ addDesc( desc );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitTryCatchBlock(org.objectweb.asm.Label, org.objectweb.asm.Label,
+ * org.objectweb.asm.Label, java.lang.String)
+ */
+ public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type )
+ {
+ addName( type );
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitLocalVariable(java.lang.String, java.lang.String, java.lang.String,
+ * org.objectweb.asm.Label, org.objectweb.asm.Label, int)
+ */
+ public void visitLocalVariable( final String name, final String desc, final String signature, final Label start,
+ final Label end, final int index )
+ {
+ if ( signature == null )
+ {
+ addDesc( desc );
+ }
+ else
+ {
+ addTypeSignature( signature );
+ }
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitLineNumber(int, org.objectweb.asm.Label)
+ */
+ public void visitLineNumber( final int line, final Label start )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.MethodVisitor#visitMaxs(int, int)
+ */
+ public void visitMaxs( final int maxStack, final int maxLocals )
+ {
+ // no-op
+ }
+
+ // AnnotationVisitor methods ----------------------------------------------
+
+ /*
+ * @see org.objectweb.asm.AnnotationVisitor#visit(java.lang.String, java.lang.Object)
+ */
+ public void visit( final String name, final Object value )
+ {
+ if ( value instanceof Type )
+ addType( (Type) value );
+ }
+
+ /*
+ * @see org.objectweb.asm.AnnotationVisitor#visitEnum(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void visitEnum( final String name, final String desc, final String value )
+ {
+ addDesc( desc );
+ }
+
+ /*
+ * @see org.objectweb.asm.AnnotationVisitor#visitAnnotation(java.lang.String, java.lang.String)
+ */
+ public AnnotationVisitor visitAnnotation( final String name, final String desc )
+ {
+ addDesc( desc );
+
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.AnnotationVisitor#visitArray(java.lang.String)
+ */
+ public AnnotationVisitor visitArray( final String name )
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
+ */
+ public void visitEnd()
+ {
+ // no-op
+ }
+
+ // SignatureVisitor methods -----------------------------------------------
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitFormalTypeParameter(java.lang.String)
+ */
+ public void visitFormalTypeParameter( final String name )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitClassBound()
+ */
+ public SignatureVisitor visitClassBound()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitInterfaceBound()
+ */
+ public SignatureVisitor visitInterfaceBound()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitSuperclass()
+ */
+ public SignatureVisitor visitSuperclass()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitInterface()
+ */
+ public SignatureVisitor visitInterface()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitParameterType()
+ */
+ public SignatureVisitor visitParameterType()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitReturnType()
+ */
+ public SignatureVisitor visitReturnType()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitExceptionType()
+ */
+ public SignatureVisitor visitExceptionType()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitBaseType(char)
+ */
+ public void visitBaseType( final char descriptor )
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitTypeVariable(java.lang.String)
+ */
+ public void visitTypeVariable( final String name )
+ {
+ // TODO: verify
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitArrayType()
+ */
+ public SignatureVisitor visitArrayType()
+ {
+ return this;
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitClassType(java.lang.String)
+ */
+ public void visitClassType( final String name )
+ {
+ addName( name );
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitInnerClassType(java.lang.String)
+ */
+ public void visitInnerClassType( final String name )
+ {
+ addName( name );
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitTypeArgument()
+ */
+ public void visitTypeArgument()
+ {
+ // no-op
+ }
+
+ /*
+ * @see org.objectweb.asm.signature.SignatureVisitor#visitTypeArgument(char)
+ */
+ public SignatureVisitor visitTypeArgument( final char wildcard )
+ {
+ return this;
+ }
+
+ // public methods ---------------------------------------------------------
+
+ public Set getClasses()
+ {
+ return classes;
+ }
+
+ // private methods --------------------------------------------------------
+
+ private void addName( String name )
+ {
+ if ( name == null )
+ return;
+
+ // decode arrays
+ if ( name.startsWith( "[L" ) && name.endsWith( ";" ) )
+ name = name.substring( 2, name.length() - 1 );
+
+ // decode internal representation
+ name = name.replace( '/', '.' );
+
+ classes.add( name );
+ }
+
+ private void addNames( final String[] names )
+ {
+ if ( names == null )
+ return;
+
+ for ( int i = 0; i < names.length; i++ )
+ addName( names[i] );
+ }
+
+ private void addDesc( final String desc )
+ {
+ addType( Type.getType( desc ) );
+ }
+
+ private void addMethodDesc( final String desc )
+ {
+ addType( Type.getReturnType( desc ) );
+
+ Type[] types = Type.getArgumentTypes( desc );
+
+ for ( int i = 0; i < types.length; i++ )
+ addType( types[i] );
+ }
+
+ private void addType( final Type t )
+ {
+ switch ( t.getSort() )
+ {
+ case Type.ARRAY:
+ addType( t.getElementType() );
+ break;
+
+ case Type.OBJECT:
+ addName( t.getClassName().replace( '.', '/' ) );
+ break;
+ }
+ }
+
+ private void addSignature( final String signature )
+ {
+ if ( signature != null )
+ new SignatureReader( signature ).accept( this );
+ }
+
+ private void addTypeSignature( final String signature )
+ {
+ if ( signature != null )
+ new SignatureReader( signature ).acceptType( this );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/AbstractFileTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/AbstractFileTest.java
new file mode 100644
index 0000000..9acfcb6
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/AbstractFileTest.java
@@ -0,0 +1,90 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.jmock.MockObjectTestCase;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public abstract class AbstractFileTest extends MockObjectTestCase
+{
+ // protected methods ------------------------------------------------------
+
+ protected File createJar() throws IOException
+ {
+ File file = File.createTempFile( "test", ".jar" );
+ file.deleteOnExit();
+
+ return file;
+ }
+
+ protected File createDir() throws IOException
+ {
+ File file = File.createTempFile( "test", null );
+ file.delete();
+
+ if ( !file.mkdir() )
+ throw new IOException( "Cannot create temporary directory: " + file );
+
+ return file;
+ }
+
+ protected File createFile( File parent, String child, String data ) throws IOException
+ {
+ File file = new File( parent, child );
+
+ OutputStream out = new FileOutputStream( file );
+ IOUtil.copy( data, out );
+ out.close();
+
+ return file;
+ }
+
+ protected File mkdirs( File parent, String child ) throws IOException
+ {
+ File dir = new File( parent, child );
+
+ FileUtils.forceMkdir( dir );
+
+ return dir;
+ }
+
+ protected void writeEntry( JarOutputStream out, String path, String data ) throws IOException
+ {
+ out.putNextEntry( new ZipEntry( path ) );
+
+ byte[] bytes = data.getBytes( "UTF-8" );
+
+ out.write( bytes, 0, bytes.length );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java
new file mode 100644
index 0000000..72fe2d7
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/ClassFileVisitorUtilsTest.java
@@ -0,0 +1,163 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.jar.JarOutputStream;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.jmock.Mock;
+
+/**
+ * Tests <code>ClassFileVisitorUtils</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see ClassFileVisitorUtils
+ */
+public class ClassFileVisitorUtilsTest
+ extends AbstractFileTest
+{
+ // tests ------------------------------------------------------------------
+
+ public void testAcceptJar()
+ throws IOException
+ {
+ File file = createJar();
+ JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
+ writeEntry( out, "a/b/c.class", "class a.b.c" );
+ writeEntry( out, "x/y/z.class", "class x.y.z" );
+ out.close();
+
+ Mock mock = mock( ClassFileVisitor.class );
+ expectVisitClass( mock, "a.b.c", "class a.b.c" );
+ expectVisitClass( mock, "x.y.z", "class x.y.z" );
+
+ ClassFileVisitorUtils.accept( file.toURI().toURL(), (ClassFileVisitor) mock.proxy() );
+
+ mock.verify();
+ }
+
+ public void testAcceptJarWithNonClassEntry()
+ throws IOException
+ {
+ File file = createJar();
+ JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
+ writeEntry( out, "a/b/c.jpg", "jpeg a.b.c" );
+ out.close();
+
+ Mock mock = mock( ClassFileVisitor.class );
+
+ ClassFileVisitorUtils.accept( file.toURI().toURL(), (ClassFileVisitor) mock.proxy() );
+
+ mock.verify();
+ }
+
+ public void testAcceptDir()
+ throws IOException
+ {
+ File dir = createDir();
+
+ File abDir = mkdirs( dir, "a/b" );
+ createFile( abDir, "c.class", "class a.b.c" );
+
+ File xyDir = mkdirs( dir, "x/y" );
+ createFile( xyDir, "z.class", "class x.y.z" );
+
+ Mock mock = mock( ClassFileVisitor.class );
+ expectVisitClass( mock, "a.b.c", "class a.b.c" );
+ expectVisitClass( mock, "x.y.z", "class x.y.z" );
+
+ ClassFileVisitorUtils.accept( dir.toURI().toURL(), (ClassFileVisitor) mock.proxy() );
+
+ FileUtils.deleteDirectory( dir );
+
+ mock.verify();
+ }
+
+ public void testAcceptDirWithNonClassFile()
+ throws IOException
+ {
+ File dir = createDir();
+
+ File abDir = mkdirs( dir, "a/b" );
+ createFile( abDir, "c.jpg", "jpeg a.b.c" );
+
+ Mock mock = mock( ClassFileVisitor.class );
+
+ ClassFileVisitorUtils.accept( dir.toURI().toURL(), (ClassFileVisitor) mock.proxy() );
+
+ FileUtils.deleteDirectory( dir );
+
+ mock.verify();
+ }
+
+ public void testAcceptWithFile()
+ throws IOException
+ {
+ File file = File.createTempFile( "test", ".class" );
+ file.deleteOnExit();
+
+ Mock mock = mock( ClassFileVisitor.class );
+
+ URL url = file.toURI().toURL();
+
+ try
+ {
+ ClassFileVisitorUtils.accept( url, (ClassFileVisitor) mock.proxy() );
+ }
+ catch ( IllegalArgumentException exception )
+ {
+ assertEquals( "Cannot accept visitor on URL: " + url, exception.getMessage() );
+ }
+ }
+
+ public void testAcceptWithUnsupportedScheme()
+ throws IOException
+ {
+ Mock mock = mock( ClassFileVisitor.class );
+
+ URL url = new URL( "http://localhost/" );
+
+ try
+ {
+ ClassFileVisitorUtils.accept( url, (ClassFileVisitor) mock.proxy() );
+ }
+ catch ( IllegalArgumentException exception )
+ {
+ assertEquals( "Cannot accept visitor on URL: " + url, exception.getMessage() );
+ }
+ }
+
+ // private methods --------------------------------------------------------
+
+ private void expectVisitClass( Mock mock, String className, String data )
+ {
+ mock.expects( atLeastOnce() ).method( "visitClass" ).with( eq( className ), in( data ) );
+ }
+
+ private InputStreamConstraint in( String expected )
+ {
+ return new InputStreamConstraint( expected );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitorTest.java
new file mode 100644
index 0000000..4c25aa8
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/CollectorClassFileVisitorTest.java
@@ -0,0 +1,67 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+import org.apache.maven.shared.dependency.analyzer.CollectorClassFileVisitor;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests <code>CollectorClassFileVisitor</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see CollectorClassFileVisitor
+ */
+public class CollectorClassFileVisitorTest
+ extends TestCase
+{
+ // fields -----------------------------------------------------------------
+
+ private CollectorClassFileVisitor visitor;
+
+ // TestCase thods ---------------------------------------------------------
+
+ /*
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp()
+ throws Exception
+ {
+ visitor = new CollectorClassFileVisitor();
+ }
+
+ // tests ------------------------------------------------------------------
+
+ public void testVisitClass()
+ {
+ visitor.visitClass( "a.b.c", null );
+ visitor.visitClass( "x.y.z", null );
+
+ Set expected = new HashSet();
+ expected.add( "a.b.c" );
+ expected.add( "x.y.z" );
+
+ assertEquals( expected, visitor.getClasses() );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java
new file mode 100644
index 0000000..89602ef
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultClassAnalyzerTest.java
@@ -0,0 +1,57 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.FileOutputStream;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarOutputStream;
+
+/**
+ * Tests <code>DefaultClassAnalyzer</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see DefaultClassAnalyzer
+ */
+public class DefaultClassAnalyzerTest extends AbstractFileTest
+{
+ // tests ------------------------------------------------------------------
+
+ public void testAnalyzeWithJar() throws IOException
+ {
+ File file = createJar();
+ JarOutputStream out = new JarOutputStream( new FileOutputStream( file ) );
+ writeEntry( out, "a/b/c.class", "class a.b.c" );
+ writeEntry( out, "x/y/z.class", "class x.y.z" );
+ out.close();
+
+ Set expectedClasses = new HashSet();
+ expectedClasses.add( "a.b.c" );
+ expectedClasses.add( "x.y.z" );
+
+ DefaultClassAnalyzer analyzer = new DefaultClassAnalyzer();
+ Set actualClasses = analyzer.analyze( file.toURI().toURL() );
+
+ assertEquals( expectedClasses, actualClasses );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/InputStreamConstraint.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/InputStreamConstraint.java
new file mode 100644
index 0000000..9481c88
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/InputStreamConstraint.java
@@ -0,0 +1,100 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.IOException;
+import java.io.InputStream;
+
+import org.codehaus.plexus.util.IOUtil;
+import org.jmock.core.Constraint;
+
+/**
+ *
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class InputStreamConstraint
+ implements Constraint
+{
+ // constants --------------------------------------------------------------
+
+ private static final String DEFAULT_CHARSET_NAME = "UTF-8";
+
+ // fields -----------------------------------------------------------------
+
+ private final String expected;
+
+ private final String charsetName;
+
+ // constructors -----------------------------------------------------------
+
+ public InputStreamConstraint( String expected )
+ {
+ this( expected, DEFAULT_CHARSET_NAME );
+ }
+
+ public InputStreamConstraint( String expected, String charsetName )
+ {
+ this.expected = expected;
+ this.charsetName = charsetName;
+ }
+
+ // Constraint methods -----------------------------------------------------
+
+ /*
+ * @see org.jmock.core.Constraint#eval(java.lang.Object)
+ */
+ public boolean eval( Object object )
+ {
+ if ( !( object instanceof InputStream ) )
+ {
+ return false;
+ }
+
+ InputStream in = (InputStream) object;
+
+ try
+ {
+ String actual = IOUtil.toString( in, charsetName );
+
+ return expected.equals( actual );
+ }
+ catch ( IOException exception )
+ {
+ return false;
+ }
+ }
+
+ // SelfDescribing methods -------------------------------------------------
+
+ /*
+ * @see org.jmock.core.SelfDescribing#describeTo(java.lang.StringBuffer)
+ */
+ public StringBuffer describeTo( StringBuffer buffer )
+ {
+ buffer.append( "in(" );
+ buffer.append( "\"" ).append( expected ).append( "\"" );
+ buffer.append( "," ).append( charsetName );
+ buffer.append( ")" );
+
+ return buffer;
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java
new file mode 100644
index 0000000..f6a9c0c
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java
@@ -0,0 +1,51 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests <code>ProjectDependencyAnalysis</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see ProjectDependencyAnalysis
+ */
+public class ProjectDependencyAnalysisTest extends TestCase
+{
+ // tests ------------------------------------------------------------------
+
+ public void testConstructor()
+ {
+ Set usedDeclaredArtifacts = new HashSet();
+ Set usedUndeclaredArtifacts = new HashSet();
+ Set unusedDeclaredArtifacts = new HashSet();
+
+ ProjectDependencyAnalysis analysis =
+ new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts, unusedDeclaredArtifacts );
+
+ assertEquals( usedDeclaredArtifacts, analysis.getUsedDeclaredArtifacts() );
+ assertEquals( usedUndeclaredArtifacts, analysis.getUsedUndeclaredArtifacts() );
+ assertEquals( unusedDeclaredArtifacts, analysis.getUnusedDeclaredArtifacts() );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerExceptionTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerExceptionTest.java
new file mode 100644
index 0000000..4a3fa7b
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzerExceptionTest.java
@@ -0,0 +1,50 @@
+package org.apache.maven.shared.dependency.analyzer;
+
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ * Tests <code>ProjectDependencyAnalyzerException</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see ProjectDependencyAnalyzerException
+ */
+public class ProjectDependencyAnalyzerExceptionTest extends TestCase
+{
+ // tests ------------------------------------------------------------------
+
+ public void testConstructor()
+ {
+ ProjectDependencyAnalyzerException exception = new ProjectDependencyAnalyzerException( "a" );
+
+ assertEquals( "a", exception.getMessage() );
+ }
+
+ public void testConstructorWithThrowable()
+ {
+ Throwable throwable = new Exception();
+ ProjectDependencyAnalyzerException exception = new ProjectDependencyAnalyzerException( "a", throwable );
+
+ assertEquals( "a", exception.getMessage() );
+ assertEquals( throwable, exception.getCause() );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitorTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitorTest.java
new file mode 100644
index 0000000..acc4059
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/DependencyVisitorTest.java
@@ -0,0 +1,722 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.objectweb.asm.Label;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+/**
+ * Tests <code>DependencyVisitor</code>.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ * @see DependencyVisitor
+ */
+public class DependencyVisitorTest extends TestCase
+{
+ // TODO: finish tests
+
+ // fields -----------------------------------------------------------------
+
+ private DependencyVisitor visitor;
+
+ // TestCase methods -------------------------------------------------------
+
+ /*
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ visitor = new DependencyVisitor();
+ }
+
+ // visit tests ------------------------------------------------------------
+
+ public void testVisitWithDefaultSuperclass()
+ {
+ // class a.b.c
+ visitor.visit( 50, 0, "a/b/c", null, "java/lang/Object", null );
+
+ assertClasses( "java.lang.Object" );
+ }
+
+ public void testVisitWithSuperclass()
+ {
+ // class a.b.c
+ visitor.visit( 50, 0, "a/b/c", null, "x/y/z", null );
+
+ assertClasses( "x.y.z" );
+ }
+
+ public void testVisitWithInterface()
+ {
+ // class a.b.c implements x.y.z
+ visitor.visit( 50, 0, "a/b/c", null, "java/lang/Object", new String[] { "x/y/z" } );
+
+ assertClasses( "java.lang.Object", "x.y.z" );
+ }
+
+ public void testVisitWithInterfaces()
+ {
+ // class a.b.c implements p.q.r, x.y.z
+ visitor.visit( 50, 0, "a/b/c", null, "java/lang/Object", new String[] { "p/q/r", "x/y/z" } );
+
+ assertClasses( "java.lang.Object", "p.q.r", "x.y.z" );
+ }
+
+ public void testVisitWithUnboundedClassTypeParameter()
+ {
+ // class a.b.c<T>
+ String signature = "<T:Ljava/lang/Object;>Ljava/lang/Object;";
+
+ visitor.visit( 50, 0, "a/b/c", signature, "java/lang/Object", null );
+
+ assertClasses( "java.lang.Object" );
+ }
+
+ public void testVisitWithBoundedClassTypeParameter()
+ {
+ // class a.b.c<T extends x.y.z>
+ String signature = "<T:Lx/y/z;>Ljava/lang/Object;";
+
+ visitor.visit( 50, 0, "a/b/c", signature, "java/lang/Object", null );
+
+ assertClasses( "java.lang.Object", "x.y.z" );
+ }
+
+ public void testVisitWithBoundedClassTypeParameters()
+ {
+ // class a.b.c<K extends p.q.r, V extends x.y.z>
+ String signature = "<K:Lp/q/r;V:Lx/y/z;>Ljava/lang/Object;";
+
+ visitor.visit( 50, 0, "a/b/c", signature, "java/lang/Object", null );
+
+ assertClasses( "java.lang.Object", "p.q.r", "x.y.z" );
+ }
+
+ public void testVisitWithGenericInterface()
+ {
+ // class a.b.c implements p.q.r<x.y.z>
+ String signature = "Ljava/lang/Object;Lp/q/r<Lx/y/z;>;";
+
+ visitor.visit( 50, 0, "a/b/c", signature, "java/lang/Object", new String[] { "p.q.r" } );
+
+ assertClasses( "java.lang.Object", "p.q.r", "x.y.z" );
+ }
+
+ public void testVisitWithInterfaceBound()
+ {
+ // class a.b.c<T> implements x.y.z<T>
+ String signature = "<T:Ljava/lang/Object;>Ljava/lang/Object;Lx/y/z<TT;>;";
+
+ visitor.visit( 50, 0, "a/b/c", signature, "java/lang/Object", new String[] { "x.y.z" } );
+
+ assertClasses( "java.lang.Object", "x.y.z" );
+ }
+
+ // visitSource tests ------------------------------------------------------
+
+ public void testVisitSource()
+ {
+ visitor.visitSource( null, null );
+
+ assertNoClasses();
+ }
+
+ // visitOuterClass tests --------------------------------------------------
+
+ public void testVisitOuterClass()
+ {
+ // class a.b.c
+ // {
+ // class ...
+ // {
+ // }
+ // }
+ visitor.visitOuterClass( "a/b/c", null, null );
+
+ assertNoClasses();
+ }
+
+ public void testVisitOuterClassInMethod()
+ {
+ // class a.b.c
+ // {
+ // x.y.z x(p.q.r p)
+ // {
+ // class ...
+ // {
+ // }
+ // }
+ // }
+ visitor.visitOuterClass( "a/b/c", "x", "(Lp/q/r;)Lx/y/z;" );
+
+ assertNoClasses();
+ }
+
+ // visitAnnotation tests --------------------------------------------------
+
+ public void testVisitAnnotation()
+ {
+ assertVisitor( visitor.visitAnnotation( "La/b/c;", false ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitAnnotationWithRuntimeVisibility()
+ {
+ assertVisitor( visitor.visitAnnotation( "La/b/c;", true ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // visitAttribute tests ---------------------------------------------------
+
+ public void testVisitAttribute()
+ {
+ visitor.visitAttribute( new MockAttribute( "a" ) );
+
+ assertNoClasses();
+ }
+
+ // visitInnerClass tests --------------------------------------------------
+
+ public void testVisitInnerClass()
+ {
+ // TODO: ensure innerName is correct
+
+ // class a.b.c { class x.y.z { } }
+ visitor.visitInnerClass( "x/y/z", "a/b/c", "z", 0 );
+
+ assertNoClasses();
+ }
+
+ public void testVisitInnerClassAnonymous()
+ {
+ // class a.b.c { new class x.y.z { } }
+ visitor.visitInnerClass( "x/y/z$1", "a/b/c", null, 0 );
+
+ assertNoClasses();
+ }
+
+ // visitField tests -------------------------------------------------------
+
+ public void testVisitField()
+ {
+ // a.b.c a
+ assertVisitor( visitor.visitField( 0, "a", "La/b/c;", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // TODO: determine actual use of default values
+ // public void testVisitFieldWithValue()
+ // {
+ // }
+
+ public void testVisitFieldArray()
+ {
+ // a.b.c[] a
+ assertVisitor( visitor.visitField( 0, "a", "[La/b/c;", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitFieldGeneric()
+ {
+ // a.b.c<x.y.z> a
+ assertVisitor( visitor.visitField( 0, "a", "La/b/c;", "La/b/c<Lx/y/z;>;", null ) );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ // visitMethod tests ------------------------------------------------------
+
+ public void testVisitMethod()
+ {
+ // void a()
+ assertVisitor( visitor.visitMethod( 0, "a", "()V", null, null ) );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMethodWithPrimitiveArgument()
+ {
+ // void a(int)
+ assertVisitor( visitor.visitMethod( 0, "a", "(I)V", null, null ) );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMethodWithPrimitiveArrayArgument()
+ {
+ // void a(int[])
+ assertVisitor( visitor.visitMethod( 0, "a", "([I)V", null, null ) );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMethodWithObjectArgument()
+ {
+ // void a(a.b.c)
+ assertVisitor( visitor.visitMethod( 0, "a", "(La/b/c;)V", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodWithObjectArguments()
+ {
+ // void a(a.b.c, x.y.z)
+ assertVisitor( visitor.visitMethod( 0, "a", "(La/b/c;Lx/y/z;)V", null, null ) );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitMethodWithObjectArrayArgument()
+ {
+ // void a(a.b.c[])
+ assertVisitor( visitor.visitMethod( 0, "a", "([La/b/c;)V", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodWithGenericArgument()
+ {
+ // void a(a.b.c<x.y.z>)
+ assertVisitor( visitor.visitMethod( 0, "a", "(La/b/c;)V", "(La/b/c<Lx/y/z;>;)V", null ) );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitMethodWithPrimitiveReturnType()
+ {
+ // int a()
+ assertVisitor( visitor.visitMethod( 0, "a", "()I", null, null ) );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMethodWithPrimitiveArrayReturnType()
+ {
+ // int[] a()
+ assertVisitor( visitor.visitMethod( 0, "a", "()[I", null, null ) );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMethodWithObjectReturnType()
+ {
+ // a.b.c a()
+ assertVisitor( visitor.visitMethod( 0, "a", "()La/b/c;", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodWithObjectArrayReturnType()
+ {
+ // a.b.c[] a()
+ assertVisitor( visitor.visitMethod( 0, "a", "()[La/b/c;", null, null ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodWithException()
+ {
+ // void a() throws a.b.c
+ assertVisitor( visitor.visitMethod( 0, "a", "()V", null, new String[] { "a/b/c" } ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodWithExceptions()
+ {
+ // void a() throws a.b.c, x.y.z
+ assertVisitor( visitor.visitMethod( 0, "a", "()V", null, new String[] { "a/b/c", "x/y/z" } ) );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ // visitAnnotationDefault tests -------------------------------------------
+
+ public void testVisitAnnotationDefault()
+ {
+ assertVisitor( visitor.visitAnnotationDefault() );
+ assertNoClasses();
+ }
+
+ // visitParameterAnnotation tests -------------------------------------------
+
+ public void testVisitParameterAnnotation()
+ {
+ // @a.b.c
+ assertVisitor( visitor.visitParameterAnnotation( 0, "La/b/c;", false ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // visitCode tests --------------------------------------------------------
+
+ public void testVisitCode()
+ {
+ visitor.visitCode();
+
+ assertNoClasses();
+ }
+
+ // visitFrame tests -------------------------------------------------------
+
+ public void testVisitFrame()
+ {
+ visitor.visitFrame( Opcodes.F_NEW, 0, new Object[0], 0, new Object[0] );
+
+ assertNoClasses();
+ }
+
+ // visitInsn tests --------------------------------------------------------
+
+ public void testVisitInsn()
+ {
+ visitor.visitInsn( Opcodes.NOP );
+
+ assertNoClasses();
+ }
+
+ // visitIntInsn tests -----------------------------------------------------
+
+ public void testVisitIntInsn()
+ {
+ visitor.visitIntInsn( Opcodes.BIPUSH, 0 );
+
+ assertNoClasses();
+ }
+
+ // visitVarInsn tests -----------------------------------------------------
+
+ public void testVisitVarInsn()
+ {
+ visitor.visitVarInsn( Opcodes.ILOAD, 0 );
+
+ assertNoClasses();
+ }
+
+ // visitTypeInsn tests ----------------------------------------------------
+
+ public void testVisitTypeInsn()
+ {
+ visitor.visitTypeInsn( Opcodes.NEW, "a/b/c" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // visitFieldInsn tests ---------------------------------------------------
+
+ public void testVisitFieldInsnWithPrimitive()
+ {
+ visitor.visitFieldInsn( Opcodes.GETFIELD, "a/b/c", "x", "I" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitFieldInsnWithObject()
+ {
+ visitor.visitFieldInsn( Opcodes.GETFIELD, "a/b/c", "x", "Lx/y/z;" );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ // visitMethodInsn tests --------------------------------------------------
+
+ public void testVisitMethodInsn()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "()V" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodInsnWithPrimitiveArgument()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "(I)V" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodInsnWithPrimitiveArrayArgument()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "([I)V" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodInsnWithObjectArgument()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "(Lx/y/z;)V" );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitMethodInsnWithObjectArguments()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "(Lp/q/r;Lx/y/z;)V" );
+
+ assertClasses( "a.b.c", "p.q.r", "x.y.z" );
+ }
+
+ public void testVisitMethodInsnWithObjectArrayArgument()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "([Lx/y/z;)V" );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitMethodInsnWithPrimitiveReturnType()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "()I" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodInsnWithPrimitiveArrayReturnType()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "()[I" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitMethodInsnWithObjectReturnType()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "()Lx/y/z;" );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitMethodInsnWithObjectArrayReturnType()
+ {
+ visitor.visitMethodInsn( Opcodes.INVOKEVIRTUAL, "a/b/c", "x", "()[Lx/y/z;" );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ // visitJumpInsn tests ----------------------------------------------------
+
+ public void testVisitJumpInsn()
+ {
+ visitor.visitJumpInsn( Opcodes.IFEQ, new Label() );
+
+ assertNoClasses();
+ }
+
+ // visitLabel tests -------------------------------------------------------
+
+ public void testVisitLabel()
+ {
+ visitor.visitLabel( new Label() );
+
+ assertNoClasses();
+ }
+
+ // visitLdcInsn tests -----------------------------------------------------
+
+ public void testVisitLdcInsnWithNonType()
+ {
+ visitor.visitLdcInsn( "a" );
+
+ assertNoClasses();
+ }
+
+ public void testVisitLdcInsnWithPrimitiveType()
+ {
+ visitor.visitLdcInsn( Type.INT_TYPE );
+
+ assertNoClasses();
+ }
+
+ public void testVisitLdcInsnWithObjectType()
+ {
+ visitor.visitLdcInsn( Type.getType( "La/b/c;" ) );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // visitIincInsn tests ----------------------------------------------------
+
+ public void testVisitIincInsn()
+ {
+ visitor.visitIincInsn( 0, 1 );
+
+ assertNoClasses();
+ }
+
+ // visitTableSwitchInsn tests ---------------------------------------------
+
+ public void testVisitTableSwitchInsn()
+ {
+ visitor.visitTableSwitchInsn( 0, 1, new Label(), new Label[] { new Label() } );
+
+ assertNoClasses();
+ }
+
+ // visitLookupSwitchInsn tests --------------------------------------------
+
+ public void testVisitLookupSwitchInsn()
+ {
+ visitor.visitLookupSwitchInsn( new Label(), new int[] { 0 }, new Label[] { new Label() } );
+
+ assertNoClasses();
+ }
+
+ // visitMultiANewArrayInsn tests ------------------------------------------
+
+ public void testVisitMultiANewArrayInsnWithPrimitive()
+ {
+ visitor.visitMultiANewArrayInsn( "I", 2 );
+
+ assertNoClasses();
+ }
+
+ public void testVisitMultiANewArrayInsnWithObject()
+ {
+ visitor.visitMultiANewArrayInsn( "La/b/c;", 2 );
+
+ assertClasses( "a.b.c" );
+ }
+
+ // visitTryCatchBlock tests -----------------------------------------------
+
+ public void testVisitTryCatchBlock()
+ {
+ visitor.visitTryCatchBlock( new Label(), new Label(), new Label(), "a/b/c" );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitTryCatchBlockForFinally()
+ {
+ visitor.visitTryCatchBlock( new Label(), new Label(), new Label(), null );
+
+ assertNoClasses();
+ }
+
+ // visitLocalVariable tests -----------------------------------------------
+
+ public void testVisitLocalVariableWithPrimitive()
+ {
+ visitor.visitLocalVariable( "a", "I", null, new Label(), new Label(), 0 );
+
+ assertNoClasses();
+ }
+
+ public void testVisitLocalVariableWithPrimitiveArray()
+ {
+ visitor.visitLocalVariable( "a", "[I", null, new Label(), new Label(), 0 );
+
+ assertNoClasses();
+ }
+
+ public void testVisitLocalVariableWithObject()
+ {
+ visitor.visitLocalVariable( "a", "La/b/c;", null, new Label(), new Label(), 0 );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitLocalVariableWithObjectArray()
+ {
+ visitor.visitLocalVariable( "a", "[La/b/c;", null, new Label(), new Label(), 0 );
+
+ assertClasses( "a.b.c" );
+ }
+
+ public void testVisitLocalVariableWithGenericObject()
+ {
+ visitor.visitLocalVariable( "a", "La/b/c;", "La/b/c<Lx/y/z;>;", new Label(), new Label(), 0 );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ public void testVisitLocalVariableWithGenericObjectArray()
+ {
+ visitor.visitLocalVariable( "a", "La/b/c;", "[La/b/c<Lx/y/z;>;", new Label(), new Label(), 0 );
+
+ assertClasses( "a.b.c", "x.y.z" );
+ }
+
+ // visitLineNumber tests --------------------------------------------------
+
+ public void testVisitLineNumber()
+ {
+ visitor.visitLineNumber( 0, new Label() );
+
+ assertNoClasses();
+ }
+
+ // visitMaxs tests --------------------------------------------------------
+
+ public void testVisitMaxs()
+ {
+ visitor.visitMaxs( 0, 0 );
+
+ assertNoClasses();
+ }
+
+ // private methods --------------------------------------------------------
+
+ private void assertVisitor( Object actualVisitor )
+ {
+ assertEquals( visitor, actualVisitor );
+ }
+
+ private void assertNoClasses()
+ {
+ assertClasses( Collections.EMPTY_SET );
+ }
+
+ private void assertClasses( String element )
+ {
+ assertClasses( Collections.singleton( element ) );
+ }
+
+ private void assertClasses( String expectedClass1, String expectedClass2 )
+ {
+ assertClasses( new String[] { expectedClass1, expectedClass2 } );
+ }
+
+ private void assertClasses( String expectedClass1, String expectedClass2, String expectedClass3 )
+ {
+ assertClasses( new String[] { expectedClass1, expectedClass2, expectedClass3 } );
+ }
+
+ private void assertClasses( String[] expectedClasses )
+ {
+ assertClasses( new HashSet( Arrays.asList( expectedClasses ) ) );
+ }
+
+ private void assertClasses( Set expectedClasses )
+ {
+ assertEquals( expectedClasses, visitor.getClasses() );
+ }
+}
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/MockAttribute.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/MockAttribute.java
new file mode 100644
index 0000000..7ee2dda
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/MockAttribute.java
@@ -0,0 +1,38 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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.objectweb.asm.Attribute;
+
+/**
+ * A simple ASM <code>Attribute</code> for use in tests.
+ *
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class MockAttribute extends Attribute
+{
+ // constructors -----------------------------------------------------------
+
+ public MockAttribute( String type )
+ {
+ super( type );
+ }
+}