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:de.tudarmstadt.ukp.dkpro.tc.weka.report.WekaBatchTrainTestReport.java

@Override
public void execute() throws Exception {
    StorageService store = getContext().getStorageService();

    FlexTable<String> table = FlexTable.forClass(String.class);

    Map<String, List<Double>> key2resultValues = new HashMap<String, List<Double>>();
    Map<List<String>, Double> confMatrixMap = new HashMap<List<String>, Double>();

    Properties outcomeIdProps = new Properties();

    for (TaskContextMetadata subcontext : getSubtasks()) {
        if (subcontext.getType().startsWith(WekaTestTask.class.getName())) {
            try {
                outcomeIdProps.putAll(store.retrieveBinary(subcontext.getId(),
                        WekaOutcomeIDReport.ID_OUTCOME_KEY, new PropertiesAdapter()).getMap());
            } catch (Exception e) {
                // silently ignore if this file was not generated
            }//from  w  w w. j a  va2  s .  com

            Map<String, String> discriminatorsMap = store
                    .retrieveBinary(subcontext.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter())
                    .getMap();
            Map<String, String> resultMap = store
                    .retrieveBinary(subcontext.getId(), WekaTestTask.RESULTS_FILENAME, new PropertiesAdapter())
                    .getMap();

            File confMatrix = store.getStorageFolder(subcontext.getId(), CONFUSIONMATRIX_KEY);

            if (confMatrix.isFile()) {
                confMatrixMap = ReportUtils.updateAggregateMatrix(confMatrixMap, confMatrix);
            } else {
                confMatrix.delete();
            }

            String key = getKey(discriminatorsMap);

            List<Double> results;
            if (key2resultValues.get(key) == null) {
                results = new ArrayList<Double>();
            } else {
                results = key2resultValues.get(key);
            }
            key2resultValues.put(key, results);

            Map<String, String> values = new HashMap<String, String>();
            Map<String, String> cleanedDiscriminatorsMap = new HashMap<String, String>();

            for (String disc : discriminatorsMap.keySet()) {
                if (!ReportUtils.containsExcludePattern(disc, discriminatorsToExclude)) {
                    cleanedDiscriminatorsMap.put(disc, discriminatorsMap.get(disc));
                }
            }
            values.putAll(cleanedDiscriminatorsMap);
            values.putAll(resultMap);

            table.addRow(subcontext.getLabel(), values);
        }
    }

    getContext().getLoggingService().message(getContextLabel(), ReportUtils.getPerformanceOverview(table));
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        getContext().storeBinary(EVAL_FILE_NAME + "_compact" + SUFFIX_EXCEL, table.getExcelWriter());
    }
    getContext().storeBinary(EVAL_FILE_NAME + "_compact" + SUFFIX_CSV, table.getCsvWriter());
    table.setCompact(false);
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        getContext().storeBinary(EVAL_FILE_NAME + SUFFIX_EXCEL, table.getExcelWriter());
    }
    getContext().storeBinary(EVAL_FILE_NAME + SUFFIX_CSV, table.getCsvWriter());

    // this report is reused in CV, and we only want to aggregate confusion matrices from folds
    // in CV, and an aggregated OutcomeIdReport
    if (getContext().getId().startsWith(ExperimentCrossValidation.class.getSimpleName())) {
        // no confusion matrix for regression
        if (confMatrixMap.size() > 0) {
            FlexTable<String> confMatrix = ReportUtils.createOverallConfusionMatrix(confMatrixMap);
            getContext().storeBinary(CONFUSIONMATRIX_KEY, confMatrix.getCsvWriter());
        }
        if (outcomeIdProps.size() > 0)
            getContext().storeBinary(WekaOutcomeIDReport.ID_OUTCOME_KEY, new PropertiesAdapter(outcomeIdProps));
    }

    // output the location of the batch evaluation folder
    // otherwise it might be hard for novice users to locate this
    File dummyFolder = store.getStorageFolder(getContext().getId(), "dummy");
    // TODO can we also do this without creating and deleting the dummy folder?
    getContext().getLoggingService().message(getContextLabel(),
            "Storing detailed results in:\n" + dummyFolder.getParent() + "\n");
    dummyFolder.delete();
}

From source file:net.cliseau.composer.javacor.MissingToolException.java

