Java Code Examples for org.openide.filesystems.FileObject#createData()

The following examples show how to use org.openide.filesystems.FileObject#createData() . 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: VCSInterceptorTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testIsLockedDoesntInvokeBeforeEdit() throws IOException {
    FileObject fo = getVersionedFolder();
    fo = fo.createData(TestVCS.ALWAYS_WRITABLE_PREFIX);
    VCSFileProxy proxy = VCSFileProxy.createFileProxy(fo);
    VCSFilesystemTestFactory.getInstance(this).setReadOnly(getRelativePath(proxy));
    logHandler.clear();
    
    assertFalse(fo.isLocked());
    List<VCSFileProxy> beforeEditFiles = inteceptor.getBeforeEditFiles();
    if(!inteceptor.getBeforeEditFiles().isEmpty()) {
        StringBuilder sb = new StringBuilder();
        sb.append("Not expected beforeEdit() intercepted for file(s): ");
        for (int i = 0; i < beforeEditFiles.size(); i++) {
            VCSFileProxy file = beforeEditFiles.get(i);
            sb.append(file.getName());
            if(i < beforeEditFiles.size() - 1) {
                sb.append(",");
            }
        }
        fail(sb.toString());
    }
}
 
Example 2
Source File: VCSInterceptorTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testFileCreateVersioned() throws IOException {
    FileObject fo = getVersionedFolder();
    logHandler.clear();
            
    fo = fo.createData("checkme.txt");
    VCSFileProxy proxy = VCSFileProxy.createFileProxy(fo);
    
    assertTrue(inteceptor.getBeforeCreateFiles().contains(proxy));
    assertTrue(inteceptor.getDoCreateFiles().contains(proxy));
    assertTrue(inteceptor.getCreatedFiles().contains(proxy));
    
    assertInterceptedCalls(
        f(beforeCreateFormat, proxy.getParentFile(), proxy.getName(), false),
        f(createSuccessFormat, proxy)
    );
}
 
Example 3
Source File: FreeformSharabilityQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSharability() throws Exception {
FreeformProject prj = copyProject(simple);
FileObject nbproject = prj.getProjectDirectory().getFileObject("nbproject");
FileObject nbprojectProjectXML = nbproject.getFileObject("project.xml");
FileObject nbprojectPrivate = nbproject.createFolder("private");
FileObject nbprojectPrivatePrivateXML = nbprojectPrivate.createData("private.xml");
FileObject src = prj.getProjectDirectory().getFileObject("src");
FileObject myAppJava = src.getFileObject("org/foo/myapp/MyApp.java");
FileObject buildXML = prj.getProjectDirectory().getFileObject("build.xml");

assertNotNull(nbproject);
assertNotNull(nbprojectProjectXML);
assertNotNull(nbprojectPrivate);
assertNotNull(nbprojectPrivatePrivateXML);
assertNotNull(src);
assertNotNull(myAppJava);
assertNotNull(buildXML);

assertEquals(SharabilityQuery.Sharability.MIXED, SharabilityQuery.getSharability(nbproject));
assertEquals(SharabilityQuery.Sharability.SHARABLE, SharabilityQuery.getSharability(nbprojectProjectXML));
assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, SharabilityQuery.getSharability(nbprojectPrivate));
assertEquals(SharabilityQuery.Sharability.NOT_SHARABLE, SharabilityQuery.getSharability(nbprojectPrivatePrivateXML));
assertEquals(SharabilityQuery.Sharability.UNKNOWN, SharabilityQuery.getSharability(src));
assertEquals(SharabilityQuery.Sharability.UNKNOWN, SharabilityQuery.getSharability(myAppJava));
assertEquals(SharabilityQuery.Sharability.UNKNOWN, SharabilityQuery.getSharability(buildXML));
   }
 
Example 4
Source File: RecentFilesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void test87252 () throws Exception {
    System.out.println("Testing fix for 87252...");
    URL url = RecentFilesTest.class.getResource("resources/recent_files/");
    assertNotNull("url not found.", url);
    
    FileObject folder = URLMapper.findFileObject(url);
    FileObject fo = folder.createData("ToBeDeleted.txt");
    
    EditorLikeTC tc = new EditorLikeTC(fo);
    tc.open();
    waitHandler.waitUntilStored();
    tc.close();
    waitHandler.waitUntilStored();
    
    // delete file and check that recent files *doesn't* contain the file
    fo.delete();
    List<HistoryItem> recentFiles = RecentFiles.getRecentFiles();
    boolean contained = false;
    for (HistoryItem historyItem : recentFiles) {
        if (fo.equals(RecentFiles.convertPath2File(historyItem.getPath()))) {
            contained = true;
            break;
        }
    }
    assertFalse("Deleted file should not be in recent files", contained);
}
 
