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  import org.apache.maven.shared.utils.io.FileUtils;
24  
25  import java.io.File;
26  import java.util.Properties;
27  
28  /**
29   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4745">MNG-4745</a>.
30   *
31   * @author Benjamin Bentmann
32   */
33  public class MavenITmng4745PluginVersionUpdateTest
34      extends AbstractMavenIntegrationTestCase
35  {
36  
37      public MavenITmng4745PluginVersionUpdateTest()
38      {
39          super( "[2.0.3,3.0-alpha-1),[3.0-beta-2,)" );
40      }
41  
42      /**
43       * Verify that the update policy of a (plugin) repository affects the check for newer plugin versions.
44       *
45       * @throws Exception in case of failure
46       */
47      public void testitRepoPolicyAlways()
48          throws Exception
49      {
50          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
51  
52          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53          verifier.setAutoclean( false );
54          verifier.setForkJvm( true );
55          verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
56          verifier.addCliOption( "-s" );
57          verifier.addCliOption( "settings.xml" );
58          Properties filterProps = verifier.newDefaultFilterProperties();
59          filterProps.setProperty( "@updates@", "always" );
60          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
61  
62          writeMetadata( testDir, "1.0", "20100729123455" );
63          verifier.setLogFileName( "log-1a.txt" );
64          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
65  
66          writeMetadata( testDir, "1.1", "20100730123456" );
67          verifier.setLogFileName( "log-1b.txt" );
68          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
69  
70          verifier.verifyErrorFreeLog();
71          verifier.resetStreams();
72  
73          Properties props = verifier.loadProperties( "target/plugin.properties" );
74          assertEquals( "1.1", props.get( "plugin.version" ) );
75      }
76  
77      /**
78       * Verify that the update policy of a (plugin) repository affects the check for newer plugin versions.
79       *
80       * @throws Exception in case of failure
81       */
82      public void testitRepoPolicyNever()
83          throws Exception
84      {
85          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
86  
87          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
88          verifier.setAutoclean( false );
89          verifier.setForkJvm( true );
90          verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
91          verifier.addCliOption( "-s" );
92          verifier.addCliOption( "settings.xml" );
93          Properties filterProps = verifier.newDefaultFilterProperties();
94          filterProps.setProperty( "@updates@", "never" );
95          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
96  
97          writeMetadata( testDir, "1.0", "20100729123455" );
98          verifier.setLogFileName( "log-2a.txt" );
99          verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
100 
101         writeMetadata( testDir, "1.1", "20100730123456" );
102         verifier.setLogFileName( "log-2b.txt" );
103         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
104 
105         verifier.verifyErrorFreeLog();
106         verifier.resetStreams();
107 
108         Properties props = verifier.loadProperties( "target/plugin.properties" );
109         assertEquals( "1.0", props.get( "plugin.version" ) );
110     }
111 
112     /**
113      * Verify that the CLI's force update flag affects the check for newer plugin versions.
114      *
115      * @throws Exception in case of failure
116      */
117     public void testitForceUpdate()
118         throws Exception
119     {
120         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4745" );
121 
122         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
123         verifier.setAutoclean( false );
124         verifier.setForkJvm( true );
125         verifier.deleteArtifacts( "org.apache.maven.its.mng4745" );
126         verifier.addCliOption( "-U" );
127         verifier.addCliOption( "-s" );
128         verifier.addCliOption( "settings.xml" );
129         Properties filterProps = verifier.newDefaultFilterProperties();
130         filterProps.setProperty( "@updates@", "never" );
131         verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
132 
133         writeMetadata( testDir, "1.0", "20100729123455" );
134         verifier.setLogFileName( "log-3a.txt" );
135         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
136 
137         writeMetadata( testDir, "1.1", "20100730123456" );
138         verifier.setLogFileName( "log-3b.txt" );
139         verifier.executeGoal( "org.apache.maven.its.mng4745:maven-it-plugin:touch" );
140 
141         verifier.verifyErrorFreeLog();
142         verifier.resetStreams();
143 
144         Properties props = verifier.loadProperties( "target/plugin.properties" );
145         assertEquals( "1.1", props.get( "plugin.version" ) );
146     }
147 
148     private static void writeMetadata( File testdir, String version, String timestamp )
149         throws Exception
150     {
151         StringBuilder content = new StringBuilder( 1024 );
152         content.append( "<?xml version=\"1.0\"?>\n" );
153         content.append( "<metadata>\n" );
154         content.append( "  <groupId>org.apache.maven.its.mng4745</groupId>\n" );
155         content.append( "  <artifactId>maven-it-plugin</artifactId>\n" );
156         content.append( "  <versioning>\n" );
157         content.append( "    <latest>" + version + "</latest>\n" );
158         content.append( "    <release>" + version + "</release>\n" );
159         content.append( "    <versions>\n" );
160         content.append( "      <version>1.0</version>\n" );
161         content.append( "    </versions>\n" );
162         content.append( "    <lastUpdated>" + timestamp + "</lastUpdated>\n" );
163         content.append( "  </versioning>\n" );
164         content.append( "</metadata>\n" );
165 
166         File metadata = new File( testdir, "repo/org/apache/maven/its/mng4745/maven-it-plugin/maven-metadata.xml" );
167         metadata.getParentFile().mkdirs();
168         FileUtils.fileWrite( metadata.getAbsolutePath(), "UTF-8", content.toString() );
169     }
170 
171 }