Example usage for java.util Properties putAll

List of usage examples for java.util Properties putAll

Introduction

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

Prototype

@Override
    public synchronized void putAll(Map<?, ?> t) 

Source Link

Usage

From source file:com.lrs.enviroment.Metadata.java

@Override
public Properties toProperties() {
    Properties prop = new Properties();
    prop.putAll(delegateMap);
    return prop;//from  ww w .  j a  v  a  2s  .  c  om
}

From source file:com.github.jrh3k5.flume.mojo.plugin.AbstractFlumePluginMojoITest.java

/**
 * Build a project.// w  w  w  .ja va2s.c om
 * 
 * @param artifactId
 *            The artifact ID of the project to build.
 * @param goal
 *            The goal to invoke.
 * @return An {@link InvocationResult} indicating the result of the build.
 * @throws Exception
 *             If any errors occur during the build.
 */
protected InvocationResult buildProject(String artifactId, LifecyclePhase goal) throws Exception {
    final Properties buildProps = new Properties();
    buildProps.putAll(getBuildArguments());
    final InvocationRequest request = build.createBasicInvocationRequest(getPom(artifactId), buildProps,
            Collections.singletonList(goal.id()), getLogFile());
    request.setShowErrors(true);
    return build.executeMaven(request);
}

From source file:com.google.enterprise.connector.db.MockDBConnectorFactory.java

/**
 * Creates a database connector./*from   w ww .  j  ava 2  s.  co m*/
 *
 * @param config map of configuration values.
 */
/* TODO(jlacey): Extract the Spring instantiation code in CM. */
@Override
public Connector makeConnector(Map<String, String> config) throws RepositoryException {
    // TODO(jlacey): The placeholder values are in the EPPC bean in
    // connectorDefaults.xml, but we're not loading that, and doing so
    // would unravel a ball of string: using setLocation instead of
    // setProperties (since the EPPC bean already has properties),
    // which in turn requires the ByteArrayResource machinery in
    // InstanceInfo or writing the properties to a file.
    Properties props = new Properties();
    for (String configKey : DBConnectorType.CONFIG_KEYS) {
        props.put(configKey, "");
    }
    // Escape MyBatis syntax that looks like a Spring placeholder.
    // See https://jira.springsource.org/browse/SPR-4953
    props.put("docIds", "#{'$'}{docIds}");
    props.putAll(config);

    Resource prototype = new ClassPathResource("config/connectorInstance.xml", MockDBConnectorFactory.class);
    Resource defaults = new ClassPathResource("config/connectorDefaults.xml", MockDBConnectorFactory.class);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory);
    try {
        beanReader.loadBeanDefinitions(prototype);
        beanReader.loadBeanDefinitions(defaults);
    } catch (BeansException e) {
        throw new RepositoryException(e);
    }

    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setProperties(props);
    cfg.postProcessBeanFactory(factory);

    String[] beanList = factory.getBeanNamesForType(DiffingConnector.class);
    Assert.assertEquals(Arrays.asList(beanList).toString(), 1, beanList.length);
    return (Connector) factory.getBean(beanList[0]);
}

From source file:org.beangle.struts2.view.freemarker.BeangleFreemarkerManager.java

/**
 * Load the multi settings from the /META-INF/freemarker.properties and
 * /freemarker.properties file on the classpath
 * //ww  w  .j  ava2  s.  co  m
 * @see freemarker.template.Configuration#setSettings for the definition of
 *      valid settings
 */
