[ https://issues.apache.org/jira/browse/MPLUGIN-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17850735#comment-17850735 ]
ASF GitHub Bot commented on MPLUGIN-508: ---------------------------------------- michael-o commented on code in PR #286: URL: https://github.com/apache/maven-plugin-tools/pull/286#discussion_r1620834033 ########## maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java: ########## @@ -38,15 +37,12 @@ * Test mojo for the v4 api plugin descriptor generation. * This mojo is not actually runnable because: * - it's using a custom lifecycle which is not defined - * - it has a @Component dependency on ArtifactInstaller (hint=test) which does not exist + * - it has a @Inject dependency on ArtifactInstaller (hint=test) which does not exist * * @since 1.2 */ -@Mojo( - name = "first", - requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.INTEGRATION_TEST) -@Execute(phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura") +@Mojo(name = "first", defaultPhase = "integration-test") +@Execute(phase = "generate-sources", lifecycle = "cobertura") public class FirstMojo implements org.apache.maven.api.plugin.Mojo { Review Comment: Is there a reason why other args to `@Mojo` are gone? ########## maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java: ########## @@ -367,6 +390,141 @@ public void generate() throws MojoExecutionException { } } + private void generateIndex() throws GeneratorException { + try { + Set<String> diBeans = new TreeSet<>(); + try (Stream<Path> paths = Files.walk(classOutputDirectory.toPath())) { + List<Path> classes = paths.filter( + p -> p.getFileName().toString().endsWith(".class")) + .collect(Collectors.toList()); + for (Path classFile : classes) { + String fileString = classFile.toString(); + String className = fileString + .substring(0, fileString.length() - ".class".length()) + .replace('/', '.'); + try (InputStream is = Files.newInputStream(classFile)) { + ClassReader rdr = new ClassReader(is); + rdr.accept( + new ClassVisitor(Opcodes.ASM9) { + String className; + + @Override + public void visit( + int version, + int access, + String name, + String signature, + String superName, + String[] interfaces) { + super.visit(version, access, name, signature, superName, interfaces); + className = name; + } + + @Override + public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + if ("Lorg/apache/maven/api/di/Named;".equals(descriptor)) { + diBeans.add(className.replace('/', '.')); + } + return null; + } + }, + ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG); + } + + // Class<?> clazz = project.getClassRealm().loadClass(className); + // boolean hasQualifier = Stream.of(clazz.getAnnotations()) + // .flatMap(ann -> Stream.of(ann.getClass().getAnnotations())) + // .anyMatch(ann -> "org.apache.maven.api.di.Qualifier" + // .equals(ann.annotationType().getName())); + // if (hasQualifier) { + // diBeans.add(className); + // } + } + } + Path path = outputDirectory.toPath().resolve("org.apache.maven.api.di.Inject"); + if (diBeans.isEmpty()) { + Files.deleteIfExists(path); + } else { + try (CachingWriter w = new CachingWriter(path, StandardCharsets.UTF_8)) { + String content = diBeans.stream().collect(Collectors.joining("\n", "", "\n")); Review Comment: `System.lineSeparator()`? ########## maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java: ########## @@ -78,6 +90,12 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo { @Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/maven", readonly = true) private File outputDirectory; + /** + * The directory where the generated class files will be put. + */ + @Parameter(defaultValue = "${project.build.outputDirectory}", readonly = true) + private File classOutputDirectory; Review Comment: `classesOutputDirectory`? > Upgrade to Maven 4.x > -------------------- > > Key: MPLUGIN-508 > URL: https://issues.apache.org/jira/browse/MPLUGIN-508 > Project: Maven Plugin Tools > Issue Type: New Feature > Affects Versions: 3.12.0 > Reporter: Guillaume Nodet > Assignee: Guillaume Nodet > Priority: Major > Fix For: 4.0.0 > > -- This message was sent by Atlassian Jira (v8.20.10#820010)