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

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

commit eca9a2e52af5275898da359cf52b1111db5e35e5
Author: rfscholte <rfscho...@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
---
 .../maven/it/MavenITmng5937MavenWrapper.java       |  5 ++
 ...mng6772NestedImportScopeRepositoryOverride.java | 77 ++++++++++++++++++++--
 .../maven/it/AbstractMavenIntegrationTestCase.java | 10 +++
 run-its.bat                                        |  5 ++
 4 files changed, 90 insertions(+), 7 deletions(-)

diff --git 
a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
index 4b47d80..fde2deb 100644
--- 
a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
+++ 
b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5937MavenWrapper.java
@@ -71,6 +71,11 @@ public class MavenITmng5937MavenWrapper
     public void setUp()
         throws Exception
     {
+        if ( isSkipped() )
+        {
+            return;
+        }
+
         String mavenDist = System.getProperty( "maven.distro" );
         if ( StringUtils.isEmpty( mavenDist ) )
         {
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..daf0ebc 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
@@ -54,8 +61,34 @@ public class 
MavenITmng6772NestedImportScopeRepositoryOverride
 
         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();
     }
 
@@ -71,8 +104,38 @@ public class 
MavenITmng6772NestedImportScopeRepositoryOverride
 
         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();
     }
 
diff --git 
a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
 
b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
index 168101f..c7f5c33 100644
--- 
a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
+++ 
b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
@@ -202,6 +202,16 @@ public abstract class AbstractMavenIntegrationTestCase
         }
     }
 
+    /**
+     * Can be called by version specific setUp calls
+     * 
+     * @return
+     */
+    protected final boolean isSkipped() 
+    {
+        return skip;        
+    }
+
     protected void runTest()
         throws Throwable
     {
diff --git a/run-its.bat b/run-its.bat
index a65e646..741d5c5 100644
--- a/run-its.bat
+++ b/run-its.bat
@@ -37,7 +37,12 @@ CALL :maven && CALL :maven-integration-testing
  CALL mvn verify -DdistributionFileName=${project.artifactId} -f 
"%_MAVENCODEBASE%" || exit /B
 
 :maven-integration-testing
+if exist "%_MAVENCODEBASE%\maven-wrapper\target\maven-wrapper.jar" (
  CALL mvn clean install -Prun-its,embedded -Dmaven.repo.local="%cd%\repo" 
-DmavenDistro="%_MAVENCODEBASE%\apache-maven\target\apache-maven-bin.zip" 
-DwrapperDistroDir="%_MAVENCODEBASE%\apache-maven\target" 
-DmavenWrapper="%_MAVENCODEBASE%\maven-wrapper\target\maven-wrapper.jar" || 
exit /B
+)
+else (
+ CALL mvn clean install -Prun-its,embedded,!maven-wrapper 
-Dmaven.repo.local="%cd%\repo" 
-DmavenDistro="%_MAVENCODEBASE%\apache-maven\target\apache-maven-bin.zip" || 
exit /B
+)
 
 :normalizePath
  SET _MAVENCODEBASE=%~dpfn1

Reply via email to