Java Code Examples for org.eclipse.core.resources.IFolder#getFolder()
The following examples show how to use
org.eclipse.core.resources.IFolder#getFolder() .
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: EclipseBasedProjectModelSetup.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void createProject(N4JSProjectName projectName, String string) throws CoreException, UnsupportedEncodingException { IProject project = workspace.getProject(projectName.toEclipseProjectName().getRawName()); IFile projectDescriptionFile = project.getFile(PROJECT_DESCRIPTION_FILENAME); @SuppressWarnings("resource") StringInputStream content = new StringInputStream(string, Charsets.UTF_8.name()); projectDescriptionFile.create(content, false, null); projectDescriptionFile.setCharset(Charsets.UTF_8.name(), null); IFolder src = project.getFolder("src"); src.create(false, true, null); IFolder sub = src.getFolder("sub"); sub.create(false, true, null); IFolder leaf = sub.getFolder("leaf"); leaf.create(false, true, null); src.getFile("A.js").create(new ByteArrayInputStream(new byte[0]), false, null); src.getFile("B.js").create(new ByteArrayInputStream(new byte[0]), false, null); sub.getFile("B.js").create(new ByteArrayInputStream(new byte[0]), false, null); sub.getFile("C.js").create(new ByteArrayInputStream(new byte[0]), false, null); leaf.getFile("D.js").create(new ByteArrayInputStream(new byte[0]), false, null); ProjectTestsUtils.createDummyN4JSRuntime(project); }
Example 2
Source File: CordovaPluginManager.java From thym with Eclipse Public License 1.0 | 6 votes |
/** * Returns the folder that the plugin with id is installed under the plugins folder. * It also uses {@link CordovaPluginRegistryMapper} to check for alternate ids. * * @param id * @return null or a folder * throws CoreException - if <i>plugins</i> folder does not exist */ private IFolder getPluginHomeFolder(String id) throws CoreException{ if(id == null ) return null; IFolder plugins = getPluginsFolder(); if(!plugins.exists()){ throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Plugin folder does not exist")); } IFolder pluginHome = plugins.getFolder(id); IPath location = pluginHome.getLocation(); if(pluginHome.exists() && location != null && location.toFile().isDirectory()){ return pluginHome; } // try the alternate ID String alternateId = CordovaPluginRegistryMapper.alternateID(id); if(alternateId != null ){ pluginHome = plugins.getFolder(alternateId); location = pluginHome.getLocation(); if(pluginHome.exists() && location != null && location.toFile().isDirectory()){ return pluginHome; } } return null; }
Example 3
Source File: TmfProjectModelElement.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Returns the trace specific supplementary folder under the project's * supplementary folder. Its parent folders will be created if they don't exist. * If createFolder is true, the returned folder will be created, otherwise it * may not exist. * * @param supplFolderPath * folder path relative to the project's supplementary folder * @param createFolder * if true, the returned folder will be created * @param progressMonitor * the progress monitor * @return the trace specific supplementary folder * @since 4.0 */ public IFolder prepareTraceSupplementaryFolder(String supplFolderPath, boolean createFolder, IProgressMonitor progressMonitor) { SubMonitor subMonitor = SubMonitor.convert(progressMonitor); IFolder folder = getTraceSupplementaryFolder(supplFolderPath); IFolder propertiesFolder = folder.getFolder(TmfCommonConstants.TRACE_PROPERTIES_FOLDER); if ((createFolder && propertiesFolder.exists() && propertiesFolder.isHidden()) || (!createFolder && folder.getParent().exists())) { return folder; } try { ICoreRunnable runnable = monitor -> { if (createFolder) { TraceUtils.createFolder(propertiesFolder, monitor); propertiesFolder.setHidden(true); } else { TraceUtils.createFolder((IFolder) folder.getParent(), monitor); } }; ResourcesPlugin.getWorkspace().run(runnable, folder.getProject(), IWorkspace.AVOID_UPDATE, subMonitor); } catch (CoreException e) { Activator.getDefault().logError("Error creating supplementary folder " + folder.getFullPath(), e); //$NON-NLS-1$ } return folder; }
Example 4
Source File: TracePackageExportOperation.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Creates a linked resource in the specified folder * * @param exportFolder the folder that will contain the linked resource * @param res the resource to export * @throws CoreException when createLink fails * @return the created linked resource */ private static IResource createExportResource(IFolder exportFolder, IResource res) throws CoreException { IResource ret = null; // Note: The resources cannot be HIDDEN or else they are ignored by ArchiveFileExportOperation if (res instanceof IFolder) { IFolder folder = exportFolder.getFolder(res.getName()); folder.createLink(res.getLocationURI(), IResource.REPLACE, null); ret = folder; } else if (res instanceof IFile) { IFile file = exportFolder.getFile(res.getName()); if (!file.exists()) { file.createLink(res.getLocationURI(), IResource.NONE, null); } ret = file; } return ret; }
Example 5
Source File: InternalImpl.java From saros with GNU General Public License v2.0 | 6 votes |
@Override public void createFolder(String projectName, String path) throws RemoteException { path = path.replace('\\', '/'); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); try { String segments[] = path.split("/"); IFolder folder = project.getFolder(segments[0]); log.trace(Arrays.asList(segments)); if (!folder.exists()) folder.create(true, true, null); if (segments.length <= 1) return; for (int i = 1; i < segments.length; i++) { folder = folder.getFolder(segments[i]); if (!folder.exists()) folder.create(true, true, null); } } catch (CoreException e) { log.error(e.getMessage(), e); throw new RemoteException(e.getMessage(), e.getCause()); } }
Example 6
Source File: PerformanceTestProjectSetup.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public static void setUp() throws Exception { testProject = createJavaProject("performance.test.project", new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature" } ); new ToggleXtextNatureCommand().toggleNature(testProject.getProject()); IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(testProject, "src"); JavaProjectSetupUtil.addSourceFolder(testProject, "xtend-gen"); List<String> filesToCopy = readResource("/files.list"); for(String fileToCopy: filesToCopy) { IPath filePath = new Path(fileToCopy); IFolder packageFolder = sourceFolder.getFolder(filePath.removeLastSegments(1)); if (!packageFolder.exists()) createFolderRecursively(packageFolder); List<String> content = readResource(fileToCopy); String contentAsString = Strings.concat("\n", content); String fileName = filePath.lastSegment(); createFile(fileName.substring(0, fileName.length() - ".txt".length()), packageFolder, contentAsString); } waitForBuild(); }
Example 7
Source File: LibraryClasspathContainerSerializer.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private IFile getFile(IJavaProject javaProject, String id, boolean create) throws CoreException { IFolder settingsFolder = javaProject.getProject().getFolder(".settings"); //$NON-NLS-1$ IFolder folder = settingsFolder.getFolder(FrameworkUtil.getBundle(getClass()).getSymbolicName()); if (!folder.exists() && create) { ResourceUtils.createFolders(folder, null); } IFile containerFile = folder.getFile(id + ".container"); //$NON-NLS-1$ return containerFile; }
Example 8
Source File: HybridMobileEngineManager.java From thym with Eclipse Public License 1.0 | 5 votes |
private IFolder getPlatformHomeFolder(String platform) throws CoreException { if (platform == null) { return null; } IFolder platforms = getPlatformsFolder(); if (!platforms.exists()) { throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Platforms folder does not exist")); } IFolder platformHome = platforms.getFolder(platform); IPath location = platformHome.getLocation(); if (platformHome.exists() && location != null && location.toFile().isDirectory()) { return platformHome; } return null; }
Example 9
Source File: ProjectModelTestData.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Adds a new experiment to the project * * @param projectElement * The project to add to * @param experimentName * Name of the experiment * @return The newly created experiment */ public static TmfExperimentElement addExperiment(TmfProjectElement projectElement, String experimentName) { TmfExperimentFolder experimentsFolder = projectElement.getExperimentsFolder(); if (experimentsFolder != null) { IFolder experimentFolder = experimentsFolder.getResource(); final IFolder folder = experimentFolder.getFolder(experimentName); WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override public void execute(IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 1000); folder.create(false, true, monitor); monitor.done(); } }; try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation); } catch (InterruptedException | InvocationTargetException | RuntimeException exception) { exception.printStackTrace(); } experimentsFolder.refresh(); for (ITmfProjectModelElement el : experimentsFolder.getChildren()) { if (el.getName().equals(experimentName) && (el instanceof TmfExperimentElement)) { return (TmfExperimentElement) el; } } } return null; }
Example 10
Source File: ImportProjectWizardPage2.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 获取指定节点被选择的子节点 * @param parentResource * 树节点的父节点 * @param parentFolder * 项目空间的父文件夹 * @return */ private void createCurProjectResource(ProjectResource parentResource, IFolder parentContainer) throws Exception { if (parentResource == null || parentContainer == null) { return; } for (Object obj : selectContentProvider.getChildren(parentResource)) { if (obj instanceof ProjectResource) { ProjectResource proResource = (ProjectResource) obj; if (!selectElementTree.getChecked(proResource)) { continue; } // 如果是文件夹,如果没有创建,直接创建 if (proResource.isFolder()) { IFolder childFolder = parentContainer.getFolder(proResource.getLabel()); if (!childFolder.exists()) { childFolder.create(true, true, null); } createCurProjectResource(proResource, childFolder); } else { // 如果是文件,则判断是否需要覆盖,若是,则直接覆盖 if (proResource.isNeedCover()) { IFile iFile = parentContainer.getFile(proResource.getLabel()); InputStream inputStream = proResource.getInputStream(); if (inputStream != null) { if (iFile.exists()) { closeOpenedFile(iFile); iFile.delete(true, null); } iFile.create(inputStream, true, null); } } } } } }
Example 11
Source File: HybridProjectTest.java From thym with Eclipse Public License 1.0 | 5 votes |
private void checkDerivedSubFolders(HybridProject hProject, String folderName) { IFolder folder = hProject.getProject().getFolder(folderName); IFolder subFolder1 = folder.getFolder(folder.getName() + "0"); assertTrue(subFolder1.isDerived()); IFolder subFolder2 = folder.getFolder(folder.getName() + "1"); assertTrue(subFolder2.isDerived()); IFile subFile1 = folder.getFile("file0"); assertFalse(subFile1.isDerived()); IFile subFile2 = folder.getFile("file1"); assertFalse(subFile2.isDerived()); }
Example 12
Source File: ImportHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static void initializeTraceResource(final LttngRelaydConnectionInfo connectionInfo, final String tracePath, final IProject project) throws CoreException, TmfTraceImportException { final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); final TmfTraceFolder tracesFolder = projectElement.getTracesFolder(); if (tracesFolder != null) { IFolder folder = tracesFolder.getResource(); IFolder traceFolder = folder.getFolder(connectionInfo.getSessionName()); Path location = new Path(tracePath); IStatus result = ResourcesPlugin.getWorkspace().validateLinkLocation(folder, location); if (result.isOK()) { traceFolder.createLink(location, IResource.REPLACE, new NullProgressMonitor()); } else { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, result.getMessage())); } TraceTypeHelper selectedTraceType = TmfTraceTypeUIUtils.selectTraceType(location.toOSString(), null, null); // No trace type was determined. TmfTraceTypeUIUtils.setTraceType(traceFolder, selectedTraceType); TmfTraceElement found = null; final List<TmfTraceElement> traces = tracesFolder.getTraces(); for (TmfTraceElement candidate : traces) { if (candidate.getName().equals(connectionInfo.getSessionName())) { found = candidate; } } if (found == null) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_LiveTraceElementError)); } // Properties used to be able to reopen a trace in live mode traceFolder.setPersistentProperty(CtfConstants.LIVE_HOST, connectionInfo.getHost()); traceFolder.setPersistentProperty(CtfConstants.LIVE_PORT, Integer.toString(connectionInfo.getPort())); traceFolder.setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, connectionInfo.getSessionName()); final TmfTraceElement finalTrace = found; Display.getDefault().syncExec(() -> TmfOpenTraceHelper.openFromElement(finalTrace)); } }
Example 13
Source File: WebProjectUtil.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Attempt to resolve the given file within the project's {@code WEB-INF}. Note that this method * may return a file that is in a build location (e.g., * {@code target/m2e-wtp/web-resources/WEB-INF}) which may be frequently removed or regenerated. * * @return the file location or {@code null} if not found */ public static IFile findInWebInf(IProject project, IPath filePath) { // Try to obtain the directory as if it was a Dynamic Web Project IVirtualComponent component = ComponentCore.createComponent(project); if (component != null && component.exists()) { IVirtualFolder root = component.getRootFolder(); // the root should exist, but the WEB-INF may not yet exist IVirtualFile file = root.getFolder(WEB_INF).getFile(filePath); if (file != null && file.exists()) { return file.getUnderlyingFile(); } return null; } // Otherwise check the standard places for (String possibleWebInfContainer : DEFAULT_WEB_PATHS) { // check each directory component to simplify mocking in tests // so we can just say WEB-INF doesn't exist IFolder defaultLocation = project.getFolder(possibleWebInfContainer); if (defaultLocation != null && defaultLocation.exists()) { defaultLocation = defaultLocation.getFolder(WEB_INF); if (defaultLocation != null && defaultLocation.exists()) { IFile resourceFile = defaultLocation.getFile(filePath); if (resourceFile != null && resourceFile.exists()) { return resourceFile; } } } } return null; }
Example 14
Source File: JobLauncher.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * This private utility method is to be used once in the process method to * generate the local job launch IFolder. * * @return folder The local job launch folder. */ private IFolder createLocalJobLaunchFolder() { // Here we should create a scratch job directory // in project/jobs IFolder jobsFolder = project.getFolder("jobs"); if (!jobsFolder.exists()) { try { jobsFolder.create(true, true, null); } catch (CoreException e) { logger.error("JobLauncher Error: Could not create the " + "jobs directory for job launches.", e); return null; } } // Create a IFolder for the local job launch IFolder jobFolder = jobsFolder.getFolder("iceLaunch_" + new SimpleDateFormat("yyyMMddhhmmss").format(new Date())); try { jobFolder.create(true, true, null); } catch (CoreException e1) { logger.error( "JobLauncher Error: Could not create the current launch job directory.", e1); return null; } // Add the Job Launch Directory name to the data map actionDataMap.put("localJobLaunchDirectory", jobFolder.getName()); // Return the job folder. return jobFolder; }
Example 15
Source File: AbstractFolderProcessor.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override public void process ( final String phase, final IFolder nodeDir, final IProgressMonitor monitor, final Map<String, String> properties ) throws Exception { if ( phase != null && !"package".equals ( phase ) ) { return; } final String name = makeName (); final IFolder folder = nodeDir.getFolder ( name ); folder.create ( true, true, monitor ); processLocal ( folder, monitor ); }
Example 16
Source File: AbstractBuilderParticipantTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/***/ protected IFolder createFolder(IFolder superFolder, String path) throws CoreException { IFolder folder = superFolder.getFolder(path); if (!folder.exists()) { createParentFolder(folder); folder.create(true, true, null); } return folder; }
Example 17
Source File: ImportProjectWizardPage2.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * 如果这几个必须的文件夹在项目中不存在,则创建。创建几个必须的文件夹,如下: Intermediate[Report, SKL], Source, Target, XLIFF 。 */ private void createRequireFolder(IProject newProject) { try { // 从上到下,先处理 Intermediate IFolder intermediateFolder = newProject.getFolder(Constant.FOLDER_INTERMEDDIATE); if (!intermediateFolder.exists()) { intermediateFolder.create(true, true, null); } // 再处理 Report IFolder reportFolder = intermediateFolder.getFolder(Constant.FOLDER_REPORT); if (!reportFolder.exists()) { reportFolder.create(true, true, null); } // 再处理 SKL IFolder sklFolder = intermediateFolder.getFolder(Constant.FOLDER_SKL); if (!sklFolder.exists()) { sklFolder.create(true, true, null); } // 再处理 source IFolder srcFolder = newProject.getFolder(Constant.FOLDER_SRC); if (!srcFolder.exists()) { srcFolder.create(true, true, null); } // 再处理 target IFolder tgtFolder = newProject.getFolder(Constant.FOLDER_TGT); if (!tgtFolder.exists()) { tgtFolder.create(true, true, null); } // 再处理 xliff IFolder xlfFolder = newProject.getFolder(Constant.FOLDER_XLIFF); if (!xlfFolder.exists()) { xlfFolder.create(true, true, null); } } catch (Exception e) { LOGGER.error(Messages.getString("importProjectWizardPage.LOGG.importEroor"), e); } }
Example 18
Source File: ExternalResourceManager.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
private static final IStatus linkDirectory(IProject p, final IFolder externalsFolder, File directory, IProgressMonitor monitor, boolean filterOutSubfolders) throws CoreException { IWorkspace workspace = ResourceUtils.getWorkspace(); if (workspace == null){ return Status.OK_STATUS; } List<File> parts = ResourceUtils.getParts(directory); IFolder folder = externalsFolder; for (int i = 0; i < parts.size() - 1; i++) { File part = parts.get(i); folder = folder.getFolder(getName(part)); if (!folder.exists()) { folder.create(IResource.FORCE | IResource.VIRTUAL, true, monitor); ResourceUtils.setAbsolutePathOfLinkedResourceAttribute(folder, part.getAbsolutePath()); ResourceUtils.setSyntheticResourceAttribute(folder); } } IFolder linkedFolder = folder.getFolder(directory.getName()); if (linkedFolder.exists() && (linkedFolder.isVirtual() || linkedFolder.getLocation() == null)) { // linkedFolder can be only linked or virtual folder (by the precondition of this method). // It can be virtual folder (linkedFolder.getLocation() === null) if lookup directory was added and it was not linked before. linkedFolder.delete(true, monitor); } if (!linkedFolder.exists()){ Path path = new Path(directory.getAbsolutePath()); IStatus validateLinkLocationStatus = workspace.validateLinkLocation(linkedFolder, path); if (!JavaUtils.areFlagsSet(validateLinkLocationStatus.getSeverity(), IStatus.ERROR | IStatus.CANCEL)){ linkedFolder.createLink(path, IResource.NONE, monitor); if (filterOutSubfolders) { ResourceUtils.applyRegexFilter(linkedFolder, IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS, ".*", monitor); //$NON-NLS-1$ } ResourceUtils.setAbsolutePathOfLinkedResourceAttribute(linkedFolder, directory.getAbsolutePath()); ResourceUtils.refreshLocalSync(folder); } return validateLinkLocationStatus; } return Status.OK_STATUS; }
Example 19
Source File: RemoteImportTracesOperation.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
private IResource downloadDirectoryTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException { IFileStore[] sources = trace.childStores(EFS.NONE, monitor); // Don't import just the metadata file if (sources.length > 1) { String traceName = trace.getName(); traceName = TmfTraceCoreUtils.validateName(traceName); IFolder folder = traceFolder.getFolder(traceName); String newName = fConflictHandler.checkAndHandleNameClash(folder.getFullPath(), monitor); if (newName == null) { return null; } folder = traceFolder.getFolder(newName); folder.create(true, true, null); SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length); subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, sources.length); for (IFileStore source : sources) { if (subMonitor.isCanceled()) { throw new InterruptedException(); } IPath destination = folder.getLocation().addTrailingSeparator().append(source.getName()); IFileInfo info = source.fetchInfo(); // TODO allow for downloading index directory and files if (!info.isDirectory()) { SubMonitor childMonitor = subMonitor.newChild(1); childMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + source.getName()); try (InputStream in = source.openInputStream(EFS.NONE, new NullProgressMonitor())) { copy(in, folder, destination, childMonitor, info.getLength()); } } } folder.refreshLocal(IResource.DEPTH_INFINITE, null); return folder; } return null; }
Example 20
Source File: TmfProjectModelElement.java From tracecompass with Eclipse Public License 2.0 | 2 votes |
/** * Returns the trace specific supplementary folder under the project's * supplementary folder. The returned folder and its parent folders may not * exist. * * @param supplFolderPath * folder path relative to the project's supplementary folder * @return the trace specific supplementary folder */ public IFolder getTraceSupplementaryFolder(String supplFolderPath) { TmfProjectElement project = getProject(); IFolder supplFolderParent = project.getSupplementaryFolder(); return supplFolderParent.getFolder(supplFolderPath); }