Example 5
Source File: FileObjTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tests it is not possible to create duplicate FileObject for the same path.
 * - create FO1
 * - create FO2
 * - delete FO1 => FO1 is invalid now
 * - rename FO2 to FO1
 * - rename FO1 to FO1 => FO1 still invalid
 * - try to write to FO1.getOutputStream() => it should not be possible because FO1 is still invalid
 */
public void testDuplicateFileObject130998() throws IOException {
    clearWorkDir();
    FileObject testFolder = FileUtil.toFileObject(getWorkDir());
    FileObject fileObject1 = testFolder.createData("fileObject1");
    FileObject fileObject2 = testFolder.createData("fileObject2");
    fileObject1.delete();
    assertFalse("fileObject1 should be invalid after delete.", fileObject1.isValid());

    FileLock lock = fileObject2.lock();
    fileObject2.rename(lock, fileObject1.getName(), null);
    lock.releaseLock();
    assertTrue("fileObject2 should be valid.", fileObject2.isValid());

    lock = fileObject1.lock();
    fileObject1.rename(lock, fileObject1.getName(), null);
    lock.releaseLock();
    assertFalse("fileObject1 should remain invalid after rename.", fileObject1.isValid());
    
    OutputStream os = fileObject1.getOutputStream();
    assertTrue("Valid file", FileUtil.toFile(fileObject1).exists());
    assertFalse("Invalid file object", fileObject1.isValid());
    assertNotNull("Since #211483 it is possible to obtain OutputStream for valid file/invalid fo", os);
}
 
Example 6
Source File: TestUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static FileObject copyResource(String path, FileObject destFolder) throws Exception {
    String filename = getFileName(path);
    
    FileObject dest = destFolder.getFileObject(filename);
    if (dest == null) {
        dest = destFolder.createData(filename);
    }
    FileLock lock = dest.lock();
    OutputStream out = dest.getOutputStream(lock);
    InputStream in = TestUtil.class.getResourceAsStream(path);
    try {
        FileUtil.copy(in, out);
    } finally {
        out.close();
        in.close();
        if (lock != null) lock.releaseLock();
    }
    return dest;
}
 
Example 7
Source File: PageFlowControllerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test of isKnownFile method, of class PageFlowController.
 */
public void testIsKnownFile() throws IOException {
    System.out.println("isKnownFile");


    controller.unregisterListeners();
    FileObject webFolder = PageFlowView.getWebFolder(tu.getJsfDO().getPrimaryFile());
    String strNewPage = "newPage";
    FileObject newFO = webFolder.createData(strNewPage, "jsp");
    boolean result = controller.isKnownFile(newFO);
    assertTrue(result);
}
 
Example 8
Source File: VCSInterceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIsMutable() throws IOException {
    File f = new File(dataRootDir, "workdir/root-test-versioned");
    FileObject fo = FileUtil.toFileObject(f);
    fo = fo.createData("checkme.txt");
    File file = FileUtil.toFile(fo);
    fo.canWrite();
    assertTrue(inteceptor.getBeforeCreateFiles().contains(file));
    assertTrue(inteceptor.getDoCreateFiles().contains(file));
    assertTrue(inteceptor.getCreatedFiles().contains(file));
    assertFalse(inteceptor.getIsMutableFiles().contains(file));
    
    file.setReadOnly();
    fo.canWrite();
    assertTrue(inteceptor.getIsMutableFiles().contains(file));
}
 
Example 9
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testBug128234() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    FileObject fo = workDirFo.createData("a");
    assertNotNull(fo);
    File f = FileUtil.toFile(fo);
    assertNotNull(f);
    FileUtil.toFileObject(new File(f,f.getName()));
}
 
