Java Code Examples for org.codehaus.plexus.DefaultContainerConfiguration#setComponentVisibility()

The following examples show how to use org.codehaus.plexus.DefaultContainerConfiguration#setComponentVisibility() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlexusTestRunner.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
@Override
protected Object createTest()
    throws Exception
{
    final TestClass testClass = getTestClass();

    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();

    // setAutoWiring is set implicitly by below.
    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( testClass.getName() );

    final DefaultPlexusContainer container = new DefaultPlexusContainer( config );
    final ClassSpace cs = new URLClassSpace( Thread.currentThread().getContextClassLoader() );

    container.addPlexusInjector( Collections.<PlexusBeanModule>singletonList( new PlexusAnnotatedBeanModule( cs, Collections.emptyMap() ) ) );

    return container.lookup( testClass.getJavaClass() );
}
 
Example 2
Source File: GroovyFunctionsTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverrideWithTemp() throws Exception
{
    final File base = TestUtils.resolveFileResource( "groovy-project-removal", "" );
    final File root = temporaryFolder.newFolder();
    FileUtils.copyDirectory( base, root);
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();

    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );

    final PlexusContainer container = new DefaultPlexusContainer( config);
    final PomIO pomIO = container.lookup( PomIO.class );
    final List<Project> projects = pomIO.parseProject( new File( root, "pom.xml" ) );

    assertThat( projects.size(), equalTo(3) );

    BaseScriptImplTest impl = new BaseScriptImplTest();
    Properties p = new Properties(  );
    p.setProperty( "versionIncrementalSuffix", "temporary-redhat" );
    p.setProperty( "restRepositoryGroup", "GroovyWithTemporary" );
    p.setProperty( "restURL", mockServer.getUrl() );

    impl.setValues(pomIO, null, null, TestUtils.createSession( p ), projects, projects.get( 0 ), InvocationStage.FIRST );

    impl.overrideProjectVersion( SimpleProjectVersionRef.parse( "org.goots:sample:1.0.0" ) );
}
 
Example 3
Source File: GroovyFunctionsTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void testTempOverrideWithNonTemp() throws Exception
{
    final File base = TestUtils.resolveFileResource( "profile.pom", "" );
    final File root = temporaryFolder.newFolder();
    final File target = new File ( root, "profile.xml");
    FileUtils.copyFile( base, target);
    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();

    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );

    final PlexusContainer container = new DefaultPlexusContainer( config);
    final PomIO pomIO = container.lookup( PomIO.class );
    final List<Project> projects = pomIO.parseProject( target );

    assertThat( projects.size(), equalTo(1) );

    BaseScriptImplTest impl = new BaseScriptImplTest();
    Properties p = new Properties(  );
    p.setProperty( "versionIncrementalSuffix", "temporary-redhat" );
    p.setProperty( "restRepositoryGroup", "GroovyWithTemporary" );
    p.setProperty( "restURL", mockServer.getUrl() );

    impl.setValues(pomIO, null, null, TestUtils.createSession( p ), projects, projects.get( 0 ), InvocationStage.FIRST );

    impl.overrideProjectVersion( SimpleProjectVersionRef.parse( "org.goots:testTempOverrideWithNonTemp:1.0.0" ) );

    assertEquals( "redhat-5",
                  impl.getUserProperties().getProperty( VersioningState.VERSION_SUFFIX_SYSPROP ) );
}
 
Example 4
Source File: InitialGroovyManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRemoveProjectInGroovyScript() throws Exception
{
    final File groovy = TestUtils.resolveFileResource( "groovy-project-removal", "manipulation.groovy" );
    final File base = TestUtils.resolveFileResource( "groovy-project-removal", "" );
    final File root = tf.newFolder();
    FileUtils.copyDirectory( base, root );
    final File projectroot = new File ( root, "pom.xml");

    final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
    config.setClassPathScanning( PlexusConstants.SCANNING_ON );
    config.setComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );
    config.setName( "PME-CLI" );
    PlexusContainer container = new DefaultPlexusContainer( config );

    PomIO pomIO = container.lookup( PomIO.class );

    List<Project> projects = pomIO.parseProject( projectroot );

    assertThat( projects.size(), equalTo( 3 ) );

    Properties userProperties = new Properties();
    userProperties.setProperty( "versionIncrementalSuffix", "rebuild" );
    userProperties.setProperty( "groovyScripts", groovy.toURI().toString() );

    TestUtils.SMContainer smc = TestUtils.createSessionAndManager( userProperties );
    smc.getRequest().setPom( projectroot );
    smc.getManager().scanAndApply( smc.getSession() );

    // re-read the projects:
    projects = pomIO.parseProject( projectroot );
    assertThat( projects.size(), equalTo( 3 ) );

    assertEquals( 1, projectForArtifactId( projects, "groovy-project-removal").getModel().getProfiles().size() );
    assertThat( projectForArtifactId( projects, "groovy-project-removal" ).getVersion(), containsString( "rebuild" ) );
    assertThat( projectForArtifactId( projects, "groovy-project-removal-moduleA" ).getVersion(),
                containsString( "rebuild" ) );
    // moduleB was removed from projects by the groovy script and therefore should not be reversioned:
    assertThat( projectForArtifactId( projects, "groovy-project-removal-moduleB" ).getVersion(), equalTo( "1.0.0" ) );
}
 
Example 5
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void initialize()
    throws PlexusSisuBridgeException
{
    DefaultContainerConfiguration conf = new DefaultContainerConfiguration();

    conf.setAutoWiring( containerAutoWiring );
    conf.setClassPathScanning( containerClassPathScanning );
    conf.setComponentVisibility( containerComponentVisibility );

    conf.setContainerConfigurationURL( overridingComponentsXml );

    ClassWorld classWorld = new ClassWorld();

    ClassLoader tccl = Thread.currentThread().getContextClassLoader();

    containerRealm = new ClassRealm( classWorld, "maven", tccl );

    // olamy hackhish but plexus-sisu need a URLClassLoader with URL filled

    if ( tccl instanceof URLClassLoader )
    {
        URL[] urls = ( (URLClassLoader) tccl ).getURLs();
        for ( URL url : urls )
        {
            containerRealm.addURL( url );
            log.debug("Added url {}", url);
        }
    }

    conf.setRealm( containerRealm );

    //conf.setClassWorld( classWorld );

    ClassLoader ori = Thread.currentThread().getContextClassLoader();

    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        InternalBinder binder = new InternalBinder( );
        plexusContainer = new DefaultPlexusContainer( conf, binder );

    }
    catch ( PlexusContainerException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    } catch (Throwable ex) {
        log.error("PlexusSisuBridge initialization failed {}", ex.getMessage(), ex);
        throw new PlexusSisuBridgeException( ex.getMessage(), ex );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}