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 java.io.File;
23  
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3284">MNG-3284</a>:
28   * that explicitly defined plugins are used, not the one that is cached.
29   */
30  public class MavenITmng3284UsingCachedPluginsTest
31      extends AbstractMavenIntegrationTestCase
32  {
33  
34      public MavenITmng3284UsingCachedPluginsTest()
35      {
36          super( "[2.1.0-M2,)" );
37      }
38  
39      /**
40       * Verify that the effective plugin versions used for a project are not influenced by other instances of this
41       * plugin in the reactor, i.e. each module gets exactly the plugin version it declares.
42       *
43       * @throws Exception in case of failure
44       */
45      public void testitMNG3284()
46          throws Exception
47      {
48          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3284" );
49  
50          /*
51           * Phase 1: Ensure both plugin versions are already in the local repo. This is a crucial prerequisite for the
52           * test because downloading the plugins just-in-time during the test build would trigger a timestamp-based
53           * reloading of the plugin container by the DefaultPluginManager in Maven 2.x, thereby hiding the bug we want
54           * to expose here.
55           */
56          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57          verifier.setAutoclean( false );
58          verifier.deleteArtifacts( "org.apache.maven.its.mng3284" );
59          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
60          verifier.addCliOption( "--settings" );
61          verifier.addCliOption( "settings.xml" );
62          verifier.executeGoal( "validate" );
63          verifier.verifyErrorFreeLog();
64          verifier.resetStreams();
65  
66          /*
67           * Phase 2: Now that the plugin versions have been downloaded to the local repo, run the actual test.
68           */
69          verifier = newVerifier( testDir.getAbsolutePath() );
70          verifier.setAutoclean( false );
71          verifier.deleteDirectory( "mod-a/target" );
72          verifier.deleteDirectory( "mod-b/target" );
73          verifier.addCliOption( "--settings" );
74          verifier.addCliOption( "settings.xml" );
75          verifier.executeGoal( "validate" );
76          verifier.verifyErrorFreeLog();
77          verifier.resetStreams();
78  
79          verifier.assertFilePresent( "mod-a/target/version-0.1.txt" );
80          verifier.assertFileNotPresent( "mod-a/target/version-0.2.txt" );
81          verifier.assertFilePresent( "mod-b/target/version-0.2.txt" );
82          verifier.assertFileNotPresent( "mod-b/target/version-0.1.txt" );
83      }
84  
85  }