Example 10
Source File: FolderObjTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test of createData method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testCreateData() throws Exception {
    File f = testFile;

    final FileObject fo = FileBasedFileSystem.getFileObject(f);
    
    File f2 = new File (testFile, "newdatacreated.txt");
    final FileObject nfo = fo.createData (f2.getName());
    assertNotNull(nfo);
    assertTrue(nfo.isData());
    File nfile = ((BaseFileObj)nfo).getFileName().getFile ();
    assertEquals(nfo.getClass(), FileBasedFileSystem.getFileObject(nfile).getClass());
    assertSame(nfo, FileBasedFileSystem.getFileObject(nfile));
    /*if (nfo.getParent() != fo) {
        nfo.getParent();
    }*/
    System.gc();System.gc();System.gc();System.gc();System.gc();System.gc();
    FileObject pp = nfo.getParent();
    assertEquals(((BaseFileObj)pp).getFileName().getFile(), ((BaseFileObj)fo).getFileName().getFile());
    assertEquals(((BaseFileObj)pp).getFileName().getId(), ((BaseFileObj)fo).getFileName().getId());
    
    assertSame(((BaseFileObj)fo).getFileName().getId() + " | " + ((BaseFileObj)nfo.getParent()).getFileName().getId(), fo, pp);        
    
    try {
        FileObject nfo2 = fo.createData (f2.getName());    
        fail ();
    } catch (IOException iox) {
        
    }
}
 
Example 11
Source File: SourceUtilsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGetFile () throws Exception {
    File workDir = getWorkDir();
    FileObject workFo = FileUtil.toFileObject(workDir);
    assertNotNull (workFo);
    FileObject src = workFo.createFolder("src");
    FileObject userDir = workFo.createFolder("ud");
    CacheFolder.setCacheFolder(userDir);
    
    ensureRootValid(src.getURL());
    
    FileObject srcInDefPkg = src.createData("Foo","java");
    assertNotNull(srcInDefPkg);
    FileObject sourceFile = src.createFolder("org").createFolder("me").createData("Test", "java");
    assertNotNull(sourceFile);
    ClasspathInfo cpInfo = ClasspathInfo.create(ClassPathSupport.createClassPath(new FileObject[0]), ClassPathSupport.createClassPath(new FileObject[0]),
        ClassPathSupport.createClassPath(new FileObject[]{src}));
    FileObject cls = ClasspathInfoAccessor.getINSTANCE().getCachedClassPath(cpInfo,PathKind.OUTPUT).getRoots()[0];
    FileObject classInDefPkg = cls.createData("Foo","class");
    assertNotNull(classInDefPkg);
    FileObject classPkg = cls.createFolder("org").createFolder("me");
    assertNotNull(classPkg);
    FileObject classFile = classPkg.createData("Test", "class");
    assertNotNull(classFile);
    FileObject classFileInnder = classPkg.createData("Test$Inner", "class");
    assertNotNull(classFileInnder);        
    SFBQImpl.getDefault().register(cls, src);
    ElementHandle<? extends Element> handle = ElementHandle.createTypeElementHandle(ElementKind.CLASS, "org.me.Test");
    assertNotNull (handle);        
    FileObject result = SourceUtils.getFile(handle, cpInfo);
    assertNotNull(result);
    handle = ElementHandle.createTypeElementHandle(ElementKind.CLASS, "org.me.Test$Inner");
    result = SourceUtils.getFile(handle,cpInfo);
    assertNotNull(result);
    handle = ElementHandle.createPackageElementHandle("org.me");
    result = SourceUtils.getFile(handle,cpInfo);
    assertNotNull(result);
    handle = ElementHandle.createTypeElementHandle(ElementKind.CLASS, "Foo");
    result = SourceUtils.getFile(handle,cpInfo);
    assertNotNull(result);
}
 
Example 12
Source File: ProviderRegistryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testDynamicGetProviders () throws Exception {
    UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/navigator/resources/testGetProvidersLayer.xml" });
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject file1 = root.createData("1");
    FileObject file2 = root.createData("2");
    Lookup checkingProvider = Lookups.singleton(new DynamicRegistration() {
        @Override
        public Collection<? extends NavigatorPanel> panelsFor(URI file) {
            return file1.toURI().equals(file) ? Collections.singletonList(new MarvelousDataTypeProvider())
                                              : Collections.emptyList();
        }
    });
    Lookups.executeWith(new ProxyLookup(Lookup.getDefault(), checkingProvider), () -> {
        ProviderRegistry providerReg = ProviderRegistry.getInstance();

        System.out.println("Asking for masked out file...");
        assertEquals(0, providerReg.getProviders("image/non_existent_type", file2).size());

        System.out.println("Asking for valid file...");
        Collection<? extends NavigatorPanel> result = providerReg.getProviders("image/non_existent_type", file1);
        assertEquals(1, result.size());
        NavigatorPanel np = result.iterator().next();
        assertTrue(np instanceof MarvelousDataTypeProvider);
        MarvelousDataTypeProvider provider = (MarvelousDataTypeProvider)np;
        assertEquals(MARVELOUS_DATA_TYPE_NAME, provider.getDisplayName());
    });
}
 
