Skip to content

Commit f103a4b

Browse files
committed
Switch to maven 4 and the new api
1 parent bee2a14 commit f103a4b

File tree

10 files changed

+846
-1452
lines changed

10 files changed

+846
-1452
lines changed

pom.xml

+47-33
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ under the License.
2626
<groupId>org.apache.maven.plugins</groupId>
2727
<artifactId>maven-plugins</artifactId>
2828
<version>36</version>
29-
<relativePath />
3029
</parent>
3130

3231
<artifactId>maven-deploy-plugin</artifactId>
33-
<version>3.0.1-SNAPSHOT</version>
32+
<version>4.0.0-SNAPSHOT</version>
3433
<packaging>maven-plugin</packaging>
3534

3635
<name>Apache Maven Deploy Plugin</name>
@@ -63,23 +62,23 @@ under the License.
6362
</distributionManagement>
6463

6564
<properties>
66-
<javaVersion>7</javaVersion>
67-
<mavenVersion>3.2.5</mavenVersion>
65+
<javaVersion>8</javaVersion>
66+
<mavenVersion>4.0.0-alpha-1-SNAPSHOT</mavenVersion>
6867
<slf4jVersion>1.7.5</slf4jVersion> <!-- Keep in sync with resolver used in maven above -->
69-
<resolverVersion>1.0.0.v20140518</resolverVersion> <!-- Keep in sync with resolver used in maven above -->
68+
<resolverVersion>1.8.1</resolverVersion> <!-- Keep in sync with resolver used in maven above -->
7069
<project.build.outputTimestamp>2022-07-16T16:14:30Z</project.build.outputTimestamp>
7170
</properties>
7271

7372
<dependencies>
7473
<dependency>
7574
<groupId>org.apache.maven</groupId>
76-
<artifactId>maven-plugin-api</artifactId>
75+
<artifactId>maven-api-core</artifactId>
7776
<version>${mavenVersion}</version>
7877
<scope>provided</scope>
7978
</dependency>
8079
<dependency>
8180
<groupId>org.apache.maven</groupId>
82-
<artifactId>maven-core</artifactId>
81+
<artifactId>maven-plugin-api</artifactId>
8382
<version>${mavenVersion}</version>
8483
<scope>provided</scope>
8584
</dependency>
@@ -107,60 +106,60 @@ under the License.
107106
<artifactId>plexus-utils</artifactId>
108107
<version>3.3.1</version>
109108
</dependency>
110-
<dependency>
111-
<groupId>org.eclipse.aether</groupId>
112-
<artifactId>aether-api</artifactId>
113-
<version>${resolverVersion}</version>
114-
<scope>provided</scope>
115-
</dependency>
116-
<dependency>
117-
<groupId>org.eclipse.aether</groupId>
118-
<artifactId>aether-util</artifactId>
119-
<version>${resolverVersion}</version>
120-
<scope>compile</scope> <!-- To work in Maven versions older than 3.9.0 -->
121-
</dependency>
109+
<!-- <dependency>-->
110+
<!-- <groupId>org.eclipse.aether</groupId>-->
111+
<!-- <artifactId>aether-api</artifactId>-->
112+
<!-- <version>${resolverVersion}</version>-->
113+
<!-- <scope>provided</scope>-->
114+
<!-- </dependency>-->
115+
<!-- <dependency>-->
116+
<!-- <groupId>org.eclipse.aether</groupId>-->
117+
<!-- <artifactId>aether-util</artifactId>-->
118+
<!-- <version>${resolverVersion}</version>-->
119+
<!-- <scope>compile</scope> &lt;!&ndash; To work in Maven versions older than 3.9.0 &ndash;&gt;-->
120+
<!-- </dependency>-->
122121

123122
<!-- dependencies to annotations -->
124-
<dependency>
125-
<groupId>org.apache.maven.plugin-tools</groupId>
126-
<artifactId>maven-plugin-annotations</artifactId>
127-
<scope>provided</scope>
128-
</dependency>
123+
<!-- <dependency>-->
124+
<!-- <groupId>org.apache.maven.plugin-tools</groupId>-->
125+
<!-- <artifactId>maven-plugin-annotations</artifactId>-->
126+
<!-- <scope>provided</scope>-->
127+
<!-- </dependency>-->
129128

