You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2014/01/20 08:13:28 UTC
git commit: better to keep classloading simpler so merging
shared-libs and batchee libs and using a bootstrap jar
Updated Branches:
refs/heads/master 1b1049540 -> 1c32a216c
better to keep classloading simpler so merging shared-libs and batchee libs and using a bootstrap jar
Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/1c32a216
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/1c32a216
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/1c32a216
Branch: refs/heads/master
Commit: 1c32a216c188fceed43b22bd592057537a31bb16
Parents: 1b10495
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Jan 20 08:13:51 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Jan 20 08:13:51 2014 +0100
----------------------------------------------------------------------
tools/cli/pom.xml | 39 +++++++++++
tools/cli/src/main/assembly/bin.xml | 21 +++++-
.../apache/batchee/cli/bootstrap/Bootstrap.java | 68 ++++++++++++++++++++
.../classloader/ChildFirstURLClassLoader.java | 14 ++--
.../batchee/cli/command/JobOperatorCommand.java | 7 +-
tools/cli/src/main/resources/batchee | 19 ++----
6 files changed, 147 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/pom.xml
----------------------------------------------------------------------
diff --git a/tools/cli/pom.xml b/tools/cli/pom.xml
index 9651e05..6db24c6 100644
--- a/tools/cli/pom.xml
+++ b/tools/cli/pom.xml
@@ -119,6 +119,45 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <id>boostrap-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/bootstrap/*</include>
+ <include>**/classloader/*</include>
+ </includes>
+ <classifier>bootstrap</classifier>
+ </configuration>
+ </execution>
+ <execution>
+ <id>runner-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>**/bootstrap/*</exclude>
+ <exclude>**/classloader/*</exclude>
+ </excludes>
+ <classifier>runner</classifier>
+ </configuration>
+ </execution>
+ <execution>
+ <id>normal-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/assembly/bin.xml b/tools/cli/src/main/assembly/bin.xml
index 2b6c3fc..c451983 100644
--- a/tools/cli/src/main/assembly/bin.xml
+++ b/tools/cli/src/main/assembly/bin.xml
@@ -24,7 +24,7 @@
</formats>
<fileSets>
<fileSet>
- <directory>${project.basedir}/target/classes</directory>
+ <directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>LICENSE</include>
@@ -32,7 +32,7 @@
</includes>
</fileSet>
<fileSet>
- <directory>${project.basedir}/target/classes</directory>
+ <directory>${project.build.outputDirectory}</directory>
<outputDirectory>bin/</outputDirectory>
<includes>
<include>batchee</include>
@@ -40,12 +40,29 @@
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
</fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/</directory>
+ <outputDirectory>bin/</outputDirectory>
+ <includes>
+ <include>batchee-cli-*-bootstrap.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>${project.build.directory}/</directory>
+ <outputDirectory>lib/</outputDirectory>
+ <includes>
+ <include>batchee-cli-*-runner.jar</include>
+ </includes>
+ </fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
+ <excludes>
+ <exclude>org.apache.batchee:batchee-cli</exclude> <!-- we use bootstrap and runner -->
+ </excludes>
</dependencySet>
</dependencySets>
</assembly>
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/src/main/java/org/apache/batchee/cli/bootstrap/Bootstrap.java
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/java/org/apache/batchee/cli/bootstrap/Bootstrap.java b/tools/cli/src/main/java/org/apache/batchee/cli/bootstrap/Bootstrap.java
new file mode 100644
index 0000000..bcb680e
--- /dev/null
+++ b/tools/cli/src/main/java/org/apache/batchee/cli/bootstrap/Bootstrap.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.batchee.cli.bootstrap;
+
+import org.apache.batchee.cli.classloader.ChildFirstURLClassLoader;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collection;
+
+// Note: don't depend from any other classes excepted classloader
+public class Bootstrap {
+ public static void main(final String[] args) throws Exception {
+ final String batcheeHome = System.getProperty("batchee.home");
+ if (batcheeHome == null) {
+ throw new IllegalArgumentException("batchee.home system property not set");
+ }
+
+ final File home = new File(batcheeHome);
+ if (!home.isDirectory()) {
+ throw new IllegalArgumentException("batchee.home doesn't exist '" + batcheeHome + "'");
+ }
+
+ final File libsDir = new File(batcheeHome, "lib");
+ if (!libsDir.isDirectory()) {
+ throw new IllegalArgumentException("lib directory doesn't exist '" + libsDir.getAbsolutePath() + "'");
+ }
+
+ // don't use a filter here to keep jar/assembly easy to do in pom.xml
+ final File[] libs = libsDir.listFiles();
+ if (libs == null) {
+ throw new IllegalArgumentException("no lib found");
+ }
+
+ final Collection<URL> urls = new ArrayList<URL>(libs.length);
+ for (final File f : libs) {
+ if (f.getName().endsWith(".jar")) {
+ urls.add(f.toURI().toURL());
+ }
+ }
+
+ final URLClassLoader loader = new ChildFirstURLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
+
+ Thread.currentThread().setContextClassLoader(loader);
+ final Class<?> cli = loader.loadClass("org.apache.batchee.cli.BatchEECLI");
+ cli.getMethod("main", String[].class).invoke(null, new Object[] { args });
+ }
+
+ private Bootstrap() {
+ // no-op
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/src/main/java/org/apache/batchee/cli/classloader/ChildFirstURLClassLoader.java
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/java/org/apache/batchee/cli/classloader/ChildFirstURLClassLoader.java b/tools/cli/src/main/java/org/apache/batchee/cli/classloader/ChildFirstURLClassLoader.java
index f92a740..61b123d 100644
--- a/tools/cli/src/main/java/org/apache/batchee/cli/classloader/ChildFirstURLClassLoader.java
+++ b/tools/cli/src/main/java/org/apache/batchee/cli/classloader/ChildFirstURLClassLoader.java
@@ -16,13 +16,8 @@
*/
package org.apache.batchee.cli.classloader;
-import org.apache.commons.io.IOUtils;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -32,6 +27,7 @@ import java.util.Enumeration;
import java.util.LinkedList;
import java.util.concurrent.CopyOnWriteArrayList;
+// Note: don't depend from any other classes
public class ChildFirstURLClassLoader extends URLClassLoader {
private final ClassLoader system;
private final Collection<File> resources = new CopyOnWriteArrayList<File>();
@@ -112,6 +108,7 @@ public class ChildFirstURLClassLoader extends URLClassLoader {
return clazz;
}
+ /* needed if classloader hierarchy is batchee* <- cdi container <- app
// lifecycle classes and cdi extensions need to be loaded from "container/lifecyle" loader
if ((name.endsWith("Lifecycle") && name.startsWith("org.apache.batchee.cli.lifecycle.impl."))
|| name.startsWith("org.apache.batchee.container.cdi.")
@@ -147,6 +144,7 @@ public class ChildFirstURLClassLoader extends URLClassLoader {
return super.loadClass(name, resolve);
}
}
+ */
// JSE classes
try {
@@ -216,4 +214,10 @@ public class ChildFirstURLClassLoader extends URLClassLoader {
public File getApplicationFolder() {
return applicationFolder;
}
+
+ public void addUrls(final Collection<URL> urls) {
+ for (final URL url : urls) {
+ addURL(url);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/src/main/java/org/apache/batchee/cli/command/JobOperatorCommand.java
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/java/org/apache/batchee/cli/command/JobOperatorCommand.java b/tools/cli/src/main/java/org/apache/batchee/cli/command/JobOperatorCommand.java
index 0c21eab..c0037d8 100644
--- a/tools/cli/src/main/java/org/apache/batchee/cli/command/JobOperatorCommand.java
+++ b/tools/cli/src/main/java/org/apache/batchee/cli/command/JobOperatorCommand.java
@@ -289,7 +289,12 @@ public abstract class JobOperatorCommand implements Runnable {
final Collection<URL> sharedUrls = new LinkedList<URL>();
final File folder = new File(sharedLibs);
addJars(folder, sharedUrls);
- usedParent = new ChildFirstURLClassLoader(sharedUrls.toArray(new URL[sharedUrls.size()]), parent);
+ if (ChildFirstURLClassLoader.class.isInstance(parent)) { // merge it
+ ChildFirstURLClassLoader.class.cast(parent).addUrls(sharedUrls);
+ usedParent = parent;
+ } else {
+ usedParent = new ChildFirstURLClassLoader(sharedUrls.toArray(new URL[sharedUrls.size()]), parent);
+ }
} else {
usedParent = parent;
}
http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/1c32a216/tools/cli/src/main/resources/batchee
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/resources/batchee b/tools/cli/src/main/resources/batchee
index b247294..463e657 100644
--- a/tools/cli/src/main/resources/batchee
+++ b/tools/cli/src/main/resources/batchee
@@ -52,23 +52,16 @@ if [ -z "$BATCHEE_HOME" -o ! -d "$BATCHEE_HOME" ] ; then
BATCHEE_HOME=`cd "$BATCHEE_HOME" && pwd`
fi
-sep=":"
+bin="$BATCHEE_HOME/bin/batchee-cli-${project.version}-bootstrap.jar"
if $cygwin; then
- sep=";"
+ bin=$(cygpath -wp "$bin")
fi
-libs="$BATCHEE_HOME/lib"
+home="$BATCHEE_HOME"
if $cygwin; then
- libs=$(cygpath -wp "$libs")
+ home=$(cygpath -wp "$home")
fi
-for i in $BATCHEE_HOME/lib/*.jar; do
- value="$i"
- if $cygwin; then
- # wp to convert to windows path, suppose java is installed on windows and not cygwin!
- value=$(cygpath -wp "$value")
- fi
- libs="$libs$sep$value"
-done
+BATCHEE_OPTS="$BATCHEE_OPTS -Dbatchee.home=$home"
args="$@"
if [ "$1" = "debug" ]; then
@@ -84,4 +77,4 @@ if [ -f "$logging" ] ; then
BATCHEE_OPTS="$BATCHEE_OPTS -Djava.util.logging.config.file=$logging"
fi
-java $BATCHEE_OPTS -cp "$libs" org.apache.batchee.cli.BatchEECLI $@
+java $BATCHEE_OPTS -cp "$bin" org.apache.batchee.cli.bootstrap.Bootstrap $@