Example usage for org.apache.commons.lang SystemUtils IS_OS_MAC

List of usage examples for org.apache.commons.lang SystemUtils IS_OS_MAC

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils IS_OS_MAC.

Prototype

boolean IS_OS_MAC

To view the source code for org.apache.commons.lang SystemUtils IS_OS_MAC.

Click Source Link

Document

Is true if this is Mac.

The field will return false if OS_NAME is null.

Usage

From source file:gmgen.util.MiscUtilities.java

/**
 *  Constructs an absolute path name from a directory and another path name.
 *  This method is VFS-aware.//  ww  w.  ja va 2s  .c o m
 *
 *@param  parent  The directory
 *@param  path    The path name
 *@return         the absolute path name
 *@since          GMGen 3.3
 */
// TODO There is probably a maintained method that does that in one of the Apache Commons libraries.
public static String constructPath(String parent, String path) {
    if (isAbsolutePath(path)) {
        return canonPath(path);
    }

    // have to handle this case specially on windows.
    // insert \ between, eg A: and myfile.txt.
    if (SystemUtils.IS_OS_WINDOWS) {
        if ((path.length() == 2) && (path.charAt(1) == ':')) {
            return path;
        } else if ((path.length() > 2) && (path.charAt(1) == ':') && (path.charAt(2) != '\\')) {
            return canonPath(path.substring(0, 2) + '\\' + path.substring(2));
        }
    }

    String dd = ".." + File.separator;
    String d = "." + File.separator;

    String returnParent = (parent == null) ? Globals.getDefaultPath() : parent;
    String returnPath = path;

    //DJ: This sucks, this also needs to be fixed
    for (;;) {
        if (returnPath.equals(".")) {
            return returnParent;
        } else if (returnPath.equals("..")) {
            return getParentOfPath(returnParent);
        } else if (returnPath.startsWith(dd) || returnPath.startsWith("../")) {
            returnParent = getParentOfPath(returnParent);
            returnPath = returnPath.substring(3);
        } else if (returnPath.startsWith(d)) {
            returnPath = returnPath.substring(2);
        } else {
            break;
        }
    }

    if (SystemUtils.IS_OS_MAC && returnPath.startsWith("\\")) {
        returnParent = returnParent.substring(0, 2);
    }

    if (!returnPath.endsWith("\\") && !returnPath.endsWith("/")) {
        returnParent += File.separator;
    }

    return returnParent + returnPath;
}

From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java

protected static Resource getDefaultWaveMakerHome() {

    Resource userHome = null;/* ww  w. j  av a  2 s  .  c  o m*/
    if (SystemUtils.IS_OS_WINDOWS) {
        String userProfileEnvVar = System.getenv("USERPROFILE");
        if (StringUtils.hasText(userProfileEnvVar)) {
            userProfileEnvVar = userProfileEnvVar.endsWith("/") ? userProfileEnvVar : userProfileEnvVar + "/";
            userHome = new FileSystemResource(System.getenv("USERPROFILE"));
        }
    }
    if (userHome == null) {
        String userHomeProp = System.getProperty("user.home");
        userHomeProp = userHomeProp.endsWith("/") ? userHomeProp : userHomeProp + "/";
        userHome = new FileSystemResource(userHomeProp);
    }

    String osVersionStr = System.getProperty("os.version");
    if (osVersionStr.contains(".")) {
        String sub = osVersionStr.substring(osVersionStr.indexOf(".") + 1);
        if (sub.contains(".")) {
            osVersionStr = osVersionStr.substring(0, osVersionStr.indexOf('.', osVersionStr.indexOf('.') + 1));
        }
    }

    try {
        if (SystemUtils.IS_OS_WINDOWS) {
            userHome = new FileSystemResource(
                    javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory());
        } else if (SystemUtils.IS_OS_MAC) {
            userHome = userHome.createRelative("Documents/");
        }

        if (!userHome.exists()) {
            throw new WMRuntimeException(MessageResource.PROJECT_USERHOMEDNE, userHome);
        }

        Resource wmHome = userHome.createRelative(WAVEMAKER_HOME);
        if (!wmHome.exists()) {
            wmHome.getFile().mkdir();
        }
        return wmHome;
    } catch (IOException ex) {
        throw new WMRuntimeException(ex);
    }
}

From source file:configuration.Config.java

/**
 * This set the default configuration properties
 *///  ww w  . j  a v a  2s . co m
