Example usage for java.lang System getenv

List of usage examples for java.lang System getenv

Introduction

In this page you can find the example usage for java.lang System getenv.

Prototype

public static String getenv(String name) 

Source Link

Document

Gets the value of the specified environment variable.

Usage

From source file:com.qspin.qtaste.tcom.rlogin.RLogin.java

/**
 * Main program./* w w  w. j a  v a 2 s  .  c  o m*/
 * <p>
 * Usage: <command> <remote_host> [-user <user>] [-reboot | -command <command>] [-interactive] [-logOutput] [-wait [seconds]] [-log4jconf <properties_file>]
 *   remote_host: remote host
 *   -user <user>: remote user
 *   -reboot: reboot remote host
 *   -command <command>: send command to remote host
 *   -interactive: enable interactive mode, i.e. sending commands from standard input, this also enables the wait parameter
 *   -logOutput: enable logging of remote host output
 *   -wait [seconds]: wait until connection is closed or given seconds
 *   -log4jconf <properties_file>: use given file as log4j properties file
 */
public static final void main(String[] args) {
    // parameters
    String remoteHost = null;
    String remoteUser = "";
    boolean reboot = false;
    String command = null;
    boolean interactive = false;
    boolean logOutput = false;
    String log4jconf = null;
    boolean wait = false;
    Integer waitTime = null;

    // parse command-line arguments
    if (args.length == 0) {
        showUsage();
    }
    remoteHost = args[0];
    int i = 1;
    while (i < args.length) {
        if (args[i].equals("-reboot")) {
            reboot = true;
            i++;
        } else if (args[i].equals("-user") && (i + 1 < args.length)) {
            remoteUser = args[i + 1];
            i += 2;
        } else if (args[i].equals("-command") && (i + 1 < args.length)) {
            command = args[i + 1];
            i += 2;
        } else if (args[i].equals("-interactive")) {
            interactive = true;
            wait = true;
            i++;
        } else if (args[i].equals("-logOutput")) {
            logOutput = true;
            i++;
        } else if (args[i].equals("-wait")) {
            wait = true;
            if ((i + 1 < args.length)) {
                // more arguments, check if next argument is a wait argument
                if (args[i + 1].startsWith("-")) {
                    i++;
                } else {
                    waitTime = Integer.valueOf(args[i + 1]);
                    i += 2;
                }
            } else {
                // no more arguments
                i++;
            }
        } else if (args[i].equals("-log4jconf") && (i + 1 < args.length)) {
            log4jconf = args[i + 1];
            i += 2;
        } else {
            showUsage();
        }
    }
    if (reboot && (command != null)) {
        showUsage();
    }

    try {
        // Log4j Configuration
        String log4jPropertiesFileName = log4jconf != null ? log4jconf
                : StaticConfiguration.CONFIG_DIRECTORY + "/log4j.properties";
        PropertyConfigurator.configure(log4jPropertiesFileName);

        // get local user name
        String localUser;
        if (OS.getType() == OS.Type.WINDOWS) {
            localUser = System.getenv("USERNAME");
        } else {
            localUser = System.getenv("USER");
        }

        // rlogin connection
        RLogin rlogin = new RLogin(remoteHost, localUser, remoteUser, "", logOutput, interactive);
        if (!rlogin.connect()) {
            System.exit(1);
        }

        // reboot if asked
        if (reboot) {
            boolean success = rlogin.reboot();
            System.exit(success ? 0 : 1);
        }

        // send command if asked
        if (command != null) {
            if (!rlogin.sendCommand(command)) {
                rlogin.disconnect();
                System.exit(1);
            }
        }

        // wait if asked
        if (wait) {
            try {
                if (waitTime != null) {
                    rlogin.outputReaderThread.join(SEC_TO_MS_FACTOR * waitTime);
                } else {
                    rlogin.outputReaderThread.join();
                }
            } catch (InterruptedException ex) {
                logger.error("Wait interrupted");
            }
        }

        rlogin.disconnect();
        System.exit(0);
    } catch (Exception e) {
        logger.error(e);
        System.exit(1);
    }
}

From source file:com.jiwhiz.mail.sendgrid.Vcapenv.java

