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

The following examples show how to use org.openide.filesystems.FileUtil#toFile() . 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: JUnitOutputReader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 */
private ClassPath findPlatformSources(final String javaExecutable) {
    
    /* Copied from JavaAntLogger */
    
    final JavaPlatform[] platforms = JavaPlatformManager.getDefault()
                                     .getInstalledPlatforms();
    for (int i = 0; i < platforms.length; i++) {
        FileObject fo = platforms[i].findTool("java");              //NOI18N
        if (fo != null) {
            File f = FileUtil.toFile(fo);
            if (f.getAbsolutePath().startsWith(javaExecutable)) {
                return platforms[i].getSourceFolders();
            }
        }
    }
    return null;
}
 
Example 2
Source File: TestCatalogModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected Document getDocument(FileObject fo){
    Document result = null;
    if (documentPooling) {
        result = documentPool().get(fo);
    }
    if (result != null) return result;
    try {

        File file = FileUtil.toFile(fo);
        FileInputStream fis = new FileInputStream(file);
        byte buffer[] = new byte[fis.available()];
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        result.remove(0, result.getLength());
        fis.read(buffer);
        fis.close();
        String str = new String(buffer);
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    if (documentPooling) {
        documentPool().put(fo, result);
    }
    return result;
}
 
Example 3
Source File: WLDeploymentManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private File getJavaBinary() {
    // TODO configurable ? or use the jdk server is running on ?
    JavaPlatform platform = JavaPlatformManager.getDefault().getDefaultPlatform();
    Collection<FileObject> folders = platform.getInstallFolders();
    String javaBinary = Utilities.isWindows() ? "java.exe" : "java"; // NOI18N
    if (folders.size() > 0) {
        FileObject folder = folders.iterator().next();
        File file = FileUtil.toFile(folder);
        if (file != null) {
            javaBinary = file.getAbsolutePath() + File.separator
                    + "bin" + File.separator
                    + (Utilities.isWindows() ? "java.exe" : "java"); // NOI18N
        }
    }
    return new File(javaBinary);
}
 
Example 4
Source File: AppClientProjectOperations.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fixOtherReferences(final File originalPath) {
    final String property = AppClientProjectProperties.META_INF;
    final File projectDir = FileUtil.toFile(project.getProjectDirectory());
    
    ProjectManager.mutex().writeAccess(new Runnable() {
        public void run() {
            EditableProperties props = project.getAntProjectHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
            String path = props.getProperty(property);
            if (path == null) {
                return;
            }
            
            if (path.startsWith(originalPath.getAbsolutePath())) {
                String relative = PropertyUtils.relativizeFile(originalPath, new File(path));
                String fixedPath = new File(projectDir, relative).getAbsolutePath();
                props.setProperty(property, fixedPath);
                project.getAntProjectHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
            }
        }
    });
}
 
Example 5
Source File: DefaultProjectOperationsImplementationTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMoveWithInnerProjectComplex() throws Exception {
    TestUtil.createFileFromContent(DefaultProjectOperationsImplementationTest.class.getResource("data/test.txt"), projdir, "lib/test.txt");
    FileObject projdir2 = projdir.getFileObject("lib").createFolder("proj2");
    
    createProject(projdir2);
    
    ProgressHandle handle = ProgressHandleFactory.createHandle("test-handle");
    handle.start(DefaultProjectOperationsImplementation.MAX_WORK);
    
    FileObject oldProject     = prj.getProjectDirectory();
    File       oldProjectFile = FileUtil.toFile(oldProject);
    FileObject newTarget      = oldProject.getParent();
    
    DefaultProjectOperationsImplementation.doMoveProject(handle, prj, "projMove", "projMove", newTarget, "ERR_Cannot_Move");
    
    File newProject = new File(FileUtil.toFile(newTarget), "projMove");
    
    assertTrue(newProject.isDirectory());
    assertTrue(new File(newProject, "nbproject").isDirectory());
    assertTrue(new File(newProject, "src").isDirectory());
    assertTrue(new File(newProject, "lib").isDirectory());
    assertTrue(new File(new File(newProject, "lib"), "proj2").isDirectory());
    assertFalse(new File(new File(oldProjectFile, "lib"), "proj2").exists());
}
 
Example 6
Source File: DefaultProjectOperationsImplementationTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMoveWithInnerProjectSimple() throws Exception {
    TestUtil.createFileFromContent(DefaultProjectOperationsImplementationTest.class.getResource("data/test.txt"), projdir, "lib/test.txt");
    FileObject projdir2 = projdir.createFolder("proj2");
    
    createProject(projdir2);
    
    ProgressHandle handle = ProgressHandleFactory.createHandle("test-handle");
    handle.start(DefaultProjectOperationsImplementation.MAX_WORK);
    FileObject oldProject = prj.getProjectDirectory();
    File       oldProjectFile = FileUtil.toFile(oldProject);
    FileObject newTarget = oldProject.getParent();
    
    DefaultProjectOperationsImplementation.doMoveProject(handle, prj, "projMove", "projMove", newTarget, "ERR_Cannot_Move");
    
    File newProject = new File(FileUtil.toFile(newTarget), "projMove");
    
    assertTrue(newProject.isDirectory());
    assertTrue(new File(newProject, "nbproject").isDirectory());
    assertTrue(new File(newProject, "src").isDirectory());
    assertTrue(new File(newProject, "lib").isDirectory());
    // We now try to just move the project directory as is:
    assertTrue(new File(newProject, "proj2").isDirectory());
    assertFalse(new File(oldProjectFile, "proj2").exists());
}
 
Example 7
Source File: DefaultFileOpenHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void open(FileObject file, int line) {
    File realFile = FileUtil.toFile(file);
    if (realFile != null) {
        try {
            Desktop.getDesktop().edit(realFile);
        } catch (IOException ex) {
            LOGGER.log(Level.INFO, null, ex);
        }
    }
}
 
Example 8
Source File: Util.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Check if candiate FileObject is a derby database.
 * 
 * @param candidate the value of candidate
 * @return true if candidate is a derby database
 */
public static boolean isDerbyDatabase(FileObject candidate) {
    if (candidate.isFolder()) {
        FileObject sp = candidate.getFileObject("service.properties");
        return sp != null && FileUtil.toFile(sp) != null;
    } else {
        return false;
    }
}
 
Example 9
Source File: DelayFSEventsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override void setUp() throws Exception {
    clearWorkDir();
    
    File u = new File(getWorkDir(), "userdir");
    File uc = new File(u, "config");
    uc.mkdirs();
    System.setProperty("netbeans.user", u.toString());
    
    File h = new File(getWorkDir(), "nb/installdir");
    new File(h, "config").mkdirs();
    System.setProperty("netbeans.home", h.toString());

    File moduleJar = createModuleJar( manifest );
    mgr = Main.getModuleSystem().getManager();
    System.setProperty("installer.done", "false");
    FileObject[] arr = FileUtil.getConfigRoot().getChildren();
    FileUtil.getConfigRoot().addFileChangeListener(this);
    try {
        mgr.mutexPrivileged().enterWriteAccess();
        myModule = mgr.create( moduleJar, null, true, false, false );
        mgr.enable( myModule );
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
    
    assertNotNull("Module layer is installed", FileUtil.getConfigFile( "foo" ) );
    
    configDir = FileUtil.toFile( FileUtil.getConfigRoot() );//new File( getWorkDir(), "userdir/config" );
}
 
Example 10
Source File: ProblemReporterImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void fileDataCreated(FileEvent fe) {
    LOG.log(Level.FINE, "due to {0} scheduling reload of {1}", new Object[] {fe.getFile(), projectPOMFile});
    reloadTask.schedule(1000);
    File f = FileUtil.toFile(fe.getFile());
    if (f != null) {
        BatchProblemNotifier.resolved(f);
    } else {
        LOG.log(Level.FINE, "no java.io.File from {0}", fe);
    }
}
 
Example 11
Source File: ExternalTouchTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDeleteOfAChildNoticed() throws Exception {
    FileObject fileObject1 = testFolder.createData("fileObject1");
    FileObject[] arr = testFolder.getChildren();
    assertEquals("One child", 1, arr.length);
    assertEquals("Right child", fileObject1, arr[0]);

    File file = FileUtil.toFile(fileObject1);
    assertNotNull("File found", file);
    arr = null;
    fileObject1 = null;
    Reference<FileObject> ref = new WeakReference<FileObject>(fileObject1);
    assertGC("File Object can disappear", ref);

    Thread.sleep(100);

    class L extends FileChangeAdapter {
        int cnt;
        FileEvent event;

        @Override
        public void fileDeleted(FileEvent fe) {
            cnt++;
            event = fe;
        }

    }
    L listener = new L();
    testFolder.addRecursiveListener(listener);

    file.delete();

    testFolder.refresh();

    assertEquals("Change notified", 1, listener.cnt);
    assertEquals("Right file", file, FileUtil.toFile(listener.event.getFile()));
}
 
Example 12
Source File: CustomizerGeneral.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void initValues() {
    if (initialized) {
        return;
    }
    FileObject projectFolder = projProperties.getProject().getProjectDirectory();
    File pf = FileUtil.toFile(projectFolder);
    jTextFieldProjectFolder.setText(pf == null ? "" : pf.getPath()); // NOI18N
    initialized = true;
}
 
Example 13
Source File: JavaFXSampleProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static File createPrivateProperties(FileObject fo) throws IOException {
    String[] nameElements = AntProjectHelper.PRIVATE_PROPERTIES_PATH.split("/"); // NOI18N
    for (int i = 0; i < nameElements.length - 1; i++) {
        FileObject tmp = fo.getFileObject(nameElements[i]);
        if (tmp == null) {
            tmp = fo.createFolder(nameElements[i]);
        }
        fo = tmp;
    }
    fo = fo.createData(nameElements[nameElements.length - 1]);
    return FileUtil.toFile(fo);
}
 
Example 14
Source File: VCSInterceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIsMutable() throws IOException {
    File f = new File(dataRootDir, "workdir/root-test-versioned");
    FileObject fo = FileUtil.toFileObject(f);
    fo = fo.createData("checkme.txt");
    File file = FileUtil.toFile(fo);
    fo.canWrite();
    assertTrue(inteceptor.getBeforeCreateFiles().contains(file));
    assertTrue(inteceptor.getDoCreateFiles().contains(file));
    assertTrue(inteceptor.getCreatedFiles().contains(file));
    assertFalse(inteceptor.getIsMutableFiles().contains(file));
    
    file.setReadOnly();
    fo.canWrite();
    assertTrue(inteceptor.getIsMutableFiles().contains(file));
}
 
Example 15
Source File: BaseProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void compile(Project project, FileObject fileObject) {
    File file = FileUtil.toFile(fileObject);
    if (file == null) {
        LOGGER.log(Level.WARNING, "Not compiling, file not found for fileobject {0}", FileUtil.getFileDisplayName(fileObject));
        return;
    }
    FileObject webRoot = getWebRoot(project, fileObject);
    File target = getTargetFile(project, webRoot, file);
    if (target == null) {
        // not found
        return;
    }
    compileInternal(project, FileUtil.toFile(webRoot), file, target,
            CssPreprocessorUtils.parseCompilerOptions(getCompilerOptions(project), webRoot));
}
 
Example 16
Source File: SnapshotsWindowUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void refreshFolder(FileObject folder, boolean fullRefresh) {
    // Converting to Files as comparing FileObjects doesn't work for global storage
    File f1 = folder == null ? null : FileUtil.toFile(folder);
    File f2 = currentFolder == null ? null : FileUtil.toFile(currentFolder);
    if (Objects.equals(f1, f2)) {
        if (fullRefresh) refreshSnapshots();
        else snapshotsTableModel.fireTableDataChanged();
    }
}
 
Example 17
Source File: ContextJspServletGenTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MetadataModel<WebAppMetadata> getMetadataModel() {
    if (myWebAppMetadataModel == null) {
        FileObject ddFO = getDeploymentDescriptor();
        File ddFile = ddFO != null ? FileUtil.toFile(ddFO) : null;
        MetadataUnit metadataUnit = MetadataUnit.create(
            myClassPathProvider.findClassPath( myWebRoot , ClassPath.BOOT),
            myClassPathProvider.findClassPath( myWebRoot ,ClassPath.COMPILE),
            myClassPathProvider.findClassPath( myWebRoot ,ClassPath.SOURCE),
            ddFile);
        myWebAppMetadataModel = WebAppMetadataModelFactory.
            createMetadataModel(metadataUnit, true);
    }
    return myWebAppMetadataModel;
}
 
Example 18
Source File: AbstractHgTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected File createFolder(File parent, String name) throws IOException {
    FileObject parentFO = FileUtil.toFileObject(parent);
    FileObject folder = parentFO.createFolder(name);                
    return FileUtil.toFile(folder);
}
 
Example 19
Source File: SBHomeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns Home if path is valid path and launcherPath points at existing launcher file
 * @param path
 * @param launcherPath
 * @param propertiesPath
 * @return Home
 */
private static Home getHomeForPath(String path, String launcherPath, String propertiesPath, String defaultVersion) throws PathDoesNotExist {
    Parameters.notNull("path", path); //NOI18N
    Parameters.notNull("launcherPath", launcherPath); //NOI18N
    Parameters.notNull("propertiesPath", propertiesPath); //NOI18N
    String homePath = path;
    if(path.startsWith("~")) { // NOI18N
        String userHome = System.getProperty("user.home"); // NOI18N
        homePath = userHome + path.substring(1);
    }
    File installDir = new File(homePath);
    if (installDir != null && installDir.exists() && installDir.isDirectory()) {
        FileObject installDirFO = FileUtil.toFileObject(installDir);

        File launcher = new File(homePath + File.separator + launcherPath);
        if(launcher != null && launcher.exists() && launcher.isFile()) {
        
            FileObject propertiesFO = installDirFO.getFileObject(propertiesPath); // NOI18N
            if (propertiesFO != null && propertiesFO.isValid() && propertiesFO.isData()) {
                try {
                    Properties props = new Properties();
                    FileReader reader = new FileReader(FileUtil.toFile(propertiesFO));
                    try {
                        props.load(reader);
                    } finally {
                        reader.close();
                    }
                    String version = props.getProperty("version"); //NOI18N
                    if (version == null) {
                        version = props.getProperty("app.version"); //NOI18N
                    }
                    return new Home(homePath, launcherPath, propertiesPath, version == null ? defaultVersion : version);
                } catch (IOException e) {
                }
            } else if (Utilities.isMac() && path.equals(NbBundle.getMessage(SBHomeFactory.class, "MAC_GLUON_HOME"))) { //NOI18N
                // Gluon SceneBuilder 8.0.0 does not have scenebuilder.properties file
                return new Home(homePath, launcherPath, propertiesPath, defaultVersion);
            }
        }
    } else {
        throw new PathDoesNotExist();
    }
    return null;
}
 
Example 20
Source File: BaseEEModuleImpl.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the module resource directory, or null if the module has no resource directory.
 * 
 * @return the module resource directory, or null if the module has no resource directory.
 */
@Override
public File getResourceDirectory() {
    return new File(FileUtil.toFile(project.getProjectDirectory()), "src" + File.separator + "main" + File.separator + "setup"); //NOI18N
}