Search in sources :

Example 6 with MavenProjectInfo

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

the class MavenUtil method _filterProjects.

private static List<MavenProjectInfo> _filterProjects(List<MavenProjectInfo> mavenProjects) {
    List<MavenProjectInfo> result = new ArrayList<>();
    for (MavenProjectInfo info : mavenProjects) {
        if (info != null) {
            File pomFile = info.getPomFile();
            URI mavenuri = pomFile.getParentFile().toURI();
            if (mavenuri.toString().endsWith("/")) {
                try {
                    mavenuri = new URI(mavenuri.toString().substring(0, mavenuri.toString().length() - 1));
                } catch (URISyntaxException urise) {
                }
            }
            boolean alreadyExists = false;
            for (IProject project : CoreUtil.getAllProjects()) {
                if (FileUtil.exists(project) && project.getLocationURI().equals(mavenuri)) {
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists) {
                result.add(info);
            }
        }
    }
    return result;
}
Also used : MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject)

Example 7 with MavenProjectInfo

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

the class MavenProjectImporter method applies.

@Override
public boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException {
    PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
    if (preferencesManager != null && !preferencesManager.getPreferences().isImportMavenEnabled()) {
        return false;
    }
    Set<MavenProjectInfo> files = getMavenProjectInfo(monitor);
    if (files != null) {
        Iterator<MavenProjectInfo> iter = files.iterator();
        while (iter.hasNext()) {
            MavenProjectInfo projectInfo = iter.next();
            File dir = projectInfo.getPomFile() == null ? null : projectInfo.getPomFile().getParentFile();
            if (dir != null && exclude(dir.toPath())) {
                iter.remove();
            }
        }
    }
    return files != null && !files.isEmpty();
}
Also used : MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) File(java.io.File)

Example 8 with MavenProjectInfo

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

the class MavenProjectImportOperation method overwriteMavenProjects.

private boolean overwriteMavenProjects(Collection<MavenProjectInfo> projectInfos, final ProjectImportConfiguration configuration, IProgressMonitor monitor) throws CoreException {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    Set<IProject> s1 = projectInfos.stream().map(project -> configuration.getProjectName(project.getModel())).map(root::getProject).filter(project -> project.exists()).collect(Collectors.toSet());
    boolean overwrite = true;
    if (!s1.isEmpty()) {
        final String message = (s1.size() == 1) ? NLS.bind(OpenShiftCommonUIMessages.MavenProjectWarningMessage, s1.iterator().next().getName()) : OpenShiftCommonUIMessages.MavenProjectsWarningMessage;
        overwrite = displayOverwriteDialog(OpenShiftCommonUIMessages.OverwriteProjectsDialogTitle, message);
        for (IProject project : s1) {
            if (overwrite) {
                project.delete(false, true, monitor);
            } else {
                project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
            }
        }
    }
    return overwrite;
}
Also used : MavenModelManager(org.eclipse.m2e.core.embedder.MavenModelManager) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) Set(java.util.Set) CoreException(org.eclipse.core.runtime.CoreException) Collectors(java.util.stream.Collectors) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) File(java.io.File) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) OpenShiftCommonUIMessages(org.jboss.tools.openshift.internal.common.ui.OpenShiftCommonUIMessages) MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) LocalProjectScanner(org.eclipse.m2e.core.project.LocalProjectScanner) IMavenProjectImportResult(org.eclipse.m2e.core.project.IMavenProjectImportResult) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject)

Example 9 with MavenProjectInfo

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

Example 10 with MavenProjectInfo

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

the class AbstractTestBuild method getProjects.

private List<MavenProjectInfo> getProjects(Collection<MavenProjectInfo> input) {
    List<MavenProjectInfo> toRet = new ArrayList<MavenProjectInfo>();
    for (MavenProjectInfo info : input) {
        toRet.add(info);
        toRet.addAll(getProjects(info.getProjects()));
    }
    return toRet;
}
Also used : MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) ArrayList(java.util.ArrayList)

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