public void setDefaultProperties() {
    //--Ask to set Email and other helpfull
    //--Path
    set("Name", "Configuration file (config.dat)");
    set("currentPath", currentPath);
    //==
    //==Note:
    //==This databasePath represent the default project filename
    set("databasePath", currentPath + File.separator + "projects" + File.separator + "New_Untitled.db");
    set("propertiesPath", currentPath + File.separator + "data" + File.separator + "properties"); // Reflect armadillo properties path
    set("classPath",
            currentPath + File.separator + "build" + File.separator + "classes" + File.separator + "programs"); //Running program class
    set("editorPath",
            currentPath + File.separator + "build" + File.separator + "classes" + File.separator + "editors"); //editor class
    set("dataPath", currentPath + File.separator + "data");
    set("ExecutableDir", currentPath + File.separator + "Executable");
    set("tmpDir", currentPath + File.separator + "tmp");
    set("temporaryDir", currentPath + File.separator + "tmp" + File.separator + "temporary");
    set("resultsDir", currentPath + File.separator + "results");
    set("testDir", currentPath + File.separator + "test");
    set("iconsPath", currentPath + File.separator + "data" + File.separator + "icons");
    set("projectsDir", currentPath + File.separator + "projects"); // Projects Directory
    set("hgncDataPath", dataPath() + File.separator + "hgnc.txt"); //default hgnc database...
    set("hgncWebDownload",
            "http://www.genenames.org/cgi-bin/hgnc_downloads.cgi?title=HGNC+output+data&hgnc_dbtag=on&preset=all&status=Approved&status=Entry+Withdrawn&status_opt=2&level=pri&=on&where=&order_by=gd_app_sym_sort&limit=&format=text&submit=submit&.cgifields=&.cgifields=level&.cgifields=chr&.cgifields=status&.cgifields=hgnc_dbtag");
    set("log", currentPath + File.separator + "armadillo.log");

    //--Try to create the tempDir (temporary file directory) if doesn't exists
    Util.CreateDir(get("tmpDir"));
    Util.CreateDir(get("resultsDir"));
    Util.CreateDir(get("projectsDir"));
    try {
        if (Util.FileExists(dataPath("New_Untitled_default.db"))) {
            Util.copy(dataPath("New_Untitled_default.db"),
                    this.projectsDir() + File.separator + "New_Untitled.db");
        } else {
            log("Unable to find the default project file...");
        }
    } catch (Exception e) {
    }

    Util.CreateDir(get("temporaryDir"));

    //--Version and Other
    set("authorArmadillo",
            "Etienne Lord, Mickael Leclercq, Alix Boc,  Abdoulaye Banir Diallo, Vladimir Makarenkov");
    set("version", "2.0");
    set("applicationName", "Armadillo Workflow Platform");
    set("webpageArmadillo", "http://adn.bioinfo.uqam.ca/armadillo/"); //--Armadillo default webpage
    set("webserverArmadillo", "http://trex.uqam.ca/armadillo/"); //--Armadillo webserver
    set("helpArmadillo", "http://adn.bioinfo.uqam.ca/armadillo/wiki/index.php/Main_Page"); //--Armadillo default help page
    set("getting_startedArmadillo",
            dataPath() + File.separator + "Documents" + File.separator + "getting_started.html"); //--Getting started page shown at start up
    set("splashIconPath", currentPath + File.separator + "data" + File.separator + "splash1.png");
    set("smallIconPath", currentPath + File.separator + "data" + File.separator + "armadillo.png");
    set("imagePath", currentPath + File.separator + "data" + File.separator + "images");
    set("imageNcbiLoading", currentPath + File.separator + "data" + File.separator + "LoadingNcbi.jpg");
    set("imageEnsemblLoading", currentPath + File.separator + "data" + File.separator + "LoadingEnsembl.jpg");
    set("imageSequenceLoading", currentPath + File.separator + "data" + File.separator + "LoadingSequence.jpg");

    //--Editor version and name
    set("editorApplicationName", "Armadillo Editor");
    set("editorVersion", "0.1");
    set("editorAuthor", "Etienne Lord, Mickael Leclercq");
    set("workflow_w", 2000); //Initial workflow size
    set("workflow_h", 600);
    set("font_size_adjuster", 0); //--Increase of decrease workflow font size;
    set("FirstTime", 1);

    //--Special (Tree Editor, etc...)
    set("LoadPhyloWidget", false);
    //--By default, display the Start page
    set("DisplayStartPage", true);

    //--Programs
    currentPath = new File("").getAbsolutePath();

    //Databases used
    set("HGNCData", currentPath + File.separator + "data" + File.separator + "hgnc.txt");
    set("Tooltip", currentPath + File.separator + "data" + File.separator + "tooltips.csv");
    //set("iso",currentPath+"//data//iso.txt");
    set("EnsemblDb", currentPath + File.separator + "data" + File.separator + "EnsemblDB.tsv");
    //Others
    set("defaultSplashPath",
            currentPath + File.separator + "data" + File.separator + "splash" + File.separator);

    set("urlToModelTest", "http://www.hiv.lanl.gov/content/sequence/findmodel/findmodel.html");
    set("download_genbank", false);
    set("debugEditor", false);

    //--System environment specific options
    if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC) {
        set("MacOSX", true);
        set("font_size_adjuster", -1);
    } else if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_UNIX) {
        set("Linux", true);
    } else if (SystemUtils.IS_OS_WINDOWS) {
        set("Windows", true);
    }
    Save();
}

