View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4771">MNG-4771</a>.
39   *
40   * @author Benjamin Bentmann
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       * Verify that repositories which have both releases and snapshots disabled aren't touched when looking for
53       * plugin prefix mappings.
54       *
55       * @throws Exception in case of failure
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             // expected
106         }
107         finally
108         {
109             verifier.resetStreams();
110             server.stop();
111             server.join();
112         }
113 
114         assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
115     }
116 }