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