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