Java Code Examples for org.openide.filesystems.XMLFileSystem

The following examples show how to use org.openide.filesystems.XMLFileSystem. These examples are extracted from open source projects. 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 Project: netbeans   Source File: ActionUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    dir = FileUtil.toFileObject(getWorkDir());
    f1 = dir.createData("f1.data");
    f1form = dir.createData("f1.form");
    f2 = dir.createData("f2");
    subdir = dir.createFolder("sub");
    f3 = subdir.createData("f3.data");
    f3a = subdir.createData("f3a.data");
    subdir2 = dir.createFolder("subdir2");
    f4 = subdir2.createData("f3.nondata");
    subsubdir = subdir2.createFolder("sub");
    f5 = subdir2.createData("f1.data");
    f5a = subsubdir.createData("f3.data");
    fx = new XMLFileSystem().getRoot();
    d1 = DataObject.find(f1);
    d2 = DataObject.find(f2);
    d3 = DataObject.find(f3);
    dx = DataObject.find(fx);
    n1 = d1.getNodeDelegate();
    n2 = d2.getNodeDelegate();
    n3 = d3.getNodeDelegate();
    nx = dx.getNodeDelegate();
}
 
Example 2
Source Project: netbeans   Source File: LayerCacheManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FileSystem load(FileSystem previous, ByteBuffer bb) throws IOException {
    byte[] arr = new byte[bb.limit()];
    bb.get(arr);
    DataInputStream is = new DataInputStream(new ByteArrayInputStream(arr));
    List<URL> urls = new ArrayList<URL>();
    while (is.available() > 0) {
        String u = is.readUTF();
        urls.add(new URL(u));
    }
    try {
        XMLFileSystem fs = (XMLFileSystem)previous;
        fs.setXmlUrls(urls.toArray(new URL[urls.size()]));
        return fs;
    } catch (PropertyVetoException pve) {
        throw (IOException) new IOException(pve.toString()).initCause(pve);
    }
}
 
Example 3
Source Project: netbeans   Source File: MenuBarTest.java    License: Apache License 2.0 6 votes vote down vote up
private void doActionIsCreatedOnlyOnce_13195(String name) throws Exception {
    // crate XML FS from data
    String[] stringLayers = new String [] { "/org/openide/awt/data/testActionOnlyOnce.xml" };
    URL[] layers = new URL[stringLayers.length];

    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }

    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);

    // build menu
    DataFolder dataFolder = DataFolder.findFolder(system.findResource(name));
    MenuBar menuBar = new MenuBar(dataFolder);
    menuBar.waitFinished();

    if (CreateOnlyOnceAction.instancesCount != 1) {
        // ensure that only one instance of action was created
        fail("Action created only once, but was: " + CreateOnlyOnceAction.instancesCount + "\n" + CreateOnlyOnceAction.w);
    }
}
 
Example 4
Source Project: netbeans   Source File: IDEInitializer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add layers to system filesystem.
 *
 * @param layers xml-layer URLs to be present in the system filesystem.
 *
 */
public static void addLayers (String[] layers) {
    ClassLoader classLoader = IDEInitializer.class.getClassLoader ();
    URL[] urls = new URL [layers.length];
    int i, k = urls.length;
    for (i = 0; i < k; i++) {
        urls [i] = classLoader.getResource (layers [i]);
    }

    systemFS = new XMLFileSystem ();
    try {
        systemFS.setXmlUrls (urls);
    } catch (Exception ex) {
        ex.printStackTrace ();
    }
    MainLookup.register(systemFS);
}
 
Example 5
Source Project: netbeans   Source File: UnitTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void prepareTest (String[] stringLayers, Lookup lkp) 
            throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[stringLayers.length];
    
    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    
    Repository repository = new Repository(system);
    
    if (lkp == null) {
        UnitTestUtils.setLookup(new Object[] { repository }, UnitTestUtils.class.getClassLoader());
    } else {
        UnitTestUtils.setLookup(new Object[] { repository }, lkp, UnitTestUtils.class.getClassLoader());
    }
}
 
