use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.
the class PluginParserTest method testRequireBundleLogged.
public void testRequireBundleLogged() {
final java.util.Set messages = new HashSet();
Logger.getLogger("DataNucleus.General").addAppender(new Appender() {
public void setName(String arg0) {
}
public void setLayout(Layout arg0) {
}
public void setErrorHandler(ErrorHandler arg0) {
}
public boolean requiresLayout() {
return false;
}
public String getName() {
return "testappender123";
}
public Layout getLayout() {
return null;
}
public Filter getFilter() {
return null;
}
public ErrorHandler getErrorHandler() {
return null;
}
public void doAppend(LoggingEvent arg0) {
if (arg0.getRenderedMessage().indexOf("but it cannot be resolved") > 0) {
messages.add(arg0.getRenderedMessage());
}
}
public void close() {
}
public void clearFilters() {
}
public void addFilter(Filter arg0) {
}
});
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
assertEquals(0, mgr.getExtensionPoints().length);
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST3.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST4.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST5.MF", null));
mgr.resolveConstraints();
try {
assertEquals(2, messages.size());
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" requires \"org.datanucleus.plugin.test6\" but it cannot be resolved."));
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" has an optional dependency to \"org.datanucleus.plugin.test7\" but it cannot be resolved"));
} finally {
Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
}
}
use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.
the class TypeManagerTest method setUp.
/**
* Create a TypeManager for testing.
*/
protected void setUp() throws Exception {
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
Properties props = new Properties();
props.setProperty("bundle-check-action", "EXCEPTION");
PluginManager pluginMgr = new PluginManager(null, clr, props);
NucleusContext nucCtx = new PersistenceNucleusContextImpl(null, null, pluginMgr);
typeMgr = nucCtx.getTypeManager();
}
use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.
the class PluginManager method createPluginManager.
/**
* Convenience method that will create and return a PluginManager using any passed in properties.
* Supports the following properties
* <ul>
* <li>datanucleus.primaryClassLoader</li>
* <li>datanucleus.plugin.pluginRegistryClassName</li>
* <li>datanucleus.plugin.pluginRegistryBundleCheck</li>
* <li>datanucleus.plugin.allowUserBundles</li>
* <li>datanucleus.plugin.validatePlugins</li>
* </ul>
* @param props Any properties defining the plugin manager capabilities
* @param loader Any class loader to make use of when loading
* @return The PluginManager
*/
public static PluginManager createPluginManager(Map props, ClassLoader loader) {
ClassLoaderResolver clr = loader != null ? new ClassLoaderResolverImpl(loader) : new ClassLoaderResolverImpl();
if (props != null) {
clr.registerUserClassLoader((ClassLoader) props.get(PropertyNames.PROPERTY_CLASSLOADER_PRIMARY));
}
Properties pluginProps = new Properties();
String registryClassName = null;
if (props != null) {
registryClassName = (String) props.get(PropertyNames.PROPERTY_PLUGIN_REGISTRY_CLASSNAME);
if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_REGISTRYBUNDLECHECK)) {
pluginProps.setProperty("bundle-check-action", (String) props.get(PropertyNames.PROPERTY_PLUGIN_REGISTRYBUNDLECHECK));
}
if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_ALLOW_USER_BUNDLES)) {
pluginProps.setProperty("allow-user-bundles", (String) props.get(PropertyNames.PROPERTY_PLUGIN_ALLOW_USER_BUNDLES));
}
if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_VALIDATEPLUGINS)) {
pluginProps.setProperty("validate-plugins", (String) props.get(PropertyNames.PROPERTY_PLUGIN_VALIDATEPLUGINS));
}
}
return new PluginManager(registryClassName, clr, pluginProps);
}
use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.
the class ImplementationGenerator method enhance.
/**
* Enhance the implementation of the class/interface.
* @param clr ClassLoader resolver
*/
public void enhance(final ClassLoaderResolver clr) {
// define the generated class in the classloader so we populate the metadata
final EnhancerClassLoader loader = new EnhancerClassLoader();
loader.defineClass(fullClassName, getBytes(), clr);
// Create MetaData for implementation of interface
final ClassLoaderResolver genclr = new ClassLoaderResolverImpl(loader);
final ClassMetaData implementationCmd;
if (inputCmd instanceof InterfaceMetaData) {
implementationCmd = new ClassMetaData((InterfaceMetaData) inputCmd, className, true);
} else {
implementationCmd = new ClassMetaData((ClassMetaData) inputCmd, className);
}
// Do as PrivilegedAction since populate()/initialise() use reflection to get additional fields
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
implementationCmd.populate(genclr, null, metaDataMgr);
implementationCmd.initialise(genclr);
return null;
}
});
// enhance the class and update the byte definition
ClassEnhancer gen = new ClassEnhancerImpl(implementationCmd, genclr, metaDataMgr, JDOEnhancementNamer.getInstance(), getBytes());
gen.enhance();
bytes = gen.getClassBytes();
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class AnnotationTest method testEmbeddable.
/**
* Test of JPA @Embeddable.
*/
public void testEmbeddable() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(DepartmentPK.class.getName(), clr);
assertNotNull(cmd1);
}
Aggregations