org.codehaus.plexus.component.repository.exception.ComponentLookupException Java Examples

The following examples show how to use org.codehaus.plexus.component.repository.exception.ComponentLookupException. 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: MdPageGeneratorMojo.java    From markdown-page-generator-plugin with MIT License 6 votes vote down vote up
/**
 * @param mavenResourcesExecution {@link MavenResourcesExecution}
 * @throws MojoExecutionException  in case of wrong lookup.
 * @throws MavenFilteringException in case of failure.
 * @since 2.5
 */
protected void executeUserFilterComponents(MavenResourcesExecution mavenResourcesExecution)
        throws MojoExecutionException, MavenFilteringException {

    if (mavenFilteringHints != null) {
        for (String hint : mavenFilteringHints) {
            try {
                // CHECKSTYLE_OFF: LineLength
                mavenFilteringComponents.add((MavenResourcesFiltering) plexusContainer.lookup(MavenResourcesFiltering.class.getName(), hint));
                // CHECKSTYLE_ON: LineLength
            } catch (ComponentLookupException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    } else {
        getLog().debug("no use filter components");
    }

    if (mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty()) {
        getLog().debug("execute user filters");
        for (MavenResourcesFiltering filter : mavenFilteringComponents) {
            filter.filterResources(mavenResourcesExecution);
        }
    }
}
 
Example #2
Source File: XPipeDataSource.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(DataSourceDescriptor descriptor) {
    if (ctripDataSourceEnabled) {
        try {
            m_delegate = (DataSource)(Class.forName(ctripDalDataSource).newInstance());
        } catch (Throwable ex) {
            logger.error("Loading ctrip datasource failed", ex);
        }
    }
    if (m_delegate == null) {
        try {
            m_delegate = getContainer().lookup(DataSource.class, "jdbc");
        } catch (ComponentLookupException e) {
            throw new DataSourceException("unidal jdbc datasource not found");
        }
    }
    if (m_delegate instanceof LogEnabled) {
        ((LogEnabled)m_delegate).enableLogging(m_logger);
    }
    m_delegate.initialize(descriptor);

    logger.info("[initialize][DataSource]{}", m_delegate);
}
 
Example #3
Source File: AbstractConsoleH2DbTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
private void setUpTestDataSource() throws ComponentLookupException, SQLException, IOException {

        DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
        DataSource dataSource = dsManager.getDataSource(DATA_SOURCE);
        String driver = dataSource.getDescriptor().getProperty("driver", null);

        if (driver != null && driver.equals("org.h2.Driver")) {
            registerMySQLFunctions();
            executeSqlScript(FileUtils.readFileAsString(TABLE_STRUCTURE));
            executeSqlScript(FileUtils.readFileAsString(TABLE_DATA));
        } else {
            logger.info("[setUpTestDataSource][do not clean]{}", driver);
        }

        executeSqlScript(prepareDatas());
    }
 
Example #4
Source File: AppMultiShardTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
private void insertShards() throws ComponentLookupException, SQLException {

        long currentShardId = beginShardId;
        long currentDcClusterShardId = beginDcClusterShardId;

        for(int i=0; i < shardCount ; i++){

            String shardName = gtShardName(i);
            String insertShard = String.format(
                    "insert into SHARD_TBL " +
                    "(id,shard_name,cluster_id) values (%d, '%s', %d);", currentShardId, shardName, clusterId);
            executeSqlScript(insertShard);

            for(Long dc_cluster_id : dcClusterIds){

                String insertDcClusterShard = String.format(
                        "insert into DC_CLUSTER_SHARD_TBL " +
                        "(dc_cluster_shard_id,dc_cluster_id,shard_id,setinel_id,dc_cluster_shard_phase) " +
                        "values (%d,%d,%d,1,1);", currentDcClusterShardId, dc_cluster_id, currentShardId);
                executeSqlScript(insertDcClusterShard);
                dcClusterShardIds.add(currentDcClusterShardId);
                currentDcClusterShardId++;
            }
            currentShardId++;
        }
    }
 
Example #5
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 #6
Source File: MigrationServiceTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void createTest() throws ComponentLookupException {
	long eventId = migrationService.createMigrationEvent(createEventDemo(1,2));
	MigrationEventTbl result = migrationService.find(eventId);
	MigrationClusterTbl result_cluster = migrationService.findMigrationCluster(eventId, 1);
	ClusterTbl cluster = clusterService.find(1);
	List<MigrationShardTbl> result_shards = migrationService.findMigrationShards(result_cluster.getId());
	
	Assert.assertEquals(eventId, result.getId());
	Assert.assertEquals("unit test", result.getOperator());
	Assert.assertNotNull(result_cluster);
	Assert.assertEquals(1, result_cluster.getClusterId());
	Assert.assertEquals(2, result_cluster.getDestinationDcId());
	Assert.assertEquals(MigrationStatus.Initiated.toString(), result_cluster.getStatus());
	Assert.assertEquals(ClusterStatus.Lock.toString(), cluster.getStatus());
	Assert.assertEquals(2, result_shards.size());
}
 
Example #7
Source File: H2Init.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
private void setUpTestDataSource() throws ComponentLookupException, SQLException, IOException {

        DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
        DataSource dataSource = null;
        try {
            dataSource = dsManager.getDataSource(DATA_SOURCE);
        } catch(Exception e) {
            logger.info("[setUpTestDataSource][ignore if it it not console]{}", e.getMessage());
            return;
        }

        String driver = dataSource.getDescriptor().getProperty("driver", null);
        if (driver != null && driver.equals("org.h2.Driver")) {
            executeSqlScript(FileUtils.readFileAsString(TABLE_STRUCTURE));
            executeSqlScript(FileUtils.readFileAsString(DEMO_DATA));

        } else {
            logger.info("[setUpTestDataSource][do not clean]{}", driver);
        }
    }
 
Example #8
Source File: PlexusComponentLocator.java    From hermes with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T lookup(Class<T> clazz, String roleHint) {
	Pair<Class<?>, String> key = new Pair<Class<?>, String>(clazz, roleHint);

	Object component = m_componentsWithRoleHintCache.get(key);

	if (component == null) {
		synchronized (m_componentsWithRoleHintCache) {
			component = m_componentsWithRoleHintCache.get(key);
			if (component == null) {
				try {
					component = ContainerLoader.getDefaultContainer().lookup(clazz, roleHint);
					m_componentsWithRoleHintCache.put(key, component);
				} catch (ComponentLookupException e) {
					throw new IllegalArgumentException(String.format(
					      "Error: Unable to lookup component %s with roleHint %s!", clazz.getName(), roleHint), e);
				}
			}
		}
	}

	return (T) component;
}
 
Example #9
Source File: PlexusComponentLocator.java    From hermes with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T lookup(Class<T> clazz) {
	Object component = m_componentsCache.get(clazz);

	if (component == null) {
		synchronized (m_componentsCache) {
			component = m_componentsCache.get(clazz);
			if (component == null) {
				try {
					component = ContainerLoader.getDefaultContainer().lookup(clazz);
					m_componentsCache.put(clazz, component);
				} catch (ComponentLookupException e) {
					throw new IllegalArgumentException(String.format("Error: Unable to lookup component %s!",
					      clazz.getName()), e);
				}
			}
		}
	}

	return (T) component;
}
 
Example #10
Source File: ExecMojo.java    From exec-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Toolchain getToolchain()
{
    Toolchain tc = null;

    try
    {
        if ( session != null ) // session is null in tests..
        {
            ToolchainManager toolchainManager =
                (ToolchainManager) session.getContainer().lookup( ToolchainManager.ROLE );

            if ( toolchainManager != null )
            {
                tc = toolchainManager.getToolchainFromBuildContext( toolchain, session );
            }
        }
    }
    catch ( ComponentLookupException componentLookupException )
    {
        // just ignore, could happen in pre-2.0.9 builds..
    }
    return tc;
}
 
Example #11
Source File: DefaultJnlpDependencyRequestBuilder.java    From webstart with MIT License 6 votes vote down vote up
protected <Task extends JnlpDependencyTask> Task registerTask( List<JnlpDependencyTask> tasks, String roleHint,
                                                               JnlpDependencyConfig config )
{
    try
    {
        // create task
        Task result = (Task) container.lookup( JnlpDependencyTask.ROLE, roleHint );

        // check configution
        result.check( config );

        // register task
        tasks.add( result );

        return result;
    }
    catch ( ComponentLookupException e )
    {
        throw new RuntimeException( "Could not find task with roleHint: " + roleHint, e );
    }
}
 
Example #12
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 6 votes vote down vote up
public <T> T lookup( Class<T> clazz )
    throws PlexusSisuBridgeException
{
    ClassLoader ori = Thread.currentThread().getContextClassLoader();
    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        return plexusContainer.lookup( clazz );
    }
    catch ( ComponentLookupException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}
 
Example #13
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 6 votes vote down vote up
public <T> T lookup( Class<T> clazz, String hint )
    throws PlexusSisuBridgeException
{
    ClassLoader ori = Thread.currentThread().getContextClassLoader();

    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        return plexusContainer.lookup( clazz, hint );
    }
    catch ( ComponentLookupException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}
 
Example #14
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 6 votes vote down vote up
public <T> List<T> lookupList( Class<T> clazz )
    throws PlexusSisuBridgeException
{
    ClassLoader ori = Thread.currentThread().getContextClassLoader();

    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        return plexusContainer.lookupList( clazz );
    }
    catch ( ComponentLookupException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}
 
Example #15
Source File: PlexusSisuBridge.java    From archiva with Apache License 2.0 6 votes vote down vote up
public <T> Map<String, T> lookupMap( Class<T> clazz )
    throws PlexusSisuBridgeException
{
    ClassLoader ori = Thread.currentThread().getContextClassLoader();

    try
    {
        Thread.currentThread().setContextClassLoader( containerRealm );
        return plexusContainer.lookupMap( clazz );
    }
    catch ( ComponentLookupException e )
    {
        throw new PlexusSisuBridgeException( e.getMessage(), e );
    }
    finally
    {
        Thread.currentThread().setContextClassLoader( ori );
    }
}
 
Example #16
Source File: AbstractConsoleH2DbTest.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
protected void executeSqlScript(String prepareSql) throws ComponentLookupException, SQLException {

        DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);

        Connection conn = null;
        PreparedStatement stmt = null;
        try {
            conn = dsManager.getDataSource(DATA_SOURCE).getConnection();
            conn.setAutoCommit(false);
            if (!Strings.isEmpty(prepareSql)) {
                for (String sql : prepareSql.split(";")) {
                    logger.debug("[setup][data]{}", sql.trim());
                    stmt = conn.prepareStatement(sql);
                    stmt.executeUpdate();
                }
            }
            conn.commit();

        } catch (Exception ex) {
            logger.error("[SetUpTestDataSource][fail]:", ex);
            if (null != conn) {
                conn.rollback();
            }
        } finally {
            if (null != stmt) {
                stmt.close();
            }
            if (null != conn) {
                conn.setAutoCommit(true);
                conn.close();
            }
        }
    }
 
Example #17
Source File: MigrationShardDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
	try {
		migrationShardDao = ContainerLoader.getDefaultContainer().lookup(MigrationShardTblDao.class);
	} catch (ComponentLookupException e) {
		throw new ServerException("Cannot construct dao.", e);
	}
}
 
