Java Code Examples for org.openide.filesystems.FileUtil#refreshFor()
The following examples show how to use
org.openide.filesystems.FileUtil#refreshFor() .
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: CompileWorkerTestBase.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { SourceUtilsTestUtil.prepareTest(new String[0], new Object[] {new SourceLevelQueryImpl()}); clearWorkDir(); File wdFile = getWorkDir(); FileUtil.refreshFor(wdFile); FileObject wd = FileUtil.toFileObject(wdFile); assertNotNull(wd); src = FileUtil.createFolder(wd, "src"); extraSrc = FileUtil.createFolder(wd, "extraSrc"); FileObject buildRoot = FileUtil.createFolder(wd, "build"); FileObject cache = FileUtil.createFolder(wd, "cache"); ClassPath sourcePath = ClassPathSupport.createClassPath(src, extraSrc); SourceUtilsTestUtil.prepareTest(sourcePath, buildRoot, cache, new FileObject[0]); }
Example 2
Source File: ClassPathProviderImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testExecuteCPOnClassesDir() throws Exception { InstalledFileLocatorImpl.registerDestDir(destDirF); TestAntLogger.getDefault().setEnabled(true); NbModuleProject prj = TestBase.generateStandaloneModule(getWorkDir(), "testing"); prj.open(); FileObject buildScript = prj.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); assertNotNull(buildScript); ExecutorTask et = ActionUtils.runTarget(buildScript, new String[]{"compile"}, null); et.waitFinished(); assertEquals("Error during ant ...",0,et.result()); TestAntLogger.getDefault().setEnabled(false); File classesF = prj.getClassesDirectory(); assertTrue("Classes dir of testing project should exist", classesF.exists()); FileUtil.refreshFor(classesF); // XXX seems necessary occasionally on deadlock - why? FileObject classes = FileUtil.toFileObject(classesF); assertNotNull(classes); ClassPath cp = ClassPath.getClassPath(classes, ClassPath.EXECUTE); assertNotNull("have exec CP for " + classes, cp); Set<String> expectedRoots = new TreeSet<String>(); expectedRoots.add(FileUtil.urlForArchiveOrDir(classesF).toExternalForm()); assertEquals("right compiled EXECUTE classpath", expectedRoots, urlsOfCp(cp)); }
Example 3
Source File: RevisionSetupSupportTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp () throws Exception { super.setUp(); workDir = getWorkDir(); clearWorkDir(); FileUtil.refreshFor(workDir); wc = new File(workDir, getName() + "_wc"); repoDir = new File(workDir, "repo"); String repoPath = repoDir.getAbsolutePath(); if(repoPath.startsWith("/")) repoPath = repoPath.substring(1, repoPath.length()); repoUrl = new SVNUrl("file:///" + repoPath); System.setProperty("netbeans.user", getDataDir() + "/userdir"); cleanUpWC(wc); TestKit.initRepo(repoDir, wc); TestKit.svnimport(repoDir, wc); wc.mkdirs(); }
Example 4
Source File: InteceptorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void afterDelete_AfterCreate_194998 () throws Exception { // init File file = new File(wc, "file"); // create FileObject fo = FileUtil.toFileObject(wc); fo.createData(file.getName()); add(file); commit(file); // test assertTrue(file.exists()); assertEquals(SVNStatusKind.NORMAL, getSVNStatus(file).getTextStatus()); file.delete(); FileUtil.refreshFor(file); assertEquals(SVNStatusKind.MISSING, getSVNStatus(file).getTextStatus()); assertCachedStatus(file, FileInformation.STATUS_VERSIONED_DELETEDLOCALLY); TestKit.write(file, "modification"); FileUtil.refreshFor(file.getParentFile()); assertCachedStatus(file, FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY_CONTENT); assertEquals(SVNStatusKind.MODIFIED, getSVNStatus(file).getTextStatus()); }
Example 5
Source File: XMLSuiteSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static File createSuiteforMethod(File targetFolder, String projectName, String pkgName, String className, String methodName) { if (!targetFolder.isDirectory()) { throw new IllegalArgumentException(targetFolder.getAbsolutePath() + " is not a directory"); //NOI18N } Map<String, Collection<String>> classes = new HashMap<String, Collection<String>>(); Set<String> methods = null; if (methodName != null) { methods = new HashSet<String>(); methods.add(methodName); } pkgName = pkgName.trim(); classes.put("".equals(pkgName) ? className : pkgName + "." + className, methods); //NOI18N LaunchSuite suite = SuiteGenerator.createSuite(projectName, null, classes, null, null, null, 1); File f = suite.save(targetFolder); FileUtil.refreshFor(targetFolder); return f; }
Example 6
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 6 votes |
private void failIfRefreshed (HgProgressSupport supp) throws Exception { InterceptorRefreshHandler handler = new InterceptorRefreshHandler(); Mercurial.STATUS_LOG.addHandler(handler); FileUtil.refreshFor(workdir); RequestProcessor.Task task = supp == null ? null : supp.start(RequestProcessor.getDefault()); for (int i = 0; i < 25; ++i) { Thread.sleep(1000); if (handler.refreshed) { fail("cache refresh started: " + handler.refreshString); } } if (task != null) { task.waitFinished(); } Mercurial.STATUS_LOG.removeHandler(handler); }
Example 7
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testExternalCommandLoggedChanges () throws Exception { Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); File toAdd = new File(modifiedFile.getParentFile(), "toAdd"); File toDelete = new File(modifiedFile.getParentFile(), "toDelete"); toDelete.createNewFile(); FileUtil.refreshFor(workdir); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File hgFolder = new File(workdir, ".hg"); final File lockFile = new File(hgFolder, "wlock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); createLockFile(lockFile); FileUtil.refreshFor(workdir); // modification write(modifiedFile, "testExternalCommandLoggedChanges"); // delete toDelete.delete(); // create toAdd.createNewFile(); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("HG", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(3), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example 8
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
@RandomlyFails public void testLogExtCmd () throws Exception { waitForInitialScan(); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); FileUtil.refreshFor(repositoryLocation); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File gitFolder = new File(repositoryLocation, ".git"); final File lockFile = new File(gitFolder, "index.lock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); lockFile.createNewFile(); FileUtil.refreshFor(repositoryLocation); pause(); lockFile.delete(); FileUtil.refreshFor(repositoryLocation); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("GIT", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(0), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example 9
Source File: RefreshPhpModuleRunnable.java From netbeans with Apache License 2.0 | 5 votes |
private void refresh(FileObject fo) { if (fo == null) { return; } File file = FileUtil.toFile(fo); if (file != null) { FileUtil.refreshFor(file); } else { // just defensive fallback fo.refresh(); } }
Example 10
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testExternalCommandLoggedNoChanges () throws Exception { Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); FileUtil.refreshFor(workdir); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File hgFolder = new File(workdir, ".hg"); final File lockFile = new File(hgFolder, "wlock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); lockFile.createNewFile(); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("HG", h.event.vcs); assertEquals("UNKNOWN", h.event.command); assertTrue(h.event.external); assertEquals(Long.valueOf(0), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example 11
Source File: InteceptorTest.java From netbeans with Apache License 2.0 | 5 votes |
public void deleteVersionedFileExternally() throws Exception { // init File file = new File(wc, "file"); FileUtil.toFileObject(wc).createData(file.getName()); assertCachedStatus(file, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY); commit(wc); assertEquals(SVNStatusKind.NORMAL, getSVNStatus(file).getTextStatus()); assertEquals(FileInformation.STATUS_VERSIONED_UPTODATE, getStatus(file)); String prop = System.getProperty("org.netbeans.modules.subversion.deleteMissingFiles", ""); try { System.setProperty("org.netbeans.modules.subversion.deleteMissingFiles", "true"); // delete externally file.delete(); // test assertFalse(file.exists()); assertEquals(SVNStatusKind.MISSING, getSVNStatus(file).getTextStatus()); // notify changes FileUtil.refreshFor(file); assertCachedStatus(file, FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY); } finally { System.setProperty("org.netbeans.modules.subversion.deleteMissingFiles", prop); } assertEquals(SVNStatusKind.DELETED, getSVNStatus(file).getTextStatus()); commit(wc); assertEquals(SVNStatusKind.UNVERSIONED, getSVNStatus(file).getTextStatus()); }
Example 12
Source File: RefreshProjectRunnable.java From netbeans with Apache License 2.0 | 5 votes |
public void run() { FileObject fo = project.getProjectDirectory(); File file = FileUtil.toFile(fo); if (file != null) { FileUtil.refreshFor(file); } else { // just defensive fallback fo.refresh(); } }
Example 13
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 5 votes |
private void waitForRefresh () throws Exception { InterceptorRefreshHandler handler = new InterceptorRefreshHandler(); Git.STATUS_LOG.addHandler(handler); FileUtil.refreshFor(repositoryLocation); for (int i=0; i<20; ++i) { Thread.sleep(1000); if (handler.refreshed) { break; } } if (!handler.refreshed) { fail("cache not refreshed"); } Git.STATUS_LOG.removeHandler(handler); }
Example 14
Source File: FileObjectFactoryTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testRefreshForNotExisting() throws Exception { EventsEvaluator fdc = new EventsEvaluator(); try { File workDir = getWorkDir(); File external = new File(workDir, "externalFile"); assertFalse(external.exists()); fdc.assertDataCreated(0); FileUtil.refreshFor(external); fdc.assertDataCreated(0); } finally { fdc.cleanUp(); } }
Example 15
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testInternalCommandLoggedChangesAfterUnlock () throws Exception { Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); final File toAdd = new File(modifiedFile.getParentFile(), "toAdd"); final File toDelete = new File(modifiedFile.getParentFile(), "toDelete"); toDelete.createNewFile(); FileUtil.refreshFor(workdir); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File hgFolder = new File(workdir, ".hg"); final File lockFile = new File(hgFolder, "wlock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); Mercurial.getInstance().runWithoutExternalEvents(workdir, "MY_COMMAND", new Callable<Void>() { @Override public Void call () throws Exception { // modification write(modifiedFile, "testExternalCommandLoggedChanges"); // delete toDelete.delete(); // create toAdd.createNewFile(); FileUtil.refreshFor(workdir); pause(); return null; } }); Thread.sleep(2000); // coming with delay after some time // still considered as part of internal command createLockFile(lockFile); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("HG", h.event.vcs); assertFalse(h.event.external); assertEquals("MY_COMMAND", h.event.command); assertEquals(Long.valueOf(3), h.event.modifications); Thread.sleep(9000); // coming after some reasonable pause, now considered as part of next external command createLockFile(lockFile); FileUtil.refreshFor(workdir); write(modifiedFile, "anotherchange"); FileUtil.refreshFor(workdir); pause(); lockFile.delete(); FileUtil.refreshFor(workdir); h.event = null; h.waitForEvent(); assertNotNull(h.event); assertEquals(2, h.numberOfEvents); assertEquals("HG", h.event.vcs); assertTrue(h.event.external); assertEquals("UNKNOWN", h.event.command); assertEquals(Long.valueOf(1), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example 16
Source File: BowerJsonTest.java From netbeans with Apache License 2.0 | 4 votes |
private void refreshForFile(File file) { FileUtil.refreshFor(file.getParentFile()); }
Example 17
Source File: Utilities.java From netbeans with Apache License 2.0 | 4 votes |
/** * attempts to save the document model to disk. * if model is in transaction, the transaction is ended first, * then dataobject's SaveCookie is called. * * @param model * @throws java.io.IOException if saving fails. */ public static void saveChanges(AbstractDocumentModel<?> model) throws IOException { if (model.isIntransaction()) { // the ISE thrown from endTransction is handled in performPOMModelOperations. model.endTransaction(); } model.sync(); DataObject dobj = model.getModelSource().getLookup().lookup(DataObject.class); if (dobj == null) { final Document doc = model.getModelSource().getLookup().lookup(Document.class); final File file = model.getModelSource().getLookup().lookup(File.class); logger.log(Level.FINE, "saving changes in {0}", file); File parent = file.getParentFile(); FileObject parentFo = FileUtil.toFileObject(parent); if (parentFo == null) { parent.mkdirs(); FileUtil.refreshFor(parent); parentFo = FileUtil.toFileObject(parent); } final FileObject fParentFo = parentFo; if (fParentFo != null) { FileSystem fs = parentFo.getFileSystem(); fs.runAtomicAction(new FileSystem.AtomicAction() { public @Override void run() throws IOException { String text; try { text = doc.getText(0, doc.getLength()); } catch (BadLocationException x) { throw new IOException(x); } FileObject fo = fParentFo.getFileObject(file.getName()); if (fo == null) { fo = fParentFo.createData(file.getName()); } OutputStream os = fo.getOutputStream(); try { os.write(text.getBytes("UTF-8")); } finally { os.close(); } } }); } else { //TODO report } } else { SaveCookie save = dobj.getLookup().lookup(SaveCookie.class); if (save != null) { logger.log(Level.FINE, "saving changes in {0}", dobj); save.save(); } else { logger.log(Level.FINE, "no changes in {0} where modified={1}", new Object[] {dobj, dobj.isModified()}); } } }
Example 18
Source File: ExternalChangesTest.java From netbeans with Apache License 2.0 | 4 votes |
@RandomlyFails public void testLogIntCmdAfterUnlock () throws Exception { waitForInitialScan(); FileChangeAdapter fca = new FileChangeAdapter(); workdirFO.addRecursiveListener(fca); final File toAdd = new File(modifiedFile.getParentFile(), "toAdd"); final File toDelete = new File(modifiedFile.getParentFile(), "toDelete"); toDelete.createNewFile(); FileUtil.refreshFor(repositoryLocation); Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down File gitFolder = new File(repositoryLocation, ".git"); final File lockFile = new File(gitFolder, "index.lock"); Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs"); ExternalCommandUsageHandler h = new ExternalCommandUsageHandler(); GESTURES_LOG.addHandler(h); Git.getInstance().runWithoutExternalEvents(repositoryLocation, "MY_COMMAND", new Callable<Void>() { @Override public Void call () throws Exception { // modification write(modifiedFile, "testExternalCommandLoggedChanges"); // delete toDelete.delete(); // create toAdd.createNewFile(); pause(); FileUtil.refreshFor(repositoryLocation); return null; } }); Thread.sleep(2000); // coming with delay after some time // still considered as part of internal command lockFile.createNewFile(); FileUtil.refreshFor(repositoryLocation); pause(); lockFile.delete(); FileUtil.refreshFor(repositoryLocation); h.waitForEvent(); assertNotNull(h.event); assertEquals(1, h.numberOfEvents); assertTrue(h.event.time > 0); assertEquals("GIT", h.event.vcs); assertFalse(h.event.external); assertEquals("MY_COMMAND", h.event.command); assertEquals(Long.valueOf(3), h.event.modifications); Thread.sleep(9000); // coming after some reasonable pause, now considered as part of external command lockFile.createNewFile(); FileUtil.refreshFor(repositoryLocation); pause(); lockFile.delete(); FileUtil.refreshFor(repositoryLocation); h.waitForEvent(); assertNotNull(h.event); assertEquals(2, h.numberOfEvents); assertEquals("GIT", h.event.vcs); assertTrue(h.event.external); assertEquals("UNKNOWN", h.event.command); assertEquals(Long.valueOf(0), h.event.modifications); GESTURES_LOG.removeHandler(h); workdirFO.removeRecursiveListener(fca); }
Example 19
Source File: EvaluationSpanTaskTest.java From netbeans with Apache License 2.0 | 3 votes |
private void prepareTest(String fileName, String code) throws Exception { clearWorkDir(); File wdFile = getWorkDir(); FileUtil.refreshFor(wdFile); FileObject wd = FileUtil.toFileObject(wdFile); assertNotNull(wd); sourceRoot = FileUtil.createFolder(wd, "src"); FileObject buildRoot = FileUtil.createFolder(wd, "build"); FileObject cache = FileUtil.createFolder(wd, "cache"); FileObject data = FileUtil.createData(sourceRoot, fileName); File dataFile = FileUtil.toFile(data); assertNotNull(dataFile); TestUtilities.copyStringToFile(dataFile, code); SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache); DataObject od = DataObject.find(data); EditorCookie ec = od.getLookup().lookup(EditorCookie.class); assertNotNull(ec); doc = ec.openDocument(); doc.putProperty(Language.class, JavaTokenId.language()); doc.putProperty("mimeType", "text/x-java"); JavaSource js = JavaSource.forFileObject(data); assertNotNull(js); info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED); assertNotNull(info); }
Example 20
Source File: TreeRuleTestBase.java From netbeans with Apache License 2.0 | 2 votes |
private void prepareTest(String fileName, String code) throws Exception { clearWorkDir(); File wdFile = getWorkDir(); FileUtil.refreshFor(wdFile); FileObject wd = FileUtil.toFileObject(wdFile); assertNotNull(wd); if (subTest != null) { wd = FileUtil.createFolder(wd, "st" + subTest); } sourceRoot = FileUtil.createFolder(wd, "src"); FileObject buildRoot = FileUtil.createFolder(wd, "build"); FileObject cache = FileUtil.createFolder(wd, "cache"); FileObject data = FileUtil.createData(sourceRoot, fileName); File dataFile = FileUtil.toFile(data); assertNotNull(dataFile); TestUtilities.copyStringToFile(dataFile, code); SourceUtilsTestUtil.setSourceLevel(data, sourceLevel); SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache, extraClassPath()); DataObject od = DataObject.find(data); EditorCookie ec = od.getCookie(EditorCookie.class); assertNotNull(ec); doc = ec.openDocument(); doc.putProperty(Language.class, JavaTokenId.language()); doc.putProperty("mimeType", "text/x-java"); JavaSource js = JavaSource.forFileObject(data); assertNotNull(js); info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED); assertNotNull(info); }