/**
 * Create the policy parameters file.// w  w  w.j  a  va  2 s  .  c o  m
 *
 * This creates the policy parameters file and adds it to the list of
 * all files in archiveFileNames.
 *
 * @exception InvalidConfigurationException Thrown when some required configuration could not be obtained.
 * @exception FileNotFoundException Thrown when the destination configuration file could not be created.
 * @exception IOException Thrown when writing the configuration file fails.
 * @todo This method is public only to be called by AspectWeaverFSI. This
 *       is not very elegant and should be resolved differently.
 */
public void createPolicyConfigurationFile(Collection<String> archiveFileNames)
        throws InvalidConfigurationException, FileNotFoundException, IOException {
    Properties policyParams = new Properties();
    policyParams.putAll(config.getLocalPolicyParameters());
    final File policyParamFile = new File(getDestinationDirectory() + File.separator + policyParamsFileName);
    policyParams.store(new FileOutputStream(policyParamFile), null);
    archiveFileNames.add(policyParamFile.getAbsolutePath());
}

From source file:org.codelibs.fess.job.GenerateThumbnailJob.java

protected void executeThumbnailGenerator() {
    final List<String> cmdList = new ArrayList<>();
    final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
    final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class);
    final ProcessHelper processHelper = ComponentUtil.getProcessHelper();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();

    cmdList.add(fessConfig.getJavaCommandPath());

    // -cp//from   w w  w.  ja v  a  2  s  . c  om
    cmdList.add("-cp");
    final StringBuilder buf = new StringBuilder(100);
    ResourceUtil.getOverrideConfPath().ifPresent(p -> {
        buf.append(p);
        buf.append(cpSeparator);
    });
    final String confPath = System.getProperty(Constants.FESS_CONF_PATH);
    if (StringUtil.isNotBlank(confPath)) {
        buf.append(confPath);
        buf.append(cpSeparator);
    }
    // WEB-INF/env/thumbnail/resources
    buf.append("WEB-INF");
    buf.append(File.separator);
    buf.append("env");
    buf.append(File.separator);
    buf.append("thumbnail");
    buf.append(File.separator);
    buf.append("resources");
    buf.append(cpSeparator);
    // WEB-INF/classes
    buf.append("WEB-INF");
    buf.append(File.separator);
    buf.append("classes");
    // target/classes
    final String userDir = System.getProperty("user.dir");
    final File targetDir = new File(userDir, "target");
    final File targetClassesDir = new File(targetDir, "classes");
    if (targetClassesDir.isDirectory()) {
        buf.append(cpSeparator);
        buf.append(targetClassesDir.getAbsolutePath());
    }
    // WEB-INF/lib
    appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/lib")),
            "WEB-INF" + File.separator + "lib" + File.separator);
    // WEB-INF/env/thumbnail/lib
    appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/env/thumbnail/lib")),
            "WEB-INF" + File.separator + "env" + File.separator + "thumbnail" + File.separator + "lib"
                    + File.separator);
    final File targetLibDir = new File(targetDir, "fess" + File.separator + "WEB-INF" + File.separator + "lib");
    if (targetLibDir.isDirectory()) {
        appendJarFile(cpSeparator, buf, targetLibDir, targetLibDir.getAbsolutePath() + File.separator);
    }
    cmdList.add(buf.toString());

    if (useLocalElasticsearch) {
        final String transportAddresses = System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES);
        if (StringUtil.isNotBlank(transportAddresses)) {
            cmdList.add("-D" + Constants.FESS_ES_TRANSPORT_ADDRESSES + "=" + transportAddresses);
        }
    }

    final String systemLastaEnv = System.getProperty("lasta.env");
    if (StringUtil.isNotBlank(systemLastaEnv)) {
        if (systemLastaEnv.equals("web")) {
            cmdList.add("-Dlasta.env=thumbnail");
        } else {
            cmdList.add("-Dlasta.env=" + systemLastaEnv);
        }
    } else if (StringUtil.isNotBlank(lastaEnv)) {
        cmdList.add("-Dlasta.env=" + lastaEnv);
    }

    addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null);
    cmdList.add("-Dfess.thumbnail.process=true");
    if (logFilePath == null) {
        final String value = System.getProperty("fess.log.path");
        logFilePath = value != null ? value : new File(targetDir, "logs").getAbsolutePath();
    }
    cmdList.add("-Dfess.log.path=" + logFilePath);
    addSystemProperty(cmdList, Constants.FESS_VAR_PATH, null, null);
    addSystemProperty(cmdList, Constants.FESS_THUMBNAIL_PATH, null, null);
    addSystemProperty(cmdList, "fess.log.name", "fess-thumbnail", "-thumbnail");
    if (logLevel != null) {
        cmdList.add("-Dfess.log.level=" + logLevel);
    }
    stream(fessConfig.getJvmThumbnailOptionsAsArray())
            .of(stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value)));

    File ownTmpDir = null;
    final String tmpDir = System.getProperty("java.io.tmpdir");
    if (fessConfig.isUseOwnTmpDir() && StringUtil.isNotBlank(tmpDir)) {
        ownTmpDir = new File(tmpDir, "fessTmpDir_" + sessionId);
        if (ownTmpDir.mkdirs()) {
            cmdList.add("-Djava.io.tmpdir=" + ownTmpDir.getAbsolutePath());
        } else {
            ownTmpDir = null;
        }
    }

    if (StringUtil.isNotBlank(jvmOptions)) {
        split(jvmOptions, " ").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(s -> cmdList.add(s)));
    }

    cmdList.add(ThumbnailGenerator.class.getCanonicalName());

    cmdList.add("--sessionId");
    cmdList.add(sessionId);
    cmdList.add("--numOfThreads");
    cmdList.add(Integer.toString(numOfThreads));
    if (cleanup) {
        cmdList.add("--cleanup");
    }

    File propFile = null;
    try {
        cmdList.add("-p");
        propFile = File.createTempFile("thumbnail_", ".properties");
        cmdList.add(propFile.getAbsolutePath());
        try (FileOutputStream out = new FileOutputStream(propFile)) {
            final Properties prop = new Properties();
            prop.putAll(ComponentUtil.getSystemProperties());
            prop.store(out, cmdList.toString());
        }

        final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();

        if (logger.isInfoEnabled()) {
            logger.info("ThumbnailGenerator: \nDirectory=" + baseDir + "\nOptions=" + cmdList);
        }

        final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> {
            pb.directory(baseDir);
            pb.redirectErrorStream(true);
        });

        final InputStreamThread it = jobProcess.getInputStreamThread();
        it.start();

        final Process currentProcess = jobProcess.getProcess();
        currentProcess.waitFor();
        it.join(5000);

        final int exitValue = currentProcess.exitValue();

        if (logger.isInfoEnabled()) {
            logger.info("ThumbnailGenerator: Exit Code=" + exitValue + " - ThumbnailGenerator Process Output:\n"
                    + it.getOutput());
        }
        if (exitValue != 0) {
            throw new FessSystemException("Exit Code: " + exitValue + "\nOutput:\n" + it.getOutput());
        }
        ComponentUtil.getPopularWordHelper().clearCache();
    } catch (final FessSystemException e) {
        throw e;
    } catch (final InterruptedException e) {
        logger.warn("ThumbnailGenerator Process interrupted.");
    } catch (final Exception e) {
        throw new FessSystemException("ThumbnailGenerator Process terminated.", e);
    } finally {
        try {
            processHelper.destroyProcess(sessionId);
        } finally {
            if (propFile != null && !propFile.delete()) {
                logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
            }
            deleteTempDir(ownTmpDir);
        }
    }
}

