Java Code Examples for org.openide.util.Utilities#isUnix()

The following examples show how to use org.openide.util.Utilities#isUnix() . 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: URLEqualityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testEqualSymlinks() throws Exception {
    if (!Utilities.isUnix()) {
        return;
    }
    File copy = new File(getWorkDir(), "copy");
    int ret = new ProcessBuilder("ln", "-s", "orig", copy.getPath()).start().waitFor();
    assertEquals("Symlink created", ret, 0);
    assertTrue("Dir exists", copy.exists());
    File f = new File(copy, "test.js");
    assertTrue("File exists", f.exists());
    
    URLEquality oe = new URLEquality(orig.toURI().toURL());
    URLEquality ne = new URLEquality(f.toURI().toURL());

    assertEquals("Same hashCode", oe.hashCode(), ne.hashCode());
    assertEquals("They are similar", oe, ne);
    
}
 
Example 2
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the path for the Sunbversion configuration dicectory used 
 * by the systems Subversion commandline client.
 *
 * @return the path
 *
 */ 
public static String getUserConfigPath() {        
    
    //T9Y - user svn config files should be changable
    String t9yUserConfigPath = System.getProperty("netbeans.t9y.svn.user.config.path");
    if (t9yUserConfigPath != null && t9yUserConfigPath.length() > 0) {
        return t9yUserConfigPath;
    }
    
    if(Utilities.isUnix()) {
        String path = System.getProperty("user.home") ;                     // NOI18N
        return path + "/" + UNIX_CONFIG_DIR;                                // NOI18N
    } else if (Utilities.isWindows()){
        return WINDOWS_CONFIG_DIR;
    } 
    return "";                                                              // NOI18N
}
 
Example 3
Source File: Util.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tries to set default L&F according to platform.
 * Uses:
 *   Metal L&F on Linux and Solaris
 *   Windows L&F on Windows
 *   Aqua L&F on Mac OS X
 *   System L&F on other OS
 */
public static void setDefaultLookAndFeel () {
    String uiClassName;
    if (Utilities.isWindows()) {
        uiClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; //NOI18N
    } else if (Utilities.isMac()) {
        uiClassName = "com.apple.laf.AquaLookAndFeel"; //NOI18N
    } else if (Utilities.isUnix()) {
        uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; //NOI18N
    } else {
        uiClassName = UIManager.getSystemLookAndFeelClassName();
    }
    if (uiClassName.equals(UIManager.getLookAndFeel().getClass().getName())) {
        //Desired L&F is already set
        return;
    }
    try {
        UIManager.setLookAndFeel(uiClassName);
    } catch (Exception ex) {
        System.err.println("Cannot set L&F " + uiClassName); //NOI18N
        System.err.println("Exception:" + ex.getMessage()); //NOI18N
        ex.printStackTrace();
    }
}
 
Example 4
Source File: ChromiumBrowser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of BrowserImpl implementation.
 * @throws UnsupportedOperationException when method is called and OS is not supported.
 * @return browserImpl implementation of browser.
 */
@Override
public HtmlBrowser.Impl createHtmlBrowserImpl() {
    ExtBrowserImpl impl = null;

    if (Utilities.isUnix() && !Utilities.isMac()) {
        impl = new UnixBrowserImpl(this);
    } else if (Utilities.isWindows()) {
        impl = new NbDdeBrowserImpl(this);
    } else {
        throw new UnsupportedOperationException (NbBundle.
                getMessage(FirefoxBrowser.class, "MSG_CannotUseBrowser"));  // NOI18N
    }
    
    return impl;
}
 
Example 5
Source File: SystemDefaultBrowser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new instance of BrowserImpl implementation.
 * @throws UnsupportedOperationException when method is called and OS is not Windows.
 * @return browserImpl implementation of browser.
 */
@Override
public HtmlBrowser.Impl createHtmlBrowserImpl() {
    if (ACTIVE) {
        return new Jdk6BrowserImpl();
    } else if (Utilities.isWindows()) {
        return new NbDdeBrowserImpl(this);
    } else if (Utilities.isMac()) {
        return new MacBrowserImpl(this);
    } else if (Utilities.isUnix() && !Utilities.isMac()) {
        return new NbDefaultUnixBrowserImpl(this);
    } else {
        throw new UnsupportedOperationException(NbBundle.getMessage(SystemDefaultBrowser.class, "MSG_CannotUseBrowser"));
    }
}
 
