Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

In this page you can find the example usage for java.util Properties put.

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:ar.edu.taco.TacoMain.java

/**
 * @param args/*from   w w  w  .j  a v  a 2  s  .  co  m*/
 */
@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    @SuppressWarnings("unused")
    int loopUnrolling = 3;

    String tacoVersion = getManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
    String tacoCreatedBy = getManifestAttribute(new Name("Created-By"));

    System.out.println("TACO: Taco static analysis tool.");
    System.out.println("Created By: " + tacoCreatedBy);
    System.out.println("Version: " + tacoVersion);
    System.out.println("");
    System.out.println("");

    Option helpOption = new Option("h", "help", false, "print this message");
    Option versionOption = new Option("v", "version", false, "shows version");

    Option configFileOption = OptionBuilder.withArgName("path").withLongOpt("configFile").hasArg()
            .withDescription("set the configuration file").create("cf");
    Option classToCheckOption = OptionBuilder.withArgName("classname").withLongOpt("classToCheck").hasArg()
            .withDescription("set the class to be checked").create('c');
    Option methodToCheckOption = OptionBuilder.withArgName("methodname").withLongOpt("methodToCheck").hasArg()
            .withDescription("set the method to be checked").create('m');
    Option dependenciesOption = OptionBuilder.withArgName("classname").withLongOpt("dependencies").hasArgs()
            .withDescription("additional sources to be parsed").create('d');
    Option relevantClassesOption = OptionBuilder.withArgName("classname").withLongOpt("relevantClasses")
            .hasArgs().withDescription("Set the relevant classes to be used").create("rd");
    Option loopsOptions = OptionBuilder.withArgName("integer").withLongOpt("unroll").hasArg()
            .withDescription("set number of loop unrollings").create('u');
    Option bitOptions = OptionBuilder.withArgName("integer").withLongOpt("width").hasArg()
            .withDescription("set bit width").create('w');
    Option instOptions = OptionBuilder.withArgName("integer").withLongOpt("bound").hasArg()
            .withDescription("set class bound").create('b');
    Option skolemizeOption = OptionBuilder.withLongOpt("skolemize")
            .withDescription("set whether or not skolemize").create("sk");
    Option simulateOption = OptionBuilder.withLongOpt("simulate")
            .withDescription("run method instead of checking").create("r");
    Option modularReasoningOption = OptionBuilder.withLongOpt("modularReasoning")
            .withDescription("check method using modular reasoning").create("mr");
    Option relevancyAnalysisOption = OptionBuilder.withLongOpt("relevancyAnalysis")
            .withDescription("calculate the needed relevantClasses").create("ra");
    Option scopeRestrictionOption = OptionBuilder.withLongOpt("scopeRestriction")
            .withDescription("restrict signature scope to value set in -b option").create("sr");
    /*
     * Option noVerifyOption = OptionBuilder.withLongOpt(
     * "noVerify").withDescription(
     * "builds output but does not invoke verification engine").create(
     * "nv");
     */
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(versionOption);
    options.addOption(configFileOption);
    options.addOption(classToCheckOption);
    options.addOption(methodToCheckOption);
    options.addOption(dependenciesOption);
    options.addOption(relevantClassesOption);
    options.addOption(loopsOptions);
    options.addOption(bitOptions);
    options.addOption(instOptions);
    options.addOption(skolemizeOption);
    options.addOption(simulateOption);
    options.addOption(modularReasoningOption);
    options.addOption(relevancyAnalysisOption);
    options.addOption(scopeRestrictionOption);
    // options.addOption(noVerifyOption)

    String configFileArgument = null;
    Properties overridingProperties = new Properties();
    TacoCustomScope tacoScope = new TacoCustomScope();

    // create the parser
    CommandLineParser parser = new PosixParser();

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        // help
        if (line.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(120, CMD, HEADER, options, FOOTER, true);
            return;
        }

        // version
        if (line.hasOption(versionOption.getOpt())) {
            System.out.println(FOOTER);
            System.out.println("");
            return;
        }

        // Configuration file
        if (line.hasOption(configFileOption.getOpt())) {
            configFileArgument = line.getOptionValue(configFileOption.getOpt());
        }

        // class to check
        if (line.hasOption(classToCheckOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.CLASS_TO_CHECK_FIELD,
                    line.getOptionValue(classToCheckOption.getOpt()));
        }

        // method to check
        if (line.hasOption(methodToCheckOption.getOpt())) {
            String methodtoCheck = line.getOptionValue(methodToCheckOption.getOpt());

            if (!methodtoCheck.matches("^[A-Za-z0-9_-]+_[0-9]")) {
                methodtoCheck = methodtoCheck + "_0";
            }
            overridingProperties.put(TacoConfigurator.METHOD_TO_CHECK_FIELD, methodtoCheck);
        }

        // Dependencies classes
        if (line.hasOption(dependenciesOption.getOpt())) {
            String dependenciesClasses = "";
            for (String aDependencyClass : line.getOptionValues(dependenciesOption.getOpt())) {
                dependenciesClasses += aDependencyClass;
            }
            overridingProperties.put(TacoConfigurator.CLASSES_FIELD, dependenciesClasses);
        }

        // Relevant classes
        if (line.hasOption(relevantClassesOption.getOpt())) {
            String relevantClasses = "";
            for (String aRelevantClass : line.getOptionValues(relevantClassesOption.getOpt())) {
                relevantClasses += aRelevantClass;
            }
            overridingProperties.put(TacoConfigurator.RELEVANT_CLASSES, relevantClasses);
        }

        // Loop unrolling
        if (line.hasOption(loopsOptions.getOpt())) {
            loopUnrolling = Integer.parseInt(line.getOptionValue(loopsOptions.getOpt()));
        }

        // Int bitwidth
        if (line.hasOption(bitOptions.getOpt())) {
            String alloy_bitwidth_str = line.getOptionValue(bitOptions.getOpt());
            overridingProperties.put(TacoConfigurator.BITWIDTH, alloy_bitwidth_str);
            int alloy_bitwidth = new Integer(alloy_bitwidth_str);
            tacoScope.setAlloyBitwidth(alloy_bitwidth);
        }

        // instances scope
        if (line.hasOption(instOptions.getOpt())) {
            String assertionsArguments = "for " + line.getOptionValue(instOptions.getOpt());
            overridingProperties.put(TacoConfigurator.ASSERTION_ARGUMENTS, assertionsArguments);
        }

        // Skolemize
        if (line.hasOption(skolemizeOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_INVARIANT, false);
            overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_ABSTRACTION, false);
        }

        // Simulation
        if (line.hasOption(simulateOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.INCLUDE_SIMULATION_PROGRAM_DECLARATION, true);
            overridingProperties.put(TacoConfigurator.GENERATE_CHECK, false);
            overridingProperties.put(TacoConfigurator.GENERATE_RUN, false);
        }

        // Modular Reasoning
        if (line.hasOption(modularReasoningOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.MODULAR_REASONING, true);
        }

        // Relevancy Analysis
        if (line.hasOption(relevancyAnalysisOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.RELEVANCY_ANALYSIS, true);
        }

    } catch (ParseException e) {
        System.err.println("Command line parsing failed: " + e.getMessage());
    }

    try {

        System.out.println("****** Starting Taco (version. " + tacoVersion + ") ****** ");
        System.out.println("");

        File file = new File("config/log4j.xml");
        if (file.exists()) {
            DOMConfigurator.configure("config/log4j.xml");
        } else {
            System.err.println("log4j:WARN File config/log4j.xml not found");
        }

        TacoMain main = new TacoMain();

        // BUILD TacoScope 

        //
        main.run(configFileArgument, overridingProperties);

    } catch (IllegalArgumentException e) {
        System.err.println("Error found:");
        System.err.println(e.getMessage());
    } catch (MethodToCheckNotFoundException e) {
        System.err.println("Error found:");
        System.err.println("Method to check was not found. Please verify config file, or add -m option");
    } catch (TacoException e) {
        System.err.println("Error found:");
        System.err.println(e.getMessage());
    }
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Run the Uploader as a stand-alone application.
 *
 * @param args//from  w w w.j  ava 2  s.c o m
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    JFrame ownerFrame = new JFrame("JetS3t Uploader");
    ownerFrame.addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent e) {
        }

        public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowIconified(WindowEvent e) {
        }

        public void windowDeiconified(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }
    });

    // Read arguments as properties of the form: <propertyName>'='<propertyValue>
    Properties argumentProperties = new Properties();
    if (args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            int delimIndex = arg.indexOf("=");
            if (delimIndex >= 0) {
                String name = arg.substring(0, delimIndex);
                String value = arg.substring(delimIndex + 1);
                argumentProperties.put(name, value);
            } else {
                System.out.println("Ignoring property argument with incorrect format: " + arg);
            }
        }
    }

    new Uploader(ownerFrame, argumentProperties);
}

