diff --git a/src/it/MCOMPILER-538/code/MyAnnotatedClass.bad.java b/src/it/MCOMPILER-538/code/MyAnnotatedClass.bad.java new file mode 100644 index 00000000..765cd64c --- /dev/null +++ b/src/it/MCOMPILER-538/code/MyAnnotatedClass.bad.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bar; + +import foo.MyAnnotation; + +@MyAnnotation +public class MyAnnotatedClass { + MyGeneratedClass generatedClass = new MyGeneratedClass(false); + + // foo + +} diff --git a/src/it/MCOMPILER-538/code/MyAnnotatedClass.good.java b/src/it/MCOMPILER-538/code/MyAnnotatedClass.good.java new file mode 100644 index 00000000..cc4126d8 --- /dev/null +++ b/src/it/MCOMPILER-538/code/MyAnnotatedClass.good.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bar; + +import foo.MyAnnotation; + +@MyAnnotation +public class MyAnnotatedClass { + MyGeneratedClass generatedClass = new MyGeneratedClass(); + + // foo + +} diff --git a/src/it/MCOMPILER-538/code/pom.xml b/src/it/MCOMPILER-538/code/pom.xml new file mode 100644 index 00000000..2dd9744f --- /dev/null +++ b/src/it/MCOMPILER-538/code/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + foo + bar + ${revision} + + ${revision} + jar + code + + + + foo + processor + ${revision} + provided + + + + + + + com.kohlschutter.mavenplugins + copy-rename-maven-plugin + 2.0.0 + + + set-source + generate-sources + + copy + + + + + ${basedir}/MyAnnotatedClass.${it.type}.java + ${basedir}/src/main/java/bar/MyAnnotatedClass.java + + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + @version.maven-clean-plugin@ + + + clean-source-file + validate + + clean + + + true + + + src/main/java + + package-info.java + + + + + + + + + + diff --git a/src/it/MCOMPILER-538/code/src/main/java/bar/.gitignore b/src/it/MCOMPILER-538/code/src/main/java/bar/.gitignore new file mode 100644 index 00000000..ebce081a --- /dev/null +++ b/src/it/MCOMPILER-538/code/src/main/java/bar/.gitignore @@ -0,0 +1 @@ +MyAnnotatedClass.java diff --git a/src/it/MCOMPILER-538/code/src/main/java/bar/package-info.java b/src/it/MCOMPILER-538/code/src/main/java/bar/package-info.java new file mode 100644 index 00000000..0dde32fa --- /dev/null +++ b/src/it/MCOMPILER-538/code/src/main/java/bar/package-info.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package bar; diff --git a/src/it/MCOMPILER-538/invoker.properties b/src/it/MCOMPILER-538/invoker.properties new file mode 100644 index 00000000..0a3163aa --- /dev/null +++ b/src/it/MCOMPILER-538/invoker.properties @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# NOTE: The first time, we run up to "integration-test" phase which includes the AntRun execution which saves the +# timestamp of the first JAR for comparison with the timestamp of the JAR from the final "package" invocation. +# Note: +invoker.goals.1 = clean +invoker.goals.2 = compile -Dit.type=bad -Dmaven.compiler.failOnError=false +invoker.goals.3 = compile -Dit.type=good diff --git a/src/it/MCOMPILER-538/pom.xml b/src/it/MCOMPILER-538/pom.xml new file mode 100644 index 00000000..3518ae9d --- /dev/null +++ b/src/it/MCOMPILER-538/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + foo + bar + ${revision} + pom + + + 1.0-SNAPSHOT + + UTF-8 + + + + processor + code + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + UTF-8 + 17 + 17 + true + true + true + false + + -Xlint:all,-processing + -Xdoclint:all,-missing,-accessibility + -Xmaxerrs + 2147483647 + -Xmaxwarns + 2147483647 + + + + + + diff --git a/src/it/MCOMPILER-538/processor/pom.xml b/src/it/MCOMPILER-538/processor/pom.xml new file mode 100644 index 00000000..744ac5d0 --- /dev/null +++ b/src/it/MCOMPILER-538/processor/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + foo + bar + ${revision} + + ${revision} + processor + jar + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + none + + + + + diff --git a/src/it/MCOMPILER-538/processor/src/main/java/foo/MyAnnotation.java b/src/it/MCOMPILER-538/processor/src/main/java/foo/MyAnnotation.java new file mode 100644 index 00000000..88431aef --- /dev/null +++ b/src/it/MCOMPILER-538/processor/src/main/java/foo/MyAnnotation.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package foo; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.TYPE) +public @interface MyAnnotation {} diff --git a/src/it/MCOMPILER-538/processor/src/main/java/foo/MyProcessor.java b/src/it/MCOMPILER-538/processor/src/main/java/foo/MyProcessor.java new file mode 100644 index 00000000..b000e2de --- /dev/null +++ b/src/it/MCOMPILER-538/processor/src/main/java/foo/MyProcessor.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package foo; + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.JavaFileObject; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +@SupportedSourceVersion(SourceVersion.RELEASE_17) +@SupportedAnnotationTypes("foo.MyAnnotation") +public class MyProcessor extends AbstractProcessor { + + private int procRun = 0; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + try { + generate(annotations, roundEnv); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return false; + } + + private void generate(Set annotations, RoundEnvironment roundEnv) throws IOException { + Messager msg = processingEnv.getMessager(); + msg.printMessage(Diagnostic.Kind.NOTE, String.format("[%d]: Hello Info", procRun)); + msg.printMessage(Diagnostic.Kind.WARNING, String.format("[%d]: Hello Warning", procRun)); + procRun++; + + if (procRun > 1) { + return; + } + + JavaFileObject file = processingEnv.getFiler().createSourceFile("bar.MyGeneratedClass"); + try (Writer writer = file.openWriter()) { + writer.write( + """ + package bar; + + public class MyGeneratedClass { + } + """); + } + } +} diff --git a/src/it/MCOMPILER-538/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/it/MCOMPILER-538/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 00000000..678af7ba --- /dev/null +++ b/src/it/MCOMPILER-538/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +foo.MyProcessor