Example 6
Source Project: netbeans   Source File: LayerUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testXMLMultiFS() throws Exception {
    clearWorkDir();
    // b-layer.xml overrides a-layer.xml now and then:
    List<File> files = new ArrayList<File>(Arrays.asList(
            new File(getDataDir(), "layers/b-layer.xml"),
            new File(getDataDir(), "layers/a-layer.xml")
            ));

    FileSystem xfs0 = new XMLFileSystem(Utilities.toURI(files.get(0)).toURL());
    FileSystem xfs1 = new XMLFileSystem(Utilities.toURI(files.get(1)).toURL());
    FileSystem mfs = new MultiFileSystem(xfs0, xfs1);
    assertNotNull(xfs1.findResource("Menu/A Folder"));
    assertNotNull(mfs.findResource("Menu/File"));
    assertNotNull(mfs.findResource("Menu/A Folder"));
    assertNull(mfs.findResource("Menu/A Folder/org-example-a-AAction.shadow"));  // hidden by b-layer
    FileObject mf = mfs.findResource("Actions/File");
    assertEquals(2, mf.getChildren().length);
    FileObject ba = mfs.findResource("Actions/File/org-example-b-BAction.instance");
    assertEquals("BBBBB", ba.getAttribute("displayName"));
    FileObject aa = mfs.findResource("Actions/File/org-example-a-AAction.instance");
    assertEquals("AAAA", aa.getAttribute("displayName"));
}
 
Example 7
Source Project: netbeans   Source File: LayerUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMixedMultiFS() throws Exception {
    clearWorkDir();
    LayerCacheManager m = LayerCacheManager.manager(true);
    // b-layer.xml overrides a-layer.xml now and then:
    File lb = new File(getDataDir(), "layers/b-layer.xml");
    File la = new File(getDataDir(), "layers/a-layer.xml");

    FileSystem cfs = createCachedFS(m, lb);
    FileSystem xfs = new XMLFileSystem(Utilities.toURI(la).toURL());
    FileSystem mfs = new MultiFileSystem(cfs, xfs);
    assertNotNull(mfs.findResource("Menu/File"));
    assertNotNull(mfs.findResource("Menu/A Folder"));
    assertNull(mfs.findResource("Menu/A Folder/org-example-a-AAction.shadow"));  // hidden by b-layer
    FileObject mf = mfs.findResource("Actions/File");
    assertEquals(2, mf.getChildren().length);
    FileObject ba = mfs.findResource("Actions/File/org-example-b-BAction.instance");
    assertEquals("BBBBB", ba.getAttribute("displayName"));
    FileObject aa = mfs.findResource("Actions/File/org-example-a-AAction.instance");
    assertEquals("AAAA", aa.getAttribute("displayName"));
}
 
Example 8
Source Project: netbeans   Source File: MavenNbModuleImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override public FileSystem getEffectiveSystemFilesystem() throws IOException {
    FileSystem projectLayer = LayerHandle.forProject(project).layer(false);
    Collection<FileSystem> platformLayers = new ArrayList<FileSystem>();
    PlatformJarProvider pjp = project.getLookup().lookup(PlatformJarProvider.class);
    if (pjp != null) {
        List<URL> urls = new ArrayList<URL>();
        for (File jar : pjp.getPlatformJars()) {
            // XXX use LayerHandle.forProject on this and sister modules instead
            urls.addAll(LayerUtil.layersOf(jar));
        }
        XMLFileSystem xmlfs = new XMLFileSystem();
        try {
            xmlfs.setXmlUrls(urls.toArray(new URL[urls.size()]));
        } catch (PropertyVetoException x) {
            throw new IOException(x);
        }
        platformLayers.add(xmlfs);
    }
    // XXX would using PlatformLayersCacheManager be beneficial? (would need to modify in several ways)
    return LayerUtil.mergeFilesystems(projectLayer, platformLayers);
}
 
Example 9
Source Project: netbeans   Source File: RepositoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static FileSystem createDefFs() {
    try
    {
        FileSystem writeFs = FileUtil.createMemoryFileSystem();
        FileSystem profilerLayer = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource(
                "org/netbeans/modules/profiler/j2ee/mf-layer.xml"));
        FileSystem layerJ2eeDeployment = new XMLFileSystem(RepositoryImpl.class.getClassLoader().
                getResource("org/netbeans/modules/j2ee/deployment/impl/layer.xml"));
        FileSystem layerTomcat = new XMLFileSystem(RepositoryImpl.class.getClassLoader().
                getResource("org/netbeans/modules/tomcat5/resources/layer.xml"));
        FileSystem layerJBoss = new XMLFileSystem(RepositoryImpl.class.getClassLoader().
                getResource("org/netbeans/modules/j2ee/jboss4/resources/layer.xml"));
        return new MultiFileSystem(new FileSystem[] {writeFs, profilerLayer, layerJ2eeDeployment,
                layerTomcat , layerJBoss });
    } catch (SAXException e) {
        AssertionError ae = new AssertionError(e.getMessage());
        ae.initCause(e);
        throw ae;
    }
}
 