From source file:de.uni_hildesheim.sse.easy_producer.instantiator.model.buildlangModel.BuildlangExecution.java

/**
 * Processes the {@link LoadProperties}.
 * /*from  w w w . j  ava 2s  .  co m*/
 * @param script the script to process the properties for
 * @param base the base path to make relative paths absolute
 * @throws VilLanguageException in case that something goes wrong
 */
private void processProperties(Script script, File base) throws VilLanguageException {
    Properties loaded = new Properties();
    for (int p = 0; p < script.getPropertiesCount(); p++) {
        LoadProperties prop = script.getProperties(p);
        String path = prop.getPath();
        try {
            path = StringReplacer.substitute(path, environment, getExpressionParser(), this);
        } catch (ExpressionException e) {
            throw new VilLanguageException(e);
        }
        File file = absolute(path, base);
        loadProperties(file, loaded, null);
        if (SystemUtils.IS_OS_MAC) {
            loadProperties(file, loaded, "macos");
        } else if (SystemUtils.IS_OS_UNIX) {
            loadProperties(file, loaded, "unix");
        } else if (SystemUtils.IS_OS_WINDOWS) {
            loadProperties(file, loaded, "win");
        }
    }
    for (int v = 0; v < script.getVariableDeclarationCount(); v++) {
        VariableDeclaration var = script.getVariableDeclaration(v);
        String value = loaded.getProperty(var.getName(), null);
        if (null != value) {
            if (var.isConstant() && null != var.getExpression()) {
                throw new VilLanguageException("constant '" + var.getName() + "' is already assigned a value",
                        VilLanguageException.ID_IS_CONSTANT);
            }
            Object actValue = evaluateExternalValue(var, value);
            environment.setValue(var, actValue);
            tracer.valueDefined(var, actValue);
        }
    }
}

From source file:com.github.vatbub.awsvpnlauncher.Main.java

/**
 * Copies {@code System.in} to new {@code InputStream}. Filters {@code CrLf}s ({@code \r\n} in Java) out and replaces them with a single {@code \n} ({@code \n} in Java)
 *
 * @return The {@code InputStream} to which the filtered contents are forwarded to.
 * @throws IOException If {@code System.in} cannot be read for any reason
 *///from   www . j  a va2s .  com
private static InputStream copyAndFilterInputStream() throws IOException {
    PipedOutputStream forwardTo = new PipedOutputStream();
    PipedInputStream res = new PipedInputStream(forwardTo);
    Thread pipeThread = new Thread(() -> {
        while (true) {
            try {
                char ch = (char) System.in.read();
                if (ch != '\r' && !SystemUtils.IS_OS_MAC) {
                    forwardTo.write((int) ch);
                }
            } catch (IOException e) {
                FOKLogger.log(Main.class.getName(), Level.SEVERE,
                        "Stopped forwarding System in due to an exception", e);
                break;
            }
        }
    });
    pipeThread.setName("pipeThread");
    pipeThread.start();

    return res;
}

From source file:net.ssehub.easy.instantiation.core.model.buildlangModel.BuildlangExecution.java

/**
 * Processes the {@link LoadProperties}.
 * /*from w  w w.  j  a  va2 s .c o m*/
 * @param script the script to process the properties for
 * @param base the base path to make relative paths absolute
 * @throws VilException in case that something goes wrong
 */