Example #18
Source File: DisplayPluginUpdatesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Find optional mojos for lifecycle.
 *
 * @param project the project
 * @param lifecycle the lifecycle
 * @return the list
 * @throws LifecycleExecutionException the lifecycle execution exception
 * @throws PluginNotFoundException the plugin not found exception
 */
private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle )
    throws LifecycleExecutionException, PluginNotFoundException
{
    String packaging = project.getPackaging();
    List<String> optionalMojos = null;

    LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging,
                                                           session.getSettings(), session.getLocalRepository() );

    if ( m != null )
    {
        optionalMojos = m.getOptionalMojos( lifecycle.getId() );
    }

    if ( optionalMojos == null )
    {
        try
        {
            m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
            optionalMojos = m.getOptionalMojos( lifecycle.getId() );
        }
        catch ( ComponentLookupException e )
        {
            getLog().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
                + lifecycle.getId() + ". Error: " + e.getMessage(), e );
        }
    }

    if ( optionalMojos == null )
    {
        optionalMojos = Collections.emptyList();
    }

    return optionalMojos;
}
 
Example #19
Source File: AuthConfigFactoryTest.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void containerSetup() throws ComponentLookupException {
    final SecDispatcher secDispatcher = new MockSecDispatcher();
    new Expectations() {{
        container.lookup(SecDispatcher.ROLE, "maven"); minTimes = 0; result = secDispatcher;

    }};
    factory = new AuthConfigFactory(container);
    factory.setLog(log);

    gsonBuilder = new GsonBuilder();
}
 