Example 10
Source Project: netbeans   Source File: BaseCaretTest.java    License: Apache License 2.0 6 votes vote down vote up
public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
    Collection<URL> allUrls = new ArrayList<URL>();
    for (String u : additionalLayers) {
        if (u.charAt(0) == '/') {
            u = u.substring(1);
        }
        for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(u); en.hasMoreElements(); ) {
            allUrls.add(en.nextElement());
        }
    }
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(allUrls.toArray(new URL[allUrls.size()]));
    
    Repository repository = new Repository(system);
    Object[] lookupContent = new Object[additionalLookupContent.length + 1];
    
    System.arraycopy(additionalLookupContent, 0, lookupContent, 1, additionalLookupContent.length);
    
    lookupContent[0] = repository;
    
    setLookup(lookupContent, BaseCaretTest.class.getClassLoader());
}
 
Example 11
Source Project: netbeans   Source File: UnitTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void prepareTest (String[] stringLayers, Lookup lkp) 
            throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[stringLayers.length];
    
    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    
    Repository repository = new Repository(system);
    
    if (lkp == null) {
        DEFAULT_LOOKUP.setLookup(new Object[] { repository }, UnitTestUtils.class.getClassLoader());
    } else {
        DEFAULT_LOOKUP.setLookup(new Object[] { repository }, lkp, UnitTestUtils.class.getClassLoader());
    }
}
 
Example 12
Source Project: netbeans   Source File: RepositoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static FileSystem createDefFs() {
    try
    {
        FileSystem writeFs = FileUtil.createMemoryFileSystem();
        FileSystem htmlFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/html/mf-layer.xml"));
        FileSystem htmlEditotFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/html/editor/resources/layer.xml"));
        FileSystem htmlEditorLibFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/html/editor/resources/layer.xml"));
        FileSystem lexerLayerFS = new XMLFileSystem(HTMLTokenId.class.getClassLoader().getResource("org/netbeans/lib/html/lexer/layer.xml"));
        FileSystem cssEditorFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/css/resources/layer.xml"));
        FileSystem jsEditorFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/javascript/editing/layer.xml"));
        return new MultiFileSystem(new FileSystem[] { writeFs, lexerLayerFS, htmlFs, 
                                                      htmlEditotFs, htmlEditorLibFs,
                                                      cssEditorFs, jsEditorFs});
    } catch (SAXException e) {
        return null;
    }
}
 
Example 13
Source Project: visualvm   Source File: DecoratedFileSystem.java    License: 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 14
Source Project: netbeans   Source File: RepositoryImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static FileSystem[] createFileSystems() {
    try {
        FileSystem writeFs = FileUtil.createMemoryFileSystem();
        FileSystem utilitiesFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("layer.xml"));
        FileSystem j2eeserverFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/j2ee/deployment/impl/layer.xml"));
        FileSystem javaProjectFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/java/project/layer.xml"));
        return new FileSystem[] { writeFs, utilitiesFs, j2eeserverFs, javaProjectFs };
    } catch (SAXException e) {
        AssertionError ae = new AssertionError(e.getMessage());
        ae.initCause(e);
        throw ae;
    }
}
 
Example 15
Source Project: netbeans   Source File: AutomaticExtraClasspathTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    URL u = getClass().getResource("AutomaticExtraClasspathTest.xml");
    FileSystem fs = new XMLFileSystem(u);
    fo = fs.findResource("testAutoProvider");
    assertNotNull("There is the resource", fo);
    bad = fs.findResource("brokenURL");
    assertNotNull("There is the bad", bad);
}
 
Example 16
Source Project: netbeans   Source File: EditorTestLookup.java    License: Apache License 2.0 5 votes vote down vote up
public static void setLookup(URL[] layers, File workDir, Object[] instances, ClassLoader cl, Class [] exclude)
throws IOException, PropertyVetoException {
    FileSystem writeableFs = createLocalFileSystem(workDir, new String[0]);
    XMLFileSystem layersFs = new XMLFileSystem();
    layersFs.setXmlUrls(layers);
    
    setLookup(new FileSystem [] { writeableFs, layersFs }, instances, cl, exclude);
}
 
