use of org.apache.maven.execution.MavenExecutionRequest in project intellij-community by JetBrains.
the class MavenEmbedder method readProjectWithModules.
@NotNull
public MavenExecutionResult readProjectWithModules(@NotNull final File file, List<String> activeProfiles, List<String> inactiveProfiles) {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
request.getGlobalProfileManager().loadSettingsProfiles(mySettings);
request.setRecursive(true);
return readProject(request);
}
use of org.apache.maven.execution.MavenExecutionRequest in project intellij-community by JetBrains.
the class MavenEmbedder method createRequest.
private MavenExecutionRequest createRequest(File file, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals) {
Properties executionProperties = myEmbedderSettings.getProperties();
if (executionProperties == null)
executionProperties = new Properties();
DefaultEventDispatcher dispatcher = new DefaultEventDispatcher();
dispatcher.addEventMonitor(new DefaultEventMonitor(myLogger));
// subclassing because in DefaultMavenExecutionRequest field isRecursive is always false
MavenExecutionRequest result = new DefaultMavenExecutionRequest(myLocalRepository, mySettings, dispatcher, goals, file.getParent(), createProfileManager(activeProfiles, inactiveProfiles, executionProperties), executionProperties, new Properties(), true) {
private boolean myIsRecursive;
@Override
public boolean isRecursive() {
return myIsRecursive;
}
@Override
public void setRecursive(final boolean recursive) {
myIsRecursive = recursive;
}
};
result.setPomFile(file.getPath());
result.setRecursive(myEmbedderSettings.isRecursive());
return result;
}
use of org.apache.maven.execution.MavenExecutionRequest in project intellij-community by JetBrains.
the class MavenEmbedder method resolveProject.
@NotNull
public MavenExecutionResult resolveProject(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, List<ResolutionListener> listeners) {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
ProjectBuilderConfiguration config = request.getProjectBuilderConfiguration();
request.getGlobalProfileManager().loadSettingsProfiles(mySettings);
ProfileManager globalProfileManager = request.getGlobalProfileManager();
globalProfileManager.loadSettingsProfiles(request.getSettings());
List<Exception> exceptions = new ArrayList<Exception>();
MavenProject project = null;
try {
// copied from DefaultMavenProjectBuilder.buildWithDependencies
MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
project = builder.build(new File(file.getPath()), config);
builder.calculateConcreteState(project, config, false);
// copied from DefaultLifecycleExecutor.execute
findExtensions(project);
// end copied from DefaultLifecycleExecutor.execute
Artifact projectArtifact = project.getArtifact();
Map managedVersions = project.getManagedVersionMap();
ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
ArtifactResolver resolver = getComponent(ArtifactResolver.class);
ArtifactResolutionResult result = resolver.resolveTransitively(project.getDependencyArtifacts(), projectArtifact, managedVersions, myLocalRepository, project.getRemoteArtifactRepositories(), metadataSource, null, listeners);
project.setArtifacts(result.getArtifacts());
// end copied from DefaultMavenProjectBuilder.buildWithDependencies
} catch (Exception e) {
return handleException(e);
}
return new MavenExecutionResult(project, exceptions);
}
use of org.apache.maven.execution.MavenExecutionRequest in project meecrowave by apache.
the class MeecrowaveRunMojoTest method run.
@Test
public void run() throws Exception {
final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final MavenSession session = mojo.newMavenSession(project);
final int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
final MojoExecution execution = mojo.newMojoExecution("run");
execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {
{
setValue(Integer.toString(port));
}
});
final InputStream in = System.in;
final CountDownLatch latch = new CountDownLatch(1);
System.setIn(new InputStream() {
// just to not return nothing
private int val = 2;
@Override
public int read() throws IOException {
try {
latch.await();
} catch (final InterruptedException e) {
Thread.interrupted();
fail(e.getMessage());
}
return val--;
}
});
final Thread runner = new Thread() {
@Override
public void run() {
try {
mojo.executeMojo(session, project, execution);
} catch (final Exception e) {
fail(e.getMessage());
}
}
};
try {
runner.start();
for (int i = 0; i < 120; i++) {
try {
assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Thread.sleep(500);
}
}
} finally {
runner.join(TimeUnit.MINUTES.toMillis(1));
System.setIn(in);
if (runner.isAlive()) {
runner.interrupt();
fail("Runner didn't terminate properly");
}
}
}
use of org.apache.maven.execution.MavenExecutionRequest 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);
}
}
Aggregations