Search in sources :

Example 1 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project che by eclipse.

the class RefactoringTest method performRefactoring.

protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
    performDummySearch();
    IUndoManager undoManager = getUndoManager();
    if (DESCRIPTOR_TEST) {
        final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
        create.run(new NullProgressMonitor());
        RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
        if (!checkingStatus.isOK())
            return checkingStatus;
        Change change = create.getChange();
        ChangeDescriptor descriptor = change.getDescriptor();
        if (descriptor instanceof RefactoringChangeDescriptor) {
            RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
            RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
            if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
                JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
                RefactoringStatus validation = jrd.validateDescriptor();
                if (!validation.isOK())
                    return validation;
                RefactoringStatus refactoringStatus = new RefactoringStatus();
                Class expected = jrd.getClass();
                RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
                jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
                assertEquals(expected, jrd.getClass());
                ref = jrd.createRefactoring(refactoringStatus);
                if (!refactoringStatus.isOK())
                    return refactoringStatus;
                TestRenameParticipantSingle.reset();
                TestCreateParticipantSingle.reset();
                TestMoveParticipantSingle.reset();
                TestDeleteParticipantSingle.reset();
            }
        }
    }
    final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
    final PerformChangeOperation perform = new PerformChangeOperation(create);
    perform.setUndoManager(undoManager, ref.getName());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (fIsPreDeltaTest) {
        IResourceChangeListener listener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
                    TestModelProvider.assertTrue(event.getDelta());
                }
            }
        };
        try {
            TestModelProvider.clearDelta();
            workspace.checkpoint(false);
            workspace.addResourceChangeListener(listener);
            executePerformOperation(perform, workspace);
        } finally {
            workspace.removeResourceChangeListener(listener);
        }
    } else {
        executePerformOperation(perform, workspace);
    }
    RefactoringStatus status = create.getConditionCheckingStatus();
    if (!status.isOK())
        return status;
    assertTrue("Change wasn't executed", perform.changeExecuted());
    Change undo = perform.getUndoChange();
    if (providesUndo) {
        assertNotNull("Undo doesn't exist", undo);
        assertTrue("Undo manager is empty", undoManager.anythingToUndo());
    } else {
        assertNull("Undo manager contains undo but shouldn't", undo);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 2 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project che by eclipse.

the class PomChangeListener method updateProms.

//    @ScheduleDelay(initialDelay = 30, delay = 3)
protected void updateProms() {
    try {
        if (projectToUpdate.size() == 0) {
            return;
        }
        Set<String> projects = new HashSet<>(projectToUpdate);
        projectToUpdate.clear();
        IWorkspace workspace = eclipseWorkspaceProvider.get();
        List<IProject> projectsList = projects.stream().map(project -> workspace.getRoot().getProject(project)).collect(Collectors.toList());
        mavenWorkspace.update(projectsList);
    } catch (Throwable t) {
        JavaPlugin.log(t);
    }
}
Also used : JavaPlugin(org.eclipse.jdt.internal.ui.JavaPlugin) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) PomModifiedEventDto(org.eclipse.che.api.project.shared.dto.event.PomModifiedEventDto) Inject(com.google.inject.Inject) Set(java.util.Set) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) Collectors(java.util.stream.Collectors) File(java.io.File) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ThreadPullLauncher(org.eclipse.che.commons.schedule.executor.ThreadPullLauncher) Model(org.eclipse.che.ide.maven.tools.Model) Path(org.eclipse.core.runtime.Path) Named(com.google.inject.name.Named) Singleton(com.google.inject.Singleton) EventService(org.eclipse.che.api.core.notification.EventService) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Example 3 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project che by eclipse.

the class MavenServerService method reimportDependencies.

