Java Code Examples for org.openide.filesystems.FileUtil#toFileObject()

The following examples show how to use org.openide.filesystems.FileUtil#toFileObject() . 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: BackupFacility2.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void storeChecksum(long l) throws IOException {
    BackupEntry backup = map.get(l);
    if(backup.orig == null) { // Find fileobject for newly created file
        backup.orig = FileUtil.toFileObject(backup.origFile);
        backup.origFile = null;
    }
    FileObject fo = backup.orig;
    if (!fo.isValid()) {
        //deleted
        backup.checkSum = new byte[16];
        Arrays.fill(backup.checkSum, (byte)0);
        return;
    }
    DataObject dob = DataObject.find(fo);
    if (dob != null) {
        CloneableEditorSupport ces = dob.getLookup().lookup(CloneableEditorSupport.class);
        final BaseDocument doc = (BaseDocument) ces.getDocument();
        if (doc !=null && doc.isAtomicLock()) {
            //workaround to avoid deadlock
            return;
        }
    }
    LOG.log(Level.FINE, "Storing MD5 for {0}", backup.orig);
    backup.checkSum = getMD5(getInputStream(backup.orig));
    LOG.log(Level.FINE, "MD5 is: {0}", MD5toString(backup.checkSum));
}
 
Example 2
Source File: ProvidedExtensionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testImplsFileLock() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    assertNotNull(fo);
    assertNotNull(iListener);
    iListener.clear();
    FileObject toLock = fo.createData(getName());
    assertNotNull(toLock);
    assertEquals("Check on " + iListener, 0, iListener.implsFileLockCalls);
    FileLock fLock = toLock.lock();
    try {
        assertTrue(fLock.isValid());
        assertEquals(0, iListener.implsFileUnlockCalls);                        
        assertEquals(1, iListener.implsFileLockCalls);            
    } finally {
        fLock.releaseLock();
        assertEquals("Just one unlock " + iListener, 1, iListener.implsFileUnlockCalls);                                    
    }        
}
 
Example 3
Source File: RTools.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
public static  PluginVersionResult handlePluginVersion(AndroidProject androidProject,Variant variant, FileObject prjDir) {
    if (androidProject!=null && variant!=null) {
        File buildFolder = androidProject.getBuildFolder();
        String modelVersion = androidProject.getModelVersion();
        PluginVersion pluginVersion = pluginVersionFromString(modelVersion);
        if (pluginVersion.compareTo(new PluginVersion(3, 3, 0)) >= 0) {
            String variantName = variant.getName();
            String rFolderPath = buildFolder.getAbsolutePath() + File.separator + "generated" + File.separator + "not_namespaced_r_class_sources" + File.separator + variantName + File.separator + "process" + StringUtils.capitalize(variantName) + "Resources" + File.separator + "r";
            File rFolder = new File(rFolderPath);
            if (rFolder.exists() && rFolder.isDirectory()) {
                FileObject src = FileUtil.toFileObject(rFolder);
                String srcName = null;
                if (prjDir != null) {
                    srcName = FileUtil.isParentOf(prjDir, src)
                            ? FileUtil.getRelativePath(prjDir, src)
                            : rFolder.getAbsolutePath();
                } else {
                    srcName = rFolder.getAbsolutePath();
                }
                return new PluginVersionResult(src, srcName);
            }
        }
    }
    return null;
}
 
Example 4
Source File: JavaSourceTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void startAndBlockClassPathScan() throws IOException, InterruptedException {
    if (blockLatch != null) {
        resumeClassPathScan();
    }
    FileObject workDir = FileUtil.toFileObject(getWorkDir());
    FileObject blockFO = FileUtil.createFolder(workDir, FileUtil.findFreeFolderName(workDir, "cp-scan-block-root"));
    MockLookup.setInstances(cpProvider, new SimpleClassPathProvider(blockFO));
    System.out.println(System.identityHashCode(ClassPath.getClassPath(blockFO, ClassPath.SOURCE)));
    IndexingManager.getDefault().refreshIndexAndWait(blockFO.getURL(), null);
    final CountDownLatch waitLatch = new CountDownLatch(1);
    blockLatch = new CountDownLatch(1);
    ClassIndex index = ClasspathInfo.create(blockFO).getClassIndex();
    index.addClassIndexListener(new ClassIndexAdapter() {
        public void typesAdded(TypesEvent event) {
            waitLatch.countDown();
            try {
                blockLatch.await();
            } catch (InterruptedException e) {
                throw new Error(e);
            }
        }
    });
    TestUtilities.copyStringToFileObject(blockFO, "Dummy.java", "public class Dummy {}");
    waitLatch.await();
}
 
