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

[MDEPLOY-291] Update POM parent and Maven #22

Merged
merged 4 commits into from May 6, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 62 additions & 27 deletions pom.xml
Expand Up @@ -25,8 +25,8 @@ under the License.
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
<version>34</version>
<relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath>
<version>36</version>
<relativePath/>
</parent>

<artifactId>maven-deploy-plugin</artifactId>
Expand Down Expand Up @@ -63,7 +63,9 @@ under the License.
</distributionManagement>

<properties>
<mavenVersion>3.0</mavenVersion>
<mavenVersion>3.2.5</mavenVersion>
<slf4jVersion>1.7.5</slf4jVersion> <!-- Keep in sync with resolver used in maven above -->
<resolverVersion>1.0.0.v20140518</resolverVersion> <!-- Keep in sync with resolver used in maven above -->
<javaVersion>7</javaVersion>
<project.build.outputTimestamp>2021-12-27T14:11:19Z</project.build.outputTimestamp>
</properties>
Expand All @@ -73,50 +75,71 @@ under the License.
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
</dependency>
<!-- Upgrade of transitive dependency. -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${resolverVersion}</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this one is provided https://maven.apache.org/ref/3.8.5/maven-core/core-extensions.html
(notice: but not aether-util)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but to keep them paired, as here both are used by the plugin, I set both to compile (GenericVersion spans both)

</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${resolverVersion}</version>
</dependency>

<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.2.0</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.1</version>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
Expand All @@ -126,33 +149,45 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>1.7</version>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<scope>provided</scope>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.5</version>
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>

Expand Down
Expand Up @@ -26,7 +26,12 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;

/**
* Abstract class for Deploy mojo's.
Expand All @@ -52,7 +57,14 @@ public abstract class AbstractDeployMojo

@Parameter( defaultValue = "${session}", readonly = true, required = true )
private MavenSession session;


@Component
private RuntimeInformation runtimeInformation;

private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";

private static final String FIXED_MAVEN_VERSION = "3.9.0";

/* Setters and Getters */

void failIfOffline()
Expand All @@ -79,4 +91,29 @@ protected final MavenSession getSession()
{
return session;
}

protected void warnIfAffectedPackagingAndMaven( final String packaging )
{
if ( AFFECTED_MAVEN_PACKAGING.equals( packaging ) )
{
try
{
GenericVersionScheme versionScheme = new GenericVersionScheme();
Version fixedMavenVersion = versionScheme.parseVersion( FIXED_MAVEN_VERSION );
Version currentMavenVersion = versionScheme.parseVersion( runtimeInformation.getMavenVersion() );
if ( fixedMavenVersion.compareTo( currentMavenVersion ) > 0 )
{
getLog().warn( "" );
getLog().warn( "You are about to deploy a maven-plugin using Maven " + currentMavenVersion + "." );
getLog().warn( "This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055" );
getLog().warn( "is fixed in those versions of Maven only!" );
getLog().warn( "" );
}
}
catch ( InvalidVersionSpecificationException e )
{
// skip it: Generic does not throw, only API contains this exception
}
}
}
}
Expand Up @@ -481,6 +481,7 @@ public void execute()

try
{
warnIfAffectedPackagingAndMaven( packaging );
artifactDeployer.deploy( getSession().getProjectBuildingRequest(), deploymentRepository,
deployableArtifacts );
}
Expand Down
Expand Up @@ -207,6 +207,7 @@ private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest p
{
try
{
warnIfAffectedPackagingAndMaven( pir.getProject().getPackaging() );
projectDeployer.deploy( pbr, pir, repo );
}
catch ( NoFileAssignedException e )
Expand Down
Expand Up @@ -30,11 +30,12 @@
import org.apache.maven.model.Model;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.repository.LocalRepository;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;

/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
Expand Down Expand Up @@ -91,9 +92,10 @@ public void testBasicDeployFile()
assertNotNull( mojo );

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
Expand Down Expand Up @@ -192,9 +194,10 @@ public void testDeployIfClassifierIsSet()
assertNotNull( mojo );

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
Expand Down Expand Up @@ -240,9 +243,10 @@ public void testDeployIfArtifactIsNotJar()
assertNotNull( mojo );

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( buildingRequest.getRepositoryMerging() ).thenReturn( ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
Expand Down
Expand Up @@ -40,14 +40,15 @@
import org.apache.maven.plugins.deploy.stubs.DeployArtifactStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.repository.LocalRepository;
import org.junit.Ignore;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;

/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
Expand Down Expand Up @@ -132,8 +133,8 @@ public void testBasicDeploy()

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

File file = new File( getBasedir(),
Expand Down Expand Up @@ -303,8 +304,8 @@ public void testBasicDeployWithPackagingAsPom()

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

File pomFile = new File( getBasedir(),
Expand Down Expand Up @@ -415,8 +416,8 @@ public void testDeployWithAttachedArtifacts()

ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );

MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/maven/plugins/deploy/Utils.java
Expand Up @@ -26,7 +26,7 @@
import java.util.Map;

import org.apache.maven.plugin.MojoExecutionException;
import org.sonatype.aether.util.ChecksumUtils;
import org.eclipse.aether.util.ChecksumUtils;

/**
* A utility class to assist testing.
Expand Down
Expand Up @@ -131,4 +131,16 @@ public boolean isBlacklisted()
{
return blacklisted;
}

// @Override
public boolean isBlocked()
{
return false;
}

// @Override
public void setBlocked( boolean b )
{

}
}