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.mgreau.jboss.as7.cli.CliLauncher.java

public static void main(String[] args) throws Exception {
    int exitCode = 0;
    CommandContext cmdCtx = null;//w w w  . ja  v a  2  s  .c o  m
    boolean gui = false;
    String appName = "";
    try {
        String argError = null;
        List<String> commands = null;
        File file = null;
        boolean connect = false;
        String defaultControllerProtocol = "http-remoting";
        String defaultControllerHost = null;
        int defaultControllerPort = -1;
        boolean version = false;
        String username = null;
        char[] password = null;
        int connectionTimeout = -1;

        //App deployment
        boolean isAppDeployment = false;
        final Properties props = new Properties();

        for (String arg : args) {
            if (arg.startsWith("--controller=") || arg.startsWith("controller=")) {
                final String fullValue;
                final String value;
                if (arg.startsWith("--")) {
                    fullValue = arg.substring(13);
                } else {
                    fullValue = arg.substring(11);
                }
                final int protocolEnd = fullValue.lastIndexOf("://");
                if (protocolEnd == -1) {
                    value = fullValue;
                } else {
                    value = fullValue.substring(protocolEnd + 3);
                    defaultControllerProtocol = fullValue.substring(0, protocolEnd);
                }

                String portStr = null;
                int colonIndex = value.lastIndexOf(':');
                if (colonIndex < 0) {
                    // default port
                    defaultControllerHost = value;
                } else if (colonIndex == 0) {
                    // default host
                    portStr = value.substring(1);
                } else {
                    final boolean hasPort;
                    int closeBracket = value.lastIndexOf(']');
                    if (closeBracket != -1) {
                        //possible ip v6
                        if (closeBracket > colonIndex) {
                            hasPort = false;
                        } else {
                            hasPort = true;
                        }
                    } else {
                        //probably ip v4
                        hasPort = true;
                    }
                    if (hasPort) {
                        defaultControllerHost = value.substring(0, colonIndex).trim();
                        portStr = value.substring(colonIndex + 1).trim();
                    } else {
                        defaultControllerHost = value;
                    }
                }

                if (portStr != null) {
                    int port = -1;
                    try {
                        port = Integer.parseInt(portStr);
                        if (port < 0) {
                            argError = "The port must be a valid non-negative integer: '" + args + "'";
                        } else {
                            defaultControllerPort = port;
                        }
                    } catch (NumberFormatException e) {
                        argError = "The port must be a valid non-negative integer: '" + arg + "'";
                    }
                }
            } else if ("--connect".equals(arg) || "-c".equals(arg)) {
                connect = true;
            } else if ("--version".equals(arg)) {
                version = true;
            } else if ("--gui".equals(arg)) {
                gui = true;
            } else if (arg.startsWith("--appDeployment=") || arg.startsWith("appDeployment=")) {
                isAppDeployment = true;
                appName = arg.startsWith("--") ? arg.substring(16) : arg.substring(14);
            } else if (arg.startsWith("--file=") || arg.startsWith("file=")) {
                if (file != null) {
                    argError = "Duplicate argument '--file'.";
                    break;
                }
                if (commands != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }

                final String fileName = arg.startsWith("--") ? arg.substring(7) : arg.substring(5);
                if (!fileName.isEmpty()) {
                    file = new File(fileName);
                    if (!file.exists()) {
                        argError = "File " + file.getAbsolutePath() + " doesn't exist.";
                        break;
                    }
                } else {
                    argError = "Argument '--file' is missing value.";
                    break;
                }
            } else if (arg.startsWith("--commands=") || arg.startsWith("commands=")) {
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                final String value = arg.startsWith("--") ? arg.substring(11) : arg.substring(9);
                commands = Util.splitCommands(value);
            } else if (arg.startsWith("--command=") || arg.startsWith("command=")) {
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                final String value = arg.startsWith("--") ? arg.substring(10) : arg.substring(8);
                commands = Collections.singletonList(value);
            } else if (arg.startsWith("--user=")) {
                username = arg.startsWith("--") ? arg.substring(7) : arg.substring(5);
            } else if (arg.startsWith("--password=")) {
                password = (arg.startsWith("--") ? arg.substring(11) : arg.substring(9)).toCharArray();
            } else if (arg.startsWith("--timeout=")) {
                if (connectionTimeout > 0) {
                    argError = "Duplicate argument '--timeout'";
                    break;
                }
                final String value = arg.substring(10);
                try {
                    connectionTimeout = Integer.parseInt(value);
                } catch (final NumberFormatException e) {
                    //
                }
                if (connectionTimeout <= 0) {
                    argError = "The timeout must be a valid positive integer: '" + value + "'";
                }
            } else if (arg.equals("--help") || arg.equals("-h")) {
                commands = Collections.singletonList("help");
            } else if (arg.startsWith("--properties=")) {
                final String value = arg.substring(13);
                final File propertiesFile = new File(value);
                if (!propertiesFile.exists()) {
                    argError = "File doesn't exist: " + propertiesFile.getAbsolutePath();
                    break;
                }

                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(propertiesFile);
                    props.load(fis);
                } catch (FileNotFoundException e) {
                    argError = e.getLocalizedMessage();
                    break;
                } catch (java.io.IOException e) {
                    argError = "Failed to load properties from " + propertiesFile.getAbsolutePath() + ": "
                            + e.getLocalizedMessage();
                    break;
                } finally {
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (java.io.IOException e) {
                        }
                    }
                }
                for (final Object prop : props.keySet()) {
                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
                        public Object run() {
                            System.setProperty((String) prop, (String) props.get(prop));
                            return null;
                        }
                    });
                }
            } else if (!(arg.startsWith("-D") || arg.equals("-XX:"))) {// skip system properties and jvm options
                // assume it's commands
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time: "
                            + arg;
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                commands = Util.splitCommands(arg);
            }
        }

        if (argError != null) {
            System.err.println(argError);
            exitCode = 1;
            return;
        }

        if (version) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            VersionHandler.INSTANCE.handle(cmdCtx);
            return;
        }

        if (file != null) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            processFile(file, cmdCtx, isAppDeployment, appName, props);
            return;
        }

        if (commands != null) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            processCommands(commands, cmdCtx);
            return;
        }

        // Interactive mode
        cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                username, password, true, connect, connectionTimeout);
        cmdCtx.interact();
    } catch (Throwable t) {
        t.printStackTrace();
        exitCode = 1;
    } finally {
        if (cmdCtx != null && cmdCtx.getExitCode() != 0) {
            exitCode = cmdCtx.getExitCode();
        }
        if (!gui) {
            System.exit(exitCode);
        }
    }
    System.exit(exitCode);
}

