use of org.apache.maven.execution.MavenSession in project maven-git-versioning-extension by qoomon.
the class VersioningConfigurationProvider method get.
public VersioningConfiguration get() {
if (configuration == null) {
MavenSession session = SessionScopeUtil.get(sessionScope, MavenSession.class).get();
List<VersionFormatDescription> branchVersionDescriptions = new LinkedList<>();
List<VersionFormatDescription> tagVersionDescriptions = new LinkedList<>();
File configFile = ExtensionUtil.getConfigFile(session.getRequest(), BuildProperties.projectArtifactId());
if (configFile.exists()) {
Configuration configurationModel = loadConfiguration(configFile);
branchVersionDescriptions.addAll(configurationModel.branches);
tagVersionDescriptions.addAll(configurationModel.tags);
} else {
logger.info("No configuration file found. Apply default configuration.");
}
branchVersionDescriptions.add(DEFAULT_BRANCH_VERSION_DESCRIPTION);
configuration = new VersioningConfiguration(branchVersionDescriptions, tagVersionDescriptions);
}
return configuration;
}
use of org.apache.maven.execution.MavenSession in project liferay-ide by liferay.
the class MavenUtil method executeMojoGoal.
public static IStatus executeMojoGoal(IMavenProjectFacade facade, IMavenExecutionContext context, String goal, IProgressMonitor monitor) throws CoreException {
IStatus retval = null;
IMaven maven = MavenPlugin.getMaven();
List<String> goals = Collections.singletonList(goal);
MavenProject mavenProject = facade.getMavenProject(monitor);
MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
Plugin plugin6x = getPlugin(facade, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
String executionArtifactId = null;
if (plugin6x != null) {
executionArtifactId = ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID;
} else {
Plugin plugin7x = getPlugin(facade, ILiferayMavenConstants.SERVICE_BUILDER_PLUGIN_KEY, monitor);
if (plugin7x != null) {
executionArtifactId = ILiferayMavenConstants.SERVICE_BUILDER_PLUGIN_ARTIFACT_ID;
}
}
MojoExecution liferayMojoExecution = getExecution(plan, executionArtifactId);
if (liferayMojoExecution != null) {
ResolverConfiguration configuration = facade.getResolverConfiguration();
configuration.setResolveWorkspaceProjects(true);
maven.execute(mavenProject, liferayMojoExecution, monitor);
}
MavenSession session = context.getSession();
List<Throwable> exceptions = session.getResult().getExceptions();
if (exceptions.size() == 1) {
retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
} else if (exceptions.size() > 1) {
List<IStatus> statues = new ArrayList<>();
for (Throwable t : exceptions) {
statues.add(LiferayMavenCore.createErrorStatus(t));
}
IStatus firstStatus = statues.get(0);
retval = new MultiStatus(LiferayMavenCore.PLUGIN_ID, IStatus.ERROR, statues.toArray(new IStatus[0]), firstStatus.getMessage(), firstStatus.getException());
}
if (retval == null) {
return Status.OK_STATUS;
}
return retval;
}
use of org.apache.maven.execution.MavenSession in project liferay-ide by liferay.
the class MavenProjectBuilder method execGoals.
public IStatus execGoals(List<String> goals, IProgressMonitor monitor) throws CoreException {
IStatus retval = null;
IMavenProjectFacade facade = MavenUtil.getProjectFacade(getProject(), monitor);
ICallable<IStatus> callable = new ICallable<IStatus>() {
public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
IStatus execStatus = MavenUtil.executeGoals(facade, context, goals, monitor);
MavenSession session = context.getSession();
List<Throwable> exceptions = session.getResult().getExceptions();
MultiStatusBuilder multiStatusBuilder = LiferayMavenCore.newMultiStatus();
multiStatusBuilder.add(execStatus);
multiStatusBuilder.addAll(exceptions);
return multiStatusBuilder.retval();
}
};
retval = executeMaven(facade, callable, monitor);
return retval;
}
use of org.apache.maven.execution.MavenSession 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;
}
use of org.apache.maven.execution.MavenSession in project docker-maven-plugin by fabric8io.
the class DockerAssemblyConfigurationSource method createRepositoryInterpolator.
private FixedStringSearchInterpolator createRepositoryInterpolator() {
final Properties settingsProperties = new Properties();
final MavenSession session = getMavenSession();
if (getLocalRepository() != null) {
settingsProperties.setProperty("localRepository", getLocalRepository().getBasedir());
settingsProperties.setProperty("settings.localRepository", getLocalRepository().getBasedir());
} else if (session != null && session.getSettings() != null) {
settingsProperties.setProperty("localRepository", session.getSettings().getLocalRepository());
settingsProperties.setProperty("settings.localRepository", getLocalRepository().getBasedir());
}
return FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(settingsProperties));
}
Aggregations