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

The following examples show how to use org.openide.filesystems.FileUtil#getConfigRoot() . 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: RunCustomMavenAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String actionDeclarationIconPath(String action) {
    String fsAction = action.replace("/", ""); //#236336 slash is evil
    FileObject root = FileUtil.getConfigRoot();
    FileObject actions = root.getFileObject("Actions");
    if (actions != null) {
        FileObject mavenCategory = actions.getFileObject("Maven");
        if (mavenCategory != null) {
            String name = fsAction + ".instance"; //action.replaceAll("[^a-z0-9_]+", "_");
            FileObject instance = mavenCategory.getFileObject(name);
            if (instance != null && action.equals(instance.getAttribute(MAVEN_ATTR))) {
                String path = (String) instance.getAttribute("imagePath");
                return path;
            }

        }
    }
    return null;
}
 
Example 2
Source File: TaskTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testEquals() throws FileStateInvalidException {
    String description = "task description";
    int lineNo = 123;
    FileObject resource = FileUtil.getConfigRoot();

    Task t1 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
    Task t2 = Task.create(resource, TASK_GROUP_NAME, description, lineNo );

    assertEquals( t1, t2 );
    assertEquals( t1.hashCode(), t2.hashCode() );

    URL url = FileUtil.getConfigRoot().getURL();

    t1 = Task.create(url, TASK_GROUP_NAME, description );
    t2 = Task.create(url, TASK_GROUP_NAME, description );

    assertEquals( t1, t2 );
    assertEquals( t1.hashCode(), t2.hashCode() );
}
 
Example 3
Source File: ToolbarPoolTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    FileObject root = FileUtil.getConfigRoot();
    toolbars = FileUtil.createFolder (root, "Toolbars");
    toolbarsFolder = DataFolder.findFolder (toolbars);
    FileObject[] arr = toolbars.getChildren ();
    for (int i = 0; i < arr.length; i++) {
        arr[i].delete ();
    }
    
    ToolbarPool tp = ToolbarPool.getDefault ();
}
 
Example 4
Source File: DataShadowTranslateTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks translation on Shadows, which use FS name + path, not URI
 * @throws Exception 
 */
