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

The following examples show how to use org.openide.filesystems.FileUtil#setMIMEType() . 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: XMLDataObjectMimeTypeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setUp(String mime) throws Exception {
    super.setUp();
    MockServices.setServices(Pool.class);
    String ext = getName();
    
    clearWorkDir();
    lfs = new LocalFileSystem();
    lfs.setRootDirectory(getWorkDir());
    FileUtil.createData(lfs.getRoot(), "AA/a."  + ext);
    Repository.getDefault().addFileSystem(lfs);
    FileUtil.setMIMEType(ext, mime);
    FileObject fo = lfs.findResource("AA/a." + ext);
    assertNotNull("file not found", fo);
    obj = DataObject.find(fo);

    assertEquals("The right class", obj.getClass(), XMLDataObject.class);

    assertFalse("Designed to run outside of AWT", SwingUtilities.isEventDispatchThread());
}
 
Example 2
Source File: ParsinApiInteractionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    Field f = IndexingUtils.class.getDeclaredField("status");
    f.setAccessible(true);
    f.set(null, null);
    FileUtil.setMIMEType(FOO_EXT, MIME_FOO);
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject file = FileUtil.createData(wd, "test.foo");    //NOI18N
    assertNotNull(file);
    src = Source.create(file);
    assertNotNull(src);
    handler = new TestHandler();
    log = Logger.getLogger(RunWhenScanFinishedSupport.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
}
 
Example 3
Source File: IndexingSupportACIDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final File wd = getWorkDir();
    final FileObject wdo = FileUtil.toFileObject(wd);
    assertNotNull("No masterfs",wdo);   //NOI18N
    final FileObject cache = wdo.createFolder("cache"); //NOI18N
    CacheFolder.setCacheFolder(cache);
    src1 = wdo.createFolder("src1");        //NOI18N
    assertNotNull(src1);
    src2 = wdo.createFolder("src2");        //NOI18N
    assertNotNull(src2);
    file1 = src1.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(file1);
    file2 = src2.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(file2);
    FileUtil.setMIMEType(FOO_EXT, FOO_MIME);
    cp1 = ClassPathSupport.createClassPath(src1);
    cp2 = ClassPathSupport.createClassPath(src2);
    MockMimeLookup.setInstances(MimePath.get(FOO_MIME), new FooIndexerFactory());
    RepositoryUpdaterTest.setMimeTypes(FOO_MIME);
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();
}
 
Example 4
Source File: JavadocAndSourceRootDetectionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFindAllSourceRoots() throws Exception {
    FileUtil.setMIMEType("java", "text/x-java");
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject root1 = FileUtil.createFolder(wd,"root1");
    final FileObject root2 = FileUtil.createFolder(wd,"foo/root2");
    final FileObject root3 = FileUtil.createFolder(wd,"foo/test/root3");
    final FileObject root4 = FileUtil.createFolder (wd,"root4");
    TestFileUtils.writeFile(root1,"org/me/Test1.java","package org.me; class Test1{}");
    TestFileUtils.writeFile(root2,"org/me/Test2.java","package org.me; class Test2{}");
    TestFileUtils.writeFile(root3,"org/me/Test3.java","package org.me; class Test3{}");
    TestFileUtils.writeFile(root4,"org/me/Test4.java","package org.me; class Test4{}");
    final List<FileObject> result = new ArrayList(JavadocAndSourceRootDetection.findSourceRoots(wd, null));
    final List<FileObject> expected = new ArrayList(Arrays.asList(
            root1,
            root2,
            root3,
            root4));
    final Comparator<FileObject> c = new Comparator<FileObject>() {
        public int compare(FileObject o1, FileObject o2) {
            return o1.getNameExt().compareToIgnoreCase(o2.getNameExt());
        }
    };
    Collections.sort(expected,c);
    Collections.sort(result,c);
    assertEquals (expected.toString(), result.toString());
}
 
Example 5
Source File: FodDataObjectXMLFactoryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCreateRecognize() throws Exception {
    assertFalse("Autoupdate is disabled", au.isEnabled());
    FileUtil.setMIMEType("huh", "text/huh+xml");
    FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "test/my.huh");
    DataObject obj = DataObject.find(fo);
    FileObject fo2 = FileUtil.createData(FileUtil.getConfigRoot(), "test/my.xml");
    DataObject obj2 = DataObject.find(fo2);

    assertTrue("It is kind of XML", obj instanceof XMLDataObject);
    assertTrue("It is kind of XML2", obj2 instanceof XMLDataObject);

    Action[] arr = obj.getNodeDelegate().getActions(true);
    Action a = assertAction("Enabled in huh object", true, arr, obj.getLookup());
    assertAction("Disabled in real xml object", false, arr, obj2.getLookup());

    a.actionPerformed(new ActionEvent(this, 0, ""));

    
}
 
