Search in sources :

Example 11 with IResourceDelta

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

the class DeltaWrapper method hasProjectChanged.

/*
     * Any change other then src, test, test_bin, or generated is fair game.
     */
boolean hasProjectChanged() throws Exception {
    if (delta == null) {
        log.basic("Full build because delta is null");
        return true;
    }
    final AtomicBoolean result = new AtomicBoolean(false);
    delta.accept(new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta visitDelta) throws CoreException {
            if ((delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED)) == 0)
                return false;
            IResource resource = visitDelta.getResource();
            if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
                return true;
            String path = resource.getProjectRelativePath().toString();
            if (resource.getType() == IResource.FOLDER) {
                if (//
                check(path, model.getProperty(Constants.DEFAULT_PROP_SRC_DIR)) || //
                check(path, model.getProperty(Constants.DEFAULT_PROP_TESTSRC_DIR)) || //
                check(path, model.getProperty(Constants.DEFAULT_PROP_TESTBIN_DIR)) || check(path, model.getProperty(Constants.DEFAULT_PROP_TARGET_DIR))) {
                    return false;
                }
            }
            if (IResourceDelta.MARKERS == delta.getFlags())
                return false;
            if (check(path, Project.BNDFILE))
                return false;
            log.basic("%s changed", resource);
            result.set(true);
            return false;
        }
    });
    return result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 12 with IResourceDelta

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

the class DeltaWrapper method toFiles.

private List<String> toFiles(final boolean dirsAlso) throws CoreException {
    if (delta == null)
        return null;
    final List<String> files = new ArrayList<String>();
    delta.accept(new IResourceDeltaVisitor() {

        @Override
        public boolean visit(IResourceDelta d) throws CoreException {
            IResource r = d.getResource();
            if (r != null) {
                if (r.getType() == IResource.PROJECT) {
                    return true;
                }
                if (r.getType() == IResource.FILE) {
                    files.add(d.getProjectRelativePath().toString());
                    return false;
                }
                if (r.getType() == IResource.FOLDER) {
                    if (dirsAlso)
                        files.add(d.getProjectRelativePath().toString());
                    return true;
                }
            }
            return false;
        }
    });
    return files;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 13 with IResourceDelta

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

the class DeltaWrapper method has.

private boolean has(File f) throws Exception {
    if (f == null)
        return false;
    if (delta == null)
        return false;
    IPath path = Central.toPath(f);
    if (path == null)
        return false;
    IPath relativePath = path.makeRelativeTo(delta.getFullPath());
    if (relativePath == null)
        return false;
    IResourceDelta delta = this.delta.findMember(relativePath);
    if (delta == null)
        return false;
    if ((delta.getFlags() == IResourceDelta.MARKERS))
        return false;
    if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED || delta.getKind() == IResourceDelta.REMOVED)
        return true;
    return false;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 14 with IResourceDelta

use of org.eclipse.core.resources.IResourceDelta 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) ArrayList(java.util.ArrayList) List(java.util.List) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 15 with IResourceDelta

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

the class DeltaProcessor method mergeDeltas.

/*
     * Merges all awaiting deltas.
     */
private IJavaElementDelta mergeDeltas(Collection deltas) {
    if (deltas.size() == 0)
        return null;
    if (deltas.size() == 1)
        return (IJavaElementDelta) deltas.iterator().next();
    if (VERBOSE) {
        System.out.println(//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "MERGING " + deltas.size() + " DELTAS [" + Thread.currentThread() + "]");
    }
    Iterator iterator = deltas.iterator();
    JavaElementDelta rootDelta = new JavaElementDelta(this.manager.javaModel);
    boolean insertedTree = false;
    while (iterator.hasNext()) {
        JavaElementDelta delta = (JavaElementDelta) iterator.next();
        if (VERBOSE) {
            System.out.println(delta.toString());
        }
        IJavaElement element = delta.getElement();
        if (this.manager.javaModel.equals(element)) {
            IJavaElementDelta[] children = delta.getAffectedChildren();
            for (int j = 0; j < children.length; j++) {
                JavaElementDelta projectDelta = (JavaElementDelta) children[j];
                rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta);
                insertedTree = true;
            }
            IResourceDelta[] resourceDeltas = delta.getResourceDeltas();
            if (resourceDeltas != null) {
                for (int i = 0, length = resourceDeltas.length; i < length; i++) {
                    rootDelta.addResourceDelta(resourceDeltas[i]);
                    insertedTree = true;
                }
            }
        } else {
            rootDelta.insertDeltaTree(element, delta);
            insertedTree = true;
        }
    }
    if (insertedTree)
        return rootDelta;
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) Iterator(java.util.Iterator) IJavaElementDelta(org.eclipse.jdt.core.IJavaElementDelta) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

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