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()]);
}
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);
}
}
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));
}
Aggregations