Skip to content

Require Maven 3.2.5+ #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,51 +59,50 @@
</distributionManagement>

<properties>
<mavenVersion>2.0.5</mavenVersion>
<surefire.version>2.22.2</surefire.version>
<mavenVersion>3.2.5</mavenVersion>
<javaVersion>8</javaVersion>
<project.build.outputTimestamp>2022-01-24T19:57:26Z</project.build.outputTimestamp>
</properties>

<dependencies>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.2</version>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.5.1</version>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>2.1.1</version>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${mavenVersion}</version>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.4.1</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${mavenVersion}</version>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.2</version>
</dependency>


<!-- testing support -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version>
</dependency>

<!-- testing support -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -134,12 +133,14 @@

<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.3.5</version>
<executions>
<execution>
<id>index-project</id>
<goals>
<goal>generate-metadata</goal>
<goal>main-index</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
* under the License.
*/

import javax.inject.Named;
import javax.inject.Singleton;

import java.io.IOException;
import java.net.URL;
import java.util.Set;
import java.util.zip.ZipException;

import org.codehaus.plexus.component.annotations.Component;

/**
* <p>DefaultClassAnalyzer class.</p>
*
* @author <a href="mailto:[email protected]">Mark Hobson</a>
*/
@Component( role = ClassAnalyzer.class )
@Named
@Singleton
public class DefaultClassAnalyzer
implements ClassAnalyzer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* under the License.
*/

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.io.File;
import java.io.IOException;
import java.net.URL;
Expand All @@ -35,28 +39,27 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;

/**
* <p>DefaultProjectDependencyAnalyzer class.</p>
*
* @author <a href="mailto:[email protected]">Mark Hobson</a>
*/
@Component( role = ProjectDependencyAnalyzer.class )
@Named
@Singleton
public class DefaultProjectDependencyAnalyzer
implements ProjectDependencyAnalyzer
{
/**
* ClassAnalyzer
*/
@Requirement
@Inject
private ClassAnalyzer classAnalyzer;

/**
* DependencyAnalyzer
*/
@Requirement
@Inject
private DependencyAnalyzer dependencyAnalyzer;

/** {@inheritDoc} */
Expand All @@ -75,17 +78,17 @@ public ProjectDependencyAnalysis analyze( MavenProject project )
Set<Artifact> declaredArtifacts = buildDeclaredArtifacts( project );

Map<Artifact, Set<String>> usedArtifacts = buildUsedArtifacts( artifactClassMap, dependencyClasses );
Set<Artifact> mainUsedArtifacts = buildUsedArtifacts( artifactClassMap, mainDependencyClasses ).keySet();
Set<Artifact> mainUsedArtifacts = buildUsedArtifacts( artifactClassMap, mainDependencyClasses ).keySet();

Set<Artifact> testArtifacts = buildUsedArtifacts( artifactClassMap, testOnlyDependencyClasses ).keySet();
Set<Artifact> testArtifacts = buildUsedArtifacts( artifactClassMap, testOnlyDependencyClasses ).keySet();
Set<Artifact> testOnlyArtifacts = removeAll( testArtifacts, mainUsedArtifacts );

Set<Artifact> usedDeclaredArtifacts = new LinkedHashSet<>( declaredArtifacts );
usedDeclaredArtifacts.retainAll( usedArtifacts.keySet() );

Map<Artifact, Set<String>> usedUndeclaredArtifactsWithClasses = new LinkedHashMap<>( usedArtifacts );
Set<Artifact> usedUndeclaredArtifacts = removeAll(
usedUndeclaredArtifactsWithClasses.keySet(), declaredArtifacts );
usedUndeclaredArtifactsWithClasses.keySet(), declaredArtifacts );
usedUndeclaredArtifactsWithClasses.keySet().retainAll( usedUndeclaredArtifacts );

Set<Artifact> unusedDeclaredArtifacts = new LinkedHashSet<>( declaredArtifacts );
Expand All @@ -94,7 +97,7 @@ public ProjectDependencyAnalysis analyze( MavenProject project )
Set<Artifact> testArtifactsWithNonTestScope = getTestArtifactsWithNonTestScope( testOnlyArtifacts );

return new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifactsWithClasses,
unusedDeclaredArtifacts, testArtifactsWithNonTestScope );
unusedDeclaredArtifacts, testArtifactsWithNonTestScope );
}
catch ( IOException exception )
{
Expand All @@ -105,8 +108,8 @@ public ProjectDependencyAnalysis analyze( MavenProject project )
/**
* This method defines a new way to remove the artifacts by using the conflict id. We don't care about the version
* here because there can be only 1 for a given artifact anyway.
*
* @param start initial set
*
* @param start initial set
* @param remove set to exclude
* @return set with remove excluded
*/
Expand Down Expand Up @@ -231,9 +234,9 @@ private Set<String> buildDependencyClasses( MavenProject project )

return dependencyClasses;
}

private Set<String> buildMainDependencyClasses( MavenProject project )
throws IOException
throws IOException
{

String outputDirectory = project.getBuild().getOutputDirectory();
Expand Down Expand Up @@ -263,7 +266,7 @@ private Set<Artifact> buildDeclaredArtifacts( MavenProject project )
}

private Map<Artifact, Set<String>> buildUsedArtifacts( Map<Artifact, Set<String>> artifactClassMap,
Set<String> dependencyClasses )
Set<String> dependencyClasses )
{
Map<Artifact, Set<String>> usedArtifacts = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
* under the License.
*/

import javax.inject.Named;
import javax.inject.Singleton;

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;
import org.codehaus.plexus.component.annotations.Component;

/**
* ASMDependencyAnalyzer
*
* @author <a href="mailto:[email protected]">Mark Hobson</a>
*/
@Component( role = DependencyAnalyzer.class )
@Named
@Singleton
public class ASMDependencyAnalyzer
implements DependencyAnalyzer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
* under the License.
*/

import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

import org.apache.maven.shared.dependency.analyzer.ClassFileVisitor;
import org.codehaus.plexus.util.IOUtil;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.signature.SignatureVisitor;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

/**
* Computes the set of classes referenced by visited class files, using
* <a href="DependencyVisitor.html">DependencyVisitor</a>.
Expand All @@ -56,7 +56,7 @@ public void visitClass( String className, InputStream in )
{
try
{
byte[] byteCode = IOUtils.toByteArray( in );
byte[] byteCode = IOUtil.toByteArray( in );
ClassReader reader = new ClassReader( byteCode );

final Set<String> constantPoolClassRefs = ConstantPoolParser.getConstantPoolClassReferences( byteCode );
Expand Down