org.openide.filesystems.FileSystem Java Examples

The following examples show how to use org.openide.filesystems.FileSystem. 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: ToDoCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String getLoaderDisplayName(String mimeType) {
    FileSystem filesystem = null;
    try {
        filesystem = FileUtil.getConfigRoot().getFileSystem();
    } catch (FileStateInvalidException ex) {
        Exceptions.printStackTrace(ex);
    }
    FileObject factoriesFO = FileUtil.getConfigFile("Loaders/" + mimeType + "/Factories");  //NOI18N
    if (factoriesFO != null) {
        FileObject[] children = factoriesFO.getChildren();
        for (FileObject child : children) {
            String childName = child.getNameExt();
            String displayName = filesystem.getDecorator().annotateName(childName, Collections.singleton(child));
            if (!childName.equals(displayName)) {
                return displayName;
            }
        }
    }
    return null;
}
 
Example #2
Source File: AnnotatedNode.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
protected final void setFiles(final Set<FileObject> files) {
    fileSystemListeners = new HashSet<FileStatusListener>();
    this.files = files;
    if (files == null) {
        return;
    }
    Set<FileSystem> hookedFileSystems = new HashSet<FileSystem>();
    for (FileObject fo : files) {
        try {
            FileSystem fs = fo.getFileSystem();
            if (hookedFileSystems.contains(fs)) {
                continue;
            }
            hookedFileSystems.add(fs);
            FileStatusListener fsl = FileUtil.weakFileStatusListener(this, fs);
            fs.addFileStatusListener(fsl);
            fileSystemListeners.add(fsl);
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.annotate(e, "Cannot get " + fo + " filesystem, ignoring...");  // NOI18N
            err.notify(ErrorManager.INFORMATIONAL, e);
        }
    }
}
 
Example #3
Source File: TemplateWizardTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Does getIterator honours DataObject's cookies?
 */
public void testGetIteratorHonoursDataObjectsCookies () throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    DataObject obj;
    Loader l = Loader.findObject (Loader.class, true);
    try {
        AddLoaderManuallyHid.addRemoveLoader (l, true);
        obj = DataObject.find (fs.getRoot ());
    } finally {
        AddLoaderManuallyHid.addRemoveLoader (l, false);
    }
    
    TemplateWizard.Iterator it = TemplateWizard.getIterator (obj);
    
    assertEquals ("Iterator obtained from the object's cookie", obj, it);
}
 
Example #4
Source File: BuildContextVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form BuildVisualPanel1
 */
public BuildContextVisual(FileSystem fileSystem) {
    initComponents();

    this.fileSystem = fileSystem;
    DefaultDocumentListener listener = new DefaultDocumentListener();
    buildContextTextField.getDocument().addDocumentListener(listener);
    ((JTextComponent) repositoryComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(listener);
    tagTextField.getDocument().addDocumentListener(listener);

    repositoryComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeSupport.fireChange();
        }
    });

    //UiUtils.loadRepositories(instance, repositoryComboBox);
}
 
Example #5
Source File: FolderLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tests delegation stuff.
 */
public void testProxyLookups () throws Exception {
    String fsstruct [] = new String [] {
        "AA/",
    };

    TestUtilHid.destroyLocalFileSystem (getName());
    FileSystem lfs = TestUtilHid.createLocalFileSystem (getWorkDir(), fsstruct);

    FileObject bb = lfs.findResource("/AA");

    DataFolder folder = DataFolder.findFolder (bb);


    Lookup lookup = new org.openide.loaders.FolderLookup (folder).getLookup ();
    addListener(lookup);

    InstanceDataObject obj = InstanceDataObject.create (folder, null, ALkp.class);
    if (lookup.lookup (Integer.class) == null) {
        fail ("Integer not found in delegating lookup");
    }

}
 
