Bug 401267 - [enterprise] Provide support for persistence provider provided by the application - change persistence library folder
diff --git a/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java b/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
index f958f76..c508dd8 100755
--- a/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
+++ b/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/main/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHook.java
@@ -42,6 +42,7 @@
 	private static final String PERSISTENCE_INTEGRATION_JAR = System.getProperty(PERSISTENCE_INTEGRATION_JAR_PROP_NAME);

 	private static final String CONFIG_AREA = "osgi.configuration.area";

 	private static final String LIB_DIR = "lib";

+	private static final String PERSISTENCE_DIR = "persistence";

 	

 	@Override

 	public void addHooks(HookRegistry registry) {

@@ -94,12 +95,17 @@
 			throw new ClasspathExtenderClassLoadingHookException("Property [" + CONFIG_AREA + "] is missing");

 		}

 		File configurationFile = new File(normalize(configurationPath));

-		File libDir = new File(configurationFile.getParentFile(), LIB_DIR);		

-		if (!libDir.exists()) {

+		File lib = new File(configurationFile.getParentFile(), LIB_DIR);

+		if (!lib.exists()) {

 			throw new ClasspathExtenderClassLoadingHookException("lib folder is missing");

 		}

 		

-		String[] libs = libDir.list(new FilenameFilter() {	

+		File persistenceLibDir = new File(lib, PERSISTENCE_DIR);

+		if (!persistenceLibDir.exists()) {

+			throw new ClasspathExtenderClassLoadingHookException("lib/persistence folder is missing");

+		}

+		

+		String[] libs = persistenceLibDir.list(new FilenameFilter() {	

 			@Override

 			public boolean accept(File dir, String name) {

 				if (name.startsWith(PERSISTENCE_INTEGRATION_JAR)) {

@@ -110,14 +116,14 @@
 		});

 		

 		if (libs.length == 0) {

-			throw new ClasspathExtenderClassLoadingHookException("No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib folder");

+			throw new ClasspathExtenderClassLoadingHookException("No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib/persistence folder");

 		}

 		

 		if (libs.length > 1) {

-			logger.log(Level.SEVERE, "Found " + libs.length + " files with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib folder (one expected); choosing [" + libs[0] + "]");

+			logger.log(Level.SEVERE, "Found " + libs.length + " files with name starting with [" + PERSISTENCE_INTEGRATION_JAR + "] was found in lib/persistence folder (one expected); choosing [" + libs[0] + "]");

 		}

 		

-		persistenceIntegrationJar = new File(libDir, libs[0]);

+		persistenceIntegrationJar = new File(persistenceLibDir, libs[0]);

 		

 	}

 

diff --git a/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/test/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHookTests.java b/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/test/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHookTests.java
index aa5f63e..7dd862c 100755
--- a/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/test/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHookTests.java
+++ b/org.eclipse.virgo.web.enterprise.persistence.openejb.classloading.hook/src/test/java/org/eclipse/virgo/web/enterprise/persistence/openejb/classloading/hook/AppLoaderClasspathExtenderClassLoadingHookTests.java
@@ -39,6 +39,7 @@
 	private static final String FILE_SCHEME = "file:";

 	private static final String CONFIG_AREA = "osgi.configuration.area";

 	private static final String LIB_DIR = "lib";

+	private static final String PERSISTENCE_DIR = "persistence";

 	private static final String WEB_CONTEXTPATH_HEADER = "Web-ContextPath";

 	private static final String PERSISTENCE_INTEGRATION_JAR1 = "org.apache.openejb.jpa.integration.jar_v1.1";

 	

@@ -83,7 +84,8 @@
 		data.setManifest(manifest);

 		ClasspathManager classpathmanager = new ClasspathManagerStub(data, new String[]{}, classloader);

 		File libDir = new File(new File("."), LIB_DIR);

-		String classpath = new File(libDir, PERSISTENCE_INTEGRATION_JAR).getAbsolutePath();

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR);

+		String classpath = new File(libPersistenceDir, PERSISTENCE_INTEGRATION_JAR).getAbsolutePath();

 		ClasspathEntry entry = new ClasspathEntry(new BundleFileStub(classpath), null);

 		cpEntries.add(entry);

 		AppLoaderClasspathExtenderClassLoadingHook hook = new AppLoaderClasspathExtenderClassLoadingHook();

@@ -110,7 +112,9 @@
 		configDir.mkdir();

 		File libDir = new File(new File("."), LIB_DIR);

 		libDir.mkdir();

-		File jpaIntegrationFile = new File(libDir, PERSISTENCE_INTEGRATION_JAR);

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR);

+		libPersistenceDir.mkdir();

+		File jpaIntegrationFile = new File(libPersistenceDir, PERSISTENCE_INTEGRATION_JAR);

 		jpaIntegrationFile.createNewFile();

 		String configurationFilePath = FILE_SCHEME + configDir.getAbsolutePath();

 		System.setProperty(CONFIG_AREA, configurationFilePath);

@@ -129,7 +133,8 @@
 		}

 		

 		File libDir = new File(new File("."), LIB_DIR);

-		File jpaIntegrationFile = new File(libDir, PERSISTENCE_INTEGRATION_JAR);

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR); 

+		File jpaIntegrationFile = new File(libPersistenceDir, PERSISTENCE_INTEGRATION_JAR);

 		

 		if (jpaIntegrationFile.exists()) {

 			jpaIntegrationFile.delete();

@@ -140,6 +145,10 @@
 			jpaIntegrationFile1.delete();

 		}

 		

+		if (libPersistenceDir.exists()) {

+			libPersistenceDir.delete();

+		}

+		

 		if (libDir.exists()) {

 			libDir.delete();

 		}

@@ -160,7 +169,8 @@
 	private boolean checkForFile(String filename) {

 		ArrayList<ClasspathEntry> cpEntries = new ArrayList<ClasspathEntry>();

 		File libDir = new File(new File("."), LIB_DIR);

-		String classpath = new File(libDir, filename).getAbsolutePath();

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR);

+		String classpath = new File(libPersistenceDir, filename).getAbsolutePath();

 		ClasspathEntry entry = new ClasspathEntry(new BundleFileStub(classpath), null);

 		cpEntries.add(entry);

 		AppLoaderClasspathExtenderClassLoadingHook hook = new AppLoaderClasspathExtenderClassLoadingHook();

@@ -245,16 +255,19 @@
 		configDir.mkdir();

 		File libDir = new File(new File("."), LIB_DIR);

 		libDir.mkdir();

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR);

+		libPersistenceDir.mkdir();

 		String configurationFilePath = FILE_SCHEME + configDir.getAbsolutePath();

 		System.setProperty(CONFIG_AREA, configurationFilePath);

-		checkForException("No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR_NAME + "] was found in lib folder");

+		checkForException("No file with name starting with [" + PERSISTENCE_INTEGRATION_JAR_NAME + "] was found in lib/persistence folder");

 	}

 	

 	@Test

 	public void testFindPersistenceIntegrationJarMultipleIntegrationJars() throws IOException {

 		File jpaIntegrationFile = prepare();

 		File libDir = new File(new File("."), LIB_DIR);

-		File jpaIntegrationFile1 = new File(libDir, PERSISTENCE_INTEGRATION_JAR1);

+		File libPersistenceDir = new File(libDir, PERSISTENCE_DIR);

+		File jpaIntegrationFile1 = new File(libPersistenceDir, PERSISTENCE_INTEGRATION_JAR1);

 		AppLoaderClasspathExtenderClassLoadingHook hook = new AppLoaderClasspathExtenderClassLoadingHook();

 		try {

 			hook.findPersistenceIntegrationJar();