Skip to content

Commit

Permalink
[MCOMPILER-525] - Incremental recompile incorrect detection of depend…
Browse files Browse the repository at this point in the history
…ency change

Signed-off-by: Jorge Solórzano <jorsol@gmail.com>
  • Loading branch information
jorsol committed Feb 1, 2023
1 parent 3f95d39 commit 9e1a2bd
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/it/MCOMPILER-275_separate-moduleinfo/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def log = new File( basedir, 'build.log').text

assert log.count( "[INFO] Toolchain in maven-compiler-plugin: JDK" ) == 1

assert log.count( "[INFO] Changes detected - recompiling the module!" ) == 3
assert log.count( "[INFO] Changes detected - recompiling the module" ) == 3

// major_version: 52 = java8 -> execution id "base-compile"
assert new File( basedir, 'target/classes/com/foo/MyClass.class' ).bytes[7] == 52
Expand Down
2 changes: 1 addition & 1 deletion src/it/MCOMPILER-500-package-info-incr/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def logFile = new File( basedir, 'build.log' )
assert logFile.exists()
content = logFile.text

assert 1 == content.count( 'Changes detected - recompiling the module!' )
assert 1 == content.count( 'Changes detected - recompiling the module' )
assert 1 == content.count( 'Nothing to compile - all classes are up to date' )


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>MJAR-70-no-recreation</artifactId>
<name>MJAR-70-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/MJAR-70-no-recreation-1.0-SNAPSHOT.jar"
tofile="target/reference.jar"
preservelastmodified="true" overwrite="true"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 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,36 @@
package myproject;

/*
* 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.
*/

/**
* 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, "MJAR-70-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"
Loading

0 comments on commit 9e1a2bd

Please sign in to comment.