Skip to content

Commit 4f9e3af

Browse files
cstamasslawekjaranowski
authored andcommitted
[MPH-185] Require Maven 3.6.3
And drop the hoops and loops, just make it simple.
1 parent 2b920a4 commit 4f9e3af

File tree

3 files changed

+42
-130
lines changed

3 files changed

+42
-130
lines changed

pom.xml

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
<properties>
6767
<javaVersion>8</javaVersion>
68-
<mavenVersion>3.2.5</mavenVersion>
68+
<mavenVersion>3.6.3</mavenVersion>
6969
<project.build.outputTimestamp>2022-08-14T12:24:27Z</project.build.outputTimestamp>
7070
</properties>
7171

@@ -86,7 +86,7 @@
8686
<dependency>
8787
<groupId>org.apache.maven</groupId>
8888
<artifactId>maven-model</artifactId>
89-
<version>3.8.5</version>
89+
<version>${mavenVersion}</version>
9090
<scope>provided</scope>
9191
</dependency>
9292
<dependency>
@@ -101,6 +101,12 @@
101101
<version>${mavenVersion}</version>
102102
<scope>provided</scope>
103103
</dependency>
104+
<dependency>
105+
<groupId>org.apache.maven</groupId>
106+
<artifactId>maven-settings-builder</artifactId>
107+
<version>${mavenVersion}</version>
108+
<scope>provided</scope>
109+
</dependency>
104110

105111
<!-- maven plugin tools -->
106112
<dependency>
@@ -230,53 +236,6 @@
230236
</plugin>
231237
</plugins>
232238
</pluginManagement>
233-
<plugins>
234-
<!-- unpack old Maven core sources for maven.mdo model to be able to generate xpp3-extended-writer when not yet provided by Maven core -->
235-
<plugin>
236-
<groupId>org.apache.maven.plugins</groupId>
237-
<artifactId>maven-dependency-plugin</artifactId>
238-
<executions>
239-
<execution>
240-
<goals>
241-
<goal>unpack</goal>
242-
</goals>
243-
<phase>generate-sources</phase>
244-
<configuration>
245-
<artifactItems>
246-
<artifactItem>
247-
<groupId>org.apache.maven</groupId>
248-
<artifactId>apache-maven</artifactId>
249-
<version>${mavenVersion}</version>
250-
<type>tar.gz</type>
251-
<classifier>src</classifier>
252-
<outputDirectory>${project.build.directory}</outputDirectory>
253-
</artifactItem>
254-
</artifactItems>
255-
</configuration>
256-
</execution>
257-
</executions>
258-
</plugin>
259-
<plugin>
260-
<groupId>org.codehaus.modello</groupId>
261-
<artifactId>modello-maven-plugin</artifactId>
262-
<configuration>
263-
<version>4.0.0</version>
264-
<models>
265-
<model>target/apache-maven-${mavenVersion}/maven-model/src/main/mdo/maven.mdo</model>
266-
</models>
267-
<!-- to avoid conflict with class provided by Maven core -->
268-
<extendedClassnameSuffix>ExOldSupport</extendedClassnameSuffix>
269-
</configuration>
270-
<executions>
271-
<execution>
272-
<id>modello</id>
273-
<goals>
274-
<goal>xpp3-extended-writer</goal>
275-
</goals>
276-
</execution>
277-
</executions>
278-
</plugin>
279-
</plugins>
280239
</build>
281240

282241
<profiles>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
20+
String content = new File( basedir, "build.log" ).text
21+
22+
// comments in the same line
23+
assert content.contains( "<groupId>org.apache.maven.its.help</groupId> <!-- " )

src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
import java.io.IOException;
2222
import java.io.StringWriter;
23-
import java.io.Writer;
24-
import java.lang.reflect.InvocationTargetException;
25-
import java.lang.reflect.Method;
2623
import java.util.Collections;
2724
import java.util.List;
2825
import java.util.Properties;
@@ -31,7 +28,7 @@
3128
import org.apache.maven.model.InputSource;
3229
import org.apache.maven.model.Model;
3330
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
34-
import org.apache.maven.model.io.xpp3.MavenXpp3WriterExOldSupport;
31+
import org.apache.maven.model.io.xpp3.MavenXpp3WriterEx;
3532
import org.apache.maven.plugin.MojoExecution;
3633
import org.apache.maven.plugin.MojoExecution.Source;
3734
import org.apache.maven.plugin.MojoExecutionException;
@@ -43,8 +40,6 @@
4340
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
4441
import org.codehaus.plexus.util.xml.XMLWriter;
4542
import org.codehaus.plexus.util.xml.XmlWriterUtil;
46-
import org.codehaus.plexus.util.xml.Xpp3Dom;
47-
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
4843

