1 package org.apache.archiva.common.plexusbridge;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.codehaus.plexus.DefaultContainerConfiguration;
23 import org.codehaus.plexus.DefaultPlexusContainer;
24 import org.codehaus.plexus.PlexusConstants;
25 import org.codehaus.plexus.PlexusContainerException;
26 import org.codehaus.plexus.classworlds.ClassWorld;
27 import org.codehaus.plexus.classworlds.realm.ClassRealm;
28 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
29 import org.springframework.stereotype.Service;
31 import javax.annotation.PostConstruct;
33 import java.util.List;
37 * Simple component which will initiate the plexus shim component
38 * to see plexus components inside a guice container.<br/>
39 * So move all of this here to be able to change quickly if needed.
41 * @author Olivier Lamy
43 @Service( "plexusSisuBridge" )
44 public class PlexusSisuBridge
47 private boolean containerAutoWiring = false;
49 private String containerClassPathScanning = PlexusConstants.SCANNING_OFF;
51 private String containerComponentVisibility = PlexusConstants.REALM_VISIBILITY;
53 private URL overridingComponentsXml;
55 private DefaultPlexusContainer plexusContainer;
58 public void initialize()
59 throws PlexusSisuBridgeException
61 DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
63 conf.setAutoWiring( containerAutoWiring );
64 conf.setClassPathScanning( containerClassPathScanning );
65 conf.setComponentVisibility( containerComponentVisibility );
67 conf.setContainerConfigurationURL( overridingComponentsXml );
69 ClassWorld classWorld = new ClassWorld();
71 ClassRealm classRealm = new ClassRealm( classWorld, "maven", Thread.currentThread().getContextClassLoader() );
72 conf.setRealm( classRealm );
74 conf.setClassWorld( classWorld );
78 plexusContainer = new DefaultPlexusContainer( conf );
80 catch ( PlexusContainerException e )
82 throw new PlexusSisuBridgeException( e.getMessage(), e );
86 public <T> T lookup( Class<T> clazz )
87 throws PlexusSisuBridgeException
91 return plexusContainer.lookup( clazz );
93 catch ( ComponentLookupException e )
95 throw new PlexusSisuBridgeException( e.getMessage(), e );
99 public <T> T lookup( Class<T> clazz, String hint )
100 throws PlexusSisuBridgeException
104 return plexusContainer.lookup( clazz, hint );
106 catch ( ComponentLookupException e )
108 throw new PlexusSisuBridgeException( e.getMessage(), e );
112 public <T> List<T> lookupList( Class<T> clazz )
113 throws PlexusSisuBridgeException
117 return plexusContainer.lookupList( clazz );
119 catch ( ComponentLookupException e )
121 throw new PlexusSisuBridgeException( e.getMessage(), e );
125 public <T> Map<String, T> lookupMap( Class<T> clazz )
126 throws PlexusSisuBridgeException
130 return plexusContainer.lookupMap( clazz );
132 catch ( ComponentLookupException e )
134 throw new PlexusSisuBridgeException( e.getMessage(), e );