Skip to content

Commit 19acfb8

Browse files
committed
Add an integration test for the annotation processor
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 2db381b commit 19acfb8

File tree

8 files changed

+329
-0
lines changed

8 files changed

+329
-0
lines changed

pom.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,43 @@
155155
<url>https://github.com/scijava/annindex</url>
156156
</scm>
157157

158+
<profiles>
159+
<profile>
160+
<id>run-its</id>
161+
<build>
162+
<defaultGoal>integration-test</defaultGoal>
163+
<plugins>
164+
<plugin>
165+
<artifactId>maven-invoker-plugin</artifactId>
166+
<version>1.8</version>
167+
<configuration>
168+
<debug>${invoker.debug}</debug>
169+
<showErrors>true</showErrors>
170+
<streamLogs>true</streamLogs>
171+
<projectsDirectory>src/it</projectsDirectory>
172+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
173+
<pomIncludes>
174+
<pomInclude>*/pom.xml</pomInclude>
175+
</pomIncludes>
176+
<settingsFile>src/it/settings.xml</settingsFile>
177+
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
178+
<preBuildHookScript>setup.bsh</preBuildHookScript>
179+
<postBuildHookScript>verify.bsh</postBuildHookScript>
180+
</configuration>
181+
<executions>
182+
<execution>
183+
<id>integration-test</id>
184+
<goals>
185+
<goal>install</goal>
186+
<goal>run</goal>
187+
</goals>
188+
</execution>
189+
</executions>
190+
</plugin>
191+
</plugins>
192+
</build>
193+
</profile>
194+
</profiles>
195+
158196
</project>
159197

src/it/apt-test/pom.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
#%L
4+
Annotation index (processor and index access library).
5+
%%
6+
Copyright (C) 2009 - 2013 Board of Regents of the University of Wisconsin-Madison.
7+
%%
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are met:
10+
11+
1. Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
2. Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
POSSIBILITY OF SUCH DAMAGE.
28+
29+
The views and conclusions contained in the software and documentation are
30+
those of the authors and should not be interpreted as representing official
31+
policies, either expressed or implied, of any organization.
32+
#L%
33+
-->
34+
35+
<project xmlns="http://maven.apache.org/POM/4.0.0"
36+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
37+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
38+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
39+
<modelVersion>4.0.0</modelVersion>
40+
41+
<groupId>@project.groupId@</groupId>
42+
<artifactId>apt-test</artifactId>
43+
<version>@project.version@</version>
44+
45+
<name>An integration test for the annotation processor</name>
46+
<description>This integration makes sure that the annotations are properly processed and indexed at compilation time.</description>
47+
48+
<properties>
49+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
50+
</properties>
51+
52+
<dependencies>
53+
<dependency>
54+
<groupId>@project.groupId@</groupId>
55+
<artifactId>@project.artifactId@</artifactId>
56+
<version>@project.version@</version>
57+
</dependency>
58+
</dependencies>
59+
60+
</project>
61+

