Java Code Examples for org.openide.filesystems.XMLFileSystem#setXmlUrls()

The following examples show how to use org.openide.filesystems.XMLFileSystem#setXmlUrls() . 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: UnitTestUtils.java    From netbeans with 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 2
Source File: LayerCacheManager.java    From netbeans with 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 File: IDEInitializer.java    From netbeans with 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 4
Source File: BaseCaretTest.java    From netbeans with 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 5
Source File: UnitTestUtils.java    From netbeans with 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 File: MavenNbModuleImpl.java    From netbeans with 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 7
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 8
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 9
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 10
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 11
Source File: UnitUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[additionalLayers.length + 1];
    
    layers[0] = Utilities.class.getResource("/org/netbeans/modules/editor/errorstripe/resources/layer.xml");
    
    for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
        layers[cntr + 1] = Utilities.class.getResource(additionalLayers[cntr]);
    }
    
    for (int cntr = 0; cntr < layers.length; cntr++) {
        if (layers[cntr] == null) {
            throw new IllegalStateException("layers[" + cntr + "]=null");
        }
    }
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    
    Repository repository = new Repository(system);
    Object[] lookupContent = new Object[additionalLookupContent.length + 1];
    
    System.arraycopy(additionalLookupContent, 0, lookupContent, 1, additionalLookupContent.length);
    
    lookupContent[0] = repository;
    
    DEFAULT_LOOKUP.setLookup(lookupContent, UnitUtilities.class.getClassLoader());
}
 
Example 12
Source File: NotificationCategoryFactoryTest.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 (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 13
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),
    });
    try {
        Assert.assertEquals (myFileSystem, FileUtil.getConfigRoot().getFileSystem());
    } catch (FileStateInvalidException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source File: EditorTestLookup.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 setLookup(URL[] layers, Object[] instances, ClassLoader cl)
throws IOException, PropertyVetoException {
    
    XMLFileSystem system = new XMLFileSystem();
    system.setXmlUrls(layers);
    Repository repository = new Repository(system);

    Object[] lookupContent = new Object[instances.length + 1];
    lookupContent[0] = repository;
    System.arraycopy(instances, 0, lookupContent, 1, instances.length);
    
    DEFAULT_LOOKUP.setLookup(lookupContent, cl);
}
 
Example 15
Source File: MenuBarCNFETest.java    From netbeans with 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 16
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 17
Source File: EditorTestLookup.java    From netbeans with 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 File: SourceUtilsTestUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void prepareTest(String[] additionalLayers, Object... additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
    List<URL> layers = new LinkedList<URL>();
    
    for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
        boolean found = false;

        for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(additionalLayers[cntr]); en.hasMoreElements(); ) {
            found = true;
            layers.add(en.nextElement());
        }

        Assert.assertTrue(additionalLayers[cntr], found);
    }
    
    XMLFileSystem xmlFS = new XMLFileSystem();
    xmlFS.setXmlUrls(layers.toArray(new URL[0]));

    FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});

    Repository repository = new Repository(system);

    try {
        //the Repository.repository might have already been assigned (typically
        //through a previous call to prepareTest, and then a listener on the openProjects)
        //hard resetting:
        Method repositoryReset = Repository.class.getDeclaredMethod("reset");

        repositoryReset.setAccessible(true);
        repositoryReset.invoke(null);
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    
    extraLookupContent = new Object[additionalLookupContent.length + 2];
    
    System.arraycopy(additionalLookupContent, 0, extraLookupContent, 2, additionalLookupContent.length);
    
    extraLookupContent[0] = repository;
    extraLookupContent[1] = new DocumentFactory() {
        @Override
        public Document createDocument(String mimeType) {
            return new BaseDocument(false, mimeType);
        }

        @Override
        public Document getDocument(FileObject file) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public FileObject getFileObject(Document document) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    };
    
    SourceUtilsTestUtil.setLookup(extraLookupContent, SourceUtilsTestUtil.class.getClassLoader());
    
    SourceUtilsTestUtil2.disableLocks();

    Set<String> amt = MimeTypes.getAllMimeTypes();
    if (amt == null) {
        amt = new HashSet<String>();
    } else {
        amt = new HashSet<String>(amt);
    }
    amt.add("text/x-java");
    MimeTypes.setAllMimeTypes(amt);
    org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();

    TestUtil.setupEditorMockServices();
}
 