From source file:herddb.server.ServerMain.java

public static void main(String... args) {
    try {//w w  w .ja va  2 s  . co  m
        LOG.log(Level.INFO, "Starting HerdDB version {0}", herddb.utils.Version.getVERSION());
        Properties configuration = new Properties();

        boolean configFileFromParameter = false;
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (!arg.startsWith("-")) {
                File configFile = new File(args[i]).getAbsoluteFile();
                LOG.log(Level.INFO, "Reading configuration from {0}", configFile);
                try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile),
                        StandardCharsets.UTF_8)) {
                    configuration.load(reader);
                }
                configFileFromParameter = true;
            } else if (arg.equals("--use-env")) {
                System.getenv().forEach((key, value) -> {
                    System.out.println("Considering env as system property " + key + " -> " + value);
                    System.setProperty(key, value);
                });
            } else if (arg.startsWith("-D")) {
                int equals = arg.indexOf('=');
                if (equals > 0) {
                    String key = arg.substring(2, equals);
                    String value = arg.substring(equals + 1);
                    System.setProperty(key, value);
                }
            }
        }
        if (!configFileFromParameter) {
            File configFile = new File("conf/server.properties").getAbsoluteFile();
            LOG.log(Level.INFO, "Reading configuration from {0}", configFile);
            if (configFile.isFile()) {
                try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile),
                        StandardCharsets.UTF_8)) {
                    configuration.load(reader);
                }
            }
        }

        System.getProperties().forEach((k, v) -> {
            String key = k + "";
            if (!key.startsWith("java") && !key.startsWith("user")) {
                configuration.put(k, v);
            }
        });

        LogManager.getLogManager().readConfiguration();

        Runtime.getRuntime().addShutdownHook(new Thread("ctrlc-hook") {

            @Override
            public void run() {
                System.out.println("Ctrl-C trapped. Shutting down");
                ServerMain _brokerMain = runningInstance;
                if (_brokerMain != null) {
                    _brokerMain.close();
                }
            }

        });
        runningInstance = new ServerMain(configuration);
        runningInstance.start();

        runningInstance.join();

    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}

