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.io.PrintWriter;
34 import java.util.Date;
35 import java.util.Deque;
36 import java.util.List;
37 import java.util.Properties;
38 import java.util.concurrent.ConcurrentLinkedDeque;
39
40
41
42
43
44
45 public class MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest
46 extends AbstractMavenIntegrationTestCase
47 {
48
49 public MavenITmng4326LocalSnapshotSuppressesRemoteCheckTest()
50 {
51 super( "[3.0-beta-1,)" );
52 }
53
54
55
56
57
58
59
60 public void testit()
61 throws Exception
62 {
63 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4326" );
64
65
66 Verifier verifier = newVerifier( new File( testDir, "dependency" ).getAbsolutePath() );
67 verifier.setAutoclean( false );
68 verifier.deleteArtifacts( "org.apache.maven.its.mng4326" );
69 verifier.deleteDirectory( "target" );
70 verifier.executeGoal( "validate" );
71 verifier.verifyErrorFreeLog();
72 verifier.resetStreams();
73
74 final Deque<String> uris = new ConcurrentLinkedDeque<>();
75
76 Handler repoHandler = new AbstractHandler()
77 {
78 @Override
79 public void handle( String target, Request baseRequest, HttpServletRequest request,
80 HttpServletResponse response )
81 throws IOException
82 {
83 PrintWriter writer = response.getWriter();
84
85 String uri = request.getRequestURI();
86
87 if ( uri.startsWith( "/repo/org/apache/maven/its/mng4326" ) && !uri.endsWith( ".md5" ) && !uri.endsWith(
88 ".sha1" ) )
89 {
90 uris.add( uri.substring( 34 ) );
91 }
92
93 if ( uri.endsWith( "dep/0.1-SNAPSHOT/maven-metadata.xml" ) )
94 {
95 java.text.DateFormat fmt = new java.text.SimpleDateFormat( "yyyyMMddHHmmss" );
96 fmt.setTimeZone( java.util.TimeZone.getTimeZone( "UTC" ) );
97 String now = fmt.format( new Date( System.currentTimeMillis() + 3000 ) );
98
99 response.setStatus( HttpServletResponse.SC_OK );
100 writer.println( "<metadata>" );
101 writer.println( " <groupId>org.apache.maven.its.mng4326</groupId>" );
102 writer.println( " <artifactId>dep</artifactId>" );
103 writer.println( " <version>0.1-SNAPSHOT</version>" );
104 writer.println( " <versioning>" );
105 writer.println( " <snapshot>" );
106 writer.println( " <timestamp>20100329.235556</timestamp>" );
107 writer.println( " <buildNumber>1</buildNumber>" );
108 writer.println( " </snapshot>" );
109 writer.println( " <lastUpdated>" + now + "</lastUpdated>" );
110 writer.println( " </versioning>" );
111 writer.println( "</metadata>" );
112 }
113 else if ( uri.endsWith( ".pom" ) )
114 {
115 response.setStatus( HttpServletResponse.SC_OK );
116 writer.println( "<project>" );
117 writer.println( " <modelVersion>4.0.0</modelVersion>" );
118 writer.println( " <groupId>org.apache.maven.its.mng4326</groupId>" );
119 writer.println( " <artifactId>dep</artifactId>" );
120 writer.println( " <version>0.1-SNAPSHOT</version>" );
121 writer.println( "</project>" );
122 }
123 else if ( uri.endsWith( ".jar" ) )
124 {
125 response.setStatus( HttpServletResponse.SC_OK );
126 writer.println( "empty" );
127 }
128 else
129 {
130 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
131 }
132
133 ( (Request) request ).setHandled( true );
134 }
135 };
136
137 Server server = new Server( 0 );
138 server.setHandler( repoHandler );
139
140 try
141 {
142 server.start();
143 if ( server.isFailed() )
144 {
145 fail( "Couldn't bind the server socket to a free port!" );
146 }
147 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
148 System.out.println( "Bound server socket to the port " + port );
149
150 verifier = newVerifier( new File( testDir, "test" ).getAbsolutePath() );
151 verifier.setAutoclean( false );
152 Properties filterProps = verifier.newDefaultFilterProperties();
153 filterProps.setProperty( "@port@", Integer.toString( port ) );
154 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
155 verifier.addCliOption( "--settings" );
156 verifier.addCliOption( "settings.xml" );
157 verifier.setLogFileName( "log-daily.txt" );
158 verifier.deleteDirectory( "target" );
159 verifier.executeGoal( "validate" );
160 verifier.verifyErrorFreeLog();
161
162 List<String> cp = verifier.loadLines( "target/classpath.txt", "UTF-8" );
163 assertTrue( cp.toString(), cp.contains( "dep-0.1-SNAPSHOT.jar" ) );
164
165 assertFalse( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/maven-metadata.xml" ) );
166 assertFalse( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/dep-0.1-20100329.235556-1.jar" ) );
167
168 uris.clear();
169
170
171 verifier.addCliOption( "-U" );
172 verifier.setLogFileName( "log-force.txt" );
173 verifier.deleteDirectory( "target" );
174 verifier.executeGoal( "validate" );
175 verifier.verifyErrorFreeLog();
176
177 cp = verifier.loadLines( "target/classpath.txt", "UTF-8" );
178 assertTrue( cp.toString(), cp.contains( "dep-0.1-SNAPSHOT.jar" ) );
179
180 assertTrue( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/maven-metadata.xml" ) );
181 assertTrue( uris.toString(), uris.contains( "/dep/0.1-SNAPSHOT/dep-0.1-20100329.235556-1.jar" ) );
182 }
183 finally
184 {
185 verifier.resetStreams();
186 server.stop();
187 }
188 }
189 }