Java Code Examples for org.eclipse.core.resources.IFolder#accept()

The following examples show how to use org.eclipse.core.resources.IFolder#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractProjectCreator.java    From xtext-eclipse with Eclipse Public License 2.0 6 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() {
		@Override
		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 2
Source File: TmfExperimentElement.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private List<IResource> getTraceResources() {
    IFolder folder = getResource();
    final List<IResource> list = new ArrayList<>();
    try {
        folder.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy resource) throws CoreException {
                /*
                 * Trace represented by a file, or a link for backward compatibility
                 */
                if (resource.getType() == IResource.FILE || resource.isLinked()) {
                    list.add(resource.requestResource());
                    /* don't visit linked folders, as they might contain files */
                    return false;
                }
                return true;
            }
        }, IResource.NONE);
    } catch (CoreException e) {
    }
    list.sort(Comparator.comparing(resource -> resource.getFullPath().toString()));
    return list;
}
 
Example 3
Source File: LegacyGWTLaunchShortcutStrategy.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 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 4
Source File: FileUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static IFile findExistingLinkedFile(final IFolder folder, final String name) {
	final IFile[] result = new IFile[1];
	try {
		folder.accept((IResourceVisitor) resource -> {
			if (resource.isLinked()) {
				final String p = resource.getLocation().toString();
				if (p.equals(name)) {
					result[0] = (IFile) resource;
					return false;
				}
			}
			return true;

		}, IResource.DEPTH_INFINITE, IResource.FILE);
	} catch (final CoreException e1) {
		e1.printStackTrace();
	}
	final IFile file = result[0];
	return file;
}
 
Example 5
Source File: CordovaPluginManager.java    From thym with Eclipse Public License 1.0 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 6
Source File: JavaRefactoringIntegrationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@After
public void deleteFilesCreatedByTest() throws Exception {
	IProject project = testHelper.getProject();
	IFolder folder = project.getFolder("src");
	folder.accept((IResource resource) -> {
		if (resource instanceof IFile)
			resource.delete(true, new NullProgressMonitor());
		return true;
	});
	syncUtil.waitForBuild(null);
}
 
Example 7
Source File: Axis2ServiceUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * This method provides logic for getting all Axis2 service folders with related project in workspace.
 *
 * @return a map contains all service folders with corresponding project
 * @throws org.wso2.developerstudio.eclipse.utils.exception.Axis2ServiceUtilsException
 */
public static Map<IFolder, IProject> getServiceFolders() throws Axis2ServiceUtilsException {
	Map<IFolder, IProject> map = new HashMap<IFolder, IProject>();
	for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
		if (WebUtils.isDynamicWebProject(project)) {
			final IFolder servicesFolder;
			servicesFolder = WebUtils.getAxis2WebContainerWEB_INFServicesFolderPath(project);
			final List<IFolder> folders = new ArrayList<IFolder>();
			try {
				if (servicesFolder.exists()) {
					servicesFolder.accept(new IResourceVisitor() {
						public boolean visit(IResource resource) throws CoreException {
							if (resource.getLocation().toOSString()
									.equals(servicesFolder.getLocation().toOSString())) {
								return true;
							} else {
								if (resource instanceof IFolder) {
									folders.add((IFolder) resource);
								}
							}
							return false;
						}

					});
				}
			} catch (CoreException e) {
				throw new Axis2ServiceUtilsException("Error in getting service folders for Axis2 projects", e);
			}
			for (IFolder folder : folders) {
				map.put(folder, project);
			}
		}
	}
	return map;
}
 
Example 8
Source File: AbstractRepositoryStore.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected List<IResource> listChildren() throws CoreException {
    refresh();
    final IFolder folder = getResource();
    final FileStoreCollector collector = new FileStoreCollector(folder,
            toArray(getCompatibleExtensions(), String.class));
    if (folder.exists()) {
        folder.accept(collector);
    }
    return collector.toList();
}
 
