reda-alaoui commented on PR #534:
URL: 
https://github.com/apache/maven-build-cache-extension/pull/534#issuecomment-6857614596

   Following up on my previous comment: I filed the managed-version case as 
#579 and turned it into an integration test. It fails on master (the build with 
the changed managed version is restored from cache) and passes on this PR's 
head (3db7dae). An unused managed version still hits the cache on both.
   
   ```
   mvn -Prun-its verify -Dit.test=Issue579Test
   ```
   
   None of the tests in this PR seems to pin this down.
   
   The test also bears on the alternative suggested in review: both versions in 
#579 are releases, so tracking only resolved SNAPSHOT artifacts would not catch 
it. If the fix changes shape, this test tells whether the managed-version case 
still works.
   
   @goutamadwant, could you add it to the PR, along with `Fixes #579` in the 
description?
   
   <details>
   
<summary><code>src/test/java/org/apache/maven/buildcache/its/Issue579Test.java</code></summary>
   
   ```java
   package org.apache.maven.buildcache.its;
   
   import java.nio.file.Path;
   import java.nio.file.Paths;
   import java.util.Collections;
   
   import org.apache.maven.buildcache.its.junit.IntegrationTest;
   import org.apache.maven.it.Verifier;
   import org.junit.jupiter.api.Test;
   
   import static org.apache.maven.buildcache.its.CacheITUtils.CACHE_HIT;
   import static org.apache.maven.buildcache.its.CacheITUtils.CACHE_MISS;
   import static org.apache.maven.buildcache.its.CacheITUtils.CACHE_SAVED;
   import static org.apache.maven.buildcache.its.CacheITUtils.assertNotInLog;
   import static org.apache.maven.buildcache.its.CacheITUtils.replaceInFile;
   import static 
org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_LOCATION_PROPERTY_NAME;
   
   /**
    * Reproducer for <a 
href="https://github.com/apache/maven-build-cache-extension/issues/579";>Issue 
#579</a>:
    * changing a managed version of a transitive dependency does not invalidate 
the cache.
    */
   @IntegrationTest("src/test/projects/mbuildcache-579")
   class Issue579Test {
   
       private static final String MANAGED_HAMCREST_CORE_1_3 =
               "<artifactId>hamcrest-core</artifactId>\n                
<version>1.3</version>";
       private static final String MANAGED_HAMCREST_CORE_1_2 =
               "<artifactId>hamcrest-core</artifactId>\n                
<version>1.2</version>";
   
       @Test
       void 
changingManagedVersionOfTransitiveDependencyInvalidatesCache(Verifier verifier) 
throws Exception {
           Path pom = setUp(verifier);
   
           // A lookup needs the descriptors of the resolved graph in the local 
repository; without them the
           // build would skip the cache entirely and the miss below would not 
prove anything.
           replaceInFile(pom, MANAGED_HAMCREST_CORE_1_3, 
MANAGED_HAMCREST_CORE_1_2);
           verifier.setSystemProperty("maven.build.cache.enabled", "false");
           build(verifier, "../log-0-download-hamcrest-core-1.2.txt");
           verifier.setSystemProperty("maven.build.cache.enabled", "true");
           replaceInFile(pom, MANAGED_HAMCREST_CORE_1_2, 
MANAGED_HAMCREST_CORE_1_3);
   
           build(verifier, "../log-1-hamcrest-core-1.3.txt");
           verifier.verifyTextInLog(CACHE_SAVED);
   
           build(verifier, "../log-2-hamcrest-core-1.3-unchanged.txt");
           verifier.verifyTextInLog(CACHE_HIT);
   
           replaceInFile(pom, MANAGED_HAMCREST_CORE_1_3, 
MANAGED_HAMCREST_CORE_1_2);
           build(verifier, "../log-3-hamcrest-core-1.2.txt");
           assertNotInLog(verifier, CACHE_HIT);
           verifier.verifyTextInLog(CACHE_MISS);
           verifier.verifyTextInLog(CACHE_SAVED);
       }
   
       @Test
       void changingManagedVersionOfUnusedDependencyKeepsCache(Verifier 
verifier) throws Exception {
           Path pom = setUp(verifier);
   
           build(verifier, "../log-1-hamcrest-library-1.3.txt");
           verifier.verifyTextInLog(CACHE_SAVED);
   
           replaceInFile(
                   pom,
                   "<artifactId>hamcrest-library</artifactId>\n                
<version>1.3</version>",
                   "<artifactId>hamcrest-library</artifactId>\n                
<version>1.2</version>");
           build(verifier, "../log-2-hamcrest-library-1.2.txt");
           verifier.verifyTextInLog(CACHE_HIT);
       }
   
       private Path setUp(Verifier verifier) {
           Path basedir = Paths.get(verifier.getBasedir());
           verifier.setAutoclean(false);
           verifier.setSystemProperty(
                   CACHE_LOCATION_PROPERTY_NAME, 
basedir.resolveSibling("cache").toString());
           return basedir.resolve("pom.xml");
       }
   
       private void build(Verifier verifier, String logFileName) throws 
Exception {
           verifier.setLogFileName(logFileName);
           verifier.executeGoals(Collections.singletonList("verify"));
           verifier.verifyErrorFreeLog();
       }
   }
   ```
   
   </details>
   
   <details>
   <summary><code>src/test/projects/mbuildcache-579/pom.xml</code></summary>
   
   `.mvn/extensions.xml` is a copy of `mbuildcache-463`'s, and 
`src/main/java/org/example/App.java` is an empty `public class App {}`.
   
   ```xml
   <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/xsd/maven-4.0.0.xsd";>
       <modelVersion>4.0.0</modelVersion>
   
       <groupId>org.apache.maven.caching.test.mbuildcache-579</groupId>
       <artifactId>mbuildcache-579</artifactId>
       <version>1.0-SNAPSHOT</version>
       <packaging>jar</packaging>
   
       <properties>
           <maven.compiler.source>1.8</maven.compiler.source>
           <maven.compiler.target>1.8</maven.compiler.target>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       </properties>
   
       <dependencyManagement>
           <dependencies>
               <!-- Reaches the project transitively through junit -->
               <dependency>
                   <groupId>org.hamcrest</groupId>
                   <artifactId>hamcrest-core</artifactId>
                   <version>1.3</version>
               </dependency>
               <!-- Not part of the project's dependency graph -->
               <dependency>
                   <groupId>org.hamcrest</groupId>
                   <artifactId>hamcrest-library</artifactId>
                   <version>1.3</version>
               </dependency>
           </dependencies>
       </dependencyManagement>
   
       <dependencies>
           <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>4.13.2</version>
               <scope>test</scope>
           </dependency>
       </dependencies>
   
       <build>
           <pluginManagement>
               <plugins>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-clean-plugin</artifactId>
                       <version>3.2.0</version>
                   </plugin>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-resources-plugin</artifactId>
                       <version>3.3.1</version>
                   </plugin>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-compiler-plugin</artifactId>
                       <version>3.11.0</version>
                   </plugin>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-surefire-plugin</artifactId>
                       <version>3.0.0</version>
                   </plugin>
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-jar-plugin</artifactId>
                       <version>3.3.0</version>
                   </plugin>
               </plugins>
           </pluginManagement>
       </build>
   </project>
   ```
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to