You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/02/09 13:24:24 UTC
svn commit: r1242295 - in /openejb/trunk/openejb:
container/openejb-loader/src/main/java/org/apache/openejb/loader/
tomee/tomee-loader/src/main/java/org/apache/tomee/loader/
Author: rmannibucau
Date: Thu Feb 9 12:24:24 2012
New Revision: 1242295
URL: http://svn.apache.org/viewvc?rev=1242295&view=rev
Log:
OPENEJB-1770 ability to put provisionned server libs where you want
Modified:
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Embedder.java
openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java
openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java
Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Embedder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Embedder.java?rev=1242295&r1=1242294&r2=1242295&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Embedder.java (original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Embedder.java Thu Feb 9 12:24:24 2012
@@ -26,6 +26,8 @@ import java.util.Properties;
* @version $Revision$ $Date$
*/
public class Embedder {
+ public static final String ADDITIONAL_LIB_FOLDER = System.getProperty("openejb.additional.lib.folder", "additionallib");
+
/**
* Represents the name of the class which implements org.apache.openejb.loader.Loader
*/
@@ -102,6 +104,16 @@ public class Embedder {
} catch (Exception e2) {
throw new Exception("Could not load OpenEJB libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
}
+
+ try {
+ final File additionalLib = SystemInstance.get().getBase().getDirectory(ADDITIONAL_LIB_FOLDER);
+ if (additionalLib.exists()){
+ classPath.addJarsToPath(additionalLib);
+ }
+ } catch (Exception e2) {
+ throw new Exception("Could not load OpenEJB libraries. Exception: " + e2.getClass().getName() + " " + e2.getMessage());
+ }
+
try {
return classLoader.loadClass(className);
} catch (Exception e2) {
Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java?rev=1242295&r1=1242294&r2=1242295&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java (original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java Thu Feb 9 12:24:24 2012
@@ -164,6 +164,15 @@ public class IO {
}
}
+ public static void copy(final File from, final File to) throws IOException {
+ final FileOutputStream fos = new FileOutputStream(to);
+ try {
+ copy(from, fos);
+ } finally {
+ close(fos);
+ }
+ }
+
public static void copy(File from, OutputStream to) throws IOException {
final InputStream read = read(from);
try {
@@ -193,7 +202,7 @@ public class IO {
public static void copy(InputStream from, OutputStream to) throws IOException {
byte[] buffer = new byte[1024];
- int length = 0;
+ int length;
while ((length = from.read(buffer)) != -1) {
to.write(buffer, 0, length);
}
Modified: openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java?rev=1242295&r1=1242294&r2=1242295&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java (original)
+++ openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHook.java Thu Feb 9 12:24:24 2012
@@ -18,6 +18,7 @@
package org.apache.tomee.loader;
import org.apache.openejb.loader.Embedder;
+import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.SystemInstance;
import java.io.File;
@@ -27,7 +28,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.zip.ZipEntry;
@@ -69,6 +69,7 @@ import static org.apache.openejb.loader.
class TomcatHook {
static final String ADDITIONAL_LIB_CONFIG = "provisioning.properties";
static final String ZIP_KEY = "zip";
+ static final String DESTINATION_KEY = "destination";
static final String JAR_KEY = "jar";
public static final String TEMP_DIR = "temp";
@@ -168,7 +169,7 @@ class TomcatHook {
// manage additional libraries
try {
- addAdditionalLibraries(SystemInstance.get().getBase().getDirectory("conf"), libDir);
+ addAdditionalLibraries(SystemInstance.get().getBase().getDirectory("conf"), new File(SystemInstance.get().getBase().getDirectory(), ADDITIONAL_LIB_CONFIG));
} catch (IOException e) {
// ignored
}
@@ -215,8 +216,18 @@ class TomcatHook {
}
}
+ File destination;
+ if (additionalLibProperties.containsKey(DESTINATION_KEY)) {
+ destination = new File(additionalLibProperties.getProperty(DESTINATION_KEY));
+ } else {
+ destination = new File(SystemInstance.get().getBase().getDirectory(), Embedder.ADDITIONAL_LIB_FOLDER);
+ }
+ if (!destination.exists()) {
+ destination = libDir;
+ }
+
for (String lib : libToCopy) {
- copy(new File(lib), libDir);
+ copy(new File(lib), destination);
}
}
@@ -225,35 +236,7 @@ class TomcatHook {
if (dest.exists()) {
return;
}
-
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try {
- fis = new FileInputStream(file);
- fos = new FileOutputStream(dest);
- byte[] buffer = new byte[1024];
- int length;
- while ((length = fis.read(buffer)) != -1) {
- fos.write(buffer, 0, length);
- }
- fos.flush();
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- // ignored
- }
- }
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException e) {
- // ignored
- }
- }
- }
-
+ IO.copy(file, dest);
}
private static Collection<String> extract(final String zip) throws IOException {
@@ -265,7 +248,7 @@ class TomcatHook {
final File zipFile = new File(realLocation(zip));
final File extracted = new File(tmp, zipFile.getName().replace(".zip", ""));
if (extracted.exists()) {
- return Collections.emptyList();
+ return list(extracted);
}
unzip(zipFile, extracted);