1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.deploy;
20
21 import org.apache.maven.api.RemoteRepository;
22 import org.apache.maven.api.Session;
23 import org.apache.maven.api.Version;
24 import org.apache.maven.api.di.Inject;
25 import org.apache.maven.api.plugin.Log;
26 import org.apache.maven.api.plugin.Mojo;
27 import org.apache.maven.api.plugin.MojoException;
28 import org.apache.maven.api.plugin.annotations.Parameter;
29
30
31
32
33 public abstract class AbstractDeployMojo implements Mojo {
34 private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
35
36 private static final String FIXED_MAVEN_VERSION = "3.9.0";
37
38 @Inject
39 protected Log logger;
40
41 @Inject
42 protected Session session;
43
44
45
46
47 @Parameter(defaultValue = "${settings.offline}", readonly = true)
48 private boolean offline;
49
50
51
52
53
54
55
56 @Parameter(property = "retryFailedDeploymentCount", defaultValue = "1")
57 private int retryFailedDeploymentCount;
58
59
60
61 void failIfOffline() throws MojoException {
62 if (offline) {
63 throw new MojoException("Cannot deploy artifacts when Maven is in offline mode");
64 }
65 }
66
67 public int getRetryFailedDeploymentCount() {
68 return retryFailedDeploymentCount;
69 }
70
71
72
73
74 protected void warnIfAffectedPackagingAndMaven(String packaging) {
75 if (AFFECTED_MAVEN_PACKAGING.equals(packaging)) {
76 Version fixedMavenVersion = session.parseVersion(FIXED_MAVEN_VERSION);
77 Version currentMavenVersion = session.getMavenVersion();
78 if (fixedMavenVersion.compareTo(currentMavenVersion) > 0) {
79 getLog().warn("");
80 getLog().warn("You are about to deploy a maven-plugin using Maven " + currentMavenVersion + ".");
81 getLog().warn("This plugin should be used ONLY with Maven 3.9.0 and newer, as MNG-7055");
82 getLog().warn("is fixed in those versions of Maven only!");
83 getLog().warn("");
84 }
85 }
86 }
87
88
89
90
91 protected RemoteRepository createDeploymentArtifactRepository(String id, String url) {
92 return getSession().createRemoteRepository(id, url);
93 }
94
95 protected Session getSession() {
96 return session;
97 }
98
99 protected Log getLog() {
100 return logger;
101 }
102 }