private static String getFileURI(IResource resource) { URI uri = resource.getLocationURI(); if (uri != null) { // If the file path contains non ASCII characters, encode the result. String uriString = uri.toASCIIString(); // Fix uris by adding missing // to single file:/ prefix. return uriString.replaceFirst("file:/([^/])", "file:///$1"); } return null; }
public static boolean areEqualInWorkspaceOrOnDisk(IResource r1, IResource r2){ if (r1 == null || r2 == null) return false; if (r1.equals(r2)) return true; URI r1Location= r1.getLocationURI(); URI r2Location= r2.getLocationURI(); if (r1Location == null || r2Location == null) return false; return r1Location.equals(r2Location); }
public static boolean areEqualInWorkspaceOrOnDisk(IResource r1, IResource r2){ if (r1 == null || r2 == null) return false; if (r1.equals(r2)) return true; URI r1Location= r1.getLocationURI(); URI r2Location= r2.getLocationURI(); if (r1Location == null || r2Location == null) return false; return r1Location.equals(r2Location); }
public static boolean areEqualInWorkspaceOrOnDisk(IResource r1, IResource r2){ if (r1 == null || r2 == null) return false; if (r1.equals(r2)) return true; URI r1Location= r1.getLocationURI(); URI r2Location= r2.getLocationURI(); if (r1Location == null || r2Location == null) return false; return r1Location.equals(r2Location); }
public static boolean areEqualInWorkspaceOrOnDisk(IResource r1, IResource r2){ if (r1 == null || r2 == null) { return false; } if (r1.equals(r2)) { return true; } URI r1Location= r1.getLocationURI(); URI r2Location= r2.getLocationURI(); if (r1Location == null || r2Location == null) { return false; } return r1Location.equals(r2Location); }
/** * Returns the location of the given resource. For local * resources this is the OS path in the local file system. For * remote resource this is the URI. * * @param resource the resource * @return the location string or <code>null</code> if the * location URI of the resource is <code>null</code> */ public static String getLocationString(IResource resource) { URI uri= resource.getLocationURI(); if (uri == null) return null; return EFS.SCHEME_FILE.equalsIgnoreCase(uri.getScheme()) ? new File(uri).getAbsolutePath() : uri.toString(); }
/** * Returns the location of the given resource. For local * resources this is the OS path in the local file system. For * remote resource this is the URI. * * @param resource the resource * @return the location string or <code>null</code> if the * location URI of the resource is <code>null</code> */ public static String getLocationString(IResource resource) { URI uri= resource.getLocationURI(); if (uri == null) return null; return EFS.SCHEME_FILE.equalsIgnoreCase(uri.getScheme()) ? new File(uri).getAbsolutePath() : uri.toString(); }
/** * Unique URI to identify this file * @since 3.3 */ default URI uri() { return getResource().getLocationURI(); }
public static File lookingFileFromPathString(String path){ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resourceInRuntimeWorkspace = root.findMember(path); if( resourceInRuntimeWorkspace == null){ return new File(path); } File file = new File(resourceInRuntimeWorkspace.getLocationURI()); return file; } }
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resourceInRuntimeWorkspace = root.findMember("rules/setup.txt"); File file = new File(resourceInRuntimeWorkspace.getLocationURI());
private static URI getCanonicalUri(IResource resource) { return getCanonicalUri(resource.getLocationURI()); }
private List/*<IResource>*/ getResourcesToVisit(IResource resource) throws CoreException { // use set for fast lookup final Set/*<URI>*/ visited = new HashSet/*<URI>*/(); // use list to preserve the order of visited resources final List/*<IResource>*/ toVisit = new ArrayList/*<IResource>*/(); visited.add(resource.getLocationURI()); resource.accept(proxy -> { IResource childResource = proxy.requestResource(); URI uri = childResource.getLocationURI(); if (!visited.contains(uri)) { visited.add(uri); toVisit.add(childResource); } return true; }, IResource.NONE); return toVisit; }
@Override public IProject getProject(URI projectUri) { try { for (IResource each : workspaceRoot().members()) { if (each.getLocationURI().equals(projectUri)) { return (IProject) each; } } throw new IllegalArgumentException("Could not find project for " + projectUri); } catch (CoreException e) { throw new RuntimeException(e); } }
@Override public File findFileFor(IPath path) { IWorkspaceRoot root = workspaceRoot(); IResource member = root.findMember(path); if (member == null) { return null; } File file = new File(member.getLocationURI().getPath()); if (file.exists()) { return file; } return null; } }
private int getFileSystemAttributes(IResource resource) { URI location = resource.getLocationURI(); if (location == null || location.getScheme() == null) return 0; IFileSystem fs; try { fs = EFS.getFileSystem(location.getScheme()); } catch (CoreException e) { return 0; } return fs.attributes(); }
/** * @param resource * @return */ private JarRecord createJARRecord(IResource jar) { IPath location = jar.getLocation(); JarRecord jarRecord = null; if (location != null) { jarRecord = createJARRecord(location.toString()); } else if (jar.getLocationURI() != null) { jarRecord = createJARRecord(jar.getLocationURI().toString()); } return jarRecord; }
private synchronized void initFromFS(ISonarLintFile file, Path temporaryDirectory) { IFileStore fileStore; try { fileStore = EFS.getStore(file.getResource().getLocationURI()); File localFile = fileStore.toLocalFile(EFS.NONE, null); if (localFile == null) { // For analyzers to properly work we should ensure the temporary file has a "correct" name, and not a generated one localFile = new File(temporaryDirectory.toFile(), file.getProjectRelativePath()); Files.createDirectories(localFile.getParentFile().toPath()); fileStore.copy(EFS.getStore(localFile.toURI()), EFS.OVERWRITE, null); } filePath = localFile.toPath().toAbsolutePath(); } catch (Exception e) { throw new IllegalStateException("Unable to find path for file " + file, e); } }
private URI getXpandAdviceFileFromWorkspace(String xpandAdvice) { URI xpandAdviceFileURI = null; IResource resource = EcorePlugin.getWorkspaceRoot().findMember(Path.fromPortableString(xpandAdvice)); if (resource != null && resource.exists()) { xpandAdviceFileURI = URI.createURI(resource.getLocationURI().toString()); } return xpandAdviceFileURI; }
/** * Returns uri for a resource * @param resource * @return */ public static String getFileURI(IResource resource) { return ResourceUtils.fixURI(resource.getRawLocationURI() == null ? resource.getLocationURI() : resource.getRawLocationURI()); }
boolean exists(IResource res) throws CoreException { URI uri = res.getLocationURI(); if (uri != null) { IFileStore fileStore = EFS.getStore(uri); return (fileStore != null) && fileStore.fetchInfo().exists(); } return false; }