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.Verifier;
23  import org.apache.maven.it.util.ResourceExtractor;
24  
25  import java.io.File;
26  import java.util.List;
27  
28  /**
29   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4768">MNG-4768</a>.
30   * 
31   * @author Benjamin Bentmann
32   */
33  public class MavenITmng4768NearestMatchConflictResolutionTest
34      extends AbstractMavenIntegrationTestCase
35  {
36  
37      public MavenITmng4768NearestMatchConflictResolutionTest()
38      {
39          super( "[2.0.9,)" );
40      }
41  
42      // Ideally, all six permutations of the three direct dependencies should yield the same result...
43  
44      public void testitABD()
45          throws Exception
46      {
47          testit( "test-abd" );
48      }
49  
50      public void testitADB()
51          throws Exception
52      {
53          requiresMavenVersion( "[3.0-beta-3,)" );
54          testit( "test-adb" );
55      }
56  
57      public void testitBAD()
58          throws Exception
59      {
60          testit( "test-bad" );
61      }
62  
63      public void testitBDA()
64          throws Exception
65      {
66          testit( "test-bda" );
67      }
68  
69      public void testitDAB()
70          throws Exception
71      {
72          requiresMavenVersion( "[3.0-beta-3,)" );
73          testit( "test-dab" );
74      }
75  
76      public void testitDBA()
77          throws Exception
78      {
79          testit( "test-dba" );
80      }
81  
82      /**
83       * Verify that conflict resolution picks the nearest version that matches all hard constraints given by ranges.
84       * And for conflicting dependencies on distinct tree levels, "nearest" shouldn't be subject to the dependency
85       * order.
86       */
87      private void testit( String test )
88          throws Exception
89      {
90          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4768" );
91  
92          Verifier verifier = newVerifier( new File( testDir, test ).getAbsolutePath() );
93          verifier.setAutoclean( false );
94          verifier.deleteDirectory( "target" );
95          verifier.deleteArtifacts( "org.apache.maven.its.mng4768" );
96          verifier.getCliOptions().add( "-s" );
97          verifier.getCliOptions().add( "settings.xml" );
98          verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
99          verifier.executeGoal( "validate" );
100         verifier.verifyErrorFreeLog();
101         verifier.resetStreams();
102 
103         List classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
104 
105         assertTrue( test + " > " + classpath.toString(), classpath.contains( "a-2.0.jar" ) );
106         assertTrue( test + " > " + classpath.toString(), classpath.contains( "b-0.1.jar" ) );
107         assertTrue( test + " > " + classpath.toString(), classpath.contains( "c-0.1.jar" ) );
108         assertTrue( test + " > " + classpath.toString(), classpath.contains( "d-0.1.jar" ) );
109 
110         assertFalse( test + " > " + classpath.toString(), classpath.contains( "a-2.1.jar" ) );
111         assertFalse( test + " > " + classpath.toString(), classpath.contains( "a-1.0.jar" ) );
112     }
113 
114 }