Example #6
Source File: MavenGroovyExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isActive() {
    final Boolean[] retValue = new Boolean[1];
    retValue[0] = false;
    try {
        pom.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
            @Override
            public void run() throws IOException {
                Utilities.performPOMModelOperations(pom, Collections.singletonList(new ModelOperation<POMModel>() {

                    @Override
                    public void performOperation(POMModel model) {
                        if (ModelUtils.hasModelDependency(model, MavenConstants.GROOVY_GROUP_ID, MavenConstants.GROOVY_ARTIFACT_ID)) {
                            retValue[0] = true;
                        } else {
                            retValue[0] = false;
                        }
                    }
                }));
            }
        });
    } catch (IOException ex) {
        return retValue[0];
    }
    return retValue[0];
}
 
Example #7
Source File: DataEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** The time when the data has been modified
*/
public Date getTime() {
    // #32777 - refresh file object and return always the actual time
    action = new FileSystem.AtomicAction() {
        public void run() throws IOException {
            getFileImpl().refresh(false);
        }
    };
    try {
        getFileImpl().getFileSystem().runAtomicAction(action);
    } catch (IOException ex) {
        //Nothing to do here
    }
    
    return getFileImpl ().lastModified ();
}
 
Example #8
Source File: WritableXMLFileSystemTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRename() throws Exception {
    Layer l = new Layer("    <folder name=\"folder1\">\n        <file name=\"file1.txt\">\n            <attr name=\"a\" stringvalue=\"v\"/>\n        </file>\n    </folder>\n");
    FileSystem fs = l.read();
    FileObject f = fs.findResource("folder1");
    assertNotNull(f);
    FileLock lock = f.lock();
    f.rename(lock, "folder2", null);
    lock.releaseLock();
    f = fs.findResource("folder2/file1.txt");
    assertNotNull(f);
    lock = f.lock();
    f.rename(lock, "file2.txt", null);
    lock.releaseLock();
    assertEquals("#63989: correct rename handling", "    <folder name=\"folder2\">\n        <file name=\"file2.txt\">\n            <attr name=\"a\" stringvalue=\"v\"/>\n        </file>\n    </folder>\n", l.write());
    // XXX should any associated ordering attrs also be renamed? might be pleasant...
}
 
Example #9
Source File: DecoratedFileSystem.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void run () {
    Lookup l = consumerVisualVM ();
    try {
        Class.forName ("org.netbeans.modules.consumervisualvm.api.PluginInfo");
    } catch (ClassNotFoundException ex) {
        // XXX: why ClassNotFoundException sometime?
        LOG.log (Level.FINE, ex.getLocalizedMessage (), ex);
        return;
    }
    Lookup.Result<PluginInfo> result = l.lookupResult (PluginInfo.class);

    List<XMLFileSystem> delegate = new ArrayList<XMLFileSystem> ();
    for (PluginInfo pi : result.allInstances ()) {
        Internal internal = PluginInfoAccessor.DEFAULT.getInternal (pi);
        if (! internal.isEnabled ()) {
            delegate.add (internal.getXMLFileSystem ());
        }
    }
    setDelegates (delegate.toArray (new FileSystem[0]));
}
 
Example #10
Source File: PageFlowController.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Unregister any listeners.
 */
