From 13ba4271d6fcdbb5eee84b11e188baee7ec87391 Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Wed, 12 Aug 2015 10:59:48 -0700 Subject: [PATCH] Use JarLauncher for module launcher --- .../module/launcher}/ModuleJarLauncher.java | 30 +++++-------------- .../module/launcher/ModuleLauncher.java | 2 +- 2 files changed, 8 insertions(+), 24 deletions(-) rename spring-cloud-stream-module-launcher/src/main/java/org/springframework/{boot/loader => cloud/stream/module/launcher}/ModuleJarLauncher.java (68%) diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/boot/loader/ModuleJarLauncher.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleJarLauncher.java similarity index 68% rename from spring-cloud-stream-module-launcher/src/main/java/org/springframework/boot/loader/ModuleJarLauncher.java rename to spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleJarLauncher.java index 266831918..bd497aa4e 100644 --- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/boot/loader/ModuleJarLauncher.java +++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleJarLauncher.java @@ -14,49 +14,35 @@ * limitations under the License. */ -package org.springframework.boot.loader; +package org.springframework.cloud.stream.module.launcher; + import java.lang.reflect.Method; import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; +import org.springframework.boot.loader.JarLauncher; import org.springframework.boot.loader.archive.Archive; -import org.springframework.boot.loader.util.AsciiBytes; import org.springframework.cloud.stream.module.utils.ClassloaderUtils; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** - * A (possibly temporary) alternative to {@link JarLauncher} that provides a public - * {@link #launch(String[])} method. + * A {@link JarLauncher} that supports launching module archive. * * Also, it restricts the classloader of the launched application to the contents of the uber-jar and the * extension classloader of the JVM. * * @author Mark Fisher * @author Marius Bogoevici + * @author Ilayaperumal Gopinathan */ -public class ModuleJarLauncher extends ExecutableArchiveLauncher { - - private static final AsciiBytes LIB = new AsciiBytes("lib/"); +public class ModuleJarLauncher extends JarLauncher { public ModuleJarLauncher(Archive archive) { super(archive); } @Override - protected boolean isNestedArchive(Archive.Entry entry) { - return !entry.isDirectory() && entry.getName().startsWith(LIB); - } - - @Override - protected void postProcessClassPathArchives(List archives) throws Exception { - archives.add(0, getArchive()); - } - - @Override - // TODO: this method is protected in Spring Boot but we need it to be public here public void launch(String[] args) { super.launch(args); } @@ -70,9 +56,7 @@ public class ModuleJarLauncher extends ExecutableArchiveLauncher { // Ensure the method is invoked on a class that is loaded by the provided // class loader (not the current context class loader): Method method = ReflectionUtils - .findMethod( - classLoader - .loadClass("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory"), + .findMethod(classLoader.loadClass("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory"), "disable"); ReflectionUtils.invokeMethod(method, null); } diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java index 4361bb784..ff947a617 100644 --- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java +++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java @@ -29,7 +29,7 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.boot.loader.ModuleJarLauncher; + import org.springframework.boot.loader.archive.Archive; import org.springframework.boot.loader.archive.JarFileArchive; import org.springframework.cloud.stream.module.resolver.ModuleResolver;