1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.it;
20
21 import java.io.File;
22 import java.util.List;
23 import java.util.regex.Pattern;
24 import org.apache.maven.it.util.ResourceExtractor;
25
26
27
28
29
30
31 public class MavenITmng4463DependencyManagementImportVersionRanges
32 extends AbstractMavenIntegrationTestCase
33 {
34
35 public MavenITmng4463DependencyManagementImportVersionRanges()
36 {
37 super( "[4.0.0-alpha-1,)" );
38 }
39
40 public void testInclusiveUpperBoundResolvesToHighestVersion()
41 throws Exception
42 {
43 final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/inclusive-upper-bound" );
44 final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
45 verifier.setAutoclean( false );
46 verifier.deleteDirectory( "target" );
47 verifier.executeGoal( "validate" );
48 verifier.verifyErrorFreeLog();
49 verifier.resetStreams();
50
51 final List<String> artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" );
52 assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) );
53 }
54
55 public void testExclusiveUpperBoundResolvesToHighestVersion()
56 throws Exception
57 {
58 final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/exclusive-upper-bound" );
59 final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
60 verifier.setAutoclean( false );
61 verifier.deleteDirectory( "target" );
62 verifier.executeGoal( "validate" );
63 verifier.verifyErrorFreeLog();
64 verifier.resetStreams();
65
66 List<String> artifacts = verifier.loadLines( "target/compile.txt", "UTF-8" );
67 assertTrue( artifacts.toString(), artifacts.contains( "org.apache.maven:maven-plugin-api:jar:3.0" ) );
68 }
69
70 public void testFailureWithoutUpperBound()
71 throws Exception
72 {
73 final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4463/no-upper-bound" );
74 final Verifier verifier = newVerifier( testDir.getAbsolutePath(), "remote" );
75
76 try
77 {
78 verifier.setAutoclean( false );
79 verifier.deleteDirectory( "target" );
80 verifier.executeGoal( "validate" );
81 fail( "Expected 'VerificationException' not thrown." );
82 }
83 catch ( final VerificationException e )
84 {
85 final List<String> lines = verifier.loadFile( new File( testDir, "log.txt" ), false );
86 assertTrue( "Expected error message not found.",
87 indexOf( lines, ".*dependency version range.*does not specify an upper bound.*" ) >= 0 );
88 }
89 finally
90 {
91 verifier.resetStreams();
92 }
93 }
94
95 private static int indexOf( final List<String> logLines, final String regex )
96 {
97 final Pattern pattern = Pattern.compile( regex );
98
99 for ( int i = 0, l0 = logLines.size(); i < l0; i++ )
100 {
101 if ( pattern.matcher( logLines.get( i ) ).matches() )
102 {
103 return i;
104 }
105 }
106
107 return -1;
108 }
109
110 }