use of org.codehaus.plexus.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.
the class VersioningCalculatorTest method setupSession.
private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
session = new ManipulationSession();
session.setMavenSession(mavenSession);
final VersioningState state = new VersioningState(properties);
session.setState(state);
final Map<String, byte[]> dataMap = new HashMap<>();
if (versionMap != null && !versionMap.isEmpty()) {
for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
final String path = toMetadataPath(entry.getKey());
final byte[] data = setupMetadataVersions(entry.getValue());
dataMap.put(path, data);
}
}
final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
final Transport mdTrans = new StubTransport(dataMap);
modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
return state;
}
use of org.codehaus.plexus.DefaultPlexusContainer in project gradle by gradle.
the class AbstractMavenPublishAction method newPlexusContainer.
private PlexusContainer newPlexusContainer(List<File> wagonJars) {
try {
ClassWorld world = new ClassWorld("plexus.core", ClassWorld.class.getClassLoader());
ClassRealm classRealm = new ClassRealm(world, "plexus.core", ClassWorld.class.getClassLoader());
if (wagonJars != null) {
for (File jar : wagonJars) {
classRealm.addURL(jar.toURI().toURL());
}
}
return new DefaultPlexusContainer(new DefaultContainerConfiguration().setRealm(classRealm));
} catch (PlexusContainerException e) {
throw UncheckedException.throwAsUncheckedException(e);
} catch (MalformedURLException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of org.codehaus.plexus.DefaultPlexusContainer 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.DefaultPlexusContainer 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.DefaultPlexusContainer in project pom-manipulation-ext by release-engineering.
the class PlexusTestRunner method createTest.
@Override
protected Object createTest() throws Exception {
final TestClass testClass = getTestClass();
final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
config.setAutoWiring(true);
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(Arrays.<PlexusBeanModule>asList(new PlexusAnnotatedBeanModule(cs, Collections.emptyMap())));
return container.lookup(testClass.getJavaClass());
}
Aggregations