Skip to content

Commit

Permalink
[MSHADE-438] Update to Maven 3.2.5 (#175)
Browse files Browse the repository at this point in the history
Up the baseline as for the rest of ASF plugins.

Changes:
* drop MAT
* drop uses of archaic constructs

Also update IT for MSHADE-340 as it was not passing with maven-jar-plugin 3+ version (maven 3.8.x used maven-jar-plugin 2.4), as the IT was replacing the main JAR intentionally, or unintentionally.

---

https://issues.apache.org/jira/browse/MSHADE-438
  • Loading branch information
cstamas committed Feb 23, 2023
1 parent 45b8bbf commit c9a4425
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 151 deletions.
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
115 changes: 52 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,15 @@
* 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.artifact.DefaultArtifact;
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 +52,19 @@
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.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 +104,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 +353,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 +832,32 @@ 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 );
org.eclipse.aether.artifact.Artifact coordinate = RepositoryUtils.toArtifact(
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersionRange(),
artifact.getScope(), artifact.getType(), classifier, artifact.getArtifactHandler(),
artifact.isOptional()
)
);

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 +1205,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

0 comments on commit c9a4425

Please sign in to comment.