From source file:Main.java

public static Connection getConnection(String dbURL, String user, String password)
        throws SQLException, ClassNotFoundException {
    Class.forName("com.mysql.jdbc.Driver");

    Properties props = new Properties();
    props.put("user", user);
    props.put("password", password);

    props.put("autoReconnect", "true");

    return DriverManager.getConnection(dbURL, props);
}

From source file:SendApp.java

public static void send(String smtpHost, int smtpPort, String from, String to, String subject, String content)
        throws AddressException, MessagingException {

    java.util.Properties props = new java.util.Properties();
    props.put("mail.smtp.host", smtpHost);
    props.put("mail.smtp.port", "" + smtpPort);
    Session session = Session.getDefaultInstance(props, null);

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    msg.setSubject(subject);//from   www .j av  a  2s  .co  m
    msg.setText(content);

    Transport.send(msg);
}

From source file:org.kurento.repository.KurentoRepositoryServerApp.java

public static ConfigurableApplicationContext start() {

    Properties properties = new Properties();
    properties.put("server.port", RepositoryApplicationContextConfiguration.SERVER_PORT);

    SpringApplication application = new SpringApplication(KurentoRepositoryServerApp.class);

    application.setDefaultProperties(properties);

    return application.run();
}

From source file:PooledConnectionExample.java

private static InitialContext createContext() throws NamingException {
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
    env.put(Context.PROVIDER_URL, "rmi://localhost:1099");
    InitialContext context = new InitialContext(env);
    return context;
}

From source file:org.kurento.repository.BootApplication.java

public static ConfigurableApplicationContext start() {

    Properties properties = new Properties();
    properties.put("server.port", getPort());

    SpringApplication application = new SpringApplication(BootApplication.class);

    application.setDefaultProperties(properties);

    return application.run();
}

From source file:Main.java

/**
 * Returns common properties for resource-adapter element
 *///from w  w w  .  j  a  v a 2 s.c  o m
public static Properties raCommonProperties() {
    Properties params = new Properties();
    params.put("archive", "some.rar");
    params.put("transaction-support", "XATransaction");
    params.put("bootstrap-context", "default");

    return params;
}

From source file:Main.java

/**
 * Method for static initializer//from www  .j av  a 2  s  .c o  m
 */
private static Properties createDefaultPropertiesForXML(boolean omitXMLDeclaration) {
    final Properties format = new Properties();
    format.put(OutputKeys.METHOD, "xml");
    format.put(OutputKeys.OMIT_XML_DECLARATION, (omitXMLDeclaration ? "yes" : "no"));
    format.put(OutputKeys.INDENT, "yes");
    return format;
}