Java Code Examples for org.eclipse.core.resources.IResourceVisitor

The following are top voted examples for showing how to use org.eclipse.core.resources.IResourceVisitor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: n4js   File: IndexableFilesDiscoveryUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Scans workspace for files that may end up in XtextIndex when given location is processed by the builder. This is
 * naive filtering based on {@link IndexableFilesDiscoveryUtil#INDEXABLE_FILTERS file extensions}. Symlinks are not
 * followed.
 *
 * @param workspace
 *            to scan
 * @return collection of indexable locations
 * @throws CoreException
 *             if scanning of the workspace is not possible.
 */
public static Collection<String> collectIndexableFiles(IWorkspace workspace) throws CoreException {
	Set<String> result = new HashSet<>();
	workspace.getRoot().accept(new IResourceVisitor() {

		@Override
		public boolean visit(IResource resource) throws CoreException {
			if (resource.getType() == IResource.FILE) {
				IFile file = (IFile) resource;
				if (INDEXABLE_FILTERS.contains(file.getFileExtension().toLowerCase())) {
					result.add(file.getFullPath().toString());
				}
			}
			return true;
		}
	});
	return result;
}
 
Example 2
Project: neoscada   File: ProjectBuilder.java   Source Code and License 6 votes vote down vote up
protected void validateAll ( final IProject project, final ComposedAdapterFactory adapterFactory, final Set<String> extensions, final IProgressMonitor monitor )
{
    logger.debug ( "Validating all resources of {}", project );

    try
    {
        project.accept ( new IResourceVisitor () {

            @Override
            public boolean visit ( final IResource resource ) throws CoreException
            {
                return handleResource ( null, resource, adapterFactory, extensions, monitor );
            }
        } );
    }
    catch ( final CoreException e )
    {
        StatusManager.getManager ().handle ( e.getStatus () );
    }
}
 
Example 3
Project: subclipse   File: SVNTeamProvider.java   Source Code and License 6 votes vote down vote up
private void configureTeamPrivateResource(IProject project)
{
	try {
		project.accept(
				new IResourceVisitor() {
					public boolean visit(IResource resource) throws CoreException {
						if ((resource.getType() == IResource.FOLDER)
								&& (resource.getName().equals(SVNProviderPlugin.getPlugin().getAdminDirectoryName()))
								&& (!resource.isTeamPrivateMember()))
						{
							resource.setTeamPrivateMember(true);
							return false;
						}
						else
						{
							return true;
						}
					}
				}, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
	} catch (CoreException e) {
		SVNProviderPlugin.log(SVNException.wrapException(e));
	}
}
 
Example 4
Project: google-cloud-eclipse   File: FacetUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Returns a list of WEB-INF folders in {@code container}.
 */
@VisibleForTesting
static List<IFolder> findAllWebInfFolders(IContainer container) {
  final List<IFolder> webInfFolders = new ArrayList<>();

  try {
    IResourceVisitor webInfCollector = new IResourceVisitor() {
      @Override
      public boolean visit(IResource resource) throws CoreException {
        if (resource.getType() == IResource.FOLDER && "WEB-INF".equals(resource.getName())) {
          webInfFolders.add((IFolder) resource);
          return false;  // No need to visit sub-directories.
        }
        return true;
      }
    };
    container.accept(webInfCollector);
  } catch (CoreException ex) {
    // Our attempt to find folders failed, but don't error out.
  }
  return webInfFolders;
}
 
Example 5
Project: dsl-devkit   File: NewCheckCatalogWizardPage.java   Source Code and License 6 votes vote down vote up
/**
 * Checks if a given catalog name already exists in the project.
 * 
 * @param packageFragment
 *          the package in which the file is looked for
 * @return true, if catalog exists
 */
private boolean catalogExists(final IResource packageFragment) {
  final Set<IResource> foundResources = Sets.newHashSet();
  final String catalogName = getCatalogName() + '.' + CheckConstants.FILE_EXTENSION;
  IResourceVisitor catalogNameVisitor = new IResourceVisitor() {
    public boolean visit(final IResource res) throws CoreException {
      String resourceName = res.getName();
      if (catalogName.equalsIgnoreCase(resourceName)) {
        foundResources.add(res);
      }
      return foundResources.isEmpty();
    }
  };
  try {
    packageFragment.accept(catalogNameVisitor);
    return !foundResources.isEmpty();
  } catch (CoreException e) {
    // packageFragment does not yet exist. Therefore, the catalog name is unique.
    return false;
  }
}
 
Example 6
Project: bts   File: Storage2UriMapperImpl.java   Source Code and License 6 votes vote down vote up
/**
 * @since 2.4
 */
public Map<URI, IStorage> getAllEntries(IContainer container) {
	final Map<URI,IStorage> result = newLinkedHashMap();
	try {
		container.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				if (resource instanceof IFile) {
					final IFile storage = (IFile) resource;
					URI uri = getUri(storage);
					if (uri != null)
						result.put(uri, storage);
				}
				if (resource instanceof IFolder) {
					return isHandled((IFolder)resource);
				}
				return true;
			}
		});
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
	return result;
}
 
