You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/03/28 13:22:47 UTC

[maven-integration-testing] 01/02: [MNG-6772] Project repositories should only be used by direct dependencies, not transitive dependencies

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MNG-6772_2
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit c07085ae3c56d3f66444c7e7a9a283c330a82a50
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Jan 16 14:41:17 2021 +0100

    [MNG-6772] Project repositories should only be used by direct dependencies, not transitive dependencies
---
 ...mng6772NestedImportScopeRepositoryOverride.java | 94 +++++++++++++++++++---
 1 file changed, 84 insertions(+), 10 deletions(-)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6772NestedImportScopeRepositoryOverride.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6772NestedImportScopeRepositoryOverride.java
index 398da08..65a9933 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6772NestedImportScopeRepositoryOverride.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6772NestedImportScopeRepositoryOverride.java
@@ -1,7 +1,5 @@
 package org.apache.maven.it;
 
-import java.io.File;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,8 +19,17 @@ import java.io.File;
  * under the License.
  */
 
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.maven.it.util.ResourceExtractor;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.startsWith;
+
 /**
  * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-6772">MNG-6772</a>:
  *
@@ -39,7 +46,7 @@ public class MavenITmng6772NestedImportScopeRepositoryOverride
 
     public MavenITmng6772NestedImportScopeRepositoryOverride()
     {
-        super( "(,4.0.0-alpha-1),[4.0.0-alpha-1,)" );
+        super( "[3.0,)" );
     }
 
     // This will test the behavior using ProjectModelResolver
@@ -49,13 +56,39 @@ public class MavenITmng6772NestedImportScopeRepositoryOverride
         final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6772-override-in-project" );
 
         final Verifier verifier = newVerifier( testDir.getAbsolutePath(), null );
-        overrideGlobalSettings( testDir, verifier );
+        overrideSettings( testDir, verifier );
         verifier.deleteArtifacts( "org.apache.maven.its.mng6772" );
 
         verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", verifier.newDefaultFilterProperties() );
 
-        verifier.executeGoal( "validate" );
-        verifier.verifyErrorFreeLog();
+        try
+        {
+            verifier.executeGoal( "validate" );
+            fail( "Shouldn't be able to find b-0.1.pom in Central " );
+        }
+        catch( VerificationException e )
+        {
+        }
+
+        List<String> logLines = Files.readAllLines( testDir.toPath().resolve( verifier.getLogFileName() ) );
+
+        List<String> downloadLines = new ArrayList<>( 3 );
+        for ( String line : logLines )
+        {
+            if ( line.startsWith( "[INFO] Downloading from central:" ) )
+            {
+                downloadLines.add( line );
+            }
+        }
+
+        assertEquals( 2, downloadLines.size() );
+
+        assertThat( downloadLines.get( 0 ), endsWith( "/a-0.1.pom" ) );
+        assertThat( downloadLines.get( 0 ), startsWith( "[INFO] Downloading from central: file" ) );
+
+        assertThat( downloadLines.get( 1 ), endsWith( "/b-0.1.pom" ) );
+        assertThat( downloadLines.get( 1 ), startsWith( "[INFO] Downloading from central: http" ) );
+
         verifier.resetStreams();
     }
 
@@ -66,21 +99,52 @@ public class MavenITmng6772NestedImportScopeRepositoryOverride
         final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6772-override-in-dependency" );
 
         final Verifier verifier = newVerifier( testDir.getAbsolutePath(), null );
-        overrideGlobalSettings( testDir, verifier );
+        overrideSettings( testDir, verifier );
         verifier.deleteArtifacts( "org.apache.maven.its.mng6772" );
 
         verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", verifier.newDefaultFilterProperties() );
 
-        verifier.executeGoal( "compile" );
-        verifier.verifyErrorFreeLog();
+        try
+        {
+            verifier.executeGoal( "compile" );
+            fail( "Shouldn't be able to find b-0.1.pom in Central " );
+        }
+        catch( VerificationException e )
+        {
+        }
+
+        List<String> logLines = Files.readAllLines( testDir.toPath().resolve( verifier.getLogFileName() ) );
+
+        List<String> downloadLines = new ArrayList<>( 3 );
+        for ( String line : logLines )
+        {
+            if ( line.startsWith( "[INFO] Downloading from central:" ) )
+            {
+                downloadLines.add( line );
+            }
+        }
+
+        assertEquals( 3, downloadLines.size() );
+
+        assertThat( downloadLines.get( 0 ), endsWith( "/dependency-0.1.pom" ) );
+        assertThat( downloadLines.get( 0 ), startsWith( "[INFO] Downloading from central: file" ) );
+
+        // this might be a bug, shouldn't it be using the repository defined in dependency-0.1.pom, even though it is a BOM
+        assertThat( downloadLines.get( 1 ), endsWith( "/a-0.1.pom" ) );
+        assertThat( downloadLines.get( 1 ), startsWith( "[INFO] Downloading from central: file" ) );
+
+        assertThat( downloadLines.get( 2 ), endsWith( "/b-0.1.pom" ) );
+        assertThat( downloadLines.get( 2 ), startsWith( "[INFO] Downloading from central: http" ) );
+
         verifier.resetStreams();
     }
 
     // central must not be defined in any settings.xml or super POM will never be in play.
-    private void overrideGlobalSettings( final File testDir, final Verifier verifier )
+    private void overrideSettings( final File testDir, final Verifier verifier )
     {
         final File settingsFile = new File( testDir, "settings-override.xml" );
         final String path = settingsFile.getAbsolutePath();
+
         verifier.getCliOptions().add( "--global-settings" );
         if ( path.indexOf( ' ' ) < 0 )
         {
@@ -90,6 +154,16 @@ public class MavenITmng6772NestedImportScopeRepositoryOverride
         {
             verifier.getCliOptions().add( '"' + path + '"' );
         }
+
+        verifier.getCliOptions().add( "--settings" );
+        if ( path.indexOf( ' ' ) < 0 )
+        {
+            verifier.getCliOptions().add( path );
+        }
+        else
+        {
+            verifier.getCliOptions().add( '"' + path + '"' );
+        }
     }
 
 }