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

The following examples show how to use org.openide.filesystems.FileUtil#getConfigFile() . 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: CodeTemplatesLocatorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFullCodeTemplatesLegacyLayout() throws Exception {
    String [] files = new String [] {
        "Editors/Defaults/abbreviations.xml",
        "Editors/abbreviations.xml",
    };
    
    LocatorTest.createOrderedFiles(files, CT_CONTENTS);
    
    FileObject baseFolder = FileUtil.getConfigFile("Editors");
    Map<String, List<Object []>> results = new HashMap<String, List<Object []>>();
    LocatorTest.scan(CodeTemplatesStorage.ID, baseFolder, null, null, true, true, true, results);
    
    assertNotNull("Scan results should not null", results);
    assertEquals("Wrong number of profiles", 1, results.size());
    
    List<Object []> profileFiles = results.get(null);
    LocatorTest.checkProfileFiles(files, null, profileFiles, null);
}
 
Example 2
Source File: LayersCheck.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testNoWarningsAboutOrderingForLoaders() {
    FileObject root = FileUtil.getConfigFile("Loaders");
    assertNotNull("Loader's root found", root);
    CharSequence log = Log.enable("org.openide.filesystems", Level.WARNING);

    Enumeration<? extends FileObject> en = root.getChildren(true);
    int cnt = 0;
    while (en.hasMoreElements()) {
        FileObject fo = en.nextElement();
        if (!fo.isFolder()) {
            continue;
        }
        FileUtil.getOrder(Arrays.asList(fo.getChildren()), true);
        cnt++;
    }
    if (cnt < 10) {
        fail("There shall be at least 10 files in loaders. Was: " + cnt);
    }

    String msg = log.toString();
    if (msg.contains(("Found same position"))) {
        fail("There shall be no same position loaders!\n" + msg);
    }
}
 
Example 3
Source File: AntBuildExtenderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    FileObject fo = FileUtil.getConfigFile("Services");
    if (fo != null) {
        fo.delete();
    }
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("proj");
    TestUtil.createFileFromContent(GeneratedFilesHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml");
    extension1 = TestUtil.createFileFromContent(GeneratedFilesHelperTest.class.getResource("data/extension1.xml"), projdir, "nbproject/extension1.xml");
    extenderImpl = new ExtImpl();
    MockLookup.setInstances(AntBasedTestUtil.testAntBasedProjectType(extenderImpl));
    pm = ProjectManager.getDefault();
    p = pm.findProject(projdir);
    extenderImpl.project = p;
    gfh = p.getLookup().lookup(GeneratedFilesHelper.class);
    assertNotNull(gfh);
}
 
Example 4
Source File: LocatorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFullFontsColorsLegacyLayout() throws Exception {
    String [] files = new String [] {
        "Editors/NetBeans/Defaults/defaultColoring.xml",
        "Editors/NetBeans/Defaults/coloring.xml",
        "Editors/NetBeans/Defaults/editorColoring.xml",
        "Editors/NetBeans/coloring.xml",
        "Editors/NetBeans/editorColoring.xml",
    };
    
    createOrderedFiles(files, FC_CONTENTS);
    
    FileObject baseFolder = FileUtil.getConfigFile("Editors");
    Map<String, List<Object []>> results = new HashMap<>();
    scan(ColoringStorage.ID, baseFolder, null, null, true, true, true, results);
    
    assertNotNull("Scan results should not null", results);
    assertEquals("Wrong number of profiles", 1, results.size());
    
    List<Object []> profileFiles = results.get("NetBeans");
    checkProfileFiles(files, null, profileFiles, "NetBeans");
}
 