Example 7
Project: statecharts   File: WorkspaceTreeContentProvider.java   Source Code and License 6 votes vote down vote up
public Object[] filterForContent(Object[] inputElements) throws CoreException {
	final Set<Object> result = new LinkedHashSet<Object>();
	for (final Object obj : inputElements) {
		((IResource) obj).accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				// no file extension check
				if (resource instanceof IFile && hasFileExtension((IFile) resource)) {
					return false;
				}
				// check if file extension is proper
				else if (resource instanceof IFile && resource.getFileExtension().equals(fileExtension)) {
					result.add(obj);
					return true;
				} else if (resource instanceof IFolder && containsFile((IFolder) resource)) {
					result.add(obj);
					return true;
				}
				return false;
			}
		});
	}
	return result.toArray(new IResource[0]);
}
 
Example 8
Project: statecharts   File: DiagramPartitioningBreadcrumbViewer.java   Source Code and License 6 votes vote down vote up
protected Set<IFile> getProjectStatechartInput(Diagram diagram) {
	final IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
	final IProject project = file.getProject();
	final Set<IFile> result = new HashSet<IFile>();
	try {
		project.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				// TODO check for package explorer filters here
				if (resource.isHidden()) {
					return false;
				}
				if (resource instanceof IFile) {
					if (file.getFileExtension().equals(resource.getFileExtension()))
						result.add((IFile) resource);
				}
				return true;
			}
		});
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return result;
}
 
Example 9
Project: che   File: ResourceChangeDescriptionFactory.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 10
Project: che   File: DeleteResourcesProcessor.java   Source Code and License 6 votes vote down vote up
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);
  }
}
 
Example 11
Project: gwt-eclipse-plugin   File: LegacyGWTLaunchShortcutStrategy.java   Source Code and License 6 votes vote down vote up
private static Set<IFile> findHostPages(IFile moduleFile) {
  List<IFolder> publicFolders = getModulePublicFolders(moduleFile);
  if (publicFolders.isEmpty()) {
    return Collections.emptySet();
  }

  final Set<IFile> hostPages = new HashSet<IFile>();
  try {
    for (IFolder publicFolder : publicFolders) {
      publicFolder.accept(new IResourceVisitor() {
        public boolean visit(IResource resource) throws CoreException {
          // Look for any HTML files
          if (resource.getType() == IResource.FILE
              && "html".equalsIgnoreCase(resource.getFileExtension())) {
            hostPages.add((IFile) resource);
          }
          return true;
        }
      });
    }
  } catch (CoreException e) {
    CorePluginLog.logError(e);
  }

  return hostPages;
}
 
Example 12
Project: gwt-eclipse-plugin   File: ModuleUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Finds all GWT modules located directly in a particular container.
 *
 * @param container container to search within
 * @return the list of modules found
 */
public static IModule[] findChildModules(IContainer container) {
  final List<IModule> modules = new ArrayList<IModule>();

  IResourceVisitor moduleVisitor = new IResourceVisitor() {
    @Override
    public boolean visit(IResource resource) throws CoreException {
      if (resource.getType() == IResource.FILE) {
        IModule module = create((IFile) resource);
        if (module != null) {
          modules.add(module);
        }
      }
      return true;
    }
  };

  try {
    container.accept(moduleVisitor, IResource.DEPTH_ONE, false);
  } catch (CoreException e) {
    GWTPluginLog.logError(e);
  }

  return modules.toArray(new IModule[modules.size()]);
}
 
