gnodet-bot commented on code in PR #1189:
URL:
https://github.com/apache/maven-plugin-tools/pull/1189#discussion_r4294374331
##########
.github/workflows/maven-verify.yml:
##########
@@ -29,3 +29,16 @@ jobs:
maven4-enabled: true # build by Maven 3.x and 4.x
maven4-version: '4.0.0-rc-6' # the same as used in project
+ bootstrap:
+ name: Verify bootstrap profile
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: '17'
+ cache: maven
+ - name: Build with bootstrap profile
+ run: mvn -B -Pbootstrap verify
Review Comment:
⚠️ **[HIGH] Bootstrap job fails on Maven 3 — reactor plugin not installed**
The `bootstrap` job runs `mvn -B -Pbootstrap verify` without a prior `mvn
install` step. The `maven-plugin-plugin-bootstrap` module is referenced as a
plugin (with `<goals>`) in `maven-plugin-plugin/pom.xml`. Maven 3 cannot
resolve reactor plugins from the local reactor — it needs them pre-installed in
the local repository.
Either add an install step before:
```yaml
- name: Install project
run: mvn -B install -DskipTests
- name: Build with bootstrap profile
run: mvn -B -Pbootstrap verify
```
or ensure the job is explicitly documented as Maven 4-only (since Maven 4
can resolve reactor plugins without prior install).
##########
maven-plugin-plugin-bootstrap/src/test/java/org/apache/maven/plugin/plugin/StandaloneDescriptorGeneratorTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.plugin;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandaloneDescriptorGeneratorTest {
+
+ @Test
+ void testFindGoalPrefix() {
+ Model model = new Model();
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Build build = new Build();
+ model.setBuild(build);
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId("maven-plugin-plugin");
+ build.addPlugin(plugin);
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Xpp3Dom configuration = new Xpp3Dom("configuration");
+ Xpp3Dom goalPrefix = new Xpp3Dom("goalPrefix");
+ goalPrefix.setValue("custom-prefix");
+ configuration.addChild(goalPrefix);
+ plugin.setConfiguration(configuration);
+
+ assertEquals("custom-prefix",
StandaloneDescriptorGenerator.findGoalPrefix(model));
+ }
+
+ @Test
+ void testFindGoalPrefixInPluginManagement() {
+ Model model = new Model();
+ Build build = new Build();
+ model.setBuild(build);
+
+ PluginManagement pluginManagement = new PluginManagement();
+ build.setPluginManagement(pluginManagement);
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId("maven-plugin-plugin");
+ pluginManagement.addPlugin(plugin);
+
+ Xpp3Dom configuration = new Xpp3Dom("configuration");
+ Xpp3Dom goalPrefix = new Xpp3Dom("goalPrefix");
+ goalPrefix.setValue("mgmt-prefix");
+ configuration.addChild(goalPrefix);
+ plugin.setConfiguration(configuration);
+
+ assertEquals("mgmt-prefix",
StandaloneDescriptorGenerator.findGoalPrefix(model));
+ }
+
+ @Test
+ void
testFindCompileSourceRootsWalksParentChainAndInterpolatesPaths(@TempDir File
tempDir) throws Exception {
+ File parentDir = new File(tempDir, "parent");
+ parentDir.mkdirs();
+ Files.write(
+ new File(parentDir, "pom.xml").toPath(),
+ ("<project><modelVersion>4.0.0</modelVersion>"
+ +
"<groupId>test</groupId><artifactId>parent</artifactId><version>1.0</version>"
+ + "<packaging>pom</packaging>"
+ +
"<properties><srcDir>custom-src</srcDir></properties>"
+ + "</project>")
+ .getBytes());
+
+ File childDir = new File(tempDir, "child");
+ childDir.mkdirs();
+ File childPom = new File(childDir, "pom.xml");
+ Files.write(
+ childPom.toPath(),
+ ("<project><modelVersion>4.0.0</modelVersion>"
+ +
"<parent><groupId>test</groupId><artifactId>parent</artifactId>"
+ +
"<version>1.0</version><relativePath>../parent/pom.xml</relativePath></parent>"
+ + "<artifactId>child</artifactId>"
+ +
"<build><sourceDirectory>${srcDir}</sourceDirectory></build>"
+ + "</project>")
+ .getBytes());
+
+ Model model =
StandaloneDescriptorGenerator.buildEffectiveModel(childPom);
+ List<File> roots =
StandaloneDescriptorGenerator.findCompileSourceRoots(model, childDir);
+ assertEquals(Collections.singletonList(new File(childDir,
"custom-src").getAbsoluteFile()), roots);
+ }
+
+ @Test
+ void testBuildScanArtifactsIncludesClasspathEntries() throws Exception {
+ String originalClasspath = System.getProperty("java.class.path");
+ try {
+ File tempDir =
Files.createTempDirectory("scan-artifacts").toFile();
+ tempDir.deleteOnExit();
+ File classpathJar = new File(tempDir, "somelib.jar");
+ classpathJar.createNewFile();
+
+ System.setProperty("java.class.path",
classpathJar.getAbsolutePath());
+
+ Set<Artifact> scanArtifacts =
StandaloneDescriptorGenerator.buildScanArtifacts();
+
+ assertTrue(
+ scanArtifacts.stream()
+ .anyMatch(a ->
classpathJar.getAbsoluteFile().equals(a.getFile())),
+ "the real classpath jar should be included for scanning");
+ } finally {
+ if (originalClasspath != null) {
+ System.setProperty("java.class.path", originalClasspath);
+ }
+ }
+ }
+
+ @Test
+ void testRun(@TempDir File tempDir) throws Exception {
+ File pomFile = new File(tempDir, "pom.xml");
+ String pomContent = "<project>\n" + "
<modelVersion>4.0.0</modelVersion>\n"
+ + " <groupId>org.example</groupId>\n"
+ + " <artifactId>test-plugin</artifactId>\n"
+ + " <version>1.0.0</version>\n"
+ + " <packaging>maven-plugin</packaging>\n"
+ + "</project>";
+ Files.write(pomFile.toPath(), pomContent.getBytes());
+
+ File classesDir = new File(tempDir, "target/classes");
+ classesDir.mkdirs();
+
+ StandaloneDescriptorGenerator.run(pomFile);
+
+ File pluginXml = new File(classesDir, "META-INF/maven/plugin.xml");
+ assertTrue(pluginXml.exists(), "plugin.xml should be generated by
run() in classesDirectory/META-INF/maven");
+ }
+
+ @Test
+ void generateV4DiIndexFindsNamedBeans(@TempDir File tempDir) throws
Exception {
+ File classesDir = new File(tempDir, "classes");
+ File outputDir = new File(tempDir, "output");
+ File packageDir = new File(classesDir, "org/example");
+ packageDir.mkdirs();
+ outputDir.mkdirs();
+
+ byte[] bytes = DescriptorGeneratorMojo.computeGeneratorClassBytes(
+ "org.example", "SomeMojoFactory", "grp:art:1.0:goal",
"java.lang.Object");
Review Comment:
🚨 **[CRITICAL] Merge conflict with PR #1236 — will fail to compile**
This test calls `DescriptorGeneratorMojo.computeGeneratorClassBytes` with
**4 arguments**: `(packageName, generatorClassName, mojoName, mojoClassName)`.
PR #1236 changes the signature to **5 arguments**:
`computeGeneratorClassBytes(packageName, generatorClassName, mojoName,
mojoClassName, mojoClassBytes)`. If #1236 merges before this PR, this test will
fail to compile. The same 4-arg call also exists in
`StandaloneDescriptorGenerator.java`.
This needs to be coordinated with the author of PR #1236, or one PR must be
rebased on top of the other after merge.
##########
maven-plugin-plugin-bootstrap/src/test/java/org/apache/maven/plugin/plugin/StandaloneDescriptorGeneratorTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.plugin;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginManagement;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandaloneDescriptorGeneratorTest {
+
+ @Test
+ void testFindGoalPrefix() {
+ Model model = new Model();
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Build build = new Build();
+ model.setBuild(build);
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId("maven-plugin-plugin");
+ build.addPlugin(plugin);
+ assertNull(StandaloneDescriptorGenerator.findGoalPrefix(model));
+
+ Xpp3Dom configuration = new Xpp3Dom("configuration");
+ Xpp3Dom goalPrefix = new Xpp3Dom("goalPrefix");
+ goalPrefix.setValue("custom-prefix");
+ configuration.addChild(goalPrefix);
+ plugin.setConfiguration(configuration);
+
+ assertEquals("custom-prefix",
StandaloneDescriptorGenerator.findGoalPrefix(model));
+ }
+
+ @Test
+ void testFindGoalPrefixInPluginManagement() {
+ Model model = new Model();
+ Build build = new Build();
+ model.setBuild(build);
+
+ PluginManagement pluginManagement = new PluginManagement();
+ build.setPluginManagement(pluginManagement);
+
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId("maven-plugin-plugin");
+ pluginManagement.addPlugin(plugin);
+
+ Xpp3Dom configuration = new Xpp3Dom("configuration");
+ Xpp3Dom goalPrefix = new Xpp3Dom("goalPrefix");
+ goalPrefix.setValue("mgmt-prefix");
+ configuration.addChild(goalPrefix);
+ plugin.setConfiguration(configuration);
+
+ assertEquals("mgmt-prefix",
StandaloneDescriptorGenerator.findGoalPrefix(model));
+ }
+
+ @Test
+ void
testFindCompileSourceRootsWalksParentChainAndInterpolatesPaths(@TempDir File
tempDir) throws Exception {
+ File parentDir = new File(tempDir, "parent");
+ parentDir.mkdirs();
+ Files.write(
+ new File(parentDir, "pom.xml").toPath(),
+ ("<project><modelVersion>4.0.0</modelVersion>"
+ +
"<groupId>test</groupId><artifactId>parent</artifactId><version>1.0</version>"
+ + "<packaging>pom</packaging>"
+ +
"<properties><srcDir>custom-src</srcDir></properties>"
+ + "</project>")
+ .getBytes());
+
+ File childDir = new File(tempDir, "child");
+ childDir.mkdirs();
+ File childPom = new File(childDir, "pom.xml");
+ Files.write(
+ childPom.toPath(),
+ ("<project><modelVersion>4.0.0</modelVersion>"
+ +
"<parent><groupId>test</groupId><artifactId>parent</artifactId>"
+ +
"<version>1.0</version><relativePath>../parent/pom.xml</relativePath></parent>"
+ + "<artifactId>child</artifactId>"
+ +
"<build><sourceDirectory>${srcDir}</sourceDirectory></build>"
+ + "</project>")
+ .getBytes());
+
+ Model model =
StandaloneDescriptorGenerator.buildEffectiveModel(childPom);
+ List<File> roots =
StandaloneDescriptorGenerator.findCompileSourceRoots(model, childDir);
+ assertEquals(Collections.singletonList(new File(childDir,
"custom-src").getAbsoluteFile()), roots);
+ }
+
+ @Test
+ void testBuildScanArtifactsIncludesClasspathEntries() throws Exception {
+ String originalClasspath = System.getProperty("java.class.path");
+ try {
+ File tempDir =
Files.createTempDirectory("scan-artifacts").toFile();
+ tempDir.deleteOnExit();
+ File classpathJar = new File(tempDir, "somelib.jar");
+ classpathJar.createNewFile();
+
+ System.setProperty("java.class.path",
classpathJar.getAbsolutePath());
Review Comment:
💡 **`System.setProperty` in test — parallel test risk**
`testBuildScanArtifactsIncludesClasspathEntries` mutates the JVM-global
`java.class.path` system property. The save/restore pattern is correct for
sequential runs, but if tests are run in parallel (e.g. with Surefire
`forkCount > 1` in the same JVM), another test could observe the mutated value
mid-run. Consider adding `@Isolated` (JUnit 5) or using a `synchronized` block,
or restructuring to avoid mutating the global property.
##########
maven-plugin-plugin-bootstrap/src/main/java/org/apache/maven/plugin/plugin/StandaloneDescriptorGenerator.java:
##########
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.plugin;
+
+import java.io.File;
+import java.lang.reflect.Proxy;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.building.DefaultModelBuilderFactory;
+import org.apache.maven.model.building.DefaultModelBuildingRequest;
+import org.apache.maven.model.building.FileModelSource;
+import org.apache.maven.model.building.ModelBuildingRequest;
+import org.apache.maven.model.building.ModelSource;
+import org.apache.maven.model.resolution.ModelResolver;
+import org.apache.maven.model.resolution.UnresolvableModelException;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
+import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
+import org.apache.maven.tools.plugin.generator.GeneratorUtils;
+import org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator;
+import org.apache.maven.tools.plugin.scanner.MojoScanner;
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.DefaultContainerConfiguration;
+import org.codehaus.plexus.DefaultPlexusContainer;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+
+/**
+ * Minimal standalone runner to generate the bootstrap plugin descriptor.
+ */
+public class StandaloneDescriptorGenerator {
+
+ public static void main(String[] args) {
+ try {
+ File pomFile =
+ (args.length == 0) ? new File("pom.xml").getAbsoluteFile()
: new File(args[0]).getAbsoluteFile();
+ File[] extraSourceRoots = new File[Math.max(0, args.length - 1)];
+ for (int i = 1; i < args.length; i++) {
+ extraSourceRoots[i - 1] = new File(args[i]).getAbsoluteFile();
+ }
+ run(pomFile, extraSourceRoots);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static void run(File pomFile, File... extraSourceRoots) throws
Exception {
+ Model model = buildEffectiveModel(pomFile);
+ File baseDir = pomFile.getParentFile();
+
+ MavenProject project = newProject(model, pomFile);
+
+ List<File> sourceRoots = findCompileSourceRoots(model, baseDir);
+ if (extraSourceRoots != null) {
+ Collections.addAll(sourceRoots, extraSourceRoots);
+ }
+
+ String outPath = (model.getBuild() != null &&
model.getBuild().getOutputDirectory() != null)
+ ? model.getBuild().getOutputDirectory()
+ : "target/classes";
+ File outDir = new File(outPath);
+ File classesDirectory = (outDir.isAbsolute() ? outDir : new
File(baseDir, outPath)).getAbsoluteFile();
+ File outputDirectory = new File(classesDirectory,
"META-INF/maven").getAbsoluteFile();
+
+ ArtifactHandler projectHandler = new
DefaultArtifactHandler("maven-plugin");
+ Artifact projectArtifact = new DefaultArtifact(
+ project.getGroupId(),
+ project.getArtifactId(),
+ project.getVersion(),
+ null,
+ "maven-plugin",
+ "",
+ projectHandler);
+ project.setArtifact(projectArtifact);
+
+ Build build = new Build();
+ File targetDirectory =
+ classesDirectory.getParentFile() != null ?
classesDirectory.getParentFile() : classesDirectory;
+ build.setDirectory(targetDirectory.getAbsolutePath());
+ build.setOutputDirectory(classesDirectory.getAbsolutePath());
+ project.setBuild(build);
+ for (File sourceRoot : sourceRoots) {
+ if (sourceRoot.isDirectory()) {
+ project.addCompileSourceRoot(sourceRoot.getAbsolutePath());
+ }
+ }
+
+ project.setArtifacts(populateDependencies(model));
+
+ ContainerConfiguration containerConfiguration = new
DefaultContainerConfiguration()
+ .setClassPathScanning(PlexusConstants.SCANNING_INDEX)
+ .setAutoWiring(true);
+ PlexusContainer container = new
DefaultPlexusContainer(containerConfiguration);
+ try {
+ container.addComponent(createMinimalRepositorySystem(),
RepositorySystem.class, "");
+ MojoScanner mojoScanner = container.lookup(MojoScanner.class);
+
+ PluginDescriptor pluginDescriptor = buildPluginDescriptor(project,
model);
+
+ DefaultPluginToolsRequest request = new
DefaultPluginToolsRequest(project, pluginDescriptor);
+ request.setEncoding("UTF-8");
+ request.setSkipErrorNoDescriptorsFound(true);
+ request.setDependencies(buildScanArtifacts());
+
+ mojoScanner.populatePluginDescriptor(request);
+
+ outputDirectory.mkdirs();
+ for (MojoDescriptor md : pluginDescriptor.getMojos()) {
+ if (md instanceof ExtendedMojoDescriptor &&
((ExtendedMojoDescriptor) md).isV4Api()) {
+ generateV4Factory(md, classesDirectory);
+ }
+ }
+ DescriptorGeneratorMojo.generateV4DiIndex(classesDirectory,
outputDirectory);
+
+ PluginDescriptorFilesGenerator generator = new
PluginDescriptorFilesGenerator();
+ generator.execute(outputDirectory, request);
+
+ File generatedFile = new File(outputDirectory, "plugin.xml");
+ if (!generatedFile.exists()) {
+ throw new IllegalStateException("Descriptor was not generated:
" + generatedFile.getAbsolutePath());
+ }
+ } finally {
+ container.dispose();
+ }
+ }
+
+ private static void generateV4Factory(MojoDescriptor md, File
classesDirectory) throws Exception {
+ String mojoClassName = md.getImplementation();
+ String packageName = mojoClassName.substring(0,
mojoClassName.lastIndexOf('.'));
+ String generatorClassName =
mojoClassName.substring(mojoClassName.lastIndexOf('.') + 1) + "Factory";
+ String mojoName = md.getId();
+
+ byte[] bin = DescriptorGeneratorMojo.computeGeneratorClassBytes(
+ packageName, generatorClassName, mojoName, mojoClassName);
+
+ File packageDir = new File(classesDirectory, packageName.replace('.',
'/'));
+ packageDir.mkdirs();
+ File classFile = new File(packageDir, generatorClassName + ".class");
+ Files.write(classFile.toPath(), bin);
+ }
+
+ private static MavenProject newProject(Model model, File pomFile) {
+ MavenProject project = new MavenProject(model);
+ project.setFile(pomFile);
+ return project;
+ }
+
+ private static String determineGoalPrefix(Model model, MavenProject
project) {
+ String goalPrefix = findGoalPrefix(model);
+ if (goalPrefix == null || goalPrefix.isEmpty()) {
+ goalPrefix = AbstractGeneratorMojo.getDefaultGoalPrefix(project);
+ }
+ return (goalPrefix == null || goalPrefix.isEmpty()) ? "plugin" :
goalPrefix;
+ }
+
+ private static PluginDescriptor buildPluginDescriptor(MavenProject
project, Model model) {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setGroupId(project.getGroupId());
+ pluginDescriptor.setArtifactId(project.getArtifactId());
+ pluginDescriptor.setVersion(project.getVersion());
+ pluginDescriptor.setGoalPrefix(determineGoalPrefix(model, project));
+ pluginDescriptor.setName(project.getName());
+ pluginDescriptor.setDescription(project.getDescription());
+
pluginDescriptor.setDependencies(GeneratorUtils.toComponentDependencies(project.getArtifacts()));
+
+ if (project.getPrerequisites() != null) {
+ String requiredMavenVersion =
project.getPrerequisites().getMaven();
+ if (requiredMavenVersion != null) {
+ pluginDescriptor.setRequiredMavenVersion(requiredMavenVersion);
+ }
+ }
+ String javaVersion = model.getProperties().getProperty("javaVersion");
+ if (javaVersion != null) {
+ if ("8".equals(javaVersion)) {
+ javaVersion = "1.8";
+ }
+ pluginDescriptor.setRequiredJavaVersion(javaVersion);
+ }
+ return pluginDescriptor;
+ }
+
+ /** Builds the fully inherited, interpolated model, the same way Maven
itself would. */
+ static Model buildEffectiveModel(File pomFile) throws Exception {
+ DefaultModelBuildingRequest request = new
DefaultModelBuildingRequest();
+ request.setPomFile(pomFile);
+
request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
+ request.setProcessPlugins(false);
+ request.setSystemProperties(System.getProperties());
+ request.setModelResolver(new
LocalRepositoryModelResolver(localRepository()));
+ return new
DefaultModelBuilderFactory().newInstance().build(request).getEffectiveModel();
+ }
+
+ private static File localRepository() {
+ String path = System.getProperty("maven.repo.local");
+ return path != null ? new File(path) : new
File(System.getProperty("user.home"), ".m2/repository");
+ }
+
+ /** Resolves parent/imported POMs already present in the local repository;
no downloading. */
+ private static final class LocalRepositoryModelResolver implements
ModelResolver {
+ private final File localRepository;
+
+ LocalRepositoryModelResolver(File localRepository) {
+ this.localRepository = localRepository;
+ }
+
+ @Override
+ public ModelSource resolveModel(String groupId, String artifactId,
String version)
+ throws UnresolvableModelException {
+ File pom = new File(
+ localRepository,
+ groupId.replace('.', '/') + '/' + artifactId + '/' +
version + '/' + artifactId + '-' + version
+ + ".pom");
+ if (!pom.isFile()) {
+ throw new UnresolvableModelException("not found in " +
localRepository, groupId, artifactId, version);
+ }
+ return new FileModelSource(pom);
+ }
+
+ @Override
+ public ModelSource resolveModel(Parent parent) throws
UnresolvableModelException {
+ return resolveModel(parent.getGroupId(), parent.getArtifactId(),
parent.getVersion());
+ }
+
+ @Override
+ public ModelSource resolveModel(Dependency dependency) throws
UnresolvableModelException {
+ return resolveModel(dependency.getGroupId(),
dependency.getArtifactId(), dependency.getVersion());
+ }
+
+ @Override
+ public void addRepository(Repository repository) {}
+
+ @Override
+ public void addRepository(Repository repository, boolean replace) {}
+
+ @Override
+ public ModelResolver newCopy() {
+ return this;
+ }
+ }
+
+ static String findGoalPrefix(Model model) {
+ if (model.getBuild() == null) {
+ return null;
+ }
+ String prefix = findGoalPrefixInPlugins(model.getBuild().getPlugins());
+ if (prefix != null) {
+ return prefix;
+ }
+ if (model.getBuild().getPluginManagement() != null) {
+ return findGoalPrefixInPlugins(
+ model.getBuild().getPluginManagement().getPlugins());
+ }
+ return null;
+ }
+
+ private static String findGoalPrefixInPlugins(List<Plugin> plugins) {
+ if (plugins == null) {
+ return null;
+ }
+ for (Plugin plugin : plugins) {
+ if ("maven-plugin-plugin".equals(plugin.getArtifactId())) {
+ Object configuration = plugin.getConfiguration();
+ if (configuration instanceof Xpp3Dom) {
+ Xpp3Dom dom = (Xpp3Dom) configuration;
+ Xpp3Dom goalPrefixNode = dom.getChild("goalPrefix");
+ if (goalPrefixNode != null) {
+ return goalPrefixNode.getValue();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ static List<File> findCompileSourceRoots(Model model, File baseDir) {
+ Set<File> roots = new LinkedHashSet<>();
+ String srcPath = (model.getBuild() != null &&
model.getBuild().getSourceDirectory() != null)
+ ? model.getBuild().getSourceDirectory()
+ : "src/main/java";
+ File defaultSrc = new File(srcPath);
+ roots.add((defaultSrc.isAbsolute() ? defaultSrc : new File(baseDir,
srcPath)).getAbsoluteFile());
+
+ if (model.getBuild() != null && model.getBuild().getPlugins() != null)
{
+ for (Plugin plugin : model.getBuild().getPlugins()) {
+ if ("maven-compiler-plugin".equals(plugin.getArtifactId())) {
+ collectCompileSourceRoots(plugin.getConfiguration(),
baseDir, roots);
+ for (PluginExecution exec : plugin.getExecutions()) {
+ collectCompileSourceRoots(exec.getConfiguration(),
baseDir, roots);
+ }
+ }
+ }
+ }
+ return new ArrayList<>(roots);
+ }
+
+ private static void collectCompileSourceRoots(Object config, File baseDir,
Set<File> roots) {
+ if (config instanceof Xpp3Dom) {
+ Xpp3Dom compileSourceRoots = ((Xpp3Dom)
config).getChild("compileSourceRoots");
+ if (compileSourceRoots != null) {
+ for (Xpp3Dom child :
compileSourceRoots.getChildren("compileSourceRoot")) {
+ String val = child.getValue();
+ if (val != null && !val.trim().isEmpty()) {
+ String s = val.trim();
+ File f = new File(s);
+ roots.add((f.isAbsolute() ? f : new File(baseDir,
s)).getAbsoluteFile());
+ }
+ }
+ }
+ }
+ }
+
+ private static Set<Artifact> populateDependencies(Model model) {
+ Set<Artifact> artifacts = new HashSet<>();
+ for (Dependency dep : model.getDependencies()) {
+ String scope = dep.getScope() != null ? dep.getScope() : "compile";
+ if ("test".equals(scope) || "provided".equals(scope)) {
+ continue;
+ }
+ String depType = dep.getType() != null ? dep.getType() : "jar";
+ ArtifactHandler depHandler = new DefaultArtifactHandler(depType);
+ Artifact art = new DefaultArtifact(
+ dep.getGroupId(),
+ dep.getArtifactId(),
+ dep.getVersion(),
+ scope,
+ depType,
+ dep.getClassifier(),
+ depHandler);
+ artifacts.add(art);
+ }
+ return artifacts;
+ }
+
+ static Set<Artifact> buildScanArtifacts() {
+ Set<Artifact> scanArtifacts = new HashSet<>();
Review Comment:
💡 **`java.class.path` unreliable outside standard JVM classloading**
`System.getProperty("java.class.path", "")` is not set in OSGi containers,
application servers, or when the JVM is started with a module path instead of a
classpath. Since this is a Maven plugin runtime, this is probably fine in
practice, but worth documenting as a known limitation (e.g. a `@implNote` or a
comment).
##########
maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/converter/JavadocInlineTagsToXhtmlConverter.java:
##########
@@ -87,6 +87,7 @@ static String toXHTML(String bodySnippet) {
String html = "<html><head></head><body>" + bodySnippet + "</body>";
// make it a valid HTML document
final Document document = Jsoup.parse(html);
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
- return document.body().html();
+ // jsoup always inserts a newline after "-->", which later renders as
a stray space
+ return document.body().html().replace("-->\n", "-->");
Review Comment:
💡 **Fragile global `String.replace` on `-->\n`**
`String.replace("-->\n", "-->")` replaces **all** occurrences throughout the
HTML output — not just the spurious jsoup-inserted ones. If a javadoc body has
a pattern like `<!-- comment -->\nSome text`, the newline after `-->` will be
stripped, potentially causing text to run together.
Consider scoping the fix more narrowly (e.g. only collapse runs of
whitespace after `-->`, or post-process with a regex that distinguishes
jsoup-generated structure from content newlines).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]