public void unregisterListeners() {

    if (pcl != null) {
        if (configModel != null) {
            configModel.removePropertyChangeListener(pcl);
        }
        pcl = null;
    }

    FileObject myWebFolder = getWebFolder();
    if (fcl != null && myWebFolder != null) {
        try {
            FileSystem fileSystem = myWebFolder.getFileSystem();
            fileSystem.removeFileChangeListener(fcl);
            fcl = null;
        } catch (FileStateInvalidException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example #11
Source File: MavenGroovyExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean activate() {
    try {
        pom.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
            @Override
            public void run() throws IOException {
                List<ModelOperation<POMModel>> operations = new ArrayList<ModelOperation<POMModel>>();
                operations.add(new AddGroovyDependency());
                operations.add(new AddMavenCompilerPlugin());
                operations.add(new AddGroovyEclipseCompiler());
                Utilities.performPOMModelOperations(pom, operations);
            }
        });
    } catch (IOException ex) {
        return false;
    }
    return true;
}
 
Example #12
Source File: MultiModuleNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
private static Pair<FileSystem,Set<? extends FileObject>> findAnnotableFiles(Collection<? extends FileObject> fos) {
    FileSystem fs = null;
    final Set<FileObject> toAnnotate = new HashSet<>();
    for (FileObject fo : fos) {
        try {
            FileSystem tmp = fo.getFileSystem();
            if (fs == null) {
                fs = tmp;
                toAnnotate.add(fo);
            } else if (fs.equals(tmp)) {
                toAnnotate.add(fo);
            }
        } catch (FileStateInvalidException e) {
        LOG.log(
            Level.WARNING,
            "Cannot determine annotations for invalid file: {0}",   //NOI18N
            FileUtil.getFileDisplayName(fo));
        }
    }
    return fs == null ?
            null :
            Pair.of(fs, toAnnotate);
}
 
Example #13
Source File: PhpDeleteRefactoringUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void doRefactoringBypass() throws IOException {
    RP.post(new Runnable() {

        @Override
        public void run() {
            try {
                // #172199
                FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
                    @Override
                    public void run() throws IOException {
                        file.delete();
                    }
                });
            } catch (IOException ex) {
                LOGGER.log(Level.SEVERE, null, ex);
            }
        }

    });
}
 
Example #14
Source File: DataLoaderGetActionsCompatibilityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the testing environment by creating testing folders
 * on the system file system.
 */
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    MockLookup.setInstances(
            new Repository(TestUtilHid.createLocalFileSystem(getWorkDir(), new String[0])),
            new Pool());
    
    MyDL loader = MyDL.getLoader(MyDL.class);

    FileSystem dfs = FileUtil.getConfigRoot().getFileSystem();
    dfs.refresh (true);        
    
    FileObject fo = FileUtil.createData (dfs.getRoot (), "a.txt");
    obj = DataObject.find (fo);
    
    assertEquals ("The correct loader", loader, obj.getLoader ());
    
    node = obj.getNodeDelegate ();    
    
    sfs = new PCL ();
    dfs.addFileChangeListener (sfs);
}
 
Example #15
Source File: SourceURLMapper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static FileObject find(URL url) {
    if (!Source.URL_PROTOCOL.equals(url.getProtocol())) {
        return null;
    }
    Matcher m = HOST.matcher(url.getHost());
    if (!m.matches()) {
        return null;
    }
    Reference<FileSystem> r;
    synchronized (filesystems) {
        r = filesystems.get(Long.parseLong(m.group(1)));
    }
    if (r == null) {
        return null;
    }
    FileSystem fs = r.get();
    if (fs == null) {
        return null;
    }
    String path = url.getPath().substring(1);
    path = percentDecode(path);
    return fs.findResource(path);
}
 
Example #16
Source File: WebAppParseSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static WebAppParseProxy create(JspParserImpl jspParser, WebModule wm) {
    WebAppParseSupport instance = new WebAppParseSupport(jspParser, wm);

    // register file listener (listen to changes of tld files, web.xml)
    try {
        FileSystem fs = wm.getDocumentBase().getFileSystem();
        fs.addFileChangeListener(FileUtil.weakFileChangeListener(instance.fileSystemListener, fs));
    } catch (FileStateInvalidException ex) {
        LOG.log(Level.INFO, null, ex);
    }

    // register weak class path listeners
    if (instance.wmRoot != null) { // in fact should not happen, see #154892 for more information
        ClassPath compileCP = ClassPath.getClassPath(instance.wmRoot, ClassPath.COMPILE);
        if (compileCP != null) {
            compileCP.addPropertyChangeListener(WeakListeners.propertyChange(instance, compileCP));
        }
        ClassPath executeCP = ClassPath.getClassPath(instance.wmRoot, ClassPath.EXECUTE);
        if (executeCP != null) {
            executeCP.addPropertyChangeListener(WeakListeners.propertyChange(instance, executeCP));
        }
    }

    return instance;
}
 