Example 13
Project: umlet   File: UmletBuilder.java   Source Code and License 6 votes vote down vote up
@Override
protected void clean(IProgressMonitor monitor) throws CoreException {

	IProject project = getProject();
	project.accept(new IResourceVisitor() {

		@Override
		public boolean visit(IResource res) throws CoreException {
			if (res instanceof IFile) {
				IFile png = (IFile) res;
				if ("png".equalsIgnoreCase(png.getFileExtension())) {
					IFile uxf = UmletPluginUtils.getUxfDiagramForImgFile(png);
					if (uxf.exists()) {
						// clean only pngs with corresponding umlet diagrams
						png.delete(true, null);
					}
				}
			}
			return true;
		}
	});
}
 
Example 14
Project: chromedevtools   File: FileBasedAction.java   Source Code and License 6 votes vote down vote up
private static <RES> List<RES> readFiles(ResourceMapping resourceMapping,
    final FileFilter<RES> fileFilter) {
  final List<RES> fileList = new ArrayList<RES>(1);
  IResourceVisitor visitor = new IResourceVisitor() {
    public boolean visit(IResource resource) throws CoreException {
      if (resource instanceof IFile == false) {
        return true;
      } else {
        IFile file = (IFile) resource;
        RES res = fileFilter.accept(file);
        if (res != null) {
          fileList.add(res);
        }
        return false;
      }
    }
  };
  try {
    resourceMapping.accept(null, visitor, null);
  } catch (CoreException e) {
    throw new RuntimeException(e);
  }
  return fileList;
}
 
Example 15
Project: filesync4eclipse   File: TestBuilder.java   Source Code and License 6 votes vote down vote up
private void delete() throws CoreException {
	IResourceVisitor visitor = new IResourceVisitor() {
		public boolean visit(IResource resource) throws CoreException {
			if (resource.getName().startsWith(".")) {
				return false;
			}
			// there is a possibility for bugs if variables file is deleted too
			// then sync breaks ... so this is intensionally
			// disabled to simulate deletion of variables files
			//                if (resource.getName().startsWith(PREFIX_EXCL_FROM_SYNC)) {
			//                    return false;
			//                }
			if (resource.getType() == IResource.FOLDER) {
				resource.delete(true, monitor);
				return false;
			}
			return true;
		}
	};
	srcProj.accept(visitor);
}
 
Example 16
Project: APICloud-Studio   File: SVNTeamProvider.java   Source Code and License 6 votes vote down vote up
private void configureTeamPrivateResource(IProject project)
{
	try {
		project.accept(
				new IResourceVisitor() {
					public boolean visit(IResource resource) throws CoreException {
						if ((resource.getType() == IResource.FOLDER)
								&& (resource.getName().equals(SVNProviderPlugin.getPlugin().getAdminDirectoryName()))
								&& (!resource.isTeamPrivateMember()))
						{
							resource.setTeamPrivateMember(true);
							return false;
						}
						else
						{
							return true;
						}
					}
				}, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
	} catch (CoreException e) {
		SVNProviderPlugin.log(SVNException.wrapException(e));
	}
}
 
Example 17
Project: mondo-hawk   File: Workspace.java   Source Code and License 6 votes vote down vote up
private Set<IFile> getAllFiles() {
	try {
		final Set<IFile> allFiles = new HashSet<>();
		ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				if (resource instanceof IFile) {
					allFiles.add((IFile) resource);
				}
				return true;
			}

		});
		return allFiles;
	} catch (CoreException e) {
		console.printerrln(e);
		return Collections.emptySet();
	}
}
 
Example 18
Project: OpenSPIFe   File: EPlanUtils.java   Source Code and License 6 votes vote down vote up
public static IFile getPlanFile(IProject project) {
	final List<IFile> planFiles = new ArrayList<IFile>();
	try {
		project.accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) {
				if (resource instanceof IFile 
						&& CommonUtils.equals("plan", resource.getFileExtension())
						&& !CommonUtils.equals("template.plan", resource.getName())) {
					planFiles.add((IFile) resource);
				}
				return true;
			}
		});
	} catch (CoreException e) {
		LogUtil.error(e);
	}
	if (planFiles.isEmpty()) {
		LogUtil.warn("Didn't fine any .plan files in project " + project.getName());
		return null;
	} else if (planFiles.size() > 1) {
		LogUtil.warn("Found more than one .plan file in project " + project.getName());
	} 
	return planFiles.get(0);
}
 
