View Javadoc

1   package org.apache.maven.wagon.tck.http;
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.wagon.Wagon;
23  import org.codehaus.classworlds.ClassRealm;
24  import org.codehaus.plexus.PlexusConstants;
25  import org.codehaus.plexus.PlexusContainer;
26  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
27  import org.codehaus.plexus.component.configurator.ComponentConfigurator;
28  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
29  import org.codehaus.plexus.configuration.PlexusConfiguration;
30  import org.codehaus.plexus.context.Context;
31  import org.codehaus.plexus.context.ContextException;
32  import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
33  
34  public class WagonTestCaseConfigurator
35      implements Contextualizable
36  {
37      private static final String UNSUPPORTED_ELEMENT = "unsupported";
38  
39      private PlexusConfiguration useCaseConfigs;
40  
41      private ComponentConfigurator configurator;
42  
43      private ClassRealm realm;
44  
45      private String wagonHint;
46  
47      public boolean isSupported( final String useCaseId )
48      {
49          if ( useCaseConfigs != null )
50          {
51              PlexusConfiguration config = useCaseConfigs.getChild( useCaseId, false );
52  
53              if ( config != null && config.getChild( UNSUPPORTED_ELEMENT, false ) != null )
54              {
55                  System.out.println( "Test case '" + useCaseId + "' is marked as unsupported by this wagon." );
56                  return false;
57              }
58          }
59  
60          return true;
61      }
62  
63      public boolean configureWagonForTest( final Wagon wagon, final String useCaseId )
64          throws ComponentConfigurationException
65      {
66          if ( useCaseConfigs != null )
67          {
68              PlexusConfiguration config = useCaseConfigs.getChild( useCaseId, false );
69  
70              if ( config != null )
71              {
72                  if ( config.getChild( UNSUPPORTED_ELEMENT, false ) != null )
73                  {
74                      System.out.println( "Test case '" + useCaseId + "' is marked as unsupported by this wagon." );
75                      return false;
76                  }
77                  else
78                  {
79                      System.out.println( "Configuring wagon for test case: " + useCaseId + " with:\n\n" + config );
80                      configurator.configureComponent( wagon, useCaseConfigs.getChild( useCaseId, false ), realm );
81                  }
82              }
83              else
84              {
85                  System.out.println( "No wagon configuration found for test case: " + useCaseId );
86              }
87          }
88          else
89          {
90              System.out.println( "No test case configurations found." );
91          }
92  
93          return true;
94      }
95  
96      public void contextualize( final Context context )
97          throws ContextException
98      {
99          PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
100         this.realm = container.getContainerRealm();
101         try
102         {
103             configurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
104         }
105         catch ( ComponentLookupException e )
106         {
107             throw new ContextException( "Failed to lookup component configurator: " + e.getMessage(), e );
108         }
109     }
110 
111     public PlexusConfiguration getUseCaseConfigs()
112     {
113         return useCaseConfigs;
114     }
115 
116     public void setUseCaseConfigs( final PlexusConfiguration useCaseConfigs )
117     {
118         this.useCaseConfigs = useCaseConfigs;
119     }
120 
121     public String getWagonHint()
122     {
123         return wagonHint;
124     }
125 
126     public void setWagonHint( final String wagonHint )
127     {
128         this.wagonHint = wagonHint;
129     }
130 
131 }