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.NetworkConnector;
24 import org.eclipse.jetty.server.Request;
25 import org.eclipse.jetty.server.Server;
26 import org.eclipse.jetty.server.handler.AbstractHandler;
27 import org.eclipse.jetty.server.handler.DefaultHandler;
28 import org.eclipse.jetty.server.handler.HandlerList;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.File;
33 import java.util.Deque;
34 import java.util.Properties;
35 import java.util.concurrent.ConcurrentLinkedDeque;
36
37
38
39
40
41
42 public class MavenITmng4771PluginPrefixResolutionDoesntTouchDisabledRepoTest
43 extends AbstractMavenIntegrationTestCase
44 {
45
46 public MavenITmng4771PluginPrefixResolutionDoesntTouchDisabledRepoTest()
47 {
48 super( "[2.0.3,3.0-alpha-1),[3.0-beta-3,)" );
49 }
50
51
52
53
54
55
56
57 public void testit()
58 throws Exception
59 {
60 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4771" );
61
62 final Deque<String> requestedUris = new ConcurrentLinkedDeque<>();
63
64 AbstractHandler logHandler = new AbstractHandler()
65 {
66 @Override
67 public void handle( String target, Request baseRequest, HttpServletRequest request,
68 HttpServletResponse response )
69 {
70 requestedUris.add( request.getRequestURI() );
71 }
72 };
73
74 HandlerList handlerList = new HandlerList();
75 handlerList.addHandler( logHandler );
76 handlerList.addHandler( new DefaultHandler() );
77
78 Server server = new Server( 0 );
79 server.setHandler( handlerList );
80 server.start();
81
82 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
83 try
84 {
85 if ( server.isFailed() )
86 {
87 fail( "Couldn't bind the server socket to a free port!" );
88 }
89 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
90 System.out.println( "Bound server socket to the port " + port );
91 verifier.setAutoclean( false );
92 verifier.deleteDirectory( "target" );
93 Properties filterProps = verifier.newDefaultFilterProperties();
94 filterProps.setProperty( "@port@", Integer.toString( port ) );
95 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
96 verifier.addCliOption( "-U" );
97 verifier.addCliOption( "-s" );
98 verifier.addCliOption( "settings.xml" );
99 verifier.executeGoal( "mng4771:touch" );
100 verifier.verifyErrorFreeLog();
101 fail( "Build should have failed to resolve unknown prefix" );
102 }
103 catch ( VerificationException e )
104 {
105
106 }
107 finally
108 {
109 verifier.resetStreams();
110 server.stop();
111 server.join();
112 }
113
114 assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
115 }
116 }