Example 5
Source File: KeybindingStorageTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testWriteKeybindings() throws IOException {
    // Create new keybindings
    Map<Collection<KeyStroke>, MultiKeyBinding> newKeybindings = new HashMap<Collection<KeyStroke>, MultiKeyBinding>();
    MultiKeyBinding mkb = new MultiKeyBinding(Utilities.stringToKeys("D-D D"), "the-super-action");
    newKeybindings.put(mkb.getKeyStrokeList(), mkb);
    
    EditorSettingsStorage<Collection<KeyStroke>, MultiKeyBinding> ess = EditorSettingsStorage.<Collection<KeyStroke>, MultiKeyBinding>get(KeyMapsStorage.ID);
    ess.save(MimePath.EMPTY, "MyProfileXyz", false, newKeybindings);
    
    FileObject settingFile = FileUtil.getConfigFile("Editors/Keybindings/MyProfileXyz/org-netbeans-modules-editor-settings-CustomKeybindings.xml");
    assertNotNull("Can't find custom settingFile", settingFile);
    assertEquals("Wrong mime type", KeyMapsStorage.MIME_TYPE, settingFile.getMIMEType());
    
    // Force loading from the files
    StorageImpl<Collection<KeyStroke>, MultiKeyBinding> storage = new StorageImpl<Collection<KeyStroke>, MultiKeyBinding>(new KeyMapsStorage(), null);
    Map<Collection<KeyStroke>, MultiKeyBinding> keybindings = storage.load(MimePath.EMPTY, "MyProfileXyz", false); //NOI18N
    assertNotNull("Keybindings map should not be null", keybindings);
    assertEquals("Wrong number of keybindings", 1, keybindings.size());
    checkKeybinding(keybindings, "the-super-action", "D-D D");
}
 
Example 6
Source File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testOwnContextAction() throws Exception {
    MultiContext.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testOwnContext.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is action", obj instanceof Action);
    assertFalse("It is not context aware action: " + obj, obj instanceof ContextAwareAction);
    Action a = (Action)obj;

    InstanceContent ic = contextI;
    ic.add(10);

    assertEquals("Number lover!", a.getValue(Action.NAME));
    a.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 10, MultiContext.cnt);

    ic.remove(10);
    a.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, MultiContext.cnt);
}
 
Example 7
Source File: TemplateAttrProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String findLicenseByMavenProjectContent(MavenProject mp) {
    // try to match the project's license URL and the mavenLicenseURL attribute of license template
    FileObject licensesFO = FileUtil.getConfigFile("Templates/Licenses"); //NOI18N
    if (licensesFO == null) {
        return null;
    }
    FileObject[] licenseFiles = licensesFO.getChildren();
    for (License license : mp.getLicenses()) {
        String url = license.getUrl();
        if (url != null) {
            for (FileObject fo : licenseFiles) {
                String str = (String)fo.getAttribute("mavenLicenseURL"); //NOI18N
                if (str != null && Arrays.asList(str.split(" ")).contains(url)) {
                    if (fo.getName().startsWith("license-")) { // NOI18N
                        return fo.getName().substring("license-".length()); //NOI18N
                    } else {
                        Logger.getLogger(TemplateAttrProvider.class.getName()).log(Level.WARNING, "Bad license file name {0} (expected to start with ''license-'' prefix)", fo.getName());
                    }
                    break;
                }
            }
        }
    }
    return null;
}
 
Example 8
Source File: NbGlobalActionGoalProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream getActionDefinitionStream() {
    checkListener();
    FileObject fo = FileUtil.getConfigFile(FILE_NAME_PATH);
    resetCache.set(false);
    if (fo != null) {
        try {
            return fo.getInputStream();
        } catch (FileNotFoundException ex) {
            LOG.log(Level.FINE, "File not found: " + FileUtil.getFileDisplayName(fo), ex);
        }
    }
    return null;
}
 
Example 9
Source File: JFXProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Adds FX specific build script jfx-impl.xml to project build system
 * @param p
 * @param dirFO
 * @param type
 * @throws IOException 
 */
