Search in sources :

Example 6 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project cas by apereo.

the class CasCoreBootstrapStandaloneConfiguration method loadSettingsFromConfigurationSources.

private void loadSettingsFromConfigurationSources(final Environment environment, final Properties props, final File config) {
    final List<String> profiles = new ArrayList<>();
    profiles.add(configurationPropertiesEnvironmentManager().getApplicationName());
    profiles.addAll(Arrays.stream(environment.getActiveProfiles()).collect(Collectors.toList()));
    final String propertyNames = profiles.stream().collect(Collectors.joining("|"));
    final String regex = String.format("(%s|application)\\.(yml|properties)", propertyNames);
    LOGGER.debug("Looking for configuration files at [{}] that match the pattern [{}]", config, regex);
    final Collection<File> configFiles = FileUtils.listFiles(config, new RegexFileFilter(regex, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE).stream().sorted(Comparator.comparing(File::getName)).collect(Collectors.toList());
    LOGGER.info("Configuration files found at [{}] are [{}]", config, configFiles);
    configFiles.forEach(Unchecked.consumer(f -> {
        LOGGER.debug("Loading configuration file [{}]", f);
        if (f.getName().toLowerCase().endsWith("yml")) {
            final Map pp = loadYamlProperties(new FileSystemResource(f));
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), f);
            props.putAll(pp);
        } else {
            final Properties pp = new Properties();
            pp.load(new FileReader(f));
            LOGGER.debug("Found settings [{}] in file [{}]", pp.keySet(), f);
            props.putAll(pp);
        }
    }));
}
Also used : Arrays(java.util.Arrays) IOCase(org.apache.commons.io.IOCase) PropertySource(org.springframework.core.env.PropertySource) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ArrayList(java.util.ArrayList) Map(java.util.Map) CasConfigurationPropertiesEnvironmentManager(org.apereo.cas.configuration.CasConfigurationPropertiesEnvironmentManager) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) Resource(org.springframework.core.io.Resource) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) Properties(java.util.Properties) Collection(java.util.Collection) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileUtils(org.apache.commons.io.FileUtils) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) File(java.io.File) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Environment(org.springframework.core.env.Environment) Bean(org.springframework.context.annotation.Bean) FileReader(java.io.FileReader) Comparator(java.util.Comparator) YamlProcessor(org.springframework.beans.factory.config.YamlProcessor) PropertySourceLocator(org.springframework.cloud.bootstrap.config.PropertySourceLocator) ArrayList(java.util.ArrayList) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) FileReader(java.io.FileReader) FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map)

Example 7 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project gocd by gocd.

the class RailsAssetsService method initialize.

public void initialize() throws IOException {
    if (!systemEnvironment.useCompressedJs()) {
        return;
    }
    String assetsDirPath = servletContext.getRealPath(servletContext.getInitParameter("rails.root") + "/public/assets/");
    File assetsDir = new File(assetsDirPath);
    if (!assetsDir.exists()) {
        throw new RuntimeException(String.format("Assets directory does not exist %s", assetsDirPath));
    }
    Collection files = FileUtils.listFiles(assetsDir, new RegexFileFilter(MANIFEST_FILE_PATTERN), null);
    if (files.isEmpty()) {
        throw new RuntimeException(String.format("Manifest json file was not found at %s", assetsDirPath));
    }
    File manifestFile = (File) files.iterator().next();
    LOG.info(String.format("Found rails assets manifest file named %s ", manifestFile.getName()));
    String manifest = FileUtil.readContentFromFile(manifestFile);
    Gson gson = new Gson();
    railsAssetsManifest = gson.fromJson(manifest, RailsAssetsManifest.class);
    LOG.info(String.format("Successfully read rails assets manifest file located at %s", manifestFile.getAbsolutePath()));
}
Also used : Collection(java.util.Collection) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) Gson(com.google.gson.Gson) File(java.io.File)

Example 8 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project oxCore by GluuFederation.

the class FacesConfigPopulator method findAndUpdateNavigationRules.

/**
     * Recursively finds all *.navigation.xml files located in custom pages directory, and adds navigation rules to
     * navigation handler
     *
     * @param path to custom pages directory
     * @throws Exception
     */
