Author: rmannibucau
Date: Wed Sep 18 13:39:39 2013
New Revision: 1524405
URL: http://svn.apache.org/r1524405
Log:
TOMEE-1032 trying to read WEB-INF/persistence.xml file in our persistence
bootstrap (for openjpa enhancement at load time)
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceBootstrap.java
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1524405&r1=1524404&r2=1524405&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Wed Sep 18 13:39:39 2013
@@ -110,7 +110,7 @@ public class DeploymentLoader implements
private boolean scanManagedBeans = true;
private static final Collection<String> KNOWN_DESCRIPTORS =
Arrays.asList("app-ctx.xml", "module.properties", "application.properties",
"web.xml", "ejb-jar.xml", "openejb-jar.xml", "env-entries.properties",
"beans.xml", "ra.xml", "application.xml", "application-client.xml",
"persistence-fragment.xml", "persistence.xml", "validation.xml",
NewLoaderLogic.EXCLUSION_FILE);
- private static String ALTDD =
SystemInstance.get().getOptions().get(OPENEJB_ALTDD_PREFIX, (String) null);
+ public static String ALTDD =
SystemInstance.get().getOptions().get(OPENEJB_ALTDD_PREFIX, (String) null);
public AppModule load(final File jarFile) throws OpenEJBException {
// verify we have a valid file
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceBootstrap.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceBootstrap.java?rev=1524405&r1=1524404&r2=1524405&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceBootstrap.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceBootstrap.java
Wed Sep 18 13:39:39 2013
@@ -16,10 +16,13 @@
*/
package org.apache.openejb.persistence;
+import org.apache.openejb.config.DeploymentLoader;
import org.apache.openejb.core.TempClassLoader;
import org.apache.openejb.javaagent.Agent;
import org.apache.openejb.loader.IO;
+import org.apache.openejb.util.URLs;
import org.apache.openejb.util.Saxs;
+import org.apache.xbean.finder.ClassLoaders;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -30,6 +33,7 @@ import javax.persistence.spi.Persistence
import javax.sql.DataSource;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -43,9 +47,11 @@ import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -84,38 +90,74 @@ public class PersistenceBootstrap {
try {
debug("searching for persistence.xml files");
- ArrayList<URL> urls =
Collections.list(classLoader.getResources("META-INF/persistence.xml"));
+ // create persistence.xml names respecting altdd
+ final Collection<String> pXmlNames = new ArrayList<String>();
+ if (DeploymentLoader.ALTDD != null) {
+ for (final String p : DeploymentLoader.ALTDD.split(",")) {
+ pXmlNames.add(p + ".persistence.xml");
+ pXmlNames.add(p + "-persistence.xml");
+ }
+ } else {
+ pXmlNames.add("persistence.xml");
+ }
+
+ final List<URL> urls = new LinkedList<URL>();
+ for (final String pXmlName : pXmlNames) { // find persistence.xml
in the classloader and in WEB-INF
+
urls.addAll(Collections.list(classLoader.getResources("META-INF/" + pXmlName)));
+ try {
+ final Collection<URL> loaderUrls =
ClassLoaders.findUrls(classLoader);
+ for (final URL url : loaderUrls) {
+ final File file = URLs.toFile(url);
+ if ("classes".equals(file.getName()) &&
"WEB-INF".equals(file.getParentFile().getName())) {
+ final File pXml = new File(file.getParentFile(),
pXmlName);
+ if (pXml.exists()) {
+ urls.add(pXml.toURI().toURL());
+ }
+ break;
+ }
+ if (file.getName().endsWith(".jar") &&
file.getParentFile().getName().equals("lib") &&
"WEB-INF".equals(file.getParentFile().getParentFile().getName())) {
+ final File pXml = new
File(file.getParentFile().getParentFile(), pXmlName);
+ if (pXml.exists()) {
+ urls.add(pXml.toURI().toURL());
+ }
+ break;
+ }
+ }
+ } catch (final Throwable th) {
+ // no-op
+ }
+ }
if (urls.size() == 0) {
debug("no persistence.xml files found");
return;
}
- Map<String, Unit> units = new HashMap<String, Unit>();
+ final Map<String, Unit> units = new HashMap<String, Unit>();
- for (URL url : urls) {
+ for (final URL url : urls) {
String urlPath = url.toExternalForm();
debug("found " + urlPath);
try {
- InputStream in = IO.read(url);
+ final InputStream in = IO.read(url);
try {
collectUnits(in, units, args);
- } catch (Throwable e) {
+ } catch (final Throwable e) {
debug("failed to read " + urlPath, e);
in.close();
}
- } catch (Throwable e) {
+ } catch (final Throwable e) {
debug("failed to read " + urlPath, e);
}
}
- for (Unit unit : units.values()) {
- String provider = unit.provider;
- String extraClassesKey = provider + "@classes";
- String unitNameKey = provider + "@unitName";
- String unitName = args.getProperty(unitNameKey,
"classpath-bootstrap");
+ for (final Unit unit : units.values()) {
+ final String provider = unit.provider;
+ final String extraClassesKey = provider + "@classes";
+ final String unitNameKey = provider + "@unitName";
+ final String unitName = args.getProperty(unitNameKey,
"classpath-bootstrap");
- String classes = args.getProperty(extraClassesKey);
+ final String classes = args.getProperty(extraClassesKey);
if (classes != null) {
debug("parsing value of " + extraClassesKey);
@@ -135,7 +177,7 @@ public class PersistenceBootstrap {
debug("starting: " + provider);
}
- PersistenceUnitInfoImpl info = new
PersistenceUnitInfoImpl(new Handler());
+ final PersistenceUnitInfoImpl info = new
PersistenceUnitInfoImpl(new Handler());
info.setManagedClassNames(new ArrayList(unit.classes));
info.setPersistenceProviderClassName(unit.provider);
info.setProperties(new Properties());
@@ -147,21 +189,21 @@ public class PersistenceBootstrap {
info.setExcludeUnlistedClasses(true);
info.setClassLoader(classLoader);
- for (String name : unit.classes) {
+ for (final String name : unit.classes) {
debug("class " + name);
}
- Class clazz = classLoader.loadClass(unit.provider);
- PersistenceProvider persistenceProvider =
(PersistenceProvider) clazz.newInstance();
+ final Class clazz = classLoader.loadClass(unit.provider);
+ final PersistenceProvider persistenceProvider =
(PersistenceProvider) clazz.newInstance();
// Create entity manager factory
- EntityManagerFactory emf =
persistenceProvider.createContainerEntityManagerFactory(info, new HashMap());
+ final EntityManagerFactory emf =
persistenceProvider.createContainerEntityManagerFactory(info, new HashMap());
emf.close();
debug("success: " + provider);
- } catch (Throwable e) {
+ } catch (final Throwable e) {
debug("failed: " + provider, e);
}
}
- } catch (Throwable t) {
+ } catch (final Throwable t) {
debug("error: ", t);
}
}