Java Code Examples for org.openide.util.Utilities#isWindows()
The following examples show how to use
org.openide.util.Utilities#isWindows() .
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: ServerLocationManager.java From netbeans with Apache License 2.0 | 6 votes |
/** * Locate update center launcher within the glassfish installation * [installRoot]/updatecenter/bin/updatetool[.BAT] * * @param asInstallRoot appserver install location * @return File reference to launcher, or null if not found. */ public static File getUpdateCenterLauncher(File asInstallRoot) { File result = null; if(asInstallRoot != null && asInstallRoot.exists()) { File updateCenterBin = new File(asInstallRoot, "updatecenter/bin"); // NOI18N if(updateCenterBin.exists()) { String launcher = "updatetool"; // NOI18N if(Utilities.isWindows()) { launcher += ".BAT"; // NOI18N } File launcherPath = new File(updateCenterBin, launcher); result = (launcherPath.exists()) ? launcherPath : null; } } return result; }
Example 2
Source File: FilesystemInterceptorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRenameFileChangeCase_FO () throws Exception { // prepare File fromFile = createFile(repositoryLocation, "file"); File toFile = new File(repositoryLocation, "FILE"); add(fromFile); commit(fromFile); // move h.setFilesToRefresh(new HashSet(Arrays.asList(fromFile, toFile))); renameFO(fromFile, toFile); // test if (Utilities.isWindows() || Utilities.isMac()) { assertTrue(Arrays.asList(toFile.getParentFile().list()).contains(toFile.getName())); assertFalse(Arrays.asList(fromFile.getParentFile().list()).contains(fromFile.getName())); } else { assertTrue(h.waitForFilesToRefresh()); assertFalse(fromFile.exists()); assertTrue(toFile.exists()); assertEquals(EnumSet.of(Status.REMOVED_HEAD_INDEX, Status.REMOVED_HEAD_WORKING_TREE), getCache().getStatus(fromFile).getStatus()); assertEquals(EnumSet.of(Status.NEW_HEAD_INDEX, Status.NEW_HEAD_WORKING_TREE), getCache().getStatus(toFile).getStatus()); } }
Example 3
Source File: FileInfoTest.java From netbeans with Apache License 2.0 | 6 votes |
/** Test getRoot() method. */ public void testGetRoot() { if(!Utilities.isWindows()) { return; } String[][] files = { // filename, expected root {"\\\\computerName\\sharedFolder\\a\\b\\c\\d.txt", "\\\\computerName\\sharedFolder"}, {"\\\\computerName\\sharedFolder", "\\\\computerName\\sharedFolder"}, {"\\\\computerName", "\\\\computerName"}, {"\\\\", "\\\\"}, {"D:\\a\\b\\c\\a.txt", "D:\\"}, {"D:\\a.txt", "D:\\"}, {"D:\\", "D:\\"} }; for (int i = 0; i < files.length; i++) { assertEquals("Wrong root for file "+files[i][0]+".", files[i][1], new FileInfo(new File(files[i][0])).getRoot().toString()); } }
Example 4
Source File: InterceptorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRenameFileChangeCase_FO () throws Exception { // prepare File fromFile = createFile("file"); File toFile = new File(getWorkTreeDir(), "FILE"); commit(fromFile); // move renameFO(fromFile, toFile.getName()); // test if (Utilities.isWindows() || Utilities.isMac()) { assertTrue(Arrays.asList(toFile.getParentFile().list()).contains(toFile.getName())); assertFalse(Arrays.asList(fromFile.getParentFile().list()).contains(fromFile.getName())); } else { assertFalse(fromFile.exists()); assertTrue(toFile.exists()); assertEquals(FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY, getCache().refresh(fromFile).getStatus()); assertEquals(FileInformation.STATUS_VERSIONED_ADDEDLOCALLY, getCache().refresh(toFile).getStatus()); } }
Example 5
Source File: AndroidSdkTool.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns a string with the path to the android tool, specific for platform (.exe for windows) * @return */ public static String getAndroidToolPath() { FileObject executable = null; FileObject folder = getSdkFolder(); if (folder == null) { return null; } if (Utilities.isWindows()) { executable = folder.getFileObject("tools/android.bat"); } else { executable = folder.getFileObject("tools/android"); } if (executable != null) { return FileUtil.toFile(executable).getPath(); } else { return null; } }
Example 6
Source File: FileStatusCache.java From netbeans with Apache License 2.0 | 6 votes |
/** * Updates cache with scanned information for the given file * @param file * @param fi * @param interestingFiles * @param alwaysFireEvent */ private void refreshFileStatus(File file, FileInformation fi) { if(file == null || fi == null) return; FileInformation current; boolean fireEvent = true; synchronized (this) { file = FileUtil.normalizeFile(file); current = getInfo(file); fi = checkForIgnore(fi, current, file); if (equivalent(fi, current)) { // no need to fire an event if (Utilities.isWindows() || Utilities.isMac()) { // but for these we need to update keys in cache because of renames AAA.java -> aaa.java fireEvent = false; } else { return; } } boolean addToIndex = updateCachedValue(fi, file); updateIndex(file, fi, addToIndex); } if (fireEvent) { fireFileStatusChanged(file, current, fi); } }
Example 7
Source File: ExtWebBrowser.java From netbeans with Apache License 2.0 | 5 votes |
/** initialize object */ private void init () { if (err.isLoggable(Level.FINE)) { err.log(Level.FINE, getClass().getName() + " " + System.currentTimeMillis() + "> init"); } pcs = new PropertyChangeSupport(this); if (Utilities.isWindows()) { pcs.addPropertyChangeListener(this); } }
Example 8
Source File: StatFilesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testToFileObject() throws IOException { File workDir = getWorkDir(); assertGC("NamingFactory not cleared.", new WeakReference<FileNaming>(NamingFactory.fromFile(workDir))); monitor.reset(); monitor(); assertNotNull(FileUtil.toFileObject(workDir)); int expectedCount = 5; if(Utilities.isWindows()) { expectedCount = 3; } monitor.getResults().assertResult(expectedCount, StatFiles.ALL); monitor.getResults().assertResult(expectedCount, StatFiles.READ); }
Example 9
Source File: WindowsHostInfoProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public HostInfo getHostInfo(ExecutionEnvironment execEnv) throws IOException, InterruptedException { // Windows is supported for localhosts only. if (!execEnv.isLocal() || !Utilities.isWindows()) { return null; } HostInfoImpl info = new HostInfoImpl(); info.initTmpDirs(); info.initUserDirs(); Shell activeShell = WindowsSupport.getInstance().getActiveShell(); if (activeShell != null && Shell.ShellType.CYGWIN.equals(activeShell.type)) { String nbstart = NbStartUtility.getInstance().getPath(execEnv, info); String envPath = info.getEnvironmentFile(); if (nbstart != null && envPath != null) { ProcessBuilder pb = new ProcessBuilder(nbstart, "--dumpenv", envPath); // NOI18N String pathKey = WindowsSupport.getInstance().getPathKey(); pb.environment().put(pathKey, "/usr/local/bin;" + activeShell.bindir.getAbsolutePath() + ";/bin;" + pb.environment().get(pathKey)); // NOI18N ExitStatus result = ProcessUtils.execute(pb); if (!result.isOK()) { Logger.getInstance().log(Level.INFO, "Failed to call nbstart -- {0}.", result.getErrorString()); // NOI18N } } } return info; }
Example 10
Source File: MicrosoftEdgeBrowser.java From netbeans with Apache License 2.0 | 5 votes |
/** * Determines whether the browser should be visible or not. * * @return {@code false} when the OS is Windows and Microsoft Edge is available, * returns {@code true} otherwise. */ public static Boolean isHidden() { if (hidden == null) { if (Utilities.isWindows()) { hidden = getAppUserModelId().isEmpty(); } else { hidden = true; } } return hidden; }
Example 11
Source File: JavaHlClientAdapterFactory.java From netbeans with Apache License 2.0 | 5 votes |
private void presetJavahl() { if(Utilities.isUnix() && !Utilities.isMac() ) { // javahl for mac is already bundled presetJavahlUnix(); } else if(Utilities.isWindows()) { presetJavahlWindows(); } }
Example 12
Source File: FolderObjTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCaseInsensitivity() throws Exception { if (!Utilities.isWindows()) return; final FileObject testRoot = FileBasedFileSystem.getFileObject(getWorkDir()); assertNotNull(testRoot); File testa = new File(getWorkDir(), "a"); File testA = new File(getWorkDir(), "A"); if (testA.exists()) { assertTrue(testA.delete()); } if (!testa.exists()) { assertTrue(testa.createNewFile()); } //FileBasedFileSystem's case sensitivity depends on platform. This is different behaviour // than originally provided by AbstractFileSystem. FileObject A = testRoot.getFileObject("A"); assertNotNull(A); assertNotNull(testRoot.getFileObject("a")); assertSame(testRoot.getFileObject("A"), testRoot.getFileObject("a")); assertSame(URLMapper.findFileObject(Utilities.toURI(testa).toURL()), URLMapper.findFileObject(Utilities.toURI(testA).toURL())); //but testRoot.getChildren(); assertEquals("A",testRoot.getFileObject("A").getName()); assertEquals("A",testRoot.getFileObject("a").getName()); BaseFileObj bobj = (BaseFileObj)testRoot.getFileObject("a"); NamingFactory.checkCaseSensitivity(bobj.getFileName(),testa); assertEquals("a",testRoot.getFileObject("a").getName()); assertEquals("a",testRoot.getFileObject("A").getName()); }
Example 13
Source File: BuildZipDistributionTest.java From netbeans with Apache License 2.0 | 5 votes |
private void run(File nbexec, String... args) throws Exception { URL tu = MainCallback.class.getProtectionDomain().getCodeSource().getLocation(); File testf = Utilities.toFile(tu.toURI()); assertTrue("file found: " + testf, testf.exists()); LinkedList<String> allArgs = new LinkedList<String>(Arrays.asList(args)); allArgs.addFirst("-J-Dnetbeans.mainclass=" + MainCallback.class.getName()); allArgs.addFirst(getWorkDirPath()); allArgs.addFirst("--userdir"); allArgs.addFirst(testf.getPath()); allArgs.addFirst("-cp:p"); if (!Utilities.isWindows()) { allArgs.addFirst(nbexec.getPath()); allArgs.addFirst("-x"); allArgs.addFirst("/bin/sh"); } else { allArgs.addFirst(nbexec.getPath()); } String[] envp = { "jdkhome=" + System.getProperty("java.home") }; StringBuffer sb = new StringBuffer(); Process p = Runtime.getRuntime().exec(allArgs.toArray(new String[0]), envp, nbexec.getParentFile()); int res = readOutput(sb, p); String output = sb.toString(); assertEquals("Execution is ok: " + output, 0, res); }
Example 14
Source File: HgURL.java From netbeans with Apache License 2.0 | 5 votes |
/** * Detects with certain probability whether the given URL string is just * a plain path (i.e. without any scheme/protocol specification). * * @param urlString path/URL string to be checked * @return {@code true} if the string seems to be a plain file path, * {@code false} otherwise */ public static boolean looksLikePlainFilePath(String urlString) { if (urlString == null) { throw new IllegalArgumentException("<null> URL string"); //NOI18N } if (urlString.length() == 0) { return false; } return (urlString.charAt(0) == '/') || Utilities.isWindows() && isWindowsAbsolutePath(urlString); }
Example 15
Source File: HgConfigFiles.java From netbeans with Apache License 2.0 | 5 votes |
public void removeProperty(String section, String name) { Ini.Section inisection = getSection(hgrc, section, false); if (inisection != null) { inisection.remove(name); if (!bIsProjectConfig && Utilities.isWindows()) { storeIni(hgrc, configFileName); } else { storeIni(hgrc, configFileName); } } }
Example 16
Source File: BaseFileObjectTestHid.java From netbeans with Apache License 2.0 | 4 votes |
public void testNormalization51910 () throws Exception { if (!Utilities.isWindows()) return; File rootFile = FileUtil.toFile(root); assertTrue(rootFile.exists()); File testFile = new File (rootFile, "abc.txt"); assertTrue(testFile.createNewFile()); assertTrue(testFile.exists()); File testFile2 = new File (rootFile, "ABC.TXT"); assertTrue(testFile2.exists()); assertEquals(Utilities.toURI(FileUtil.normalizeFile(testFile)).toURL(), Utilities.toURI(FileUtil.normalizeFile(testFile2)).toURL()); }
Example 17
Source File: DirectoryChooserUI.java From netbeans with Apache License 2.0 | 4 votes |
private void updateUseShellFolder() { // Decide whether to use the ShellFolder class to populate shortcut // panel and combobox. Boolean prop = (Boolean)fileChooser.getClientProperty(DelegatingChooserUI.USE_SHELL_FOLDER); if (prop != null) { useShellFolder = prop.booleanValue(); } else { // See if FileSystemView.getRoots() returns the desktop folder, // i.e. the normal Windows hierarchy. useShellFolder = false; File[] roots = fileChooser.getFileSystemView().getRoots(); if (roots != null && roots.length == 1) { File[] cbFolders = getShellFolderRoots(); if (cbFolders != null && cbFolders.length > 0 && Arrays.asList(cbFolders).contains(roots[0])) { useShellFolder = true; } } } if (Utilities.isWindows()) { if (useShellFolder) { if (placesBar == null) { placesBar = getPlacesBar(); } if (placesBar != null) { fileChooser.add(placesBar, BorderLayout.BEFORE_LINE_BEGINS); if (placesBar instanceof PropertyChangeListener) { fileChooser.addPropertyChangeListener((PropertyChangeListener)placesBar); } } } else { if (placesBar != null) { fileChooser.remove(placesBar); if (placesBar instanceof PropertyChangeListener) { fileChooser.removePropertyChangeListener((PropertyChangeListener)placesBar); } placesBar = null; } } } }
Example 18
Source File: ProxySettings.java From netbeans with Apache License 2.0 | 4 votes |
private static String getModifiedNonProxyHosts (String systemPreset) { String fromSystem = systemPreset.replaceAll (";", "|").replaceAll (",", "|"); //NOI18N String fromUser = getPresetNonProxyHosts () == null ? "" : getPresetNonProxyHosts ().replaceAll (";", "|").replaceAll (",", "|"); //NOI18N if (Utilities.isWindows ()) { fromSystem = addReguralToNonProxyHosts (fromSystem); } String nonProxy = fromUser + (fromUser.length () == 0 ? "" : "|") + fromSystem + (fromSystem.length () == 0 ? "" : "|") + "localhost|127.0.0.1"; // NOI18N String localhost = ""; // NOI18N try { localhost = InetAddress.getLocalHost().getHostName(); if (!"localhost".equals(localhost)) { // NOI18N nonProxy = nonProxy + "|" + localhost; // NOI18N } else { // Avoid this error when hostname == localhost: // Error in http.nonProxyHosts system property: sun.misc.REException: localhost is a duplicate } } catch (UnknownHostException e) { // OK. Sometimes a hostname is assigned by DNS, but a computer // is later pulled off the network. It may then produce a bogus // name for itself which can't actually be resolved. Normally // "localhost" is aliased to 127.0.0.1 anyway. } /* per Milan's agreement it's removed. See issue #89868 try { String localhost2 = InetAddress.getLocalHost().getCanonicalHostName(); if (!"localhost".equals(localhost2) && !localhost2.equals(localhost)) { // NOI18N nonProxy = nonProxy + "|" + localhost2; // NOI18N } else { // Avoid this error when hostname == localhost: // Error in http.nonProxyHosts system property: sun.misc.REException: localhost is a duplicate } } catch (UnknownHostException e) { // OK. Sometimes a hostname is assigned by DNS, but a computer // is later pulled off the network. It may then produce a bogus // name for itself which can't actually be resolved. Normally // "localhost" is aliased to 127.0.0.1 anyway. } */ return compactNonProxyHosts (nonProxy); }
Example 19
Source File: MiniEdit.java From netbeans with Apache License 2.0 | 4 votes |
/** Creates new form MiniEdit */ public MiniEdit() { initComponents(); //Hopefully avoid the floppy drive on Windows by setting index to 1. int rootIdx = Utilities.isWindows() ? 1 : 0; //Aim our file tree at some filesystem root fileTree.setModel(new FileTreeModel( File.listRoots()[rootIdx])); //Get a URL for our actions definition URL file URL url = MiniEdit.class.getClassLoader().getResource( "org/netbeans/actions/examples/actiondefs.xml"); //Get a resource bundle with localized names for our actions ResourceBundle bundle = ResourceBundle.getBundle( "org/netbeans/actions/examples/actions"); //Pass the XML file and the resource bundle to create an instance of //Engine which can create menus, toolbars, keymaps, etc., from it engine = SimpleEngine.createEngine(url, bundle); engine.setContextProvider(this); //Install the menu bar the engine supplies setJMenuBar(engine.createMenuBar()); //Get an array of toolbars to install JToolBar[] toolbars = engine.createToolbars(); //Install the toolbars for (int i=0; i < toolbars.length; i++) { toolbars[i].setFloatable(false); toolbarPanel.add(toolbars[i]); } //Very simply set up keyboard mappings for the entire app window from //those defined in the engine's XML file getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, engine.createInputMap(getRootPane())); getRootPane().setActionMap(engine.createActionMap()); //Add focus listeners that will advise the engine to check enablement //of actions toolbarPanel.setLayout (new FlowLayout()); fileTree.setLargeModel(true); fileTree.addFocusListener(this); toolbarPanel.addFocusListener(this); //Misc ui stuff fileTree.setAutoscrolls(true); fileTree.addMouseListener(this); pack(); }
Example 20
Source File: AddServerLocationPanel.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isLegalFolder(File installDir) { return getCanonicalFile(installDir) != null && (!Utilities.isWindows() || ILLEGAL_WINDOWS_CHARS.matcher(installDir.getPath()).find() == false); }