Example 13
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void createNewFile() throws Exception {
    // init
    File file = new File(wc, "file");
    
    // create
    FileObject fo = FileUtil.toFileObject(wc);
    fo.createData(file.getName());
                                    
    // test 
    assertTrue(file.exists());
    
    assertEquals(SVNStatusKind.UNVERSIONED, getSVNStatus(file).getTextStatus());        
    assertCachedStatus(file, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY);                
}
 
Example 14
Source File: DataShadowTranslateTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks translation on Shadows, which use FS name + path, not URI
 * @throws Exception 
 */
public void testFSNameAndPath() throws Exception {
    FileObject fo = FileUtil.getConfigRoot();
    
    FileObject origDir = fo.createFolder("origFolder3");
    
    // create empty real file with special and non-ASCII chars
    FileObject newFile = origDir.createData("moved-here.txt");
    
    // createa a fake file, just to get its URI right:
    FileObject fake = fo.createData("dead-file-location.old");
    
    final FileObject d = fo.createFolder("subfolder3");
    OutputStream ostm = d.createAndOpen("regularShadowURI.shadow");
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    bw.write(fake.getPath());
    bw.newLine();
    bw.write(fake.getFileSystem().getSystemName());
    bw.newLine();
    
    fake.delete();
    
    bw.close();
    
    FileObject fob = d.getFileObject("regularShadowURI.shadow");
    DataObject dd = DataObject.find(fob);
    
    assertTrue("Shadow must be translated, not broken", dd instanceof DataShadow);
    
    DataShadow ds = (DataShadow)dd;
    assertEquals("Shadow's original must be on the translated location", newFile, ds.getOriginal().getPrimaryFile());
}
 
Example 15
Source File: IndentFileEntry.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Creates a new Java source from the template. Unlike the standard FileEntry.Format,
       this indents the resulting text using an indentation engine.
   */
   @Override
   public FileObject createFromTemplate (FileObject f, String name) throws IOException {
       String ext = getFile ().getExt ();

       if (name == null) {
           name = FileUtil.findFreeFileName(f, getFile ().getName (), ext);
       }
       FileObject fo = f.createData (name, ext);
       java.text.Format frm = createFormat (f, name, ext);
       InputStream is=getFile ().getInputStream ();
       Charset encoding = FileEncodingQuery.getEncoding(getFile());
       Reader reader = new InputStreamReader(is,encoding);
       BufferedReader r = new BufferedReader (reader);
       StyledDocument doc = createDocument(createEditorKit(fo.getMIMEType()));
       IndentEngine eng = (IndentEngine)indentEngine.get();
       if (eng == null) eng = IndentEngine.find(doc);
       Object attr = getFile().getAttribute(EA_PREFORMATTED);
       boolean preformatted = false;
       
       if (attr != null && attr instanceof Boolean) {
           preformatted = ((Boolean)attr).booleanValue();
       }

       try {
           FileLock lock = fo.lock ();
           try {
               encoding = FileEncodingQuery.getEncoding(fo);
               OutputStream os=fo.getOutputStream(lock);
               OutputStreamWriter w = new OutputStreamWriter(os, encoding);
               try {
                   String line = null;
                   String current;
                   int offset = 0;

                   while ((current = r.readLine ()) != null) {
                       if (line != null) {
                           // newline between lines
                           doc.insertString(offset, NEWLINE, null);
                           offset++;
                       }
                       line = frm.format (current);

                       // partial indentation used only for pre-formatted sources
                       // see #19178 etc.
                       if (!preformatted || !line.equals(current)) {
                           line = fixupGuardedBlocks(safeIndent(eng, line, doc, offset));
                       }
                       doc.insertString(offset, line, null);
                           offset += line.length();
                   }
                   doc.insertString(doc.getLength(), NEWLINE, null);
                   w.write(doc.getText(0, doc.getLength()));
               } catch (javax.swing.text.BadLocationException e) {
               } finally {
                   w.close ();
               }
           } finally {
               lock.releaseLock ();
           }
       } finally {
           r.close ();
       }
       // copy attributes
       FileUtil.copyAttributes (getFile (), fo);
// hack to overcome package-private modifier in setTemplate(fo, boolean)
       fo.setAttribute(DataObject.PROP_TEMPLATE, null);
       return fo;
   }
 