Example 19
Project: thym   File: CordovaPluginManager.java   Source Code and License 6 votes vote down vote up
private void updatePluginList() throws CoreException {
	long start = System.currentTimeMillis();
	if(installedPlugins == null || installedPlugins.isEmpty()) {
		HybridCore.trace("Really updating the installed plugin list");
		IResourceVisitor visitor = new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				if(resource.getType() == IResource.FOLDER){
					IFolder folder = (IFolder) resource.getAdapter(IFolder.class);
					IFile file = folder.getFile(PlatformConstants.FILE_XML_PLUGIN);
					if(file.exists()){
						addInstalledPlugin(file);
					}
				}
				return resource.getName().equals(PlatformConstants.DIR_PLUGINS);
			}
		};
		IFolder plugins = this.project.getProject().getFolder(PlatformConstants.DIR_PLUGINS);
		if(plugins != null && plugins.exists()){
			synchronized (installedPlugins) {
				plugins.accept(visitor,IResource.DEPTH_ONE,false);
			}
		}
	}
	HybridCore.trace(NLS.bind("Updated plugin list in {0} ms", (System.currentTimeMillis() - start)));
}
 
Example 20
Project: AutoDeriv   File: TreeRule.java   Source Code and License 6 votes vote down vote up
@Override
public void applyOnProject(final IProgressMonitor progress) {
	// initialization
	if(!checkIni()) return;

	// effective action
	try {
		member.accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource res) throws CoreException {
				Tools.checkedSetDerived(res, isDerived, progress);
				return true;
			}
		});
	} catch (CoreException e) { e.printStackTrace(); }
}
 
Example 21
Project: Pydev   File: PyFileListing.java   Source Code and License 6 votes vote down vote up
/**
 * @return All the IFiles below the current folder that are python files (does not check if it has an __init__ path)
 */
public static List<IFile> getAllIFilesBelow(IContainer member) {
    final ArrayList<IFile> ret = new ArrayList<IFile>();
    try {
        member.accept(new IResourceVisitor() {

            @Override
            public boolean visit(IResource resource) {
                if (resource instanceof IFile) {
                    ret.add((IFile) resource);
                    return false; //has no members
                }
                return true;
            }

        });
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
    return ret;
}
 
Example 22
Project: bento   File: FindFileDialog.java   Source Code and License 6 votes vote down vote up
@Override
public int open() {
	final ArrayList<IResource> resources = new ArrayList<IResource>();

	try {
		ResourcesPlugin.getWorkspace().getRoot().accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				// if ( resource instanceof IFile && ((IFile) resource).
				if ( resource.getLocation() != null && resource.getLocation().getFileExtension() != null && 
					 resource.getLocation().getFileExtension().equals( extension ) ) {
					resources.add(resource);
				}
				return true;
			}
		});
	} catch (CoreException e1) {
		e1.printStackTrace();
	}

	this.setElements(resources.toArray());

	return super.open();
}
 
Example 23
Project: q7.quality.mockups   File: LockResourcesPart.java   Source Code and License 6 votes vote down vote up
protected void lockResources() {
	if (files.size() == 0) {
		try {
			ResourcesPlugin.getWorkspace().getRoot()
					.accept(new IResourceVisitor() {

						public boolean visit(IResource resource)
								throws CoreException {
							if (resource.isAccessible()
									&& resource.getType() == IResource.FILE) {
								files.put((IFile) resource,
										((IFile) resource).getContents());
							}
							return resource.isAccessible();
						}
					});
		} catch (CoreException e) {
			e.printStackTrace();
		}
		if (files.size() > 0) {
			value.setValue("Locked:" + files.size());
		}
	}
}
 
Example 24
Project: GrayTin   File: DownloadSdkBundlesJob.java   Source Code and License 6 votes vote down vote up
private void cleanUpFolder(final IProgressMonitor monitor) throws CoreException {
	monitor.subTask("Deleting existing files.");
	// delete all files in the target folder

	sdkBundlesFolder.accept(new IResourceVisitor() {

		@Override
		public boolean visit(IResource resource) {
			if (resource instanceof IFile) {
				deleteFile((IFile) resource, monitor);
			}
			return true;
		}
	}, IResource.DEPTH_ONE, false);
	monitor.worked(1);
}
 
Example 25
Project: byteman-editor   File: BytemanEditorPluginBuilder.java   Source Code and License 6 votes vote down vote up
protected void fullBuild(IProgressMonitor monitor) {
	class FullBuildVisitor implements IResourceVisitor {

		@Override
		public boolean visit(IResource resource) throws CoreException {
			buildRuleFile(resource);
			return true;
		}
	}

	try {
		getProject().accept(new FullBuildVisitor());
	} catch (CoreException e) {
		BytemanEditorPlugin.logException(e);
	}
}
 