@POST
@Path("reimport")
@ApiOperation(value = "Re-import maven model")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response reimportDependencies(@ApiParam(value = "The paths to projects which need to be reimported") @QueryParam("projectPath") List<String> paths) throws ServerException {
    IWorkspace workspace = eclipseWorkspaceProvider.get();
    List<IProject> projectsList = paths.stream().map(projectPath -> workspace.getRoot().getProject(projectPath)).collect(Collectors.toList());
    mavenWorkspace.update(projectsList);
    return Response.ok().build();
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Inject(com.google.inject.Inject) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) Document(org.eclipse.jface.text.Document) MavenProgressNotifier(org.eclipse.che.plugin.maven.server.core.MavenProgressNotifier) QueryParam(javax.ws.rs.QueryParam) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Model(org.eclipse.che.ide.maven.tools.Model) BadLocationException(org.eclipse.jface.text.BadLocationException) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TEXT_XML(javax.ws.rs.core.MediaType.TEXT_XML) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Response(javax.ws.rs.core.Response) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project che by eclipse.

the class ResourceChangeDescriptionFactory method getDelta.

private ProposedResourceDelta getDelta(IResource resource) {
    ProposedResourceDelta delta = (ProposedResourceDelta) root.findMember(resource.getFullPath());
    if (delta != null) {
        return delta;
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IResource iResource = resource.getParent();
    if (iResource == null) {
        iResource = ((Workspace) workspace).newResource(resource.getFullPath().removeLastSegments(1), IResource.FOLDER);
    }
    ProposedResourceDelta parent = getDelta(iResource);
    delta = new ProposedResourceDelta(resource);
    parent.add(delta);
    return delta;
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) IResource(org.eclipse.core.resources.IResource)

Example 5 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project flux by eclipse.

the class Activator method initCoreService.

private void initCoreService(String userChannel) throws CoreException {
    repository = new Repository(messageConnector, userChannel);
    liveEditCoordinator = new LiveEditCoordinator(messageConnector);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    resourceListener = new CloudSyncResourceListener(repository);
    workspace.addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_CHANGE);
    metadataListener = new CloudSyncMetadataListener(repository);
    workspace.addResourceChangeListener(metadataListener, IResourceChangeEvent.POST_BUILD);
    this.repositoryListener = new IRepositoryListener() {

        @Override
        public void projectDisconnected(IProject project) {
            removeConnectedProjectPreference(project.getName());
        }

        @Override
        public void projectConnected(IProject project) {
            addConnectedProjectPreference(project.getName());
        }

        @Override
        public void resourceChanged(IResource resource) {
        // nothing
        }
    };
    getRepository().addRepositoryListener(repositoryListener);
    workspaceListener = new IResourceChangeListener() {

        public void resourceChanged(IResourceChangeEvent event) {
            if (event.getResource() instanceof IProject) {
                IResourceDelta delta = event.getDelta();
                if (delta == null) {
                    return;
                }
                if (delta.getKind() == IResourceDelta.REMOVED) {
                    IProject project = (IProject) event.getResource();
                    removeConnectedProjectPreference(project.getName());
                } else if (delta.getKind() == IResourceDelta.CHANGED) {
                // TODO, we aren't handling project renaming yet
                // IProject project = (IProject) event.getResource();
                // String oldName =
                // delta.getMovedFromPath().lastSegment();
                // removeConnectedProjectPreference(oldName);
                // addConnectedProjectPreference(project.getName());
                }
            }
        }
    };
    workspace.addResourceChangeListener(workspaceListener);
    updateProjectConnections();
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CloudSyncMetadataListener(org.eclipse.flux.core.internal.CloudSyncMetadataListener) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) CloudSyncResourceListener(org.eclipse.flux.core.internal.CloudSyncResourceListener) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)71 CoreException (org.eclipse.core.runtime.CoreException)41 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)30 IProject (org.eclipse.core.resources.IProject)29 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IPath (org.eclipse.core.runtime.IPath)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)15 IFile (org.eclipse.core.resources.IFile)14 ArrayList (java.util.ArrayList)11 Status (org.eclipse.core.runtime.Status)11 Path (org.eclipse.core.runtime.Path)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 File (java.io.File)9 IOException (java.io.IOException)9 IResource (org.eclipse.core.resources.IResource)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)8