Example 17
Source Project: netbeans   Source File: EditorTestLookup.java    License: Apache License 2.0 5 votes vote down vote up
public static void setLookup(URL[] layers, File workDir, Object[] instances, ClassLoader cl, Class [] exclude)
throws IOException, PropertyVetoException {
    FileSystem writeableFs = createLocalFileSystem(workDir, new String[0]);
    XMLFileSystem layersFs = new XMLFileSystem();
    layersFs.setXmlUrls(layers);
    
    setLookup(new FileSystem [] { writeableFs, layersFs }, instances, cl, exclude);
}
 
Example 18
Source Project: netbeans   Source File: NbRepositoryClasspathTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * #129583: XML layers from classpath modules should always be loaded.
 */
public void testNbRepositoryInitializedFromClasspath() throws Exception {
    MockLookup.setInstances();
    final String PATH = "Services/MIMEResolver/org-netbeans-core-startup-layers-SystemFileSystem-Extension.xml";
    assertNotNull(FileUtil.getConfigFile(PATH));
    MockLookup.setInstances(new XMLFileSystem()); // #200848
    assertNotNull(FileUtil.getConfigFile(PATH));
}
 
Example 19
Source Project: netbeans   Source File: MenuBarCNFETest.java    License: Apache License 2.0 5 votes vote down vote up
public void testALotOfClassNotFoundExceptions() throws Exception {
    // crate XML FS from data
    String[] stringLayers = new String [] { "/org/openide/awt/data/testActionOnlyOnce.xml" };
    URL[] layers = new URL[stringLayers.length];

    for (int cntr = 0; cntr < layers.length; cntr++) {
        layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
    }

    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);

    // build menu
    DataFolder dataFolder = DataFolder.findFolder(system.findResource("FullOfCNFs"));
    CharSequence log = Log.enable("org.openide.awt", Level.INFO);
    MenuBar menuBar = new MenuBar(dataFolder);
    menuBar.waitFinished();

    int componentCount = 0;
    for (Component c : menuBar.getComponents()) {
        if (!c.isVisible()) {
            continue;
        }
        componentCount++;
    }
    assertEquals("No instances", 0, componentCount);
    AWTTaskTest.waitEQ();

    
    if (log.toString().indexOf("initCause") >= 0) {
        fail("Something wrong with initCause:\n" + log);
    }

}
 
Example 20
public void testSynchronization() throws Exception {
    FileSystem fs = new XMLFileSystem(this.getClass().getClassLoader().getResource("org/openide/loaders/data/InstanceDataObjectTest.xml"));
    FileObject fo = fs.findResource("testInstanceDefinitions/s.instance");
    assertNotNull(fo);
    final String filename = fo.getNameExt();
    DataObject dobj = DataObject.find(fo);
    final InstanceCookie ic = dobj.getLookup().lookup(InstanceCookie.class);
    assertNotNull(filename, ic);

    int numThreads = 10;

    final CountDownLatch startSignal = new CountDownLatch(1);
    final CountDownLatch doneSignal = new CountDownLatch(numThreads);
    final Set<TestSync> all = new CopyOnWriteArraySet<TestSync>();

    // first create some threads
    while (numThreads-- > 0) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    startSignal.await();
                    TestSync ts = (TestSync) ic.instanceCreate();
                    all.add(ts);
                    doneSignal.countDown();
                } catch (Exception e) {
                }
            }
        }).start();
    }
    // now start them all
    startSignal.countDown();
    doneSignal.await();
    // this is certainly the goal:
    assertEquals("Only one instance of TestSync returned:\n" + all, 1, all.size());
    // the following may be hard to guarantee however:
    assertEquals("Just one instance of TestSync created:\n" + all, 1, TestSync.instanceCounter.get());
}
 
Example 21
Source Project: netbeans   Source File: InstanceDataObjectGetNameTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void setUp () throws Exception {
    
    cnt = 0;
    
    File f = new File(getWorkDir(), "layer.xml");
    FileWriter w = new FileWriter(f);
    w.write("<filesystem><file name='x.instance'> ");
    w.write("  <attr name='name' methodvalue='" + InstanceDataObjectGetNameTest.class.getName() + ".computeName'/> ");
    w.write("</file></filesystem> ");
    w.close();

    fs = new MultiFileSystem(new FileSystem[] { 
        FileUtil.createMemoryFileSystem(), 
        new XMLFileSystem(f.toURL())
    });
    FileObject fo = fs.findResource("x.instance");
    assertNotNull(fo);
    
    assertNull(fo.getAttribute("name"));
    assertEquals("One call", 1, cnt);
    // clean
    cnt = 0;

    obj = DataObject.find(fo);
    
    assertEquals("No calls now", 0, cnt);
}
 