Example 26
Project: byteman-editor   File: BytemanEditorPluginBuilder.java   Source Code and License 6 votes vote down vote up
protected void cleanBuild(IProgressMonitor monitor) {
	class CleanBuildVisitor implements IResourceVisitor {
		@Override
		public boolean visit(IResource resource) throws CoreException {
			if(resource instanceof IFile && resource.getName().endsWith(".btm")) {
				BytemanRuleValidator.deleteMarker(resource);
			}
			return true;
		}
	}
	try {
		getProject().accept(new CleanBuildVisitor());
	} catch (CoreException e) {
		BytemanEditorPlugin.logException(e);
	}
}
 
Example 27
Project: n4js   File: ExternalFolder.java   Source Code and License 5 votes vote down vote up
@Override
public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
	if (depth == DEPTH_ZERO) {
		visitor.visit(this);
	} else {
		if (visitor.visit(this)) {
			for (IResource member : members()) {
				member.accept(visitor, DEPTH_ONE == depth ? DEPTH_ZERO : DEPTH_INFINITE, memberFlags);
			}
		}
	}
}
 
Example 28
Project: n4js   File: ExternalFolder.java   Source Code and License 5 votes vote down vote up
private void acceptUnsafe(IResourceVisitor visitor) {
	try {
		accept(visitor);
	} catch (final CoreException e) {
		throw new RuntimeException("Error while visiting resource." + this, e);
	}
}
 
Example 29
Project: n4js   File: ExternalProject.java   Source Code and License 5 votes vote down vote up
@Override
public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
	if (depth == DEPTH_ZERO) {
		visitor.visit(this);
	} else {
		if (visitor.visit(this)) {
			for (IResource member : members()) {
				member.accept(visitor, DEPTH_ONE == depth ? DEPTH_ZERO : DEPTH_INFINITE, memberFlags);
			}
		}
	}
}
 
Example 30
Project: n4js   File: ExternalProject.java   Source Code and License 5 votes vote down vote up
private void acceptUnsafe(IResourceVisitor visitor) {
	try {
		accept(visitor);
	} catch (CoreException e) {
		throw new RuntimeException("Error while visiting resource." + this, e);
	}
}
 
Example 31
Project: n4js   File: EclipseBasedN4JSWorkspace.java   Source Code and License 5 votes vote down vote up
@Override
public UnmodifiableIterator<URI> getFolderIterator(URI folderLocation) {
	final IContainer container;
	if (DIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT == folderLocation.segmentCount()) {
		container = workspace.getProject(folderLocation.lastSegment());
	} else {
		container = workspace.getFolder(new Path(folderLocation.toPlatformString(true)));
	}
	if (container != null && container.exists()) {
		final List<URI> result = Lists.newLinkedList();
		try {
			container.accept(new IResourceVisitor() {
				@Override
				public boolean visit(IResource resource) throws CoreException {
					if (resource.getType() == IResource.FILE) {
						result.add(URI.createPlatformResourceURI(resource.getFullPath().toString(), true));
					}
					return true;
				}
			});
			return Iterators.unmodifiableIterator(result.iterator());
		} catch (CoreException e) {
			return Iterators.unmodifiableIterator(result.iterator());
		}
	}
	return Iterators.emptyIterator();
}
 
Example 32
Project: gw4e.project   File: JDTManager.java   Source Code and License 5 votes vote down vote up
public static IPath guessPackageRootFragment(IProject project, boolean main)
		throws CoreException, FileNotFoundException {
	IPath folder = project.getFullPath()
			.append(GraphWalkerContextManager.getTargetFolderForTestInterface(project.getName(), main));

	IResource interfaceFolder = ResourceManager.toResource(folder);
	List<IPath> paths = new ArrayList<IPath>();
	if (interfaceFolder != null) {
		interfaceFolder.accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				IJavaElement element = JavaCore.create(resource);
				if (element != null && element instanceof ICompilationUnit) {
					try {
						ICompilationUnit cu = (ICompilationUnit) element;
						CompilationUnit ast = parse(cu);
						ast.accept(new ASTVisitor() {
							public boolean visit(PackageDeclaration node) {
								PackageDeclaration decl = (PackageDeclaration) node;
								String pkgname = decl.getName().getFullyQualifiedName();
								int sizePath = pkgname.split("\\.").length;
								paths.add(resource.getParent().getFullPath().removeLastSegments(sizePath));
								return false;
							}
						});
					} catch (Exception e) {
						ResourceManager.logException(e);
					}
				}
				return true;
			}
		});
	}
	if (paths.size() == 0)
		return null;
	return paths.get(0);
}
 
