Search in sources :

Example 26 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta in project ow by vtst.

the class ClosureBuilder method build.

/* (non-Javadoc)
	 * @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
	 */
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
    IProject project = getProject();
    OwJsDev.log("Start build: %s", project.getName());
    monitor.beginTask(messages.format("build_closure", project.getName()), 2);
    if (kind == FULL_BUILD) {
        fullBuild(monitor, project);
    } else {
        IResourceDelta delta = getDelta(project);
        if (delta == null) {
            fullBuild(monitor, project);
        } else {
            incrementalBuild(monitor, project, delta);
        }
    }
    monitor.done();
    OwJsDev.log("End build: %s", project.getName());
    return ResourceProperties.getTransitivelyReferencedProjects(project);
}
Also used : IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 27 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta 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 28 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta 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)

Example 29 with IResourceDelta

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

the class JAREditor method resourceChanged.

@Override
public void resourceChanged(final IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());
    IResourceDelta delta = event.getDelta();
    if (delta == null) {
        return;
    }
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null) {
        return;
    }
    if (delta.getKind() == IResourceDelta.REMOVED) {
        close(false);
    } else if (delta.getKind() == IResourceDelta.CHANGED) {
        updateContent(getEditorInput());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 30 with IResourceDelta

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

the class BndEditor method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());
    IResourceDelta delta = event.getDelta();
    if (delta == null)
        return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null)
        return;
    // Delegate to any interested pages
    for (Object page : pages) {
        if (page instanceof IResourceChangeListener) {
            ((IResourceChangeListener) page).resourceChanged(event);
        }
    }
    // Close editor if file removed or switch to new location if file moved
    if (delta.getKind() == IResourceDelta.REMOVED) {
        if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
            final FileEditorInput newInput = new FileEditorInput(file);
            setInput(newInput);
            Display display = getEditorSite().getShell().getDisplay();
            if (display != null) {
                SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {

                    @Override
                    public void run() {
                        setPartNameForInput(newInput);
                        sourcePage.setInput(newInput);
                    }
                });
            }
        } else {
            close(false);
        }
    } else // File content updated externally => reload all pages
    if ((delta.getKind() & IResourceDelta.CHANGED) > 0 && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
        if (!saving.get()) {
            final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
            // #1625: Ensure the IDocumentProvider is not null.
            if (docProvider != null) {
                final IDocument document = docProvider.getDocument(getEditorInput());
                SWTConcurrencyUtil.execForControl(getEditorSite().getShell(), true, new Runnable() {

                    @Override
                    public void run() {
                        try {
                            model.loadFrom(new IDocumentWrapper(document));
                            updateIncludedPages();
                        } catch (IOException e) {
                            logger.logError("Failed to reload document", e);
                        }
                    }
                });
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IOException(java.io.IOException) IDocumentWrapper(bndtools.editor.model.IDocumentWrapper) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display)

Aggregations

IResourceDelta (org.eclipse.core.resources.IResourceDelta)33 IResource (org.eclipse.core.resources.IResource)21 IPath (org.eclipse.core.runtime.IPath)12 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)9 IResourceDeltaVisitor (org.eclipse.core.resources.IResourceDeltaVisitor)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Iterator (java.util.Iterator)3 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)3 Project (aQute.bnd.build.Project)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IFolder (org.eclipse.core.resources.IFolder)2 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2