use of org.apache.openejb.loader.FileUtils in project tomee by apache.
the class ServiceManager method overrideProperties.
private void overrideProperties(final String serviceName, final Properties serviceProperties) throws IOException {
final SystemInstance systemInstance = SystemInstance.get();
final FileUtils base = systemInstance.getBase();
// Override with file from conf dir
final File conf = base.getDirectory("conf");
if (conf.exists()) {
final String legacy = System.getProperty("openejb.conf.schema.legacy");
boolean legacySchema = Boolean.parseBoolean((null != legacy ? legacy : "false"));
if (null == legacy) {
// Legacy is not configured either way, so make an educated guess.
// If we find at least 2 known service.properties files then assume legacy
final File[] files = conf.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, String name) {
name = name.toLowerCase(Locale.ENGLISH);
return name.equals("ejbd.properties") || name.equals("ejbds.properties") || name.equals("admin.properties") || name.equals("httpejbd.properties");
}
});
if (null != files && files.length > 1) {
legacySchema = true;
}
}
addProperties(conf, legacySchema, new File(conf, serviceName + ".properties"), serviceProperties, true);
addProperties(conf, legacySchema, new File(conf, SystemInstance.get().currentProfile() + "." + serviceName + ".properties"), serviceProperties, false);
}
holdsWithUpdate(serviceProperties);
// Override with system properties
final String prefix = serviceName + ".";
final Properties sysProps = new Properties(System.getProperties());
sysProps.putAll(systemInstance.getProperties());
for (final Map.Entry<Object, Object> entry : sysProps.entrySet()) {
final Map.Entry entry1 = (Map.Entry) entry;
final Object value = entry1.getValue();
String key = (String) entry1.getKey();
if (value instanceof String && key.startsWith(prefix)) {
key = key.replaceFirst(prefix, "");
serviceProperties.setProperty(key, (String) value);
}
}
}
use of org.apache.openejb.loader.FileUtils in project tomee by apache.
the class JarExtractor method extract.
/**
* Extract the Jar file into an unpacked directory structure, and
* return the absolute pathname to the extracted directory.
*
* @param file Jar file to unpack
* @param pathname Context path name for web application
* @throws IllegalArgumentException if this is not a "jar:" URL
* @throws IOException if an input/output error was encountered
* during expansion
*/
public static File extract(final File file, final String pathname) throws IOException {
final Properties properties = SystemInstance.get().getProperties();
final String key = "tomee.unpack.dir";
File unpackDir = file.getParentFile();
if (properties.containsKey(key)) {
final FileUtils base = SystemInstance.get().getBase();
unpackDir = base.getDirectory(properties.getProperty(key), true);
}
File docBase = new File(unpackDir, pathname);
docBase = extract(file, docBase);
return docBase;
}
use of org.apache.openejb.loader.FileUtils in project tomee by apache.
the class UrlCache method createCacheDir.
private static File createCacheDir() {
try {
final FileUtils openejbBase = SystemInstance.get().getBase();
File dir = null;
// if we are not embedded, cache (temp) dir is under base dir
if (SystemInstance.get().getConf(null).exists()) {
try {
dir = openejbBase.getDirectory("temp");
} catch (final IOException e) {
// Ignore
}
}
// if we are embedded, tmp dir is in the system tmp dir
if (dir == null) {
dir = Files.tmpdir();
}
// If the cache dir already exists then empty its contents
if (dir.exists()) {
final File[] files = dir.listFiles();
if (null != files) {
for (final File f : files) {
deleteDir(f);
}
}
} else {
dir = createCacheDir(new File(dir.getAbsolutePath()));
}
return dir;
} catch (final IOException e) {
throw new OpenEJBRuntimeException(e);
}
}
use of org.apache.openejb.loader.FileUtils in project tomee by apache.
the class Log4jLogStreamFactory method preprocessProperties.
private void preprocessProperties(final Properties properties) {
final FileUtils base = SystemInstance.get().getBase();
final File confDir = SystemInstance.get().getConf(null);
final File baseDir = base.getDirectory();
final File userDir = new File("foo").getParentFile();
final File[] paths = { confDir, baseDir, userDir };
final List<File> missing = new ArrayList<>();
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
final String key = (String) entry.getKey();
final String value = (String) entry.getValue();
if (key.endsWith(".File")) {
boolean found = false;
for (int i = 0; i < paths.length && !found; i++) {
final File path = paths[i];
final File logfile = new File(path, value);
if (logfile.getParentFile().exists()) {
properties.setProperty(key, logfile.getAbsolutePath());
found = true;
}
}
if (!found) {
final File logfile = new File(paths[0], value);
missing.add(logfile);
}
}
}
if (missing.size() > 0) {
final org.apache.log4j.Logger logger = getFallabckLogger();
logger.error("Logging may not operate as expected. The directories for the following files do not exist so no file can be created. See the list below.");
for (int i = 0; i < missing.size(); i++) {
final File file = missing.get(i);
logger.error("[" + i + "] " + file.getAbsolutePath());
}
}
}
use of org.apache.openejb.loader.FileUtils in project tomee by apache.
the class DeployerEjbTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
final FileUtils base = SystemInstance.get().getBase();
final File conf = base.getDirectory("conf", false);
Files.delete(conf);
final File apps = base.getDirectory("apps", true);
Files.delete(apps);
base.getDirectory("apps", true);
base.getDirectory("conf", true);
property.set(System.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS));
System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString());
warArchive.set(WebArchives.warArchive(TestClass.class));
}
Aggregations