org.codehaus.plexus.PlexusConstants Java Examples

The following examples show how to use org.codehaus.plexus.PlexusConstants. 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: EmbedderFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static @NonNull MavenEmbedder createProjectLikeEmbedder() throws PlexusContainerException {
        final String mavenCoreRealmId = "plexus.core";
        ContainerConfiguration dpcreq = new DefaultContainerConfiguration()
            .setClassWorld( new ClassWorld(mavenCoreRealmId, EmbedderFactory.class.getClassLoader()) )
            .setClassPathScanning( PlexusConstants.SCANNING_INDEX )
            .setName("maven");
        
        DefaultPlexusContainer pc = new DefaultPlexusContainer(dpcreq, new ExtensionModule());
        pc.setLoggerManager(new NbLoggerManager());

        Properties userprops = new Properties();
        userprops.putAll(getCustomGlobalUserProperties());
        EmbedderConfiguration configuration = new EmbedderConfiguration(pc, cloneStaticProps(), userprops, true, getSettingsXml());
        
        try {
            return new MavenEmbedder(configuration);
            //MEVENIDE-634 make all instances non-interactive
//            WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//            wagonManager.setInteractive(false);
        } catch (ComponentLookupException ex) {
            throw new PlexusContainerException(ex.toString(), ex);
        }
    }
 
Example #2
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 #3
Source File: RepositoryUtility.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
static MavenProject createMavenProject(Path pomFile, RepositorySystemSession session)
    throws MavenRepositoryException {
  // MavenCli's way to instantiate PlexusContainer
  ClassWorld classWorld =
      new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
  ContainerConfiguration containerConfiguration =
      new DefaultContainerConfiguration()
          .setClassWorld(classWorld)
          .setRealm(classWorld.getClassRealm("plexus.core"))
          .setClassPathScanning(PlexusConstants.SCANNING_INDEX)
          .setAutoWiring(true)
          .setJSR250Lifecycle(true)
          .setName("linkage-checker");
  try {
    PlexusContainer container = new DefaultPlexusContainer(containerConfiguration);

    MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest projectBuildingRequest =
        mavenExecutionRequest.getProjectBuildingRequest();

    projectBuildingRequest.setRepositorySession(session);

    // Profile activation needs properties such as JDK version
    Properties properties = new Properties(); // allowing duplicate entries
    properties.putAll(projectBuildingRequest.getSystemProperties());
    properties.putAll(OsProperties.detectOsProperties());
    properties.putAll(System.getProperties());
    projectBuildingRequest.setSystemProperties(properties);

    ProjectBuilder projectBuilder = container.lookup(ProjectBuilder.class);
    ProjectBuildingResult projectBuildingResult =
        projectBuilder.build(pomFile.toFile(), projectBuildingRequest);
    return projectBuildingResult.getProject();
  } catch (PlexusContainerException | ComponentLookupException | ProjectBuildingException ex) {
    throw new MavenRepositoryException(ex);
  }
}
 
Example #4
Source File: MockitoComponentTestCase.java    From hermes with Apache License 2.0 5 votes vote down vote up
private <T> void defineComponentWithFactory(Class<T> role, String roleHint) throws Exception {
	super.defineComponent(role, roleHint, role);

	if (roleHint == null) {
		roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT;
	}

	getContainer().getComponentDescriptor(role, role.getName(), roleHint).setComponentFactory(FACTORY);
}
 
Example #5
Source File: NexusRepositoryIndexerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initIndexer () {
    if (!inited) {
        try {
            ContainerConfiguration config = new DefaultContainerConfiguration();
            //#154755 - start
            ClassLoader indexerLoader = NexusRepositoryIndexerImpl.class.getClassLoader();
            ClassWorld classWorld = new ClassWorld();
            ClassRealm plexusRealm = classWorld.newRealm("plexus.core", EmbedderFactory.class.getClassLoader()); //NOI18N
            plexusRealm.importFrom(indexerLoader, "META-INF/sisu"); //NOI18N
            plexusRealm.importFrom(indexerLoader, "org.apache.maven.index"); //NOI18N
            plexusRealm.importFrom(indexerLoader, "org.netbeans.modules.maven.indexer"); //NOI18N
            config.setClassWorld(classWorld);
            config.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
            //#154755 - end
            embedder = new DefaultPlexusContainer(config);

            ComponentDescriptor<ArtifactContextProducer> desc = new ComponentDescriptor<ArtifactContextProducer>();
            desc.setRoleClass(ArtifactContextProducer.class);
            desc.setImplementationClass(CustomArtifactContextProducer.class);
            ComponentRequirement req = new ComponentRequirement(); // XXX why is this not automatic?
            req.setFieldName("mapper");
            req.setRole(ArtifactPackagingMapper.class.getName());
            desc.addRequirement(req);
            embedder.addComponentDescriptor(desc);
            indexer = embedder.lookup(Indexer.class);
            searcher = embedder.lookup(SearchEngine.class);
            remoteIndexUpdater = embedder.lookup(IndexUpdater.class);
            contextProducer = embedder.lookup(ArtifactContextProducer.class);
            scanner = new FastScanner(contextProducer);
            inited = true;
        } catch (Exception x) {
            Exceptions.printStackTrace(x);
        }
    }
}
 