Example 6
Source File: EncodingTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    // invoke the pallete factory in advance to prevent deadlock
    HtmlPaletteFactory.getHtmlPalette();
    Utils.setUp();
    
    // to help the loader to recognize our files
    FileUtil.setMIMEType("html", "text/html");
}
 
Example 7
Source File: FileListWorkOrderingTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final File wd = getWorkDir();
    final FileObject wdo = FileUtil.toFileObject(wd);
    assertNotNull("No masterfs",wdo);   //NOI18N
    final FileObject cache = wdo.createFolder("cache"); //NOI18N
    CacheFolder.setCacheFolder(cache);
    src1 = wdo.createFolder("src1");        //NOI18N
    assertNotNull(src1);
    src2 = wdo.createFolder("src2");        //NOI18N
    assertNotNull(src2);
    src1file1 = src1.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src1file1);
    src1file2 = src1.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src1file2);
    src2file1 = src2.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(src2file1);
    src2file2 = src2.createData("test2", FOO_EXT);  //NOI18N
    assertNotNull(src2file2);

    FileUtil.setMIMEType(FOO_EXT, FOO_MIME);
    cp1 = ClassPathSupport.createClassPath(src1,src2);
    MockMimeLookup.setInstances(MimePath.get(FOO_MIME), new FooIndexerFactory());
    RepositoryUpdaterTest.setMimeTypes(FOO_MIME);
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();
}
 
Example 8
Source File: EmbeddedIndexerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    this.clearWorkDir();
    final File _wd = this.getWorkDir();
    final FileObject wd = FileUtil.toFileObject(_wd);
    final FileObject cache = wd.createFolder("cache");  //NOI18N
    CacheFolder.setCacheFolder(cache);
    final Map<String,Object> attrMap = new HashMap<String,Object>();
    attrMap.put(EmbeddingProviderFactory.ATTR_TARGET_MIME_TYPE, MIME_INNER);
    attrMap.put(EmbeddingProviderFactory.ATTR_PROVIDER, new TopToInnerEmbProvider());
    MockMimeLookup.setInstances(
            MimePath.get(MIME_TOP),
            new TopParser.Factory(),
            EmbeddingProviderFactory.create(attrMap),
            new TopIndexer.Factory());
    MockMimeLookup.setInstances(
            MimePath.get(MIME_INNER),
            new InnerParser.Factory(),
            new InnerIndexer.Factory());
    srcRoot = wd.createFolder("src");   //NOI18N
    srcFile = FileUtil.toFileObject(
        TestFileUtils.writeFile(
            new File(FileUtil.toFile(srcRoot), "source.top"),   //NOI18N
            "   <A>   <B>   < A> < >"));                        //NOI18N
    FileUtil.setMIMEType(EXT_TOP, MIME_TOP);
    RepositoryUpdaterTest.setMimeTypes(MIME_TOP, MIME_INNER);
    ClassPathProviderImpl.setRoot(srcRoot);
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();
}
 
Example 9
Source File: QuerySupportLifeLock230220Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    clearWorkDir();
    final FileObject wd = FileUtil.toFileObject(getWorkDir());
    final FileObject cache = FileUtil.createFolder(wd, "cache"); //NOI18N
    CacheFolder.setCacheFolder(cache);

    MockMimeLookup.setInstances(
        MimePath.get(FooPathRecognizer.FOO_MIME),
        new FooParser.Factory(),
        new EmbEmbeddingProvider.Factory(),
        new FooIndexer.Factory());
    MockMimeLookup.setInstances(
        MimePath.get(EmbeddedPathRecognizer.EMB_MIME),
        new EmbParser.Factory(),
        new EmbIndexer.Factory());

    sources = FileUtil.createFolder(wd, "src");         //NOI18N
    srcFile = FileUtil.createData(sources, "file.foo"); //NOI18N
    scp = ClassPathSupport.createClassPath(sources);
    final ClassPathProviderImpl cppImpl = Lookup.getDefault().lookup(ClassPathProviderImpl.class);
    cppImpl.roots2cp = Pair.<FileObject[],ClassPath>of(
        new FileObject[]{sources},
        scp);
    TestFileUtils.writeFile(
        FileUtil.toFile(srcFile),
        "class {Lookup} class {ProjectManager} class {FileOwnerQuery}");    //NOI18N
    FileUtil.setMIMEType("foo", FooPathRecognizer.FOO_MIME);    //NOI18N
    RepositoryUpdaterTest.setMimeTypes(
        FooPathRecognizer.FOO_MIME,
        EmbeddedPathRecognizer.EMB_MIME);
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();
}
 