static void createJfxExtension(Project p, FileObject dirFO, WizardType type) throws IOException {
    FileObject templateFO = FileUtil.getConfigFile("Templates/JFX/jfx-impl.xml"); // NOI18N
    if (templateFO != null) {
        FileObject nbprojectFO = dirFO.getFileObject("nbproject"); // NOI18N
        FileObject jfxBuildFile = FileUtil.copyFile(templateFO, nbprojectFO, "jfx-impl"); // NOI18N
        if (type == JavaFXProjectWizardIterator.WizardType.SWING) {
            FileObject templatesFO = nbprojectFO.getFileObject("templates"); // NOI18N
            if (templatesFO == null) {
                templatesFO = nbprojectFO.createFolder("templates"); // NOI18N
            }
            FileObject swingTemplateFO1 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplate.html"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO1, templatesFO, "FXSwingTemplate"); // NOI18N
            }
            FileObject swingTemplateFO2 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplateApplet.jnlp"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO2, templatesFO, "FXSwingTemplateApplet"); // NOI18N
            }
            FileObject swingTemplateFO3 = FileUtil.getConfigFile("Templates/JFX/FXSwingTemplateApplication.jnlp"); // NOI18N
            if (swingTemplateFO1 != null) {
                FileUtil.copyFile(swingTemplateFO3, templatesFO, "FXSwingTemplateApplication"); // NOI18N
            }
        }
        JFXProjectUtils.addExtension(p);
    }
}
 
Example 10
Source File: Env.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** find an entity registration according to passed provider
 * @param provider provider file object
 * @return entity file object
 */
public static FileObject findEntityRegistration(FileObject provider) {
    String filename = provider.getPath();
    int i = filename.lastIndexOf('.');
    if (i != -1 && i > filename.lastIndexOf('/')) {
        filename = filename.substring(0, i);
    }
    String resource = xmlEntitiesPrefix +
        filename.substring(xmlLookupsPrefix.length(), filename.length());
    
    return FileUtil.getConfigFile(resource);
}
 
Example 11
Source File: WebProjectUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static FileObject createWelcomeFile(FileObject webFolder, Profile profile) throws IOException {
    FileObject template = profile != null && profile.isAtLeast(Profile.JAVA_EE_7_WEB) ?
            FileUtil.getConfigFile( "Templates/JSP_Servlet/Html.html" ) :
            FileUtil.getConfigFile( "Templates/JSP_Servlet/JSP.jsp" ); // NOI18N
    
    if (template == null) {
        return null; // Don't know the template
    }
    
    DataObject mt = DataObject.find(template);
    DataFolder webDf = DataFolder.findFolder(webFolder);
    return mt.createFromTemplate(webDf, "index").getPrimaryFile(); // NOI18N
}
 
Example 12
Source File: LibrariesCheck.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCheckLibrariesReal() throws Exception {
    StringBuilder errors = new StringBuilder();
    FileObject fo = FileUtil.getConfigFile("org-netbeans-api-project-libraries/Libraries");
    for (Object o : System.getProperties().keySet()) {
        String f = (String)o;
        if (f.startsWith("nblibraries.")) {
            String contents = System.getProperties().getProperty(f);
            f = f.substring("nblibraries.".length());
            FileObject l = fo.getFileObject(f);
            if (l == null) {
                if (f.endsWith("jaxb.xml") || f.endsWith("junit.xml") || f.endsWith("junit_4.xml") || f.endsWith("hamcrest.xml") || f.endsWith("junit_5.xml")) {
                    // this is a library defined in autoload module
                    // which is not enabled in ergonomic mode right now
                    continue;
                }
                errors.append("Missing library " + f + "\n");
                continue;
            }
            if (l.asText().equals(contents)) {
                Object n = l.getAttribute("displayName");
                String origN = System.getProperty("displayName.nblibraries." + l.getNameExt());
                if (origN == null || !origN.equals(n)) {
                    errors.append("Wrong name of " + l.getNameExt() + " old: " + origN + " new: " + n + "\n");
                }
                continue;
            }
            errors.append("Wrong library: "+ l.getNameExt() + "\n");
        }
    }

    if (errors.length() > 0) {
        fail(errors.toString());
    }
}
 
