Skip to content
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

[MDEP-726]: dependency:copy finds missing versions in TRANSITIVE depend… #109

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
130 changes: 124 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,48 @@ under the License.
</contributors>

<properties>
<enforcer.skip>true</enforcer.skip>
<mavenVersion>3.1.1</mavenVersion>
<doxiaVersion>1.9.1</doxiaVersion>
<doxiaSiteVersion>1.9.2</doxiaSiteVersion>
<jettyVersion>9.2.28.v20190418</jettyVersion>
<pluginTestingVersion>3.1.0</pluginTestingVersion>
<javaVersion>7</javaVersion>
<project.build.outputTimestamp>2020-03-07T11:40:47Z</project.build.outputTimestamp>
<java.version>1.8</java.version>
<junit.platform.version>1.3.1</junit.platform.version>
<junitPlatformArtifactName>org.junit.platform:junit-platform-engine</junitPlatformArtifactName>
<!-- rat.excludesFile>-d /surefire</rat.excludesFile -->
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<!-- version>2.20</version -->
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>maven-surefire-common</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
Expand All @@ -109,7 +140,33 @@ under the License.
</dependencyManagement>

<dependencies>
<!-- maven -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<!-- version>2.20</version -->
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>maven-surefire-common</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.0.1</version>
</dependency>
<!-- aether -->
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>1.1.0</version>
</dependency>
<!-- Remove once deprecated code has been replaced/removed -->
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -226,7 +283,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.1.0</version>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down Expand Up @@ -354,6 +411,7 @@ under the License.
These files contain results for integration tests which can't contain license header
otherwise the IT's will fail.
-->
<exclude>surefire/*</exclude>
<exclude>src/it/projects/tree/expected.txt</exclude>
<exclude>src/it/projects/tree-includes/expected.txt</exclude>
<exclude>src/it/projects/tree-multimodule/expected.txt</exclude>
Expand All @@ -371,6 +429,27 @@ under the License.
</plugins>
</pluginManagement>
<plugins>
<plugin> <!-- start maven-plugin-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<!-- version>2.9</version --> <!-- NoSuchMethod org.apache.maven.tools.plugin.PluginToolsRequest.getDependencies()Ljava/util/Set; -->
<!-- version>3.0</ version--> <!-- 'Goal: help already exists in the plugin descriptor for prefix: dependency -->
<!-- version>3.2</version --> <!-- Execution generate-helpmojo of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:helpmojo failed. -->
<!-- version>3.3</version --> <!-- Execution generate-helpmojo of goal org.apache.maven.plugins:maven-plugin-plugin:3.3:helpmojo failed. -->
<!-- version>3.4</version --> <!-- Execution generate-helpmojo of goal org.apache.maven.plugins:maven-plugin-plugin:3.4:helpmojo failed. -->
<!-- version>3.5</version --> <!-- Execution 'Goal: help already exists in the plugin descriptor for prefix: dependency -->
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin> <!-- end maven-plugin-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand All @@ -396,8 +475,43 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<!-- version>2.20</version -->
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>maven-surefire-common</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
</dependency>
</dependencies>
<configuration>
<!-- Need more heap space in order to run the unit tests !-->
<junitPlatformArtifactName default-value="org.junit.platform:junit-platform-engine">org.junit.platform:junit-platform-engine</junitPlatformArtifactName>
<argLine>-Xmx384m</argLine>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
Expand All @@ -412,6 +526,7 @@ under the License.
<id>run-its</id>
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand All @@ -423,20 +538,20 @@ under the License.
<projectsDirectory>src/it/projects</projectsDirectory>
<pomExcludes>
<pomExclude>purge-local-repository-bad-pom/pom.xml</pomExclude>
<!-- verbose was using Maven2 code, removed with MDEP-494, requires MSHARED-339 to be fixed first -->
<pomExclude>tree-verbose/pom.xml</pomExclude>
</pomExcludes>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
<pomInclude>purge-local-repository-without-pom</pomInclude>
</pomIncludes>
<!-- for mrm -->
<settingsFile>src/it/mrm/settings.xml</settingsFile>
<filterProperties>
<repository.proxy.url>${repository.proxy.url}</repository.proxy.url>
</filterProperties>
</configuration>
</plugin>
-->
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mrm-maven-plugin</artifactId>
Expand All @@ -455,22 +570,24 @@ under the License.
<mockRepo>
<source>src/it/mrm/repository</source>
</mockRepo>
<!--

<mockRepo>
<source>src/test/resources/m2repo</source>
</mockRepo>
-->

<proxyRepo />
</repositories>
</configuration>
</plugin>
-->
</plugins>
</build>
</profile>
<profile>
<id>reporting</id>
<reporting>
<plugins>
<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>l10n-maven-plugin</artifactId>
Expand All @@ -483,6 +600,7 @@ under the License.
</locales>
</configuration>
</plugin>
-->
</plugins>
</reporting>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@
*/

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;

import org.apache.maven.ProjectDependenciesResolver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.model.Dependency;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.dependency.AbstractDependencyMojo;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
Expand Down Expand Up @@ -270,33 +275,31 @@ protected Artifact getArtifact( ArtifactItem artifactItem )
private void fillMissingArtifactVersion( ArtifactItem artifact )
throws MojoExecutionException
{
MavenProject project = getProject();
List<Dependency> deps = project.getDependencies();
List<Dependency> depMngt = project.getDependencyManagement() == null ? Collections.<Dependency>emptyList()
: project.getDependencyManagement().getDependencies();

if ( !findDependencyVersion( artifact, deps, false )
&& ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, false ) )
&& !findDependencyVersion( artifact, deps, true )
&& ( project.getDependencyManagement() == null || !findDependencyVersion( artifact, depMngt, true ) ) )
try
{
if ( !this.findDependencyVersion( artifact, false ) && !this.findDependencyVersion( artifact, true ) )
{
throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + " in transitively resolved dependencies." );
}
}
catch ( final ArtifactResolutionException | ArtifactNotFoundException e )
{
throw new MojoExecutionException( "Unable to find artifact version of " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + " in either dependency list or in project's dependency management." );
throw new MojoExecutionException( "Failed to transitively resolve project dependencies.", e );
}
}

/**
* Tries to find missing version from a list of dependencies. If found, the artifact is updated with the correct
* version.
*
* @param artifact representing configured file.
* @param dependencies list of dependencies to search.
* @param looseMatch only look at artifactId and groupId
* @return the found dependency
*/
private boolean findDependencyVersion( ArtifactItem artifact, List<Dependency> dependencies, boolean looseMatch )
@Inject
private ProjectDependenciesResolver resolver;

private boolean findDependencyVersion( final ArtifactItem artifact, boolean looseMatch )
throws ArtifactResolutionException, ArtifactNotFoundException
{
for ( Dependency dependency : dependencies )
final Set<Artifact> resolvedArtifacts =
this.resolver.resolve( this.getProject(),
Arrays.asList( "compile", "provided", "runtime", "test", "system", "import" ),
this.session );
for ( final Artifact dependency : resolvedArtifacts )
{
if ( Objects.equals( dependency.getArtifactId(), artifact.getArtifactId() )
&& Objects.equals( dependency.getGroupId(), artifact.getGroupId() )
Expand Down