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.ArrayList;
34  import java.util.Collections;
35  import java.util.List;
36  import java.util.Properties;
37  
38  /**
39   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-4772">MNG-4772</a>.
40   *
41   * @author Benjamin Bentmann
42   */
43  public class MavenITmng4772PluginVersionResolutionDoesntTouchDisabledRepoTest
44      extends AbstractMavenIntegrationTestCase
45  {
46  
47      public MavenITmng4772PluginVersionResolutionDoesntTouchDisabledRepoTest()
48      {
49          super( "[2.0.3,3.0-alpha-1),[3.0-beta-3,)" );
50      }
51  
52      /**
53       * Verify that repositories which have both releases and snapshots disabled aren't touched when looking for
54       * the latest plugin version.
55       *
56       * @throws Exception in case of failure
57       */
58      public void testit()
59          throws Exception
60      {
61          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4772" );
62  
63          final List<String> requestedUris = Collections.synchronizedList( new ArrayList<String>() );
64  
65          AbstractHandler logHandler = new AbstractHandler()
66          {
67              @Override
68              public void handle( String target, Request baseRequest, HttpServletRequest request,
69                                  HttpServletResponse response )
70              {
71                  requestedUris.add( request.getRequestURI() );
72              }
73          };
74  
75          HandlerList handlerList = new HandlerList();
76          handlerList.addHandler( logHandler );
77          handlerList.addHandler( new DefaultHandler() );
78  
79          Server server = new Server( 0 );
80          server.setHandler( handlerList );
81          server.start();
82  
83          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
84          try
85          {
86              if ( server.isFailed() )
87              {
88                  fail( "Couldn't bind the server socket to a free port!" );
89              }
90              int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
91              System.out.println( "Bound server socket to the port " + port );
92              verifier.setAutoclean( false );
93              verifier.deleteDirectory( "target" );
94              Properties filterProps = verifier.newDefaultFilterProperties();
95              filterProps.setProperty( "@port@", Integer.toString( port ) );
96              verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
97              verifier.addCliOption( "-U" );
98              verifier.addCliOption( "-s" );
99              verifier.addCliOption( "settings.xml" );
100             verifier.executeGoal( "org.apache.maven.its.mng4772:maven-it-plugin:touch" );
101             verifier.verifyErrorFreeLog();
102             fail( "Build should have failed to resolve version for unknown plugin" );
103         }
104         catch ( VerificationException e )
105         {
106             // expected
107         }
108         finally
109         {
110             verifier.resetStreams();
111             server.stop();
112             server.join();
113         }
114 
115         assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
116     }
117 }