public void testFSNameAndPath() throws Exception {
    FileObject fo = FileUtil.getConfigRoot();
    
    FileObject origDir = fo.createFolder("origFolder3");
    
    // create empty real file with special and non-ASCII chars
    FileObject newFile = origDir.createData("moved-here.txt");
    
    // createa a fake file, just to get its URI right:
    FileObject fake = fo.createData("dead-file-location.old");
    
    final FileObject d = fo.createFolder("subfolder3");
    OutputStream ostm = d.createAndOpen("regularShadowURI.shadow");
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    bw.write(fake.getPath());
    bw.newLine();
    bw.write(fake.getFileSystem().getSystemName());
    bw.newLine();
    
    fake.delete();
    
    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 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: ScannerCallbackTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFileScanner() {
    FileTaskScanner.Callback callback = AccessorImpl.DEFAULT.createCallback( taskManager, fileScanner );
    
    callback.refreshAll();
    assertEquals( fileScanner, taskManager.refreshedScanner );
    
    taskManager.refreshedScanner = null;
    FileObject fo = FileUtil.getConfigRoot();
    callback.refresh( fo );
    assertEquals( fileScanner, taskManager.refreshedScanner );
    assertEquals( fo, taskManager.refreshedResources[0] );
}
 
Example 7
Source File: SnapUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds an action into the folder given by {@code path} of the SNAP Desktop / NetBeans file system at the given {@code position}.
 *
 * @param action   The action.
 * @param path     The folder path.
 * @param position The position within the folder. May be {@code null}.
 * @return The file object representing the action.
 */
public synchronized static FileObject addAction(Action action, String path, Integer position) {
    FileObject configRoot = FileUtil.getConfigRoot();
    try {
        FileObject actionFile = FileUtil.createData(configRoot, getActionDataPath(path, action));
        actionFile.setAttribute("instanceCreate", new TransientAction(action, actionFile.getPath()));
        if (position != null) {
            actionFile.setAttribute("position", position);
        }
        return actionFile;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return null;
}
 
Example 8
Source File: OutputKeymapManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void storeShortCuts(String profileName) {
    FileObject root = FileUtil.getConfigRoot();
    try {
        FileObject actionsDir = FileUtil.createFolder(
                root, STORAGE_DIR + profileName);
        for (OutWinShortCutAction a : allActions) {
            FileObject data = actionsDir.getFileObject(a.getId());
            if (data == null) {
                data = actionsDir.createData(a.getId());
            } else if (data.isFolder()) {
                throw new IOException(data + " is a folder.");      //NOI18N
            }
            Enumeration<String> atts = data.getAttributes();
            while (atts.hasMoreElements()) {
                String attName = atts.nextElement();
                data.setAttribute(attName, null);
            }
            int index = 1;
            if (keymaps.get(profileName).get(a) == null) {
                continue;
            }
            for (String shortCut : keymaps.get(profileName).get(a)) {
                data.setAttribute(SHORTCUT_PREFIX + index++, shortCut);
            }
        }
    } catch (IOException e) {
        LOG.log(Level.WARNING, "Cannot create folder", e);          //NOI18N
    }
}
 
Example 9
Source File: ToolbarPoolDeadlockTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testWhoCreatesConstructor() throws Exception {
    FileObject root = FileUtil.getConfigRoot();
    FileObject fo = FileUtil.createFolder (root, "ToolbarsWhoCreates");
    final DataFolder df = DataFolder.findFolder(fo);
    ToolbarPool pool = new ToolbarPool(df);

    assertEquals("No children now", 0, pool.getToolbars().length);

    class Atom implements FileSystem.AtomicAction {

        FileObject m1, m2;

        public void run() throws IOException {
            m1 = FileUtil.createFolder(df.getPrimaryFile(), "m1");
            DataFolder f1 = DataFolder.findFolder(m1);
            InstanceDataObject.create(f1, "X", MyAction.class);
        }
    }
    Atom atom = new Atom();
    df.getPrimaryFile().getFileSystem().runAtomicAction(atom);
    pool.waitFinished();

    assertEquals("One toolbar is there", 1, pool.getToolbars().length);
    Toolbar tb = pool.getToolbars()[0];
    assertEquals("Pool name", "m1", tb.getName());
    assertEquals("Has one subcomponent", 1, tb.getComponents().length);
    Object o1 = tb.getComponent(0);
    if (!(o1 instanceof JButton)) {
        fail("Need JPanel " + o1);
    }
    assertEquals("And now the action is created", 1, MyAction.counter);
}
 
Example 10
Source File: WLTrustHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static synchronized void removeFromTrustStore(String url) throws GeneralSecurityException, IOException {
    FileObject root = FileUtil.getConfigRoot();
    FileObject ts = root.getFileObject(TRUST_STORE_PATH);
    if (ts == null) {
        return;
    }

    char[] password = Keyring.read(TRUST_PASSWORD_KEY);

    KeyStore keystore = KeyStore.getInstance("JKS"); // NOI18N
    InputStream is = new BufferedInputStream(ts.getInputStream());
    try {
        keystore.load(is, password);
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, null, ex);
        return;
    } finally {
        is.close();
    }

    keystore.deleteEntry(url);

    OutputStream out = new BufferedOutputStream(ts.getOutputStream());
    try {
        keystore.store(out, password);
    } finally {
        out.close();
    }
}
 
Example 11
Source File: NBFilesystemTestAction.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
    public void actionPerformed(final ActionEvent e) {
        final FileObject root = FileUtil.getConfigRoot();
        for (final FileObject fo : root.getChildren()) {
            LOGGER.log(Level.INFO, "object: {0}", fo.getPath());
        }

        final FileObject toolbars = root.getFileObject("Toolbars");
        descend(toolbars, 0);

//        final FileObject misc = root.getFileObject("OptionsDialog/Advanced");
//        for(final FileObject fo : misc.getChildren())
//        {
//            System.out.printf("@@file object Advanced: %s\n", fo.getPath());
//        }
//        final String unwanted1 = "OptionsDialog/General.instance";
//        final String unwanted2 = "OptionsDialog/Advanced/org-netbeans-core-ui-options-filetypes-FileAssociationsOptionsPanelController.instance";
//        for(final String unwanted : new String[]{unwanted1, unwanted2})
//        {
//            final FileObject general = root.getFileObject(unwanted);
//            if(general!=null)
//            {
//                System.out.printf("@@file object delete %s\n", unwanted);
//                try
//                {
//                    general.delete();
//                }
//                catch(IOException ex)
//                {
//                    Exceptions.printStackTrace(ex);
//                }
//            }
//        }
    }
 
Example 12
Source File: ToolbarPoolDeadlockTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    FileObject root = FileUtil.getConfigRoot();
    toolbars = FileUtil.createFolder (root, "Toolbars");
    toolbarsFolder = DataFolder.findFolder (toolbars);
    FileObject[] arr = toolbars.getChildren ();
    for (int i = 0; i < arr.length; i++) {
        arr[i].delete ();
    }
    
    ToolbarPool tp = ToolbarPool.getDefault ();
    tp.waitFinished ();
}
 
