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