From f4a8a54e116b07e888ac7b6371fa24b7a81517b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sol=C3=B3rzano?= Date: Mon, 13 Feb 2023 11:00:49 +0100 Subject: [PATCH] [MCOMPILER-525] Incorrect detection of dependency change (#172) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jorge Solórzano Co-authored-by: Guillaume Nodet --- src/it/MCOMPILER-525/invoker.properties | 21 ++++++ src/it/MCOMPILER-525/pom.xml | 64 +++++++++++++++++++ .../src/main/java/myproject/HelloWorld.java | 34 ++++++++++ src/it/MCOMPILER-525/verify.groovy | 44 +++++++++++++ .../plugin/compiler/AbstractCompilerMojo.java | 2 +- 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/it/MCOMPILER-525/invoker.properties create mode 100644 src/it/MCOMPILER-525/pom.xml create mode 100644 src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java create mode 100644 src/it/MCOMPILER-525/verify.groovy diff --git a/src/it/MCOMPILER-525/invoker.properties b/src/it/MCOMPILER-525/invoker.properties new file mode 100644 index 00000000..da0f0927 --- /dev/null +++ b/src/it/MCOMPILER-525/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. + +# 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 = clean integration-test package -Dmaven.compiler.showCompilationChanges=true diff --git a/src/it/MCOMPILER-525/pom.xml b/src/it/MCOMPILER-525/pom.xml new file mode 100644 index 00000000..48de91e9 --- /dev/null +++ b/src/it/MCOMPILER-525/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + org.apache.maven.plugins + MCOMPILER-525-no-recreation + MCOMPILER-525-no-recreation + jar + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + @project.version@ + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + + touch + integration-test + + run + + + + + + + + + + + + + diff --git a/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java b/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java new file mode 100644 index 00000000..8318e9fb --- /dev/null +++ b/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java @@ -0,0 +1,34 @@ +/* + * 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 myproject; + +/** + * The classic Hello World App. + */ +public class HelloWorld { + + /** + * Main method. + * + * @param args Not used + */ + public static void main(String[] args) { + System.out.println("Hi!"); + } +} diff --git a/src/it/MCOMPILER-525/verify.groovy b/src/it/MCOMPILER-525/verify.groovy new file mode 100644 index 00000000..0e97225d --- /dev/null +++ b/src/it/MCOMPILER-525/verify.groovy @@ -0,0 +1,44 @@ + +/* + * 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. + */ + +import java.nio.file.*; +import java.time.*; +import java.time.temporal.* +import java.util.*; + +File target = new File( basedir, "target" ); +assert target.isDirectory() + +File jarFile = new File( target, "MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar" ); +assert jarFile.isFile() + +File refFile = new File( target, "reference.jar" ); +assert refFile.isFile() + +Instant referenceTimestamp = Files.getLastModifiedTime( refFile.toPath() ) + .toInstant().truncatedTo( ChronoUnit.MILLIS ); +System.out.println( "Reference timestamp: " + referenceTimestamp ); + +Instant actualTimestamp = Files.getLastModifiedTime( jarFile.toPath() ) + .toInstant().truncatedTo( ChronoUnit.MILLIS ); +System.out.println( "Actual timestamp : " + actualTimestamp ); + +assert referenceTimestamp.equals(actualTimestamp), + "Timestamps don't match, JAR was recreated although contents has not changed" 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 aff9059b..ad68b4f0 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1538,7 +1538,7 @@ protected boolean isDependencyChanged() { for (String pathElement : pathElements) { File artifactPath = new File(pathElement); if (artifactPath.isDirectory() || artifactPath.isFile()) { - if (hasNewFile(artifactPath, buildStartTime)) { + if (!artifactPath.equals(getOutputDirectory()) && hasNewFile(artifactPath, buildStartTime)) { if (showCompilationChanges) { getLog().info("New dependency detected: " + artifactPath.getAbsolutePath()); } else {