Example 13
Source File: ProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    root = FileUtil.getConfigRoot();
    for (FileObject f : root.getChildren()) {
        f.delete();
    }
}
 
Example 14
Source File: TemplateWizardTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    // set up user directory
    clearWorkDir();
    File wd = new File(getWorkDir(), "config");
    wd.mkdirs();
    System.setProperty("netbeans.user", wd.toString());
    FileObject fo = FileUtil.getConfigRoot ();
    FileUtil.createFolder (fo, "Templates");
}
 
Example 15
Source File: WhiteListCategoryPanelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void createWhiteListsFolder(Class<? extends WhiteListQueryImplementation.UserSelectable>... queries) throws IOException {
    final FileObject root = FileUtil.getConfigRoot();
    final FileObject folder = FileUtil.createFolder(root,"org-netbeans-api-java/whitelists/");  //NOI18N
    final DataFolder target = DataFolder.findFolder(folder);
    for (Class<? extends WhiteListQueryImplementation.UserSelectable> q : queries) {
        InstanceDataObject.create(target, q.getSimpleName(), q);
    }
}
 
Example 16
Source File: TaskTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNegativeLineNumberAllowed() throws FileStateInvalidException {
    String description = "task description";
    int lineNo = -1;
    FileObject resource = FileUtil.getConfigRoot();
    
    Task t = Task.create(resource, TASK_GROUP_NAME, description, lineNo );
    
    assertEquals( description, t.getDescription() );
    assertEquals( lineNo, t.getLine() );
    assertEquals( resource, t.getFile() );
    assertEquals( TaskGroupFactory.getDefault().getGroup( TASK_GROUP_NAME), t.getGroup() );
}
 
Example 17
Source File: RunCustomMavenAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void deleteDeclaration(String action) throws IOException {
    String fsAction = action.replace("/", ""); //#236336 slash is evil
    FileObject root = FileUtil.getConfigRoot();
    FileObject fo = root.getFileObject("Toolbars/Build/maven_" + fsAction + ".shadow");
    if (fo != null) {
        fo.delete();
    }
    fo = root.getFileObject("Actions/Maven/" + fsAction + ".instance");
    if (fo != null) {
        fo.delete();
    }
}
 
Example 18
Source File: ProjectLibraryProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void registerTestLibraryTypeProvider () throws Exception {
    StringTokenizer tk = new StringTokenizer("org-netbeans-api-project-libraries/LibraryTypeProviders","/");
    FileObject root = FileUtil.getConfigRoot();
    while (tk.hasMoreElements()) {
        String pathElement = tk.nextToken();
        FileObject tmp = root.getFileObject(pathElement);
        if (tmp == null) {
            tmp = root.createFolder(pathElement);
        }
        root = tmp;
    }
    if (root.getChildren().length == 0) {
        InstanceDataObject.create (DataFolder.findFolder(root),"TestLibraryTypeProvider",TestLibraryTypeProvider.class);
    }
}
 
