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);
}
}));
}
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()));
}
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);
}
}
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);
}
}
}
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()));
}
Aggregations