public static char getFileSeparatorChar(FileSystem fs) { if (isLocalFileSystem(fs)) { return File.separatorChar; } else { return '/'; //NOI18N } }
public FSPath(FileSystem fileSystem, String path) { this.fileSystem = fileSystem; this.path = CndFileUtils.normalizeAbsolutePath(fileSystem, path); }
public FileObject getFileObject() { // using fileSystem.findResource is not safe, see #196425 - AssertionError: no FileObject return CndFileUtils.toFileObject(fileSystem, path); }
@Override public List<FSPath> getSystemIncludePaths() { return CndFileUtils.toFSPathList(CndFileUtils.getLocalFileSystem(), this.sysIncludes); }
public static boolean isExistingFile(String filePath) { return isExistingFile(getLocalFileSystem(), filePath); }
private static String changeStringCaseIfNeeded(FileSystem fs, String path) { if (isLocalFileSystem(fs)) { if (CndFileUtils.isSystemCaseSensitive()) { return path; } else { return path.toLowerCase(); } } else { return path; // remote is always case sensitive } }
public boolean showSource(SourceFileInfo lineInfo, boolean isReadOnly) { FileObject fo = CndFileUtils.toFileObject(CndFileUtils.normalizeAbsolutePath(lineInfo.getFileName())); try { new ROEditor(fo).open(); } catch (DataObjectNotFoundException e) { e.printStackTrace(); return false; } return true; }
/** * In many places, standard sequence is as follows: * - convert path to absolute if need * - normalize it * - find file object * In the case of non-local file systems we should delegate it to correspondent file systems. */ public static FileObject getFileObject(FileObject baseFileObject, String relativeOrAbsolutePath) { FileObject result = FileSystemProvider.getFileObject(baseFileObject, relativeOrAbsolutePath); if (result == null) { String absRootPath = CndPathUtilities.toAbsolutePath(baseFileObject, relativeOrAbsolutePath); try { // XXX:fullRemote we use old logic for local and new for remote // but remote approach for local gives #197093 - Exception: null file final FileSystem fs = baseFileObject.getFileSystem(); if (CndFileUtils.isLocalFileSystem(fs)) { result = CndFileUtils.toFileObject(CndFileUtils.normalizeAbsolutePath(absRootPath)); } else { result = InvalidFileObjectSupport.getInvalidFileObject(fs, absRootPath); } } catch (FileStateInvalidException ex) { Exceptions.printStackTrace(ex); result = InvalidFileObjectSupport.getInvalidFileObject(InvalidFileObjectSupport.getDummyFileSystem(), absRootPath); } } return result; }
assert debug = true; if (debug) { if (!CndFileUtils.isExistingFile(fileSystem, this.path.toString())) { APTUtils.LOG.log(Level.WARNING, "ResolvedPath: isExistingFile failed in {0} for {1}", new Object[]{fileSystem, path}); if (CndFileUtils.isLocalFileSystem(fileSystem)) { if (CndFileUtils.toFileObject(fileSystem, path) == null) { APTUtils.LOG.log(Level.WARNING, "ResolvedPath: no FileObject in {0} for {1} FileUtil.toFileObject = {2} second check = {3}", new Object[]{
@Override public FileSystem getFileSystem() { return CndFileUtils.getLocalFileSystem(); }
private static FileObject toFileObjectImpl(FileSystem fs, CharSequence absolutePath) { if (isLocalFileSystem(fs)) { return toFileObject(absolutePath); } else { return fs.findResource(absolutePath.toString());
FileObject fo = CndFileUtils.toFileObject(CndFileUtils.normalizeAbsolutePath(fileName)); if (fo == null || ! fo.isValid()) { InputStream inputStream = null; URI uri = new URI(lineInfo.getFileName()); if (uri.getScheme() != null && uri.getScheme().equals("file")) { // NOI18N fo = CndFileUtils.toFileObject(FileUtil.normalizeFile(new File(uri))); // XXX:fullRemote writer.flush(); writer.close(); fo = CndFileUtils.toFileObject(CndFileUtils.normalizeFile(tempFile));
private static void index(FileSystem fs, String path, ConcurrentMap<String, Flags> files) { if (isLocalFileSystem(fs)) { File file = new File(path); if (CndFileSystemProvider.canRead(path)) { CndFileSystemProvider.FileInfo[] listFiles = listFilesImpl(file); for (CndFileSystemProvider.FileInfo curFile : listFiles) { String absPath = changeStringCaseIfNeeded(fs, curFile.absolutePath); if (isWindows) { // isLocalFS(fs) checked above absPath = absPath.replace('/', '\\'); FileObject file = fs.findResource(path); if (file != null && file.isFolder() && file.canRead()) { final char fileSeparatorChar = getFileSeparatorChar(fs); for (FileObject child : file.getChildren()) { assert changeStringCaseIfNeeded(fs, path).equals(path); files.put(path, Flags.INDEXED_DIRECTORY);
/** * tries to detect mime type of file checking cnd known types first * @param file file to check * @return one of mime types or "content/unknown" */ public static String getSourceFileMIMEType(File file) { FileObject fo = CndFileUtils.toFileObject(CndFileUtils.normalizeFile(file)); String mime; if (fo != null && fo.isValid()) { // try fast check mime = getSourceFileMIMEType(fo); } else { mime = getKnownSourceFileMIMETypeByExtension(file.getPath()); } return mime != null ? mime : "content/unknown"; // NOI18N }
String includePrefix = cCompiler.getIncludeFilePathPrefix(); File file = new File(includePrefix + absPath1); if (!CndFileUtils.exists(file) && absPath2 != null) { file = new File(includePrefix + absPath2); if (CndFileUtils.exists(file)) { FileObject fo = CndFileUtils.toFileObject(CndFileUtils.normalizeFile(file)); return fo;
@Override public Map<String, File> getBinaryFiles(ExecutionEnvironment env) { Map<String, File> result = new HashMap<String, File>(); if (relativePath != null && localAbsPath != null) { result.put(relativePath, CndFileUtils.createLocalFile(localAbsPath)); // NOI18N } return result; }
try { FileSystem fs = dObj.getPrimaryFile().getFileSystem(); if (!CndFileUtils.isLocalFileSystem(fs)) { annotationAttrs.add(new AttrValuePair(ATTR_ANNOTATION_FS, CndFileUtils.fileObjectToUrl(fs.getRoot()).toString()));
@Override public void fileFolderCreated(FileEvent fe) { File file = CndFileUtils.toFile(fe.getFile()); String path = file.getAbsolutePath(); String absPath = preparePath(path); if (getFilesMap(getLocalFileSystem()).put(absPath, Flags.DIRECTORY) != null) { // If there was something in the map already - invalidate it invalidateFile(path, absPath); } }
public static boolean exists(File file) { return getFlags(getLocalFileSystem(), file.getAbsolutePath(), true).exist; }
public static String naturalizeSlashes(FileSystem fileSystem, String path) { char rightSlash = CndFileUtils.getFileSeparatorChar(fileSystem); char wrongSlash = (rightSlash == '/') ? '\\' : '/'; return path.replace(wrongSlash, rightSlash); }