Example #20
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 #21
Source File: BuildMojo.java    From opoopress with Apache License 2.0 5 votes vote down vote up
private ResourceBuilder createResourceBuilder(Map<String, Object> buildConfig) throws MojoFailureException {
    String type = (String) buildConfig.get("type");
    if(StringUtils.isBlank(type)){
        throw new MojoFailureException("The type of resource builder is required.");
    }

    try {
        return (ResourceBuilder) container.lookup(ResourceBuilder.class.getName(), type);
    } catch (ComponentLookupException e) {
        throw new MojoFailureException("Resource builder not found in plexus container: " + type, e);
    }
}
 
Example #22
Source File: H2Init.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
protected void executeSqlScript(String prepareSql) throws ComponentLookupException, SQLException {

        DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);

        Connection conn = null;
        PreparedStatement stmt = null;
        try {
            conn = dsManager.getDataSource(DATA_SOURCE).getConnection();
            conn.setAutoCommit(false);
            if (!Strings.isEmpty(prepareSql)) {
                for (String sql : prepareSql.split(";")) {
                    logger.debug("[setup][data]{}", sql.trim());
                    stmt = conn.prepareStatement(sql);
                    stmt.executeUpdate();
                }
            }
            conn.commit();

        } catch (Exception ex) {
            logger.error("[SetUpTestDataSource][fail]:", ex);
            if (null != conn) {
                conn.rollback();
            }
        } finally {
            if (null != stmt) {
                stmt.close();
            }
            if (null != conn) {
                conn.setAutoCommit(true);
                conn.close();
            }
        }
    }
 
