Java Code Examples for org.eclipse.core.resources.IContainer#exists()
The following examples show how to use
org.eclipse.core.resources.IContainer#exists() .
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: CleanInstruction.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void cleanOutput(IProject aProject, OutputConfiguration config, IProgressMonitor monitor) throws CoreException { IContainer container = getContainer(aProject, config.getOutputDirectory()); if (!container.exists()) { return; } if (config.isCanClearOutputDirectory()) { for (IResource resource : container.members()) { resource.delete(IResource.KEEP_HISTORY, monitor); } } else if (config.isCleanUpDerivedResources()) { List<IFile> resources = derivedResourceMarkers.findDerivedResources(container, null); for (IFile iFile : resources) { iFile.delete(IResource.KEEP_HISTORY, monitor); } } }
Example 2
Source File: WorkbenchResourceUtil.java From typescript.java with MIT License | 6 votes |
public static IContainer findContainerFromWorkspace(IPath containerPath) { if (containerPath == null) { return null; } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IContainer container = root.getContainerForLocation(containerPath); if (container != null && container.exists()) { return container; } IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(containerPath); if (containers.length > 0) { container = containers[0]; if (container.exists()) { return container; } } return null; }
Example 3
Source File: SyncFileChangeListener.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
protected boolean isEntries(IResource resource) { if (resource.getType() != IResource.FILE || !resource.getName().equals(SVNConstants.SVN_ENTRIES)) { return false; } IContainer parent = resource.getParent(); if ((parent != null) && (SVNProviderPlugin.getPlugin().isAdminDirectory(parent.getName())) && (parent.isTeamPrivateMember() || !parent.exists()) ) { return true; } return false; }
Example 4
Source File: TypeScriptSourceMapLanguageSupport.java From typescript.java with MIT License | 6 votes |
@Override public IPath getJsFile(IPath tsFilePath) { // Search js file in the same folder than ts file. IPath jsFilePath = tsFilePath.removeFileExtension().addFileExtension("js"); IFile jsFile = WorkbenchResourceUtil.findFileFromWorkspace(jsFilePath); if (jsFile != null) { return jsFilePath; } // Search js file in the well folder by using tsconfig.json IFile tsFile = WorkbenchResourceUtil.findFileFromWorkspace(tsFilePath); try { IDETsconfigJson tsconfig = TypeScriptResourceUtil.findTsconfig(tsFile); if (tsconfig != null) { IContainer configOutDir = tsconfig.getOutDir(); if (configOutDir != null && configOutDir.exists()) { IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, configOutDir) .removeFileExtension(); return tsFileNamePath.addFileExtension("js"); } } } catch (CoreException e) { e.printStackTrace(); } return null; }
Example 5
Source File: GetContainers.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Gets an IContainer inside a container given a path in the filesystem (resolves the full path of the container and * checks if the location given is under it). * @param mustExist */ public static final IContainer getContainerInContainer(IPath location, IContainer container, boolean mustExist) { IPath projectLocation = container.getLocation(); if (projectLocation != null && projectLocation.isPrefixOf(location)) { int segmentsToRemove = projectLocation.segmentCount(); IPath removeFirstSegments = location.removeFirstSegments(segmentsToRemove); if (removeFirstSegments.segmentCount() == 0) { return container; //I.e.: equal to container } IContainer file = container.getFolder(removeFirstSegments); if (!mustExist || file.exists()) { return file; } } return null; }
Example 6
Source File: MoreActiveAnnotationsTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void createFolder(final IContainer container) { try { boolean _exists = container.exists(); boolean _not = (!_exists); if (_not) { this.createFolder(container.getParent()); ((IFolder) container).create(true, false, null); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 7
Source File: NewModulePage.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
private boolean checkExist(String folder, String file) { IWorkspaceRoot root = project.getWorkspace().getRoot(); IContainer f = (IContainer)root.findMember(folder); if (f.exists()) { if (f.getFile(new Path(file)).exists()) { return true; } } return false; }
Example 8
Source File: ActiveAnnotationsProcessingInIDETest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void createIfNotExistent(final IContainer container) { try { boolean _exists = container.exists(); boolean _not = (!_exists); if (_not) { this.createIfNotExistent(container.getParent()); ((IFolder) container).create(true, false, null); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 9
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static void createFolders(IContainer folder, IProgressMonitor monitor) throws CoreException { if (!folder.exists() && folder instanceof IFolder) { IContainer parent = folder.getParent(); createFolders(parent, monitor); folder.refreshLocal(IResource.DEPTH_ZERO, monitor); if (!folder.exists()) { ((IFolder)folder).create(true, true, monitor); } } }
Example 10
Source File: ProjectCustomizer.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates a file in a project with an InputStream for the content * * @param container * an IProject * @param fileName * pathname relative to the project * @param is * An inputStream for the the content * @param overrideContentIfExist * if true, overrides existing file * @return a handle to the file (IFile) * @throws PearException * If a problem occurs */ public static IFile createFile(IContainer container, String fileName, InputStream is, boolean overrideContentIfExist) throws PearException { try { createPearFolderStructure(container); // if we have a container if (container.exists()) { IFile newFile = container.getFile(new Path(fileName)); // If the file does not exist, create with content, mark, and return if (!newFile.exists()) { newFile.create(is, false, null); return newFile; } else { if (overrideContentIfExist) newFile.setContents(is, true, true, null); // return what already exisited return newFile; } } else // return null as there is no container to place a file in return null; } catch (Throwable e) { PearException subEx = new PearException(fileName + " could not be created/saved properly.", e); throw subEx; } }
Example 11
Source File: EclipseResourceFileSystemAccess2.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void ensureExists(IContainer container) throws CoreException { if (container.exists()) return; if (container instanceof IFolder) { ensureExists(container.getParent()); ((IFolder) container).create(true, true, monitor); } }
Example 12
Source File: ProjectFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void createRecursive(final IContainer resource) { if (!resource.exists()) { if (!resource.getParent().exists()) { createRecursive(resource.getParent()); } if (resource instanceof IFolder) { try { ((IFolder) resource).create(false, true, new NullProgressMonitor()); } catch (CoreException e) { logger.error(e.getMessage(), e); } } } }
Example 13
Source File: TypeScriptResourceUtil.java From typescript.java with MIT License | 5 votes |
public static void refreshAndCollectEmittedFiles(IFile tsFile, IDETsconfigJson tsconfig, boolean refresh, List<IFile> emittedFiles) throws CoreException { IContainer baseDir = tsFile.getParent(); // Set outDir with the folder of the ts file. IContainer outDir = tsFile.getParent(); if (tsconfig != null) { // tsconfig.json exists and "outDir" is setted, set "outDir" with // the tsconfig.json/compilerOption/outDir IContainer configOutDir = tsconfig.getOutDir(); if (configOutDir != null && configOutDir.exists()) { outDir = configOutDir; } } IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, baseDir).removeFileExtension(); // Refresh *.js file IPath jsFilePath = tsFileNamePath.addFileExtension(FileUtils.JS_EXTENSION); refreshAndCollectEmittedFile(jsFilePath, outDir, refresh, emittedFiles); // Refresh *.js.map file IPath jsMapFilePath = tsFileNamePath.addFileExtension(FileUtils.JS_EXTENSION) .addFileExtension(FileUtils.MAP_EXTENSION); refreshAndCollectEmittedFile(jsMapFilePath, outDir, refresh, emittedFiles); // Refresh ts file if (refresh) { refreshFile(tsFile, false); } }
Example 14
Source File: DialogUtils.java From typescript.java with MIT License | 5 votes |
public static ElementTreeSelectionDialog createFolderDialog(String initialFolder, final IProject project, final boolean showAllProjects, final boolean showFolder, Shell shell) { ILabelProvider lp = new WorkbenchLabelProvider(); ITreeContentProvider cp = new WorkbenchContentProvider(); FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp); // dialog.setTitle(TypeScriptUIMessages.TernModuleOptionsPanel_selectPathDialogTitle); IContainer folder = StringUtils.isEmpty(initialFolder) ? project : (project != null ? project.getFolder(initialFolder) : ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(initialFolder))); if (folder != null && folder.exists()) { dialog.setInitialSelection(folder); } dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); ViewerFilter filter = new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IProject) { if (showAllProjects) return true; IProject p = (IProject) element; return (p.equals(project)); } else if (element instanceof IContainer) { IContainer container = (IContainer) element; if (showFolder && container.getType() == IResource.FOLDER) { return true; } return false; } return false; } }; dialog.addFilter(filter); return dialog; }
Example 15
Source File: TmfCommonProjectElement.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static void deleteFolder(IFolder folder) throws CoreException { if (folder.exists()) { folder.delete(true, new NullProgressMonitor()); } IContainer parent = folder.getParent(); // delete empty folders up to the parent project if (parent instanceof IFolder && (!parent.exists() || parent.members().length == 0)) { deleteFolder((IFolder) parent); } }
Example 16
Source File: RenameModifications.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private boolean canMove(IContainer source, IContainer target) { return !target.exists() && !source.getFullPath().isPrefixOf(target.getFullPath()); }
Example 17
Source File: RenameModifications.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean canMove(IContainer source, IContainer target) { return !target.exists() && !source.getFullPath().isPrefixOf(target.getFullPath()); }
Example 18
Source File: FileUtils.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Makes sure that the parent directories of the given {@linkplain IResource resource} exist. * * @throws CoreException */ public static void mkdirs(final IResource resource) throws CoreException { final List<IFolder> parents = new ArrayList<IFolder>(); IContainer parent = resource.getParent(); while (parent != null && parent.getType() == IResource.FOLDER) { if (parent.exists()) break; parents.add((IFolder) parent); parent = parent.getParent(); } Collections.reverse(parents); for (final IFolder folder : parents) folder.create(false, true, null); }
Example 19
Source File: RefactoringModifications.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected void createIncludingParents(IContainer container) { while (container != null && !(container.exists() || getResourceModifications().willExist(container))) { getResourceModifications().addCreate(container); container= container.getParent(); } }
Example 20
Source File: IO.java From spotbugs with GNU Lesser General Public License v2.1 | 3 votes |
/** * Recursively creates all folders needed, up to the project. Project must * already exist. * * @param resource * non null * @param monitor * non null * @throws CoreException */ private static void mkdirs(@Nonnull IResource resource, IProgressMonitor monitor) throws CoreException { IContainer container = resource.getParent(); if (container.getType() == IResource.FOLDER && !container.exists()) { if (!container.getParent().exists()) { mkdirs(container, monitor); } ((IFolder) container).create(true, true, monitor); } }