Example 19
Source File: SourceUtilsTestUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void prepareTest(String[] additionalLayers, Object[] additionalLookupContent) throws IOException, SAXException, PropertyVetoException {
    URL[] layers = new URL[additionalLayers.length];
    
    for (int cntr = 0; cntr < additionalLayers.length; cntr++) {
        layers[cntr] = Thread.currentThread().getContextClassLoader().getResource(additionalLayers[cntr]);
    }
    
    XMLFileSystem xmlFS = new XMLFileSystem();
    xmlFS.setXmlUrls(layers);
    
    FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});
    
    Repository repository = new Repository(system);
    extraLookupContent = new Object[additionalLookupContent.length + 1];
    
    System.arraycopy(additionalLookupContent, 0, extraLookupContent, 1, additionalLookupContent.length);
    
    extraLookupContent[0] = repository;
    
    setLookup(extraLookupContent, SourceUtilsTestUtil.class.getClassLoader());
}
 
Example 20
Source File: HintTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private HintTest() throws Exception {
    List<URL> layers = new LinkedList<URL>();

    for (String layer : new String[] {"META-INF/generated-layer.xml"}) {
        boolean found = false;

        for (Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(layer); en.hasMoreElements(); ) {
            found = true;
            layers.add(en.nextElement());
        }

        Assert.assertTrue(layer, found);
    }

    XMLFileSystem xmlFS = new XMLFileSystem();
    xmlFS.setXmlUrls(layers.toArray(new URL[0]));

    FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS});

    Repository repository = new Repository(system);

    assertEquals(Lookup.getDefault().getClass().getCanonicalName(), TestLookup.class, Lookup.getDefault().getClass());

    ((TestLookup) Lookup.getDefault()).setLookupsImpl(
        Lookups.fixed(repository,
                      new TestProxyClassPathProvider(),
                      new TestSourceForBinaryQuery(),
                      new TestSourceLevelQueryImplementation(),
                      new TestCompilerOptionsQueryImplementation(),
                      JavaDataLoader.findObject(JavaDataLoader.class, true)),
        Lookups.metaInfServices(HintTest.class.getClassLoader()),
        Lookups.singleton(HintTest.class.getClassLoader())
    );

    Set<String> amt = MimeTypes.getAllMimeTypes();
    if (amt == null) {
        amt = new HashSet<String>();
    } else {
        amt = new HashSet<String>(amt);
    }
    amt.add("text/x-java");
    MimeTypes.setAllMimeTypes(amt);
    org.netbeans.api.project.ui.OpenProjects.getDefault().getOpenProjects();

    testPreferences = new TempPreferences();
    hintSettings = new HintsSettings() {
        @Override public boolean isEnabled(HintMetadata hint) {
            return true;
        }
        @Override public void setEnabled(HintMetadata hint, boolean value) {
            throw new UnsupportedOperationException("Not supported.");
        }
        @Override public Preferences getHintPreferences(HintMetadata hint) {
            return testPreferences;
        }
        @Override public Severity getSeverity(HintMetadata hint) {
            return hint.severity;
        }
        @Override public void setSeverity(HintMetadata hint, Severity severity) {
            throw new UnsupportedOperationException("Not supported.");
        }
    };

    workDir = getWorkDir();
    deleteSubFiles(workDir);
    FileUtil.refreshFor(workDir);

    FileObject wd = FileUtil.toFileObject(workDir);
    
    assertNotNull(wd);

    sourceRoot = FileUtil.createFolder(wd, "src");
    buildRoot = FileUtil.createFolder(wd, "build");
    cache = FileUtil.createFolder(wd, "cache");

    CacheFolder.setCacheFolder(cache);

    NbBundle.setBranding("test");

    sourcePath = ClassPathSupport.createClassPath(sourceRoot);
    
    Main.initializeURLFactory();
    JavacParser.DISABLE_SOURCE_LEVEL_DOWNGRADE = true;
}