Skip to content

Commit 8436101

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

30 files changed

+863
-2044
lines changed

Diff for: pom.xml

+44-73
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,39 +62,20 @@ 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>
80-
<dependency>
81-
<groupId>org.apache.maven</groupId>
82-
<artifactId>maven-core</artifactId>
83-
<version>${mavenVersion}</version>
84-
<scope>provided</scope>
85-
</dependency>
86-
<dependency>
87-
<groupId>org.apache.maven</groupId>
88-
<artifactId>maven-model</artifactId>
89-
<version>${mavenVersion}</version>
90-
<scope>provided</scope>
91-
</dependency>
92-
<dependency>
93-
<groupId>org.apache.maven</groupId>
94-
<artifactId>maven-artifact</artifactId>
95-
<version>${mavenVersion}</version>
96-
<scope>provided</scope>
97-
</dependency>
98-
9979
<dependency>
10080
<groupId>org.slf4j</groupId>
10181
<artifactId>slf4j-api</artifactId>
@@ -105,77 +85,58 @@ under the License.
10585
<dependency>
10686
<groupId>org.codehaus.plexus</groupId>
10787
<artifactId>plexus-utils</artifactId>
108-
<version>3.3.1</version>
109-
</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>
122-
123-
<!-- dependencies to annotations -->
124-
<dependency>
125-
<groupId>org.apache.maven.plugin-tools</groupId>
126-
<artifactId>maven-plugin-annotations</artifactId>
127-
<scope>provided</scope>
88+
<version>${mavenVersion}</version>
12889
</dependency>
12990

13091
<!-- Test -->
13192
<dependency>
13293
<groupId>org.apache.maven.plugin-testing</groupId>
13394
<artifactId>maven-plugin-testing-harness</artifactId>
134-
<version>3.3.0</version>
95+
<version>4.0.0-SNAPSHOT</version>
13596
<scope>test</scope>
13697
</dependency>
13798
<dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
13899
<groupId>org.apache.maven</groupId>
139-
<artifactId>maven-compat</artifactId>
100+
<artifactId>maven-core</artifactId>
140101
<version>${mavenVersion}</version>
141102
<scope>test</scope>
142103
</dependency>
143104
<dependency>
144105
<groupId>org.apache.maven</groupId>
145-
<artifactId>maven-aether-provider</artifactId>
106+
<artifactId>maven-resolver-provider</artifactId>
146107
<version>${mavenVersion}</version>
147108
<scope>test</scope>
148109
</dependency>
149-
<dependency>
150-
<groupId>org.eclipse.aether</groupId>
151-
<artifactId>aether-connector-basic</artifactId>
152-
<version>${resolverVersion}</version>
153-
<scope>test</scope>
154-
</dependency>
155-
<dependency>
156-
<groupId>org.eclipse.aether</groupId>
157-
<artifactId>aether-transport-file</artifactId>
158-
<version>${resolverVersion}</version>
159-
<scope>test</scope>
160-
</dependency>
161-
<dependency>
162-
<groupId>org.eclipse.aether</groupId>
163-
<artifactId>aether-transport-http</artifactId>
164-
<version>${resolverVersion}</version>
165-
<scope>test</scope>
166-
</dependency>
110+
<!-- <dependency>-->
111+
<!-- <groupId>org.apache.maven.resolver</groupId>-->
112+
<!-- <artifactId>maven-resolver-connector-basic</artifactId>-->
113+
<!-- <version>${resolverVersion}</version>-->
114+
<!-- <scope>test</scope>-->
115+
<!-- </dependency>-->
116+
<!-- <dependency>-->
117+
<!-- <groupId>org.apache.maven.resolver</groupId>-->
118+
<!-- <artifactId>maven-resolver-transport-file</artifactId>-->
119+
<!-- <version>${resolverVersion}</version>-->
120+
<!-- <scope>test</scope>-->
121+
<!-- </dependency>-->
122+
<!-- <dependency>-->
123+
<!-- <groupId>org.apache.maven.resolver</groupId>-->
124+
<!-- <artifactId>maven-resolver-transport-http</artifactId>-->
125+
<!-- <version>${resolverVersion}</version>-->
126+
<!-- <scope>test</scope>-->
127+
<!-- </dependency>-->
128+
<!-- <dependency>-->
129+
<!-- <groupId>org.mockito</groupId>-->
130+
<!-- <artifactId>mockito-core</artifactId>-->
131+
<!-- <version>2.28.2</version>-->
132+
<!-- <scope>test</scope>-->
133+
<!-- </dependency>-->
167134
<dependency>
168135
<groupId>org.mockito</groupId>
169-
<artifactId>mockito-core</artifactId>
136+
<artifactId>mockito-junit-jupiter</artifactId>
170137
<version>2.28.2</version>
171138
<scope>test</scope>
172139
</dependency>
173-
<dependency>
174-
<groupId>junit</groupId>
175-
<artifactId>junit</artifactId>
176-
<version>4.13.2</version>
177-
<scope>test</scope>
178-
</dependency>
179140
<dependency>
180141
<groupId>org.slf4j</groupId>
181142
<artifactId>slf4j-nop</artifactId>
@@ -204,6 +165,16 @@ under the License.
204165
</excludes>
205166
</configuration>
206167
</plugin>
168+
<plugin>
169+
<groupId>org.apache.maven.plugins</groupId>
170+
<artifactId>maven-plugin-plugin</artifactId>
171+
<version>4.0.0-SNAPSHOT</version>
172+
</plugin>
173+
<plugin>
174+
<groupId>org.apache.maven.plugins</groupId>
175+
<artifactId>maven-surefire-plugin</artifactId>
176+
<version>3.0.0-M7</version>
177+
</plugin>
207178
</plugins>
208179
</build>
209180
<profiles>