Example 33
Project: gw4e.project   File: JDTManager.java   Source Code and License 5 votes vote down vote up
/**
 * @param project
 * @return
 * @throws CoreException
 * @throws FileNotFoundException
 */
public static ICompilationUnit[] getExistingGeneratedTestInterfaces(IProject project, boolean main)
		throws CoreException, FileNotFoundException {
	IPath folder = project.getFullPath()
			.append(GraphWalkerContextManager.getTargetFolderForTestInterface(project.getName(), main));
	List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
	IResource interfaceFolder = ResourceManager.toResource(folder);
	if (interfaceFolder != null) {
		interfaceFolder.accept(new IResourceVisitor() {
			@Override
			public boolean visit(IResource resource) throws CoreException {
				IJavaElement element = JavaCore.create(resource);
				if (element != null && element instanceof ICompilationUnit) {
					try {
						ICompilationUnit cu = (ICompilationUnit) element;
						IType interf = cu.findPrimaryType();
						if (interf != null && interf.isInterface()) {
							units.add(cu);
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				return true;
			}
		});
	}
	ICompilationUnit[] ret = new ICompilationUnit[units.size()];
	units.toArray(ret);
	return ret;
}
 
Example 34
Project: gw4e.project   File: ResourceManagerTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testCreateFileDeleteIfExistsStringStringStringIProgressMonitor() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, true);
	IFile impl = (IFile) ResourceManager
			.getResource(project.getProject().getFullPath().append("src/test/java/SimpleImpl.java").toString());
	int[] count = new int[1];

	count[0] = 0;
	IResourceVisitor visitor = new IResourceVisitor() {
		@Override
		public boolean visit(IResource resource) throws CoreException {
			if (resource.getFileExtension() != null && resource.getFileExtension().equalsIgnoreCase("java")) {
				count[0] = count[0] + 1;
			}
			return true;
		}
	};
	impl.getParent().accept(visitor);
	assertTrue(count[0] == 1);

	ResourceManager.createFileDeleteIfExists(impl.getParent().getFullPath().toString(), "SimpleImpl.java", "",
			new NullProgressMonitor());
	String s = IOHelper.getContent(impl);
	assertTrue(s.length() == 0);

	count[0] = 0;
	impl.getParent().accept(visitor);
	assertTrue(count[0] == 2);
}
 
Example 35
Project: visuflow-plugin   File: Visuflow.java   Source Code and License 5 votes vote down vote up
@Override
public void start(BundleContext context) {

	Visuflow.context = context;
	plugin = this;
	logger = new Logger(getLog());
	logger.info("Visuflow plug-in starting...");
	JimpleBreakpointManager.getInstance();

	// iterate over all projects in the workspace to find projects with the
	// visuflow nature. for these projects we trigger a full build to fill
	// the data model directly after the launch. there is also the ProjectListener,
	// which triggers a build for newly opened projects (e.g. opening a closed one or
	// importing a project etc.)
	// the builds are only executed, if the workspace is set to auto build
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(projectListener, IResourceChangeEvent.POST_CHANGE);
	if(workspace.isAutoBuilding()) {
		IWorkspaceRoot root = workspace.getRoot();
		try {
			root.accept(new IResourceVisitor() {
				@Override
				public boolean visit(IResource resource) throws CoreException {
					if(resource.getType() == IResource.PROJECT) {
						IProject project = (IProject) resource;
						projectListener.triggerBuild(project);
						return false;
					}
					return true;
				}
			});
		} catch (CoreException e) {
			logger.error("Error while trying to build visuflow projects", e);
		}
	}
}
 
Example 36
Project: subclipse   File: StatusCacheManager.java   Source Code and License 5 votes vote down vote up
private Set<IResource> resourcesToRefresh(IResource resource, int depth, int flags, int expectedSize) throws CoreException
  {
      if (!resource.exists() && !resource.isPhantom())
      {
          return new HashSet<IResource>(0);
      }
  	final Set<IResource> resultSet = (expectedSize != 0) ? new HashSet<IResource>(expectedSize) : new HashSet<IResource>();
resource.accept(new IResourceVisitor() {
	public boolean visit(IResource aResource) throws CoreException {
		resultSet.add(aResource);
		return true;
	}
}, depth, flags);
return resultSet;
  }
 
Example 37
Project: subclipse   File: SVNLightweightDecorator.java   Source Code and License 5 votes vote down vote up
public void refresh(IProject project) {
	final List resources = new ArrayList();
	try {
		project.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) {
				resources.add(resource);
				return true;
			}
		});
		postLabelEvent(new LabelProviderChangedEvent(this, resources.toArray()));
	} catch (CoreException e) {
		SVNProviderPlugin.log(e.getStatus());
	}
}
 
