Search in sources :

Example 1 with ResourceFinder

use of org.apache.xbean.finder.ResourceFinder in project crate by crate.

the class PluginLoader method findImplementations.

@Nullable
private Collection<Class<? extends Plugin>> findImplementations(Collection<URL> pluginUrls) {
    URL[] urls = pluginUrls.toArray(new URL[pluginUrls.size()]);
    ClassLoader loader = URLClassLoader.newInstance(urls, getClass().getClassLoader());
    ResourceFinder finder = new ResourceFinder(RESOURCE_PATH, loader, urls);
    try {
        return finder.findAllImplementations(Plugin.class);
    } catch (ClassCastException e) {
        logger.error("plugin does not implement io.crate.Plugin interface", e);
    } catch (ClassNotFoundException e) {
        logger.error("error while loading plugin, misconfigured plugin", e);
    } catch (Throwable t) {
        logger.error("error while loading plugins", t);
    }
    return null;
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Nullable(org.elasticsearch.common.Nullable)

Example 2 with ResourceFinder

use of org.apache.xbean.finder.ResourceFinder in project tomee by apache.

the class Assembler method createTransactionPolicyFactory.

private TransactionPolicyFactory createTransactionPolicyFactory(final EjbJarInfo ejbJar, final ClassLoader classLoader) {
    TransactionPolicyFactory factory = null;
    final Object value = ejbJar.properties.get(TransactionPolicyFactory.class.getName());
    if (value instanceof TransactionPolicyFactory) {
        factory = (TransactionPolicyFactory) value;
    } else if (value instanceof String) {
        try {
            final String[] parts = ((String) value).split(":", 2);
            final ResourceFinder finder = new ResourceFinder("META-INF", classLoader);
            final Map<String, Class<? extends TransactionPolicyFactory>> plugins = finder.mapAvailableImplementations(TransactionPolicyFactory.class);
            final Class<? extends TransactionPolicyFactory> clazz = plugins.get(parts[0]);
            if (clazz != null) {
                if (parts.length == 1) {
                    factory = clazz.getConstructor(String.class).newInstance(parts[1]);
                } else {
                    factory = clazz.newInstance();
                }
            }
        } catch (final Exception ignored) {
        // couldn't determine the plugins, which isn't fatal
        }
    }
    if (factory == null) {
        factory = new JtaTransactionPolicyFactory(transactionManager);
    }
    return factory;
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) JtaTransactionPolicyFactory(org.apache.openejb.core.transaction.JtaTransactionPolicyFactory) JtaTransactionPolicyFactory(org.apache.openejb.core.transaction.JtaTransactionPolicyFactory) TransactionPolicyFactory(org.apache.openejb.core.transaction.TransactionPolicyFactory) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 3 with ResourceFinder

use of org.apache.xbean.finder.ResourceFinder in project tomee by apache.

the class Cipher method availableCiphers.

private static void availableCiphers() {
    try {
        final ResourceFinder finder = new ResourceFinder("META-INF/");
        final Map<String, Class<? extends PasswordCipher>> impls = finder.mapAllImplementations(PasswordCipher.class);
        System.out.println("Available ciphers are: " + Join.join(", ", impls.keySet()));
    } catch (final Exception ignore) {
    // no-op
    }
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) PasswordCipher(org.apache.openejb.cipher.PasswordCipher) PasswordCipherException(org.apache.openejb.cipher.PasswordCipherException) ParseException(org.apache.commons.cli.ParseException) SystemExitException(org.apache.openejb.cli.SystemExitException)

Example 4 with ResourceFinder

use of org.apache.xbean.finder.ResourceFinder in project tomee by apache.

the class MainImpl method help.

private static void help(final boolean printHeader) {
    // We actually use a different Options object to parse the 'openejb' command
    try {
        final Options options = new Options();
        final ResourceFinder commandFinder = new ResourceFinder("META-INF");
        final Map<String, Properties> commands = commandFinder.mapAvailableProperties("org.apache.openejb.cli");
        for (final Map.Entry<String, Properties> command : commands.entrySet()) {
            if (command.getKey().contains(".")) {
                continue;
            }
            final Properties p = command.getValue();
            final String description = p.getProperty(descriptionI18n, p.getProperty(descriptionBase));
            options.addOption(command.getKey(), false, description);
        }
        final HelpFormatter formatter = new HelpFormatter();
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw);
        final String syntax = "openejb <command> [options] [args]";
        final String header = "\nAvailable commands:";
        final String footer = "\n" + "Try 'openejb <command> --help' for help on a specific command.\n" + "For example 'openejb deploy --help'.\n" + "Important: to display exceptions while running commands, add -e option.\n" + "\n" + "Apache OpenEJB -- EJB Container System and Server.\n" + "For additional information, see http://tomee.apache.org\n" + "Bug Reports to <users@tomee.apache.org>";
        if (!printHeader) {
            pw.append(header).append("\n\n");
            formatter.printOptions(pw, 74, options, 1, 3);
        } else {
            formatter.printHelp(pw, 74, syntax, header, options, 1, 3, footer, false);
        }
        pw.flush();
        // Fix up the commons-cli output to our liking.
        String text = sw.toString().replaceAll("\n -", "\n  ");
        text = text.replace("\nApache OpenEJB", "\n\nApache OpenEJB");
        System.out.print(text);
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) ResourceFinder(org.apache.xbean.finder.ResourceFinder) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Properties(java.util.Properties) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 5 with ResourceFinder

use of org.apache.xbean.finder.ResourceFinder in project tomee by apache.

the class DeploymentLoader method addWebModuleDescriptors.

public static void addWebModuleDescriptors(final URL baseUrl, final WebModule webModule, final AppModule appModule) throws OpenEJBException {
    final List<URL> urls = webModule.getScannableUrls();
    final ResourceFinder finder = new ResourceFinder("", urls.toArray(new URL[urls.size()]));
    final Map<String, Object> otherDD = new HashMap<>(getDescriptors(finder, false));
    // "persistence.xml" is done separately since we manage a list of url and not s single url
    try {
        final List<URL> persistenceXmls = finder.findAll(META_INF + "persistence.xml");
        if (persistenceXmls.size() >= 1) {
            final URL old = (URL) otherDD.get("persistence.xml");
            if (old != null && !persistenceXmls.contains(old)) {
                persistenceXmls.add(old);
            }
            otherDD.put("persistence.xml", persistenceXmls);
        }
    } catch (final IOException e) {
    // ignored
    }
    addConnectorModules(appModule, webModule);
    addWebPersistenceDD("persistence.xml", otherDD, appModule);
    addWebPersistenceDD("persistence-fragment.xml", otherDD, appModule);
    addPersistenceUnits(appModule, baseUrl);
    addWebFragments(webModule, urls);
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

ResourceFinder (org.apache.xbean.finder.ResourceFinder)20 IOException (java.io.IOException)12 URL (java.net.URL)12 File (java.io.File)7 HashMap (java.util.HashMap)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 InputStream (java.io.InputStream)3 TreeMap (java.util.TreeMap)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 MalformedURLException (java.net.MalformedURLException)2 URLClassLoader (java.net.URLClassLoader)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 PosixParser (org.apache.commons.cli.PosixParser)2 OpenEJBException (org.apache.openejb.OpenEJBException)2