Example 5
Source File: ALT_Resizing12Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ALT_Resizing12Test(String name) {
    super(name);
    try {
 className = this.getClass().getName();
 className = className.substring(className.lastIndexOf('.') + 1, className.length());
        startingFormFile = FileUtil.toFileObject(new File(url.getFile() + goldenFilesPath + className + "-StartingForm.form").getCanonicalFile());
    } catch (IOException ioe) {
        fail(ioe.toString());
    }
}
 
Example 6
Source File: ProvidedExtensionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDuringAtomicAction() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    iListener.clear();
    fo.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            FileObject f = FileUtil.createData(new File(getWorkDir(), "a/b/c/d/e/f/g.txt"));
            assertEquals(7, iListener.implsCreateSuccessCalls);
            f.delete();
            assertEquals(1, iListener.implsDeleteSuccessCalls);
        }            
    });
}
 
Example 7
Source File: VCSContextTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    dataRootDir = getDataDir();
    File userdir = new File(getWorkDir() + "userdir");
    userdir.mkdirs();
    System.setProperty("netbeans.user", userdir.getAbsolutePath());
    System.setProperty("data.root.dir", dataRootDir.getAbsolutePath());
    FileObject fo = FileUtil.toFileObject(getDataDir());
}
 
Example 8
Source File: ProvidedExtensionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreatedExternally() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    FileObject[] children = fo.getChildren(); // scan folder

    FileObject folder = fo.createFolder("folder");
    iListener.clear();
    assertEquals(0, iListener.implsCreatedExternallyCalls);
    File f = new File(FileUtil.toFile(fo), "file");
    f.createNewFile();
    assertEquals(0, iListener.implsCreatedExternallyCalls);
    fo.refresh();
    assertEquals(1, iListener.implsCreatedExternallyCalls);
}
 
Example 9
Source File: ConstrainedBinaryIndexerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private URL createArchive(
        @NonNull final File dir,
        @NonNull final String name,
        @NonNull String[] requiredResources) throws IOException {
    final FileObject folder = FileUtil.toFileObject(dir);
    FileObject tmp = folder.getFileObject(name);
    if (tmp != null) {
        tmp.delete();
    }
    tmp = folder.createData(name);
    final FileLock lock = tmp.lock();
    try {
        final ZipOutputStream out = new ZipOutputStream(tmp.getOutputStream(lock));
        try {
            //Put at least something.
            out.putNextEntry(new ZipEntry("nothing.txt"));  //NOI18N
            for (String res : requiredResources) {
                out.putNextEntry(new ZipEntry(res));
            }
        } finally {
            out.close();
        }
    } finally {
        lock.releaseLock();
    }
    return FileUtil.getArchiveRoot(tmp.getURL());
}
 
Example 10
Source File: ALT_MaintainSize06Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ALT_MaintainSize06Test(String name) {
    super(name);
    try {
 className = this.getClass().getName();
 className = className.substring(className.lastIndexOf('.') + 1, className.length());
        startingFormFile = FileUtil.toFileObject(new File(url.getFile() + goldenFilesPath + className + "-StartingForm.form").getCanonicalFile());
    } catch (IOException ioe) {
        fail(ioe.toString());
    }
}
 
Example 11
Source File: StatusTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    System.setProperty("netbeans.user", new File(getWorkDir().getParentFile(), "userdir").getAbsolutePath());
    super.setUp();
    
    // create
    FileObject fo = FileUtil.toFileObject(getWorkTreeDir());
    
}
 
