Search in sources :

Example 6 with IResourceDeltaVisitor

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

the class ResourceChangeChecker method getChangedFiles.

/* package */
IFile[] getChangedFiles() throws CoreException {
    IResourceDelta root = fDeltaFactory.getDelta();
    final List result = new ArrayList();
    root.accept(new IResourceDeltaVisitor() {

        public boolean visit(IResourceDelta delta) throws CoreException {
            final IResource resource = delta.getResource();
            if (resource.getType() == IResource.FILE) {
                final int kind = delta.getKind();
                if (isSet(kind, IResourceDelta.CHANGED)) {
                    result.add(resource);
                } else if (isSet(kind, IResourceDelta.ADDED) && isSet(delta.getFlags(), IResourceDelta.CONTENT | IResourceDelta.MOVED_FROM)) {
                    final IFile movedFrom = resource.getWorkspace().getRoot().getFile(delta.getMovedFromPath());
                    result.add(movedFrom);
                }
            }
            return true;
        }
    });
    return (IFile[]) result.toArray(new IFile[result.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 7 with IResourceDeltaVisitor

use of org.eclipse.core.resources.IResourceDeltaVisitor in project azure-tools-for-java by Microsoft.

the class AIResourceChangeListener method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta resourcedelta = event.getDelta();
    IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta delta) throws CoreException {
            IProject project = delta.getResource().getProject();
            // Check if project is of required nature
            if (project != null && project.isOpen() && WebPropertyTester.isWebProj(project)) {
                handleResourceChange(delta);
            }
            return true;
        }
    };
    try {
        resourcedelta.accept(visitor);
        WorkspaceJob job = new WorkspaceJob(Messages.refreshJobName) {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                return Status.OK_STATUS;
            }
        };
        job.schedule();
    } catch (CoreException e) {
        Activator.getDefault().log(Messages.resChangeErr, e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 8 with IResourceDeltaVisitor

use of org.eclipse.core.resources.IResourceDeltaVisitor in project bndtools by bndtools.

the class OSGiRunLaunchDelegate method registerLaunchPropertiesRegenerator.

/**
     * Registers a resource listener with the project model file to update the launcher when the model or any of the
     * run-bundles changes. The resource listener is automatically unregistered when the launched process terminates.
     *
     * @param project
     * @param launch
     * @throws CoreException
     */
private void registerLaunchPropertiesRegenerator(final Project project, final ILaunch launch) throws CoreException {
    final IResource targetResource = LaunchUtils.getTargetResource(launch.getLaunchConfiguration());
    if (targetResource == null)
        return;
    final IPath bndbndPath;
    try {
        bndbndPath = Central.toPath(project.getPropertiesFile());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error querying bnd.bnd file location", e));
    }
    try {
        Central.toPath(project.getTarget());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error querying project output folder", e));
    }
    final IResourceChangeListener resourceListener = new IResourceChangeListener() {

        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            try {
                final AtomicBoolean update = new AtomicBoolean(false);
                // Was the properties file (bnd.bnd or *.bndrun) included in
                // the delta?
                IResourceDelta propsDelta = event.getDelta().findMember(bndbndPath);
                if (propsDelta == null && targetResource.getType() == IResource.FILE)
                    propsDelta = event.getDelta().findMember(targetResource.getFullPath());
                if (propsDelta != null) {
                    if (propsDelta.getKind() == IResourceDelta.CHANGED) {
                        update.set(true);
                    }
                }
                // list
                if (!update.get()) {
                    final Set<String> runBundleSet = new HashSet<String>();
                    for (String bundlePath : bndLauncher.getRunBundles()) {
                        runBundleSet.add(new org.eclipse.core.runtime.Path(bundlePath).toPortableString());
                    }
                    event.getDelta().accept(new IResourceDeltaVisitor() {

                        @Override
                        public boolean visit(IResourceDelta delta) throws CoreException {
                            // match
                            if (update.get())
                                return false;
                            IResource resource = delta.getResource();
                            if (resource.getType() == IResource.FILE) {
                                IPath location = resource.getLocation();
                                boolean isRunBundle = location != null ? runBundleSet.contains(location.toPortableString()) : false;
                                update.compareAndSet(false, isRunBundle);
                                return false;
                            }
                            // Recurse into containers
                            return true;
                        }
                    });
                }
                if (update.get()) {
                    project.forceRefresh();
                    project.setChanged();
                    bndLauncher.update();
                }
            } catch (Exception e) {
                logger.logError("Error updating launch properties file.", e);
            }
        }
    };
    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener);
    // Register a listener for termination of the launched process
    Runnable onTerminate = new Runnable() {

        @Override
        public void run() {
            ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener);
            display.asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (dialog != null && dialog.getShell() != null) {
                        dialog.getShell().dispose();
                    }
                }
            });
        }
    };
    DebugPlugin.getDefault().addDebugEventListener(new TerminationListener(launch, onTerminate));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) HashSet(java.util.HashSet)

Aggregations

IResourceDelta (org.eclipse.core.resources.IResourceDelta)8 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)8 CoreException (org.eclipse.core.runtime.CoreException)8 IResource (org.eclipse.core.resources.IResource)6 ArrayList (java.util.ArrayList)3 IProject (org.eclipse.core.resources.IProject)3 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IFile (org.eclipse.core.resources.IFile)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1