From eb7840cf9f0d29c1cf805c5aec180f7f78e454ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Tue, 19 Dec 2023 01:27:52 +0100 Subject: [PATCH] [MCOMPILER-567] - Fail to compile if the "generated-sources/annotations" does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano --- src/it/MCOMPILER-567-kt/invoker.properties | 18 +++++ src/it/MCOMPILER-567-kt/pom.xml | 78 +++++++++++++++++++ .../src/main/kotlin/KotlinService.kt | 26 +++++++ src/it/MCOMPILER-567-kt/verify.groovy | 23 ++++++ src/it/MCOMPILER-567/invoker.properties | 18 +++++ src/it/MCOMPILER-567/pom.xml | 39 ++++++++++ src/it/MCOMPILER-567/src/main/java/Main.java | 19 +++++ src/it/MCOMPILER-567/src/test/java/.keep | 16 ++++ src/it/MCOMPILER-567/verify.groovy | 23 ++++++ .../plugin/compiler/AbstractCompilerMojo.java | 6 +- 10 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 src/it/MCOMPILER-567-kt/invoker.properties create mode 100644 src/it/MCOMPILER-567-kt/pom.xml create mode 100644 src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt create mode 100644 src/it/MCOMPILER-567-kt/verify.groovy create mode 100644 src/it/MCOMPILER-567/invoker.properties create mode 100644 src/it/MCOMPILER-567/pom.xml create mode 100644 src/it/MCOMPILER-567/src/main/java/Main.java create mode 100644 src/it/MCOMPILER-567/src/test/java/.keep create mode 100644 src/it/MCOMPILER-567/verify.groovy diff --git a/src/it/MCOMPILER-567-kt/invoker.properties b/src/it/MCOMPILER-567-kt/invoker.properties new file mode 100644 index 00000000..df01a38b --- /dev/null +++ b/src/it/MCOMPILER-567-kt/invoker.properties @@ -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. + +invoker.goals = clean compile diff --git a/src/it/MCOMPILER-567-kt/pom.xml b/src/it/MCOMPILER-567-kt/pom.xml new file mode 100644 index 00000000..a4cf61d0 --- /dev/null +++ b/src/it/MCOMPILER-567-kt/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + org.apache.maven.plugins + MCOMPILER-567-kt + MCOMPILER-567-kt + jar + 1.0-SNAPSHOT + + + + org.jetbrains.kotlin + kotlin-stdlib + 1.9.21 + + + + + ${project.basedir}/src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + 1.9.21 + + + compile + + compile + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + + default-compile + none + + + default-testCompile + none + + + java-compile + compile + + compile + + + + + + + diff --git a/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt b/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt new file mode 100644 index 00000000..31aee972 --- /dev/null +++ b/src/it/MCOMPILER-567-kt/src/main/kotlin/KotlinService.kt @@ -0,0 +1,26 @@ +/* + * 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. + */ + +class KotlinService { + + fun sayHello() { + System.out.println("Kotlin says 'Hello World!'") + } + +} diff --git a/src/it/MCOMPILER-567-kt/verify.groovy b/src/it/MCOMPILER-567-kt/verify.groovy new file mode 100644 index 00000000..5d1960e0 --- /dev/null +++ b/src/it/MCOMPILER-567-kt/verify.groovy @@ -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. + */ + +File target = new File( basedir, "target" ); +assert target.isDirectory() + +assert new File( target, "classes/KotlinService.class" ).exists(); diff --git a/src/it/MCOMPILER-567/invoker.properties b/src/it/MCOMPILER-567/invoker.properties new file mode 100644 index 00000000..e08297d6 --- /dev/null +++ b/src/it/MCOMPILER-567/invoker.properties @@ -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. + +invoker.goals = test diff --git a/src/it/MCOMPILER-567/pom.xml b/src/it/MCOMPILER-567/pom.xml new file mode 100644 index 00000000..1c0af3c5 --- /dev/null +++ b/src/it/MCOMPILER-567/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + org.apache.maven.plugins + MCOMPILER-567 + MCOMPILER-567 + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + + + diff --git a/src/it/MCOMPILER-567/src/main/java/Main.java b/src/it/MCOMPILER-567/src/main/java/Main.java new file mode 100644 index 00000000..48add13b --- /dev/null +++ b/src/it/MCOMPILER-567/src/main/java/Main.java @@ -0,0 +1,19 @@ +/* + * 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. + */ +public class Main {} diff --git a/src/it/MCOMPILER-567/src/test/java/.keep b/src/it/MCOMPILER-567/src/test/java/.keep new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/src/it/MCOMPILER-567/src/test/java/.keep @@ -0,0 +1,16 @@ +# 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. diff --git a/src/it/MCOMPILER-567/verify.groovy b/src/it/MCOMPILER-567/verify.groovy new file mode 100644 index 00000000..d71fe341 --- /dev/null +++ b/src/it/MCOMPILER-567/verify.groovy @@ -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. + */ + +File target = new File( basedir, "target" ); +assert target.isDirectory() + +assert new File( target, "classes/Main.class" ).exists(); diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index fb285afb..83fa7790 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1166,12 +1166,14 @@ public void execute() throws MojoExecutionException, CompilationFailureException if (useIncrementalCompilation) { incrementalBuildHelperRequest.outputDirectory(getOutputDirectory()); - // Cleanup the generated source files created by annotation processing - // they are regenerated by the java compiler. + // MCOMPILER-333: Cleanup the generated source files created by annotation processing + // to avoid issues with `javac` compiler when the source code is rebuild. if (getGeneratedSourcesDirectory() != null) { try (Stream walk = Files.walk(getGeneratedSourcesDirectory().toPath())) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + // MCOMPILER-567: The directory must already exist because javac does not create it. + Files.createDirectories(getGeneratedSourcesDirectory().toPath()); } catch (IOException ex) { getLog().warn("I/O error deleting the annotation processing generated files: " + ex.getMessage()); }