Example 10
Source File: XMLDataObjectMimeTypeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp(String mime) throws Exception {
    super.setUp();

    String ext = getName();
    
    registerIntoLookup(new DD());

    DD x = Lookup.getDefault().lookup(DD.class);
    assertNotNull("DD is there", x);

    String fsstruct [] = new String [] {
        "AA/a."  + ext
    };

    TestUtilHid.destroyLocalFileSystem(getName());
    lfs = TestUtilHid.createLocalFileSystem(getWorkDir(), fsstruct);
    Repository.getDefault().addFileSystem(lfs);
    FileUtil.setMIMEType(ext, mime);
    FileObject fo = lfs.findResource("AA/a." + ext);
    assertNotNull("file not found", fo);
    obj = DataObject.find(fo);

    assertEquals("The right class", obj.getClass(), XMLDataObject.class);

    assertFalse("Designed to run outside of AWT", SwingUtilities.isEventDispatchThread());
    DD.options = null;
    DD.disableTest = false;
}
 
Example 11
Source File: TaskProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testWarningWhenRunUserTaskCalledFromAWT() throws Exception {
    this.clearWorkDir();
    final File _wd = this.getWorkDir();
    final FileObject wd = FileUtil.toFileObject(_wd);

    FileUtil.setMIMEType("foo", "text/foo");
    final FileObject foo = wd.createData("file.foo");
    final LogRecord[] warning = new LogRecord[1];
    final String msgTemplate = "ParserManager.parse called in AWT event thread by: {0}";  //NOI18N

    MockMimeLookup.setInstances(MimePath.parse("text/foo"), new FooParserFactory());
    Logger.getLogger(TaskProcessor.class.getName()).addHandler(new Handler() {
        public @Override void publish(LogRecord record) {
            if (record.getMessage().startsWith(msgTemplate)) {
                warning[0] = record;
            }
        }

        public @Override void flush() {
        }

        public @Override void close() throws SecurityException {
        }
    });

    final StackTraceUserTask stackTraceUserTask = new StackTraceUserTask();
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            try {
                ParserManager.parse(Collections.singleton(Source.create(foo)), stackTraceUserTask);
            } catch (ParseException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });

    assertNotNull("No warning when calling ParserManager.parse from AWT", warning[0]);
    assertEquals("Wrong message", msgTemplate, warning[0].getMessage());
    assertEquals("Suspiciosly wrong warning message (is the caller identified correctly?)", stackTraceUserTask.caller, warning[0].getParameters()[0]);
}
 
Example 12
Source File: ParsinApiInteractionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testRunWhenScanFinishGetCalledUnderCCLock() throws Exception {
    final File wd = getWorkDir();
    final File srcDir = new File (wd,"src");
    srcDir.mkdirs();
    final File file = new File (srcDir,"test.foo");
    file.createNewFile();
    FileUtil.setMIMEType("foo", "text/foo");
    MockMimeLookup.setInstances(MimePath.parse("text/foo"), new FooParserFactory(), new PlainKit());
    final FileObject fo = FileUtil.toFileObject(file);
    final DataObject dobj = DataObject.find(fo);
    final EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
    final StyledDocument doc = ec.openDocument();
    final Source src = Source.create(doc);
    final CountDownLatch ruRunning = new CountDownLatch(1);
    final CountDownLatch rwsfCalled = new CountDownLatch(1);
    final AtomicReference<Set<RepositoryUpdater.IndexingState>> indexing = new AtomicReference<Set<RepositoryUpdater.IndexingState>>();
    final IndexingUtils.IndexingStatus is = new IndexingUtils.IndexingStatus() {
        @Override
        public Set<? extends RepositoryUpdater.IndexingState> getIndexingState() {
            return indexing.get();
        }
    };
    IndexingUtils.setIndexingStatus(is);
    RepositoryUpdaterTestSupport.runAsWork(
            new Runnable(){
                @Override
                public void run() {
                    indexing.set(EnumSet.of(RepositoryUpdater.IndexingState.WORKING));
                    try {
                        ruRunning.countDown();
                        rwsfCalled.await();
                    } catch (InterruptedException ie) {
                    } finally {
                        indexing.set(EnumSet.noneOf(RepositoryUpdater.IndexingState.class));
                    }
                }
            });
    ruRunning.await();
    doc.putProperty("completion-active", Boolean.TRUE);
    try {
        final Future<Void> done = ParserManager.parseWhenScanFinished(Collections.<Source>singleton(src),new UserTask() {
            @Override
            public void run(ResultIterator resultIterator) throws Exception {                    
            }
    });
    assertFalse(done.isDone());
    assertFalse(done.isCancelled());
    rwsfCalled.countDown();
    try {
        done.get(5, TimeUnit.SECONDS);
    } catch (TimeoutException te) {
        assertTrue("Deadlock",false);
    }
    } finally {
        doc.putProperty("completion-active", null);
    }
}
 
