1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
30
31
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
44
45
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
79
80
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
114
115
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 }