Example #17
Source File: DataFolderIndexTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIndexCookieOfferedOnlyWhenAppropriate() throws Exception {
    Node n = df.getNodeDelegate();
    assertNotNull("have an index cookie on SFS", n.getLookup().lookup(Index.class));
    LocalFileSystem lfs = new LocalFileSystem();
    lfs.setRootDirectory(getWorkDir());
    n = DataFolder.findFolder(lfs.getRoot()).getNodeDelegate();
    assertNull("have no index cookie on a local folder", n.getLookup().lookup(Index.class));
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject x = fs.getRoot().createFolder("x");
    FileObject y = fs.getRoot().createFolder("y");
    y.setAttribute("DataFolder.Index.reorderable", Boolean.TRUE);
    n = DataFolder.findFolder(x).getNodeDelegate();
    assertNull("have no index cookie on a random folder in a random FS", n.getLookup().lookup(Index.class));
    n = DataFolder.findFolder(y).getNodeDelegate();
    assertNotNull("do have index cookie if magic attr is set", n.getLookup().lookup(Index.class));
}
 
Example #18
Source File: WSUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void removeImplClass(Project project, String implClass) {
    Sources sources = project.getLookup().lookup(Sources.class);
    String resource = implClass.replace('.','/')+".java"; //NOI18N
    if (sources!=null) {
        SourceGroup[] srcGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i=0;i<srcGroup.length;i++) {
            final FileObject srcRoot = srcGroup[i].getRootFolder();
            final FileObject implClassFo = srcRoot.getFileObject(resource);
            if (implClassFo!=null) {
                try {
                    FileSystem fs = implClassFo.getFileSystem();
                    fs.runAtomicAction(new AtomicAction() {
                        public void run() {
                            deleteFile(implClassFo);
                        }
                    });
                } catch (IOException ex) {
                    ErrorManager.getDefault().notify(ex);
                }
                return;
            }
        }
    }
}
 
Example #19
Source File: EnablePreviewMavenProj.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeInfo implement() throws Exception {

    try {

        final FileObject pom = prj.getProjectDirectory().getFileObject("pom.xml"); // NOI18N
        pom.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
            @Override
            public void run() throws IOException {
                List<ModelOperation<POMModel>> operations = new ArrayList<ModelOperation<POMModel>>();
                operations.add(new AddMvnCompilerPluginForEnablePreview());
                org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(pom, operations);
            }
        });

    } catch (IOException ex) {
    }
    ProjectConfiguration cfg = prj.getLookup().lookup(ProjectConfigurationProvider.class).getActiveConfiguration();

    for (String action : new String[]{"run", "debug", "profile"}) { // NOI18N

        NetbeansActionMapping mapp = ModelHandle2.getMapping(action, prj, cfg);
        Map<String, String> properties = mapp.getProperties();

        for (Entry<String, String> entry : properties.entrySet()) {
            if (entry.getKey().equals("exec.args")) { // NOI18Nl
                if (!entry.getValue().contains(ENABLE_PREVIEW_FLAG + " ")) {
                    properties.put(entry.getKey(), ENABLE_PREVIEW_FLAG + " " + entry.getValue());
                }
            }
        }
        if (mapp != null) {
            ModelHandle2.putMapping(mapp, prj, cfg);
        }

    }

    return null;
}
 
