...
 
Commits (3)
/target/
.idea/
*.iml
......@@ -4,12 +4,13 @@
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.32</version>
<version>1.37</version>
<relativePath />
</parent>
<artifactId>annotation-indexer</artifactId>
<name>Annotation Indexer</name>
<version>1.9</version>
<version>1.12</version>
<description>
Creates index of annotations.
</description>
......@@ -18,7 +19,7 @@
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.5</version>
<version>1.7</version>
<optional>true</optional>
</dependency>
<dependency>
......@@ -38,6 +39,7 @@
<scm>
<connection>scm:git:git://github.com/jenkinsci/lib-${project.artifactId}.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/lib-${project.artifactId}.git</developerConnection>
<tag>annotation-indexer-1.12</tag>
</scm>
<licenses>
......
......@@ -6,8 +6,7 @@ import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import static javax.lang.model.SourceVersion.RELEASE_6;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
......@@ -35,7 +34,6 @@ import java.util.TreeSet;
*
* @author Kohsuke Kawaguchi
*/
@SupportedSourceVersion(RELEASE_6)
@SupportedAnnotationTypes("*")
@SuppressWarnings({"Since15"})
@MetaInfServices(Processor.class)
......@@ -111,6 +109,8 @@ public class AnnotationProcessorImpl extends AbstractProcessor {
}
} catch (FileNotFoundException x) {
// OK, created for the first time
} catch (java.nio.file.NoSuchFileException x) {
// OK, created for the first time
}
return elements;
}
......@@ -141,12 +141,18 @@ public class AnnotationProcessorImpl extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver() || roundEnv.errorRaised())
// TODO we should not write until processingOver
return false;
execute(annotations, roundEnv);
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
protected void execute(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// map from indexable annotation names, to actual uses
Map<String,Use> output = new HashMap<String,Use>();
......
......@@ -107,6 +107,8 @@ public class Index {
LOGGER.log(Level.FINE, "Failed to load: "+name,e);
} catch (LinkageError x) {
LOGGER.log(Level.WARNING, "Failed to load " + name, x);
} catch (RuntimeException x) {
LOGGER.log(Level.WARNING, "Failed to load " + name, x);
}
}
}
......
......@@ -27,8 +27,8 @@ public class AnnotationProcessorImplTest {
addLine("package some.pkg;").
addLine("@some.api.A public class Stuff {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterSupportedSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/annotations/some.api.A"));
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/some.api.A"));
}
@Indexed @Retention(RetentionPolicy.RUNTIME) public @interface A {}
......@@ -38,8 +38,8 @@ public class AnnotationProcessorImplTest {
addLine("package some.pkg;").
addLine("@" + A.class.getCanonicalName() + " public class Stuff {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterSupportedSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
}
@Test public void incremental() {
......@@ -48,15 +48,15 @@ public class AnnotationProcessorImplTest {
addLine("package some.pkg;").
addLine("@" + A.class.getCanonicalName() + " public class Stuff {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterSupportedSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
compilation = new Compilation(compilation);
compilation.addSource("some.pkg.MoreStuff").
addLine("package some.pkg;").
addLine("@" + A.class.getCanonicalName() + " public class MoreStuff {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterSupportedSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.MoreStuff\nsome.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.MoreStuff" + System.getProperty("line.separator") + "some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
}
@Indexed @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface B {}
......@@ -67,7 +67,7 @@ public class AnnotationProcessorImplTest {
addLine("package some.pkg;").
addLine("public class Stuff extends " + Super.class.getCanonicalName() + " {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterSupportedSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
/* XXX #7188605 currently broken on JDK 6; perhaps need to use a ElementScanner6 on roundEnv.rootElements whose visitType checks for annotations
assertEquals("some.pkg.Stuff\n", Utils.getGeneratedResource(compilation, "META-INF/annotations/" + B.class.getName()));
*/
......
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
......@@ -20,21 +21,30 @@ import net.java.dev.hickory.testing.Compilation;
// XXX partial copy of class from Stapler; should be pushed up into Hickory ASAP
class Utils {
/**
* Filter out warnings about {@link SupportedSourceVersion}.
* {@code metainf-services-1.1.jar} produces {@code warning: No SupportedSourceVersion annotation found on org.kohsuke.metainf_services.AnnotationProcessorImpl, returning RELEASE_6.} which is irrelevant to us.
* (Development versions have already fixed this; when released and used here, delete this method.)
*/
public static List<Diagnostic<? extends JavaFileObject>> filterSupportedSourceVersionWarnings(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
// Filter out warnings about source 1.6 is obsolete in java 9
// This usually appears with other warnings
public static final List<String> IGNORE = Arrays.asList(
"source value 1.6 is obsolete and will be removed in a future release", // Filter out warnings about source 1.6 is obsolete in java 9
"To suppress warnings about obsolete options" // This usually appears with other warnings
);
public static List<Diagnostic<? extends JavaFileObject>> filterObsoleteSourceVersionWarnings(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
List<Diagnostic<? extends JavaFileObject>> r = new ArrayList<Diagnostic<? extends JavaFileObject>>();
for (Diagnostic<? extends JavaFileObject> d : diagnostics) {
if (!d.getMessage(Locale.ENGLISH).contains("SupportedSourceVersion")) {
if (!isIgnored(d.getMessage(Locale.ENGLISH))) {
r.add(d);
}
}
return r;
}
private static boolean isIgnored(String message) {
for (String i : IGNORE) {
if (message.contains(i)) return true;
}
return false;
}
private static JavaFileManager fileManager(Compilation compilation) {
try {
Field f = Compilation.class.getDeclaredField("jfm");
......