View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.util.List;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4800">MNG-4800</a>.
29   *
30   * @author Benjamin Bentmann
31   */
32  public class MavenITmng4800NearestWinsVsScopeWideningTest
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng4800NearestWinsVsScopeWideningTest()
37      {
38          super( "[3.0-beta-4,)" );
39      }
40  
41      public void testitAB()
42          throws Exception
43      {
44          testit( "test-ab" );
45      }
46  
47      public void testitBA()
48          throws Exception
49      {
50          testit( "test-ba" );
51      }
52  
53      /**
54       * Verify that nearest-wins conflict resolution doesn't get confused when a farther conflicting dependency has
55       * a wider scope than the nearer dependency, i.e. one should still end up with the nearer dependency (s:1) and
56       * its sub tree (x) but in the wider scope (compile).
57       */
58      private void testit( String test )
59          throws Exception
60      {
61          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4800" );
62  
63          Verifier verifier = newVerifier( new File( testDir, test ).getAbsolutePath() );
64          verifier.setAutoclean( false );
65          verifier.deleteDirectory( "target" );
66          verifier.deleteArtifacts( "org.apache.maven.its.mng4800" );
67          verifier.addCliOption( "-s" );
68          verifier.addCliOption( "settings.xml" );
69          verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
70          verifier.executeGoal( "validate" );
71          verifier.verifyErrorFreeLog();
72          verifier.resetStreams();
73  
74          List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
75  
76          assertTrue( test + " > " + compile.toString(), compile.contains( "b-0.1.jar" ) );
77          assertTrue( test + " > " + compile.toString(), compile.contains( "c-0.1.jar" ) );
78          assertTrue( test + " > " + compile.toString(), compile.contains( "s-0.1.jar" ) );
79          assertTrue( test + " > " + compile.toString(), compile.contains( "x-0.1.jar" ) );
80          assertFalse( test + " > " + compile.toString(), compile.contains( "a-0.1.jar" ) );
81          assertFalse( test + " > " + compile.toString(), compile.contains( "s-0.2.jar" ) );
82          assertFalse( test + " > " + compile.toString(), compile.contains( "y-0.1.jar" ) );
83  
84          List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
85  
86          assertTrue( test + " > " + runtime.toString(), runtime.contains( "b-0.1.jar" ) );
87          assertTrue( test + " > " + runtime.toString(), runtime.contains( "c-0.1.jar" ) );
88          assertTrue( test + " > " + runtime.toString(), runtime.contains( "s-0.1.jar" ) );
89          assertTrue( test + " > " + runtime.toString(), runtime.contains( "x-0.1.jar" ) );
90          assertTrue( test + " > " + runtime.toString(), runtime.contains( "a-0.1.jar" ) );
91          assertFalse( test + " > " + runtime.toString(), runtime.contains( "s-0.2.jar" ) );
92          assertFalse( test + " > " + runtime.toString(), runtime.contains( "y-0.1.jar" ) );
93      }
94  
95  }