Example #20
Source File: FileStateManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void define (final FileObject mfo, int layer, boolean revert) throws IOException {
    // ignore request when file is already defined on layer
    if (FSTATE_DEFINED == getFileState (mfo, layer))
        return;

    FileSystem fsLayer = getLayer (layer);
    if (fsLayer == null)
        throw new IllegalArgumentException ("Invalid layer " + layer); //NOI18N

    // find file on specified layer
    FileObject fo = fsLayer.findResource (mfo.getPath());
    
    // remove the file if it exists and current definition should be preserved
    if (fo != null && !revert) {
        deleteImpl (mfo, fsLayer);
        fo = null;
    }

    // create file on specified layer if it doesn't exist
    if (fo == null) {
        String parent = mfo.getParent ().getPath();
        final FileObject fparent = FileUtil.createFolder (fsLayer.getRoot (), parent);
        fparent.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
            public void run () throws IOException {
                mfo.copy (fparent, mfo.getName (), mfo.getExt ());
            }
        });
    }

    // remove above defined files
    for (int i = 0; i < layer; i++) {
        FileSystem fsl = getLayer (i);
        if (fsl != null)
            deleteImpl (mfo, fsl);
    }
}
 
Example #21
Source File: DataShadowTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFindOriginalFromAnonymousFilesystemToSFS() throws Exception {
    // Useful for dynamically injecting action registrations.
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject shadow = FileUtil.createData(fs.getRoot(), "link.shadow");
    shadow.setAttribute("originalFile", getName() + "/folder/original.txt");
    assertEquals("found the right original file", original, DataShadow.deserialize(shadow));
    assertEquals("found the right original URL", original.getPrimaryFile().getURL(), DataShadow.readURL(shadow));
}
 
Example #22
Source File: BIEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void detachStatusListeners() {
    Iterator<Map.Entry<FileSystem, FileStatusListener>> iter = fsToStatusListener.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<FileSystem, FileStatusListener> entry = iter.next();
        FileSystem fs = entry.getKey();
        FileStatusListener fsl = entry.getValue();
        fs.removeFileStatusListener(fsl);
    }
    fsToStatusListener.clear();
}
 
Example #23
Source File: NbClassPathCompat.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Method to obtain class path for the current state of the repository.
* The classpath should be scanned for all occured exception caused
* by file systems that cannot be converted to class path by a call to
* method getExceptions().
*
*
* @param cap the capability that must be satisfied by the file system
*    added to the class path
* @return class path for all reachable systems in the repository
* @deprecated Please use the <a href="@org-netbeans-api-java-classpath@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead.
*/
@Deprecated
public static NbClassPath createRepositoryPath (FileSystemCapability cap) {
    Thread.dumpStack();
    final LinkedList res = new LinkedList ();


    final class Env extends FileSystem$Environment {
        /* method of interface Environment */
        public void addClassPath(String element) {
            res.add (element);
        }
    }


    Env env = new Env ();
    Enumeration<? extends FileSystem> en = cap.fileSystems();
    while (en.hasMoreElements ()) {
        try {
            FileSystem fs = en.nextElement();
            FileSystemCompat.compat(fs).prepareEnvironment((FileSystem$Environment)env);
        } catch (EnvironmentNotSupportedException ex) {
            // store the exception
            res.add (ex);
        }
    }

    // return it
    return new NbClassPath (res.toArray ());
}
 
Example #24
Source File: TestAnnotationProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void init() {
    Set filesystems = getRootFilesystems();
    for (Iterator i = filesystems.iterator(); i.hasNext();) {
        FileSystem fileSystem = (FileSystem) i.next();
        fileSystem.addFileChangeListener(interceptor);
    }
    events.clear();
}
 
Example #25
Source File: LayoutIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run(FileSystem layer) throws IOException {
    FileObject folder = layer.getRoot().getFileObject("Actions/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Actions/Window"); // NOI18N
    }
    String instance = packageName.replace('.','-') + "-" + name; // NOI18N
    FileObject file = folder.createData(instance, "instance"); // NOI18N
    folder = layer.getRoot().getFileObject("Menu/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Menu/Window"); // NOI18N
    }
    file = folder.createData(name, "shadow"); // NOI18N
    file.setAttribute("originalFile", "Actions/Window/" + instance + ".instance"); // NOI18N
}
 
