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
27
28
29
30
31
32 public class MavenITmng4368TimestampAwareArtifactInstallerTest
33 extends AbstractMavenIntegrationTestCase
34 {
35
36 public MavenITmng4368TimestampAwareArtifactInstallerTest()
37 {
38 super( "[2.0.3,3.0-alpha-1),[3.0-alpha-6,)" );
39 }
40
41
42
43
44
45
46
47 public void testitPomPackaging()
48 throws Exception
49 {
50 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4368/pom" );
51
52 File aDir = new File( testDir, "branch-a" );
53 File aPom = new File( aDir, "pom.xml" );
54 File bDir = new File( testDir, "branch-b" );
55 File bPom = new File( bDir, "pom.xml" );
56
57 aPom.setLastModified( System.currentTimeMillis() );
58 bPom.setLastModified( aPom.lastModified() - 1000 * 60 );
59
60 Verifier verifier = newVerifier( aDir.getAbsolutePath() );
61 verifier.setAutoclean( false );
62 verifier.deleteDirectory( "target" );
63 verifier.deleteArtifacts( "org.apache.maven.its.mng4368" );
64 verifier.executeGoal( "initialize" );
65 verifier.verifyErrorFreeLog();
66 verifier.resetStreams();
67
68 File installedPom =
69 new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "pom" ) );
70
71 String pom = FileUtils.fileRead( installedPom, "UTF-8" );
72 assertTrue( pom.indexOf( "Branch-A" ) > 0 );
73 assertFalse( pom.contains( "Branch-B" ) );
74
75 assertEquals( aPom.length(), bPom.length() );
76 assertTrue( aPom.lastModified() > bPom.lastModified() );
77 assertTrue( installedPom.lastModified() > bPom.lastModified() );
78
79 verifier = newVerifier( bDir.getAbsolutePath() );
80 verifier.setAutoclean( false );
81 verifier.deleteDirectory( "target" );
82 verifier.executeGoal( "initialize" );
83 verifier.verifyErrorFreeLog();
84 verifier.resetStreams();
85
86 pom = FileUtils.fileRead( installedPom, "UTF-8" );
87 assertFalse( pom.contains( "Branch-A" ) );
88 assertTrue( pom.indexOf( "Branch-B" ) > 0 );
89 }
90
91
92
93
94
95
96
97 public void testitJarPackaging()
98 throws Exception
99 {
100 requiresMavenVersion( "[2.2.2,3.0-alpha-1),[3.0-alpha-6,)" );
101
102 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4368/jar" );
103
104 File aDir = new File( testDir, "branch-a" );
105 File aArtifact = new File( aDir, "artifact.jar" );
106 File bDir = new File( testDir, "branch-b" );
107 File bArtifact = new File( bDir, "artifact.jar" );
108
109 FileUtils.fileWrite( aArtifact.getPath(), "UTF-8", "from Branch-A" );
110 aArtifact.setLastModified( System.currentTimeMillis() );
111 FileUtils.fileWrite( bArtifact.getPath(), "UTF-8", "from Branch-B" );
112 bArtifact.setLastModified( aArtifact.lastModified() - 1000 * 60 );
113
114 Verifier verifier = newVerifier( aDir.getAbsolutePath() );
115 verifier.setAutoclean( false );
116 verifier.deleteDirectory( "target" );
117 verifier.deleteArtifacts( "org.apache.maven.its.mng4368" );
118 verifier.executeGoal( "initialize" );
119 verifier.verifyErrorFreeLog();
120 verifier.resetStreams();
121
122 File installedArtifact =
123 new File( verifier.getArtifactPath( "org.apache.maven.its.mng4368", "test", "0.1-SNAPSHOT", "jar" ) );
124
125 String data = FileUtils.fileRead( installedArtifact, "UTF-8" );
126 assertTrue( data.indexOf( "Branch-A" ) > 0 );
127 assertFalse( data.contains( "Branch-B" ) );
128
129 assertEquals( aArtifact.length(), bArtifact.length() );
130 assertTrue( aArtifact.lastModified() > bArtifact.lastModified() );
131 assertTrue( installedArtifact.lastModified() > bArtifact.lastModified() );
132
133 verifier = newVerifier( bDir.getAbsolutePath() );
134 verifier.setAutoclean( false );
135 verifier.deleteDirectory( "target" );
136 verifier.executeGoal( "initialize" );
137 verifier.verifyErrorFreeLog();
138 verifier.resetStreams();
139
140 data = FileUtils.fileRead( installedArtifact, "UTF-8" );
141 assertFalse( data.contains( "Branch-A" ) );
142 assertTrue( data.indexOf( "Branch-B" ) > 0 );
143
144 long lastModified = installedArtifact.lastModified();
145 FileUtils.fileWrite( installedArtifact.getPath(), "UTF-8", "from Branch-C" );
146 installedArtifact.setLastModified( lastModified );
147
148 verifier = newVerifier( bDir.getAbsolutePath() );
149 verifier.setAutoclean( false );
150 verifier.deleteDirectory( "target" );
151 verifier.setLogFileName( "log-b.txt" );
152 verifier.executeGoal( "initialize" );
153 verifier.verifyErrorFreeLog();
154 verifier.resetStreams();
155
156 data = FileUtils.fileRead( installedArtifact, "UTF-8" );
157 assertFalse( data.contains( "Branch-B" ) );
158 assertTrue( data.indexOf( "Branch-C" ) > 0 );
159 }
160
161 }