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;
}
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;
}
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
}
}
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();
}
}
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);
}
Aggregations