Example 13
Source File: AutomaticRegistration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static int list(String clusterDirValue) {
    // tell the infrastructure that the userdir is cluster dir
    System.setProperty("netbeans.user", clusterDirValue); // NOI18N

    // we could do this via registry, but the classspath would explode
    FileObject serverInstanceDir = FileUtil.getConfigFile("J2EE/InstalledServers"); // NOI18N

    if (serverInstanceDir == null) {
        LOGGER.log(Level.INFO, "The config/J2EE/InstalledServers folder does not exist."); // NOI18N
        return 2;
    }

    Pattern pattern = Pattern.compile(
            "^" + Pattern.quote(WLDeploymentFactory.URI_PREFIX) // NOI18N
            + "(.+):(.+):(.+):(.+)$"); // NOI18N

    for (FileObject f : serverInstanceDir.getChildren()) {
        String url = f.getAttribute(InstanceProperties.URL_ATTR).toString();
        if (url != null) {
            Matcher matcher = pattern.matcher(url);
            if (matcher.matches()) {
                System.out.println(matcher.group(3) + " " + matcher.group(4));
            }
        }
    }
    return 0;
}
 
Example 14
Source File: LibrariesStorageDeadlock167218Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    MockLookup.setInstances(
        new TestEntityCatalog(),
        new LibraryTypeRegistryImpl(),
        new LibrariesTestUtil.MockProjectManager());
    storageFolder = FileUtil.getConfigFile("org-netbeans-api-project-libraries/Libraries");
    assertNotNull("storageFolder found", storageFolder);
}
 
Example 15
Source File: ProductLibraryActionExtRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void registerActions() {
    final FileObject fileObj = FileUtil.getConfigFile("ProductLibraryActions");
    if (fileObj == null) {
        SystemUtils.LOG.warning("No ProductLibrary Action found.");
        return;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        ProductLibraryActionExtDescriptor actionExtDescriptor = null;
        try {
            actionExtDescriptor = createDescriptor(file);
        } catch (Exception e) {
            SystemUtils.LOG.severe(String.format("Failed to create ProductLibrary action from layer.xml path '%s'", file.getPath()));
        }
        if (actionExtDescriptor != null) {
            if(!actionExtDescriptor.isSeperator()) {
                final ProductLibraryActionExtDescriptor existingDescriptor = actionExtDescriptors.get(actionExtDescriptor.getId());
                if (existingDescriptor != null) {
                    SystemUtils.LOG.warning(String.format("ProductLibrary action [%s] has been redeclared!\n",
                            actionExtDescriptor.getId()));
                }
            }

            actionExtDescriptors.put(actionExtDescriptor.getId(), actionExtDescriptor);
            SystemUtils.LOG.fine(String.format("New ProductLibrary action added from layer.xml path '%s': %s",
                    file.getPath(), actionExtDescriptor.getId()));
        }
    }
}
 
Example 16
Source File: JBPluginProperties.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject getPropertiesFile() throws java.io.IOException {
    FileObject dir = FileUtil.getConfigFile("J2EE");
    FileObject retVal = null;
    if (null != dir) {
        retVal = dir.getFileObject("jb","properties"); // NOI18N
        if (null == retVal) {
            retVal = dir.createData("jb","properties"); //NOI18N
        }
    }
    return retVal;
}
 
Example 17
Source File: ClientSideProjectWizardIterator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void createIndexFile(FileObject siteRoot) throws IOException {
    FileObject indexTemplate = FileUtil.getConfigFile("Templates/Other/html.html"); // NOI18N
    DataFolder dataFolder = DataFolder.findFolder(siteRoot);
    DataObject dataIndex = DataObject.find(indexTemplate);
    dataIndex.createFromTemplate(dataFolder, "index"); // NOI18N
}
 