src/it/apt-test/setup.bsh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.io.File;
2+
3+
assertTrue(message, condition) {
4+
if (!condition) {
5+
throw new Exception(message);
6+
}
7+
}
8+
9+
rmRF(directory) {
10+
list = directory.listFiles();
11+
for (i = 0; list != null && i < list.length; i++) {
12+
if ((list[i].isFile() && !list[i].delete()) ||
13+
(list[i].isDirectory() && !rmRF(list[i]))) {
14+
print("Could not delete " + list[i]);
15+
return false;
16+
}
17+
}
18+
return directory.delete();
19+
}
20+
21+
metaInf = new File(basedir, "target/classes/META-INF");
22+
23+
assertTrue("Could not delete META-INF/", !metaInf.isDirectory() || rmRF(metaInf));
24+
print("Setup completed");
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* #%L
3+
* Annotation index (processor and index access library).
4+
* %%
5+
* Copyright (C) 2009 - 2013 Board of Regents of the University of Wisconsin-Madison.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* The views and conclusions contained in the software and documentation are
29+
* those of the authors and should not be interpreted as representing official
30+
* policies, either expressed or implied, of any organization.
31+
* #L%
32+
*/
33+
package org.scijava.annotations.its;
34+
35+
/**
36+
* An annotated class, to be indexed in the integration test
37+
*
38+
* @author Johannes Schindelin
39+
*/
40+
@CustomAnnotation(greeting = "Hey, what's up, doc?")
41+
public class Annotated { }
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* #%L
3+
* Annotation index (processor and index access library).
4+
* %%
5+
* Copyright (C) 2009 - 2013 Board of Regents of the University of Wisconsin-Madison.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* The views and conclusions contained in the software and documentation are
29+
* those of the authors and should not be interpreted as representing official
30+
* policies, either expressed or implied, of any organization.
31+
* #L%
32+
*/
33+
package org.scijava.annotations.its;
34+
35+
import java.lang.annotation.ElementType;
36+
import java.lang.annotation.Retention;
37+
import java.lang.annotation.RetentionPolicy;
38+
import java.lang.annotation.Target;
39+
40+
import org.scijava.annotations.Indexable;
41+
42+
/**
43+
* A simple annotation for use in the integration test.
44+
*
45+
* @author Johannes Schindelin
46+
*/
47+
@Retention(RetentionPolicy.RUNTIME)
48+
@Target({ElementType.TYPE})
49+
@Indexable
50+
public @interface CustomAnnotation {
51+
52+
String greeting() default "Hello, World!";
53+
54+
}
55+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"org.scijava.annotations.its.Annotated","values":{"greeting":"Hey, what's up, doc?"}}

src/it/apt-test/verify.bsh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.BufferedReader;
2+
import java.io.File;
3+
import java.io.FileReader;
4+
5+
assertTrue(message, condition) {
6+
if (!condition) {
7+
throw new Exception(message);
8+
}
9+
}
10+
11+
assertEquals(a, b) {
12+
if (a !=b && (a == null || !a.equals(b))) {
13+
throw new Exception("Not equal: " + a + " != " + b);
14+
}
15+
}
16+
17+
readAsString(file) {
18+
builder = new StringBuilder();
19+
reader = new BufferedReader(new FileReader(file));
20+
for (;;) {
21+
line = reader.readLine();
22+
if (line == null) {
23+
break;
24+
}
25+
if (builder.length() > 0) {
26+
builder.append('\n');
27+
}
28+
builder.append(line);
29+
}
30+
reader.close();
31+
return builder.toString();
32+
}
33+
34+
annotationIndex = new File(basedir,
35+
"target/classes/META-INF/json/org.scijava.annotations.its.CustomAnnotation");
36+
37+
assertTrue("File does not exist: " + annotationIndex, annotationIndex.exists());
38+
39+
expect = readAsString(new File(basedir, "src/test/resources/expect"));
40+
actual = readAsString(annotationIndex);
41+
assertEquals(expect, actual);

src/it/settings.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
#%L
4+
Annotation index (processor and index access library).
5+
%%
6+
Copyright (C) 2009 - 2013 Board of Regents of the University of Wisconsin-Madison.
7+
%%
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are met:
10+
11+
1. Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
2. Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
POSSIBILITY OF SUCH DAMAGE.
28+
29+
The views and conclusions contained in the software and documentation are
30+
those of the authors and should not be interpreted as representing official
31+
policies, either expressed or implied, of any organization.
32+
#L%
33+
-->
34+
35+
<settings>
36+
<profiles>
37+
<profile>
38+
<id>it-repo</id>
39+
<activation>
40+
<activeByDefault>true</activeByDefault>
41+
</activation>
42+
<repositories>
43+
<repository>
44+
<id>local.central</id>
45+
<url>@localRepositoryUrl@</url>
46+
<releases>
47+
<enabled>true</enabled>
48+
</releases>
49+
<snapshots>
50+
<enabled>true</enabled>
51+
</snapshots>
52+
</repository>
53+
</repositories>
54+
<pluginRepositories>
55+
<pluginRepository>
56+
<id>local.central</id>
57+
<url>@localRepositoryUrl@</url>
58+
<releases>
59+
<enabled>true</enabled>
60+
</releases>
61+
<snapshots>
62+
<enabled>true</enabled>
63+
</snapshots>
64+
</pluginRepository>
65+
</pluginRepositories>
66+
</profile>
67+
</profiles>
68+
</settings>

0 commit comments

Comments
 (0)