Example 9
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Clear the traces folder
 *
 * @param bot
 *            a given workbench bot
 * @param projectName
 *            the name of the project (needs to exist)
 */
public static void clearTracesFolder(SWTWorkbenchBot bot, String projectName) {
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
    TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
    if (tracesFolder == null) {
        return;
    }
    try {
        for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
            traceElement.delete(null);
        }

        final IFolder resource = tracesFolder.getResource();
        resource.accept(new IResourceVisitor() {
            @Override
            public boolean visit(IResource visitedResource) throws CoreException {
                if (visitedResource != resource) {
                    visitedResource.delete(true, null);
                }
                return true;
            }
        }, IResource.DEPTH_ONE, 0);
    } catch (CoreException e) {
        fail(e.getMessage());
    }

    bot.waitUntil(new DefaultCondition() {
        private int fTraceNb = 0;

        @Override
        public boolean test() throws Exception {
            List<TmfTraceElement> traces = tracesFolder.getTraces();
            fTraceNb = traces.size();
            return fTraceNb == 0;
        }

        @Override
        public String getFailureMessage() {
            return "Traces Folder not empty (" + fTraceNb + ")";
        }
    });
}
 
Example 10
Source File: BuildDelegate.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void buildNow(IProgressMonitor monitor) throws CoreException {
	if(monitor.isCanceled())
		return;
	
	SubMonitor sm = SubMonitor.convert(monitor, "Build project for Android", 100);

	try {
		HybridProject hybridProject = HybridProject.getHybridProject(this.getProject());
		if (hybridProject == null) {
			throw new CoreException(new Status(IStatus.ERROR, AndroidCore.PLUGIN_ID,
					"Not a hybrid mobile project, can not generate files"));
		}
		String buildType = "--debug";
		if(isRelease()){
			buildType = "--release";
		}
		hybridProject.build(sm.split(90), "android",buildType);
		
		IFolder androidProject = hybridProject.getProject().getFolder("platforms/android");
		androidProject.accept(new IResourceProxyVisitor() {
			
			@Override
			public boolean visit(IResourceProxy proxy) throws CoreException {
				switch (proxy.getType()) {
				case IResource.FOLDER:
					for (String folder : outputFolders) {
							if(folder.equals(proxy.getName())){
							return true;
						}
					}
					break;
				case IResource.FILE:
					if(isRelease() && proxy.getName().endsWith("-release-unsigned.apk")){
						setBuildArtifact(proxy.requestResource().getLocation().toFile());
						return false;
					}
					if(proxy.getName().endsWith("-debug.apk")){
						setBuildArtifact(proxy.requestResource().getLocation().toFile());
						return false;
					}
				default:
					break;
				}
				return false;
			}
		}, IContainer.INCLUDE_HIDDEN | IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS );
		
       	if(getBuildArtifact() == null || !getBuildArtifact().exists()){
       		throw new CoreException(new Status(IStatus.ERROR, AndroidCore.PLUGIN_ID, "Build failed... Build artifact does not exist"));
       	}
	}
	finally{
		sm.done();
	}
}
 
Example 11
Source File: ImportChartRuntimeAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handle action to clear some old chart runtime files
 * 
 * @param webContentPath
 * @param monitor
 * @throws Exception
 */
protected void doClearAction( IPath webContentPath, IProgressMonitor monitor )
		throws Exception
{
	// remove the root folder
	IPath webPath = webContentPath;
	if ( webPath.segmentCount( ) > 0 )
		webPath = webPath.removeFirstSegments( 1 );

	// get conflict resources
	Map<String, List<String>> map = BirtWizardUtil.initConflictResources( null );

	// clear
	Iterator<Entry<String, List<String>>> it = map.entrySet( ).iterator( );
	while ( it.hasNext( ) )
	{
		Entry<String, List<String>> entry = it.next();
		String folder = (String) entry.getKey( );
		if ( folder == null )
			continue;

		// get the target folder
		IPath path = webPath.append( folder );
		IFolder tempFolder = project.getFolder( path );
		if ( tempFolder == null || !tempFolder.exists( ) )
			continue;

		List<String> files = (List<String>) entry.getValue( );
		if ( files == null || files.size( ) <= 0 )
		{
			// delete the whole folder
			tempFolder.delete( true, monitor );
		}
		else
		{
			// delete the defined files
			tempFolder.accept( new LibResourceVisitor( monitor, files ),
					IResource.DEPTH_INFINITE, false );
		}
	}
}
 
