Search in sources :

Example 21 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project pom-manipulation-ext by release-engineering.

the class Cli method parseSettings.

private Settings parseSettings(File settings) throws PlexusContainerException, ComponentLookupException, SettingsBuildingException {
    PlexusContainer container = new DefaultPlexusContainer();
    DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
    settingsRequest.setUserSettingsFile(settings);
    settingsRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
    settingsRequest.setUserProperties(session.getUserProperties());
    settingsRequest.setSystemProperties(System.getProperties());
    SettingsBuilder settingsBuilder = container.lookup(SettingsBuilder.class);
    SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
    Settings effectiveSettings = settingsResult.getEffectiveSettings();
    ProfileSelector profileSelector = container.lookup(ProfileSelector.class);
    ProfileActivationContext profileActivationContext = new DefaultProfileActivationContext().setActiveProfileIds(effectiveSettings.getActiveProfiles());
    List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<>();
    for (Profile profile : effectiveSettings.getProfiles()) {
        modelProfiles.add(SettingsUtils.convertFromSettingsProfile(profile));
    }
    List<org.apache.maven.model.Profile> activeModelProfiles = profileSelector.getActiveProfiles(modelProfiles, profileActivationContext, new ModelProblemCollector() {

        @Override
        public void add(ModelProblem.Severity severity, String message, InputLocation location, Exception cause) {
        // do nothing
        }
    });
    List<String> activeProfiles = new ArrayList<>();
    for (org.apache.maven.model.Profile profile : activeModelProfiles) {
        activeProfiles.add(profile.getId());
    }
    effectiveSettings.setActiveProfiles(activeProfiles);
    return effectiveSettings;
}
Also used : InputLocation(org.apache.maven.model.InputLocation) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) ArrayList(java.util.ArrayList) Profile(org.apache.maven.settings.Profile) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ModelProblem(org.apache.maven.model.building.ModelProblem) ProfileSelector(org.apache.maven.model.profile.ProfileSelector) Settings(org.apache.maven.settings.Settings) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext) ProfileActivationContext(org.apache.maven.model.profile.ProfileActivationContext) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) ParseException(org.apache.commons.cli.ParseException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ModelProblemCollector(org.apache.maven.model.building.ModelProblemCollector) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext)

Example 22 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project pom-manipulation-ext by release-engineering.

the class Cli method createSession.

private void createSession(File target, File settings) {
    try {
        PlexusContainer container = new DefaultPlexusContainer();
        pomIO = container.lookup(PomIO.class);
        session = container.lookup(ManipulationSession.class);
        manipulationManager = container.lookup(ManipulationManager.class);
        final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(System.getProperties()).setUserProperties(userProps).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
        ArtifactRepository ar = null;
        if (settings == null) {
            // No, this is not a typo. If current default is null, supply new local and global.
            // This function passes in settings to make it easier to test.
            this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml");
            ar = new MavenArtifactRepository();
            ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository");
            req.setLocalRepository(ar);
        }
        req.setUserSettingsFile(settings);
        req.setGlobalSettingsFile(settings);
        MavenExecutionRequestPopulator executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
        executionRequestPopulator.populateFromSettings(req, parseSettings(settings));
        executionRequestPopulator.populateDefaults(req);
        if (ar != null) {
            ar.setUrl("file://" + req.getLocalRepositoryPath());
        }
        if (userProps != null && userProps.containsKey("maven.repo.local")) {
            if (ar == null) {
                ar = new MavenArtifactRepository();
            }
            ar.setUrl("file://" + userProps.getProperty("maven.repo.local"));
            req.setLocalRepository(ar);
        }
        final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
        mavenSession.getRequest().setPom(target);
        session.setMavenSession(mavenSession);
    } catch (ComponentLookupException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (PlexusContainerException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (SettingsBuildingException e) {
        logger.debug("Caught problem parsing settings file ", e);
        System.err.println("Unable to parse settings.xml file");
        System.exit(100);
    } catch (MavenExecutionRequestPopulationException e) {
        logger.debug("Caught problem populating maven request from settings file ", e);
        System.err.println("Unable to create maven execution request from settings.xml file");
        System.exit(100);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationManager(org.commonjava.maven.ext.core.ManipulationManager) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomIO(org.commonjava.maven.ext.io.PomIO) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 23 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project x-pipe by ctripcorp.

the class AbstractConsoleService method postConstruct.

@SuppressWarnings("unchecked")
@PostConstruct
private void postConstruct() {
    try {
        logger.info("[postConstruct]{}", getClass().getSimpleName());
        Type superClass = getClass().getGenericSuperclass();
        if (superClass instanceof Class<?>) {
            // sanity check, should never happen
            throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information");
        }
        Type type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
        Class clazz = Class.forName(parseTypeName(type.toString()));
        dao = (T) ContainerLoader.getDefaultContainer().lookup(clazz);
    } catch (ComponentLookupException e) {
        throw new ServerException("Dao construct failed.", e);
    } catch (ClassNotFoundException e) {
        throw new ServerException("Dao construct failed due to class not found.", e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Example 24 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project x-pipe by ctripcorp.

the class AbstractConsoleH2DbTest method executeSqlScript.

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();
        }
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DataSourceManager(org.unidal.dal.jdbc.datasource.DataSourceManager) IOException(java.io.IOException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SQLException(java.sql.SQLException)

Example 25 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project x-pipe by ctripcorp.

the class ClusterDao method postConstruct.

@PostConstruct
private void postConstruct() {
    try {
        dcTblDao = ContainerLoader.getDefaultContainer().lookup(DcTblDao.class);
        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);
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)40 IOException (java.io.IOException)11 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ArrayList (java.util.ArrayList)6 PostConstruct (javax.annotation.PostConstruct)6 File (java.io.File)5 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)4 MavenSession (org.apache.maven.execution.MavenSession)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)3 ResolutionGroup (org.apache.maven.artifact.metadata.ResolutionGroup)3 DefaultMetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest)3 MetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest)3