Example 13
Source File: TaskProcessorSuspendTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testRunLoopSuspend2() throws Exception {
    FileUtil.setMIMEType("foo", "text/foo");    //NOI18N
    MockMimeLookup.setInstances(MimePath.parse("text/foo"), new TaskProcessorTest.FooParserFactory(), new PlainKit());    //NOI18N
    final File wd = getWorkDir();
    final File srcFolder = new File (wd,"src");
    final FileObject srcRoot = FileUtil.createFolder(srcFolder);
    final FileObject srcFile = srcRoot.createData("test.foo");  //NOI18N
    final Source source = Source.create(srcFile);
    final SourceCache cache = SourceAccessor.getINSTANCE().getCache(source);
    final CountDownLatch taskCalled = new CountDownLatch(1);
    final SchedulerTask task = new ParserResultTask() {
        @Override
        public void run(Parser.Result result, SchedulerEvent event) {
            taskCalled.countDown();
        }

        @Override
        public int getPriority() {
            return 10;
        }

        @Override
        public Class<? extends Scheduler> getSchedulerClass() {
            return Scheduler.SELECTED_NODES_SENSITIVE_TASK_SCHEDULER;
        }

        @Override
        public void cancel() {
        }
    };

    runLoop(source, true);
    try {
        TaskProcessor.addPhaseCompletionTasks(
            Arrays.asList(Pair.<SchedulerTask,Class<? extends Scheduler>>of(task,task.getSchedulerClass())),
            cache,
            false);
        assertFalse(taskCalled.await(2000, TimeUnit.MILLISECONDS));
    } finally {
        runLoop(source, false);
    }
    assertTrue(taskCalled.await(5000, TimeUnit.MILLISECONDS));
}
 
Example 14
Source File: IndentEngineIntTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected void setUp() throws Exception {
    MockServices.setServices(DD.class, Pool.class);
    MockMimeLookup.setInstances(MimePath.get("text/jarda"), new IEImpl2());
    FileUtil.setMIMEType("txt", "text/jarda");
}
 
Example 15
Source File: FodDataObjectLineSetTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@RandomlyFails // ergonomics #3485
public void testCreateRecognize() throws Exception {
    assertFalse("Autoupdate is disabled", au.isEnabled());
    FileUtil.setMIMEType("huh", "text/x-huh");
    FileObject fo = FileUtil.createData(FileUtil.getConfigRoot(), "test/my.huh");
    DataObject obj = DataObject.find(fo);
    FileObject fo2 = FileUtil.createData(FileUtil.getConfigRoot(), "test/subdir/my.huh");
    DataObject obj2 = DataObject.find(fo2);
    CharSequence log = Log.enable("org.openide.loaders", Level.WARNING);
    LineCookie lineCookie = obj.getLookup().lookup(LineCookie.class);
    assertNotNull("Line cookie found", lineCookie);
    assertEquals("Cookie is OK too", lineCookie, obj.getCookie(LineCookie.class));
    assertEquals("Node is OK too", lineCookie, obj.getNodeDelegate().getCookie(LineCookie.class));
    assertEquals("Node lookup is OK too", lineCookie, obj.getNodeDelegate().getLookup().lookup(LineCookie.class));
    assertTrue("It is our cookie: " + lineCookie, lineCookie.getClass().getName().contains("ergonomics"));
    assertEquals("No warnings: " + log, 0, log.length());

    Line.Set lineSet = lineCookie.getLineSet();
    assertTrue("Autoupdate is enabled", au.isEnabled());
    assertNotNull("Line set found", lineSet);
    for (int i = 0; ; i++) {
        DataObject newObj = DataObject.find(fo);
        if (obj == newObj) {
            if (i < 50) {
                Thread.sleep(1000);
                continue;
            }
            fail("New object shall be created: " + newObj);
        }
        break;
    }
    assertFalse("Old is no longer valid", obj.isValid());

    DataObject newObj2 = DataObject.find(fo2);
    if (obj2 == newObj2) {
        fail("New object shall be created for all objects: " + newObj2);
    }

    DataObject folder = FodDataObjectFactory.create(fo).findDataObject(fo.getParent(), new HashSet<FileObject>());
    assertNull("Folders are not recognized", folder);
}
 
