[ https://issues.apache.org/jira/browse/MPLUGIN-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17850816#comment-17850816 ]
ASF GitHub Bot commented on MPLUGIN-508: ---------------------------------------- gnodet commented on code in PR #286: URL: https://github.com/apache/maven-plugin-tools/pull/286#discussion_r1621196292 ########## 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: Fixed ########## 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: Fixed > 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)