Diff for: 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>

Diff for: 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>

Diff for: src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java

+43-103
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
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.plugin.MojoException;
27+
import org.apache.maven.api.plugin.annotations.Parameter;
28+
import org.apache.maven.api.services.VersionParser;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
3731

3832
/**
3933
* Abstract class for Deploy mojo's.
4034
*/
4135
public abstract class AbstractDeployMojo
42-
extends AbstractMojo
36+
implements Mojo
4337
{
38+
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
39+
40+
private static final String FIXED_MAVEN_VERSION = "3.9.0";
41+
42+
protected final Logger logger = LoggerFactory.getLogger( getClass() );
43+
4444
/**
4545
* Flag whether Maven is currently in online/offline mode.
4646
*/
@@ -56,123 +56,63 @@ public abstract class AbstractDeployMojo
5656
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
5757
private int retryFailedDeploymentCount;
5858

59-
@Component
60-
private RuntimeInformation runtimeInformation;
61-
6259
@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";
60+
protected Session session;
7161

7262
/* Setters and Getters */
7363

7464
void failIfOffline()
75-
throws MojoFailureException
65+
throws MojoException
7666
{
7767
if ( offline )
7868
{
79-
throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
69+
throw new MojoException( "Cannot deploy artifacts when Maven is in offline mode" );
8070
}
8171
}
8272

73+
public int getRetryFailedDeploymentCount()
74+
{
75+
return retryFailedDeploymentCount;
76+
}
77+
8378
/**
8479
* If this plugin used in pre-3.9.0 Maven, the packaging {@code maven-plugin} will not deploy G level metadata.
8580
*/
8681
protected void warnIfAffectedPackagingAndMaven( final String packaging )
8782
{
8883
if ( AFFECTED_MAVEN_PACKAGING.equals( packaging ) )
8984
{
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 )
85+
VersionParser parser = session.getService( VersionParser.class );
86+
Version fixedMavenVersion = parser.parseVersion( FIXED_MAVEN_VERSION );
87+
Version currentMavenVersion = parser.parseVersion( session.getMavenVersion() );
88+
if ( fixedMavenVersion.compareTo( currentMavenVersion ) > 0 )
10589
{
106-
// skip it: Generic does not throw, only API contains this exception
90+
getLog().warn( "" );
91+
getLog().warn( "You are about to deploy a maven-plugin using Maven " + currentMavenVersion + "." );
92+
getLog().warn( "This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055" );
93+
getLog().warn( "is fixed in those versions of Maven only!" );
94+
getLog().warn( "" );
10795
}
10896
}
10997
}
11098

11199
/**
112100
* Creates resolver {@link RemoteRepository} equipped with needed whistles and bells.
113101
*/
114-
protected RemoteRepository getRemoteRepository( final String repositoryId, final String url )
102+
protected RemoteRepository createDeploymentArtifactRepository( String id, String url )
115103
{
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-
}
104+
return getSession().createRemoteRepository( id, url );
105+
}
135106

136-
return result;
107+
protected Session getSession()
108+
{
109+
return session;
137110
}
138111

139-
/**
140-
* Handles high level retries (this was buried into MAT).
141-
*/
142-
protected void deploy( RepositorySystemSession session, DeployRequest deployRequest ) throws MojoExecutionException
112+
protected Logger getLog()
143113
{
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-
}
114+
return logger;
177115
}
116+
117+
178118
}

0 commit comments

Comments
 (0)