Example #23
Source File: MigrationEventDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
	try {
		migrationEventTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationEventTblDao.class);
		migrationClusterTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationClusterTblDao.class);
		migrationShardTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationShardTblDao.class);
		clusterTblDao = ContainerLoader.getDefaultContainer().lookup(ClusterTblDao.class);
		shardTblDao = ContainerLoader.getDefaultContainer().lookup(ShardTblDao.class);
	} catch (ComponentLookupException e) {
		throw new ServerException("Cannot construct dao.", e);
	}
}
 
Example #24
Source File: SentinelServiceImpl.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
	try {
		dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
	} catch (ComponentLookupException e) {
		throw new ServerException("Dao construct failed.", e);
	}
}
 
Example #25
Source File: ProxyDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
    try {
        dao = ContainerLoader.getDefaultContainer().lookup(ProxyTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}
 
Example #26
Source File: MigrationServiceImpl.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() throws ServerException {
    try {
        migrationShardTblDao = ContainerLoader.getDefaultContainer().lookup(MigrationShardTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.");
    }
}
 
Example #27
Source File: ShardDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
	try {
		clusterTblDao = ContainerLoader.getDefaultContainer().lookup(ClusterTblDao.class);
		dcClusterTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterTblDao.class);
		shardTblDao = ContainerLoader.getDefaultContainer().lookup(ShardTblDao.class);
		dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
	} catch (ComponentLookupException e) {
		throw new ServerException("Cannot construct dao.", e);
	}
}
 
Example #28
Source File: DcClusterDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
	try {
		dcClusterTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterTblDao.class);
		dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
	} catch (ComponentLookupException e) {
		throw new ServerException("Cannot construct dao.", e);
	}
}
 
Example #29
Source File: MavenJarUtil.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private List<Artifact> collectDependenciesIntoArtifacts(CollectRequest collectRequest)
    throws PlexusContainerException, ComponentLookupException, DependencyCollectionException,
    ArtifactResolutionException {
    RepositorySystem repositorySystem = this.newRepositorySystem();
    RepositorySystemSession session = this.newSession(repositorySystem);
    DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot();
    repositorySystem.resolveDependencies(session, node, null);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    node.accept(nlg);
    return nlg.getArtifacts(false);
}
 
Example #30
Source File: OrganizationDao.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void postConstruct() {
    try {
        organizationTblDao = ContainerLoader.getDefaultContainer().lookup(OrganizationTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}