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.ArrayList;
26  import java.util.List;
27  import java.util.Properties;
28  
29  /**
30   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4666">MNG-4666</a>.
31   *
32   * @author Benjamin Bentmann
33   */
34  public class MavenITmng4666CoreRealmImportTest
35      extends AbstractMavenIntegrationTestCase
36  {
37  
38      public MavenITmng4666CoreRealmImportTest()
39      {
40          super( "[2.0.11,2.0.99),[2.1.0,3.0-alpha-1),[3.0-beta-2,)" );
41      }
42  
43      /**
44       * Verify that API types from the Maven core realm are shared/imported into the plugin realm despite the plugin
45       * declaring conflicting dependencies. For the core artifact filter, this boils down to the filter properly
46       * recognizing such a conflicting dependency, i.e. knowing the relevant groupId:artifactId's.
47       *
48       * @throws Exception in case of failure
49       */
50      public void testit()
51          throws Exception
52      {
53          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4666" );
54  
55          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
56          verifier.setAutoclean( false );
57          verifier.deleteDirectory( "target" );
58          verifier.deleteArtifacts( "org.apache.maven", "maven-model", "0.1-stub" );
59          verifier.deleteArtifacts( "org.apache.maven", "maven-settings", "0.1-stub" );
60          verifier.deleteArtifacts( "org.apache.maven", "maven-project", "0.1-stub" );
61          verifier.deleteArtifacts( "org.apache.maven", "maven-artifact", "0.1-stub" );
62          verifier.deleteArtifacts( "org.apache.maven", "maven-core", "0.1-stub" );
63          verifier.deleteArtifacts( "org.apache.maven", "maven-plugin-api", "0.1-stub" );
64          verifier.deleteArtifacts( "org.apache.maven", "maven-plugin-descriptor", "0.1-stub" );
65          verifier.deleteArtifacts( "plexus", "plexus-container-default", "0.1-stub" );
66          verifier.deleteArtifacts( "org.codehaus.plexus", "plexus-container-default", "0.1-stub" );
67          verifier.deleteArtifacts( "org.codehaus.plexus", "plexus-component-api", "0.1-stub" );
68          verifier.deleteArtifacts( "org.codehaus.plexus", "plexus-utils", "0.1-stub" );
69          verifier.deleteArtifacts( "org.codehaus.plexus", "plexus-classworlds", "0.1-stub" );
70          verifier.deleteArtifacts( "org.sonatype.aether", "aether-api", "0.1-stub" );
71          verifier.deleteArtifacts( "org.sonatype.aether", "aether-spi", "0.1-stub" );
72          verifier.deleteArtifacts( "org.sonatype.aether", "aether-impl", "0.1-stub" );
73          verifier.deleteArtifacts( "org.sonatype.sisu", "sisu-inject-plexus", "0.1-stub" );
74          verifier.deleteArtifacts( "org.sonatype.spice", "spice-inject-plexus", "0.1-stub" );
75          verifier.deleteArtifacts( "classworlds", "classworlds", "0.1-stub" );
76          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
77          verifier.addCliOption( "-s" );
78          verifier.addCliOption( "settings.xml" );
79          verifier.executeGoal( "validate" );
80          verifier.verifyErrorFreeLog();
81          verifier.resetStreams();
82  
83          Properties props = verifier.loadProperties( "target/type.properties" );
84          List<String> types = getTypes( props );
85          if ( !matchesVersionRange( "[3.0-beta-4,)" ) )
86          {
87              // MNG-4725, MNG-4807
88              types.remove( "org.codehaus.plexus.configuration.PlexusConfiguration" );
89              types.remove( "org.codehaus.plexus.logging.Logger" );
90          }
91          assertFalse( types.isEmpty() );
92          for ( String type : types )
93          {
94              assertEquals( type, props.get( "plugin." + type ), props.get( "core." + type ) );
95          }
96      }
97  
98      private List<String> getTypes( Properties props )
99      {
100         List<String> types = new ArrayList<>();
101         for ( Object o : props.keySet() )
102         {
103             String key = o.toString();
104             if ( key.startsWith( "core." ) )
105             {
106                 String type = key.substring( 5 );
107                 if ( props.getProperty( key, "" ).length() > 0 )
108                 {
109                     // types not in the core realm can't be exported/shared, so ignore those
110                     types.add( type );
111                 }
112             }
113         }
114         return types;
115     }
116 
117 }