130129
<!-- Test -->
131130
<dependency>
132131
<groupId>org.apache.maven.plugin-testing</groupId>
133132
<artifactId>maven-plugin-testing-harness</artifactId>
134-
<version>3.3.0</version>
133+
<version>4.0.0-SNAPSHOT</version>
135134
<scope>test</scope>
136135
</dependency>
137136
<dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
138137
<groupId>org.apache.maven</groupId>
139-
<artifactId>maven-compat</artifactId>
138+
<artifactId>maven-core</artifactId>
140139
<version>${mavenVersion}</version>
141140
<scope>test</scope>
142141
</dependency>
143142
<dependency>
144143
<groupId>org.apache.maven</groupId>
145-
<artifactId>maven-aether-provider</artifactId>
144+
<artifactId>maven-resolver-provider</artifactId>
146145
<version>${mavenVersion}</version>
147146
<scope>test</scope>
148147
</dependency>
149148
<dependency>
150-
<groupId>org.eclipse.aether</groupId>
151-
<artifactId>aether-connector-basic</artifactId>
149+
<groupId>org.apache.maven.resolver</groupId>
150+
<artifactId>maven-resolver-connector-basic</artifactId>
152151
<version>${resolverVersion}</version>
153152
<scope>test</scope>
154153
</dependency>
155154
<dependency>
156-
<groupId>org.eclipse.aether</groupId>
157-
<artifactId>aether-transport-file</artifactId>
155+
<groupId>org.apache.maven.resolver</groupId>
156+
<artifactId>maven-resolver-transport-file</artifactId>
158157
<version>${resolverVersion}</version>
159158
<scope>test</scope>
160159
</dependency>
161160
<dependency>
162-
<groupId>org.eclipse.aether</groupId>
163-
<artifactId>aether-transport-http</artifactId>
161+
<groupId>org.apache.maven.resolver</groupId>
162+
<artifactId>maven-resolver-transport-http</artifactId>
164163
<version>${resolverVersion}</version>
165164
<scope>test</scope>
166165
</dependency>
@@ -170,6 +169,12 @@ under the License.
170169
<version>2.28.2</version>
171170
<scope>test</scope>
172171
</dependency>
172+
<dependency>
173+
<groupId>org.mockito</groupId>
174+
<artifactId>mockito-junit-jupiter</artifactId>
175+
<version>2.28.2</version>
176+
<scope>test</scope>
177+
</dependency>
173178
<dependency>
174179
<groupId>junit</groupId>
175180
<artifactId>junit</artifactId>
@@ -193,6 +198,15 @@ under the License.
193198
</contributors>
194199

195200
<build>
201+
<pluginManagement>
202+
<plugins>
203+
<plugin>
204+
<groupId>org.apache.maven.plugins</groupId>
205+
<artifactId>maven-plugin-plugin</artifactId>
206+
<version>4.0.0-SNAPSHOT</version>
207+
</plugin>
208+
</plugins>
209+
</pluginManagement>
196210
<plugins>
197211
<!-- https://issues.apache.org/jira/browse/MPOM-226 -->
198212
<plugin>

src/it/deploy-at-end-fail/module1/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<plugin>
2828
<groupId>org.apache.maven.plugins</groupId>
2929
<artifactId>maven-enforcer-plugin</artifactId>
30-
<version>1.2</version>
30+
<version>3.0.0</version>
3131
<executions>
3232
<execution>
3333
<id>enforce</id>

src/it/deploy-at-end-pass/module1/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<plugin>
2828
<groupId>org.apache.maven.plugins</groupId>
2929
<artifactId>maven-enforcer-plugin</artifactId>
30-
<version>1.2</version>
30+
<version>3.0.0</version>
3131
<executions>
3232
<execution>
3333
<id>enforce</id>

src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java

+45-103
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,29 @@
1919
* under the License.
2020
*/
2121

22-
import org.apache.maven.execution.MavenSession;
23-
import org.apache.maven.plugin.AbstractMojo;
24-
import org.apache.maven.plugin.MojoExecutionException;
25-
import org.apache.maven.plugin.MojoFailureException;
26-
import org.apache.maven.plugins.annotations.Component;
27-
import org.apache.maven.plugins.annotations.Parameter;
28-
import org.apache.maven.rtinfo.RuntimeInformation;
29-
import org.eclipse.aether.RepositorySystem;
30-
import org.eclipse.aether.RepositorySystemSession;
31-
import org.eclipse.aether.deployment.DeployRequest;
32-
import org.eclipse.aether.deployment.DeploymentException;
33-
import org.eclipse.aether.repository.RemoteRepository;
34-
import org.eclipse.aether.util.version.GenericVersionScheme;
35-
import org.eclipse.aether.version.InvalidVersionSpecificationException;
36-
import org.eclipse.aether.version.Version;
22+
import org.apache.maven.api.RemoteRepository;
23+
import org.apache.maven.api.Version;
24+
import org.apache.maven.api.plugin.Mojo;
25+
import org.apache.maven.api.Session;
26+
import org.apache.maven.api.services.RepositoryFactory;
27+
import org.apache.maven.api.plugin.MojoException;
28+
import org.apache.maven.api.plugin.annotations.Parameter;
29+
import org.apache.maven.api.services.VersionParser;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3732