Example 16
Source File: JavaDataLoaderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void XtestPerformance() throws Exception {
    MockServices.setServices(JavaDataLoader.class);
    FileUtil.setMIMEType("bbb", "text/x-java");
    recognize(1000);
    recognize(1000);
}
 
Example 17
Source File: RepositoryUpdaterTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
    protected void setUp() throws Exception {
//        TopLogging.initializeQuietly();
        super.setUp();
        this.clearWorkDir();
        final File _wd = this.getWorkDir();
        final FileObject wd = FileUtil.toFileObject(_wd);
        final FileObject cache = wd.createFolder("cache");
        CacheFolder.setCacheFolder(cache);
        RootsListener.setUseAsyncListneres(false);

        MockMimeLookup.setInstances(MimePath.EMPTY, binIndexerFactory);
//        MockMimeLookup.setInstances(MimePath.get(JARMIME), jarIndexerFactory);
        MockMimeLookup.setInstances(MimePath.get(MIME), indexerFactory);
        MockMimeLookup.setInstances(MimePath.get(EMIME), eindexerFactory, new EmbParserFactory());
        setMimeTypes(EMIME, MIME);

        assertNotNull("No masterfs",wd);
        srcRoot1 = wd.createFolder("src1");
        assertNotNull(srcRoot1);
        srcRoot2 = wd.createFolder("src2");
        assertNotNull(srcRoot2);
        srcRoot3 = wd.createFolder("src3");
        assertNotNull (srcRoot3);
        compRoot1 = wd.createFolder("comp1");
        assertNotNull (compRoot1);
        compRoot2 = wd.createFolder("comp2");
        assertNotNull (compRoot2);
        bootRoot1 = wd.createFolder("boot1");
        assertNotNull (bootRoot1);
        bootRoot2 = wd.createFolder("boot2");
        assertNotNull (bootRoot2);
        bootRoot3 = wd.createFolder("boot3");
        assertNotNull (bootRoot3);
        
        FileUtil.setMIMEType("jar", JARMIME);
        jarFile = FileUtil.createData(bootRoot3, "JavaApplication1.jar");
        assertNotNull(jarFile);
        zipFileObject(jarFile);
        assertTrue(FileUtil.isArchiveFile(jarFile));
        
        compSrc1 = wd.createFolder("cs1");
        assertNotNull (compSrc1);
        compSrc2 = wd.createFolder("cs2");
        assertNotNull (compSrc2);
        bootSrc1 = wd.createFolder("bs1");
        assertNotNull (bootSrc1);
        unknown1 = wd.createFolder("uknw1");
        assertNotNull (unknown1);
        unknown2 = wd.createFolder("uknw2");
        assertNotNull (unknown2);
        unknownSrc2 = wd.createFolder("uknwSrc2");
        assertNotNull(unknownSrc2);
        SFBQImpl.register (bootRoot1,bootSrc1);
        SFBQImpl.register (compRoot1,compSrc1);
        SFBQImpl.register (compRoot2,compSrc2);
        SFBQImpl.register (unknown2,unknownSrc2);

        srcRootWithFiles1 = wd.createFolder("srcwf1");
        assertNotNull(srcRootWithFiles1);
        FileUtil.setMIMEType("foo", MIME);
        f1 = FileUtil.createData(srcRootWithFiles1,"folder/a.foo");
        assertNotNull(f1);
        assertEquals(MIME, f1.getMIMEType());
        FileObject f2 = FileUtil.createData(srcRootWithFiles1,"folder/b.foo");
        assertNotNull(f2);
        assertEquals(MIME, f2.getMIMEType());
        customFiles = new URL[] {f1.toURL(), f2.toURL()};

        FileUtil.setMIMEType("emb", EMIME);
        f3 = FileUtil.createData(srcRootWithFiles1,"folder/a.emb");
        assertNotNull(f3);
        assertEquals(EMIME, f3.getMIMEType());
        FileObject f4 = FileUtil.createData(srcRootWithFiles1,"folder/b.emb");
        assertNotNull(f4);
        assertEquals(EMIME, f4.getMIMEType());
        embeddedFiles = new URL[] {f3.toURL(), f4.toURL()};


        waitForRepositoryUpdaterInit();
    }
 
