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  
27  /**
28   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-449">MNG-449</a>.
29   * 
30   * @author Benjamin Bentmann
31   * @version $Id: MavenITmng0449PluginVersionResolutionTest.java 981712 2010-08-03 00:36:19Z bentmann $
32   */
33  public class MavenITmng0449PluginVersionResolutionTest
34      extends AbstractMavenIntegrationTestCase
35  {
36  
37      public MavenITmng0449PluginVersionResolutionTest()
38      {
39          super( "[2.0,)" );
40      }
41  
42      /**
43       * Verify that versions for plugins are automatically resolved if not given in the POM by checking first LATEST and
44       * then RELEASE in the repo metadata when the plugin is invoked from the lifecycle.
45       */
46      public void testitLifecycleInvocation()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0449" );
50          testDir = new File( testDir, "lifecycle" );
51  
52          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53          verifier.setAutoclean( false );
54          verifier.deleteDirectory( "target" );
55          try
56          {
57              verifier.deleteArtifacts( "org.apache.maven.its.mng0449" );
58          }
59          catch ( Exception e )
60          {
61              // when we run Maven embedded, the plugin class realm locks the artifacts so we can't delete them
62          }
63          verifier.getCliOptions().add( "--settings" );
64          verifier.getCliOptions().add( "settings.xml" );
65          verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
66          verifier.executeGoal( "validate" );
67          verifier.verifyErrorFreeLog();
68          verifier.resetStreams();
69  
70          // Maven 3.x prefers RELEASE over LATEST (see MNG-4206)
71          if ( matchesVersionRange( "(,3.0-alpha-3)" ) )
72          {
73              verifier.assertFileNotPresent( "target/touch-release.txt" );
74              verifier.assertFilePresent( "target/touch-snapshot.txt" );
75          }
76          else
77          {
78              verifier.assertFilePresent( "target/touch-release.txt" );
79              verifier.assertFileNotPresent( "target/touch-snapshot.txt" );
80          }
81          verifier.assertFilePresent( "target/package.txt" );
82      }
83  
84      /**
85       * Verify that versions for plugins are automatically resolved if not given in the POM by checking LATEST and
86       * RELEASE in the repo metadata when the plugin is invoked directly from the command line.
87       */
88      public void testitCliInvocation()
89          throws Exception
90      {
91          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0449" );
92          testDir = new File( testDir, "direct" );
93  
94          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
95          verifier.setAutoclean( false );
96          verifier.deleteDirectory( "target" );
97          try
98          {
99              verifier.deleteArtifacts( "org.apache.maven.its.mng0449" );
100         }
101         catch ( Exception e )
102         {
103             // when we run Maven embedded, the plugin class realm locks the artifacts so we can't delete them
104         }
105         verifier.getCliOptions().add( "--settings" );
106         verifier.getCliOptions().add( "settings.xml" );
107         verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
108         verifier.executeGoal( "org.apache.maven.its.mng0449:maven-it-plugin-a:touch" );
109         verifier.verifyErrorFreeLog();
110         verifier.resetStreams();
111 
112         // Maven 3.x prefers RELEASE over LATEST (see MNG-4206)
113         if ( matchesVersionRange( "(,3.0-alpha-3)" ) )
114         {
115             verifier.assertFileNotPresent( "target/touch-release.txt" );
116             verifier.assertFilePresent( "target/touch-snapshot.txt" );
117         }
118         else
119         {
120             verifier.assertFilePresent( "target/touch-release.txt" );
121             verifier.assertFileNotPresent( "target/touch-snapshot.txt" );
122         }
123     }
124 
125 }