Example 6
Source File: PhpEnvironment.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get the OS dependent PHP environment.
 * @return the OS dependent PHP environment.
 */
public static PhpEnvironment get() {
    if (isSolaris()) {
        return new SolarisPhpEnvironment();
    } else if (Utilities.isWindows()) {
        return new WindowsPhpEnvironment();
    } else if (Utilities.isMac()) {
        return new MacPhpEnvironment();
    } else if (Utilities.isUnix()) {
        return new UnixPhpEnvironment();
    }
    return UNKNOWN_PHP_ENVIRONMENT;
}
 
Example 7
Source File: SftpConnectionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SshFiles getDefaultSshFiles() {
    if (Utilities.isWindows()) {
        return getDefaultWindowsSshFiles();
    } else if (Utilities.isUnix()) {
        return getDefaultUnixSshFiles();
    }
    return UNKNOWN_SSH_FILES;
}
 
Example 8
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Return the path for the systemwide command lines configuration directory 
 */
private static String getGlobalConfigPath () {
    if(Utilities.isUnix()) {
        return "/etc/subversion";               // NOI18N
    } else if (Utilities.isWindows()){
        return WINDOWS_GLOBAL_CONFIG_DIR;
    } 
    return "";                                  // NOI18N
}
 
Example 9
Source File: NetworkProxyReloader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns proper network resolver for running environment.
 * 
 * If not suitable proxy resolver found, the fallback is used.
 * 
 * @return Proper network resolver for running environment.
 */
private static NetworkProxyResolver getNetworkProxyResolver() {
    if (NETWORK_PROXY_RESOLVER == null) {        
        if (Utilities.isWindows()) {
            LOGGER.log(Level.INFO, "System network proxy resolver: Windows"); //NOI18N
            return new WindowsNetworkProxy();
        } 
        
        if (Utilities.isMac()) {
            LOGGER.log(Level.INFO, "System network proxy resolver: Mac"); //NOI18N
            return new MacNetworkProxy();
        }
        
        if (Utilities.isUnix()){
            String env = System.getProperty(RUNNING_ENV_SYS_PROPERTY);
            if (env != null) {
                if (env.toLowerCase().equals(GNOME)) {
                    LOGGER.log(Level.INFO, "System network proxy resolver: Gnome"); //NOI18N
                    return new GnomeNetworkProxy();
                }
                
                if (env.toLowerCase().equals(KDE)) {
                    LOGGER.log(Level.INFO, "System network proxy resolver: KDE"); //NOI18N
                    return new KdeNetworkProxy();
                }
            }
        }
        
        LOGGER.log(Level.INFO, "System network proxy resolver: no suitable found, using fallback."); //NOI18N
        return new FallbackNetworkProxy();
    } else {
        return NETWORK_PROXY_RESOLVER;
    }   
}
 
Example 10
Source File: NbPresenter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doShow () {
    //#206802 - dialog windows are hidden behind full screen window
    Window fullScreenWindow = null;
    if( Utilities.isUnix() ) {
        GraphicsDevice gd = getGraphicsConfiguration().getDevice();
        if( gd.isFullScreenSupported() ) {
            fullScreenWindow = gd.getFullScreenWindow();
            if( null != fullScreenWindow )
                gd.setFullScreenWindow( null );
        }
    }
    NbPresenter prev = null;
    try {
        MenuSelectionManager.defaultManager().clearSelectedPath();
    } catch( NullPointerException npE ) {
        //#216184
        LOG.log( Level.FINE, null, npE );
    }
    if (isModal()) {
        prev = currentModalDialog;
        currentModalDialog = this;
        fireChangeEvent();
    }

    superShow();

    if( null != fullScreenWindow )
        getGraphicsConfiguration().getDevice().setFullScreenWindow( fullScreenWindow );

    if (currentModalDialog != prev) {
        currentModalDialog = prev;
        fireChangeEvent();
    }
}
 
Example 11
Source File: RecentViewListAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Only here for fix #41477:, called from layer.xml:
 * For KDE on unixes, Ctrl+TAB is occupied by OS,
 * so we also register Ctrl+BACk_QUOTE as recent view list action shortcut.
 * For other OS's, Ctrl+TAB is the only default, because we create link
 * not pointing to anything by returning null
 */
