Search in sources :

Example 76 with MavenSession

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;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Configuration(com.qoomon.maven.extension.gitversioning.config.model.Configuration) VersionFormatDescription(com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription) File(java.io.File) LinkedList(java.util.LinkedList)

Example 77 with MavenSession

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;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) List(java.util.List) ArrayList(java.util.ArrayList) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Example 78 with MavenSession

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;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MultiStatusBuilder(com.liferay.ide.core.util.MultiStatusBuilder) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 79 with MavenSession

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) Properties(java.util.Properties) SystemProperties(org.gradle.internal.SystemProperties) ContainerConfiguration(org.codehaus.plexus.ContainerConfiguration) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ProjectBuilder(org.apache.maven.project.ProjectBuilder) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 80 with MavenSession

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));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)118 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)20 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 Properties (java.util.Properties)17 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)12 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6