From 9eb8e3d4e38892d7fd9edfc0eef7d2f9fc9ca7ff Mon Sep 17 00:00:00 2001 From: hanyong Date: Thu, 23 Nov 2017 11:37:00 +0800 Subject: [PATCH 1/2] Support nested jar paths in loader.path See gh-11121 --- .../springframework/boot/loader/PropertiesLauncher.java | 4 ++++ .../boot/loader/PropertiesLauncherTests.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index 200b418634..b1eb6b2947 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -483,6 +483,10 @@ public class PropertiesLauncher extends Launcher { } private Archive getArchive(File file) throws IOException { + // Nested path never exists as plain jar file, which should be ignored here. + if (file.getPath().contains("!")) { + return null; + } String name = file.getName().toLowerCase(); if (name.endsWith(".jar") || name.endsWith(".zip")) { return new JarFileArchive(file); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index ce816b9258..9de725c7b4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -213,6 +213,15 @@ public class PropertiesLauncherTests { assertThat(archives).areExactly(1, endingWith("app.jar!/")); } + @Test + public void testUserSpecifiedNestedJarPath() throws Exception { + System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar"); + System.setProperty("loader.main", "demo.Application"); + PropertiesLauncher launcher = new PropertiesLauncher(); + List archives = launcher.getClassPathArchives(); + assertThat(archives).hasSize(1).areExactly(1, endingWith("foo.jar!/")); + } + @Test public void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives() throws Exception { From 76ed52c2f5393964068d5ec8d3c519626512ce64 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 5 Feb 2018 16:01:14 +0000 Subject: [PATCH 2/2] Polish "Support nested jar paths in loader.path" Closes gh-11121 --- .../boot/loader/PropertiesLauncher.java | 10 ++++++++-- .../boot/loader/PropertiesLauncherTests.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index b1eb6b2947..00f7a50a7c 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -121,6 +121,8 @@ public class PropertiesLauncher extends Launcher { private static final Pattern WORD_SEPARATOR = Pattern.compile("\\W+"); + private static final String NESTED_ARCHIVE_SEPARATOR = "!" + File.separator; + private final File home; private List paths = new ArrayList<>(); @@ -452,6 +454,7 @@ public class PropertiesLauncher extends Launcher { private List getClassPathArchives(String path) throws Exception { String root = cleanupPath(stripFileUrlPrefix(path)); + System.out.println(root); List lib = new ArrayList<>(); File file = new File(root); if (!"/".equals(root)) { @@ -483,8 +486,7 @@ public class PropertiesLauncher extends Launcher { } private Archive getArchive(File file) throws IOException { - // Nested path never exists as plain jar file, which should be ignored here. - if (file.getPath().contains("!")) { + if (isNestedArchivePath(file)) { return null; } String name = file.getName().toLowerCase(); @@ -494,6 +496,10 @@ public class PropertiesLauncher extends Launcher { return null; } + private boolean isNestedArchivePath(File file) { + return file.getPath().contains(NESTED_ARCHIVE_SEPARATOR); + } + private List getNestedArchives(String path) throws Exception { Archive parent = this.parent; String root = path; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java index 9de725c7b4..0cdfa14540 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/PropertiesLauncherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.