Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

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

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:com.krawler.portal.util.SystemProperties.java

public static void set(String key, String value) {
    System.setProperty(key, value);

    _instance._props.put(key, value);
}

From source file:hudson.plugins.blazemeter.ProxyConfigurator.java

public static void updateProxySettings(ProxyConfiguration proxyConfiguration, boolean isSlave)
        throws Exception {
    if (isSlave && "true".equals(System.getProperty(PROXY_OVERRIDE))) {
        LOGGER.info("Override proxy setting for slave");
        LOGGER.info("Use proxy host: " + System.getProperty(PROXY_HOST));
        LOGGER.info("Use proxy port: " + System.getProperty(PROXY_PORT));
        return;/*from   w ww. j av a  2s  .  c  o m*/
    }

    if (proxyConfiguration != null) {
        if (StringUtils.isNotBlank(proxyConfiguration.name)) {
            LOGGER.info("Use proxy host: " + proxyConfiguration.name);
            System.setProperty(PROXY_HOST, proxyConfiguration.name);
        }

        if (StringUtils.isNotBlank(String.valueOf(proxyConfiguration.port))) {
            LOGGER.info("Use proxy port: " + proxyConfiguration.port);
            System.setProperty(PROXY_PORT, String.valueOf(proxyConfiguration.port));
        }

        if (StringUtils.isNotBlank(proxyConfiguration.getUserName())) {
            System.setProperty(PROXY_USER, proxyConfiguration.getUserName());
        }

        if (StringUtils.isNotBlank(proxyConfiguration.getPassword())) {
            System.setProperty(PROXY_PASS, proxyConfiguration.getPassword());
        }
    } else {
        LOGGER.info("Clear proxy configs");
        System.clearProperty(PROXY_HOST);
        System.clearProperty(PROXY_PORT);
        System.clearProperty(PROXY_USER);
        System.clearProperty(PROXY_PASS);
    }
}

From source file:com.streamsets.datacollector.runner.production.TestProductionSourceOffsetTracker.java

@BeforeClass
public static void beforeClass() throws IOException {
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR, "./target/var");
    File f = new File(System.getProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR));
    try {/*from  w  w w. j  a v a2s . c  o m*/
        FileUtils.deleteDirectory(f);
    } catch (Exception ex) {
        LOG.info(Utils.format("Got exception while deleting directory: {}", f.getAbsolutePath()), ex);
    }

}

From source file:io.github.azige.moebooruviewer.MoebooruAPITest.java

@BeforeClass
public static void setUpClass() {
    System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.err");
}

From source file:com.streamsets.datacollector.execution.runner.common.TestProductionSourceOffsetCommitterOffsetTracker.java

@BeforeClass
public static void beforeClass() throws IOException {
    System.setProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR, "./target/var");
    File f = new File(System.getProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR));
    FileUtils.deleteDirectory(f);//  w ww . ja  va 2  s.  c om
}

From source file:com.od.jtimeseries.component.AbstractJTimeSeriesComponent.java

private static void initializeLogging(Class logClass) {
    //set the hostname as a system property so that it is available on startup to the spring context property placeholder configurer
    System.setProperty("hostname", getHostname(logClass));

    //First read the logging configuration and set this up before other classes are loaded, since other classes in JTimeSeriesServer will
    //initialize their static loggers when they are first loaded, and the logging subsystem needs to be set up first.
    ApplicationContext loggingContext = new ClassPathXmlApplicationContext("logContext.xml");
    configureLogging(loggingContext, logClass);

    logMethods = LogUtils.getLogMethods(logClass);
}

From source file:org.springframework.cloud.stream.metrics.ApplicationMetricsExporterTests.java

@BeforeClass
public static void setSystemProps() {
    System.setProperty("SPRING_TEST_ENV_SYNTAX", "testing");
}

From source file:alfio.repository.EventRepositoryTest.java

@BeforeClass
public static void initEnv() {
    System.setProperty("datasource.dialect", "HSQLDB");
    System.setProperty("datasource.driver", "org.hsqldb.jdbcDriver");
    System.setProperty("datasource.url", "jdbc:hsqldb:mem:alfio");
    System.setProperty("datasource.username", "sa");
    System.setProperty("datasource.password", "");
    System.setProperty("datasource.validationQuery", "SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    System.setProperty("spring.profiles.active", Initializer.PROFILE_DEV);
}

From source file:junit.org.rapidpm.microservice.demo.ServletTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    final PortUtils portUtils = new PortUtils();
    final int restPort = portUtils.nextFreePortForTest();
    final int servletPort = portUtils.nextFreePortForTest();

    url = "http://127.0.0.1:" + servletPort + Main.MYAPP
            + MessageServlet.class.getAnnotation(WebServlet.class).urlPatterns()[0];

    System.setProperty(Main.REST_HOST_PROPERTY, "127.0.0.1");
    System.setProperty(Main.SERVLET_HOST_PROPERTY, "127.0.0.1");

    System.setProperty(Main.REST_PORT_PROPERTY, restPort + "");
    System.setProperty(Main.SERVLET_PORT_PROPERTY, servletPort + "");
}

From source file:org.apache.s4.client.Adapter.java

@SuppressWarnings("static-access")
public static void main(String args[]) throws IOException, InterruptedException {

    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(/*from  w  w  w  .  j av  a 2  s.  c  o m*/
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    options.addOption(OptionBuilder.withArgName("userconfig").hasArg()
            .withDescription("user-defined legacy data adapter configuration file").create("d"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    String userConfigFilename = null;
    if (commandLine.hasOption("d")) {
        userConfigFilename = commandLine.getOptionValue("d");
    }

    File userConfigFile = new File(userConfigFilename);
    if (!userConfigFile.isFile()) {
        System.err.println("Bad user configuration file: " + userConfigFilename);
        System.exit(1);
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = configBase + File.separatorChar + "client-adapter-conf.xml";
    File configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("adapter config file %s does not exist\n", configPath);
        System.exit(1);
    }

    // load adapter config xml
    ApplicationContext coreContext;
    coreContext = new FileSystemXmlApplicationContext("file:" + configPath);
    ApplicationContext context = coreContext;

    Adapter adapter = (Adapter) context.getBean("client_adapter");

    ApplicationContext appContext = new FileSystemXmlApplicationContext(
            new String[] { "file:" + userConfigFilename }, context);

    Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class);
    Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class);

    if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) {
        System.err.println("No user-defined input/output stub beans");
        System.exit(1);
    }

    ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size());
    ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size());

    // add all input stubs
    for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding InputStub " + beanName);
        inputStubs.add((InputStub) e.getValue());
    }

    // add all output stubs
    for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) {
        String beanName = (String) e.getKey();
        System.out.println("Adding OutputStub " + beanName);
        outputStubs.add((OutputStub) e.getValue());
    }

    adapter.setInputStubs(inputStubs);
    adapter.setOutputStubs(outputStubs);

}