Java Code Examples for org.openide.filesystems.FileObject#toURI()

The following examples show how to use org.openide.filesystems.FileObject#toURI() . 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: QueriesCache.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
protected List<? extends URI> getRootURIs() {
    final List<URI> result = new ArrayList<>(roots.length);
    for (FileObject root : roots) {
        final URI uri = root.toURI();
        if (uri != null) {
            result.add(uri);
        } else {
            LOG.log(
                Level.WARNING,
                "Cannot convert: {0} to URI.",  //NOI18N
                FileUtil.getFileDisplayName(root));
        }
    }
    return Collections.unmodifiableList(result);
}
 
Example 2
Source File: ProfileSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
Key createKey(@NonNull final URL rootURL) {
    final URL fileURL = FileUtil.getArchiveFile(rootURL);
    if (fileURL == null) {
        //Not an archive
        return null;
    }
    final FileObject fileFo = URLMapper.findFileObject(fileURL);
    if (fileFo == null) {
        return null;
    }
    return new Key(
        fileFo.toURI(),
        fileFo.lastModified().getTime(),
        fileFo.getSize());
}
 
Example 3
Source File: SimpleFileOwnerQueryImplementation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @see FileOwnerQuery#markExternalOwner */
public static void markExternalOwnerTransient(URI root, Project owner) {
    externalRootsIncludeNonFolders |= !root.getPath().endsWith("/");
    if (owner != null) {
        FileObject fo = owner.getProjectDirectory();
        URI foUri = owner == FileOwnerQuery.UNOWNED ? UNOWNED_URI : fo.toURI();
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.put(root, foUri);
            deserializedExternalOwners.remove(root);
        }
    } else {
        synchronized (cacheLock) {
            cacheInvalid = true;
            externalOwners.remove(root);
        }
    }
}
 
Example 4
Source File: RunToCursorActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
    public void doAction(Object action) {
        if (oneShotBreakpoint != null) {
            removeBreakpoints(oneShotBreakpoint);
            oneShotBreakpoint = null;
        }
        FileObject fo = EditorContextDispatcher.getDefault().getCurrentFile();
        if (fo == null) {
            return ;
        }
        URI uri = Source.getTruffleInternalURI(fo);
        if (uri == null) {
            uri = fo.toURI();
        }
        //File file = FileUtil.toFile(fo);
        //if (file == null) {
//            return ;
        //}
        //final String path = file.getAbsolutePath();
        int line = EditorContextDispatcher.getDefault().getCurrentLineNumber ();
        submitOneShotBreakpoint(uri.toString(), line);
        JPDAThread currentThread = debugger.getCurrentThread();
        if (currentThread != null) {
            currentThread.resume();
        }
        
    }
 
Example 5
Source File: DataShadowTranslateTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that file with just regular characters in name is translated OK
 * @throws Exception 
 */
public void testRegularURI() throws Exception {
    
    FileObject fo = FileUtil.getConfigRoot();
    
    FileObject origDir = fo.createFolder("origFolder");
    FileObject newFile = origDir.createData("regularFileName.txt");
    
    final FileObject d = fo.createFolder("subfolder");
    OutputStream ostm = d.createAndOpen("regularShadowURI.shadow");
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    URI uri = newFile.toURI();
    String urlString = newFile.toURI().toString();
    bw.write(urlString + ".old");
    bw.newLine();
    bw.newLine();
    bw.close();
    
    FileObject fob = d.getFileObject("regularShadowURI.shadow");
    DataObject dd = DataObject.find(fob);
    
    assertTrue("Shadow must be translated, not broken", dd instanceof DataShadow);
    
    DataShadow ds = (DataShadow)dd;
    assertEquals("Shadow's original must be on the translated location", newFile, ds.getOriginal().getPrimaryFile());
}
 
Example 6
Source File: SimpleFileOwnerQueryImplementation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean hasRoot(
        @NonNull final Set<URI> extRoots,
        @NonNull final FileObject file,
        final boolean folder,
        @NonNull final URI[] furi) {
    if (extRoots.isEmpty() || !(folder || externalRootsIncludeNonFolders)) {
        return false;
    }
    furi[0] = file.toURI();
    return extRoots.contains(furi[0]);
}
 
Example 7
Source File: ProviderRegistry.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Finds appropriate providers for given data content type
 * (similar to mime type)
 * and returns list of provider classes.
 *
 * @return Collection of providers, which implements NavigatorPanel interface.
 * Never return null, only empty List if no provider exists for given content type.
 */
public Collection<? extends NavigatorPanel> getProviders (String contentType, FileObject file) {
    if (contentTypes2Providers == null) {
        contentTypes2Providers = new HashMap<String, Collection<? extends NavigatorPanel>>(15);
    }
    Collection<? extends NavigatorPanel> result = contentTypes2Providers.get(contentType);
    if (result == null) {
        // load and instantiate provider classes
        result = loadProviders(contentType);
        contentTypes2Providers.put(contentType, result);
    }
    if (file != null) {
        if (file2Providers == null) {
            file2Providers = new WeakHashMap<>();
        }
        URI uri = file.toURI();
        Reference<Collection<? extends NavigatorPanel>> fileResultRef = file2Providers.computeIfAbsent(file, f ->
                new SoftReference<>(Lookup.getDefault().lookupAll(DynamicRegistration.class).stream().flatMap(reg -> reg.panelsFor(uri).stream()).collect(Collectors.toList()))
        );
        Collection<? extends NavigatorPanel> fileResult = fileResultRef != null ? fileResultRef.get() : null;
        if (result == null) return fileResult;
        if (fileResult == null) return result;
        List<NavigatorPanel> panels = new ArrayList<>();
        panels.addAll(result);
        panels.addAll(fileResult);
        return panels;
    } else {
        return result;
    }
}
 
Example 8
Source File: BootClassPathUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public InferableJavaFileObject(FileObject file, Kind kind) {
    super(file.toURI(), kind);
    String relPath = FileUtil.getRelativePath(output, file);
    className = relPath.substring(0, relPath.length() - ".class".length()).replace('/', '.');
}
 
Example 9
Source File: BootClassPathUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public InferableJavaFileObject(FileObject file, Kind kind) {
    super(file.toURI(), kind);
    String relPath = FileUtil.getRelativePath(output, file);
    className = relPath.substring(0, relPath.length() - ".class".length()).replace('/', '.');
}