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-4415">MNG-4415</a>.
31   *
32   * @author Benjamin Bentmann
33   */
34  public class MavenITmng4415InheritedPluginOrderTest
35      extends AbstractMavenIntegrationTestCase
36  {
37  
38      public MavenITmng4415InheritedPluginOrderTest()
39      {
40          super( "[2.0.5,)" );
41      }
42  
43      /**
44       * Test that merging of plugins during inheritance follows these rules regarding ordering:
45       * {@code parent: X ->      A -> B ->      D -> E
46       * child:       Y -> A ->      C -> D ->      F
47       * result: X -> Y -> A -> B -> C -> D -> E -> F}
48       *
49       * @throws Exception in case of failure
50       */
51      public void testit()
52          throws Exception
53      {
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4415" );
55  
56          Verifier verifier = newVerifier( new File( testDir, "sub" ).getAbsolutePath() );
57          verifier.setAutoclean( false );
58          verifier.deleteDirectory( "target" );
59          verifier.executeGoal( "validate" );
60          verifier.verifyErrorFreeLog();
61          verifier.resetStreams();
62  
63          Properties props = verifier.loadProperties( "target/it.properties" );
64          assertNotNull( props.getProperty( "project.build.plugins" ) );
65  
66          List<String> expected = new ArrayList<>();
67          expected.add( "maven-it-plugin-error" );
68          expected.add( "maven-it-plugin-configuration" );
69          expected.add( "maven-it-plugin-dependency-resolution" );
70          expected.add( "maven-it-plugin-packaging" );
71          expected.add( "maven-it-plugin-log-file" );
72          expected.add( "maven-it-plugin-expression" );
73          expected.add( "maven-it-plugin-fork" );
74          expected.add( "maven-it-plugin-touch" );
75  
76          List<String> actual = new ArrayList<>();
77  
78          int count = Integer.parseInt( props.getProperty( "project.build.plugins" ) );
79          for ( int i = 0; i < count; i++ )
80          {
81              actual.add( props.getProperty( "project.build.plugins." + i + ".artifactId" ) );
82          }
83  
84          actual.retainAll( expected );
85  
86          assertEquals( actual, expected );
87      }
88  
89  }