Example 16
Source File: TimesCollectorPeerTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testHandleDelete() throws Exception {
    FileObject dir  = makeScratchDir(this);
    FileObject file = dir.createData("test.txt");
    
    TimesCollectorPeer.getDefault().reportTime(file, "test", "test", 0);
    
    file.delete();
    
    assertTrue(TimesCollectorPeer.getDefault().getFiles().isEmpty());
    
    JFrame f = new JFrame();
    
    f.add(new TimeComponentPanel());
    
    f.setVisible(true);
    
    file = dir.createData("test.txt");
    
    TimesCollectorPeer.getDefault().reportTime(file, "test", "test", 0);
    
    file.delete();
}
 
Example 17
Source File: AbstractGitTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected File createFile(File parent, String name) throws IOException {
    FileObject parentFO = FileUtil.toFileObject(parent);
    FileObject fo = parentFO.createData(name);
    return FileUtil.toFile(fo);
}
 
Example 18
Source File: J2SEActionProviderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected @Override void setUp() throws Exception {
        super.setUp();
        MockLookup.setLayersAndInstances(new SimplePlatformProvider());
        scratch = TestUtil.makeScratchDir(this);
        projdir = scratch.createFolder("proj");
        J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.6"));   //NOI18N
        helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj","foo.Main","manifest.mf",null, false); //NOI18N
        EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
        ep.put(ProjectProperties.DO_DEPEND, "true"); // to avoid too many changes in tests from issue #118079       
        helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
        J2SEProjectGenerator.setDefaultSourceLevel(null);
        pm = ProjectManager.getDefault();
        pp = pm.findProject(projdir).getLookup().lookup(J2SEProject.class);
        actionProvider = new J2SEActionProvider(pp, pp.getUpdateHelper());
        actionProvider.startFSListener();
        sources = projdir.getFileObject("src");
        tests = projdir.getFileObject("test");
//        projdir.createData("build.xml");
        build = projdir.createFolder("build");
        build.createFolder("classes");
        FileObject pkg = sources.getFileObject("foo");        
        FileObject fo = pkg.createData("Bar.java");
        sourcePkg1 = DataFolder.findFolder (pkg);
        pkg = sources.createFolder("foo2");
        sourcePkg2 = DataFolder.findFolder (pkg);
        someSource1 = DataObject.find(fo);
        fo = sources.getFileObject("foo").getFileObject("Main.java");
        createMain(fo);
        someSource2 = DataObject.find(fo);
        fo = sources.getFileObject("foo").createData("Third.java");
        someSource3 = DataObject.find(fo);
        pkg = tests.createFolder("foo");
        fo = pkg.createData("BarTest.java");
        testPkg1 = DataFolder.findFolder (pkg);
        pkg = tests.createFolder("foo2");
        testPkg2 = DataFolder.findFolder (pkg);
        someTest1 = DataObject.find(fo);
        fo = tests.getFileObject("foo").createData("MainTest.java");
        someTest2 = DataObject.find(fo);
        assertNotNull(someSource1);
        assertNotNull(someSource2);
        assertNotNull(someTest1);
        assertNotNull(someTest2);
    }
 
