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 java.io.File;
23 import java.io.IOException;
24 import java.util.Properties;
25
26 import org.apache.maven.it.util.ResourceExtractor;
27 import org.codehaus.plexus.util.ReaderFactory;
28 import org.codehaus.plexus.util.xml.Xpp3Dom;
29 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
30 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
31
32
33
34
35
36
37
38
39
40
41 public class MavenITmng3057VersionExprTransformationsTest
42 extends AbstractMavenIntegrationTestCase
43 {
44
45 public MavenITmng3057VersionExprTransformationsTest()
46 {
47 super( "[2.1.0,2.1.1)" );
48 }
49
50 public void testitMNG3057 ()
51 throws Exception
52 {
53 requiresJavaVersion( "[1.5,)" );
54
55 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3057" );
56
57 File remoteRepo = new File( testDir, "target/deployment" );
58
59 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
60 verifier.setAutoclean( false );
61 verifier.deleteDirectory( "target" );
62 verifier.deleteDirectory( "level2/target" );
63 verifier.deleteDirectory( "level2/level3/target" );
64 verifier.deleteArtifacts( "org.apache.maven.its.mng3057" );
65
66 Properties properties = verifier.newDefaultFilterProperties();
67 properties.setProperty( "@deployTo@", remoteRepo.toURI().toURL().toExternalForm() );
68
69 verifier.filterFile( "pom.xml", "pom-filtered.xml", "UTF-8", properties );
70
71 verifier.addCliOption( "-V" );
72 verifier.addCliOption( "-DtestVersion=1" );
73 verifier.addCliOption( "-f pom-filtered.xml" );
74
75 verifier.executeGoal( "generate-sources" );
76 verifier.verifyErrorFreeLog();
77 verifier.resetStreams();
78
79 assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "mng-3057", "1", "pom" ) ), "1", null );
80 assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level2", "1", "pom" ) ), "1", "1" );
81 assertVersions( new File( verifier.getArtifactPath( "org.apache.maven.its.mng3057", "level3", "1", "pom" ) ), "1", "1" );
82
83 assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/mng-3057/1/mng-3057-1.pom" ), "1", null );
84 assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
85 assertVersions( new File( remoteRepo, "org/apache/maven/its/mng3057/level2/1/level2-1.pom" ), "1", "1" );
86 }
87
88 private void assertVersions( File file, String version, String parentVersion )
89 throws XmlPullParserException, IOException
90 {
91 Xpp3Dom dom = Xpp3DomBuilder.build( ReaderFactory.newXmlReader( file ) );
92 assertEquals( version, dom.getChild( "version" ).getValue() );
93 Xpp3Dom parent = dom.getChild( "parent" );
94 if ( parentVersion != null )
95 {
96 assertNotNull( parent );
97 assertEquals( parentVersion, parent.getChild( "version" ).getValue() );
98 }
99 else
100 {
101 assertNull( parent );
102 }
103 }
104
105 }