protected void processProperties(Script script, File base) throws VilException {
    Properties loaded = new Properties();
    for (int p = 0; p < script.getPropertiesCount(); p++) {
        LoadProperties prop = script.getProperties(p);
        String path = prop.getPath();
        path = StringReplacer.substitute(path, new Resolver(environment), getExpressionParser(), this, null);
        File file = absolute(path, base);
        loadProperties(file, loaded, null);
        if (SystemUtils.IS_OS_MAC) {
            loadProperties(file, loaded, "macos");
        } else if (SystemUtils.IS_OS_UNIX) {
            loadProperties(file, loaded, "unix");
        } else if (SystemUtils.IS_OS_WINDOWS) {
            loadProperties(file, loaded, "win");
        }
    }
    for (int v = 0; v < script.getVariableDeclarationCount(); v++) {
        VariableDeclaration var = script.getVariableDeclaration(v);
        String value = loaded.getProperty(var.getName(), null);
        if (null != value) {
            if (var.isConstant() && null != var.getExpression()) {
                throw new VilException("constant '" + var.getName() + "' is already assigned a value",
                        VilException.ID_IS_CONSTANT);
            }
            Object actValue = evaluateExternalValue(var, value);
            environment.setValue(var, actValue);
            tracer.valueDefined(var, null, actValue);
        }
    }
}

From source file:no.java.ems.client.swing.EmsClient.java

private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu();
    fileMenu.setName("menus.file");
    fileMenu.add(new DelegatingAction("new", tabs));
    fileMenu.addSeparator();/*from   w  ww  .j a v  a2  s  .co  m*/
    fileMenu.add(new DelegatingAction("open", tabs));
    fileMenu.addSeparator();
    fileMenu.add(new DelegatingAction("refresh", tabs));
    fileMenu.addSeparator();
    fileMenu.add(new CloseTabAction());
    fileMenu.addSeparator();
    fileMenu.add(saveAction);
    fileMenu.addSeparator();
    fileMenu.add(logInAction);
    fileMenu.add(logOutAction);
    if (!SystemUtils.IS_OS_MAC) {
        fileMenu.addSeparator();
        fileMenu.add(exitAction);
    }
    menuBar.add(fileMenu);
    JMenu editMenu = new JMenu();
    editMenu.setName("menus.edit");
    editMenu.add(undoAction);
    editMenu.add(redoAction);
    editMenu.addSeparator();
    editMenu.add(new DelegatingAction("cut", tabs));
    editMenu.add(new DelegatingAction("copy", tabs));
    editMenu.add(new DelegatingAction("paste", tabs));
    editMenu.add(new DelegatingAction("delete", tabs));
    editMenu.addSeparator();
    editMenu.add(new DelegatingAction("addTags", tabs));
    editMenu.add(new DelegatingAction("replaceTags", tabs));
    editMenu.add(new DelegatingAction("addKeywords", tabs));
    editMenu.add(new DelegatingAction("replaceKeywords", tabs));
    menuBar.add(editMenu);
    if (SystemUtils.IS_OS_MAC) {
        for (int index = 0; index < menuBar.getMenuCount(); index++) {
            removeIcons(menuBar.getMenu(index));
        }
    }
    return menuBar;
}

From source file:org.alfresco.os.mac.app.ScreenShotTest.java

@Test(groups = { "development" })
public void ldtp() {
    try {//from  w  ww.  ja va  2  s  .  c  o m
        if (SystemUtils.IS_OS_MAC) {
            TextEdit notepad = new TextEdit();
            notepad.openApplication();
            notepad.close("error");
        } else if (SystemUtils.IS_OS_WINDOWS) {
            Notepad notepad = new Notepad();
            notepad.openApplication();
            notepad.close(new File("error"));
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TestException(e.getMessage(), e.getCause());
    }
}

From source file:org.alfresco.utilities.LdtpUtils.java

/**
 * This will kill a process based on windowsName - works on linux/mac OS
 * Fow windows application, just pass the exe name of the application as <windowName> e.g. "notepad.exe"
 * // w  w  w.  ja v a  2 s.  co  m
 * @author <a href="mailto:paulbrodner@gmail.com">Paul Brodner</a>
 * @param windowName
 */
public static void killProcessByWindowName(String windowName) {

    if (SystemUtils.IS_OS_MAC) {
        executeOnUnix("kill `ps ax | grep \"" + windowName + "\" | awk '{print $1}'`");
    }

    if (SystemUtils.IS_OS_WINDOWS) {
        execute(new String[] { "taskkill", "/F", "/IM", windowName });
    }
}

From source file:org.alfresco.utilities.LdtpUtils.java

public static File getDocumentsFolder() {
    if (SystemUtils.IS_OS_MAC) {
        return new File(getHomeFolder(), "Documents");
    } else if (SystemUtils.IS_OS_WINDOWS) {
        return new File(getHomeFolder(), "My Documents");
    }/*from   ww  w  . j a va 2s  .  co  m*/
    return null;
}