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 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.nio.file.Files;
34 import java.nio.file.Path;
35 import java.util.Arrays;
36
37
38
39
40
41
42 public class MavenITmng5868NoDuplicateAttachedArtifacts
43 extends AbstractMavenIntegrationTestCase
44 {
45
46 private File testDir;
47
48 private Server server;
49
50 private int port;
51
52 private int deployedJarArtifactNumber = 0;
53
54 public MavenITmng5868NoDuplicateAttachedArtifacts()
55 {
56 super( "[3.8.2,)" );
57 }
58
59 @Override
60 protected void setUp()
61 throws Exception
62 {
63 testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5868" );
64
65 Handler repoHandler = new AbstractHandler()
66 {
67 @Override
68 public void handle( String target, Request baseRequest, HttpServletRequest request,
69 HttpServletResponse response )
70 {
71 System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
72
73 if ( "PUT".equalsIgnoreCase( request.getMethod() ) )
74 {
75 String uri = request.getRequestURI();
76 if (uri.startsWith( "/repo/org/apache/maven/its/mng5868/mng5868/1.0-SNAPSHOT/mng5868-1.0" ) && uri.endsWith( "-run.jar" ))
77 {
78 deployedJarArtifactNumber++;
79 }
80 response.setStatus( HttpServletResponse.SC_OK );
81 }
82 else
83 {
84 response.setStatus( HttpServletResponse.SC_NOT_FOUND );
85 }
86
87 ( (Request) request ).setHandled( true );
88 }
89 };
90
91 server = new Server( 0 );
92
93 HandlerList handlerList = new HandlerList();
94 handlerList.addHandler( repoHandler );
95
96 server.setHandler( handlerList );
97 server.start();
98 if ( server.isFailed() )
99 {
100 fail( "Couldn't bind the server socket to a free port!" );
101 }
102 port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
103 System.out.println( "Bound server socket to the port " + port );
104 }
105
106 @Override
107 protected void tearDown()
108 throws Exception
109 {
110 if ( server != null )
111 {
112 server.stop();
113 server.join();
114 }
115 }
116
117 public void testNoDeployNotDuplicate()
118 throws Exception
119 {
120 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
121 Path tmp = Files.createTempFile( testDir.toPath(), "FOO", "txt");
122
123 verifier.setAutoclean( false );
124 verifier.deleteDirectory( "target" );
125 verifier.deleteArtifacts( "org.apache.maven.its.mng5868" );
126 verifier.addCliOption( "-Dartifact.attachedFile=" + tmp.toFile().getCanonicalPath() );
127 verifier.addCliOption( "-DdeploymentPort=" + port );
128 verifier.displayStreamBuffers();
129 verifier.executeGoals( Arrays.asList("org.apache.maven.its.plugins:maven-it-plugin-artifact:2.1-SNAPSHOT:attach", "deploy" ) );
130 verifier.verifyErrorFreeLog();
131 verifier.resetStreams();
132 assertEquals("deployedJarArtifactNumber: " + deployedJarArtifactNumber, 1, deployedJarArtifactNumber );
133 }
134
135 }