Example 22
Source Project: netbeans   Source File: IDEInitializer.java    License: 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),
    });
    try {
        Assert.assertEquals (myFileSystem, FileUtil.getConfigRoot().getFileSystem());
    } catch (FileStateInvalidException e) {
        e.printStackTrace();
    }
}
 
Example 23
Source Project: netbeans   Source File: XMLFSvsParserTest.java    License: Apache License 2.0 5 votes vote down vote up
/** Tests how quickly an XML fs can be created.
 */
public void testXMLFS () throws Exception {
    int cnt = getIterationCount ();
    while (cnt-- > 0) {
        XMLFileSystem fs = new XMLFileSystem (url);
    }
}
 
Example 24
Source Project: netbeans   Source File: OSGiRepository.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized void addLayers(URL... resources) {
    LOG.log(Level.FINE, "addLayers: {0}", Arrays.asList(resources));
    for (URL resource : resources) {
        try {
            fss.put(resource.toString(), new XMLFileSystem(resource));
        } catch (SAXException x) {
            LOG.log(Level.WARNING, "Could not parse layer: " + resource, x);
        }
    }
    resetLayers();
}
 
Example 25
Source Project: netbeans   Source File: XMLPropertiesConvertorTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void setUp() throws java.lang.Exception {
    super.setUp();
    Lookup.getDefault().lookup(ModuleInfo.class);
    java.net.URL layer = this.getClass().getResource("data/layer.xml");
    fs = new XMLFileSystem(layer);
    root = FileUtil.getConfigRoot();
    assertNotNull("SFS root not found", root);
    
    FileObject serdata = FileUtil.getConfigFile("xml/lookups/NetBeans/DTD_Session_settings_1_0.instance");
    assertNotNull("missing registration for serialdata format", serdata);
    Object attr = serdata.getAttribute("instanceCreate");
    assertNotNull("core's registration for serialdata format", attr);
    assertEquals(SerialDataConvertor.Provider.class, attr.getClass());
}
 
Example 26
Source Project: netbeans   Source File: ReadJustOnceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    URL u = this.getClass().getResource ("code-fs.xml");        
    FileSystem fs = new XMLFileSystem(u);
    FileObject resolversRoot = fs.getRoot().getFileObject("root");
    resolversRoot.refresh();
    
    FileObject fos[] = resolversRoot.getChildren();
    List<MIMEResolver> resolvers = new ArrayList<MIMEResolver>();
    for (int i = 0; i<fos.length; i++) {
        resolvers.add(createResolver(fos[i]));
    }
    
    MockLookup.setInstances(resolvers.toArray());
}
 
Example 27
Source Project: netbeans   Source File: LayerBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAbsolutizeAndValidateResourcesExistent() throws Exception {
    AnnotationProcessorTestUtils.makeSource(src, "p.C", "@" + V.class.getCanonicalName() + "(r1=\"other/x1\", r2=\"resources/x2\") public class C {}");
    File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1");
    TestFileUtils.writeFile(new File(src, "p/resources/x2"), "x2");
    ByteArrayOutputStream err = new ByteArrayOutputStream();
    boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, BaseUtilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err);
    String msgs = err.toString();
    assertTrue(msgs, status);
    assertTrue(msgs, msgs.contains("r1=x1") ^ AnnotationProcessorTestUtils.searchClasspathBroken());
    assertTrue(msgs, msgs.contains("r2=x2"));
    FileObject f = new XMLFileSystem(BaseUtilities.toURI(new File(dest, "META-INF/generated-layer.xml")).toURL()).findResource("f");
    assertNotNull(f);
    assertEquals("other/x1", f.getAttribute("r1"));
    assertEquals("p/resources/x2", f.getAttribute("r2"));
}
 
Example 28
Source Project: netbeans   Source File: IDEInitializer.java    License: 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 Project: netbeans   Source File: NotificationCategoryFactoryTest.java    License: 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 (PropertyVetoException | IOException ex) {
        throw new RuntimeException(ex);
    }
    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),});
    assertTrue(myFileSystem.isDefault());
}
 
Example 30
Source Project: netbeans   Source File: AdditionalProjectFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    LOG = Logger.getLogger("test." + getName());
    URL u = AdditionalProjectFactoryTest.class.getResource("default.xml");
    assertNotNull("Default layer found", u);
    XMLFileSystem xml = new XMLFileSystem(u);
    FileObject fo = xml.findResource("Menu/Edit_hidden");
    assertNotNull("File found", fo);
}