Search in sources :

Example 6 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project azure-tools-for-java by Microsoft.

the class MavenExecuteAction method setProjectConfiguration.

private void setProjectConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IContainer basedir) {
    IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
    IFile pomFile = basedir.getFile(new Path(IMavenConstants.POM_FILE_NAME));
    IMavenProjectFacade projectFacade = projectManager.create(pomFile, false, new NullProgressMonitor());
    if (projectFacade != null) {
        ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
        String selectedProfiles = configuration.getSelectedProfiles();
        if (selectedProfiles != null && selectedProfiles.length() > 0) {
            workingCopy.setAttribute(MavenLaunchConstants.ATTR_PROFILES, selectedProfiles);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 7 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project azure-tools-for-java by Microsoft.

the class HDInsightsJavaProjectWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        CreateProjectUtil.createSampleFile(this.id, this.pageOne.getProjectName(), pageOne.sparkLibraryOptionsPanel.getUsingMaven(), pageOne.sparkLibraryOptionsPanel.getSparkVersion());
    } catch (CoreException e) {
        Activator.getDefault().log("Create HDInsight project error", e);
    }
    // Configure Java project first and then enable Maven nature, otherwise the classpath will be overwritten
    boolean result = super.performFinish();
    if (pageOne.sparkLibraryOptionsPanel.getUsingMaven()) {
        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            dialog.run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        MavenPlugin.getProjectConfigurationManager().enableMavenNature(pageTwo.getJavaProject().getProject(), new ResolverConfiguration(), monitor);
                    } catch (CoreException e) {
                        Activator.getDefault().log("Error in enabling Maven nature", e);
                    }
                }
            });
        } catch (InvocationTargetException | InterruptedException e1) {
            Activator.getDefault().log("Fail to enable Maven feature", e1);
        }
    }
    return result;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 8 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project azure-tools-for-java by Microsoft.

the class HDInsightsScalaProjectWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        CreateProjectUtil.createSampleFile(this.id, this.hdInsightScalaPageOne.getProjectName(), this.isUsingMaven, this.sparkVersion);
    } catch (CoreException e) {
        Activator.getDefault().log("Create HDInsight project error", e);
    }
    // Configure Java project first and then enable Maven nature, otherwise the classpath will be overwritten
    boolean result = super.performFinish();
    if (isUsingMaven) {
        try {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            dialog.run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        MavenPlugin.getProjectConfigurationManager().enableMavenNature(hdInsightScalaPageTwo.getJavaProject().getProject(), new ResolverConfiguration(), monitor);
                    } catch (CoreException e) {
                        Activator.getDefault().log("Error in enabling Maven nature", e);
                    }
                }
            });
        } catch (InvocationTargetException | InterruptedException e1) {
            Activator.getDefault().log("Fail to enable Maven feature", e1);
        }
    }
    return result;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 9 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project azure-tools-for-java by Microsoft.

the class MavenUtils method getMavenProject.

@NotNull
private static MavenProject getMavenProject(@NotNull IFile pom) throws Exception {
    final IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
    final NullProgressMonitor monitor = new NullProgressMonitor();
    if (projectManager == null) {
        throw new Exception(CANNOT_GET_REG);
    }
    final IMavenProjectFacade mavenFacade = projectManager.create(pom, true, monitor);
    if (mavenFacade == null) {
        throw new Exception(CANNOT_CREATE_FACADE);
    }
    final MavenProject mavenProject = mavenFacade.getMavenProject(monitor);
    if (mavenProject == null) {
        throw new Exception(CANNOT_GET_MAVEN_PROJ);
    }
    final ResolverConfiguration configuration = mavenFacade.getResolverConfiguration();
    configuration.setResolveWorkspaceProjects(true);
    return mavenProject;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) CoreException(org.eclipse.core.runtime.CoreException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 10 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration 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)

Aggregations

ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)15 CoreException (org.eclipse.core.runtime.CoreException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 MavenProject (org.apache.maven.project.MavenProject)5 IPath (org.eclipse.core.runtime.IPath)5 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)4 MojoExecution (org.apache.maven.plugin.MojoExecution)4 IStatus (org.eclipse.core.runtime.IStatus)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IMaven (org.eclipse.m2e.core.embedder.IMaven)3 IProjectConfigurationManager (org.eclipse.m2e.core.project.IProjectConfigurationManager)3 LaunchHelper (com.liferay.ide.core.util.LaunchHelper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MavenSession (org.apache.maven.execution.MavenSession)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)2