Search in sources :

Example 1 with MavenModelManager

use of org.eclipse.m2e.core.embedder.MavenModelManager in project liferay-ide by liferay.

the class MavenUtil method importProject.

public static List<IMavenProjectImportResult> importProject(String location, IProgressMonitor monitor) throws CoreException, InterruptedException {
    MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();
    IWorkspaceRoot workspaceRoot = CoreUtil.getWorkspaceRoot();
    File root = workspaceRoot.getLocation().toFile();
    AbstractProjectScanner<MavenProjectInfo> scanner = new LocalProjectScanner(root, location, false, mavenModelManager);
    scanner.run(monitor);
    List<MavenProjectInfo> projects = scanner.getProjects();
    List<MavenProjectInfo> mavenProjects = new ArrayList<>();
    _findChildMavenProjects(mavenProjects, projects);
    mavenProjects = _filterProjects(mavenProjects);
    ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
    IProjectConfigurationManager projectConfigurationManager = MavenPlugin.getProjectConfigurationManager();
    return projectConfigurationManager.importProjects(mavenProjects, importConfiguration, monitor);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) LocalProjectScanner(org.eclipse.m2e.core.project.LocalProjectScanner) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) ArrayList(java.util.ArrayList) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager) MavenModelManager(org.eclipse.m2e.core.embedder.MavenModelManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with MavenModelManager

use of org.eclipse.m2e.core.embedder.MavenModelManager in project jbosstools-openshift by jbosstools.

the class MavenProjectImportOperation method importToWorkspace.

public List<IProject> importToWorkspace(IProgressMonitor monitor) throws CoreException, InterruptedException {
    MavenPluginActivator mavenPlugin = MavenPluginActivator.getDefault();
    IProjectConfigurationManager configurationManager = mavenPlugin.getProjectConfigurationManager();
    MavenModelManager modelManager = mavenPlugin.getMavenModelManager();
    Set<MavenProjectInfo> projectInfos = getMavenProjects(getProjectDirectory(), filters, modelManager, monitor);
    ProjectImportConfiguration projectImportConfiguration = new ProjectImportConfiguration();
    if (overwriteMavenProjects(projectInfos, projectImportConfiguration, monitor)) {
        List<IMavenProjectImportResult> importResults = configurationManager.importProjects(projectInfos, projectImportConfiguration, monitor);
        return validate(toProjects(importResults));
    } else {
        return Collections.emptyList();
    }
}
Also used : MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IMavenProjectImportResult(org.eclipse.m2e.core.project.IMavenProjectImportResult) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) MavenModelManager(org.eclipse.m2e.core.embedder.MavenModelManager)

Example 3 with MavenModelManager

use of org.eclipse.m2e.core.embedder.MavenModelManager in project m2e-nar by maven-nar.

the class AbstractTestBuild method importProject.

protected List<IProject> importProject(final String path) {
    final ArrayList<IMavenProjectImportResult> importResults = new ArrayList<IMavenProjectImportResult>();
    Job job = new Job("Importing test project") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                final IProjectConfigurationManager configManager = MavenPlugin.getProjectConfigurationManager();
                final MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();
                final ProjectImportConfiguration configuration = new ProjectImportConfiguration();
                final LocalProjectScanner scanner = new LocalProjectScanner(workspace.getRoot().getLocation().toFile(), path, true, mavenModelManager);
                scanner.run(monitor);
                final List<MavenProjectInfo> projects = getProjects(scanner.getProjects());
                workspace.run(new IWorkspaceRunnable() {

                    public void run(IProgressMonitor monitor) throws CoreException {
                        importResults.addAll(configManager.importProjects(projects, configuration, monitor));
                    }
                }, MavenPlugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                return e.getStatus();
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
    waitForJobs();
    List<IProject> createdProjects = new ArrayList<IProject>();
    for (IMavenProjectImportResult r : importResults) {
        IProject p = r.getProject();
        if (p != null && p.exists()) {
            createdProjects.add(p);
        }
    }
    assertFalse("Could not create project " + path, createdProjects.isEmpty());
    return createdProjects;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) LocalProjectScanner(org.eclipse.m2e.core.project.LocalProjectScanner) ArrayList(java.util.ArrayList) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager) IProject(org.eclipse.core.resources.IProject) IMavenProjectImportResult(org.eclipse.m2e.core.project.IMavenProjectImportResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) CoreException(org.eclipse.core.runtime.CoreException) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) MavenModelManager(org.eclipse.m2e.core.embedder.MavenModelManager) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

MavenModelManager (org.eclipse.m2e.core.embedder.MavenModelManager)3 IProjectConfigurationManager (org.eclipse.m2e.core.project.IProjectConfigurationManager)3 MavenProjectInfo (org.eclipse.m2e.core.project.MavenProjectInfo)3 ProjectImportConfiguration (org.eclipse.m2e.core.project.ProjectImportConfiguration)3 ArrayList (java.util.ArrayList)2 IMavenProjectImportResult (org.eclipse.m2e.core.project.IMavenProjectImportResult)2 LocalProjectScanner (org.eclipse.m2e.core.project.LocalProjectScanner)2 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 MavenPluginActivator (org.eclipse.m2e.core.internal.MavenPluginActivator)1