Skip to content

Commit

Permalink
[MCOMPILER-525] Incorrect detection of dependency change (#172)
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
  • Loading branch information
jorsol and gnodet committed Feb 13, 2023
1 parent 86b9f59 commit f4a8a54
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/it/MCOMPILER-525/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions src/it/MCOMPILER-525/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>MCOMPILER-525-no-recreation</artifactId>
<name>MCOMPILER-525-no-recreation</name>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@project.version@</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>touch</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Save the JAR and especially its timestamp for evaluation by the post-build hook script -->
<copy file="target/MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar"
tofile="target/reference.jar"
preservelastmodified="true" overwrite="true"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
34 changes: 34 additions & 0 deletions src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -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!");
}
}
44 changes: 44 additions & 0 deletions src/it/MCOMPILER-525/verify.groovy
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f4a8a54

Please sign in to comment.