Example 12
Source File: ImportBirtRuntimeAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * handle action to clear some old birt runtime files
 * 
 * @param webContentPath
 * @param monitor
 * @throws Exception
 */
protected void doClearAction( IPath webContentPath, IProgressMonitor monitor )
		throws Exception
{
	// remove the root folder
	IPath webPath = webContentPath;
	if ( webPath.segmentCount( ) > 0 )
		webPath = webPath.removeFirstSegments( 1 );

	// get conflict resources
	Map map = BirtWizardUtil.initConflictResources( null );

	// clear
	Iterator it = map.entrySet( ).iterator( );
	while ( it.hasNext( ) )
	{
		Map.Entry entry = (Map.Entry)it.next( );
		String folder = (String) entry.getKey( );
		if ( folder == null )
			continue;

		// get the target folder
		IPath path = webPath.append( folder );
		IFolder tempFolder = project.getFolder( path );
		if ( tempFolder == null || !tempFolder.exists( ) )
			continue;

		List files = (List) entry.getValue( );
		if ( files == null || files.size( ) <= 0 )
		{
			// delete the whole folder
			tempFolder.delete( true, monitor );
		}
		else
		{
			// delete the defined files
			tempFolder.accept( new LibResourceVisitor( monitor, files ),
					IResource.DEPTH_INFINITE, false );
		}
	}
}
 
Example 13
Source File: AbstractGroovyScriptConfigurationSynchronizer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void addNewPackage(Configuration configuration, AbstractProcess process, GroovyRepositoryStore store,
        CompoundCommand cc, EditingDomain editingDomain) {
    IFolder srcFolder = store.getResource();
    FragmentContainer groovyContainer = getContainer(configuration);
    Assert.isNotNull(groovyContainer);

    try {
        srcFolder.accept(new IResourceVisitor() {

            @Override
            public boolean visit(IResource resource) throws CoreException {
                if (Objects.equals("groovy", resource.getFileExtension())) {
                    boolean exists = false;
                    for (Fragment f : groovyContainer.getFragments()) {
                        if (f.getValue().equals(toPath(srcFolder, resource))) {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists) {
                        Fragment newFragment = ConfigurationFactory.eINSTANCE.createFragment();
                        newFragment.setType(FragmentTypes.GROOVY_SCRIPT);
                        String path = toPath(srcFolder, resource);
                        newFragment.setKey(path);
                        newFragment.setValue(path);
                        List<Expression> expressions = ModelHelper.getAllItemsOfType(process,
                                ExpressionPackage.Literals.EXPRESSION);
                        newFragment.setExported(false);
                        String qualifiedName = path;
                        if (path.contains("/")) {
                            qualifiedName = qualifiedName.replaceAll("/", ".");
                        }
                        qualifiedName = qualifiedName.substring(0,
                                qualifiedName.lastIndexOf(".groovy"));
                        for (Expression exp : expressions) {
                            if (exp.getType() != null && exp.getType().equals(ExpressionConstants.SCRIPT_TYPE)) {
                                if (exp.getContent() != null && exp.getContent().contains(qualifiedName)) {
                                    newFragment.setExported(true);
                                    break;
                                }
                            }
                        }
                        cc.append(AddCommand.create(editingDomain, groovyContainer,
                                ConfigurationPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS, newFragment));
                    }
                    return false;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        BonitaStudioLog.error(e);
    }

}