Skip to content

Commit 373f359

Browse files
committed
[MCOMPILER-540] Add test case
1 parent fdebd58 commit 373f359

File tree

8 files changed

+385
-0
lines changed

8 files changed

+385
-0
lines changed

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

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
<dependencies>
33+
<dependency>
34+
<groupId>foo</groupId>
35+
<artifactId>processor</artifactId>
36+
<version>${revision}</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<pluginManagement>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.honton.chas</groupId>
46+
<artifactId>touch-maven-plugin</artifactId>
47+
<version>0.0.3</version>
48+
</plugin>
49+
</plugins>
50+
</pluginManagement>
51+
</build>
52+
53+
<profiles>
54+
<profile>
55+
<id>touchFiles</id>
56+
<activation>
57+
<activeByDefault>false</activeByDefault>
58+
</activation>
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.honton.chas</groupId>
63+
<artifactId>touch-maven-plugin</artifactId>
64+
<executions>
65+
<execution>
66+
<id>touch-gen-src</id>
67+
<goals>
68+
<goal>touch</goal>
69+
</goals>
70+
<phase>validate</phase>
71+
<configuration>
72+
<files>
73+
<directory>${basedir}/target/generated-sources/annotations/bar</directory>
74+
<includes>
75+
<include>MyGeneratedClass.java</include>
76+
</includes>
77+
</files>
78+
</configuration>
79+
</execution>
80+
<execution>
81+
<id>touch-src</id>
82+
<goals>
83+
<goal>touch</goal>
84+
</goals>
85+
<phase>validate</phase>
86+
<configuration>
87+
<files>
88+
<directory>${project.build.sourceDirectory}/bar</directory>
89+
<includes>
90+
<include>MyAnnotatedClass.java</include>
91+
</includes>
92+
</files>
93+
</configuration>
94+
</execution>
95+
</executions>
96+
</plugin>
97+
</plugins>
98+
</build>
99+
</profile>
100+
</profiles>
101+
</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
22+
invoker.goals.2 = validate -PtouchFiles
23+
invoker.goals.3 = compile

src/it/MCOMPILER-540/pom.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
<source>17</source>
57+
<target>17</target>
58+
<showWarnings>true</showWarnings>
59+
<showDeprecation>true</showDeprecation>
60+
<fork>true</fork> <!-- Change this to false and the Diagnostic.Kind.NOTE messages show up -->
61+
<useIncrementalCompilation>false</useIncrementalCompilation>
62+
<compilerArgs combine.children="append">
63+
<arg>-Xlint:all,-processing</arg>
64+
<arg>-Xdoclint:all,-missing,-accessibility</arg>
65+
<arg>-Xmaxerrs</arg>
66+
<arg>2147483647</arg>
67+
<arg>-Xmaxwarns</arg>
68+
<arg>2147483647</arg>
69+
</compilerArgs>
70+
</configuration>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</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,69 @@
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+
@SupportedSourceVersion(SourceVersion.RELEASE_17)
32+
@SupportedAnnotationTypes("foo.MyAnnotation")
33+
public class MyProcessor extends AbstractProcessor {
34+
35+
private int procRun = 0;
36+
37+
@Override
38+
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
39+
try {
40+
generate(annotations, roundEnv);
41+
} catch (IOException e) {
42+
throw new RuntimeException(e);
43+
}
44+
45+
return false;
46+
}
47+
48+
private void generate(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws IOException {
49+
Messager msg = processingEnv.getMessager();
50+
msg.printMessage(Diagnostic.Kind.NOTE, String.format("[%d]: Hello Info", procRun));
51+
msg.printMessage(Diagnostic.Kind.WARNING, String.format("[%d]: Hello Warning", procRun));
52+
procRun++;
53+
54+
if (procRun > 1) {
55+
return;
56+
}
57+
58+
JavaFileObject file = processingEnv.getFiler().createSourceFile("bar.MyGeneratedClass");
59+
try (Writer writer = file.openWriter()) {
60+
writer.write(
61+
"""
62+
package bar;
63+
64+
public class MyGeneratedClass {
65+
}
66+
""");
67+
}
68+
}
69+
}
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)