Example #26
Source File: DiskFileKey.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object o) {
    if (this == o) return true;

    if (o instanceof DiskFileKey) {

        DiskFileKey key = (DiskFileKey) o;

        if (hashCode != key.hashCode) return false;
        FileObject fo2 = key.fileObject;
        FileObject fo = fileObject;

        if (fo == fo2) return true;

        try {
            FileSystem fs = fo.getFileSystem();
            FileSystem fs2 = fo2.getFileSystem();
            if (fs.equals(fs2)) {
                return fo.equals(fo2);
            } else {
                // fallback use absolute paths (cache them)
                if (absolutePath == null) {
                    File f = FileUtil.toFile(fo);
                    absolutePath = f.getAbsolutePath();
                }
                if (key.absolutePath == null) {
                    File f2 = FileUtil.toFile(fo2);
                    key.absolutePath = f2.getAbsolutePath();
                }
                return absolutePath.equals(key.absolutePath);
            }
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.notify(e);
        }
    }
    return false;
}
 
Example #27
Source File: SetupUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileSystem[] computeDelegates() {
    List<FileSystem> arr = new ArrayList<FileSystem>();
    arr.add(MEMORY);
    arr.add(layers);
    arr.add(configRoot);
    arr.addAll(ALL.allInstances());
    return arr.toArray(new FileSystem[0]);
}
 
Example #28
Source File: IDEInitializer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Set the global default lookup with the specified content.
 *
 * @param layers xml-layer URLs to be present in the system filesystem.
 * @param instances object instances to be present in the default lookup.
 */
public static void setup (
    String[] layers, 
    Object[] instances
) {
    ClassLoader classLoader = IDEInitializer.class.getClassLoader ();
    File workDir = new File (Manager.getWorkDirPath ());
    URL[] urls = new URL [layers.length];
    int i, k = urls.length;
    for (i = 0; i < k; i++)
        urls [i] = classLoader.getResource (layers [i]);

    // 1) create repository
    XMLFileSystem systemFS = new XMLFileSystem ();
    lfs = FileUtil.createMemoryFileSystem();
    try {
        systemFS.setXmlUrls (urls);
    } catch (Exception ex) {
        ex.printStackTrace ();
    }
    MyFileSystem myFileSystem = new MyFileSystem (
        new FileSystem [] {lfs, systemFS}
    );
    Repository repository = new Repository (myFileSystem);

    Object[] lookupContent = new Object [instances.length + 1];
    lookupContent [0] = repository;
    System.arraycopy (instances, 0, lookupContent, 1, instances.length);
    
    DEFAULT_LOOKUP.setLookups (new Lookup[] {
        Lookups.fixed (lookupContent),
        Lookups.metaInfServices (classLoader),
        Lookups.singleton (classLoader),
    });
    Assert.assertTrue (myFileSystem.isDefault());
}
 
Example #29
Source File: IDEInitializer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MyFileSystem (FileSystem[] fileSystems) {
    super (fileSystems);
    try {
        setSystemName ("TestFS");
    } catch (PropertyVetoException ex) {
        ex.printStackTrace();
    }
}
 
Example #30
Source File: WritableXMLFileSystemTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateNewFolder() throws Exception {
    Layer l = new Layer("");
    FileSystem fs = l.read();
    FileObject x = fs.getRoot().createFolder("x");
    assertEquals("in-memory write worked", 1, fs.getRoot().getChildren().length);
    assertEquals("wrote correct content for top-level folder", "    <folder name=\"x\"/>\n", l.write());
    x.createFolder("y");
    assertEquals("wrote correct content for 2nd-level folder", "    <folder name=\"x\">\n        <folder name=\"y\"/>\n    </folder>\n", l.write());
    l = new Layer("    <folder name=\"original\"/>\n");
    fs = l.read();
    fs.getRoot().createFolder("aardvark");
    fs.getRoot().createFolder("xyzzy");
    assertEquals("alphabetized new folders", "    <folder name=\"aardvark\"/>\n    <folder name=\"original\"/>\n    <folder name=\"xyzzy\"/>\n", l.write());
}