Skip to content

Commit

Permalink
[JENKINS-66247] Call Index.listClassNames
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jul 29, 2021
1 parent 762976d commit 2788ba4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>org.jenkins-ci</groupId>
<artifactId>annotation-indexer</artifactId>
<version>1.14</version>
<version>1.15-SNAPSHOT</version> <!-- TODO https://github.com/jenkinsci/lib-annotation-indexer/pull/12 -->
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import org.jvnet.hudson.annotation_indexer.Index;

/**
* @author Kohsuke Kawaguchi
Expand All @@ -50,28 +50,14 @@ public class ProcessMojo extends AbstractMojo {
private File classesDirectory;

public void execute() throws MojoExecutionException, MojoFailureException {
File index = new File(classesDirectory, "META-INF/services/annotations/" + WithBridgeMethods.class.getName());
if (!index.exists()) {
getLog().debug("Skipping because there's no "+index);
return;
}

BufferedReader r = null;
try {
r = new BufferedReader(new InputStreamReader(new FileInputStream(index),"UTF-8"));
String line;
while ((line=r.readLine())!=null) {
for (String line : Index.listClassNames(WithBridgeMethods.class, new URLClassLoader(new URL[] {classesDirectory.toURI().toURL()}, ClassLoader.getSystemClassLoader().getParent()))) {
File classFile = new File(classesDirectory,line.replace('.','/')+".class");
getLog().debug("Processing "+line);
new MethodInjector().handle(classFile);
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to process @WithBridgeMethods",e);
} finally {
try {
if (r!=null) r.close();
} catch (IOException _) {
}
}
}
}

0 comments on commit 2788ba4

Please sign in to comment.