Skip to content
Commits on Source (6)
_extends: .github
tag-template: annotation-indexer-$NEXT_MINOR_VERSION
# Annotation Indexer library
The library creates an index of annotations which can be then accessed by other components.
It is used inside the [Jenkins project](http://jenkins.io), but it can be also used in other projects.
## Javadoc
To be published soon, see https://github.com/jenkins-infra/javadoc/pull/22
## Changelog
For version 1.13 and above, see [GitHub Releases](https://github.com/jenkinsci/lib-annotation-indexer/releases)
annotation-indexer (1.13-1) unstable; urgency=medium
* Team upload.
* New upstream release
- Set the compatibility level to Java 8
* Standards-Version updated to 4.5.0
* Removed the javadoc package
-- Emmanuel Bourg <ebourg@apache.org> Mon, 27 Jan 2020 10:09:11 +0100
annotation-indexer (1.12-1) unstable; urgency=medium
* Team upload.
......
......@@ -6,14 +6,11 @@ Uploaders: James Page <james.page@ubuntu.com>
Build-Depends:
debhelper (>= 11),
default-jdk,
default-jdk-doc,
junit4,
libmaven-compiler-plugin-java,
libmaven-javadoc-plugin-java,
libmetainf-services-java,
libmetainf-services-java-doc,
maven-debian-helper
Standards-Version: 4.1.4
Standards-Version: 4.5.0
Vcs-Git: https://salsa.debian.org/java-team/annotation-indexer.git
Vcs-Browser: https://salsa.debian.org/java-team/annotation-indexer
Homepage: https://github.com/jenkinsci/lib-annotation-indexer
......@@ -27,20 +24,3 @@ Description: Indexing and validation of Java annotations
with the @Indexed annotation at compile time and supports
validation of indexes to allow for early error detection and
querying of the indexed elements for specific annotations.
Package: libannotation-indexer-java-doc
Architecture: all
Section: doc
Depends:
default-jdk-doc,
libmetainf-services-java-doc,
${maven:DocDepends},
${misc:Depends}
Suggests: libannotation-indexer-java
Description: Documentation for libannotation-indexer-java
Annotation Indexer builds indices of Java code annotated
with the @Indexed annotation at compile time and supports
validation of indexes to allow for early error detection and
querying of the indexed elements for specific annotations.
.
This package provides the API documentation for libannotation-indexer-java.
Document: libannotation-indexer-java
Title: API Javadoc for annotation-indexer
Author: annotation-indexer developers
Abstract: This is the API Javadoc provided for the
libannotation-indexer-java library.
Section: Programming
Format: HTML
Index: /usr/share/doc/libannotation-indexer-java/api/index.html
Files: /usr/share/doc/libannotation-indexer-java/api/*
target/apidocs/* usr/share/doc/libannotation-indexer-java/api
......@@ -3,3 +3,5 @@
# maven.test.skip=true
maven.test.skip=true
maven.compiler.release=8
......@@ -4,22 +4,27 @@
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.37</version>
<version>1.46</version>
<relativePath />
</parent>
<artifactId>annotation-indexer</artifactId>
<name>Annotation Indexer</name>
<version>1.12</version>
<version>1.13</version>
<description>
Creates index of annotations.
</description>
<properties>
<java.level>8</java.level>
<java.level.test>8</java.level.test>
</properties>
<dependencies>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.7</version>
<version>1.8</version>
<optional>true</optional>
</dependency>
<dependency>
......@@ -39,7 +44,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>
<tag>annotation-indexer-1.13</tag>
</scm>
<licenses>
......
......@@ -9,6 +9,7 @@ import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic.Kind;
......@@ -80,6 +81,10 @@ public class AnnotationProcessorImpl extends AbstractProcessor {
case CONSTRUCTOR:
t = (TypeElement) elt.getEnclosingElement();
break;
case PACKAGE:
classes.add(((PackageElement)elt).getQualifiedName().toString()+".*");
return;
default:
// throw new AssertionError(elt.getKind());
return;
......
......@@ -45,15 +45,13 @@ public class Index {
final Enumeration<URL> res = cl.getResources("META-INF/annotations/"+type.getName());
while (res.hasMoreElements()) {
URL url = res.nextElement();
InputStream is = url.openStream();
try {
BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
try (InputStream is = url.openStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
while ((line = r.readLine()) != null) {
ids.add(line);
}
} finally {
is.close();
}
}
......@@ -96,6 +94,11 @@ public class Index {
String name = iditr.next();
try {
if (name.endsWith(".*")) {
final Package p = Package.getPackage(name.substring(0, name.length() - 2));
lookaheads.add(p);
}
Class<?> c = cl.loadClass(name);
if (c.isAnnotationPresent(type))
......
package org.jvnet.hudson.annotation_indexer;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
......@@ -26,7 +27,7 @@ public class AnnotationProcessorImplTest {
compilation.addSource("some.pkg.Stuff").
addLine("package some.pkg;").
addLine("@some.api.A public class Stuff {}");
compilation.doCompile(null, "-source", "6");
compilation.doCompile(null, "-source", "8");
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/some.api.A"));
}
......@@ -37,7 +38,7 @@ public class AnnotationProcessorImplTest {
compilation.addSource("some.pkg.Stuff").
addLine("package some.pkg;").
addLine("@" + A.class.getCanonicalName() + " public class Stuff {}");
compilation.doCompile(null, "-source", "6");
compilation.doCompile(null, "-source", "8");
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
}
......@@ -47,14 +48,14 @@ public class AnnotationProcessorImplTest {
compilation.addSource("some.pkg.Stuff").
addLine("package some.pkg;").
addLine("@" + A.class.getCanonicalName() + " public class Stuff {}");
compilation.doCompile(null, "-source", "6");
compilation.doCompile(null, "-source", "8");
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");
compilation.doCompile(null, "-source", "8");
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()));
}
......@@ -66,7 +67,7 @@ public class AnnotationProcessorImplTest {
compilation.addSource("some.pkg.Stuff").
addLine("package some.pkg;").
addLine("public class Stuff extends " + Super.class.getCanonicalName() + " {}");
compilation.doCompile(null, "-source", "6");
compilation.doCompile(null, "-source", "8");
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()));
......@@ -109,4 +110,13 @@ public class AnnotationProcessorImplTest {
assertFalse(it.hasNext());
}
@Indexed @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PACKAGE) public @interface OnPackage {}
@Test public void packageinfo() throws IOException {
Iterator<AnnotatedElement> it = Index.list(OnPackage.class, Stuff.class.getClassLoader()).iterator();
assertTrue(it.hasNext());
final Package p = (Package) it.next();
assertEquals("org.jvnet.hudson.annotation_indexer", p.getName());
}
}
......@@ -24,8 +24,7 @@ class Utils {
// 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
"RELEASE_6" // Filter out warnings about source 1.6 is obsolete in java 9+
);
public static List<Diagnostic<? extends JavaFileObject>> filterObsoleteSourceVersionWarnings(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
......
@AnnotationProcessorImplTest.OnPackage
package org.jvnet.hudson.annotation_indexer;