3833
/**
3934
* Abstract class for Deploy mojo's.
4035
*/
4136
public abstract class AbstractDeployMojo
42-
extends AbstractMojo
37+
implements Mojo
4338
{
39+
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
40+
41+
private static final String FIXED_MAVEN_VERSION = "3.9.0";
42+
43+
protected final Logger logger = LoggerFactory.getLogger( getClass() );
44+
4445
/**
4546
* Flag whether Maven is currently in online/offline mode.
4647
*/
@@ -56,123 +57,64 @@ public abstract class AbstractDeployMojo
5657
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
5758
private int retryFailedDeploymentCount;
5859

59-
@Component
60-
private RuntimeInformation runtimeInformation;
61-
6260
@Parameter( defaultValue = "${session}", readonly = true, required = true )
63-
protected MavenSession session;
64-
65-
@Component
66-
protected RepositorySystem repositorySystem;
67-
68-
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
69-
70-
private static final String FIXED_MAVEN_VERSION = "3.9.0";
61+
protected Session session;
7162

7263
/* Setters and Getters */
7364

7465
void failIfOffline()
75-
throws MojoFailureException
66+
throws MojoException
7667
{
7768
if ( offline )
7869
{
79-
throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
70+
throw new MojoException( "Cannot deploy artifacts when Maven is in offline mode" );
8071
}
8172
}
8273

74+
public int getRetryFailedDeploymentCount()
75+
{
76+
return retryFailedDeploymentCount;
77+
}
78+
8379
/**
8480
* If this plugin used in pre-3.9.0 Maven, the packaging {@code maven-plugin} will not deploy G level metadata.
8581
*/
8682
protected void warnIfAffectedPackagingAndMaven( final String packaging )
8783
{
8884
if ( AFFECTED_MAVEN_PACKAGING.equals( packaging ) )
8985
{
90-
try
91-
{
92-
GenericVersionScheme versionScheme = new GenericVersionScheme();
93-
Version fixedMavenVersion = versionScheme.parseVersion( FIXED_MAVEN_VERSION );
94-
Version currentMavenVersion = versionScheme.parseVersion( runtimeInformation.getMavenVersion() );
95-
if ( fixedMavenVersion.compareTo( currentMavenVersion ) > 0 )
96-
{
97-
getLog().warn( "" );
98-
getLog().warn( "You are about to deploy a maven-plugin using Maven " + currentMavenVersion + "." );
99-
getLog().warn( "This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055" );
100-
getLog().warn( "is fixed in those versions of Maven only!" );
101-
getLog().warn( "" );
102-
}
103-
}
104-
catch ( InvalidVersionSpecificationException e )
86+
VersionParser parser = session.getService( VersionParser.class );
87+
Version fixedMavenVersion = parser.parseVersion( FIXED_MAVEN_VERSION );
88+
Version currentMavenVersion = parser.parseVersion( session.getMavenVersion() );
89+
if ( fixedMavenVersion.compareTo( currentMavenVersion ) > 0 )
10590
{
106-
// skip it: Generic does not throw, only API contains this exception
91+
getLog().warn( "" );
92+
getLog().warn( "You are about to deploy a maven-plugin using Maven " + currentMavenVersion + "." );
93+
getLog().warn( "This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055" );
94+
getLog().warn( "is fixed in those versions of Maven only!" );
95+
getLog().warn( "" );
10796
}
10897
}
10998
}
11099

111100
/**
112101
* Creates resolver {@link RemoteRepository} equipped with needed whistles and bells.
113102
*/
114-
protected RemoteRepository getRemoteRepository( final String repositoryId, final String url )
103+
protected RemoteRepository createDeploymentArtifactRepository( String id, String url )
115104
{
116-
RemoteRepository result = new RemoteRepository.Builder( repositoryId, "default", url ).build();
117-
118-
if ( result.getAuthentication() == null || result.getProxy() == null )
119-
{
120-
RemoteRepository.Builder builder = new RemoteRepository.Builder( result );
121-
122-
if ( result.getAuthentication() == null )
123-
{
124-
builder.setAuthentication( session.getRepositorySession().getAuthenticationSelector()
125-
.getAuthentication( result ) );
126-
}
127-
128-
if ( result.getProxy() == null )
129-
{
130-
builder.setProxy( session.getRepositorySession().getProxySelector().getProxy( result ) );
131-
}
132-
133-
result = builder.build();
134-
}
105+
return getSession().getService( RepositoryFactory.class )
106+
.createRemote( id, url );
107+
}
135108

136-
return result;
109+
protected Session getSession()
110+
{
111+
return session;
137112
}
138113

139-
/**
140-
* Handles high level retries (this was buried into MAT).
141-
*/
142-
protected void deploy( RepositorySystemSession session, DeployRequest deployRequest ) throws MojoExecutionException
114+
protected Logger getLog()
143115
{
144-
int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) );
145-
DeploymentException exception = null;
146-
for ( int count = 0; count < retryFailedDeploymentCounter; count++ )
147-
{
148-
try
149-
{
150-
if ( count > 0 )
151-
{
152-
getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of "
153-
+ retryFailedDeploymentCounter );
154-
}
155-
156-
repositorySystem.deploy( session, deployRequest );
157-
exception = null;
158-
break;
159-
}
160-
catch ( DeploymentException e )
161-
{
162-
if ( count + 1 < retryFailedDeploymentCounter )
163-
{
164-
getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage() );
165-
getLog().debug( e );
166-
}
167-
if ( exception == null )
168-
{
169-
exception = e;
170-
}
171-
}
172-
}
173-
if ( exception != null )
174-
{
175-
throw new MojoExecutionException( exception.getMessage(), exception );
176-
}
116+
return logger;
177117
}
118+
119+
178120
}

0 commit comments

Comments
 (0)