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;
}
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);
}
}
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);
}
}
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();
}
}
}
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);
}
}
Aggregations