Search in sources :

Example 46 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project winery by eclipse.

the class CsarExporter method addNamespacePrefixes.

/**
 * Writes the configured mapping namespaceprefix -> namespace to the archive
 * <p>
 * This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using JAXB and stored in
 * the NamespacesResource
 */
private void addNamespacePrefixes(ArchiveOutputStream zos, IRepository repository) throws IOException {
    Configuration configuration = repository.getConfiguration(new NamespacesId());
    if (configuration instanceof PropertiesConfiguration) {
        // Quick hack: direct serialization only works for PropertiesConfiguration
        PropertiesConfiguration pconf = (PropertiesConfiguration) configuration;
        ArchiveEntry archiveEntry = new ZipArchiveEntry(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
        zos.putArchiveEntry(archiveEntry);
        try {
            pconf.save(zos);
        } catch (ConfigurationException e) {
            CsarExporter.LOGGER.debug(e.getMessage(), e);
            zos.write("#Could not export properties".getBytes());
            zos.write(("#" + e.getMessage()).getBytes());
        }
        zos.closeArchiveEntry();
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) NamespacesId(org.eclipse.winery.common.ids.admin.NamespacesId) ConfigurationException(org.apache.commons.configuration.ConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 47 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project winery by eclipse.

the class CsarImporter method importNamespacePrefixes.

/**
 * Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
 * extracted using JAXB and stored in the NamespacesResource
 *
 * @param rootPath the root path of the extracted CSAR
 */
private void importNamespacePrefixes(Path rootPath) {
    NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
    Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
    if (Files.exists(properties)) {
        PropertiesConfiguration pconf;
        try {
            pconf = new PropertiesConfiguration(properties.toFile());
        } catch (ConfigurationException e) {
            CsarImporter.LOGGER.debug(e.getMessage(), e);
            return;
        }
        Iterator<String> namespaces = pconf.getKeys();
        while (namespaces.hasNext()) {
            boolean addToStorage = false;
            String namespace = namespaces.next();
            if (namespaceManager.hasPrefix(namespace)) {
                String storedPrefix = namespaceManager.getPrefix(namespace);
                // QUICK HACK to check whether the prefix is a generated one
                // We assume we know the internal generation routine
                Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
                if (m.matches()) {
                    // the stored prefix is a generated one
                    // replace it by the one stored in the exported properties
                    addToStorage = true;
                }
            } else {
                addToStorage = true;
            }
            if (addToStorage) {
                String prefix = pconf.getString(namespace);
                namespaceManager.setPrefix(namespace, prefix);
            }
        }
    }
}
Also used : NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ConfigurationException(org.apache.commons.configuration.ConfigurationException) Matcher(java.util.regex.Matcher) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 48 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project grakn by graknlabs.

the class QueueConfig method parseFileToMap.

private static Map<String, List<Object>> parseFileToMap(Path configPath) {
    Map<String, List<Object>> map = new HashMap<>();
    try {
        PropertiesConfiguration props = new PropertiesConfiguration(configPath.toFile());
        props.getKeys().forEachRemaining(key -> map.put(key, props.getList(key)));
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.commons.configuration.ConfigurationException) List(java.util.List) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 49 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project grakn by graknlabs.

the class GraknSparkComputer method main.

public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new GraknSparkComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 50 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project gocd by gocd.

the class AgentAutoRegistrationPropertiesImpl method scrubRegistrationProperties.

@Override
public void scrubRegistrationProperties() {
    if (!exist()) {
        return;
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
        layout.setLineSeparator("\n");
        layout.load(reader());
        try (FileWriter out = new FileWriter(this.configFile)) {
            layout.save(out);
        }
        loadProperties();
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfigurationLayout(org.apache.commons.configuration.PropertiesConfigurationLayout)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)118 File (java.io.File)38 Configuration (org.apache.commons.configuration.Configuration)33 ConfigurationException (org.apache.commons.configuration.ConfigurationException)33 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 FileInputStream (java.io.FileInputStream)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Path (java.nio.file.Path)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4