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:hudson.maven.RedeployPublisherTest.java

@Bug(2593)
@Test//from   w  w  w. j ava  2  s .c o m
public void testBug2593() throws Exception {
    Assume.assumeFalse(
            "Not a v4.0.0 POM. for project org.jvnet.maven-antrun-extended-plugin:maven-antrun-extended-plugin at /home/jenkins/.m2/repository/org/jvnet/maven-antrun-extended-plugin/maven-antrun-extended-plugin/1.39/maven-antrun-extended-plugin-1.39.pom",
            "https://jenkins.ci.cloudbees.com/job/core/job/jenkins_main_trunk/"
                    .equals(System.getenv("JOB_URL")));
    j.configureDefaultMaven();
    MavenModuleSet m2 = j.createMavenProject();
    File repo = tmp.getRoot();

    // a fake build
    m2.setScm(new SingleFileSCM("pom.xml", getClass().getResource("big-artifact.pom")));
    m2.getPublishersList().add(new RedeployPublisher("", repo.toURI().toString(), true, false));

    MavenModuleSetBuild b = m2.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.SUCCESS, b);

    // TODO: confirm that the artifacts use a consistent timestamp
    // TODO: we need to somehow introduce a large delay between deploy since timestamp is only second precision
    // TODO: or maybe we could use a btrace like capability to count the # of invocations?

    System.out.println(repo);
}

From source file:com.ibm.watson.apis.conversation_enhanced.retrieve_and_rank.Query.java

public Query() {
    ServiceCredentials creds = CredentialUtils.getUserNameAndPassword("retrieve_and_rank"); //$NON-NLS-1$
    if (creds == null) {
        throw new IllegalArgumentException(Messages.getString("Query.NO_SERVICE_CREDENTIALS")); //$NON-NLS-1$
    }/* w w w  . j ava  2  s  . co m*/
    USERNAME = creds.getUsername();
    PASSWORD = creds.getPassword();

    RetrieveAndRank retrieveAndRankService = new RetrieveAndRank();
    retrieveAndRankService.setUsernameAndPassword(USERNAME, PASSWORD);

    if (StringUtils.isNotBlank(System.getenv("CLUSTER_ID"))) { //$NON-NLS-1$
        CLUSTER_ID = System.getenv("CLUSTER_ID"); //$NON-NLS-1$
    } else {
        try {
            CLUSTER_ID = retrieveAndRankService.getSolrClusters().execute().getSolrClusters().get(0).getId();
        } catch (Exception e) {
            throw new IllegalArgumentException(Messages.getString("Query.MISSING_CLUSTER_ID")); //$NON-NLS-1$
        }
    }
    if (StringUtils.isNotBlank(System.getenv("RANKER_ID"))) { //$NON-NLS-1$
        RANKER_ID = System.getenv("RANKER_ID"); //$NON-NLS-1$
    } else {
        try {
            RANKER_ID = retrieveAndRankService.getRankers().execute().getRankers().get(0).getId();
        } catch (Exception e) {
            throw new IllegalArgumentException(Messages.getString("Query.MISSING_RANKER_ID")); //$NON-NLS-1$
        }
    }
    if (StringUtils.isNotBlank(System.getenv("COLLECTION_NAME"))) { //$NON-NLS-1$
        COLLECTION_NAME = System.getenv("COLLECTION_NAME"); //$NON-NLS-1$
    } else {
        COLLECTION_NAME = Constants.COLLECTION_NAME;
    }
}

From source file:idgs.metadata.LocalStoreLoader.java