public String setNode() {
    String vcap_services = System.getenv("VCAP_SERVICES");

    try {//from w ww.  ja  v  a2 s. c o m
        this.original_node = this.mapper.readValue(vcap_services, JsonNode.class);
        this.current_node = this.mapper.readValue(vcap_services, JsonNode.class);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return vcap_services;
}

From source file:com.google.testing.web.screenshotter.Screenshotter.java

/**
 * Create a new Screenshotter that interacts with the WebDriver session to which driver is
 * connected./* w w  w . j  a v a2 s  .  c  om*/
 */
public Screenshotter(WebDriver driver) {
    this(String.format("%s/session/%s/google/screenshot", System.getenv("WEB_TEST_WEBDRIVER_SERVER"),
            String.valueOf(((RemoteWebDriver) driver).getSessionId())), Optional.empty(), ImmutableSet.of());
}

From source file:com.opera.core.systems.OperaPaths.java

/**
 * This method will try and find Opera on any system. It takes the following
 * steps://from w  w w.jav a2s .  c  o  m
 *  1. Check the environment variable "OPERA_PATH". If it exists, and the
 *     file it points to exists, then return
 *  2. Check if Opera exists at the default location on the respective OS
 *  3. (Unix) Call `which opera` to find the location
 *  4. Give up and return null
 * @return The path to Opera, or null
 */
public String operaPath() {
    String path = System.getenv("OPERA_PATH");

    if (isPathValid(path))
        return path;

    Platform platform = Platform.getCurrent();

    switch (platform) {
    case LINUX:
    case UNIX:
        path = "/usr/bin/opera";
        if (!isPathValid(path)) {
            CommandLine line = new CommandLine("which", "opera");
            line.execute();
            path = line.getStdOut().trim();
        }
        break;
    case MAC:
        path = "/Applications/Opera.app/Contents/MacOS/Opera";
        break;
    case WINDOWS:
    case XP:
    case VISTA:
        String x86 = System.getenv("ProgramFiles(x86)");
        String progfiles = (x86 == null) ? System.getenv("PROGRAMFILES") : x86;
        if (progfiles == null)
            progfiles = "\\Program Files";
        path = progfiles + "\\Opera\\opera.exe";
        break;
    default:
        throw new WebDriverException("Auto find is not support on this platform"); // android?
    }
    return (isPathValid(path)) ? path : null;
}

From source file:org.kiji.checkin.CommandLogger.java

/**
 * Constructs a new instance of the CommandLogger.
 *///from   ww w  .  j  a va2 s . c  o m
public CommandLogger() {
    // Environment variable set by script in kiji or bento.
    String checkinServerUrl = System.getenv(KIJI_CHECKIN_SERVER);
    if (checkinServerUrl != null) {
        try {
            // TODO: BENTO-37: environment variable should be a base URI
            // until then, let's do a few checks to make sure the suffix is correct
            if (checkinServerUrl.endsWith("/checkin") || checkinServerUrl.endsWith("/checkin/")) {
                checkinServerUrl = checkinServerUrl.replace("/checkin", "/command");
            } else if (!checkinServerUrl.endsWith("/command")) {
                String suffix = "command";
                if (!checkinServerUrl.endsWith("/")) {
                    suffix = "/" + suffix;
                }
                checkinServerUrl += suffix;
            }

            mCheckinServerUri = new URI(checkinServerUrl);
        } catch (URISyntaxException e) {
            LOG.error("ERROR", e);
        }
    }
}

From source file:com.devnexus.ting.common.SystemInformationUtils.java

/**
 *
 * @return//from   w w  w.  ja  v  a 2  s.c o  m
 */
public static Apphome retrieveBasicSystemInformation() {

    final Apphome apphome = new Apphome();

    CloudEnvironment env = new CloudEnvironment();
    if (env.getInstanceInfo() != null) {

        apphome.setAppHomePath(null);
        apphome.setAppHomeSource(AppHomeSource.CLOUD);

    } else if (StringUtils.isNotBlank(System.getProperty(Apphome.APP_HOME_DIRECTORY))) {

        apphome.setAppHomePath(System.getProperty(Apphome.APP_HOME_DIRECTORY));
        apphome.setAppHomeSource(AppHomeSource.SYSTEM_PROPERTY);

    } else if (StringUtils.isNotBlank(System.getenv(Apphome.APP_HOME_DIRECTORY))) {

        apphome.setAppHomePath(System.getenv(Apphome.APP_HOME_DIRECTORY));
        apphome.setAppHomeSource(AppHomeSource.ENVIRONMENT_VARIABLE);

    } else {

        final String userHomeDirectiory = System.getProperty("user.home");

        apphome.setAppHomePath(userHomeDirectiory + File.separator + ".ting");
        apphome.setAppHomeSource(AppHomeSource.USER_DIRECTORY);

    }

    return apphome;
}

From source file:com.intuit.tank.vm.settings.CloudCredentials.java

/**
 * @return the key/*from w  w  w .  j a v  a  2s.c o  m*/
 */
public String getKey() {
    // first try userData
    String ret = AmazonUtil.getAWSKeyFromUserData();
    if (StringUtils.isBlank(ret)) {
        // try to get from property
        String key = config.getString("secret-key-property", "AWS_SECRET_KEY");
        ret = System.getProperty(key);
        if (StringUtils.isBlank(ret)) {
            ret = System.getenv(key);
        }
        if (StringUtils.isBlank(ret)) {
            // finally get straight from config
            ret = config.getString("secret-key");
        }
    }
    return ret;
}

From source file:com.twosigma.beaker.kdb.KdbProcess.java

/**
 * Create a new KdbProcess.//from  w w  w  . j  a  v  a  2  s . c om
 *
 * @param sessionId  the session id (for namespace access).
 * @param kdbPort    the port for kdb to listen on.
 */
public KdbProcess(String sessionId, int kdbPort, String qh) throws Exception {
    super("kdb-" + sessionId + ":" + kdbPort);
    this.sessionId = sessionId;
    this.kdbPort = kdbPort;

    if (qh == null) {
        qhome = System.getenv(QHOME);
    } else {
        qhome = qh;
    }

    // Try to find the q binary.
    if (qhome == null) {
        throw new Exception("QHOME is not set");
    }

    {
        // Get OS-specific candidates.
        List<String> binaries = new ArrayList<>();
        if (SystemUtils.IS_OS_WINDOWS) {
            binaries.add("w64/q.exe");
            binaries.add("w32/q.exe");
        } else if (SystemUtils.IS_OS_MAC_OSX) {
            binaries.add("m64/q");
            binaries.add("m32/q");
        } else if (SystemUtils.IS_OS_LINUX) {
            binaries.add("l64/q");
            binaries.add("l32/q");
        } else {
            throw new Exception("Unsupported operating system");
        }

        String bin = null;
        for (String s : binaries) {
            String f = qhome + File.separator + s;
            if (new File(f).canExecute()) {
                bin = f;
                break;
            }
        }

        if (bin == null) {
            throw new Exception("Cannot find q binary");
        } else {
            qbin = bin;
        }
    }

    // Beaker calls destroy() on us, so add a shutdown hook to
    // cleanly shut down kdb at the end.
    Runtime.getRuntime().addShutdownHook(new Thread("kdb-killer") {
        @Override
        public void run() {
            KdbProcess.this.interrupt();
        }
    });
}

From source file:net.firejack.platform.service.deployment.broker.DeployBroker.java

@Override
protected ServiceResponse perform(ServiceRequest<NamedValues> request) throws Exception {
    Long packageId = (Long) request.getData().get("packageId");
    String name = (String) request.getData().get("name");
    String file = (String) request.getData().get("file");
    String host = InetAddress.getLocalHost().getHostName();

    if (debug) {/*from   w  ww  . ja v a2 s.c o  m*/
        webapps = new File(System.getenv("CATALINA_HOME"), "webapps");
    }

    InputStream stream = OPFEngine.RegistryService.getPackageArchive(packageId, file);

    File app = new File(webapps, name + ".temp");
    FileOutputStream outputStream = FileUtils.openOutputStream(app);
    if (stream != null) {
        IOUtils.copy(stream, outputStream);
        IOUtils.closeQuietly(outputStream);
        IOUtils.closeQuietly(stream);

        File war = new File(app.getParent(), name);
        FileUtils.deleteQuietly(war);
        FileUtils.moveFile(app, war);
    }

    return new ServiceResponse("Deploy to server " + host + " successfully", true);
}

From source file:com.yfiton.notifiers.email.EmailNotifierTest.java

@Test
public void testOutlook() throws MessagingException, ConfigurationException, ParameterException {
    // http://pchelp.ricmedia.com/how-to-fix-550-5-3-4-requested-action-not-taken-error/
    testSendEmail("outlook", "imap-mail.outlook.com", System.getenv("OUTLOOK_EMAIL"),
            System.getenv("OUTLOOK_USERNAME"), System.getenv("OUTLOOK_PASSWORD"));
}