Search in sources :

Example 1 with FileUtils

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);
        }
    }
}
Also used : FileUtils(org.apache.openejb.loader.FileUtils) Properties(java.util.Properties) FilenameFilter(java.io.FilenameFilter) SystemInstance(org.apache.openejb.loader.SystemInstance) File(java.io.File) Map(java.util.Map)

Example 2 with FileUtils

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;
}
Also used : FileUtils(org.apache.openejb.loader.FileUtils) Properties(java.util.Properties) File(java.io.File)

Example 3 with FileUtils

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);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) FileUtils(org.apache.openejb.loader.FileUtils) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with FileUtils

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());
        }
    }
}
Also used : FileUtils(org.apache.openejb.loader.FileUtils) ArrayList(java.util.ArrayList) File(java.io.File) Map(java.util.Map)

Example 5 with FileUtils

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));
}
Also used : FileUtils(org.apache.openejb.loader.FileUtils) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

File (java.io.File)8 FileUtils (org.apache.openejb.loader.FileUtils)8 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Properties (java.util.Properties)3 MalformedURLException (java.net.MalformedURLException)2 JarFile (java.util.jar.JarFile)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 FilenameFilter (java.io.FilenameFilter)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1