Visitar URL original
Restore compatibility in maven-embedder (#11320) (#11340) · apache/maven@59a6806 · GitHub
Skip to content

Commit 59a6806

Browse files
gnodetCopilotlaeubi
authored
Restore compatibility in maven-embedder (#11320) (#11340)
* Initial plan * Add missing deprecated constants to MavenCli for backward compatibility * Add missing extension model classes for backward compatibility - Created org.apache.maven.cli.internal.extension.model package - Added CoreExtension and CoreExtensions classes (deprecated) - Updated ExtensionResolutionException to return old model type - Added overloaded constructor for compatibility with new API * Add missing xpp3 reader/writer * Do not add @deprecated on constants since the class already is * Add two other missing constants --------- (cherry picked from commit 9a5fb67) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
1 parent c5bd4d7 commit 59a6806

6 files changed

Lines changed: 1186 additions & 1 deletion

File tree

‎compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,42 @@
140140
@Deprecated
141141
public class MavenCli {
142142

143+
/**
144+
* @deprecated Use {@link org.apache.maven.api.Constants#MAVEN_REPO_LOCAL} instead
145+
*/
146+
public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
147+
148+
/**
149+
* @deprecated Use {@link org.apache.maven.api.Session#getRootDirectory()} instead
150+
*/
143151
public static final String MULTIMODULE_PROJECT_DIRECTORY = "maven.multiModuleProjectDirectory";
144152

153+
/**
154+
* @deprecated Use {@link System#getProperty(String)} with "user.home" instead
155+
*/
156+
public static final String USER_HOME = System.getProperty("user.home");
157+
158+
/**
159+
* @deprecated Use {@link org.apache.maven.api.Constants#MAVEN_USER_CONF} instead
160+
*/
161+
public static final File USER_MAVEN_CONFIGURATION_HOME = new File(USER_HOME, ".m2");
162+
163+
/**
164+
* @deprecated Use {@link org.apache.maven.api.Constants#MAVEN_USER_TOOLCHAINS} instead
165+
*/
166+
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File(USER_MAVEN_CONFIGURATION_HOME, "toolchains.xml");
167+
168+
/**
169+
* @deprecated Use {@link org.apache.maven.api.Constants#MAVEN_INSTALLATION_TOOLCHAINS} instead
170+
*/
171+
public static final File DEFAULT_GLOBAL_TOOLCHAINS_FILE =
172+
new File(System.getProperty("maven.conf"), "toolchains.xml");
173+
174+
/**
175+
* @deprecated Use {@link org.apache.maven.api.Constants#MAVEN_STYLE_COLOR_PROPERTY} instead
176+
*/
177+
public static final String STYLE_COLOR_PROPERTY = "style.color";
178+
145179
private static final String MVN_MAVEN_CONFIG = ".mvn/maven.config";
146180

147181
private ClassWorld classWorld;

‎compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/ExtensionResolutionException.java‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package org.apache.maven.cli.internal;
2020

21-
import org.apache.maven.api.cli.extensions.CoreExtension;
21+
import org.apache.maven.cli.internal.extension.model.CoreExtension;
2222

2323
/**
2424
* Exception occurring trying to resolve a plugin.
@@ -37,6 +37,28 @@ public ExtensionResolutionException(CoreExtension extension, Throwable cause) {
3737
this.extension = extension;
3838
}
3939

40+
/**
41+
* Constructor accepting the new API type for internal use.
42+
*
43+
* @param extension the new API extension
44+
* @param cause the cause
45+
*/
46+
public ExtensionResolutionException(org.apache.maven.api.cli.extensions.CoreExtension extension, Throwable cause) {
47+
super(
48+
"Extension " + extension.getId() + " or one of its dependencies could not be resolved: "
49+
+ cause.getMessage(),
50+
cause);
51+
// Convert to old type
52+
CoreExtension oldExtension = new CoreExtension();
53+
oldExtension.setGroupId(extension.getGroupId());
54+
oldExtension.setArtifactId(extension.getArtifactId());
55+
oldExtension.setVersion(extension.getVersion());
56+
if (extension.getClassLoadingStrategy() != null) {
57+
oldExtension.setClassLoadingStrategy(extension.getClassLoadingStrategy());
58+
}
59+
this.extension = oldExtension;
60+
}
61+
4062
public CoreExtension getExtension() {
4163
return extension;
4264
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.cli.internal.extension.model;
20+
21+
/**
22+
* Describes a build extension to utilise.
23+
*
24+
* @deprecated Use {@link org.apache.maven.api.cli.extensions.CoreExtension} instead
25+
*/
26+
@Deprecated
27+
@SuppressWarnings("all")
28+
public class CoreExtension implements java.io.Serializable {
29+
30+
// --------------------------/
31+
// - Class/Member Variables -/
32+
// --------------------------/
33+
34+
/**
35+
* The group ID of the extension's artifact.
36+
*/
37+
private String groupId;
38+
39+
/**
40+
* The artifact ID of the extension.
41+
*/
42+
private String artifactId;
43+
44+
/**
45+
* The version of the extension.
46+
*/
47+
private String version;
48+
49+
/**
50+
* The class loading strategy: 'self-first' (the default),
51+
* 'parent-first' (loads classes from the parent, then from the
52+
* extension) or 'plugin' (follows the rules from extensions
53+
* defined as plugins).
54+
*/
55+
private String classLoadingStrategy = "self-first";
56+
57+
// -----------/
58+
// - Methods -/
59+
// -----------/
60+
61+
/**
62+
* Get the artifact ID of the extension.
63+
*
64+
* @return String
65+
*/
66+
public String getArtifactId() {
67+
return this.artifactId;
68+
} // -- String getArtifactId()
69+
70+
/**
71+
* Get the class loading strategy: 'self-first' (the default),
72+
* 'parent-first' (loads classes from the parent, then from the
73+
* extension) or 'plugin' (follows the rules from extensions
74+
* defined as plugins).
75+
*
76+
* @return String
77+
*/
78+
public String getClassLoadingStrategy() {
79+
return this.classLoadingStrategy;
80+
} // -- String getClassLoadingStrategy()
81+
82+
/**
83+
* Get the group ID of the extension's artifact.
84+
*
85+
* @return String
86+
*/
87+
public String getGroupId() {
88+
return this.groupId;
89+
} // -- String getGroupId()
90+
91+
/**
92+
* Get the version of the extension.
93+
*
94+
* @return String
95+
*/
96+
public String getVersion() {
97+
return this.version;
98+
} // -- String getVersion()
99+
100+
/**
101+
* Set the artifact ID of the extension.
102+
*
103+
* @param artifactId a artifactId object.
104+
*/
105+
public void setArtifactId(String artifactId) {
106+
this.artifactId = artifactId;
107+
} // -- void setArtifactId( String )
108+
109+
/**
110+
* Set the class loading strategy: 'self-first' (the default),
111+
* 'parent-first' (loads classes from the parent, then from the
112+
* extension) or 'plugin' (follows the rules from extensions
113+
* defined as plugins).
114+
*
115+
* @param classLoadingStrategy a classLoadingStrategy object.
116+
*/
117+
public void setClassLoadingStrategy(String classLoadingStrategy) {
118+
this.classLoadingStrategy = classLoadingStrategy;
119+
} // -- void setClassLoadingStrategy( String )
120+
121+
/**
122+
* Set the group ID of the extension's artifact.
123+
*
124+
* @param groupId a groupId object.
125+
*/
126+
public void setGroupId(String groupId) {
127+
this.groupId = groupId;
128+
} // -- void setGroupId( String )
129+
130+
/**
131+
* Set the version of the extension.
132+
*
133+
* @param version a version object.
134+
*/
135+
public void setVersion(String version) {
136+
this.version = version;
137+
} // -- void setVersion( String )
138+
139+
/**
140+
* Gets the identifier of the extension.
141+
*
142+
* @return The extension id in the form {@code <groupId>:<artifactId>:<version>}, never {@code null}.
143+
*/
144+
public String getId() {
145+
StringBuilder id = new StringBuilder(128);
146+
147+
id.append((getGroupId() == null) ? "[unknown-group-id]" : getGroupId());
148+
id.append(":");
149+
id.append((getArtifactId() == null) ? "[unknown-artifact-id]" : getArtifactId());
150+
id.append(":");
151+
id.append((getVersion() == null) ? "[unknown-version]" : getVersion());
152+
153+
return id.toString();
154+
}
155+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.cli.internal.extension.model;
20+
21+
import java.io.Serializable;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
/**
26+
* Extensions to load.
27+
*
28+
* @deprecated Use {@link org.apache.maven.api.cli.extensions.CoreExtension} instead
29+
*/
30+
@Deprecated
31+
@SuppressWarnings("all")
32+
public class CoreExtensions implements Serializable {
33+
34+
// --------------------------/
35+
// - Class/Member Variables -/
36+
// --------------------------/
37+
38+
/**
39+
* Field extensions.
40+
*/
41+
private List<CoreExtension> extensions;
42+
43+
/**
44+
* Field modelEncoding.
45+
*/
46+
private String modelEncoding = "UTF-8";
47+
48+
// -----------/
49+
// - Methods -/
50+
// -----------/
51+
52+
/**
53+
* Method addExtension.
54+
*
55+
* @param coreExtension a coreExtension object.
56+
*/
57+
public void addExtension(CoreExtension coreExtension) {
58+
getExtensions().add(coreExtension);
59+
} // -- void addExtension( CoreExtension )
60+
61+
/**
62+
* Method getExtensions.
63+
*
64+
* @return List
65+
*/
66+
public List<CoreExtension> getExtensions() {
67+
if (this.extensions == null) {
68+
this.extensions = new ArrayList<CoreExtension>();
69+
}
70+
71+
return this.extensions;
72+
} // -- List<CoreExtension> getExtensions()
73+
74+
/**
75+
* Get the modelEncoding field.
76+
*
77+
* @return String
78+
*/
79+
public String getModelEncoding() {
80+
return this.modelEncoding;
81+
} // -- String getModelEncoding()
82+
83+
/**
84+
* Method removeExtension.
85+
*
86+
* @param coreExtension a coreExtension object.
87+
*/
88+
public void removeExtension(CoreExtension coreExtension) {
89+
getExtensions().remove(coreExtension);
90+
} // -- void removeExtension( CoreExtension )
91+
92+
/**
93+
* Set a set of build extensions to use from this project.
94+
*
95+
* @param extensions a extensions object.
96+
*/
97+
public void setExtensions(List<CoreExtension> extensions) {
98+
this.extensions = extensions;
99+
} // -- void setExtensions( List )
100+
101+
/**
102+
* Set the modelEncoding field.
103+
*
104+
* @param modelEncoding a modelEncoding object.
105+
*/
106+
public void setModelEncoding(String modelEncoding) {
107+
this.modelEncoding = modelEncoding;
108+
} // -- void setModelEncoding( String )
109+
}

0 commit comments

Comments
 (0)