@Override
public DataStoreConfig loadDataStoreConf() throws IdgsException {
    log.info("load store config: " + cfgFilePath);
    if (storeConfigMap.containsKey(cfgFilePath)) {
        return storeConfigMap.get(cfgFilePath);
    }//from   ww w  . j ava  2s  .  com

    File file = new File(cfgFilePath);
    do {
        if (file.exists()) {
            break;
        }

        String temppath;
        // IDGS_HOME env
        if ((temppath = System.getenv("IDGS_HOME")) != null) {
            temppath = temppath + "/" + cfgFilePath;
            file = new File(temppath);
            if (file.exists()) {
                break;
            }
        }

        URL url = LocalStoreLoader.class.getClassLoader().getResource(cfgFilePath);
        if (url != null) {
            file = new File(url.getFile());
            break;
        }

        log.error("Data store config file " + cfgFilePath + " is not found.");
        throw new IdgsException("Data store config file " + cfgFilePath + " is not found.");
    } while (false);

    DataStoreConfig.Builder builder = DataStoreConfig.newBuilder();
    try {
        JsonUtil.jsonFileToPb(builder, file.getAbsolutePath());
    } catch (IOException e) {
        log.error(e.getMessage());
        throw new IdgsException(e);
    }

    DataStoreConfig conf = builder.build();
    storeConfigMap.put(cfgFilePath, conf);
    return conf;
}

From source file:com.cloudera.seismic.segy.SegyLoader.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("cwproot", true, "The path to CWPROOT on this machine");
    options.addOption("input", true, "SEG-Y files to import into Hadoop");
    options.addOption("output", true, "The path of the sequence file to write in Hadoop");

    // Parse the commandline and check for required arguments.
    CommandLine cmdLine = new PosixParser().parse(options, args, false);
    if (!cmdLine.hasOption("input") || !cmdLine.hasOption("output")) {
        System.out.println("Mising required input/output arguments");
        new HelpFormatter().printHelp("SegyLoader", options);
        System.exit(1);/*from  w ww .j  ava2  s  .  c o m*/
    }

    String cwproot = System.getenv("CWPROOT");
    if (cmdLine.hasOption("cwproot")) {
        cwproot = cmdLine.getOptionValue("cwproot");
    }
    if (cwproot == null || cwproot.isEmpty()) {
        System.out.println("Could not determine CWPROOT value, using /usr/local/su...");
        cwproot = "/usr/local/su";
    }

    // Assume any remaining args are for segyread
    List<String> segyReadArgs = Lists.newArrayList();
    for (String arg : cmdLine.getArgs()) {
        if (arg.contains("=")) {
            segyReadArgs.add(arg);
        }
    }

    // Open the output sequence file.
    Configuration conf = getConf();
    Path outputPath = new Path(cmdLine.getOptionValue("output"));
    SequenceFile.Writer writer = SequenceFile.createWriter(FileSystem.get(conf), conf, outputPath,
            NullWritable.class, BytesWritable.class, CompressionType.BLOCK);
    int rc = 0;
    SequenceFileCallback sfc = new SequenceFileCallback(writer);
    try {
        for (String filename : cmdLine.getOptionValues("input")) {
            System.out.println("Reading input file: " + filename);
            if (filename.endsWith(".su")) {
                SUReader reader = new SUReader(new BufferedInputStream(new FileInputStream(filename)),
                        ImmutableList.<SUCallback>of(sfc));
                reader.run();
                System.out.println("Bytes read: " + reader.getBytesRead());
            } else {
                SUProcess proc = new SUProcess(cwproot, "segyread");
                for (String arg : segyReadArgs) {
                    proc.addArg(arg);
                }
                proc.addArg(String.format("tape=%s", filename));
                proc.addCallback(sfc);
                proc.start();
                rc += proc.closeAndWait();
                System.out.println("Bytes read: " + proc.getTotalBytesRead());
            }
        }
        System.out.println("Bytes written: " + sfc.getBytesWritten());
    } catch (Throwable t) {
        t.printStackTrace();
        rc = 1;
    } finally {
        writer.close();
    }
    return rc;
}

From source file:fr.inria.lille.repair.nopol.NoPolLauncher.java