Example 18
Source File: ScanStartedTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    
    handler = new TestHandler(); 

    this.clearWorkDir();
    final File _wd = this.getWorkDir();
    final FileObject wd = FileUtil.toFileObject(_wd);
    assertNotNull("No masterfs",wd);                    //NOI18N
    final FileObject cache = wd.createFolder("cache");  //NOI18N
    CacheFolder.setCacheFolder(cache);
    src1 = wd.createFolder("src1");     //NOI18N
    assertNotNull(src1);
    file1 = src1.createData("test", FOO_EXT);   //NOI18N
    assertNotNull(file1);
    FileUtil.setMIMEType(FOO_EXT, FOO_MIME);
    bin1 = wd.createFolder("bin1"); //NOI18N
    file2 = bin1.createData("test", "bin"); //NOI18N

    factory1 = new IndexerFactory("factory1", 1);   //NOI18N
    factory2 = new IndexerFactory("factory2", 1);   //NOI18N
    factory3 = new IndexerFactory("factory3", 1);   //NOI18N

    binFactory1 = new BinIndexerFactory("binFactory1", 1);  //NOI18N
    binFactory2 = new BinIndexerFactory("binFactory2", 1);  //NOI18N
    binFactory3 = new BinIndexerFactory("binFactory3", 1);  //NOI18N

    cp1 = ClassPathSupport.createClassPath(src1);
    bcp1 = ClassPathSupport.createClassPath(bin1);
    FooCPP.roots2cps = Collections.unmodifiableMap(
            new HashMap() {
                {
                    put(src1, Collections.singletonMap(FOO_SOURCES, cp1));
                    put(bin1, Collections.singletonMap(FOO_BINARY, bcp1));
                }
            });
    MockMimeLookup.setInstances(MimePath.EMPTY, binFactory1, binFactory2, binFactory3);
    MockMimeLookup.setInstances(MimePath.get(FOO_MIME), factory1, factory2, factory3);
    RepositoryUpdaterTest.setMimeTypes(FOO_MIME);
    
    RepositoryUpdaterTest.waitForRepositoryUpdaterInit();  
    
    LOG.setLevel (Level.FINEST);
    LOG.addHandler(handler);

}
 
Example 19
Source File: HtmlDataObjectTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private static void init() {
    FileUtil.setMIMEType("html", "text/html");
}
 
Example 20
Source File: BinaryUsagesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clearWorkDir();
    MockServices.setServices(OrderedURLMapper.class, CPProvider.class, SLQ.class);
    MockMimeLookup.setInstances(
            MimePath.get(MIME_JAVA),    //NOI18N
            new JavaCustomIndexer.Factory(),
            new JavacParserFactory());
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    cache = FileUtil.createFolder(wd, "cache"); //NOI18N
    final File srcDir = FileUtil.normalizeFile(new File(getWorkDir(),"src"));
    srcDir.mkdirs();
    File[] fos = prepareContent(srcDir);
    lfs = new OrderedFS(new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            final int e1 = rank(FileObjects.getExtension(o1));
            final int e2 = rank(FileObjects.getExtension(o2));
            int res = e1 - e2;
            if (res == 0) {
                res = o1.compareTo(o2);
            }
            return res;
        }

        private int rank(String ext) {
            switch (ext) {
                case FileObjects.CLASS:
                    return 0;
                case FileObjects.JAVA:
                    return 1;
                default:
                    return 2;
            }
        }
    });
    lfs.setRootDirectory(srcDir);
    Repository.getDefault().addFileSystem(lfs);
    src = lfs.getRoot();
    CacheFolder.setCacheFolder(cache);
    java = FileUtil.toFileObject(fos[0]);
    clz = FileUtil.toFileObject(fos[1]);
    FileUtil.setMIMEType(FileObjects.CLASS, MIME_CLASS);
    FileUtil.setMIMEType(FileObjects.JAVA, MIME_JAVA);
    Lookup.getDefault().lookup(CPProvider.class).configure(src);
    Lookup.getDefault().lookup(SLQ.class).configure(src);
    super.setUp();
}