Example 12
Source File: ALT_Baseline03Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ALT_Baseline03Test(String name) {
    super(name);
    try {
 className = this.getClass().getName();
 className = className.substring(className.lastIndexOf('.') + 1, className.length());
        startingFormFile = FileUtil.toFileObject(new File(url.getFile() + goldenFilesPath + className + "-StartingForm.form").getCanonicalFile());
    } catch (IOException ioe) {
        fail(ioe.toString());
    }
}
 
Example 13
Source File: MessageDestinationSupportImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void ensureDestinationsFOExists() throws IOException {
    if (!destinationsFile.exists()) {
        return;
    }
    if (destinationsFO == null || !destinationsFO.isValid()) {
        destinationsFO = FileUtil.toFileObject(destinationsFile);
        assert (destinationsFO != null);
        destinationsFO.addFileChangeListener(new MessageDestinationFileListener());
    }
}
 
Example 14
Source File: PackageJsonTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    File dummy = new File(getWorkDir(), "dummy");
    assertTrue(dummy.mkdir());
    directory = FileUtil.toFileObject(dummy);
    assertNotNull(directory);
    packageJson = new PackageJson(directory);
}
 
Example 15
Source File: ALT_Positioning06Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ALT_Positioning06Test(String name) {
    super(name);
    try {
 className = this.getClass().getName();
 className = className.substring(className.lastIndexOf('.') + 1, className.length());
        startingFormFile = FileUtil.toFileObject(new File(url.getFile() + goldenFilesPath + className + "-StartingForm.form").getCanonicalFile());
    } catch (IOException ioe) {
        fail(ioe.toString());
    }
}
 
Example 16
Source File: BackupFacilityTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    FileObject workdir = FileUtil.toFileObject(getWorkDir());
    f = FileUtil.createData(workdir, "test");
    folder = FileUtil.createFolder(workdir, "test2");
    f2 = FileUtil.createData(folder, "test");
    OutputStream outputStream = f.getOutputStream();
    outputStream.write("test".getBytes());
    outputStream.close();
}
 
Example 17
Source File: FileBasedFileSystem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public FileObject getTempFolder() throws IOException {
    FileObject tmpDir =  FileUtil.toFileObject(new File(System.getProperty("java.io.tmpdir")));
    if (tmpDir != null && tmpDir.isFolder() && tmpDir.isValid()) {
        return tmpDir;
    }
    throw new IOException("Cannot find temporary folder"); // NOI18N
}
 
Example 18
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFolderToFileWithParentRefresh() throws Exception {
    File f = new File(getWorkDir(), "classes");
    f.createNewFile();
    assertTrue("File created", f.isFile());
    
    FileObject fo = FileUtil.toFileObject(f);
    assertTrue("Is data", fo.isData());
    FileObject parent = fo.getParent();
    List<FileObject> arr = Arrays.asList(parent.getChildren());
    
    assertTrue("Contains " + fo + ": " +arr, arr.contains(fo));
    
    f.delete();
    f.mkdirs();
    assertTrue("Is dir", f.isDirectory());
    
    
    parent.refresh();
    
    assertFalse("No longer valid", fo.isValid());
    FileObject folder = FileUtil.toFileObject(f);
   
    if (fo == folder) {
        fail("Should not be the same: " + folder);
    }
    assertTrue("Is folder", folder.isFolder());
}
 
Example 19
Source File: TestAnnotationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Set<FileSystem> getRootFilesystems() {
    Set<FileSystem> filesystems = new HashSet<FileSystem>();
    File [] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
        File root = roots[i];
        FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(root));
        if (fo == null) continue;
        try {
            filesystems.add(fo.getFileSystem());
        } catch (FileStateInvalidException e) {
            // ignore invalid filesystems
        }
    }
    return filesystems;
}
 
Example 20
Source File: DiffResultsViewForLine.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public LocalFileDiffStreamSource (File file, boolean isRight) {
    this.file = FileUtil.normalizeFile(file);
    this.fileObject = FileUtil.toFileObject(this.file);
    this.isRight = isRight;
}