Example 18
Source File: RootNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void enableActionsOnExpand(ServerRegistry registry) {
    FileObject fo = FileUtil.getConfigFile(registry.getPath()+"/Actions"); // NOI18N
    Enumeration<String> en;
    if (fo != null) {
        for (FileObject o : fo.getChildren()) {
            en = o.getAttributes();
            while (en.hasMoreElements()) {
                String attr = en.nextElement();
                boolean enable = false;
                final String prefix = "property-"; // NOI18N
                if (attr.startsWith(prefix)) {
                    attr = attr.substring(prefix.length());
                    if (System.getProperty(attr) != null) {
                        enable = true;
                    }
                } else {
                    final String config = "config-"; // NOI18N
                    if (attr.startsWith(config)) {
                        attr = attr.substring(config.length());
                        FileObject configFile = FileUtil.getConfigFile(attr);
                        if (configFile != null) {
                            if (!configFile.isFolder() || configFile.getChildren().length > 0) {
                                enable = true;
                            }
                        }
                    }
                }

                if (enable) {
                    Lookup l = Lookups.forPath(registry.getPath()+"/Actions"); // NOI18N
                    for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
                        if (item.getId().contains(o.getName())) {
                            Action a = item.getInstance();
                            a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
                        }
                    }
                }
            }
        }
    }
}
 
Example 19
Source File: ValidateNbinstTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void implNbinstHost(TestHandler handler) throws ParserConfigurationException, IOException, IllegalArgumentException, SAXException {
        FileObject libs = FileUtil.getConfigFile("org-netbeans-api-project-libraries/Libraries");                
        if (libs != null) {
            final List<FileObject> schemas = new ArrayList<FileObject>(3);
            schemas.add(null);
            final FileObject schema2 = FileUtil.getConfigFile("ProjectXMLCatalog/library-declaration/2.xsd");
            if (schema2 != null) {
                schemas.add(schema2);
            }
            final FileObject schema3 = FileUtil.getConfigFile("ProjectXMLCatalog/library-declaration/3.xsd");
            if (schema3 != null) {
                schemas.add(schema3);
            }
next:       for (FileObject lib : libs.getChildren()) {
                SAXException lastException = null;
                for (FileObject schema : schemas) {
                    lastException = null;
                    try {
                        final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                        docBuilderFactory.setValidating(true);
                        if (schema != null) {
                            docBuilderFactory.setNamespaceAware(true);
                            docBuilderFactory.setAttribute(
                                "http://java.sun.com/xml/jaxp/properties/schemaLanguage",   //NOI18N
                                "http://www.w3.org/2001/XMLSchema");                        //NOI18N
                            docBuilderFactory.setAttribute(
                                "http://java.sun.com/xml/jaxp/properties/schemaSource",     //NOI18N
                                schema.toURI().toString());
                        }
                        final DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
                        builder.setErrorHandler(XMLUtil.defaultErrorHandler());
                        builder.setEntityResolver(EntityCatalog.getDefault());
                        Document doc = builder.parse(new InputSource(lib.toURL().toString()));
                        NodeList nl = doc.getElementsByTagName("resource");
                        for (int i = 0; i < nl.getLength(); i++) {
                            Element resource = (Element) nl.item(i);
                            validateNbinstURL(new URL(XMLUtil.findText(resource)), handler, lib);
                        }
                        continue next;
                    } catch (SAXException e) {
                        lastException = e;
                    }
                }
                throw lastException;
            }
        }
        for (FileObject f : NbCollections.iterable(FileUtil.getConfigRoot().getChildren(true))) {
            for (String attr : NbCollections.iterable(f.getAttributes())) {
                if (attr.equals("instanceCreate")) {
                    continue; // e.g. on Services/Hidden/org-netbeans-lib-jakarta_oro-antlibrary.instance prints stack trace
                }
                Object val = f.getAttribute(attr);
                if (val instanceof URL) {
                    validateNbinstURL((URL) val, handler, f);
                }
            }
        }
        assertNoErrors("No improper nbinst URLs", handler.errors());
    }
 
Example 20
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testReferenceWithoutPosition() throws Exception {
    FileObject fo = FileUtil.getConfigFile("Shortcuts/C-F2 D-A.shadow");
    assertNotNull(fo);
    assertEquals("Actions/eager/direct-two.instance", fo.getAttribute("originalFile"));
    assertEquals(null, fo.getAttribute("position"));
}