private void findAndUpdateNavigationRules(Document toPopulate, String path) throws Exception {
    File file = new File(path);
    RegexFileFilter regexFileFilter = new RegexFileFilter(FACES_CONFIG_PATTERN);
    Collection<File> facesConfigFiles = FileUtils.listFiles(file, regexFileFilter, DirectoryFileFilter.DIRECTORY);
    log.debug("Found '{}' navigation rules files", facesConfigFiles.size());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    for (File files : facesConfigFiles) {
        String faceConfig = files.getAbsolutePath();
        updateDocument(toPopulate, builder, faceConfig);
        log.debug("Added navigation rules from {}", faceConfig);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File)

Example 9 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project oxCore by GluuFederation.

the class AccessRewriteConfiguration method addRulesForAllXHTML.

private void addRulesForAllXHTML(DocumentBuilder documentBuilder, String contexPath, String path, ConfigurationBuilder builder) {
    Collection<File> xhtmlFiles = FileUtils.listFiles(new File(contexPath), new RegexFileFilter(".*\\.xhtml$"), DirectoryFileFilter.DIRECTORY);
    Collection<File> navigationFiles = FileUtils.listFiles(new File(path), new RegexFileFilter(".*\\.navigation\\.xml"), DirectoryFileFilter.DIRECTORY);
    Map<String, String> rewriteMap = getRewriteMap(documentBuilder, navigationFiles);
    for (File file : xhtmlFiles) {
        String xhtmlPath = file.getAbsolutePath();
        xhtmlPath = xhtmlPath.replace("\\", "/");
        String xhtmlUri = xhtmlPath.substring(contexPath.length(), xhtmlPath.lastIndexOf(".xhtml"));
        try {
            String rewriteKey = file.getName().split("\\.")[0];
            if (rewriteMap.containsKey(rewriteKey)) {
                builder.addRule(Join.path(rewriteMap.get(rewriteKey)).to(xhtmlUri + ".htm"));
                log.debug("Added rule from navigation.xml {}", rewriteMap.get(rewriteKey), xhtmlUri + ".htm");
            } else {
                if (!xhtmlUri.startsWith(WEB_INF_PATH)) {
                    builder.addRule(Join.path(xhtmlUri).to(xhtmlUri + ".htm"));
                    log.debug("Added rule {}", xhtmlUri, xhtmlUri + ".htm");
                }
            }
        } catch (ParameterizedPatternSyntaxException ex) {
            FacesLogger.CONFIG.getLogger().log(Level.SEVERE, "Failed to add rule for " + xhtmlPath, ex);
        }
    }
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) ParameterizedPatternSyntaxException(org.ocpsoft.rewrite.param.ParameterizedPatternSyntaxException) File(java.io.File)

Example 10 with RegexFileFilter

use of org.apache.commons.io.filefilter.RegexFileFilter in project geode by apache.

the class IncrementalBackupDUnitTest method performRestore.

/**
   * Peforms an operation log restore for a member.
   * 
   * @param backupDir the member's backup directory containing the restore script.
   */
private void performRestore(File memberDir, File backupDir) throws IOException, InterruptedException {
    /*
     * The restore script will not restore if there is an if file in the copy to directory. Remove
     * these files first.
     */
    Collection<File> ifFiles = FileUtils.listFiles(memberDir, new RegexFileFilter(".*\\.if$"), DirectoryFileFilter.DIRECTORY);
    for (File file : ifFiles) {
        file.delete();
    }
    /*
     * Remove all operation logs.
     */
    Collection<File> oplogs = FileUtils.listFiles(memberDir, new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
    for (File file : oplogs) {
        file.delete();
    }
    /*
     * Get a hold of the restore script and make sure it is there.
     */
    File restoreScript = new File(backupDir, "restore.sh");
    if (!restoreScript.exists()) {
        restoreScript = new File(backupDir, "restore.bat");
    }
    assertTrue(restoreScript.exists());
    assertEquals(0, execute(restoreScript.getAbsolutePath()));
}
Also used : RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) File(java.io.File)

Aggregations

File (java.io.File)15 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)15 Test (org.junit.Test)7 LinkedList (java.util.LinkedList)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 PersistentID (org.apache.geode.cache.persistence.PersistentID)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 AdminException (org.apache.geode.admin.AdminException)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 Gson (com.google.gson.Gson)1 FileReader (java.io.FileReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1