Example 19
Source File: DerbyRegistration.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static int registerDerbyInstallation(String cluster, String derbyHome) throws IOException {
    LOGGER.log(Level.FINE, "Cluster for JavaDB registration is " + cluster);
    System.setProperty("netbeans.user", cluster); // NOI18N
    // check writable cluster
    FileObject javaDBRegistrationDir = FileUtil.getConfigFile(DERBY_REGISTRATION_DIR);

    if (javaDBRegistrationDir == null) {
        javaDBRegistrationDir = FileUtil.createFolder(FileUtil.getConfigRoot(), DERBY_REGISTRATION_DIR);
        if (javaDBRegistrationDir == null) {
            LOGGER.log(Level.INFO, "Cannot register the default JavaDB. The config/" + DERBY_REGISTRATION_DIR + " folder cannot be created."); // NOI18N
            return 2;
        }
    }

    // check if exists
    File derbyHomeFile = new File(derbyHome);
    if (!derbyHomeFile.exists()) {
        LOGGER.log(Level.INFO, "Cannot register the default JavaDB. " // NOI18N
                + "The JavaDB installation directory " + derbyHome // NOI18N
                + " does not exist."); // NOI18N
        return 3;
    }

    // check if solid JavaDB home
    if (! Util.isDerbyInstallLocation(derbyHomeFile)) {
        LOGGER.log(Level.INFO, "Cannot register the default JavaDB. " // NOI18N
                + "The JavaDB installation directory " + derbyHome // NOI18N
                + " does not contain expected libraries."); // NOI18N
        return 4;
    }

    FileObject registrationFO = FileUtil.getConfigFile(DERBY_REGISTRATION_DIR + "/" + DERBY_REGISTRATION_FILE); // NOI18N
    if (registrationFO == null) {
        try {
            registrationFO = javaDBRegistrationDir.createData(DERBY_REGISTRATION_FILE);
            registrationFO.setAttribute(ATTR_DERBY_HOME, derbyHome);
            LOGGER.log(Level.FINE, "New registration links to " + registrationFO.getAttribute(ATTR_DERBY_HOME)); // NOI18N
        } catch (IOException e) {
            LOGGER.log(Level.INFO, "Cannot register JavaDB, cause " + e.getLocalizedMessage(), e); // NOI18N
            return 5;
        }
    } else {
        LOGGER.log(Level.INFO, "The previous registration found. Links to " + registrationFO.getAttribute(ATTR_DERBY_HOME)); // NOI18N
    }

    return 0;
}
 
Example 20
Source File: CompoundSearchInfoTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testMultipleItemsList() throws IOException {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject fsRoot = fs.getRoot();
    
    FileObject dir1 = fsRoot.createFolder("dir1");
    dir1.createData("1a", DummyDataLoader.dummyExt);
    dir1.createData("1b", DummyDataLoader.dummyExt);
    dir1.createData("1c", DummyDataLoader.dummyExt);
    DataFolder folder1 = DataFolder.findFolder(dir1);
    
    FileObject dir2 = fsRoot.createFolder("dir2");
    dir2.createData("2a", DummyDataLoader.dummyExt);
    dir2.createData("2b", DummyDataLoader.dummyExt);
    DataFolder folder2 = DataFolder.findFolder(dir2);
    
    
    SearchInfo refSearchInfo1, refSearchInfo2;
    SearchInfo testSearchInfo;
    Iterator refIt;
    Iterator testIt;
    
    refSearchInfo1 = new SimpleSearchInfo(folder1, false, null);
    refSearchInfo2 = new SimpleSearchInfo(folder2, false, null);
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo1,
                                                              refSearchInfo2});
    assertTrue(testSearchInfo.canSearch());
    

    Set testSet = new HashSet();
    for(testIt = testSearchInfo.objectsToSearch(); testIt.hasNext();){
        testSet.add(testIt.next());
    }
    refIt = refSearchInfo1.objectsToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    refIt = refSearchInfo2.objectsToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    
    assertTrue(testSet.isEmpty());
    
    refSearchInfo1 = new SimpleSearchInfo(folder1, false, null);
    refSearchInfo2 = new SimpleSearchInfo(folder2, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo1,
                                                              refSearchInfo2});
    assertTrue(testSearchInfo.canSearch());
    
    testSet.clear();
    for(testIt = testSearchInfo.objectsToSearch(); testIt.hasNext();){
        testSet.add(testIt.next());
    }
    refIt = refSearchInfo1.objectsToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    assertTrue(testSet.isEmpty());
    
    
    refSearchInfo1 = new SimpleSearchInfo(folder1, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    refSearchInfo2 = new SimpleSearchInfo(folder2, false, null);
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo1,
                                                              refSearchInfo2});
    assertTrue(testSearchInfo.canSearch());
    
    testSet.clear();
    for(testIt = testSearchInfo.objectsToSearch(); testIt.hasNext();){
        testSet.add(testIt.next());
    }
    refIt = refSearchInfo2.objectsToSearch();
    while (refIt.hasNext()) {
        assertTrue(testSet.remove(refIt.next()));
    }
    assertTrue(testSet.isEmpty());
    
    
    refSearchInfo1 = new SimpleSearchInfo(folder1, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    refSearchInfo2 = new SimpleSearchInfo(folder2, false, null) {
        public boolean canSearch() {
            return false;
        }
    };
    testSearchInfo = new CompoundSearchInfo(new SearchInfo[] {refSearchInfo1,
                                                              refSearchInfo2});
    assertFalse(testSearchInfo.canSearch());
}