Example #6
Source File: IndexQuerier.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
public IndexQuerier() throws PlexusContainerException, ComponentLookupException {

        DefaultContainerConfiguration config = new DefaultContainerConfiguration();
        config.setClassPathScanning(PlexusConstants.SCANNING_INDEX);

        this.plexusContainer = new DefaultPlexusContainer(config);

        // lookup the indexer components from plexus
        this.indexer = plexusContainer.lookup(Indexer.class);
        this.indexUpdater = plexusContainer.lookup(IndexUpdater.class);
        // lookup wagon used to remotely fetch index
        this.httpWagon = plexusContainer.lookup(Wagon.class, "https");
    }
 
Example #7
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 #8
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 #9
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 #10
Source File: GatewayAbstractMojo.java    From apigee-deploy-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize(Context context) throws ContextException {
	container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
	if (container.hasComponent(SettingsDecrypter.class)) {
		try {
			settingsDecrypter = container.lookup(SettingsDecrypter.class);
		} catch (ComponentLookupException e) {
			getLog().warn("Failed to lookup build in maven component session decrypter.", e);
		}
	}
}
 
Example #11
Source File: AbstractAppAssemblerMojo.java    From appassembler with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize( Context context )
    throws ContextException
{
    container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
 
Example #12
Source File: MdPageGeneratorMojo.java    From markdown-page-generator-plugin with MIT License 4 votes vote down vote up
public void contextualize(Context context) throws ContextException {
    plexusContainer = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #13
Source File: InternalRunMojo.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #14
Source File: BuildMojo.java    From opoopress with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
 
Example #15
Source File: AbstractDeployMojo.java    From opoopress with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #16
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    authConfigFactory = new AuthConfigFactory((PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY));
}
 
Example #17
Source File: DefaultJnlpDependencyRequestBuilder.java    From webstart with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize( final Context context )
        throws ContextException
{
    container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
 
Example #18
Source File: AbstractDockerMojo.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
    plexusContainer = ((PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY));
}
 
Example #19
Source File: RemoteExistsMojo.java    From exists-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void contextualize(Context context) throws ContextException {
  container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #20
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull static MavenEmbedder createOnlineEmbedder() throws PlexusContainerException {
        final String mavenCoreRealmId = "plexus.core";
        ContainerConfiguration dpcreq = new DefaultContainerConfiguration()
            .setClassWorld( new ClassWorld(mavenCoreRealmId, EmbedderFactory.class.getClassLoader()) )
            .setClassPathScanning( PlexusConstants.SCANNING_INDEX )
            .setName("maven");

        DefaultPlexusContainer pc = new DefaultPlexusContainer(dpcreq);
        pc.setLoggerManager(new NbLoggerManager());

        Properties userprops = new Properties();
        userprops.putAll(getCustomGlobalUserProperties());
        EmbedderConfiguration req = new EmbedderConfiguration(pc, cloneStaticProps(), userprops, false, getSettingsXml());

//        //TODO remove explicit activation
//        req.addActiveProfile("netbeans-public").addActiveProfile("netbeans-private"); //NOI18N


//        req.setConfigurationCustomizer(new ContainerCustomizer() {
//
//            public void customize(PlexusContainer plexusContainer) {
//                    //MEVENIDE-634
//                    ComponentDescriptor desc = plexusContainer.getComponentDescriptor(KnownHostsProvider.ROLE, "file"); //NOI18N
//                    desc.getConfiguration().getChild("hostKeyChecking").setValue("no"); //NOI18N
//
//                    //MEVENIDE-634
//                    desc = plexusContainer.getComponentDescriptor(KnownHostsProvider.ROLE, "null"); //NOI18N
//                    desc.getConfiguration().getChild("hostKeyChecking").setValue("no"); //NOI18N
//            }
//        });

        try {
            return new MavenEmbedder(req);
            //MEVENIDE-634 make all instances non-interactive
//            WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//            wagonManager.setInteractive(false);
        } catch (ComponentLookupException ex) {
            throw new PlexusContainerException(ex.toString(), ex);
        }
//            try {
//                //MEVENIDE-634 make all instances non-interactive
//                WagonManager wagonManager = (WagonManager) embedder.getPlexusContainer().lookup(WagonManager.ROLE);
//                wagonManager.setInteractive( false );
//                wagonManager.setDownloadMonitor(new ProgressTransferListener());
//            } catch (ComponentLookupException ex) {
//                ErrorManager.getDefault().notify(ex);
//            }
    }
 
Example #21
Source File: MockitoComponentTestCase.java    From hermes with Apache License 2.0 4 votes vote down vote up
public static <T> void offerMockitoComponent(Class<T> role, String roleHint, T instance) {
	roleHint = roleHint == null ? PlexusConstants.PLEXUS_DEFAULT_HINT : roleHint;
	instances.put(new Pair<Class<?>, String>(role, roleHint), instance);
}
 
Example #22
Source File: TarsBuildMojo.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #23
Source File: AbstractVertxMojo.java    From vertx-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Plexus container.
 *
 * @param context the context
 * @throws ContextException if the container cannot be retrieved.
 */
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #24
Source File: AbstractVertxMojo.java    From vertx-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Plexus container.
 *
 * @param context the context
 * @throws ContextException if the container cannot be retrieved.
 */
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
 
Example #25
Source File: RunMojo.java    From wisdom with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Plexus container.
 * @param context the context
 * @throws ContextException if the container cannot be retrieved.
 */
@Override
public void contextualize(Context context) throws ContextException {
    container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}