public static String getStringRep4Unixes() {
    if (Utilities.isUnix() && !Utilities.isMac()) {
        return "Actions/Window/org-netbeans-core-windows-actions-RecentViewListAction.instance"; //NOI18N
    }
    return null;
}
 
Example 12
Source File: MozillaBrowser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new instance of BrowserImpl implementation.
 * @throws UnsupportedOperationException when method is called and OS is not Windows.
 * @return browserImpl implementation of browser.
 */
@Override
public HtmlBrowser.Impl createHtmlBrowserImpl() {
    ExtBrowserImpl impl = null;

    if (Utilities.isWindows()) {
        impl = new NbDdeBrowserImpl(this);
    } else if (Utilities.isUnix() && !Utilities.isMac()) {
        impl = new UnixBrowserImpl(this);
    } else {
        throw new UnsupportedOperationException (NbBundle.getMessage (MozillaBrowser.class, "MSG_CannotUseBrowser"));
    }
    
    return impl;
}
 
Example 13
Source File: LockForFileTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testHardLockExclusion() throws Throwable {
    if (Utilities.isUnix() && new File("/bin/ln").exists()) {
        File fold1 = testFile.getParentFile();
        File fold2 = new File(fold1.getParentFile(), fold1.getName() + "XXX");
        fold2.delete();
        assertTrue(fold1.exists());
        assertFalse(fold2.exists());
        ProcessBuilder pb = new ProcessBuilder("/bin/ln","-s",fold1.getAbsolutePath(), fold2.getAbsolutePath());
        try {
            pb.start().waitFor();
        } catch(Throwable th) {
            //System.out.println("");
            th.printStackTrace();
            throw th;
        }
         assertTrue(fold2.exists());
        File f1 = new File(fold1, testFile.getName());
        File f2 = new File(fold2, testFile.getName());
        FileObject fo1 = FileBasedFileSystem.getFileObject(f1);
        FileObject fo2 = FileBasedFileSystem.getFileObject(f2);
        assertNotNull(fo1);
        assertNotNull(fo2);
        for (int i = 0; i < 5; i++) {
            LockForFile lock = (LockForFile) fo1.lock();
            assertFalse(lock.isHardLocked());
            try {
                fo2.lock();
                fail();
            } catch (Exception iex) {
            }
            assertTrue(lock.isHardLocked());
            lock.releaseLock();
        }
    }
}
 
Example 14
Source File: HttpServerSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Intended to be called by the thread which failed to start the server. 
 * It decides whether try to start server on next port or show appropriate
 * error message.
 */
void runFailure(Throwable t) {
    running = false;
    if (t instanceof IncompatibleClassChangeError) {
        // likely there is a wrong servlet API version on CLASSPATH
        DialogDisplayer.getDefault ().notify(new NotifyDescriptor.Message(
           NbBundle.getMessage (HttpServerSettings.class, "MSG_HTTP_SERVER_incompatbleClasses"),
           NotifyDescriptor.Message.WARNING_MESSAGE));
    }
    else if (t instanceof java.net.BindException) {
        // can't open socket - we can retry
        currentRetries ++;
        if (currentRetries <= MAX_START_RETRIES) {
            setPort(getPort() + 1);
            setRunning(true);
        }
        else {
            currentRetries = 0;
            DialogDisplayer.getDefault ().notify(new NotifyDescriptor.Message(
                                           NbBundle.getMessage (HttpServerSettings.class, "MSG_HTTP_SERVER_START_FAIL"),
                                           NotifyDescriptor.Message.WARNING_MESSAGE));
            int p = getPort ();
            if (p < 1024 && inited && Utilities.isUnix()) {
                DialogDisplayer.getDefault ().notify(new NotifyDescriptor.Message(
                                           NbBundle.getMessage (HttpServerSettings.class, "MSG_onlyRootOnUnix"),
                                           NotifyDescriptor.WARNING_MESSAGE));
            }

        }
    }
    else {
        // unknown problem
        DialogDisplayer.getDefault ().notify(new NotifyDescriptor.Message(
           NbBundle.getMessage (HttpServerSettings.class, "MSG_HTTP_SERVER_START_FAIL_unknown"),
           NotifyDescriptor.Message.WARNING_MESSAGE));
    }
}
 
Example 15
Source File: HelpSetRegistrationProcessorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Use safe temp directory if the default one contains problematic
 * characters (e.g. plus sign "+" on Mac).
 * 
 * #201194.
 * 
 * We have to use java.io.File and File.createTempFile instead of NetBeans
 * specific classes and utility methods, as the code is called at 
 * compile-time.
 *
 * @throws IOException 
 */