Example 19
Source File: ValidateLayerConsistencyTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testAreAttributesFine () {
    List<String> errors = new ArrayList<String>();
    
    FileObject root = FileUtil.getConfigRoot();
    Enumeration<? extends FileObject> files = Enumerations.concat(Enumerations.singleton(root), root.getChildren(true));
    while (files.hasMoreElements()) {
        FileObject fo = files.nextElement();
        
        if (
            "Keymaps/NetBeans/D-BACK_QUOTE.shadow".equals(fo.getPath()) ||
            "Keymaps/NetBeans55/D-BACK_QUOTE.shadow".equals(fo.getPath()) ||
            "Keymaps/Emacs/D-BACK_QUOTE.shadow".equals(fo.getPath())
        ) {
            // #46753
            continue;
        }
        if (
            "Services/Browsers/FirefoxBrowser.settings".equals(fo.getPath()) ||
            "Services/Browsers/MozillaBrowser.settings".equals(fo.getPath()) ||
            "Services/Browsers/NetscapeBrowser.settings".equals(fo.getPath())
        ) {
            // #161784
            continue;
        }
        
        Enumeration<String> attrs = fo.getAttributes();
        while (attrs.hasMoreElements()) {
            String name = attrs.nextElement();

            if (isInstanceAttribute(name)) {
                continue;
            }
            
            if (name.indexOf('\\') != -1) {
                errors.add("File: " + fo.getPath() + " attribute name must not contain backslashes: " + name);
            }
            
            Object attr = fo.getAttribute(name);
            if (attr == null) {
                CharSequence warning = Log.enable("", Level.WARNING);
                if (
                    fo.getAttribute("class:" + name) != null &&
                    fo.getAttribute(name) == null &&
                    warning.length() == 0
                ) {
                    // ok, factory method returned null
                    continue;
                }

                errors.add("File: " + fo.getPath() + " attribute name: " + name);
            }

            if (attr instanceof URL) {
                URL u = (URL) attr;
                int read = -1;
                try {
                    read = u.openStream().read(new byte[4096]);
                } catch (IOException ex) {
                    errors.add(fo.getPath() + ": " + ex.getMessage());
                }
                if (read <= 0) {
                    errors.add("URL resource does not exist: " + fo.getPath() + " attr: " + name + " value: " + attr);
                }
            }

        }
    }
    
    assertNoErrors("Some attributes in files are unreadable", errors);
}
 
Example 20
Source File: DataShadowTranslateTest.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Checks that DataShadows to regular (non-SFS) files are not translated
 * even if a translation is defined for their path
 * 
 * @throws Exception 
 */
public void testNonSFSUriNotAffected() throws Exception {
    File wd = getWorkDir();
    
    clearWorkDir();
    
    FileObject origDir = FileUtil.toFileObject(wd);
    
    FileObject dirWithSpace = origDir.createFolder("Space Dir");
    FileObject newFile = dirWithSpace.createData("testFile.txt");
    

    File subDir = new File(wd, "translate");
    
    subDir.mkdirs();
    
    File metaTranslate = new File(subDir, "META-INF/netbeans");
    metaTranslate.mkdirs();
    
    String workPath = newFile.toURI().getRawPath();
    FileWriter wr = new FileWriter(new File(metaTranslate, "translate.names"));
    BufferedWriter bw = new BufferedWriter(wr);
    
    bw.write(workPath.substring(1) + "/testFile.txt=" + workPath.substring(1) + "/moved/testFile.txt");
    bw.close();
    
    
    FileObject fo = FileUtil.toFileObject(wd);
    
    ClassLoader orig = Lookup.getDefault().lookup(ClassLoader.class);
    
    ClassLoader my = new URLClassLoader(new URL[] {
        subDir.toURL()
    }, orig);
    
    MockLookup.setInstances(my);
    
    
    FileObject cfgRoot = FileUtil.getConfigRoot();
    
    
    OutputStream ostm = cfgRoot.createAndOpen("nonSFSFile.shadow");
    
    bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    bw.write(newFile.toURI().toString());
    bw.newLine();
    bw.newLine();
    
    newFile.delete();
    
    bw.close();
    
    FileObject fob = cfgRoot.getFileObject("nonSFSFile.shadow");
    DataObject dd = DataObject.find(fob);
    
    assertFalse("Shadow must be still broken", dd instanceof DataShadow);
}