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

[MSHADE-438] Update to Maven 3.2.5 #175

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</distributionManagement>

<properties>
<mavenVersion>3.1.1</mavenVersion>
<mavenVersion>3.2.5</mavenVersion>
<javaVersion>8</javaVersion>
<sisu.version>0.3.5</sisu.version>
<currentVersion>${project.version}</currentVersion>
Expand Down Expand Up @@ -160,18 +160,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Others -->
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -202,7 +190,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.vafer</groupId>
Expand All @@ -212,7 +200,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
<version>4.3</version>
</dependency>

<!-- Test -->
Expand Down Expand Up @@ -258,6 +246,18 @@
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ under the License.
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>default-source</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
Expand All @@ -92,6 +93,7 @@ under the License.
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
Expand Down
113 changes: 50 additions & 63 deletions src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
* under the License.
*/

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -52,19 +51,21 @@
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -104,42 +105,6 @@ public class ShadeMojo
@Parameter( defaultValue = "${project}", readonly = true, required = true )
private MavenProject project;

@Component
private MavenProjectHelper projectHelper;

@Component( hint = "default", role = org.apache.maven.plugins.shade.Shader.class )
private Shader shader;

/**
* The dependency graph builder to use.
*/
@Component
private DependencyGraphBuilder dependencyGraphBuilder;

/**
* ProjectBuilder, needed to create projects from the artifacts.
*/
@Component
private ProjectBuilder projectBuilder;

/**
* Remote repositories which will be searched for source attachments.
*/
@Parameter( readonly = true, required = true, defaultValue = "${project.remoteArtifactRepositories}" )
protected List<ArtifactRepository> remoteArtifactRepositories;

/**
* Local maven repository.
*/
@Parameter( readonly = true, required = true, defaultValue = "${localRepository}" )
protected ArtifactRepository localRepository;

/**
* Artifact resolver, needed to download source jars for inclusion in classpath.
*/
@Component
protected ArtifactResolver artifactResolver;

/**
* Artifacts to include/exclude from the final artifact. Artifacts are denoted by composite identifiers of the
* general form <code>groupId:artifactId:type:classifier</code>. Since version 1.3, the wildcard characters '*' and
Expand Down Expand Up @@ -389,22 +354,44 @@ public class ShadeMojo
@Parameter( defaultValue = "false" )
private boolean shadeTestJar;

/**
* All the present Shaders.
*/
@Inject
private Map<String, Shader> shaders;

/**
* When true, skips the execution of this MOJO.
* @since 3.3.0
*/
@Parameter( defaultValue = "false" )
private boolean skip;


@Inject
private MavenProjectHelper projectHelper;

@Inject
private Shader shader;

@Inject
private RepositorySystem repositorySystem;

/**
* The dependency graph builder to use.
*/
@Inject
private DependencyGraphBuilder dependencyGraphBuilder;

/**
* ProjectBuilder, needed to create projects from the artifacts.
*/
@Inject
private ProjectBuilder projectBuilder;

/**
* All the present Shaders.
*/
@Inject
private Map<String, Shader> shaders;

/**
* @throws MojoExecutionException in case of an error.
*/
@Override
public void execute()
throws MojoExecutionException
{
Expand Down Expand Up @@ -846,29 +833,29 @@ private void replaceFile( File oldFile, File newFile )
private void copyFiles( File source, File target )
throws IOException
{
try ( InputStream in = new FileInputStream( source );
OutputStream out = new FileOutputStream( target ) )
try ( InputStream in = Files.newInputStream( source.toPath() );
OutputStream out = Files.newOutputStream( target.toPath() ) )
{
IOUtil.copy( in, out );
}
}

private File resolveArtifactForClassifier( Artifact artifact, String classifier )
{
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId( artifact.getGroupId() );
coordinate.setArtifactId( artifact.getArtifactId() );
coordinate.setVersion( artifact.getVersion() );
coordinate.setExtension( "jar" );
coordinate.setClassifier( classifier );
ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry().get( artifact.getType() );
cstamas marked this conversation as resolved.
Show resolved Hide resolved
org.eclipse.aether.artifact.DefaultArtifact coordinate = new DefaultArtifact( artifact.getGroupId(),
artifact.getArtifactId(), classifier, artifactType.getExtension(), artifact.getVersion(),
cstamas marked this conversation as resolved.
Show resolved Hide resolved
null, artifactType );
ArtifactRequest request = new ArtifactRequest(
coordinate, RepositoryUtils.toRepos( project.getRemoteArtifactRepositories() ), "shade" );

Artifact resolvedArtifact;
try
{
resolvedArtifact =
artifactResolver.resolveArtifact( session.getProjectBuildingRequest(), coordinate ).getArtifact();
ArtifactResult result = repositorySystem.resolveArtifact( session.getRepositorySession(), request );
resolvedArtifact = RepositoryUtils.toArtifact( result.getArtifact() );
}
catch ( ArtifactResolverException e )
catch ( ArtifactResolutionException e )
{
getLog().warn( "Could not get " + classifier + " for " + artifact );
return null;
Expand Down Expand Up @@ -1216,8 +1203,8 @@ private void rewriteDependencyReducedPomIfWeHaveReduction( List<Dependency> depe

ProjectBuildingRequest projectBuildingRequest =
new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
projectBuildingRequest.setLocalRepository( localRepository );
projectBuildingRequest.setRemoteRepositories( remoteArtifactRepositories );
projectBuildingRequest.setLocalRepository( session.getLocalRepository() );
projectBuildingRequest.setRemoteRepositories( project.getRemoteArtifactRepositories() );

ProjectBuildingResult result = projectBuilder.build( f, projectBuildingRequest );

Expand Down