4944
/**
5045
* Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact.
@@ -187,11 +182,9 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo
187182
StringWriter sWriter = new StringWriter();
188183
try {
189184
if (verbose) {
190-
// try to use Maven core-provided xpp3 extended writer (available since Maven 3.6.1)
191-
if (!writeMavenXpp3WriterEx(sWriter, pom)) {
192-
// xpp3 extended writer not provided by Maven core, use local code
193-
new EffectiveWriterExOldSupport().write(sWriter, pom);
194-
}
185+
MavenXpp3WriterEx mavenXpp3WriterEx = new MavenXpp3WriterEx();
186+
mavenXpp3WriterEx.setStringFormatter(new InputLocationStringFormatter());
187+
mavenXpp3WriterEx.write(sWriter, pom);
195188
} else {
196189
new MavenXpp3Writer().write(sWriter, pom);
197190
}
@@ -218,81 +211,18 @@ private static void cleanModel(Model pom) {
218211
pom.setProperties(properties);
219212
}
220213

221-
private void warnWriteMavenXpp3WriterEx(Throwable t) {
222-
getLog().warn(
223-
"Unexpected exception while running Maven Model Extended Writer, "
224-
+ "falling back to old internal implementation.",
225-
t);
226-
}
227-
228-
private boolean writeMavenXpp3WriterEx(Writer writer, Model model) throws IOException {
229-
try {
230-
Class<?> mavenXpp3WriterExClass = Class.forName("org.apache.maven.model.io.xpp3.MavenXpp3WriterEx");
231-
Object mavenXpp3WriterEx =
232-
mavenXpp3WriterExClass.getDeclaredConstructor().newInstance();
233-
234-
Method setStringFormatter =
235-
mavenXpp3WriterExClass.getMethod("setStringFormatter", InputLocation.StringFormatter.class);
236-
setStringFormatter.invoke(mavenXpp3WriterEx, new InputLocationStringFormatter());
237-
238-
Method write = mavenXpp3WriterExClass.getMethod("write", Writer.class, Model.class);
239-
write.invoke(mavenXpp3WriterEx, writer, model);
240-
241-
return true;
242-
} catch (ClassNotFoundException e) {
243-
// MavenXpp3WriterEx not available in running Maven version
244-
} catch (NoSuchMethodException
245-
| SecurityException
246-
| IllegalArgumentException
247-
| IllegalAccessException
248-
| InstantiationException e) {
249-
warnWriteMavenXpp3WriterEx(e);
250-
} catch (InvocationTargetException e) {
251-
if (e.getTargetException() instanceof IOException) {
252-
throw (IOException) e.getTargetException();
253-
} else if (e.getTargetException() instanceof RuntimeException) {
254-
throw (RuntimeException) e.getTargetException();
255-
}
256-
warnWriteMavenXpp3WriterEx(e);
257-
}
258-
return false;
259-
}
260-
261-
private static String toString(InputLocation location) {
262-
InputSource source = location.getSource();
263-
264-
String s = source.getModelId(); // by default, display modelId
265-
266-
if (StringUtils.isBlank(s) || s.contains("[unknown-version]")) {
267-
// unless it is blank or does not provide version information
268-
s = source.toString();
269-
}
270-
271-
return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + location.getLineNumber() : "") + ' ';
272-
}
273-
274214
private static class InputLocationStringFormatter extends InputLocation.StringFormatter {
275-
215+
@Override
276216
public String toString(InputLocation location) {
277-
return EffectivePomMojo.toString(location);
278-
}
279-
}
217+
InputSource source = location.getSource();
280218

281-
/**
282-
* Xpp3 extended writer extension to improve default InputSource display
283-
*/
284-
private static class EffectiveWriterExOldSupport extends MavenXpp3WriterExOldSupport {
219+
String s = source.getLocation(); // by default, display the path
285220

286-
@Override
287-
public String toString(InputLocation location) {
288-
return EffectivePomMojo.toString(location);
289-
}
221+
if (s == null || s.trim().isEmpty()) {
222+
s = source.getModelId();
223+
}
290224

291-
@Override
292-
protected void writeXpp3DomToSerializer(Xpp3Dom dom, XmlSerializer serializer) throws IOException {
293-
// default method uses Xpp3Dom input location tracking, not available in older Maven versions
294-
// use old Xpp3Dom serialization, without input location tracking
295-
dom.writeToSerializer(null, serializer);
225+
return '}' + s + ((location.getLineNumber() >= 0) ? ", line " + location.getLineNumber() : "") + ' ';
296226
}
297227
}
298228
}

0 commit comments

Comments
 (0)