From source file:org.openqa.selenium.environment.webserver.AppServerTest.java

@BeforeClass
public static void startDriver() throws Throwable {
    System.setProperty("webdriver.chrome.driver", CommandLine.find("chromedriver"));
    driver = new ChromeDriver();
}

From source file:mytubermiserver.RMIClient.java

public RMIClient(String address, String registryName) throws RemoteException, NotBoundException {
    System.setProperty("com.healthmarketscience.rmiio.exporter.port", "6667");
    Registry registry = LocateRegistry.getRegistry(address);
    server = (Server) registry.lookup(registryName);
}

From source file:com.streamsets.datacollector.execution.runner.common.TestProdSourceOffsetTracker.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  ww  .jav a  2s  .  c  om
        FileUtils.deleteDirectory(f);
    } catch (Exception ex) {
        LOG.info(Utils.format("Got exception while deleting directory: {}", f.getAbsolutePath()), ex);
    }
}

From source file:org.trustedanalytics.utils.hdfs.LocalConfigTests.java

@BeforeClass
public static void initializeTmpFolder() throws IOException {
    // we use relative path as it seems to be harder case
    DESTINATION_PATH = Paths.get("local_hdfs_tests_folder_" + randomString());
    System.setProperty(FOLDER_PROPERTY, DESTINATION_PATH.toString());
}

From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDController_Objects_Test.java

