org.codehaus.plexus.ContainerConfiguration Java Examples

The following examples show how to use org.codehaus.plexus.ContainerConfiguration. 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: 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 #3
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 #4
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);
//            }
    }