From source file:org.apache.falcon.lifecycle.engine.oozie.utils.OozieBuilderUtils.java

public static Properties createDefaultConfiguration(Cluster cluster, Entity entity,
        WorkflowExecutionContext.EntityOperations operation) throws FalconException {
    Properties props = new Properties();
    props.put(WorkflowExecutionArgs.ENTITY_NAME.getName(), entity.getName());
    props.put(WorkflowExecutionArgs.ENTITY_TYPE.getName(), entity.getEntityType().name());
    props.put(WorkflowExecutionArgs.CLUSTER_NAME.getName(), cluster.getName());
    props.put(WorkflowExecutionArgs.DATASOURCE_NAME.getName(), "NA");
    props.put("falconDataOperation", operation.name());

    props.put(WorkflowExecutionArgs.LOG_DIR.getName(), getStoragePath(EntityUtil.getLogPath(cluster, entity)));
    props.put(WorkflowExecutionArgs.WF_ENGINE_URL.getName(), ClusterHelper.getOozieUrl(cluster));

    addLateDataProperties(props, entity);
    addBrokerProperties(cluster, props);

    props.put(MR_QUEUE_NAME, "default");
    props.put(MR_JOB_PRIORITY, "NORMAL");

    //properties provided in entity override the default generated properties
    props.putAll(EntityUtil.getEntityProperties(entity));
    props.putAll(createAppProperties(cluster));
    return props;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java

private Properties sortProperties(Properties properties) throws ConfigurationException, IOException {
    Properties sp = new SortedProperties();
    sp.putAll(properties);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    sp.store(baos, null);/*  w  ww  . java2 s  .c o m*/

    properties.clear();
    properties.load(new ByteArrayInputStream(baos.toByteArray()));

    return properties;
}

From source file:org.apache.hadoop.http.HttpServer2.java

private static Properties getFilterProperties(Configuration conf, String prefix) {
    Properties prop = new Properties();
    Map<String, String> filterConfig = AuthenticationFilterInitializer.getFilterConfigMap(conf, prefix);
    prop.putAll(filterConfig);
    return prop;/*www. j a va 2s . com*/
}

From source file:no.dusken.common.plugin.PluginPropertyPlaceholderConfigurer.java

/**
 * Return a merged Properties instance containing both the
 * loaded properties and properties set on this FactoryBean.
 *///w w w  .  j  av a  2s .  c  om
@Override
protected Properties mergeProperties() throws IOException {
    PluginStore store = pluginStoreProvider.getStore(plugin);
    Properties properties = super.mergeProperties();
    for (String s : properties.stringPropertyNames()) {
        String value = store.getString(s, null);
        if (value == null) {
            store.setString(s, properties.getProperty(s));
        } else {
            properties.setProperty(s, value);
        }
    }
    if (exposedProperties != null) {
        properties.putAll(exposedProperties);
    }
    return properties;
}

From source file:is.artefact.flume.source.kafka.KafkaSourceEmbeddedKafka.java

public KafkaSourceEmbeddedKafka(Properties properties) {
    zookeeper = new KafkaSourceEmbeddedZookeeper(zkPort);
    dir = new File(System.getProperty("java.io.tmpdir"), "kafka_log-" + UUID.randomUUID());
    try {//ww w . j  a v  a 2  s.  com
        FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Properties props = new Properties();
    props.put("zookeeper.connect", zookeeper.getConnectString());
    props.put("broker.id", "1");
    props.put("host.name", "localhost");
    props.put("port", String.valueOf(serverPort));
    props.put("log.dir", dir.getAbsolutePath());
    if (properties != null) {
        props.putAll(properties);
    }
    KafkaConfig config = new KafkaConfig(props);
    kafkaServer = new KafkaServerStartable(config);
    kafkaServer.startup();
    initProducer();
}

From source file:org.codehaus.mojo.hibernate3.HibernateExporterMojo.java

/**
 * Configures the Exporter./* ww  w.  ja  v a 2  s.c  o m*/
 *
 * @param exporter Exporter to configure
 * @return Exporter
 * @throws MojoExecutionException if there is an error configuring the exporter
 * @noinspection unchecked
 */
protected Exporter configureExporter(Exporter exporter) throws MojoExecutionException {

    String implementation = getComponentProperty("implementation", getComponent().getImplementation());

    ComponentConfiguration componentConfiguration = getComponentConfiguration(implementation);
    getLog().info("using " + componentConfiguration.getName() + " task.");

    Properties properties = new Properties();
    properties.putAll(componentProperties);

    exporter.setProperties(properties);
    exporter.setConfiguration(componentConfiguration.getConfiguration(this));
    exporter.setOutputDirectory(new File(getProject().getBasedir(), getComponent().getOutputDirectory()));

    File outputDir = getExporterOutputDir();
    if (getComponent().isCompileSourceRoot()) {
        // add output directory to compile roots
        getProject().addCompileSourceRoot(outputDir.getPath());
    }

    // now let's set the template path for custom templates if the directory exists
    // template path would need to be found inside the project directory
    String templatePath = getComponentProperty("templatepath", "/src/main/config/templates");
    File templatePathDir = new File(getProject().getBasedir(), templatePath);
    if (templatePathDir.exists() && templatePathDir.isDirectory()) {
        getLog().info("Exporter will use templatepath : " + templatePathDir.getPath());
        exporter.setTemplatePath(new String[] { templatePathDir.getPath() });
    }

    return exporter;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.ml.report.BatchTrainTestReport.java

@Override
public void execute() throws Exception {
    StorageService store = getContext().getStorageService();

    FlexTable<String> table = FlexTable.forClass(String.class);

    Map<String, List<Double>> key2resultValues = new HashMap<String, List<Double>>();
    Map<List<String>, Double> confMatrixMap = new HashMap<List<String>, Double>();

    Properties outcomeIdProps = new Properties();

    for (TaskContextMetadata subcontext : getSubtasks()) {
        // FIXME this is a bad hack
        if (subcontext.getType().contains("TestTask")) {
            try {
                outcomeIdProps.putAll(store
                        .retrieveBinary(subcontext.getId(), Constants.ID_OUTCOME_KEY, new PropertiesAdapter())
                        .getMap());/*from  ww w . j  a  va 2 s.c o  m*/
            } catch (Exception e) {
                // silently ignore if this file was not generated
            }

            Map<String, String> discriminatorsMap = store
                    .retrieveBinary(subcontext.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter())
                    .getMap();
            Map<String, String> resultMap = store
                    .retrieveBinary(subcontext.getId(), Constants.RESULTS_FILENAME, new PropertiesAdapter())
                    .getMap();

            File confMatrix = store.getStorageFolder(subcontext.getId(), CONFUSIONMATRIX_KEY);

            if (confMatrix.isFile()) {
                confMatrixMap = ReportUtils.updateAggregateMatrix(confMatrixMap, confMatrix);
            } else {
                confMatrix.delete();
            }

            String key = getKey(discriminatorsMap);

            List<Double> results;
            if (key2resultValues.get(key) == null) {
                results = new ArrayList<Double>();
            } else {
                results = key2resultValues.get(key);
            }
            key2resultValues.put(key, results);

            Map<String, String> values = new HashMap<String, String>();
            Map<String, String> cleanedDiscriminatorsMap = new HashMap<String, String>();

            for (String disc : discriminatorsMap.keySet()) {
                if (!ReportUtils.containsExcludePattern(disc, discriminatorsToExclude)) {
                    cleanedDiscriminatorsMap.put(disc, discriminatorsMap.get(disc));
                }
            }
            values.putAll(cleanedDiscriminatorsMap);
            values.putAll(resultMap);

            table.addRow(subcontext.getLabel(), values);
        }
    }

    getContext().getLoggingService().message(getContextLabel(), ReportUtils.getPerformanceOverview(table));
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        getContext().storeBinary(EVAL_FILE_NAME + "_compact" + SUFFIX_EXCEL, table.getExcelWriter());
    }
    getContext().storeBinary(EVAL_FILE_NAME + "_compact" + SUFFIX_CSV, table.getCsvWriter());
    table.setCompact(false);
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        getContext().storeBinary(EVAL_FILE_NAME + SUFFIX_EXCEL, table.getExcelWriter());
    }
    getContext().storeBinary(EVAL_FILE_NAME + SUFFIX_CSV, table.getCsvWriter());

    // this report is reused in CV, and we only want to aggregate confusion matrices from folds
    // in CV, and an aggregated OutcomeIdReport
    if (getContext().getId().startsWith(ExperimentCrossValidation.class.getSimpleName())) {
        // no confusion matrix for regression
        if (confMatrixMap.size() > 0) {
            FlexTable<String> confMatrix = ReportUtils.createOverallConfusionMatrix(confMatrixMap);
            getContext().storeBinary(CONFUSIONMATRIX_KEY, confMatrix.getCsvWriter());
        }
        if (outcomeIdProps.size() > 0)
            getContext().storeBinary(Constants.ID_OUTCOME_KEY, new PropertiesAdapter(outcomeIdProps));
    }

    // output the location of the batch evaluation folder
    // otherwise it might be hard for novice users to locate this
    File dummyFolder = store.getStorageFolder(getContext().getId(), "dummy");
    // TODO can we also do this without creating and deleting the dummy folder?
    getContext().getLoggingService().message(getContextLabel(),
            "Storing detailed results in:\n" + dummyFolder.getParent() + "\n");
    dummyFolder.delete();
}