use of org.apache.maven.execution.MavenExecutionResult in project sts4 by spring-projects.
the class MavenBridge method readMavenProject.
public MavenExecutionResult readMavenProject(File pomFile, ProjectBuildingRequest configuration) throws MavenException {
long start = System.currentTimeMillis();
// $NON-NLS-1$
log.debug("Reading Maven project: {}", pomFile.getAbsoluteFile());
MavenExecutionResult result = new DefaultMavenExecutionResult();
try {
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
ProjectBuildingResult projectBuildingResult = lookup(ProjectBuilder.class).build(pomFile, configuration);
result.setProject(projectBuildingResult.getProject());
result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult());
} catch (ProjectBuildingException ex) {
if (ex.getResults() != null && ex.getResults().size() == 1) {
ProjectBuildingResult projectBuildingResult = ex.getResults().get(0);
result.setProject(projectBuildingResult.getProject());
result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult());
}
result.addException(ex);
} catch (RuntimeException e) {
result.addException(e);
} finally {
// $NON-NLS-1$
log.debug("Read Maven project: {} in {} ms", pomFile.getAbsoluteFile(), System.currentTimeMillis() - start);
}
return result;
}
use of org.apache.maven.execution.MavenExecutionResult in project sts4 by spring-projects.
the class MavenBridge method createSession.
@SuppressWarnings("deprecation")
public MavenSession createSession(MavenExecutionRequest request, MavenProject project) throws MavenException {
RepositorySystemSession repoSession = createRepositorySession(request);
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenSession mavenSession = new MavenSession(plexus, repoSession, request, result);
if (project != null) {
mavenSession.setProjects(Collections.singletonList(project));
}
return mavenSession;
}
use of org.apache.maven.execution.MavenExecutionResult in project maven-plugins by apache.
the class DefaultDependencyResolverTest method newMavenSession.
protected MavenSession newMavenSession(MavenProject project) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
repoSession.setLocalRepositoryManager(LegacyLocalRepositoryManager.wrap(new StubArtifactRepository("target/local-repo"), null));
MavenSession session = new MavenSession(getContainer(), repoSession, request, result);
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
return session;
}
use of org.apache.maven.execution.MavenExecutionResult in project tycho by eclipse.
the class ValidateIdTest method getMojo.
private ValidateIdMojo getMojo(File basedir) throws Exception {
File pom = new File(basedir, "pom.xml");
MavenExecutionRequest request = newMavenExecutionRequest(pom);
request.getProjectBuildingRequest().setProcessPlugins(false);
MavenExecutionResult result = maven.execute(request);
MavenProject project = result.getProject();
ValidateIdMojo mojo = (ValidateIdMojo) lookupMojo("validate-id", project.getFile());
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "packaging", project.getPackaging());
return mojo;
}
use of org.apache.maven.execution.MavenExecutionResult in project gradle by gradle.
the class MavenProjectsCreator method createNow.
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("mavenCore").setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true);
DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
ProjectBuilder builder = container.lookup(ProjectBuilder.class);
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final Properties properties = SystemProperties.getInstance().withSystemProperties(() -> {
final Properties currentProperties = new Properties();
currentProperties.putAll(System.getProperties());
return currentProperties;
});
executionRequest.setSystemProperties(properties);
MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
populateFromSettings(settings, executionRequest, populator);
populator.populateDefaults(executionRequest);
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.getRemoteRepositories().forEach(repository -> {
if (repository.getId().equals(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
repository.setUrl(RepositoryHandler.MAVEN_CENTRAL_URL);
}
});
buildingRequest.setProcessPlugins(false);
MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
Set<MavenProject> reactorProjects = new LinkedHashSet<>();
// TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
// the converter should not depend on the order of reactor projects.
// we should add coverage for nested multi-project builds with multiple parents.
reactorProjects.add(mavenProject);
List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
// noinspection NullableProblems
CollectionUtils.collect(allProjects, reactorProjects, ProjectBuildingResult::getProject);
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setProject(mavenProject);
RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
session.setCurrentProject(mavenProject);
return reactorProjects;
}
Aggregations