Search in sources :

Example 21 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManager method internalDelete.

private void internalDelete(MavenProject parentProject, MavenProject removedModule, UpdateState state) {
    for (MavenProject project : findModules(removedModule)) {
        internalDelete(removedModule, project, state);
    }
    writeLock.lock();
    try {
        if (parentProject == null) {
            rootProjects.remove(removedModule);
        } else {
            removeModule(parentProject, removedModule);
        }
        projectToMavenProjectMap.remove(removedModule.getProject());
        clearMavenKeyMap(removedModule);
        moduleToParentMap.remove(removedModule);
        parentToModulesMap.remove(removedModule);
    } finally {
        writeLock.unlock();
    }
    state.remove(removedModule);
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject)

Example 22 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManager method internalUpdate.

private void internalUpdate(MavenProject mavenProject, MavenProject parentProject, boolean isNew, boolean recursive, UpdateState state, Deque<MavenProject> stack) {
    if (stack.contains(mavenProject)) {
        //recursion
        return;
    }
    stack.addFirst(mavenProject);
    mavenNotifier.setText("Reading pom: " + mavenProject.getPomPath());
    List<MavenProject> oldModules = findModules(mavenProject);
    Set<MavenProject> oldChilds = new HashSet<>();
    if (!isNew) {
        oldChilds.addAll(findChildProjects(mavenProject));
    }
    writeLock.lock();
    try {
        if (!isNew) {
            clearMavenKeyMap(mavenProject);
        }
    } finally {
        writeLock.unlock();
    }
    MavenProjectModifications modifications = new MavenProjectModifications();
    //re read maven project meta info from pom.xml
    modifications = modifications.addChanges(mavenProject.read(serverManager));
    writeLock.lock();
    try {
        fillMavenKeyMap(mavenProject);
        projectToMavenProjectMap.put(mavenProject.getProject(), mavenProject);
    } finally {
        writeLock.unlock();
    }
    if (isNew) {
        addToChild(parentProject, mavenProject);
    } else {
        updateChild(parentProject, mavenProject);
    }
    //        if (hasparent) {
    state.addUpdate(mavenProject, modifications);
    //        }
    List<IProject> modules = mavenProject.getModulesProjects();
    List<MavenProject> removedModules = oldModules.stream().filter(oldModule -> !modules.contains(oldModule.getProject())).collect(Collectors.toList());
    for (MavenProject removedModule : removedModules) {
        removeModule(mavenProject, removedModule);
        internalDelete(mavenProject, removedModule, state);
        oldChilds.removeAll(state.removedProjects);
    }
    for (IProject module : modules) {
        MavenProject project = findMavenProject(module);
        boolean isNewProject = project == null;
        if (isNewProject) {
            project = new MavenProject(module, workspaceProvider.get());
        } else {
            MavenProject parent = findParentProject(project);
            if (parent != null && parent != mavenProject) {
                //TODO add log
                continue;
            }
        }
        if (isNewProject || recursive) {
            internalUpdate(project, mavenProject, isNewProject, recursive, state, stack);
        } else {
            if (updateChild(mavenProject, project)) {
                state.addUpdate(project, new MavenProjectModifications());
            }
        }
    }
    oldChilds.addAll(findChildProjects(mavenProject));
    for (MavenProject oldModule : oldChilds) {
        internalUpdate(oldModule, findParentProject(oldModule), false, false, state, stack);
    }
    stack.pop();
}
Also used : MavenServerManager(org.eclipse.che.plugin.maven.server.MavenServerManager) MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) Proxy(java.lang.reflect.Proxy) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Map(java.util.Map) LinkedList(java.util.LinkedList) Set(java.util.Set) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) Provider(com.google.inject.Provider) MavenKey(org.eclipse.che.maven.data.MavenKey) List(java.util.List) Lock(java.util.concurrent.locks.Lock) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenWorkspaceCache(org.eclipse.che.maven.data.MavenWorkspaceCache) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenProjectModifications(org.eclipse.che.plugin.maven.server.core.project.MavenProjectModifications) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 23 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManager method internalAddMavenProject.

private void internalAddMavenProject(IProject project, boolean recursive, UpdateState state, Deque<MavenProject> stack) {
    MavenProject mavenProject = new MavenProject(project, workspaceProvider.get());
    MavenProject potentialParent = null;
    for (MavenProject parent : getAllProjects()) {
        if (parent.containsAsModule(project.getFullPath())) {
            potentialParent = parent;
            break;
        }
    }
    internalUpdate(mavenProject, potentialParent, true, recursive, state, stack);
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject)

Example 24 with MavenProject

use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.

the class MavenProjectManager method delete.

public void delete(List<IProject> projects) {
    if (projects.isEmpty()) {
        return;
    }
    UpdateState state = new UpdateState();
    Deque<MavenProject> stack = new LinkedList<>();
    Set<MavenProject> childToUpdate = new HashSet<>();
    for (IProject project : projects) {
        MavenProject mavenProject = findMavenProject(project);
        if (mavenProject == null) {
            return;
        }
        childToUpdate.addAll(findChildProjects(mavenProject));
        internalDelete(findParentProject(mavenProject), mavenProject, state);
    }
    childToUpdate.removeAll(state.removedProjects);
    for (MavenProject mavenProject : childToUpdate) {
        internalUpdate(mavenProject, null, false, false, state, stack);
    }
    state.fireUpdate();
}
Also used : MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Aggregations

MavenProject (org.eclipse.che.plugin.maven.server.core.project.MavenProject)24 IProject (org.eclipse.core.resources.IProject)16 Test (org.testng.annotations.Test)13 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)9 MavenKey (org.eclipse.che.maven.data.MavenKey)7 List (java.util.List)6 Collections (java.util.Collections)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 Inject (com.google.inject.Inject)4 Provider (com.google.inject.Provider)4 Singleton (com.google.inject.Singleton)4 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Collectors (java.util.stream.Collectors)4 Path (org.eclipse.core.runtime.Path)4 Map (java.util.Map)3 ProjectRegistry (org.eclipse.che.api.project.server.ProjectRegistry)3 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)3 MavenTerminal (org.eclipse.che.maven.server.MavenTerminal)3