@BeforeClass
public static void beforeClass() throws Exception {
    ldapServer.add(BASEDB_USERS, new Attribute[] { new Attribute("objectClass", "top"),
            new Attribute("objectClass", "organizationalUnit"), new Attribute("ou", "Users") });

    System.setProperty("ldap.host", "localhost");
    System.setProperty("ldap.port", String.valueOf(LdapServerExternalResource.DEFAULT_PORT));
    System.setProperty("ldap.database", "test");
    System.setProperty("ldap.personWithAddress.basedn", BASEDB_USERS);

    System.setProperty("mongo.host", "localhost");
    System.setProperty("mongo.port", String.valueOf(MongoServerExternalResource.DEFAULT_PORT));
    System.setProperty("mongo.database", "lightblue");

    initLightblueFactory("./datasources.json", "./metadata/person-with-address-metadata.json");
}

From source file:com.github.hronom.scrape.dat.rooms.core.grabbers.JxBrowserGrabber.java

public JxBrowserGrabber() {
    System.setProperty("teamdev.license.info", "true");
    Handler log4jHandler = createHandler();
    for (Handler handler : LoggerProvider.getBrowserLogger().getHandlers()) {
        LoggerProvider.getBrowserLogger().removeHandler(handler);
    }//  w w  w  .j a v a2 s . c o  m
    LoggerProvider.getBrowserLogger().addHandler(log4jHandler);

    for (Handler handler : LoggerProvider.getIPCLogger().getHandlers()) {
        LoggerProvider.getIPCLogger().removeHandler(handler);
    }
    LoggerProvider.getIPCLogger().addHandler(log4jHandler);

    for (Handler handler : LoggerProvider.getChromiumProcessLogger().getHandlers()) {
        LoggerProvider.getChromiumProcessLogger().removeHandler(handler);
    }
    LoggerProvider.getChromiumProcessLogger().addHandler(log4jHandler);
}

From source file:ipat_fx.IPAT_FX.java

@Override
public void start(Stage stage) throws Exception {
    String contextPath = System.getProperty("user.dir") + "/web/";
    File logFile = new File(contextPath + "/log/log4j-IPAT.log");
    System.setProperty("rootPath", logFile.getAbsolutePath());

    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);// w w  w.  j  a  v a2  s .  com
    stage.show();
    stage.setOnHiding((WindowEvent event) -> {
        Platform.runLater(() -> {
            File src = new File(contextPath + "/Client Data");
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
            Date date = new Date();
            File dest = new File(contextPath + "/Saves/Ipat_" + dateFormat.format(date));
            if (!dest.exists()) {
                dest.mkdirs();
            }
            try {
                FileUtils.copyDirectory(src, dest);
            } catch (IOException ex) {
                Logger.getLogger(IPAT_FX.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.exit(0);
        });
    });
}

From source file:org.apache.cxf.fediz.service.idp.integrationtests.RestITTest.java

@BeforeClass
public static void init() {
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info");

    idpHttpsPort = System.getProperty("idp.https.port");
    Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);

    SpringBusFactory bf = new SpringBusFactory();

    URL busFile = RestITTest.class.getResource("/rest-client.xml");
    bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);

}

From source file:cherry.foundation.batch.tools.Main.java

public static ExitStatus doMain(String... origArgs) {

    Options options = new Options();
    options.addOption("j", "jobid", true, "Job Id");
    options.addOption("h", "help", false, "Help");

    CommandLine cmdline = parse(options, origArgs);
    if (cmdline == null) {
        printHelp(options);/*www.  jav a 2 s . co  m*/
        return ExitStatus.FATAL;
    }
    if (cmdline.hasOption("h")) {
        printHelp(options);
        return ExitStatus.NORMAL;
    }

    String[] args = cmdline.getArgs();
    if (args.length <= 0) {
        return ExitStatus.FATAL;
    }

    String batchId = args[0];
    String[] newArgs = new String[args.length - 1];
    System.arraycopy(args, 1, newArgs, 0, args.length - 1);

    if (cmdline.hasOption("j")) {
        System.setProperty("jobId", cmdline.getOptionValue("j"));
    } else {
        System.setProperty("jobId", batchId);
    }

    Launcher launcher = new Launcher(batchId);
    ExitStatus status = launcher.launch(newArgs);
    return status;
}