public void testCreateTempFile() throws IOException {

    if (Utilities.isWindows()) {
        if (!new File("c:\\temp").isDirectory()) {
            return;
        }
    } else if (Utilities.isUnix()) {
        if (!new File("/tmp").isDirectory()) {
            return;
        }
    } else {
        return;
    }

    // Create a problematic directory.
    File tempRoot = File.createTempFile("temp+Root", "");
    tempRoot.delete();
    tempRoot.mkdir();

    // Set the problematic directory as default temp directory.
    String origTmpDir = System.getProperty(PROP_TMP_DIR);
    System.setProperty(PROP_TMP_DIR, tempRoot.getAbsolutePath());

    File tempFile = null;
    File safeFile = null;

    try {

        assertFalse(
                HelpSetRegistrationProcessor.isUrlCompatible(
                tempRoot));

        tempFile = File.createTempFile("tempFile", ".tmp");

        if (!tempRoot.getAbsolutePath().equals(
                tempFile.getParentFile().getAbsolutePath())) {
            // Default temp directory location hasn't been affected by
            // changing system property java.io.tmpdir, skipping the test.
            return;
        }

        // File created in custom method should be created in 
        // a non-problematic directory.
        safeFile = HelpSetRegistrationProcessor.createTempFile(
                "tempFile2", ".txt");

        System.out.println("Temp root: " + tempRoot.getAbsolutePath());
        System.out.println("Safe temp file: " + safeFile.getAbsolutePath());

        if (Utilities.isWindows() || Utilities.isMac()
                || Utilities.isUnix()) {

            assertNotSame(tempRoot.getAbsolutePath(), tempFile.getParent());
            HelpSetRegistrationProcessor.isUrlCompatible(
                    safeFile);
        }
    } finally {
        System.setProperty(PROP_TMP_DIR, origTmpDir);
        if (tempFile != null && tempFile.isFile()) {
            tempFile.delete();
        }
        if (safeFile != null && safeFile.isFile()) {
            safeFile.delete();
        }
        tempRoot.delete();
    }
}
 
Example 16
Source File: LinuxXAMPPInstallation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean isInstalled() {
    return Utilities.isUnix() && Utils.isValidExecutable(LAMPP)
            && Utils.isValidExecutable(GKSU);
}
 
Example 17
Source File: SXDEWebStackInstallation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean isInstalled() {
    return Utilities.isUnix() && Utils.isValidExecutable(SVC_EXE) &&
            Utils.isValidExecutable(GKSU) && 
            Utils.isValidExecutable(MYSQLD_PATH);
}
 
Example 18
Source File: LinuxStandaloneInstallation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean isInstalled() {
    return Utilities.isUnix() && Utils.isValidExecutable(SVC_EXE) &&
            Utils.isValidExecutable(GKSU);
}
 
Example 19
Source File: SystemDefaultBrowser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean defaultBrowserUnixReady() {
    return Utilities.isUnix() && NbDefaultUnixBrowserImpl.isAvailable();
}
 
Example 20
Source File: HelpSetRegistrationProcessor.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/** Create a temp file that can be used for turning into directory
 * and setting as database directory for indexing JavaHelp files.
 * 
 * This method was created because default temp directory on some systems
 * (Mac) contains plus sign "+" in its path. Plus signs are replaced with
 * spaces in JavaHelp indexer because of encoding path to URL and later
 * decoding URL back to path.
 * 
 * #201194
 *
 * This is workaround only. Fixed upstream, see
 * http://java.net/jira/browse/JAVAHELP-33.
 * When a new version of JavaHelp with that fix is released (e.g. 2.0_06)
 * and bundled in NetBeans, standard File.createTempFile can be used instead
 * of this method, and createTempFile, replaceTempFile and isUrlCompatible
 * methods can be removed.
 */
static File createTempFile(String pref, String suff) throws IOException {

    File f = File.createTempFile(pref, suff); //file in default tmp folder
    if (!isUrlCompatible(f)) {
        if (Utilities.isWindows()) {
            f = replaceTempFile(f, "c:\\Temp", pref, suff);         //NOI18N
        } else if (Utilities.isUnix()) {
            f = replaceTempFile(f, "/tmp", pref, suff);             //NOI18N
        }
    }
    return f;
}