use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.
the class TestUnpackDependenciesMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("unpack-dependencies", true, false);
File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml");
mojo = (UnpackDependenciesMojo) lookupMojo("unpack-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
mojo.setUseJvmChmod(true);
// mojo.silent = true;
// it needs to get the archivermanager
stubFactory.setUnpackableFile(mojo.getArchiverManager());
// i'm using one file repeatedly to archive so I can test the name
// programmatically.
stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + UNPACKABLE_FILE_PATH));
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
ArtifactHandlerManager manager = lookup(ArtifactHandlerManager.class);
setVariableValueToObject(mojo, "artifactHandlerManager", manager);
}
use of org.apache.maven.execution.MavenSession 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.apache.maven.execution.MavenSession in project pom-manipulation-ext by release-engineering.
the class CliTest method checkLocalRepositoryWithDefaultsAndModifiedUserSettings.
@Test
public void checkLocalRepositoryWithDefaultsAndModifiedUserSettings() throws Exception {
boolean restore = false;
Path source = Paths.get(System.getProperty("user.home") + File.separatorChar + ".m2" + File.separatorChar + "settings.xml");
Path backup = Paths.get(source.toString() + '.' + UUID.randomUUID().toString());
Path tmpSettings = Paths.get(getClass().getResource("/settings-test.xml").getFile());
try {
if (source.toFile().exists()) {
System.out.println("Backing up settings.xml to " + backup);
restore = true;
Files.move(source, backup, StandardCopyOption.ATOMIC_MOVE);
}
Files.copy(tmpSettings, source);
Cli c = new Cli();
executeMethod(c, "run", new Object[] { new String[] {} });
ManipulationSession session = (ManipulationSession) FieldUtils.readField(c, "session", true);
MavenSession ms = (MavenSession) FieldUtils.readField(session, "mavenSession", true);
assertTrue(ms.getRequest().getLocalRepository().getBasedir().equals(ms.getRequest().getLocalRepositoryPath().toString()));
assertTrue(ms.getLocalRepository().getBasedir().equals(System.getProperty("user.home") + File.separatorChar + ".m2-mead-test"));
} finally {
if (restore) {
Files.move(backup, source, StandardCopyOption.ATOMIC_MOVE);
} else {
Files.delete(source);
}
}
}
use of org.apache.maven.execution.MavenSession in project pom-manipulation-ext by release-engineering.
the class DistributionEnforcingManipulatorTest method setMavenSession.
private void setMavenSession() throws Exception {
final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(userCliProperties).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
session.setMavenSession(mavenSession);
}
use of org.apache.maven.execution.MavenSession in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method createUpdateSession.
private ManipulationSession createUpdateSession() throws Exception {
ManipulationSession session = new ManipulationSession();
session.setState(new DependencyState(p));
session.setState(new VersioningState(p));
session.setState(new CommonState(p));
final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(p).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
session.setMavenSession(mavenSession);
return session;
}
Aggregations