@SuppressWarnings("unchecked")
@Override
protected void loadSettings(ServletContext servletContext) {
    try {
        Properties properties = new Properties();
        Enumeration<?> em = BeangleFreemarkerManager.class.getClassLoader()
                .getResources("META-INF/freemarker.properties");
        while (em.hasMoreElements()) {
            properties.putAll(getProperties((URL) em.nextElement()));
        }
        em = BeangleFreemarkerManager.class.getClassLoader().getResources("freemarker.properties");
        while (em.hasMoreElements()) {
            properties.putAll(getProperties((URL) em.nextElement()));
        }
        StringBuilder sb = new StringBuilder();
        @SuppressWarnings("rawtypes")
        List keys = CollectUtils.newArrayList(properties.keySet());
        Collections.sort(keys);
        for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
            String key = iter.next();
            String value = (String) properties.get(key);
            if (key == null) {
                throw new IOException(
                        "init-param without param-name.  Maybe the freemarker.properties is not well-formed?");
            }
            if (value == null) {
                throw new IOException(
                        "init-param without param-value.  Maybe the freemarker.properties is not well-formed?");
            }
            addSetting(key, value);
            sb.append(StringUtils.leftPad(key, 21)).append(" : ").append(value);
            if (iter.hasNext())
                sb.append('\n');
        }
        logger.info("Freemarker properties: ->\n{} ", sb);
    } catch (IOException e) {
        logger.error("Error while loading freemarker.properties", e);
    } catch (TemplateException e) {
        logger.error("Error while setting freemarker.properties", e);
    }
}

From source file:org.apache.atlas.kafka.KafkaNotification.java

private Properties getConsumerProperties(NotificationType type) {
    // find the configured group id for the given notification type
    String groupId = properties.getProperty(type.toString().toLowerCase() + "." + CONSUMER_GROUP_ID_PROPERTY);

    if (groupId == null) {
        throw new IllegalStateException("No configuration group id set for the notification type " + type);
    }/*from w  w w . j  a  va  2  s.c o m*/

    Properties consumerProperties = new Properties();
    consumerProperties.putAll(properties);
    consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);

    LOG.info("Consumer property: auto.commit.enable: {}", consumerProperties.getProperty("auto.commit.enable"));
    return consumerProperties;
}

From source file:org.apache.ace.configurator.ConfiguratorTest.java

@Test(groups = { UNIT })
public void testChangeConfigurationUsingSameKeyNoReconfigure() throws Exception {
    String pid = "test-change";

    Properties configurationValues = createProperties();
    Properties initialConfigurationValues = new Properties();
    initialConfigurationValues.putAll(configurationValues);
    saveConfiguration(pid, configurationValues);

    Dictionary<String, ?> configuration = getAndWaitForConfigurationUpdate(pid);
    assertNotNull(configuration, "No configuration received from configurator");
    assertEquals(configurationValues, configuration);

    configurationValues.put("test", "value42");
    saveConfiguration("test-change", configurationValues);

    // The update should have been ignored, and the old values should still be present.
    configuration = getAndWaitForConfigurationUpdate(pid);
    assertNotNull(configuration, "No configuration received from configurator");
    assertEquals(initialConfigurationValues, configuration);
}

