use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class TslPreCompiler method findIncludeDependencies.
private void findIncludeDependencies(String fullScriptPath, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc) throws UserException {
NodeList includes = tslDoc.getElementsByTagName("include");
for (int i = 0; i < includes.getLength(); i++) {
Element n = (Element) includes.item(i);
String includedScript = n.getAttribute("script");
if (includedScript == null || includedScript.equals("")) {
throw new UserException(-1, "No script name found in include tag (missing or empty script attribute): " + n);
}
if (scriptTenant != null) {
// trying tenant-specific variant first
String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript + "_" + scriptTenant);
// Check if exists
if (includeScriptFile != null) {
deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
// Thus continue with next include
continue;
}
}
String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript);
// Check if exists
boolean isBroken = false;
if (includeScriptFile == null) {
isBroken = true;
includeScriptFile = scriptFolder + File.separator + includedScript + ".broken";
}
if (includeScriptFile.equals(fullScriptPath)) {
throw new UserException(-1, "Cannot include myself!");
}
deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
if (scriptTenant == null) {
File scriptFolderFile = new File(includeScriptFile).getParentFile();
if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
for (File f : files) {
deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
}
// NS3
AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
for (File f : filesNS3) {
deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
}
}
}
}
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project fuse-karaf 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);
Utils.mkdirs(zip.getParentFile());
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 ignored) /*on Windows*/
{
}
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 pentaho-platform by pentaho.
the class KarafBoot method startup.
@Override
public boolean startup(IPentahoSession session) {
try {
String solutionRootPath = PentahoSystem.getApplicationContext().getSolutionRootPath();
File karafDir = new File(solutionRootPath + KARAF_DIR);
if (!karafDir.exists()) {
logger.warn("Karaf not found in standard dir of '" + (solutionRootPath + KARAF_DIR) + "' ");
String osxAppRootDir = System.getProperty(SYSTEM_PROP_OSX_APP_ROOT_DIR);
if (!StringUtils.isEmpty(osxAppRootDir)) {
logger.warn("Given that the system property '" + SYSTEM_PROP_OSX_APP_ROOT_DIR + "' is set, we are in " + "a OSX .app context; we'll try looking for Karaf in the app's root dir '" + osxAppRootDir + "' ");
File osxAppKarafDir = new File(osxAppRootDir + KARAF_DIR);
if (osxAppKarafDir.exists()) {
// karaf found in the app's root dir
karafDir = osxAppKarafDir;
}
}
}
// Use getAbsolutePath to prevent invalid path in Windows
String root = karafDir.getAbsolutePath();
// See if user specified a karaf folder they would like to use
String rootCopyFolderString = System.getProperty(PENTAHO_KARAF_ROOT_COPY_DEST_FOLDER);
// Use a transient folder (will be deleted on exit) if user says to or cannot open config.properties
boolean transientRoot = Boolean.parseBoolean(System.getProperty(PENTAHO_KARAF_ROOT_TRANSIENT, "false"));
if (rootCopyFolderString == null && !canOpenConfigPropertiesForEdit(root)) {
transientRoot = true;
}
final File destDir;
if (transientRoot) {
if (rootCopyFolderString == null) {
destDir = Files.createTempDirectory("karaf").toFile();
} else {
int directoryAttempts = Integer.parseInt(System.getProperty(PENTAHO_KARAF_ROOT_TRANSIENT_DIRECTORY_ATTEMPTS, "250"));
File candidate = new File(rootCopyFolderString);
int i = 1;
while (candidate.exists() || !candidate.mkdirs()) {
if (i > directoryAttempts) {
candidate = Files.createTempDirectory("karaf").toFile();
logger.warn("Unable to create " + rootCopyFolderString + " after " + i + " attempts, using temp dir " + candidate);
break;
}
candidate = new File(rootCopyFolderString + (i++));
}
destDir = candidate;
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
try {
if (main != null) {
main.destroy();
}
// release lock
if (karafInstance != null) {
karafInstance.close();
}
deleteRecursiveIfExists(destDir);
} catch (IOException e) {
logger.error("Unable to delete karaf directory " + destDir, e);
} catch (Exception e) {
logger.error("Error stopping Karaf", e);
}
}
}));
} else if (rootCopyFolderString != null) {
destDir = new File(rootCopyFolderString);
} else {
destDir = null;
}
// Copy karaf (symlinking allowed files/folders if possible)
if (destDir != null && (transientRoot || !destDir.exists())) {
final Set<String> symlinks = new HashSet<>();
String symlinkFiles = System.getProperty(PENTAHO_KARAF_ROOT_COPY_FOLDER_SYMLINK_FILES, "lib,system");
if (symlinkFiles != null) {
for (String symlink : symlinkFiles.split(",")) {
symlinks.add(symlink.trim());
}
}
final Set<String> excludes = new HashSet<>();
String excludeFiles = System.getProperty(PENTAHO_KARAF_ROOT_COPY_FOLDER_EXCLUDE_FILES, "caches");
if (excludeFiles != null) {
for (String exclude : excludeFiles.split(",")) {
excludes.add(exclude.trim());
}
}
final Path karafDirPath = Paths.get(karafDir.toURI());
FileUtils.copyDirectory(karafDir, destDir, new AbstractFileFilter() {
@Override
public boolean accept(File file) {
Path filePath = Paths.get(file.toURI());
String relativePath = karafDirPath.relativize(filePath).toString();
if (excludes.contains(relativePath)) {
return false;
} else if (symlinks.contains(relativePath)) {
File linkFile = new File(destDir, relativePath);
try {
boolean linkFileDirCreated = linkFile.getParentFile().mkdirs();
logger.info("link file " + linkFile.getParentFile().getAbsolutePath() + (linkFileDirCreated ? "created" : "already existed"));
} catch (SecurityException exception) {
logger.error(linkFile.getParentFile().getAbsolutePath() + " Access denied.");
throw exception;
}
Path link = Paths.get(linkFile.toURI());
try {
// Try to create a symlink and skip the copy if successful
if (Files.createSymbolicLink(link, filePath) != null) {
return false;
}
} catch (IOException e) {
logger.warn("Unable to create symlink " + linkFile.getAbsolutePath() + " -> " + file.getAbsolutePath());
}
}
return true;
}
});
}
if (destDir != null) {
root = destDir.toURI().getPath();
}
this.karafCustomProperties = this.readCustomProperties(root);
configureSystemProperties(solutionRootPath, root);
expandSystemPackages();
cleanCachesIfFlagSet(root);
// Setup karaf instance configuration
karafInstance = createAndProcessKarafInstance(root);
// Wrap the startup of Karaf in a child thread which has explicitly set a bogus authentication. This is
// work-around and issue with Karaf inheriting the Authenticaiton set on the main system thread due to the
// InheritableThreadLocal backing the SecurityContext. By setting a fake authentication, calls to the
// org.pentaho.platform.osgi.SpringSecurityLoginModule always challenge the user.
Thread karafThread = new Thread(new Runnable() {
@Override
public void run() {
// Bogus authentication
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(UUID.randomUUID().toString(), ""));
main = new Main(new String[0]);
try {
main.launch();
} catch (Exception e) {
main = null;
logger.error("Error starting Karaf", e);
}
}
});
karafThread.setDaemon(true);
karafThread.run();
karafThread.join();
} catch (Exception e) {
main = null;
logger.error("Error starting Karaf", e);
}
// release memory reserved for karaf custom properties, as they are only needed in the startup phase.
this.karafCustomProperties = null;
return main != null;
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class TslPreCompiler method findMethodDependencies.
private void findMethodDependencies(String scriptFile, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc) {
NodeList methods = tslDoc.getElementsByTagName("method");
for (int i = 0; i < methods.getLength(); i++) {
Element n = (Element) methods.item(i);
String methodScript = n.getAttribute("name");
if (methodScript == null || methodScript.equals("")) {
return;
}
if (scriptTenant != null) {
// trying tenant-specific variant first
String methodScriptFile = fetchScriptFileName(scriptFolder + File.separator + methodScript);
// Check if exists
if (methodScriptFile != null) {
deps.add(new Dependency(scriptFile, methodScriptFile, Dependency.METHOD_DEPENDENCY, getLineNr(n)));
// Thus continue with next method
continue;
}
}
String methodScriptFile = fetchScriptFileName(scriptFolder + File.separator + methodScript);
// Check if exists
boolean isBroken = false;
if (methodScriptFile == null) {
isBroken = true;
methodScriptFile = scriptFolder + File.separator + methodScript + ".unknown";
}
deps.add(new Dependency(scriptFile, methodScriptFile, Dependency.METHOD_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
File scriptFolderFile = new File(methodScriptFile).getParentFile();
if (scriptTenant == null && scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(methodScript) + "_*.xml");
Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
for (File f : files) {
deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.METHOD_DEPENDENCY, getLineNr(n)));
}
// Check NS3
AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(methodScript) + "_*.ns");
Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
for (File f : filesNS3) {
deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.METHOD_DEPENDENCY, getLineNr(n)));
}
}
}
}
use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.
the class TslPreCompiler method findEntityDependencies.
private void findEntityDependencies(String scriptFile, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc) {
if (scriptFile.indexOf("entity") < 1) {
return;
}
NodeList operations = tslDoc.getElementsByTagName("operation");
NodeList messages = tslDoc.getElementsByTagName("message");
for (int i = 0; i < operations.getLength(); i++) {
Element n = (Element) operations.item(i);
String operationScript = n.getAttribute("service").equals("") ? null : n.getAttribute("service");
String operationValidationScript = n.getAttribute("validationService").equals("") ? null : n.getAttribute("validationService");
if (operationScript != null && !"".equals(operationScript)) {
if (scriptTenant != null) {
// trying tenant-specific variant first
String operationScriptFile = fetchScriptFileName(scriptFolder + File.separator + operationScript + "_" + scriptTenant);
// Check if exists
if (new File(operationScriptFile).exists()) {
deps.add(new Dependency(scriptFile, operationScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
// Thus continue with next entity
continue;
}
}
String operationScriptFile = fetchScriptFileName(scriptFolder + File.separator + operationScript);
String operationValidationScriptFile = (operationValidationScript != null ? fetchScriptFileName(scriptFolder + File.separator + operationValidationScript) : null);
// Check if exists
boolean isBroken = false;
if (operationScriptFile == null) {
isBroken = true;
operationScriptFile = scriptFolder + File.separator + operationScript + ".broken";
}
deps.add(new Dependency(scriptFile, operationScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
if (scriptTenant == null) {
File scriptFolderFile = new File(operationScriptFile).getParentFile();
if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(operationScript) + "_*.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(operationScript) + "_*.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)));
}
}
}
// Handle validation service
if (operationValidationScriptFile == null) {
isBroken = true;
}
if (operationValidationScript != null) {
deps.add(new Dependency(scriptFile, operationValidationScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
if (scriptTenant == null) {
File scriptFolderFile = new File(operationValidationScriptFile).getParentFile();
if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(operationValidationScript) + "_*.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(operationValidationScript) + "_*.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)));
}
}
}
}
}
}
for (int i = 0; i < messages.getLength(); i++) {
Element n = (Element) messages.item(i);
String subType = n.getAttribute("subtype");
if (subType != null && !subType.equals("")) {
String[] subTypeElements = subType.split(",");
for (String subTypeElement : subTypeElements) {
if (subTypeElement.startsWith("interface=")) {
for (String iface : subTypeElement.replace("interface=", "").split(";")) {
addSuperEntityDependency(scriptFile, scriptTenant, scriptFolder, deps, tslDoc, n, iface);
}
}
}
}
String extendsAttr = n.getAttribute("extends");
if (extendsAttr == null || extendsAttr.equals("") || !extendsAttr.startsWith("navajo://")) {
continue;
}
String ext = extendsAttr.substring(9);
// Entity versioning stuff
String[] superEntities = ext.split(",");
for (String superEntity : superEntities) {
addSuperEntityDependency(scriptFile, scriptTenant, scriptFolder, deps, tslDoc, n, superEntity);
}
}
}
Aggregations