IPath path = new Path(violation.getSourceFile().getAbsolutePath()); IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation(); path = path.makeRelativeTo(workspacePath); IFile toOpen = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
@Override public String getText(Object element) { IPath rootLocation = new Path(job.getRoot().getAbsolutePath()); IPath projectLocation = ((Entry<IPath, Exception>)element).getKey(); return projectLocation.makeRelativeTo(rootLocation).toString(); } });
public static String makeRelative(String original, String rootPath) { IPath path = new Path(original); // ensure we have an absolute path to start with if (!path.isAbsolute()) return original; //Returns the original string if no relativization has been done IPath result = path.makeRelativeTo(new Path(rootPath)); return path.equals(result) ? original : result.toString(); }
public static String makeRelative(String original, String rootPath) { IPath path = new Path(original); // ensure we have an absolute path to start with if (!path.isAbsolute()) return original; //Returns the original string if no relativization has been done IPath result = path.makeRelativeTo(new Path(rootPath)); return path.equals(result) ? original : result.toString(); }
/** * Calculates the relative path from a base to a target path. * * @param base the base path to make the target path relative to * @param target the target file to which the relative path is calculated * @return the relative path from the base to the target location * @throws NullPointerException if an argument is {@code null} * @throws IllegalArgumentException if an argument does not denote an absolute path */ public static IPath getRelativePath(IPath base, IPath target) { Preconditions.checkNotNull(base); Preconditions.checkNotNull(target); Preconditions.checkArgument(base.isAbsolute()); Preconditions.checkArgument(target.isAbsolute()); return target.makeRelativeTo(base); }
/** * Returns the generated value of this entry for the build.properties file. * * @return value to enter into build.properties */ String getValue() { StringBuffer buf = new StringBuffer(); IContainer root = PDEProject.getBundleRoot(fResource.getProject()); buf.append(fResource.getFullPath().makeRelativeTo(root.getFullPath()).makeAbsolute()); buf.append('['); buf.append(fEncoding); buf.append(']'); return buf.toString(); }
protected FileListener(AFileManager<T> fileManager) { this.fileManager = fileManager; IPath absolutePath2 = new org.eclipse.core.runtime.Path(fileManager.getAbsolutePath()); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IPath rootLocation = root.getLocation(); if (absolutePath2.matchingFirstSegments(rootLocation) != rootLocation.segmentCount()) { try { final IFile[] filesOfLocation = root.findFilesForLocationURI(URI.create("file:/" + absolutePath2.toString().replace(" ", "%20"))); absolutePath2 = filesOfLocation[0].getFullPath().makeRelativeTo(rootLocation); } catch (final IndexOutOfBoundsException e) { Logger.logError(e); eclipseFile = null; return; } } this.eclipseFile = absolutePath2.makeRelativeTo(rootLocation); }
private void addFileIfMatch(File file, FileToPathMap result, IPath baseDir, IPath destination) { IPath relativePath = Path.fromOSString(file.getAbsolutePath()).makeRelativeTo(baseDir); IPath destinationPath = destination.append(relativePath); if (matches(relativePath)) { result.put(file, destinationPath); } } }
private IPath getReplacementPath(File originalFolder, IFolder webResourcesFolder, IPath defaultOutputPathPrefix) throws IOException { IPath originalDestinationFolderPath = Path.fromOSString(originalFolder.getCanonicalPath()); if (!defaultOutputPathPrefix.isPrefixOf(originalDestinationFolderPath)) { return null; } IPath relativePath = originalDestinationFolderPath.makeRelativeTo(defaultOutputPathPrefix); IPath customPath = webResourcesFolder.getLocation().append(relativePath); return customPath; }
@Override public boolean visit(IResourceProxy resourceProxy) { String proxyName = resourceProxy.getName(); if ((resourceProxy.getType() != IResource.FILE) || !proxyName.endsWith(PROPERTIES_FILE_SUFFIX)) { return true; } IResource resource = resourceProxy.requestResource(); if (FileUtil.notExists(resource)) { return true; } IPath resourcePath = resource.getLocation(); IPath path = resourcePath.makeRelativeTo(_entryResource.getLocation()); String pathString = path.toString(); String relativePath = pathString.replace(PROPERTIES_FILE_SUFFIX, ""); try { if (relativePath.matches(_matchedRelativePath)) { _resources.add((IFile)resource); } } catch (Exception e) { // in case something is wrong when doing match regular expression return true; } return true; }
private String getLinkedResourceInResource(IContainer root, IContainer folder) { StringBuffer sb = new StringBuffer(); try { for (IResource ir : folder.members()) { if (ir instanceof IFolder) { if (ir.isLinked()) { sb.append(ir.getProjectRelativePath().makeRelativeTo( root.getProjectRelativePath()) + "=" + ir.getLocation() + ";"); } sb.append(getLinkedResourceInResource(root, (IFolder) ir)); } } } catch (CoreException e) { e.printStackTrace(); } return sb.toString(); }
private static String makeRelativePath(IPath pathToConvert, IPath jarPath, IPath rootPath) { if (pathToConvert == null) { return null; } if (!jarPath.equals(pathToConvert) && rootPath.isPrefixOf(pathToConvert)) { return pathToConvert.makeRelativeTo(rootPath).toPortableString(); } return pathToConvert.toPortableString(); }
private IFolder getScriptFolderOf(IScriptFolder scriptFolder, IScriptProject scriptProject) throws CoreException { List<IFolder> scriptFolders = RutaProjectUtils.getScriptFolders(scriptProject); for (IFolder each : scriptFolders) { if (each.equals(scriptFolder.getResource())) { return each; } IPath path = scriptFolder.getPath().makeRelativeTo(each.getFullPath()); IResource findMember = each.findMember(path); if (findMember != null && findMember instanceof IFolder) { return each; } } return null; }
private static void addPath(ArrayList<IPath> result, IProject project, IPath path) { IPath resultPath = null; if (path.isAbsolute()) resultPath = path; else if (path.segmentCount() > 0 && path.segment(0).equals(project.getName())) { IContainer bundleRoot = PDEProject.getBundleRoot(project); IPath rootPath = bundleRoot.getFullPath(); // make path relative to bundle root path = path.makeRelativeTo(rootPath); if (path.segmentCount() == 0) resultPath = new Path(DOT); else { IResource resource = bundleRoot.findMember(path); if (resource != null) resultPath = path; } } if (resultPath != null && !result.contains(resultPath)) result.add(resultPath); }
private static IPath getWorkspacePath(IPath path) { PreferenceManager manager = JavaLanguageServerPlugin.getPreferencesManager(); Collection<IPath> rootPaths = manager.getPreferences().getRootPaths(); if (rootPaths != null) { for (IPath rootPath : rootPaths) { if (rootPath.isPrefixOf(path)) { return path.makeRelativeTo(rootPath.append("..")); } } } return path; }
parentSrcPaths.add(entry.getPath()); } else if (sourcePath.isPrefixOf(entry.getPath())) { exclusionPatterns.add(entry.getPath().makeRelativeTo(sourcePath).addTrailingSeparator()); for (IPath exclusion : exclusionPaths) { if (sourcePath.isPrefixOf(exclusion) && !sourcePath.equals(exclusion)) { exclusionPatterns.add(exclusion.makeRelativeTo(sourcePath).addTrailingSeparator());
IPath relativeTo = path.makeRelativeTo(fullPath); if (!relativeTo.isEmpty()) { sb.append("PACKAGE ");
@Override protected void handleBuildCheckStateChange(boolean wasTopParentChecked) { IResource resource = fParentResource; String resourceName = fParentResource.getProjectRelativePath().makeRelativeTo(fBundleRoot.getProjectRelativePath()).toPortableString(); IBuild build = fBuildModel.getBuild(); IBuildEntry includes = build.getEntry(IBuildPropertiesConstants.PROPERTY_SRC_INCLUDES); IBuildEntry excludes = build.getEntry(IBuildPropertiesConstants.PROPERTY_SRC_EXCLUDES); resourceName = handleResourceFolder(resource, resourceName); if (isChecked) handleCheck(includes, excludes, resourceName, resource, wasTopParentChecked, IBuildPropertiesConstants.PROPERTY_SRC_INCLUDES); else handleUncheck(includes, excludes, resourceName, resource, IBuildPropertiesConstants.PROPERTY_SRC_EXCLUDES); deleteEmptyEntries(); } }
@Override protected void handleBuildCheckStateChange(boolean wasTopParentChecked) { IResource resource = fParentResource; String resourceName = fParentResource.getProjectRelativePath().makeRelativeTo(fBundleRoot.getProjectRelativePath()).toPortableString(); IBuild build = fBuildModel.getBuild(); IBuildEntry includes = build.getEntry(IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); IBuildEntry excludes = build.getEntry(IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); resourceName = handleResourceFolder(resource, resourceName); if (isChecked) handleCheck(includes, excludes, resourceName, resource, wasTopParentChecked, IBuildPropertiesConstants.PROPERTY_BIN_INCLUDES); else handleUncheck(includes, excludes, resourceName, resource, IBuildPropertiesConstants.PROPERTY_BIN_EXCLUDES); deleteEmptyEntries(); fParentResource = fOriginalResource = null; }
protected boolean containsDebugFiles(IJavaProject project) { try { IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (getFile(folder, ".profile.d", "ngrok.sh") != null) {//$NON-NLS-1$ //$NON-NLS-2$ return true; } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } catch (CoreException ce) { CloudFoundryPlugin.logError(ce); } return false; }