Search in sources :

Example 1 with IResourceVisitor

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

the class DeleteResourcesProcessor method checkDirtyResources.

private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
    for (int i = 0; i < fResources.length; i++) {
        IResource resource = fResources[i];
        if (resource instanceof IProject && !((IProject) resource).isOpen())
            continue;
        resource.accept(new IResourceVisitor() {

            public boolean visit(IResource visitedResource) throws CoreException {
                if (visitedResource instanceof IFile) {
                    checkDirtyFile(result, (IFile) visitedResource);
                }
                return true;
            }
        }, IResource.DEPTH_INFINITE, false);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 2 with IResourceVisitor

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

the class Repository method getProject.

public void getProject(JSONObject request) {
    try {
        final int callbackID = request.getInt("callback_id");
        final String sender = request.getString("requestSenderID");
        final String projectName = request.getString("project");
        final String username = request.getString("username");
        final ConnectedProject connectedProject = this.syncedProjects.get(projectName);
        if (this.username.equals(username) && connectedProject != null) {
            final JSONArray files = new JSONArray();
            IProject project = connectedProject.getProject();
            try {
                project.accept(new IResourceVisitor() {

                    @Override
                    public boolean visit(IResource resource) throws CoreException {
                        JSONObject projectResource = new JSONObject();
                        String path = resource.getProjectRelativePath().toString();
                        try {
                            projectResource.put("path", path);
                            projectResource.put("timestamp", connectedProject.getTimestamp(path));
                            projectResource.put("hash", connectedProject.getHash(path));
                            if (resource instanceof IFile) {
                                projectResource.put("type", "file");
                            } else if (resource instanceof IFolder) {
                                projectResource.put("type", "folder");
                            }
                            files.put(projectResource);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        return true;
                    }
                }, IResource.DEPTH_INFINITE, IContainer.EXCLUDE_DERIVED);
            } catch (Exception e) {
                e.printStackTrace();
            }
            JSONObject message = new JSONObject();
            message.put("callback_id", callbackID);
            message.put("requestSenderID", sender);
            message.put("username", this.username);
            message.put("project", projectName);
            message.put("username", this.username);
            message.put("files", files);
            messagingConnector.send("getProjectResponse", message);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) JSONObject(org.json.JSONObject) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IResourceVisitor

use of org.eclipse.core.resources.IResourceVisitor in project sling by apache.

the class ExportWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
                final Repository[] selectedServer = new Repository[1];
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            selectedServer[0] = ServerUtil.getConnectedRepository(exportPage.getServer(), monitor);
                        } catch (CoreException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
                try {
                    syncStartPoint.accept(new IResourceVisitor() {

                        @Override
                        public boolean visit(IResource resource) throws CoreException {
                            Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
                            if (command == null) {
                                return true;
                            }
                            Result<?> result = command.execute();
                            if (!result.isSuccess()) {
                                throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed exporting: " + result.toString()));
                            }
                            return true;
                        }
                    });
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } catch (Throwable t) {
                    t.printStackTrace();
                    throw new InvocationTargetException(t);
                }
            }
        });
        return true;
    } catch (RuntimeException | InterruptedException e) {
        exportPage.setErrorMessage(e.getMessage());
        return false;
    } catch (InvocationTargetException e) {
        exportPage.setErrorMessage(e.getCause().getMessage());
        return false;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) IResource(org.eclipse.core.resources.IResource)

Example 4 with IResourceVisitor

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

the class ResourceChangeDescriptionFactory method moveOrCopyDeep.

/**
	 * Helper method that generate a move or copy delta for a sub-tree
	 * of resources being moved or copied.
	 */
private void moveOrCopyDeep(IResource resource, IPath destination, final boolean move) {
    final IPath sourcePrefix = resource.getFullPath();
    final IPath destinationPrefix = destination;
    try {
        //build delta for the entire sub-tree if available
        if (resource.isAccessible()) {
            resource.accept(new IResourceVisitor() {

                public boolean visit(IResource child) {
                    return moveOrCopy(child, sourcePrefix, destinationPrefix, move);
                }
            });
        } else {
            //just build a delta for the single resource
            moveOrCopy(resource, sourcePrefix, destination, move);
        }
    } catch (CoreException e) {
        fail(e);
    }
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Example 5 with IResourceVisitor

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

the class DeleteResourceChange method perform.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    //$NON-NLS-1$
    pm.beginTask("", 10);
    pm.setTaskName(RefactoringCoreMessages.DeleteResourceChange_deleting);
    try {
        IResource resource = getResource();
        if (resource == null || !resource.exists()) {
            if (fDeleteContent)
                // see https://bugs.eclipse.org/343584
                return null;
            String message = Messages.format(RefactoringCoreMessages.DeleteResourceChange_error_resource_not_exists, BasicElementLabels.getPathLabel(fResourcePath.makeRelative(), false));
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), message));
        }
        // make sure all files inside the resource are saved so restoring works
        if (resource.isAccessible()) {
            resource.accept(new IResourceVisitor() {

                public boolean visit(IResource curr) throws CoreException {
                    try {
                        if (curr instanceof IFile) {
                            // progress is covered outside.
                            saveFileIfNeeded((IFile) curr, new NullProgressMonitor());
                        }
                    } catch (CoreException e) {
                    // ignore
                    }
                    return true;
                }
            }, IResource.DEPTH_INFINITE, false);
        }
        ResourceUndoState desc = ResourceUndoState.fromResource(resource);
        if (resource instanceof IProject) {
            ((IProject) resource).delete(fDeleteContent, fForceOutOfSync, new SubProgressMonitor(pm, 10));
        } else {
            int updateFlags;
            if (fForceOutOfSync) {
                updateFlags = IResource.KEEP_HISTORY | IResource.FORCE;
            } else {
                updateFlags = IResource.KEEP_HISTORY;
            }
            resource.delete(updateFlags, new SubProgressMonitor(pm, 5));
            desc.recordStateFromHistory(resource, new SubProgressMonitor(pm, 5));
        }
        return new UndoDeleteResourceChange(desc);
    } finally {
        pm.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) UndoDeleteResourceChange(org.eclipse.ltk.internal.core.refactoring.resource.UndoDeleteResourceChange) ResourceUndoState(org.eclipse.ltk.internal.core.refactoring.resource.undostates.ResourceUndoState) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

IResource (org.eclipse.core.resources.IResource)10 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)10 CoreException (org.eclipse.core.runtime.CoreException)9 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)5 Status (org.eclipse.core.runtime.Status)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ResourceChangeCommandFactory (org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ResourceAndInfo (org.apache.sling.ide.eclipse.core.internal.ResourceAndInfo)1 FilterResult (org.apache.sling.ide.filter.FilterResult)1 IContainer (org.eclipse.core.resources.IContainer)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1