From 9c00842514cf75aa1a93160f238984cc82faf6e1 Mon Sep 17 00:00:00 2001 From: "a.tsyganenko" Date: Wed, 1 Aug 2018 13:22:37 +0200 Subject: [PATCH] [MCOMPILER-349] - changed dependency detection. Default fileExtensions contained '.class', while FileUtils#getExtension( method used in AbstractCompilerMojo#hasNewFile returns file extension without '.' (e.g. 'class') --- .../dependent-module/pom.xml | 44 +++++++++++ .../dependent-module/src/main/java/Main.java | 27 +++++++ .../invoker.properties | 21 ++++++ .../MCOMPILER-349_dependencyChanged/pom.xml | 75 +++++++++++++++++++ .../service/pom.xml | 36 +++++++++ .../service/src/main/java/TestService.java | 27 +++++++ .../verify.groovy | 26 +++++++ .../plugin/compiler/AbstractCompilerMojo.java | 2 +- 8 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 src/it/MCOMPILER-349_dependencyChanged/dependent-module/pom.xml create mode 100644 src/it/MCOMPILER-349_dependencyChanged/dependent-module/src/main/java/Main.java create mode 100644 src/it/MCOMPILER-349_dependencyChanged/invoker.properties create mode 100644 src/it/MCOMPILER-349_dependencyChanged/pom.xml create mode 100644 src/it/MCOMPILER-349_dependencyChanged/service/pom.xml create mode 100644 src/it/MCOMPILER-349_dependencyChanged/service/src/main/java/TestService.java create mode 100644 src/it/MCOMPILER-349_dependencyChanged/verify.groovy diff --git a/src/it/MCOMPILER-349_dependencyChanged/dependent-module/pom.xml b/src/it/MCOMPILER-349_dependencyChanged/dependent-module/pom.xml new file mode 100644 index 00000000..c0220506 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/dependent-module/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + + org.apache.maven.plugins.compiler.it + mcompiler349-test + 1.0-SNAPSHOT + + + dependent-module + + + + org.apache.maven.plugins.compiler.it + service + 1.0-SNAPSHOT + + + + + + diff --git a/src/it/MCOMPILER-349_dependencyChanged/dependent-module/src/main/java/Main.java b/src/it/MCOMPILER-349_dependencyChanged/dependent-module/src/main/java/Main.java new file mode 100644 index 00000000..f77ad070 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/dependent-module/src/main/java/Main.java @@ -0,0 +1,27 @@ +/* + * 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 +{ + public static void main( String[] args ) + { + TestService testService = new TestService(); + testService.run(); + } +} \ No newline at end of file diff --git a/src/it/MCOMPILER-349_dependencyChanged/invoker.properties b/src/it/MCOMPILER-349_dependencyChanged/invoker.properties new file mode 100644 index 00000000..572447af --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/invoker.properties @@ -0,0 +1,21 @@ +# 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 +invoker.goals.2 = groovy:execute +invoker.goals.3 = compile +invoker.buildResult.3 = failure diff --git a/src/it/MCOMPILER-349_dependencyChanged/pom.xml b/src/it/MCOMPILER-349_dependencyChanged/pom.xml new file mode 100644 index 00000000..d985a190 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.compiler.it + mcompiler349-test + 1.0-SNAPSHOT + pom + + + IT test to verify that dependent-module recompile, when run 'mvn compile' without 'clean' if module dependency + changed. + The compilation should fail as dependent-module use method that is no longer exists (run() method of TestService + renamed to + newMethodName()). + + + + dependent-module + service + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + + org.codehaus.gmaven + groovy-maven-plugin + 2.0 + + + def fileToModify = new File(project.basedir, 'service/src/main/java/TestService.java') + processFileInplace(fileToModify) { text -> + text.replaceAll(/run/, 'newMethodName') + } + + def processFileInplace(file, Closure processText) { + file.write(processText(file.text)) + } + + + + + + + + + + diff --git a/src/it/MCOMPILER-349_dependencyChanged/service/pom.xml b/src/it/MCOMPILER-349_dependencyChanged/service/pom.xml new file mode 100644 index 00000000..57a08fa3 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/service/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + + org.apache.maven.plugins.compiler.it + mcompiler349-test + 1.0-SNAPSHOT + + + service + + + + diff --git a/src/it/MCOMPILER-349_dependencyChanged/service/src/main/java/TestService.java b/src/it/MCOMPILER-349_dependencyChanged/service/src/main/java/TestService.java new file mode 100644 index 00000000..df21d267 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/service/src/main/java/TestService.java @@ -0,0 +1,27 @@ +/* + * 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 TestService +{ + + public void run() + { + + } +} \ No newline at end of file diff --git a/src/it/MCOMPILER-349_dependencyChanged/verify.groovy b/src/it/MCOMPILER-349_dependencyChanged/verify.groovy new file mode 100644 index 00000000..c2182819 --- /dev/null +++ b/src/it/MCOMPILER-349_dependencyChanged/verify.groovy @@ -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. + */ +def logFile = new File( basedir, 'build.log' ) +assert logFile.exists() +content = logFile.text + +assert content.contains( 'COMPILATION ERROR :' ) + + 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 e213f3b9..92954990 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1577,7 +1577,7 @@ protected boolean isDependencyChanged() if ( fileExtensions == null || fileExtensions.isEmpty() ) { fileExtensions = new ArrayList(); - fileExtensions.add( ".class" ); + fileExtensions.add( "class" ); } Date buildStartTime = getBuildStartTime();