use of org.apache.commons.io.filefilter.AbstractFileFilter in project fabric8 by jboss-fuse.
the class PatchTestSupport method preparePatchZip.
protected void preparePatchZip(String directoryToZip, String zipFile, final boolean includeParentDirectory) throws IOException {
File zip = new File(zipFile);
zip.getParentFile().mkdirs();
final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(new FileOutputStream(zip));
final File patchDirectory = new File(directoryToZip);
FileUtils.iterateFilesAndDirs(patchDirectory, new AbstractFileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return false;
}
String path = Utils.relative(includeParentDirectory ? patchDirectory.getParentFile() : patchDirectory, file);
ZipArchiveEntry entry = new ZipArchiveEntry(path);
try {
try {
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(file.toPath());
entry.setUnixMode(Utils.getUnixModeFromPermissions(file, permissions));
} catch (UnsupportedOperationException ignoredOnWindows) {
}
byte[] bytes = FileUtils.readFileToByteArray(file);
zos1.putArchiveEntry(entry);
zos1.write(bytes, 0, bytes.length);
zos1.closeArchiveEntry();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return true;
}
}, DirectoryFileFilter.DIRECTORY);
zos1.close();
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project dcos-commons by mesosphere.
the class ExampleMultiServiceResource method listYamls.
/**
* Returns a list of all available YAML examples, suitable for launching an example service against.
*/
@Path("yaml")
@GET
public Response listYamls() {
JSONArray yamls = new JSONArray();
// Sort names alphabetically:
Collection<File> files = new TreeSet<>(FileUtils.listFiles(new File(YAML_DIR), new AbstractFileFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(YAML_EXT);
}
}, null));
for (File f : files) {
String name = f.getName();
// Remove .yml extension in response:
yamls.put(name.substring(0, name.length() - YAML_EXT.length()));
}
return ResponseUtils.jsonOkResponse(yamls);
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class BundleCreatorComponent method doInstall.
private Bundle doInstall(String scriptPath, boolean force) throws BundleException, FileNotFoundException, MalformedURLException {
String rpcName = rpcNameFromScriptPath(scriptPath);
Bundle b = null;
// Non-tenant specific jar file
File compiledPath = new File(navajoIOConfig.getCompiledScriptPath(), FilenameUtils.getPath(rpcName));
File jarFile = new File(compiledPath, FilenameUtils.getBaseName(rpcName) + ".jar");
// Look for other tenant-specific jar files
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getBaseName(rpcName) + "_*.jar");
if (!compiledPath.exists() || !compiledPath.isDirectory()) {
logger.warn("CompiledPath is not a directory? {} This is going to crash...", compiledPath);
}
Collection<File> files = FileUtils.listFiles(compiledPath, fileFilter, null);
if (jarFile.exists()) {
files.add(jarFile);
}
for (File bundleFile : files) {
final String uri = bundleFile.toURI().toURL().toString();
Bundle previous = bundleContext.getBundle(uri);
if (previous != null) {
if (force) {
logger.debug("uninstalling bundle with URI {} with file: {}: ", uri, bundleFile);
previous.uninstall();
} else {
logger.debug("Skipping bundle at: " + uri + " as it is already installed. Lastmod: " + new Date(previous.getLastModified()) + " status: " + previous.getState());
continue;
}
}
logger.debug("Installing script: {}", bundleFile.getName());
FileInputStream fis = new FileInputStream(bundleFile);
b = this.bundleContext.installBundle(uri, fis);
b.start();
}
scriptsMap.remove(rpcName);
return b;
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class BundleCreatorComponent method removeOldCompiledScriptFiles.
private void removeOldCompiledScriptFiles(String rpcName) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getBaseName(rpcName) + "_*.jar");
File compiledPath = new File(navajoIOConfig.getCompiledScriptPath(), FilenameUtils.getPath(rpcName));
if (compiledPath.isDirectory()) {
// Removing jar itself
File jarFile = new File(compiledPath, FilenameUtils.getBaseName(rpcName) + ".jar");
if (jarFile.exists()) {
jarFile.delete();
}
Collection<File> files = FileUtils.listFiles(compiledPath, fileFilter, null);
for (File bundleFile : files) {
if (bundleFile.isFile() && bundleFile.exists()) {
bundleFile.delete();
}
}
}
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class TslPreCompiler method addSuperEntityDependency.
private void addSuperEntityDependency(String scriptFile, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc, Element n, String superEntity) {
String version = "0";
if (superEntity.indexOf(".") != -1) {
version = superEntity.substring(superEntity.indexOf(".") + 1, superEntity.indexOf("?") == -1 ? superEntity.length() : superEntity.indexOf("?"));
}
String replace = "." + version;
superEntity = superEntity.replace(replace, "");
if (superEntity.indexOf('?') > 0) {
superEntity = superEntity.split("\\?")[0];
}
if (scriptTenant != null) {
// trying tenant-specific variant first
String operationScriptFile = fetchScriptFileName(scriptFolder + File.separator + superEntity + "_" + scriptTenant);
// Check if exists
if (operationScriptFile != null) {
deps.add(new Dependency(scriptFile, operationScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
// Thus continue with next entity
return;
}
}
String superScriptFile = fetchScriptFileName(scriptFolder + File.separator + "entity" + File.separator + superEntity);
// Check if exists
boolean isBroken = false;
if (superScriptFile == null) {
isBroken = true;
superScriptFile = scriptFolder + File.separator + "entity" + File.separator + superEntity + ".broken";
}
deps.add(new Dependency(scriptFile, superScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
if (scriptTenant == null) {
File scriptFolderFile = new File(superScriptFile).getParentFile();
if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(superEntity) + "_*.xml");
Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
for (File f : files) {
deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
}
// NS3
AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(superEntity) + "_*.ns");
Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
for (File f : filesNS3) {
deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
}
}
}
}
Aggregations