Example 38
Project: dsl-devkit   File: DeployJob.java   Source Code and License 5 votes vote down vote up
/**
 * Fetches the check configuration files of this project.
 *
 * @return the list of configuration files, never {@code null}
 * @throws DeployException
 *           deploy exception
 */
private List<IFile> getCheckConfigurationFiles() throws DeployException {
  final List<IFile> checkCfgFiles = new ArrayList<IFile>();
  try {
    project.accept(new IResourceVisitor() {
      @Override
      public boolean visit(final IResource resource) throws CoreException {
        if (resource instanceof IProject) {
          return true;
        }
        if (resource instanceof IFile && CheckCfgConstants.FILE_EXTENSION.equals(((IFile) resource).getFileExtension())) {
          checkCfgFiles.add((IFile) resource);
          return false;
        }
        if (isProjectJarIgnoreResource(resource)) {
          return false;
        }
        if (resource instanceof IFolder && "bin".equals(resource.getName())) {
          return false;
        }
        return true;
      }
    });
  } catch (CoreException e) {
    LOGGER.error(e.getMessage(), e);
    throw new DeployException(e);
  }
  return checkCfgFiles;
}
 
Example 39
Project: bts   File: AbstractProjectCreator.java   Source Code and License 5 votes vote down vote up
protected IFile getModelFile(IProject project) throws CoreException {
	IFolder srcFolder = project.getFolder(getModelFolderName());
	final String expectedExtension = getPrimaryModelFileExtension();
	final IFile[] result = new IFile[1];
	srcFolder.accept(new IResourceVisitor() {
		public boolean visit(IResource resource) throws CoreException {
			if (IResource.FILE == resource.getType() && expectedExtension.equals(resource.getFileExtension())) {
				result[0] = (IFile) resource;
				return false;
			}
			return IResource.FOLDER == resource.getType();
		}
	});
	return result[0];
}
 
Example 40
Project: che   File: Resource.java   Source Code and License 5 votes vote down vote up
@Override
public void accept(final IResourceVisitor visitor, int depth, int memberFlags)
    throws CoreException {
  // use the fast visitor if visiting to infinite depth
  if (depth == IResource.DEPTH_INFINITE) {
    accept(
        new IResourceProxyVisitor() {
          public boolean visit(IResourceProxy proxy) throws CoreException {
            return visitor.visit(proxy.requestResource());
          }
        },
        memberFlags);
    return;
  }
  // it is invalid to call accept on a phantom when INCLUDE_PHANTOMS is not specified
  final boolean includePhantoms = (memberFlags & IContainer.INCLUDE_PHANTOMS) != 0;
  ResourceInfo info = getResourceInfo(includePhantoms, false);
  int flags = getFlags(info);
  if ((memberFlags & IContainer.DO_NOT_CHECK_EXISTENCE) == 0) checkAccessible(flags);

  // check that this resource matches the member flags
  if (!isMember(flags, memberFlags)) return;
  // visit this resource
  if (!visitor.visit(this) || depth == DEPTH_ZERO) return;
  // get the info again because it might have been changed by the visitor
  info = getResourceInfo(includePhantoms, false);
  if (info == null) return;
  // thread safety: (cache the type to avoid changes -- we might not be inside an operation)
  int type = info.getType();
  if (type == FILE) return;
  // if we had a gender change we need to fix up the resource before asking for its members
  IContainer resource =
      getType() != type
          ? (IContainer) workspace.newResource(getFullPath(), type)
          : (IContainer) this;
  IResource[] members = resource.members(memberFlags);
  for (int i = 0; i < members.length; i++)
    members[i].accept(visitor, DEPTH_ZERO, memberFlags | IContainer.DO_NOT_CHECK_EXISTENCE);
}