public static List<Patch> launch(File[] sourceFile, URL[] classpath, StatementType type, String[] args) {
    System.out.println("Source files: " + Arrays.toString(sourceFile));
    System.out.println("Classpath: " + Arrays.toString(classpath));
    System.out.println("Statement type: " + type);
    System.out.println("Args: " + Arrays.toString(args));
    System.out.println("Config: " + Config.INSTANCE);
    System.out.println("Available processors (cores): " + Runtime.getRuntime().availableProcessors());

    /* Total amount of free memory available to the JVM */
    System.out.println("Free memory: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory()));

    /* This will return Long.MAX_VALUE if there is no preset limit */
    long maxMemory = Runtime.getRuntime().maxMemory();
    /* Maximum amount of memory the JVM will attempt to use */
    System.out.println("Maximum memory: "
            + (maxMemory == Long.MAX_VALUE ? "no limit" : FileUtils.byteCountToDisplaySize(maxMemory)));

    /* Total memory currently available to the JVM */
    System.out.println("Total memory available to JVM: "
            + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory()));

    System.out.println("Java version: " + Runtime.class.getPackage().getImplementationVersion());
    System.out.println("JAVA_HOME: " + System.getenv("JAVA_HOME"));
    System.out.println("PATH: " + System.getenv("PATH"));

    long executionTime = System.currentTimeMillis();
    NoPol nopol = new NoPol(sourceFile, classpath, type);
    List<Patch> patches = null;
    try {//from  w ww. ja  v  a 2s.c  o  m
        if (args.length > 0) {
            patches = nopol.build(args);
        } else {
            patches = nopol.build();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        executionTime = System.currentTimeMillis() - executionTime;
        displayResult(nopol, patches, executionTime);
    }
    return patches;
}

From source file:com.seleniumtests.ut.connectors.extools.TestSoapUi.java

@Test(groups = { "ut" })
public void testSoapUiInstallOk() throws IOException {
    File tmp = Files.createTempDir();
    File runner = Paths.get(tmp.getAbsolutePath(), "bin", "testrunner.bat").toFile();
    FileUtils.write(runner, "rem");

    PowerMockito.mockStatic(System.class);
    when(System.getenv("SOAPUI_HOME")).thenReturn(tmp.getAbsolutePath());
    new SoapUi();
}

From source file:cz.hobrasoft.pdfmu.operation.args.PasswordArgs.java

@Override
public void setFromNamespace(Namespace namespace) {
    assert title != null;
    assert passwordArgument != null;
    password = namespace.getString(passwordArgument.getDest());
    if (password == null) {
        // Load the password from an environment variable
        assert environmentVariableArgument != null;
        String envVar = namespace.getString(environmentVariableArgument.getDest());
        assert envVar != null; // The argument has a default value
        logger.info(String.format("%s environment variable: %s", StringUtils.capitalize(title), envVar));
        password = System.getenv(envVar);
        if (password != null) {
            logger.info(String.format("%s loaded from the environment variable %s.",
                    StringUtils.capitalize(title), envVar));
        } else {/*from   w ww . j  a v  a2 s.  co  m*/
            logger.info(String.format("%s was not set.", StringUtils.capitalize(title)));
        }
    } else {
        logger.info(String.format("%s loaded from the command line.", StringUtils.capitalize(title)));
    }
}

From source file:com.prowidesoftware.deprecation.DeprecationUtils.java

/**
 * Returns true if the environment variable {@link #PW_DEPRECATED} contains
 * the given key in its value//from   ww w .java 2s  . c o m
 */
private static final boolean isSet(final EnvironmentVariableKey key) {
    return StringUtils.containsIgnoreCase(System.getenv(PW_DEPRECATED), key.name());
}

From source file:org.hazelcast.cloudfoundry.servicebroker.service.HazelcastAdmin.java

private Config getHazelcastInstanceConfig(String serviceInstanceId) {
    Config config = new Config();
    String managementCenterURL = System.getenv("MANAGEMENT_CENTER_URL");
    if (managementCenterURL != null && !managementCenterURL.equals("")) {
        config.getManagementCenterConfig().setEnabled(true).setUrl(managementCenterURL).setUpdateInterval(3);
    }/*w w w  . j  av a 2  s . co m*/
    config.setInstanceName(serviceInstanceId);
    NetworkConfig network = config.getNetworkConfig();
    JoinConfig join = network.getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().setEnabled(true);
    String clusterMembers = getClusterMembersConfig();
    if (clusterMembers != null)
        join.getTcpIpConfig().addMember(clusterMembers);
    network.getInterfaces().setEnabled(true).addInterface("10.*.*.*");

    return config;
}