Search in sources :

Example 1 with MavenProjectInfo

use of org.eclipse.m2e.core.project.MavenProjectInfo in project eclipse.jdt.ls by eclipse.

the class MavenProjectImporter method importToWorkspace.

@Override
public void importToWorkspace(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
    JavaLanguageServerPlugin.logInfo(IMPORTING_MAVEN_PROJECTS);
    MavenConfigurationImpl configurationImpl = (MavenConfigurationImpl) MavenPlugin.getMavenConfiguration();
    configurationImpl.setDownloadSources(true);
    configurationImpl.setNotCoveredMojoExecutionSeverity(ProblemSeverity.ignore.toString());
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    subMonitor.setTaskName(IMPORTING_MAVEN_PROJECTS);
    Set<MavenProjectInfo> files = getMavenProjectInfo(subMonitor.split(5));
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    Collection<IProject> projects = new LinkedHashSet<>();
    Collection<MavenProjectInfo> toImport = new LinkedHashSet<>();
    long lastWorkspaceStateSaved = getLastWorkspaceStateModified();
    // Separate existing projects from new ones
    for (MavenProjectInfo projectInfo : files) {
        File pom = projectInfo.getPomFile();
        IContainer container = root.getContainerForLocation(new Path(pom.getAbsolutePath()));
        if (container == null) {
            toImport.add(projectInfo);
        } else {
            IProject project = container.getProject();
            if (ProjectUtils.isMavenProject(project)) {
                projects.add(container.getProject());
            } else if (project != null) {
                // Project doesn't have the Maven nature, so we (re)import it
                toImport.add(projectInfo);
            }
        }
    }
    if (!toImport.isEmpty()) {
        ProjectImportConfiguration importConfig = new ProjectImportConfiguration();
        configurationManager.importProjects(toImport, importConfig, subMonitor.split(75));
    }
    subMonitor.setWorkRemaining(20);
    updateProjects(projects, lastWorkspaceStateSaved, subMonitor.split(20));
    subMonitor.done();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(org.eclipse.core.runtime.Path) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) MavenConfigurationImpl(org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File)

Example 2 with MavenProjectInfo

use of org.eclipse.m2e.core.project.MavenProjectInfo 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 3 with MavenProjectInfo

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

the class MavenProjectImportOperation method getMavenProjects.

private Set<MavenProjectInfo> getMavenProjects(File directory, Collection<String> filters, MavenModelManager modelManager, IProgressMonitor monitor) throws InterruptedException {
    if (filters == null || filters.isEmpty()) {
        return scan(directory, modelManager, monitor);
    }
    Set<MavenProjectInfo> projectInfos = new LinkedHashSet<>();
    for (String path : filters) {
        File dir = new File(directory, path);
        projectInfos.addAll(scan(dir, modelManager, monitor));
    }
    return projectInfos;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) File(java.io.File)

Example 4 with MavenProjectInfo

use of org.eclipse.m2e.core.project.MavenProjectInfo 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 5 with MavenProjectInfo

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

the class MavenUtil method _findChildMavenProjects.

private static void _findChildMavenProjects(List<MavenProjectInfo> results, Collection<MavenProjectInfo> infos) {
    for (MavenProjectInfo info : infos) {
        results.add(info);
        Collection<MavenProjectInfo> children = info.getProjects();
        if (ListUtil.isNotEmpty(children)) {
            _findChildMavenProjects(results, children);
        }
    }
}
Also used : MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo)

Aggregations

MavenProjectInfo (org.eclipse.m2e.core.project.MavenProjectInfo)10 File (java.io.File)6 ArrayList (java.util.ArrayList)5 ProjectImportConfiguration (org.eclipse.m2e.core.project.ProjectImportConfiguration)5 IProject (org.eclipse.core.resources.IProject)4 MavenModelManager (org.eclipse.m2e.core.embedder.MavenModelManager)4 IProjectConfigurationManager (org.eclipse.m2e.core.project.IProjectConfigurationManager)4 LinkedHashSet (java.util.LinkedHashSet)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 IMavenProjectImportResult (org.eclipse.m2e.core.project.IMavenProjectImportResult)3 LocalProjectScanner (org.eclipse.m2e.core.project.LocalProjectScanner)3 IFile (org.eclipse.core.resources.IFile)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 MavenPluginActivator (org.eclipse.m2e.core.internal.MavenPluginActivator)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1