diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml
index e4db1c10..23624bd5 100644
--- a/maven-plugin-plugin/pom.xml
+++ b/maven-plugin-plugin/pom.xml
@@ -137,6 +137,12 @@
0.0.7
+
+ javax.inject
+ javax.inject
+ 1
+
+
org.junit.jupiter
diff --git a/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java b/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java
index 879f3cef..a613046b 100644
--- a/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java
@@ -20,13 +20,14 @@
import java.nio.file.Path;
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
import org.apache.maven.api.MojoExecution;
import org.apache.maven.api.Project;
import org.apache.maven.api.ResolutionScope;
import org.apache.maven.api.Session;
import org.apache.maven.api.plugin.Log;
import org.apache.maven.api.plugin.MojoException;
-import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Execute;
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
import org.apache.maven.api.plugin.annotations.Mojo;
@@ -44,7 +45,7 @@
*/
@Mojo(
name = "first",
- requiresDependencyResolution = ResolutionScope.TEST,
+ dependencyResolutionRequired = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.INTEGRATION_TEST)
@Execute(phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura")
public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
@@ -66,23 +67,24 @@ public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
@Parameter(name = "namedParam", alias = "alias")
private String aliasedParam;
- @Component
+ @Inject
private Session session;
- @Component
+ @Inject
private Project project;
- @Component
+ @Inject
private MojoExecution mojo;
- @Component
+ @Inject
private Settings settings;
- @Component
+ @Inject
private Log log;
- @Component(role = ArtifactInstaller.class, hint = "test")
- private Object custom;
+ @Inject
+ @Named("test")
+ private ArtifactInstaller custom;
public void execute() throws MojoException {}
}
diff --git a/maven-plugin-plugin/src/it/v4api/verify.groovy b/maven-plugin-plugin/src/it/v4api/verify.groovy
index 5ce732ad..4c399138 100644
--- a/maven-plugin-plugin/src/it/v4api/verify.groovy
+++ b/maven-plugin-plugin/src/it/v4api/verify.groovy
@@ -25,7 +25,7 @@ assert descriptorFile.isFile()
def pluginDescriptor = new XmlParser().parse( descriptorFile );
assert pluginDescriptor.requiredJavaVersion.text() == '1.8'
-assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-alpha-4'
+assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-alpha-8'
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first" }[0]
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
index 48861725..6bb66d04 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java
@@ -277,7 +277,6 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
protected BuildContext buildContext;
public void generate() throws MojoExecutionException {
-
if (!"maven-plugin".equalsIgnoreCase(project.getArtifactId())
&& project.getArtifactId().toLowerCase().startsWith("maven-")
&& project.getArtifactId().toLowerCase().endsWith("-plugin")
diff --git a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
index c9e30570..64b3f47f 100644
--- a/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
+++ b/maven-plugin-report-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/EnhancedPluginDescriptorBuilder.java
@@ -67,12 +67,7 @@ public PlexusConfiguration buildConfiguration(Reader reader) throws PlexusConfig
@Override
public PluginDescriptor build(Reader reader, String source) throws PlexusConfigurationException {
PluginDescriptor pluginDescriptor = super.build(reader, source);
- // elements added in plugin descriptor 1.1
ExtendedPluginDescriptor extendedPluginDescriptor = new ExtendedPluginDescriptor(pluginDescriptor);
- extendedPluginDescriptor.setRequiredJavaVersion(
- configuration.getChild("requiredJavaVersion").getValue());
- extendedPluginDescriptor.setRequiredMavenVersion(
- configuration.getChild("requiredMavenVersion").getValue());
return extendedPluginDescriptor;
}
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java
index a541969b..dfa8cb81 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java
@@ -75,7 +75,6 @@
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScannerRequest;
import org.apache.maven.tools.plugin.javadoc.JavadocLinkGenerator;
-import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
@@ -89,6 +88,8 @@
import org.eclipse.aether.resolution.ArtifactResult;
import org.objectweb.asm.Opcodes;
+import static org.apache.maven.tools.plugin.util.PluginUtils.MAVEN_COMPONENTS;
+
/**
* JavaMojoDescriptorExtractor, a MojoDescriptor extractor to read descriptors from java classes with annotations.
* Notice that source files are also parsed to get description, since and deprecation information.
@@ -769,6 +770,14 @@ private List toMojoDescriptors(
parameter.setRequired(parameterAnnotationContent.required());
mojoDescriptor.addParameter(parameter);
+
+ if (MAVEN_COMPONENTS.values().contains(parameter.getExpression())) {
+ getLogger()
+ .warn("Deprecated @Parameter(expression = " + parameter.getExpression()
+ + ") annotation for '" + parameter.getName() + "' field in "
+ + mojoAnnotatedClass.getClassName()
+ + ": replace with @Component or @Inject");
+ }
}
// Component annotations
@@ -781,18 +790,13 @@ private List toMojoDescriptors(
parameter.setName(componentAnnotationContent.getFieldName());
// recognize Maven-injected objects as components annotations instead of parameters
- String expression = PluginUtils.MAVEN_COMPONENTS.get(componentAnnotationContent.getRoleClassName());
+ String expression = MAVEN_COMPONENTS.get(componentAnnotationContent.getRoleClassName());
if (expression == null) {
// normal component
parameter.setRequirement(new Requirement(
componentAnnotationContent.getRoleClassName(), componentAnnotationContent.hint()));
} else {
// not a component but a Maven object to be transformed into an expression/property: deprecated
- getLogger()
- .warn("Deprecated @Component annotation for '" + parameter.getName() + "' field in "
- + mojoAnnotatedClass.getClassName()
- + ": replace with @Parameter( defaultValue = \"" + expression
- + "\", readonly = true )");
parameter.setDefaultValue(expression);
parameter.setType(componentAnnotationContent.getRoleClassName());
parameter.setRequired(true);
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java
index a3b6f6e8..c65f8808 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/datamodel/MojoAnnotationContent.java
@@ -81,6 +81,10 @@ public void requiresDependencyResolution(String requiresDependencyResolution) {
this.requiresDependencyResolution = ResolutionScope.valueOf(requiresDependencyResolution);
}
+ public void dependencyResolutionRequired(String dependencyResolutionRequired) {
+ this.requiresDependencyResolution = ResolutionScope.valueOf(dependencyResolutionRequired);
+ }
+
@Override
public ResolutionScope requiresDependencyCollection() {
return requiresDependencyCollection;
@@ -117,6 +121,10 @@ public void requiresProject(boolean requiresProject) {
this.requiresProject = requiresProject;
}
+ public void projectRequired(boolean requiresProject) {
+ this.requiresProject = requiresProject;
+ }
+
@Override
public boolean requiresReports() {
return requiresReports;
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
index a91aea24..57bca934 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java
@@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -88,15 +89,23 @@ public Map scan(MojoAnnotationsScannerRequest reques
Map mojoAnnotatedClasses = new HashMap<>();
try {
+ String mavenApiVersion = null;
for (Artifact dependency : request.getDependencies()) {
scan(mojoAnnotatedClasses, dependency.getFile(), request.getIncludePatterns(), dependency, true);
if (request.getMavenApiVersion() == null
&& dependency.getGroupId().equals("org.apache.maven")
&& (dependency.getArtifactId().equals("maven-plugin-api")
|| dependency.getArtifactId().equals("maven-api-core"))) {
- request.setMavenApiVersion(dependency.getVersion());
+ String version = dependency.getVersion();
+ if (mavenApiVersion != null && !Objects.equals(version, mavenApiVersion)) {
+ throw new UnsupportedOperationException("Mixing Maven 3 and Maven 4 plugins is not supported."
+ + " Fix your dependencies so that you depend either on maven-plugin-api for a Maven 3 plugin,"
+ + " or maven-api-core for a Maven 4 plugin.");
+ }
+ mavenApiVersion = version;
}
}
+ request.setMavenApiVersion(mavenApiVersion);
for (File classDirectory : request.getClassesDirectories()) {
scan(
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java
index d5796ba5..5de14478 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/ParametersWithGenericsMojo.java
@@ -46,6 +46,9 @@ public class ParametersWithGenericsMojo extends AbstractMojo {
@Parameter
private Collection integerArrayCollection;
+ @Parameter
+ private Map> stringListStringMap;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {}
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
index 83dd04c4..bc8c0723 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScannerTest.java
@@ -132,6 +132,12 @@ void scanParametersWithGenerics() throws ExtractionException, IOException {
assertNotNull(parameter);
assertEquals("java.util.List", parameter.getClassName());
assertThat(parameter.getTypeParameters()).containsExactly("java.lang.Number");
+
+ parameter = annotatedClass.getParameters().get("stringListStringMap");
+ assertNotNull(parameter);
+ assertEquals("java.util.Map", parameter.getClassName());
+ assertThat(parameter.getTypeParameters())
+ .containsExactly("java.lang.String", "java.util.List");
}
@Test
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java
index bb3dc5c0..20bccf9c 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/ExtendedPluginDescriptor.java
@@ -18,20 +18,21 @@
*/
package org.apache.maven.tools.plugin;
+import javax.xml.stream.XMLStreamException;
+
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugin.lifecycle.Lifecycle;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Extensions to {@link PluginDescriptor} not supported by Maven 3.2.5.
@@ -223,7 +224,7 @@ public void setPluginArtifact(Artifact pluginArtifact) {
}
@Override
- public Lifecycle getLifecycleMapping(String lifecycleId) throws IOException, XmlPullParserException {
+ public Lifecycle getLifecycleMapping(String lifecycleId) throws IOException, XMLStreamException {
return delegate.getLifecycleMapping(lifecycleId);
}
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
index 4aa62ae7..d686481d 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
@@ -117,13 +117,7 @@ public static String[] findSources(String basedir, String include, String exclud
*/
public static void sortMojos(List mojoDescriptors) {
if (mojoDescriptors != null) {
- Collections.sort(mojoDescriptors, new Comparator() {
- /** {@inheritDoc} */
- @Override
- public int compare(MojoDescriptor mojo0, MojoDescriptor mojo1) {
- return mojo0.getGoal().compareToIgnoreCase(mojo1.getGoal());
- }
- });
+ mojoDescriptors.sort(Comparator.comparing(MojoDescriptor::getGoal));
}
}
@@ -136,13 +130,7 @@ public int compare(MojoDescriptor mojo0, MojoDescriptor mojo1) {
*/
public static void sortMojoParameters(List parameters) {
if (parameters != null) {
- Collections.sort(parameters, new Comparator() {
- /** {@inheritDoc} */
- @Override
- public int compare(Parameter parameter1, Parameter parameter2) {
- return parameter1.getName().compareToIgnoreCase(parameter2.getName());
- }
- });
+ parameters.sort(Comparator.comparing(Parameter::getName));
}
}
diff --git a/maven-plugin-tools-generators/pom.xml b/maven-plugin-tools-generators/pom.xml
index 13af689a..0b03b9c4 100644
--- a/maven-plugin-tools-generators/pom.xml
+++ b/maven-plugin-tools-generators/pom.xml
@@ -60,6 +60,15 @@
velocity
+
+ com.fasterxml.woodstox
+ woodstox-core
+
+
+ org.apache.maven
+ maven-xml-impl
+
+
org.ow2.asm
asm
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
index c9779870..fbd9c169 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
@@ -22,6 +22,8 @@
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -33,6 +35,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -43,8 +46,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.component.repository.ComponentDependency;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.XMLWriter;
import org.w3c.tidy.Tidy;
/**
@@ -61,12 +62,13 @@ private GeneratorUtils() {
* @param w not null writer
* @param pluginDescriptor not null
*/
- public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescriptor) {
- w.startElement("dependencies");
+ public static void writeDependencies(XMLStreamWriter w, PluginDescriptor pluginDescriptor)
+ throws XMLStreamException {
+ w.writeStartElement("dependencies");
List deps = pluginDescriptor.getDependencies();
for (ComponentDependency dep : deps) {
- w.startElement("dependency");
+ w.writeStartElement("dependency");
element(w, "groupId", dep.getGroupId());
@@ -76,10 +78,10 @@ public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescrip
element(w, "version", dep.getVersion());
- w.endElement();
+ w.writeEndElement();
}
- w.endElement();
+ w.writeEndElement();
}
/**
@@ -87,16 +89,16 @@ public static void writeDependencies(XMLWriter w, PluginDescriptor pluginDescrip
* @param name not null
* @param value could be null
*/
- public static void element(XMLWriter w, String name, String value) {
- w.startElement(name);
+ public static void element(XMLStreamWriter w, String name, String value) throws XMLStreamException {
+ w.writeStartElement(name);
if (value == null) {
value = "";
}
- w.writeText(value);
+ w.writeCharacters(value);
- w.endElement();
+ w.writeEndElement();
}
/**
@@ -178,9 +180,9 @@ static String decodeJavadocTags(String description) {
while (matcher.find()) {
String tag = matcher.group(1);
String text = matcher.group(2);
- text = StringUtils.replace(text, "&", "&");
- text = StringUtils.replace(text, "<", "<");
- text = StringUtils.replace(text, ">", ">");
+ text = text.replace("&", "&");
+ text = text.replace("<", "<");
+ text = text.replace(">", ">");
if ("code".equals(tag)) {
text = "" + text + "
";
} else if ("link".equals(tag) || "linkplain".equals(tag) || "value".equals(tag)) {
@@ -197,12 +199,12 @@ static String decodeJavadocTags(String description) {
if (text == null || text.isEmpty()) {
text = "";
}
- if (StringUtils.isNotEmpty(link.group(member))) {
+ if (link.group(member) != null && !link.group(member).isEmpty()) {
if (text != null && !text.isEmpty()) {
text += '.';
}
text += link.group(member);
- if (StringUtils.isNotEmpty(link.group(args))) {
+ if (link.group(args) != null && !link.group(args).isEmpty()) {
text += "()";
}
}
@@ -516,7 +518,7 @@ public static String discoverPackageName(PluginDescriptor pluginDescriptor) {
for (MojoDescriptor descriptor : mojoDescriptors) {
String impl = descriptor.getImplementation();
- if (StringUtils.equals(descriptor.getGoal(), "help") && StringUtils.equals("HelpMojo", impl)) {
+ if (Objects.equals(descriptor.getGoal(), "help") && Objects.equals("HelpMojo", impl)) {
continue;
}
if (impl.lastIndexOf('.') != -1) {
diff --git a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
index 3f44f034..df588272 100644
--- a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
+++ b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGenerator.java
@@ -18,6 +18,10 @@
*/
package org.apache.maven.tools.plugin.generator;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -41,8 +45,7 @@
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.io.CachingOutputStream;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.stax2.util.StreamWriterDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -87,7 +90,7 @@ public void execute(File destinationDirectory, PluginToolsRequest request) throw
// write enhanced plugin-enhanced.xml descriptor (containing some XHTML values)
f = getEnhancedDescriptorFilePath(mavenProject);
writeDescriptor(f, request, DescriptorType.XHTML);
- } catch (IOException e) {
+ } catch (IOException | XMLStreamException e) {
throw new GeneratorException(e.getMessage(), e);
}
}
@@ -103,15 +106,25 @@ private String getVersion() {
}
public void writeDescriptor(File destinationFile, PluginToolsRequest request, DescriptorType type)
- throws IOException {
+ throws IOException, XMLStreamException {
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
+ String apiVersion = request.getUsedMavenApiVersion();
+ boolean isV4 = apiVersion != null && apiVersion.startsWith("4.");
+ String namespace = isV4 ? "http://maven.apache.org/PLUGIN/2.0.0" : null;
+ String location = isV4 ? "https://maven.apache.org/xsd/plugin-2.0.0-alpha-9.xsd" : null;
+
if (!destinationFile.getParentFile().exists()) {
destinationFile.getParentFile().mkdirs();
}
try (Writer writer = new OutputStreamWriter(new CachingOutputStream(destinationFile), UTF_8)) {
- XMLWriter w = new PrettyPrintXMLWriter(writer, UTF_8.name(), null);
+ XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
+ factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_ADD_SPACE_AFTER_EMPTY_ELEM, true);
+ XMLStreamWriter w = new IndentingXMLStreamWriter(factory.createXMLStreamWriter(writer));
+ w.writeStartDocument(UTF_8.name(), null);
final String additionalInfo;
switch (type) {
@@ -125,28 +138,33 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De
additionalInfo = "";
break;
}
- w.writeMarkup("\n\n\n");
-
- w.startElement("plugin");
-
+ w.writeCharacters("\n");
+ w.writeComment(" Generated by maven-plugin-tools " + getVersion() + additionalInfo + " ");
+
+ if (isV4) {
+ w.writeStartElement("", "plugin", namespace);
+ // xmlns="http://maven.apache.org/PLUGIN/2.0.0"
+ // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ // xsi:schemaLocation="http://maven.apache.org/PLUGIN/2.0.0
+ // https://maven.apache.org/xsd/plugin-2.0.0-alpha-9.xsd"
+ w.writeNamespace("", namespace);
+ w.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ w.writeAttribute(
+ "http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", namespace + " " + location);
+ } else {
+ w.writeStartElement("plugin");
+ }
GeneratorUtils.element(w, "name", pluginDescriptor.getName());
-
GeneratorUtils.element(w, "description", pluginDescriptor.getDescription());
-
GeneratorUtils.element(w, "groupId", pluginDescriptor.getGroupId());
-
GeneratorUtils.element(w, "artifactId", pluginDescriptor.getArtifactId());
-
GeneratorUtils.element(w, "version", pluginDescriptor.getVersion());
-
GeneratorUtils.element(w, "goalPrefix", pluginDescriptor.getGoalPrefix());
if (type != DescriptorType.LIMITED_FOR_HELP_MOJO) {
GeneratorUtils.element(w, "isolatedRealm", String.valueOf(pluginDescriptor.isIsolatedRealm()));
-
GeneratorUtils.element(
w, "inheritedByDefault", String.valueOf(pluginDescriptor.isInheritedByDefault()));
-
if (pluginDescriptor instanceof ExtendedPluginDescriptor) {
ExtendedPluginDescriptor extPluginDescriptor = (ExtendedPluginDescriptor) pluginDescriptor;
if (StringUtils.isNotBlank(extPluginDescriptor.getRequiredJavaVersion())) {
@@ -158,7 +176,7 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De
}
}
- w.startElement("mojos");
+ w.writeStartElement("mojos");
final JavadocLinkGenerator javadocLinkGenerator;
if (request.getInternalJavadocBaseUrl() != null
@@ -174,22 +192,18 @@ public void writeDescriptor(File destinationFile, PluginToolsRequest request, De
}
if (pluginDescriptor.getMojos() != null) {
List descriptors = pluginDescriptor.getMojos();
-
PluginUtils.sortMojos(descriptors);
-
for (MojoDescriptor descriptor : descriptors) {
- processMojoDescriptor(descriptor, w, type, javadocLinkGenerator);
+ processMojoDescriptor(descriptor, w, type, javadocLinkGenerator, isV4);
}
}
- w.endElement();
-
- if (type != DescriptorType.LIMITED_FOR_HELP_MOJO) {
+ w.writeEndElement();
+ if (type != DescriptorType.LIMITED_FOR_HELP_MOJO && !isV4) {
GeneratorUtils.writeDependencies(w, pluginDescriptor);
}
-
- w.endElement();
-
+ w.writeEndElement();
+ w.close();
writer.flush();
}
}
@@ -219,21 +233,23 @@ private static String getTextValue(DescriptorType type, boolean containsXhtmlVal
@SuppressWarnings("deprecation")
protected void processMojoDescriptor(
MojoDescriptor mojoDescriptor,
- XMLWriter w,
+ XMLStreamWriter w,
DescriptorType type,
- JavadocLinkGenerator javadocLinkGenerator) {
+ JavadocLinkGenerator javadocLinkGenerator,
+ boolean isV4)
+ throws XMLStreamException {
boolean containsXhtmlTextValues = mojoDescriptor instanceof ExtendedMojoDescriptor
&& ((ExtendedMojoDescriptor) mojoDescriptor).containsXhtmlTextValues();
- w.startElement("mojo");
+ w.writeStartElement("mojo");
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- w.startElement("goal");
- w.writeText(mojoDescriptor.getGoal());
- w.endElement();
+ w.writeStartElement("goal");
+ w.writeCharacters(mojoDescriptor.getGoal());
+ w.writeEndElement();
// ----------------------------------------------------------------------
//
@@ -242,9 +258,9 @@ protected void processMojoDescriptor(
String description = mojoDescriptor.getDescription();
if (description != null && !description.isEmpty()) {
- w.startElement("description");
- w.writeText(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDescription()));
- w.endElement();
+ w.writeStartElement("description");
+ w.writeCharacters(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDescription()));
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
@@ -252,26 +268,34 @@ protected void processMojoDescriptor(
// ----------------------------------------------------------------------
if (StringUtils.isNotEmpty(mojoDescriptor.isDependencyResolutionRequired())) {
- GeneratorUtils.element(w, "requiresDependencyResolution", mojoDescriptor.isDependencyResolutionRequired());
+ GeneratorUtils.element(
+ w,
+ isV4 ? "dependencyResolution" : "requiresDependencyResolution",
+ mojoDescriptor.isDependencyResolutionRequired());
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
-
- GeneratorUtils.element(w, "requiresDirectInvocation", String.valueOf(mojoDescriptor.isDirectInvocationOnly()));
+ if (!isV4) {
+ GeneratorUtils.element(
+ w, "requiresDirectInvocation", String.valueOf(mojoDescriptor.isDirectInvocationOnly()));
+ }
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- GeneratorUtils.element(w, "requiresProject", String.valueOf(mojoDescriptor.isProjectRequired()));
+ GeneratorUtils.element(
+ w, isV4 ? "projectRequired" : "requiresProject", String.valueOf(mojoDescriptor.isProjectRequired()));
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- GeneratorUtils.element(w, "requiresReports", String.valueOf(mojoDescriptor.isRequiresReports()));
+ if (!isV4) {
+ GeneratorUtils.element(w, "requiresReports", String.valueOf(mojoDescriptor.isRequiresReports()));
+ }
// ----------------------------------------------------------------------
//
@@ -283,7 +307,8 @@ protected void processMojoDescriptor(
//
// ----------------------------------------------------------------------
- GeneratorUtils.element(w, "requiresOnline", String.valueOf(mojoDescriptor.isOnlineRequired()));
+ GeneratorUtils.element(
+ w, isV4 ? "onlineRequired" : "requiresOnline", String.valueOf(mojoDescriptor.isOnlineRequired()));
// ----------------------------------------------------------------------
//
@@ -319,26 +344,26 @@ protected void processMojoDescriptor(
//
// ----------------------------------------------------------------------
- w.startElement("implementation");
- w.writeText(mojoDescriptor.getImplementation());
- w.endElement();
+ w.writeStartElement("implementation");
+ w.writeCharacters(mojoDescriptor.getImplementation());
+ w.writeEndElement();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- w.startElement("language");
- w.writeText(mojoDescriptor.getLanguage());
- w.endElement();
+ w.writeStartElement("language");
+ w.writeCharacters(mojoDescriptor.getLanguage());
+ w.writeEndElement();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
if (StringUtils.isNotEmpty(mojoDescriptor.getComponentConfigurator())) {
- w.startElement("configurator");
- w.writeText(mojoDescriptor.getComponentConfigurator());
- w.endElement();
+ w.writeStartElement("configurator");
+ w.writeCharacters(mojoDescriptor.getComponentConfigurator());
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
@@ -346,41 +371,45 @@ protected void processMojoDescriptor(
// ----------------------------------------------------------------------
if (StringUtils.isNotEmpty(mojoDescriptor.getComponentComposer())) {
- w.startElement("composer");
- w.writeText(mojoDescriptor.getComponentComposer());
- w.endElement();
+ w.writeStartElement("composer");
+ w.writeCharacters(mojoDescriptor.getComponentComposer());
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
- w.startElement("instantiationStrategy");
- w.writeText(mojoDescriptor.getInstantiationStrategy());
- w.endElement();
+ if (!isV4) {
+ w.writeStartElement("instantiationStrategy");
+ w.writeCharacters(mojoDescriptor.getInstantiationStrategy());
+ w.writeEndElement();
+ }
// ----------------------------------------------------------------------
// Strategy for handling repeated reference to mojo in
// the calculated (decorated, resolved) execution stack
// ----------------------------------------------------------------------
- w.startElement("executionStrategy");
- w.writeText(mojoDescriptor.getExecutionStrategy());
- w.endElement();
+ if (!isV4) {
+ w.writeStartElement("executionStrategy");
+ w.writeCharacters(mojoDescriptor.getExecutionStrategy());
+ w.writeEndElement();
+ }
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
if (mojoDescriptor.getSince() != null) {
- w.startElement("since");
+ w.writeStartElement("since");
if (StringUtils.isEmpty(mojoDescriptor.getSince())) {
- w.writeText("No version given");
+ w.writeCharacters("No version given");
} else {
- w.writeText(mojoDescriptor.getSince());
+ w.writeCharacters(mojoDescriptor.getSince());
}
- w.endElement();
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
@@ -388,15 +417,15 @@ protected void processMojoDescriptor(
// ----------------------------------------------------------------------
if (mojoDescriptor.getDeprecated() != null) {
- w.startElement("deprecated");
+ w.writeStartElement("deprecated");
if (StringUtils.isEmpty(mojoDescriptor.getDeprecated())) {
- w.writeText("No reason given");
+ w.writeCharacters("No reason given");
} else {
- w.writeText(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDeprecated()));
+ w.writeCharacters(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDeprecated()));
}
- w.endElement();
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
@@ -407,14 +436,13 @@ protected void processMojoDescriptor(
ExtendedMojoDescriptor extendedMojoDescriptor = (ExtendedMojoDescriptor) mojoDescriptor;
if (extendedMojoDescriptor.getDependencyCollectionRequired() != null) {
GeneratorUtils.element(
- w, "requiresDependencyCollection", extendedMojoDescriptor.getDependencyCollectionRequired());
+ w,
+ isV4 ? "dependencyCollection" : "requiresDependencyCollection",
+ extendedMojoDescriptor.getDependencyCollectionRequired());
}
- GeneratorUtils.element(w, "threadSafe", String.valueOf(extendedMojoDescriptor.isThreadSafe()));
-
- boolean v4Api = extendedMojoDescriptor.isV4Api();
- if (v4Api) {
- GeneratorUtils.element(w, "v4Api", String.valueOf(v4Api));
+ if (!isV4) {
+ GeneratorUtils.element(w, "threadSafe", String.valueOf(extendedMojoDescriptor.isThreadSafe()));
}
}
@@ -424,7 +452,7 @@ protected void processMojoDescriptor(
List parameters = mojoDescriptor.getParameters();
- w.startElement("parameters");
+ w.writeStartElement("parameters");
Map requirements = new LinkedHashMap<>();
@@ -462,7 +490,7 @@ protected void processMojoDescriptor(
else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable()) {
// treat it as a normal parameter.
- w.startElement("parameter");
+ w.writeStartElement("parameter");
GeneratorUtils.element(w, "name", parameter.getName());
@@ -470,18 +498,22 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
GeneratorUtils.element(w, "alias", parameter.getAlias());
}
- writeParameterType(w, type, javadocLinkGenerator, parameter, mojoDescriptor.getGoal());
+ if (isV4 && type == DescriptorType.STANDARD) {
+ GeneratorUtils.element(w, "type", parameter.getType());
+ } else {
+ writeParameterType(w, type, javadocLinkGenerator, parameter, mojoDescriptor.getGoal());
+ }
if (parameter.getSince() != null) {
- w.startElement("since");
+ w.writeStartElement("since");
if (StringUtils.isEmpty(parameter.getSince())) {
- w.writeText("No version given");
+ w.writeCharacters("No version given");
} else {
- w.writeText(parameter.getSince());
+ w.writeCharacters(parameter.getSince());
}
- w.endElement();
+ w.writeEndElement();
}
if (parameter.getDeprecated() != null) {
@@ -495,7 +527,7 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
}
}
- if (parameter.getImplementation() != null) {
+ if (!isV4 && parameter.getImplementation() != null) {
GeneratorUtils.element(w, "implementation", parameter.getImplementation());
}
@@ -506,24 +538,31 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
GeneratorUtils.element(
w, "description", getTextValue(type, containsXhtmlTextValues, parameter.getDescription()));
- if (StringUtils.isNotEmpty(parameter.getDefaultValue())
+ if (isV4) {
+ if (parameter.getDefaultValue() != null) {
+ GeneratorUtils.element(w, "defaultValue", parameter.getDefaultValue());
+ }
+ if (StringUtils.isNotEmpty(parameter.getExpression())) {
+ GeneratorUtils.element(w, "expression", parameter.getExpression());
+ }
+ } else if (StringUtils.isNotEmpty(parameter.getDefaultValue())
|| StringUtils.isNotEmpty(parameter.getExpression())) {
configuration.add(parameter);
}
- w.endElement();
+ w.writeEndElement();
}
}
}
- w.endElement();
+ w.writeEndElement();
// ----------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------
- if (!configuration.isEmpty()) {
- w.startElement("configuration");
+ if (!isV4 && !configuration.isEmpty()) {
+ w.writeStartElement("configuration");
for (Parameter parameter : configuration) {
if (type == DescriptorType.LIMITED_FOR_HELP_MOJO && !parameter.isEditable()) {
@@ -531,40 +570,40 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
continue;
}
- w.startElement(parameter.getName());
+ w.writeStartElement(parameter.getName());
// strip type by parameter type (generics) information
String parameterType = StringUtils.chomp(parameter.getType(), "<");
if (parameterType != null && !parameterType.isEmpty()) {
- w.addAttribute("implementation", parameterType);
+ w.writeAttribute("implementation", parameterType);
}
if (parameter.getDefaultValue() != null) {
- w.addAttribute("default-value", parameter.getDefaultValue());
+ w.writeAttribute("default-value", parameter.getDefaultValue());
}
if (StringUtils.isNotEmpty(parameter.getExpression())) {
- w.writeText(parameter.getExpression());
+ w.writeCharacters(parameter.getExpression());
}
- w.endElement();
+ w.writeEndElement();
}
- w.endElement();
+ w.writeEndElement();
}
// ----------------------------------------------------------------------
// Requirements
// ----------------------------------------------------------------------
- if (!requirements.isEmpty() && type != DescriptorType.LIMITED_FOR_HELP_MOJO) {
- w.startElement("requirements");
+ if (!isV4 && !requirements.isEmpty() && type != DescriptorType.LIMITED_FOR_HELP_MOJO) {
+ w.writeStartElement("requirements");
for (Map.Entry entry : requirements.entrySet()) {
String key = entry.getKey();
Requirement requirement = entry.getValue();
- w.startElement("requirement");
+ w.writeStartElement("requirement");
GeneratorUtils.element(w, "role", requirement.getRole());
@@ -574,13 +613,13 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
GeneratorUtils.element(w, "field-name", key);
- w.endElement();
+ w.writeEndElement();
}
- w.endElement();
+ w.writeEndElement();
}
- w.endElement();
+ w.writeEndElement();
}
/**
@@ -592,11 +631,12 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())
* @param goal
*/
protected void writeParameterType(
- XMLWriter w,
+ XMLStreamWriter w,
DescriptorType type,
JavadocLinkGenerator javadocLinkGenerator,
Parameter parameter,
- String goal) {
+ String goal)
+ throws XMLStreamException {
String parameterType = parameter.getType();
if (type == DescriptorType.STANDARD) {
@@ -666,4 +706,76 @@ private String getExpression(Parameter parameter) {
}
return expression;
}
+
+ static class IndentingXMLStreamWriter extends StreamWriterDelegate {
+
+ int depth = 0;
+ boolean hasChildren = false;
+
+ IndentingXMLStreamWriter(XMLStreamWriter parent) {
+ super(parent);
+ }
+
+ @Override
+ public void writeEmptyElement(String localName) throws XMLStreamException {
+ indent();
+ super.writeEmptyElement(localName);
+ hasChildren = true;
+ }
+
+ @Override
+ public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
+ indent();
+ super.writeEmptyElement(namespaceURI, localName);
+ hasChildren = true;
+ }
+
+ @Override
+ public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+ indent();
+ super.writeEmptyElement(prefix, localName, namespaceURI);
+ hasChildren = true;
+ }
+
+ @Override
+ public void writeStartElement(String localName) throws XMLStreamException {
+ indent();
+ super.writeStartElement(localName);
+ depth++;
+ hasChildren = false;
+ }
+
+ @Override
+ public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
+ indent();
+ super.writeStartElement(namespaceURI, localName);
+ depth++;
+ hasChildren = false;
+ }
+
+ @Override
+ public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+ indent();
+ super.writeStartElement(prefix, localName, namespaceURI);
+ depth++;
+ hasChildren = false;
+ }
+
+ @Override
+ public void writeEndElement() throws XMLStreamException {
+ depth--;
+ if (hasChildren) {
+ indent();
+ }
+ super.writeEndElement();
+ hasChildren = true;
+ }
+
+ private void indent() throws XMLStreamException {
+ super.writeCharacters("\n");
+ for (int i = 0; i < depth; i++) {
+ super.writeCharacters(" ");
+ }
+ }
+ }
}
diff --git a/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm b/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm
index 0ac5b891..1f2ba56c 100644
--- a/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm
+++ b/maven-plugin-tools-generators/src/main/resources/help-class-source-v4.vm
@@ -19,7 +19,6 @@ package ${helpPackageName};
#end
import org.apache.maven.api.plugin.MojoException;
-import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.api.plugin.Log;
@@ -30,6 +29,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import jakarta.inject.Inject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -43,11 +43,11 @@ import java.util.List;
* Call mvn ${goalPrefix}:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
* @author maven-plugin-tools
*/
-@Mojo( name = "help", requiresProject = false )
+@Mojo( name = "help", projectRequired = false )
public class HelpMojo
implements org.apache.maven.api.plugin.Mojo
{
- @Component
+ @Inject
private Log logger;
/**
diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
index f592b631..9677180d 100644
--- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
@@ -105,7 +105,73 @@ public void testGenerator() throws Exception {
extendPluginDescriptor(pluginDescriptor);
generator.execute(destinationDirectory, new DefaultPluginToolsRequest(mavenProject, pluginDescriptor));
- validate(destinationDirectory);
+ validate(destinationDirectory, false);
+
+ FileUtils.deleteDirectory(destinationDirectory);
+ }
+
+ @Test
+ public void testGeneratorV4() throws Exception {
+ setupGenerator();
+
+ MojoDescriptor mojoDescriptor = new MojoDescriptor();
+ mojoDescriptor.setGoal("testGoal");
+ mojoDescriptor.setImplementation("org.apache.maven.tools.plugin.generator.TestMojo");
+ mojoDescriptor.setDependencyResolutionRequired("compile");
+ mojoDescriptor.setSince("mojoSince");
+
+ List params = new ArrayList<>();
+
+ Parameter param = new Parameter();
+ param.setExpression("${project.build.directory}");
+ param.setDefaultValue("");
+ param.setName("dir");
+ param.setRequired(true);
+ param.setType("java.lang.String");
+ param.setDescription("Test parameter description");
+ param.setAlias("some.alias");
+ param.setSince("paramDirSince");
+ params.add(param);
+
+ param = new Parameter();
+ param.setName("withoutSince");
+ param.setType("java.lang.String");
+ params.add(param);
+
+ mojoDescriptor.setParameters(params);
+
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ mojoDescriptor.setPluginDescriptor(pluginDescriptor);
+
+ pluginDescriptor.addMojo(mojoDescriptor);
+
+ pluginDescriptor.setArtifactId("maven-unitTesting-plugin");
+ pluginDescriptor.setGoalPrefix("test");
+
+ ComponentDependency dependency = new ComponentDependency();
+ dependency.setGroupId("testGroup");
+ dependency.setArtifactId("testArtifact");
+ dependency.setVersion("0.0.0");
+
+ pluginDescriptor.setDependencies(Collections.singletonList(dependency));
+
+ File destinationDirectory =
+ Files.createTempDirectory("testGenerator-outDir").toFile();
+ destinationDirectory.mkdir();
+
+ MavenProject mavenProject = new MavenProject();
+ mavenProject.setGroupId("foo");
+ mavenProject.setArtifactId("bar");
+ Build build = new Build();
+ build.setDirectory(basedir + "/target");
+ build.setOutputDirectory(basedir + "/target");
+ mavenProject.setBuild(build);
+ extendPluginDescriptor(pluginDescriptor);
+ DefaultPluginToolsRequest request = new DefaultPluginToolsRequest(mavenProject, pluginDescriptor);
+ request.setUsedMavenApiVersion("4.0.0");
+ generator.execute(destinationDirectory, request);
+
+ validate(destinationDirectory, true);
FileUtils.deleteDirectory(destinationDirectory);
}
@@ -145,7 +211,7 @@ protected void setupGenerator() throws Exception {
//
// ----------------------------------------------------------------------
- protected void validate(File destinationDirectory) throws Exception {
+ protected void validate(File destinationDirectory, boolean isV4) throws Exception {
// empty
}
}
diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
index d0e10c8e..53adda69 100644
--- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
@@ -18,6 +18,9 @@
*/
package org.apache.maven.tools.plugin.generator;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;
@@ -27,8 +30,6 @@
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.repository.ComponentDependency;
-import org.codehaus.plexus.util.xml.CompactXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -49,9 +50,14 @@ void testShouldWriteDependencies() throws Exception {
descriptor.setDependencies(Collections.singletonList(dependency));
StringWriter sWriter = new StringWriter();
- XMLWriter writer = new CompactXMLWriter(sWriter);
+ XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
+ factory.setProperty(com.ctc.wstx.api.WstxOutputProperties.P_ADD_SPACE_AFTER_EMPTY_ELEM, true);
+ XMLStreamWriter writer = factory.createXMLStreamWriter(sWriter);
GeneratorUtils.writeDependencies(writer, descriptor);
+ writer.close();
String output = sWriter.toString();
diff --git a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
index c58e9d20..8bfa1ae0 100644
--- a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
+++ b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorFilesGeneratorTest.java
@@ -60,20 +60,22 @@ protected void extendPluginDescriptor(PluginDescriptor pluginDescriptor) throws
}
@Override
- protected void validate(File destinationDirectory) throws Exception {
+ protected void validate(File destinationDirectory, boolean isV4) throws Exception {
PluginDescriptorBuilder pdb = new PluginDescriptorBuilder();
File pluginDescriptorFile = new File(destinationDirectory, "plugin.xml");
String pd = readFile(pluginDescriptorFile);
+ System.err.println(pd);
+
PluginDescriptor pluginDescriptor = pdb.build(new StringReader(pd));
assertEquals(1, pluginDescriptor.getMojos().size());
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojos().get(0);
- checkMojo(mojoDescriptor);
+ checkMojo(mojoDescriptor, isV4);
// ----------------------------------------------------------------------
// Dependencies
@@ -81,14 +83,12 @@ protected void validate(File destinationDirectory) throws Exception {
List dependencies = pluginDescriptor.getDependencies();
- checkDependency("testGroup", "testArtifact", "0.0.0", dependencies.get(0));
-
- assertEquals(1, dependencies.size());
-
- ComponentDependency dependency = dependencies.get(0);
- assertEquals("testGroup", dependency.getGroupId());
- assertEquals("testArtifact", dependency.getArtifactId());
- assertEquals("0.0.0", dependency.getVersion());
+ if (isV4) {
+ assertEquals(0, dependencies.size());
+ } else {
+ assertEquals(1, dependencies.size());
+ checkDependency("testGroup", "testArtifact", "0.0.0", dependencies.get(0));
+ }
}
private String readFile(File pluginDescriptorFile) throws IOException {
@@ -105,7 +105,7 @@ private String readFile(File pluginDescriptorFile) throws IOException {
return sWriter.toString();
}
- private void checkMojo(MojoDescriptor mojoDescriptor) {
+ private void checkMojo(MojoDescriptor mojoDescriptor, boolean isV4) {
assertEquals("test:testGoal", mojoDescriptor.getFullGoalName());
assertEquals("org.apache.maven.tools.plugin.generator.TestMojo", mojoDescriptor.getImplementation());
@@ -122,14 +122,26 @@ private void checkMojo(MojoDescriptor mojoDescriptor) {
Parameter parameterWithGenerics = mojoDescriptor.getParameters().get(2);
assertNotNull(parameterWithGenerics);
assertEquals("parameterWithGenerics", parameterWithGenerics.getName());
- assertEquals("java.util.Collection", parameterWithGenerics.getType());
+
+ if (isV4) {
+ assertEquals("java.util.Collection", parameterWithGenerics.getType());
+ } else {
+ assertEquals("java.util.Collection", parameterWithGenerics.getType());
+ }
PlexusConfiguration configurations = mojoDescriptor.getMojoConfiguration();
assertNotNull(configurations);
PlexusConfiguration configuration = configurations.getChild("parameterWithGenerics");
- assertEquals("java.util.Collection", configuration.getAttribute("implementation"));
- assertEquals("a,b,c", configuration.getAttribute("default-value"));
- assertEquals("${customParam}", configuration.getValue());
+ if (isV4) {
+ assertEquals(0, configuration.getChildren().length);
+ assertEquals("a,b,c", parameterWithGenerics.getParameterV4().getDefaultValue());
+ assertEquals(
+ "${customParam}", parameterWithGenerics.getParameterV4().getExpression());
+ } else {
+ assertEquals("java.util.Collection", configuration.getAttribute("implementation"));
+ assertEquals("a,b,c", configuration.getAttribute("default-value"));
+ assertEquals("${customParam}", configuration.getValue());
+ }
}
private void checkParameter(Parameter parameter) {
diff --git a/maven-script/maven-script-ant/pom.xml b/maven-script/maven-script-ant/pom.xml
index 05c26b4c..d4a1d097 100644
--- a/maven-script/maven-script-ant/pom.xml
+++ b/maven-script/maven-script-ant/pom.xml
@@ -77,6 +77,14 @@ under the License.
org.apache.maven
maven-core
+
+ com.fasterxml.woodstox
+ woodstox-core
+
+
+ org.apache.maven
+ maven-xml-impl
+
org.codehaus.plexus
plexus-xml
diff --git a/pom.xml b/pom.xml
index 2343a0c3..ceb43349 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,7 +92,7 @@
8
3.3.0
- 4.0.0-alpha-4
+ 4.0.0-alpha-9-SNAPSHOT
3.2.5
1.7.36
1.10.14
@@ -107,6 +107,7 @@
3.2.0
3.11.0
3.5.0
+ 6.5.1
2023-11-02T22:38:45Z
@@ -166,7 +167,12 @@
org.apache.maven
maven-plugin-api
- ${mavenVersion}
+ ${maven4Version}
+
+
+ org.apache.maven
+ maven-xml-impl
+ ${maven4Version}
org.apache.maven
@@ -200,6 +206,11 @@
+
+ com.fasterxml.woodstox
+ woodstox-core
+ ${woodstoxVersion}
+
org.slf4j