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.eclipse.jetty.server.Handler;
24 import org.eclipse.jetty.server.NetworkConnector;
25 import org.eclipse.jetty.server.Request;
26 import org.eclipse.jetty.server.Server;
27 import org.eclipse.jetty.server.handler.AbstractHandler;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.io.File;
32 import java.io.IOException;
33 import java.util.Properties;
34
35
36
37
38
39
40
41 public class MavenITmng3461MirrorMatchingTest
42 extends AbstractMavenIntegrationTestCase
43 {
44
45 public MavenITmng3461MirrorMatchingTest()
46 {
47 super( "(2.0.8,)" );
48 }
49
50
51
52
53
54
55
56 public void testitExactMatchDominatesWildcard()
57 throws Exception
58 {
59 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3461/test-1" );
60
61 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
62 verifier.setAutoclean( false );
63 verifier.deleteArtifacts( "org.apache.maven.its.mng3461" );
64 Properties filterProps = verifier.newDefaultFilterProperties();
65 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
66 verifier.addCliOption( "--settings" );
67 verifier.addCliOption( "settings.xml" );
68 verifier.executeGoal( "validate" );
69 verifier.verifyErrorFreeLog();
70 verifier.resetStreams();
71
72 verifier.assertArtifactPresent( "org.apache.maven.its.mng3461", "a", "0.1", "jar" );
73 }
74
75
76
77
78
79
80
81 public void testitExternalWildcard()
82 throws Exception
83 {
84 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3461/test-2" );
85
86 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
87
88 Handler repoHandler = new AbstractHandler()
89 {
90 @Override
91 public void handle( String target, Request baseRequest, HttpServletRequest request,
92 HttpServletResponse response )
93 throws IOException
94 {
95 System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
96
97 if ( request.getRequestURI().endsWith( "/b-0.1.jar" ) )
98 {
99 response.setStatus( HttpServletResponse.SC_OK );
100 response.getWriter().println( request.getRequestURI() );
101 }
102 else if ( request.getRequestURI().endsWith( "/b-0.1.pom" ) )
103 {
104 response.setStatus( HttpServletResponse.SC_OK );
105 response.getWriter().println( "<project>" );
106 response.getWriter().println( " <modelVersion>4.0.0</modelVersion>" );
107 response.getWriter().println( " <groupId>org.apache.maven.its.mng3461</groupId>" );
108 response.getWriter().println( " <artifactId>b</artifactId>" );
109 response.getWriter().println( " <version>0.1</version>" );
110 response.getWriter().println( "</project>" );
111 }
112 else
113 {
114 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
115 }
116
117 ( (Request) request ).setHandled( true );
118 }
119 };
120
121 Server server = new Server( 0 );
122 server.setHandler( repoHandler );
123
124 try
125 {
126 server.start();
127 if ( server.isFailed() )
128 {
129 fail( "Couldn't bind the server socket to a free port!" );
130 }
131
132 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
133 System.out.println( "Bound server socket to the port " + port );
134
135 verifier.setAutoclean( false );
136 verifier.deleteArtifacts( "org.apache.maven.its.mng3461" );
137 Properties filterProps = verifier.newDefaultFilterProperties();
138 filterProps.setProperty( "@test.port@", Integer.toString( port ) );
139 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
140 verifier.addCliOption( "--settings" );
141 verifier.addCliOption( "settings.xml" );
142 verifier.executeGoal( "validate" );
143 verifier.verifyErrorFreeLog();
144 verifier.resetStreams();
145 }
146 finally
147 {
148 server.stop();
149 server.join();
150 }
151
152 verifier.assertArtifactPresent( "org.apache.maven.its.mng3461", "a", "0.1", "jar" );
153 verifier.assertArtifactPresent( "org.apache.maven.its.mng3461", "b", "0.1", "jar" );
154 verifier.assertArtifactPresent( "org.apache.maven.its.mng3461", "c", "0.1", "jar" );
155 }
156
157
158
159
160
161
162
163 public void testitNonGreedyWildcard()
164 throws Exception
165 {
166 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3461/test-3" );
167
168 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
169 verifier.setAutoclean( false );
170 verifier.deleteArtifacts( "org.apache.maven.its.mng3461" );
171 Properties filterProps = verifier.newDefaultFilterProperties();
172 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
173 verifier.addCliOption( "--settings" );
174 verifier.addCliOption( "settings.xml" );
175 verifier.executeGoal( "validate" );
176 verifier.verifyErrorFreeLog();
177 verifier.resetStreams();
178
179 verifier.assertArtifactPresent( "org.apache.maven.its.mng3461", "a", "0.1", "jar" );
180 }
181 }