Refine search
ContainerConfiguration cc = new DefaultContainerConfiguration() // .setClassWorld( cliRequest.classWorld ) // .setRealm( containerRealm ) // .setClassPathScanning( PlexusConstants.SCANNING_INDEX ) // .setAutoWiring( true ) // .setJSR250Lifecycle( true ) // .setName( "maven" ); DefaultPlexusContainer container = new DefaultPlexusContainer( cc, new AbstractModule() container.setLookupRealm( null ); container.setLoggerManager( plexusLoggerManager ); container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() ); Thread.currentThread().setContextClassLoader( container.getContainerRealm() ); executionRequestPopulator = container.lookup( MavenExecutionRequestPopulator.class ); configurationProcessors = container.lookupMap( ConfigurationProcessor.class ); BootstrapCoreExtensionManager resolver = container.lookup( BootstrapCoreExtensionManager.class ); container.dispose();
public TeslaTranslatorCli(ClassWorld classWorld) throws Exception { if (classWorld == null) { classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); } ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld(classWorld).setName("translator"); container = new DefaultPlexusContainer(cc); translator = container.lookup(TeslaModelTranslator.class); }
public void removeComponentRealm( ClassRealm realm ) throws PlexusContainerException { if ( getContainerRealm().getId().equals( realm.getId() ) ) { throw new IllegalArgumentException( "Cannot remove container realm: " + realm.getId() + "\n(trying to remove container realm as if it were a component realm)." ); } componentRegistry.removeComponentRealm( realm ); ClassRealm lookupRealm = getLookupRealm(); if ( ( lookupRealm != null ) && lookupRealm.getId().equals( realm.getId() ) ) { setLookupRealm( getContainerRealm() ); } }
public Maven30xRuntime(Module[] modules) throws Exception { ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); ContainerConfiguration cc = new DefaultContainerConfiguration() // .setClassWorld(classWorld) // .setClassPathScanning(PlexusConstants.SCANNING_INDEX) // .setAutoWiring(true) // .setName("maven"); this.container = new DefaultPlexusContainer(cc, modules); this.mojoDescriptors = Collections.unmodifiableMap(readPluginXml(container)); }
/** * code from org.apache.maven.cli.MavenCli.container(CliRequest) * <p> * cf also https://github.com/igor-suhorukov/mvn-classloader/blob/master/dropship/src/main/java/com/github/smreed/dropship/ClassLoaderBuilder.java */ private static PlexusContainer mvnContainer() { ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory(); Slf4jLoggerManager plexusLoggerManager = new Slf4jLoggerManager(); ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); DefaultPlexusContainer container = null; ContainerConfiguration cc = new DefaultContainerConfiguration() .setClassWorld(classWorld) .setClassPathScanning(PlexusConstants.SCANNING_INDEX) .setAutoWiring(true) .setName("maven"); try { container = new DefaultPlexusContainer(cc, new AbstractModule() { protected void configure() { bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory); } }); } catch (PlexusContainerException e) { LOGGER.error("unable to create PlexusContainer", e); } // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups container.setLookupRealm(null); container.setLoggerManager(plexusLoggerManager); Thread.currentThread().setContextClassLoader(container.getContainerRealm()); return container; }
public static int main( String[] args ) throws Exception { ClassLoader orig = Thread.currentThread().getContextClassLoader(); try { ClassRealm containerRealm = (ClassRealm) Thread.currentThread().getContextClassLoader(); ContainerConfiguration cc = new DefaultContainerConfiguration().setName( "maven" ) .setRealm( containerRealm ); DefaultPlexusContainer container = new DefaultPlexusContainer( cc ); MavenLoggerManager mavenLoggerManager = new MavenLoggerManager( new PrintStreamLogger( System.out ) ); container.setLoggerManager( mavenLoggerManager ); Maven maven = (Maven) container.lookup( "org.apache.maven.Maven", "default" ); MavenExecutionRequest request = getMavenExecutionRequest( args, container ); MavenExecutionResult result = maven.execute( request ); hudsonMavenExecutionResult = new HudsonMavenExecutionResult( result ); // we don't care about cli mavenExecutionResult will be study in the the plugin return 0;// cli.doMain( args, null ); } catch ( ComponentLookupException e ) { throw new Exception( e.getMessage(), e ); } finally { Thread.currentThread().setContextClassLoader( orig ); } }
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() .setName( "test" ) .setContext( context.getContextData() ); containerConfiguration.setContainerConfiguration( config ); containerConfiguration.setContainerConfiguration( resource ); container = new DefaultPlexusContainer( containerConfiguration );
new DefaultContainerConfiguration().setName( "maven" ).setRealm( containerRealm ).setClassPathScanning( PlexusConstants.SCANNING_INDEX ).setAutoWiring( true ); DefaultPlexusContainer container = new DefaultPlexusContainer( cc ); Slf4jLoggerManager mavenLoggerManager = new Slf4jLoggerManager(); container.setLoggerManager( mavenLoggerManager ); Maven maven = (Maven) container.lookup( "org.apache.maven.Maven", "default" ); EventSpyDispatcher eventSpyDispatcher = container.lookup( EventSpyDispatcher.class ); List<EventSpy> spies = container.lookupList( EventSpy.class ); if (spies != null && !spies.isEmpty())
/** * This method will start the container, this is a non-blocking method, and will return once container has started * * @throws Exception */ public void startContainer() throws Exception { ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld( world ).setContainerConfiguration( configuration.getAbsolutePath() ).setContext( createContainerContext() ); container = new DefaultPlexusContainer( cc ); }
protected void setupContainer() { ContainerConfiguration cc = setupContainerConfiguration(); try { List<Module> modules = new ArrayList<Module>(); addGuiceModules( modules ); container = new DefaultPlexusContainer( cc, modules.toArray( new Module[modules.size()] ) ); } catch ( PlexusContainerException e ) { e.printStackTrace(); fail( "Failed to create plexus container." ); } }
public static ComponentManager initializePlexus() throws PlexusContainerException { DefaultContainerConfiguration configuration = new DefaultContainerConfiguration(); DefaultPlexusContainer container = new DefaultPlexusContainer(configuration); // Register the XWiki Lifecycle Handler // TODO: Can only be used with more recent Plexus versions. When this is done the plexus.xml file // can be removed. /* LifecycleHandler handler = new XWikiLifecycleHandler(); handler.addBeginSegment(new LogEnablePhase()); handler.addBeginSegment(new ComposePhase()); handler.addBeginSegment(new InitializePhase()); configuration.addLifecycleHandler(handler); */ return new PlexusComponentManager(container); } }
public static RepositorySystem newRepositorySystem() { /* * Aether's components are equipped with plexus-specific metadata to enable discovery and wiring of components * by a Plexus container so this is as easy as looking up the implementation. */ try { ContainerConfiguration config = new DefaultContainerConfiguration(); config.setAutoWiring( true ); config.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); return new DefaultPlexusContainer( config ).lookup( RepositorySystem.class ); } catch ( Exception e ) { throw new IllegalStateException( "dependency injection failed", e ); } }
@Override public void initialize() throws InitializationException { try { ContainerConfiguration config = new DefaultContainerConfiguration(); config.setAutoWiring(true); config.setClassPathScanning(PlexusConstants.SCANNING_INDEX); this.plexusContainer = new DefaultPlexusContainer(config); this.plexusContainer.setLoggerManager(new XWikiLoggerManager(this.logger)); } catch (PlexusContainerException e) { throw new InitializationException("Failed to initialize Maven", e); } }
@Override public DefaultPlexusContainer call() throws Exception { try { ContainerConfiguration config = new DefaultContainerConfiguration().setAutoWiring(true) .setClassPathScanning(PlexusConstants.SCANNING_INDEX); plexusContainer = new DefaultPlexusContainer(config); // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups plexusContainer.setLookupRealm(null); ConsoleLoggerManager loggerManager = new ConsoleLoggerManager(); loggerManager.setThreshold("ERROR"); plexusContainer.setLoggerManager(loggerManager); return plexusContainer; } catch (Exception e) { throw new RuntimeException( "Could not initialize Maven", e); } } });
public static DefaultPlexusContainer container(ClassWorld classWorld, ClassRealm realm, int loglevel) { DefaultContainerConfiguration config; DefaultPlexusContainer container; config = new DefaultContainerConfiguration(); if (classWorld != null) { config.setClassWorld(classWorld); } if (realm != null) { config.setRealm(realm); } config.setAutoWiring(true); config.setClassPathScanning(PlexusConstants.SCANNING_INDEX); try { container = new DefaultPlexusContainer(config); } catch (PlexusContainerException e) { throw new IllegalStateException(e); } container.getLoggerManager().setThreshold(loglevel); return container; }
public void execute( AppDeploymentContext context ) throws AppDeploymentException { String name = "plexus.application." + context.getApplicationId(); // ---------------------------------------------------------------------------- // Create the container and start // ---------------------------------------------------------------------------- DefaultPlexusContainer applicationContainer; try { addLibJars( context, name ); // This call will initialise and start the container String config = context.getAppConfigurationFile() == null ? null : context.getAppConfigurationFile().getAbsolutePath(); ContainerConfiguration cc= new DefaultContainerConfiguration(); cc.setName( name ); cc.setContext( context.getContextValues() ); cc.setClassWorld( context .getAppRuntimeProfile().getApplicationWorld() ); cc.setContainerConfiguration( config ); cc.setParentContainer( context.getAppServerContainer() ); applicationContainer = new DefaultPlexusContainer( cc ); } catch ( PlexusContainerException e ) { throw new AppDeploymentException( "Error starting container.", e ); } context.getAppRuntimeProfile().setApplicationContainer( applicationContainer ); }
private static PlexusContainer buildPlexusContainer(MavenRequest mavenRequest,ContainerConfiguration containerConfiguration ) throws MavenEmbedderException { try { DefaultPlexusContainer plexusContainer = new DefaultPlexusContainer( containerConfiguration ); if (mavenRequest.getMavenLoggerManager() != null) { plexusContainer.setLoggerManager( mavenRequest.getMavenLoggerManager() ); } if (mavenRequest.getLoggingLevel() > 0) { plexusContainer.getLoggerManager().setThreshold( mavenRequest.getLoggingLevel() ); } return plexusContainer; } catch ( PlexusContainerException e ) { throw new MavenEmbedderException( e.getMessage(), e ); } }
/** * Start the Plexus container. * * @throws PlexusContainerException if any */ private void startPlexusContainer() throws PlexusContainerException { if ( plexus != null ) { return; } Map context = new HashMap(); context.put( "basedir", new File( "" ).getAbsolutePath() ); ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration(); containerConfiguration.setName( "Doxia" ); containerConfiguration.setContext( context ); plexus = new DefaultPlexusContainer( containerConfiguration ); }
private PlexusContainer createContainer() throws Exception { DefaultContainerConfiguration config = new DefaultContainerConfiguration(); // When running under ClassWorlds already, then set the containers realm to the current realm ClassLoader cl = getClass().getClassLoader(); if (cl instanceof ClassRealm) { config.setRealm((ClassRealm)cl); } else { // Else, when testing, setup a new realm ClassWorld classWorld = new ClassWorld(); ClassRealm classRealm = classWorld.newRealm("testing", getClass().getClassLoader()); config.setRealm(classRealm); } DefaultPlexusContainer container = new DefaultPlexusContainer(config); container.setLoggerManager(new Slf4jLoggingManager()); log.debug("Constructed Plexus container: {}", container); return container; }
public PlexusContainer createChildContainer( String name, ClassRealm realm ) throws PlexusContainerException { if ( hasChildContainer( name ) ) { throw new DuplicateChildContainerException( getName(), name ); } ContainerConfiguration c = new DefaultContainerConfiguration() .setName( name ).setParentContainer( this ).setClassWorld( new ClassWorld( name, realm ) ); PlexusContainer childContainer = new DefaultPlexusContainer( c ); childContainers.put( name, childContainer ); return childContainer; }