Skip to content

Commit 22ec826

Browse files
committed
[MCOMPILER-540] Add test case
1 parent 0b8b00b commit 22ec826

File tree

8 files changed

+367
-0
lines changed

8 files changed

+367
-0
lines changed

src/it/MCOMPILER-540/code/pom.xml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>foo</groupId>
25+
<artifactId>bar</artifactId>
26+
<version>${revision}</version>
27+
</parent>
28+
<version>${revision}</version>
29+
<packaging>jar</packaging>
30+
<artifactId>code</artifactId>
31+
32+
<build>
33+
<pluginManagement>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-antrun-plugin</artifactId>
38+
<version>3.1.0</version>
39+
</plugin>
40+
</plugins>
41+
</pluginManagement>
42+
</build>
43+
44+
<profiles>
45+
<profile>
46+
<id>actualBuild</id>
47+
<dependencies>
48+
<dependency>
49+
<groupId>foo</groupId>
50+
<artifactId>processor</artifactId>
51+
<version>${revision}</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
</dependencies>
55+
</profile>
56+
57+
<profile>
58+
<id>touchFiles</id>
59+
<activation>
60+
<activeByDefault>false</activeByDefault>
61+
</activation>
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-antrun-plugin</artifactId>
67+
<executions>
68+
<execution>
69+
<id>touch-gen-src</id>
70+
<goals>
71+
<goal>run</goal>
72+
</goals>
73+
<phase>validate</phase>
74+
<configuration>
75+
<target>
76+
<touch file="${basedir}/target/generated-sources/annotations/bar/MyGeneratedClass.java"/>
77+
<touch file="${project.build.sourceDirectory}/bar/MyAnnotatedClass.java"/>
78+
</target>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
</plugins>
84+
</build>
85+
</profile>
86+
</profiles>
87+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package bar;
20+
21+
import foo.MyAnnotation;
22+
23+
@MyAnnotation
24+
public class MyAnnotatedClass {
25+
MyGeneratedClass generatedClass = new MyGeneratedClass();
26+
27+
// foo
28+
29+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# NOTE: The first time, we run up to "integration-test" phase which includes the AntRun execution which saves the
19+
# timestamp of the first JAR for comparison with the timestamp of the JAR from the final "package" invocation.
20+
# Note:
21+
invoker.goals.1 = clean compile -PactualBuild
22+
invoker.goals.2 = validate -PtouchFiles
23+
invoker.goals.3 = compile -PactualBuild

src/it/MCOMPILER-540/pom.xml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
22+
<modelVersion>4.0.0</modelVersion>
23+
<groupId>foo</groupId>
24+
<artifactId>bar</artifactId>
25+
<version>${revision}</version>
26+
<packaging>pom</packaging>
27+
28+
<properties>
29+
<revision>1.0-SNAPSHOT</revision>
30+
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
<modules>
35+
<module>processor</module>
36+
<module>code</module>
37+
</modules>
38+
39+
<build>
40+
<pluginManagement>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>@project.version@</version>
46+
</plugin>
47+
</plugins>
48+
</pluginManagement>
49+
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<configuration>
55+
<encoding>UTF-8</encoding>
56+
<showWarnings>true</showWarnings>
57+
<showDeprecation>true</showDeprecation>
58+
<fork>true</fork> <!-- Change this to false and the Diagnostic.Kind.NOTE messages show up -->
59+
<useIncrementalCompilation>false</useIncrementalCompilation>
60+
<compilerArgs combine.children="append">
61+
<arg>-Xlint:all,-processing</arg>
62+
<arg>-Xdoclint:all,-missing,-accessibility</arg>
63+
<arg>-Xmaxerrs</arg>
64+
<arg>2147483647</arg>
65+
<arg>-Xmaxwarns</arg>
66+
<arg>2147483647</arg>
67+
</compilerArgs>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
</project>
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>foo</groupId>
25+
<artifactId>bar</artifactId>
26+
<version>${revision}</version>
27+
</parent>
28+
<version>${revision}</version>
29+
<artifactId>processor</artifactId>
30+
<packaging>jar</packaging>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-compiler-plugin</artifactId>
37+
<configuration>
38+
<proc>none</proc>
39+
</configuration>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package foo;
20+
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
@Retention(RetentionPolicy.SOURCE)
27+
@Target(ElementType.TYPE)
28+
public @interface MyAnnotation {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package foo;
20+
21+
import javax.annotation.processing.*;
22+
import javax.lang.model.SourceVersion;
23+
import javax.lang.model.element.TypeElement;
24+
import javax.tools.Diagnostic;
25+
import javax.tools.JavaFileObject;
26+
27+
import java.io.IOException;
28+
import java.io.Writer;
29+
import java.util.Set;
30+
31+
@SupportedAnnotationTypes("foo.MyAnnotation")
32+
public class MyProcessor extends AbstractProcessor {
33+
34+
private int procRun = 0;
35+
36+
@Override
37+
public SourceVersion getSupportedSourceVersion() {
38+
return SourceVersion.latestSupported();
39+
}
40+
41+
@Override
42+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
43+
try {
44+
generate(annotations, roundEnv);
45+
} catch (IOException e) {
46+
throw new RuntimeException(e);
47+
}
48+
49+
return false;
50+
}
51+
52+
private void generate(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws IOException {
53+
Messager msg = processingEnv.getMessager();
54+
msg.printMessage(Diagnostic.Kind.NOTE, String.format("[%d]: Hello Info", procRun));
55+
msg.printMessage(Diagnostic.Kind.WARNING, String.format("[%d]: Hello Warning", procRun));
56+
procRun++;
57+
58+
if (procRun > 1) {
59+
return;
60+
}
61+
62+
JavaFileObject file = processingEnv.getFiler().createSourceFile("bar.MyGeneratedClass");
63+
try (Writer writer = file.openWriter()) {
64+
writer.write("package bar;\npublic class MyGeneratedClass {}");
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
foo.MyProcessor

0 commit comments

Comments
 (0)