Java Code Examples for org.eclipse.core.runtime.Path#fromPortableString()
The following examples show how to use
org.eclipse.core.runtime.Path#fromPortableString() .
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: BundleUtil.java From sarl with Apache License 2.0 | 6 votes |
private static IPath getSourceRootProjectFolderPath(Bundle bundle) { for (final String srcFolder : SRC_FOLDERS) { final IPath relPath = Path.fromPortableString(srcFolder); final URL srcFolderURL = FileLocator.find(bundle, relPath, null); if (srcFolderURL != null) { try { final URL srcFolderFileURL = FileLocator.toFileURL(srcFolderURL); IPath absPath = new Path(srcFolderFileURL.getPath()).makeAbsolute(); absPath = absPath.removeLastSegments(relPath.segmentCount()); return absPath; } catch (IOException e) { // } } } return null; }
Example 2
Source File: ManifestBasedSREInstall.java From sarl with Apache License 2.0 | 6 votes |
/** Path the given string for extracting a path. * * @param path the string representation of the path to parse. * @param defaultPath the default path. * @param rootPath the root path to use is the given path is not absolute. * @return the absolute path. */ private static IPath parsePath(String path, IPath defaultPath, IPath rootPath) { if (!Strings.isNullOrEmpty(path)) { try { final IPath pathObject = Path.fromPortableString(path); if (pathObject != null) { if (rootPath != null && !pathObject.isAbsolute()) { return rootPath.append(pathObject); } return pathObject; } } catch (Throwable exception) { // } } return defaultPath; }
Example 3
Source File: ReferenceManagerPersister.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static IReferenceLocation loadReferenceLocation(IMemento memento) throws PersistenceException { String className = getStringOrThrowException(memento, KEY_CLASS); if (ClasspathRelativeFileReferenceLocation.class.getSimpleName().equals( className)) { String classpathRelativePath = getStringOrThrowException(memento, KEY_CLASSPATH_RELATIVE_PATH); return new ClasspathRelativeFileReferenceLocation( Path.fromPortableString(classpathRelativePath)); } else if (LogicalJavaElementReferenceLocation.class.getSimpleName().equals( className)) { ILogicalJavaElement logicalJavaElement = loadLogicalJavaElement(getChildMementoOrThrowException( memento, KEY_LOGICAL_JAVA_ELEMENT)); return new LogicalJavaElementReferenceLocation(logicalJavaElement); } else { throw new PersistenceException("Unknown reference location class " + className); } }
Example 4
Source File: LegacyGWTHostPageSelectionDialog.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Builds the tree nodes for a set of modules and host pages. * * @param modulesHostPages the set of modules along with their respective * host pages * @return tree root nodes */ static LegacyGWTHostPageSelectionTreeItem[] buildTree( Map<String, Set<String>> modulesHostPages) { List<LegacyGWTHostPageSelectionTreeItem> treeItems = new ArrayList<LegacyGWTHostPageSelectionTreeItem>(); for (String moduleName : modulesHostPages.keySet()) { LegacyGWTHostPageSelectionTreeItem moduleItem = new LegacyGWTHostPageSelectionTreeItem( Path.fromPortableString(moduleName.replace('.', '/'))); treeItems.add(moduleItem); for (String hostPage : modulesHostPages.get(moduleName)) { new LegacyGWTHostPageSelectionTreeItem( Path.fromPortableString(hostPage), moduleItem); } } return treeItems.toArray(new LegacyGWTHostPageSelectionTreeItem[0]); }
Example 5
Source File: NodeJSService.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Downloads a file from url, return the {@link File} on disk where it was saved. * * @param url * @param monitor * @return * @throws CoreException */ private File download(URL url, String extension, IProgressMonitor monitor) throws CoreException { DownloadManager manager = new DownloadManager(); IPath path = Path.fromPortableString(url.getPath()); String name = path.lastSegment(); File f = new File(FileUtil.getTempDirectory().toFile(), name + extension); f.deleteOnExit(); manager.addURL(url, f); IStatus status = manager.start(monitor); if (!status.isOK()) { throw new CoreException(status); } List<IPath> locations = manager.getContentsLocations(); return locations.get(0).toFile(); }
Example 6
Source File: EFSUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * getRelativePath * * @param parentFileStore * @param childFileStore * @return */ public static IPath getRelativePath(IFileStore parentFileStore, IFileStore childFileStore) { if (parentFileStore.isParentOf(childFileStore)) { IPath parentPath = Path.fromPortableString(parentFileStore.toURI().getPath()); IPath childPath = Path.fromPortableString(childFileStore.toURI().getPath()); return childPath.makeRelativeTo(parentPath); } return null; }
Example 7
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 5 votes |
private File getProjectFolderForSourceFolder(File file) { final IPath filePath = Path.fromOSString(file.getAbsolutePath()); for (final String rawPath : this.candidates) { final IPath path = Path.fromPortableString(rawPath); IPath parent = null; IPath fp = (IPath) filePath.clone(); while (fp != null) { if (path.isPrefixOf(fp)) { if (parent == null) { return file.getParentFile(); } return parent.toFile(); } if (parent == null) { parent = Path.fromPortableString("/" + fp.segment(0)); //$NON-NLS-1$ } else { parent = parent.append(fp.segment(0)); } if (fp.segmentCount() > 1) { fp = fp.removeFirstSegments(1); } else { fp = null; } } } return null; }
Example 8
Source File: PyPackageStateSaver.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private Object getResourceFromPath(IMemento m) { IPath path = Path.fromPortableString(m.getID()); IResource resource = FindWorkspaceFiles.getFileForLocation(path, null); if (resource == null || !resource.exists()) { resource = FindWorkspaceFiles.getContainerForLocation(path, null); } if (resource != null && resource.exists()) { return provider.getResourceInPythonModel(resource); } return null; }
Example 9
Source File: SarlExampleInstallerWizard.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the file into the project. * * @return the file or {@code null} if the file cannot be found. */ @SuppressWarnings("checkstyle:nestedifdepth") public IFile findProjectFile() { if (this.projectFile == null) { final IProject prj = this.project.get(); if (prj != null) { // 3 cases for location: // * prj / src folder / source path // * src folder / source path // * source path final IPath path0 = Path.fromPortableString(getLocation()); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path0); if (file != null && file.exists()) { this.projectFile = file; } else { file = prj.getFile(path0); if (file != null && file.exists()) { this.projectFile = file; } else { final IPath srcFolder = Path.fromOSString(SARLConfig.FOLDER_SOURCE_SARL); final IPath path1 = srcFolder.append(path0); file = prj.getFile(path1); if (file != null && file.exists()) { this.projectFile = file; } } } } } return this.projectFile; }
Example 10
Source File: URIUtil.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public static String getFileName(URI uri) { if (uri == null) { return null; } String uriPath = uri.getPath(); IPath path = Path.fromPortableString(uriPath); if (path == null) { return null; } return path.lastSegment(); }
Example 11
Source File: WorkspaceConnectionPoint.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected void loadState(IMemento memento) { super.loadState(memento); IMemento child = memento.getChild(ELEMENT_PATH); if (child != null) { path = Path.fromPortableString(child.getTextData()); } }
Example 12
Source File: LocalConnectionPoint.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected void loadState(IMemento memento) { super.loadState(memento); IMemento child = memento.getChild(ELEMENT_PATH); if (child != null) { path = Path.fromPortableString(child.getTextData()); } }
Example 13
Source File: TestEnvironmentUtil.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Installs an SDK or other development resource that is bundled in a testing plug-in into that * plug-in's data area and returns the absolute path where it was installed. * * @param bundle the {@link Bundle} in which the SDK is bundled * @param fileUrl the path to the zip * @return the absolute path of the installed bundle */ public static IPath installTestSdk(Bundle bundle, URL fileUrl) { byte[] buffer = new byte[1024]; IPath sdkRootPath = null; File output = bundle.getDataFile(""); try (ZipInputStream is = new ZipInputStream(new FileInputStream(new File(FileLocator.toFileURL(fileUrl).getPath())))) { ZipEntry entry = is.getNextEntry(); if (entry != null) { String rootEntryPath = Path.fromPortableString(entry.getName()).segment(0); sdkRootPath = Path.fromPortableString(new File(output, rootEntryPath).getAbsolutePath()); if (!sdkRootPath.toFile().exists()) { while (entry != null) { IPath fileName = Path.fromPortableString(entry.getName()); if (!"demos".equals(fileName.segment(1)) && !"samples".equals(fileName.segment(1))) { File newFile = new File(output + File.separator + fileName); if (!entry.isDirectory()) { new File(newFile.getParent()).mkdirs(); try (FileOutputStream os = new FileOutputStream(newFile)) { int bytesRead; while ((bytesRead = is.read(buffer)) > 0) { os.write(buffer, 0, bytesRead); } } } } entry = is.getNextEntry(); } } } is.closeEntry(); } catch (IOException e) { throw new IllegalStateException("Unable to install the SDK. fileUrl=" + fileUrl, e); } return sdkRootPath; }
Example 14
Source File: MavenUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Creates a MavenInfo instance based on the path to a Maven artifact in a local repository and * the artifact's group id. * * @param artifactPath the path to the artifact in the user's local repository (e.g., * <code>/home/user/.m2/repository/com/google/gwt/gwt * -user/2.1-SNAPSHOT/gwt-user-2.1-SNAPSHOT.jar</code>) * @param groupId the group id of the artifact (e.g., <code>com.google.gwt</code>) * @return an instance of MavenInfo, or null if one could not be found due to a mismatch between * the group id and the artifact path */ public static MavenInfo create(IPath artifactPath, String groupId) { if (artifactPath == null || artifactPath.isEmpty() || groupId == null || StringUtilities.isEmpty(groupId)) { return null; } IPath groupPath = Path.fromPortableString(groupId.replace('.', '/')); final int numTrailingSegmentsAfterRepositoryBase = NUM_TRAILING_SEGMENTS_AFTER_GROUP_ID + groupPath.segmentCount(); if (artifactPath.segmentCount() <= numTrailingSegmentsAfterRepositoryBase) { return null; } String artifactName = artifactPath.lastSegment(); String version = artifactPath.segment(artifactPath.segmentCount() - VERSION_INDEX_FROM_END_OF_MAVEN_PATH - 1); String artifactId = artifactPath.segment(artifactPath.segmentCount() - ARTIFACTID_INDEX_FROM_END_OF_MAVEN_PATH - 1); if (!artifactPath.removeLastSegments(NUM_TRAILING_SEGMENTS_AFTER_GROUP_ID) .removeTrailingSeparator().toPortableString().endsWith(groupPath.toPortableString())) { return null; } IPath repositoryPath = artifactPath.removeLastSegments(numTrailingSegmentsAfterRepositoryBase); return new MavenInfo(repositoryPath, groupId, artifactId, artifactName, version); }
Example 15
Source File: AppEngineConfigFileSchemaLocationProvider.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Override public Map<String, String> getExternalSchemaLocation(URI fileURI) { Preconditions.checkNotNull(fileURI); IPath path = Path.fromPortableString(fileURI.getPath()); if (path.segmentCount() == 0) { return Collections.emptyMap(); } String basename = path.lastSegment(); return schemaLocations.getOrDefault(basename, Collections.emptyMap()); }
Example 16
Source File: RustDebugDelegate.java From corrosion with Eclipse Public License 2.0 | 4 votes |
@Override public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException { setDefaultProcessFactory(configuration); // Reset process factory to what GdbLaunch expected String projectName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); String workingDirectoryString = RustLaunchDelegateTools.performVariableSubstitution( configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, "").trim()); //$NON-NLS-1$ File workingDirectory = RustLaunchDelegateTools.convertToAbsolutePath(workingDirectoryString); if (workingDirectoryString.isEmpty() || !workingDirectory.exists() || !workingDirectory.isDirectory()) { workingDirectory = project.getLocation().toFile(); } String executableString = RustLaunchDelegateTools.performVariableSubstitution( configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "").trim()); //$NON-NLS-1$ File executable = RustLaunchDelegateTools.convertToAbsolutePath(executableString); if (!executable.exists()) { IPath executablePath = Path.fromPortableString(executableString); if (project != null && executablePath.segment(0).equals(project.getName())) { // project relative path executable = project.getFile(executablePath.removeFirstSegments(1)).getLocation().toFile() .getAbsoluteFile(); } } ILaunchConfigurationWorkingCopy wc = configuration.copy(configuration.getName()); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, executable.getAbsolutePath()); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workingDirectory.getAbsolutePath()); wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_LOCATION, project.getLocation().toString()); String stopInMainSymbol = configuration .getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ""); //$NON-NLS-1$ if (stopInMainSymbol.equals("main")) { //$NON-NLS-1$ wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, projectName + "::main"); //$NON-NLS-1$ } ILaunch launch = super.getLaunch(wc.doSave(), mode); if (!(launch instanceof RustGDBLaunchWrapper)) { launch = new RustGDBLaunchWrapper(launch); } // workaround for DLTK bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=419273 launch.setAttribute("org.eclipse.dltk.debug.debugConsole", Boolean.toString(false)); //$NON-NLS-1$ return launch; }
Example 17
Source File: BaseConnectionFileManager.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private ExtendedFileInfo resolveSymlink(IPath dirPath, String linkTarget, int options, IProgressMonitor monitor) throws CoreException, FileNotFoundException { Set<IPath> visited = new HashSet<IPath>(); visited.add(dirPath); while (linkTarget != null && linkTarget.length() > 0) { IPath targetPath = Path.fromPortableString(linkTarget); if (!targetPath.isAbsolute()) { targetPath = dirPath.append(targetPath); } if (visited.contains(targetPath)) { break; } visited.add(targetPath); ExtendedFileInfo targetFileInfo = getCachedFileInfo(targetPath); if (targetFileInfo == null) { Policy.checkCanceled(monitor); try { targetFileInfo = cache(targetPath, fetchFileInternal(targetPath, options, Policy.subMonitorFor(monitor, 1))); } catch (PermissionDeniedException e) { // permission denied is like file not found for the case of symlink resolving throw initFileNotFoundException(targetPath, e); } } cache(targetPath, targetFileInfo); if (targetFileInfo.getAttribute(EFS.ATTRIBUTE_SYMLINK)) { linkTarget = targetFileInfo.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET); dirPath = targetPath.removeLastSegments(1); continue; } return targetFileInfo; } return new ExtendedFileInfo(); }
Example 18
Source File: JarPackageReader.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private IPath getPath(Element element) throws IOException { String pathString= element.getAttribute("path"); //$NON-NLS-1$ if (pathString.length() == 0) throw new IOException(JarPackagerMessages.JarPackageReader_error_tagPathNotFound); return Path.fromPortableString(element.getAttribute("path")); //$NON-NLS-1$ }
Example 19
Source File: ValidatorProblemMarkerResolutionGenerator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
public IMarkerResolution[] getResolutions(IMarker marker) { List<IMarkerResolution> markerResolutions = new ArrayList<IMarkerResolution>(); int problemId = marker.getAttribute(MarkerUtilities.PROBLEM_TYPE_ID, -1); if (problemId == -1) { return new IMarkerResolution[0]; } ProjectStructureOrSdkProblemType problemType = ProjectStructureOrSdkProblemType.getProblemType(problemId); String problemTypeData = marker.getAttribute( MarkerUtilities.PROBLEM_TYPE_DATA, ""); switch (problemType) { case MISSING_WEB_XML: { markerResolutions.add(new CreateWebXMLFileMarkerResolution()); break; } case BUILD_OUTPUT_DIR_NOT_WEBINF_CLASSES: { markerResolutions.add(new WrongOutputDirectoryMarkerResolution()); markerResolutions.add(new StopManagingWarOutputDirectoryResolution( marker.getResource().getProject())); break; } case JAR_OUTSIDE_WEBINF_LIB: { IPath buildClasspathFilePath = Path.fromPortableString(problemTypeData); markerResolutions.add(new CopyToServerClasspathMarkerResolution( buildClasspathFilePath)); markerResolutions.add(new AddToWarningExclusionListMarkerResolution( buildClasspathFilePath)); markerResolutions.add(new StopManagingWarOutputDirectoryResolution( marker.getResource().getProject())); break; } } return markerResolutions.toArray(new IMarkerResolution[0]); }
Example 20
Source File: JavaRefactoringDescriptorUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Converts an input handle with the given prefix back to the corresponding * resource. * * @param project * the project, or <code>null</code> for the workspace * @param handle * the input handle * * @return the corresponding resource, or <code>null</code> if no such * resource exists. * Note: if the given handle is absolute, the project is not used to resolve. */ public static IResource handleToResource(final String project, final String handle) { final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); if ("".equals(handle)) //$NON-NLS-1$ return null; final IPath path= Path.fromPortableString(handle); if (path == null) return null; if (project != null && !"".equals(project) && ! path.isAbsolute()) //$NON-NLS-1$ return root.getProject(project).findMember(path); return root.findMember(path); }