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