From source file:com.hp.application.automation.tools.run.RunFromFileBuilder.java

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {

    EnvVars env = null;//w w w  .j a v a 2s. c  o  m
    try {
        env = build.getEnvironment(listener);

    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    } catch (InterruptedException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    VariableResolver<String> varResolver = build.getBuildVariableResolver();

    // now merge them into one list
    Properties mergedProperties = new Properties();

    mergedProperties.putAll(runFromFileModel.getProperties(env, varResolver));
    int idx = 0;
    for (String key : env.keySet()) {
        idx++;
        mergedProperties.put("JenkinsEnv" + idx, key + ";" + env.get(key));
    }

    Date now = new Date();
    Format formatter = new SimpleDateFormat("ddMMyyyyHHmmssSSS");
    String time = formatter.format(now);

    // get a unique filename for the params file
    ParamFileName = "props" + time + ".txt";
    ResultFilename = "Results" + time + ".xml";
    //KillFileName = "stop" + time + ".txt";

    mergedProperties.put("runType", RunType.FileSystem.toString());
    mergedProperties.put("resultsFilename", ResultFilename);

    // get properties serialized into a stream
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        mergedProperties.store(stream, "");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        build.setResult(Result.FAILURE);
    }
    String propsSerialization = stream.toString();
    InputStream propsStream = IOUtils.toInputStream(propsSerialization);

    // get the remote workspace filesys
    FilePath projectWS = build.getWorkspace();

    // Get the URL to the Script used to run the test, which is bundled
    // in the plugin
    URL cmdExeUrl = Hudson.getInstance().pluginManager.uberClassLoader.getResource(HpToolsLauncher_SCRIPT_NAME);
    if (cmdExeUrl == null) {
        listener.fatalError(HpToolsLauncher_SCRIPT_NAME + " not found in resources");
        return false;
    }

    URL cmdExe2Url = Hudson.getInstance().pluginManager.uberClassLoader.getResource(LRAnalysisLauncher_EXE);
    if (cmdExe2Url == null) {
        listener.fatalError(LRAnalysisLauncher_EXE + "not found in resources");
        return false;
    }

    FilePath propsFileName = projectWS.child(ParamFileName);
    FilePath CmdLineExe = projectWS.child(HpToolsLauncher_SCRIPT_NAME);
    FilePath CmdLineExe2 = projectWS.child(LRAnalysisLauncher_EXE);

    try {
        // create a file for the properties file, and save the properties
        propsFileName.copyFrom(propsStream);

        // Copy the script to the project workspace
        CmdLineExe.copyFrom(cmdExeUrl);

        CmdLineExe2.copyFrom(cmdExe2Url);

    } catch (IOException e1) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e1) {
        build.setResult(Result.FAILURE);
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    try {
        // Run the HpToolsLauncher.exe
        AlmToolsUtils.runOnBuildEnv(build, launcher, listener, CmdLineExe, ParamFileName);
        // Has the report been successfuly generated?
    } catch (IOException ioe) {
        Util.displayIOException(ioe, listener);
        build.setResult(Result.FAILURE);
        return false;
    } catch (InterruptedException e) {
        build.setResult(Result.ABORTED);
        PrintStream out = listener.getLogger();

        try {
            AlmToolsUtils.runHpToolsAborterOnBuildEnv(build, launcher, listener, ParamFileName);
        } catch (IOException e1) {
            Util.displayIOException(e1, listener);
            build.setResult(Result.FAILURE);
            return false;
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        // kill processes
        /*FilePath killFile = projectWS.child(KillFileName);
        try {
           killFile.write("\n", "UTF-8");
        while (!killFile.exists())
            Thread.sleep(1000);
        Thread.sleep(1500);
        } catch (IOException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
        } catch (InterruptedException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
        }*/

        out.println("Operation Was aborted by user.");
    }

    return true;

}

From source file:com.u2apple.tool.dao.DeviceI18nDaoImpl.java

private void storeProperties(Properties properties, String fileKey) throws FileNotFoundException, IOException {
    Properties tempProperties = new Properties() {
        @Override//from ww  w. java2 s . co m
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    tempProperties.putAll(properties);
    String file = Configuration.getProperty(fileKey);
    tempProperties.store(new FileOutputStream(file), null);
}

From source file:org.beadle.framework.view.ReturnTypeViewResolver.java

/**
 * Set the mapping from file extensions to media types.
 * <p>When this mapping is not set or when an extension is not present, this view resolver
 * will fall back to using a {@link FileTypeMap} when the Java Action Framework is available.
 * @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
 *///from w ww  .j av  a2  s .co  m
@Deprecated
public void setMediaTypes(Map<String, String> mediaTypes) {
    if (mediaTypes != null) {
        Properties props = new Properties();
        props.putAll(mediaTypes);
        this.cnManagerFactoryBean.setMediaTypes(props);
    }
}

From source file:org.cloudcoder.healthmonitor.HealthMonitor.java

/**
 * Create a mail Session based on information in the
 * given {@link HealthMonitorConfig}.//from   w  w  w.  j ava2s  . c  o  m
 * 
 * @param config the {@link HealthMonitorConfig}
 * @return the mail Session
 */
private Session createMailSession(HealthMonitorConfig config) {
    final PasswordAuthentication passwordAuthentication = new PasswordAuthentication(config.getSmtpUsername(),
            config.getSmtpPassword());

    Properties properties = new Properties();
    properties.putAll(System.getProperties());
    properties.setProperty("mail.smtp.submitter", passwordAuthentication.getUserName());
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.host", config.getSmtpServer());
    properties.setProperty("mail.smtp.port", String.valueOf(config.getSmtpPort()));
    properties.setProperty("mail.smtp.starttls.enable", String.valueOf(config.isSmtpUseTLS()));

    return Session.getInstance(properties, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return passwordAuthentication;
        }
    });
}