21
21
import java .io .IOException ;
22
22
import java .io .InputStream ;
23
23
import java .net .HttpURLConnection ;
24
+ import java .net .MalformedURLException ;
24
25
import java .net .URISyntaxException ;
25
26
import java .net .URL ;
26
27
import java .net .URLClassLoader ;
27
28
import java .net .URLConnection ;
28
29
import java .net .URLDecoder ;
29
30
import java .util .ArrayList ;
30
- import java .util .Arrays ;
31
31
import java .util .Collections ;
32
+ import java .util .Iterator ;
32
33
import java .util .List ;
33
34
import java .util .Properties ;
34
35
import java .util .jar .Manifest ;
39
40
import org .springframework .boot .loader .archive .Archive .Entry ;
40
41
import org .springframework .boot .loader .archive .Archive .EntryFilter ;
41
42
import org .springframework .boot .loader .archive .ExplodedArchive ;
42
- import org .springframework .boot .loader .archive .FilteredArchive ;
43
43
import org .springframework .boot .loader .archive .JarFileArchive ;
44
- import org .springframework .boot .loader .util .AsciiBytes ;
45
44
import org .springframework .boot .loader .util .SystemPropertyUtils ;
46
45
47
46
/**
@@ -122,8 +121,6 @@ public class PropertiesLauncher extends Launcher {
122
121
*/
123
122
public static final String SET_SYSTEM_PROPERTIES = "loader.system" ;
124
123
125
- private static final List <String > DEFAULT_PATHS = Arrays .asList ();
126
-
127
124
private static final Pattern WORD_SEPARATOR = Pattern .compile ("\\ W+" );
128
125
129
126
private static final URL [] EMPTY_URLS = {};
@@ -132,7 +129,7 @@ public class PropertiesLauncher extends Launcher {
132
129
133
130
private final JavaAgentDetector javaAgentDetector ;
134
131
135
- private List <String > paths = new ArrayList <String >(DEFAULT_PATHS );
132
+ private List <String > paths = new ArrayList <String >();
136
133
137
134
private final Properties properties = new Properties ();
138
135
@@ -168,7 +165,6 @@ private void initializeProperties(File home) throws Exception, IOException {
168
165
config = SystemPropertyUtils .resolvePlaceholders (
169
166
SystemPropertyUtils .getProperty (CONFIG_LOCATION , config ));
170
167
InputStream resource = getResource (config );
171
-
172
168
if (resource != null ) {
173
169
log ("Found: " + config );
174
170
try {
@@ -353,7 +349,6 @@ protected ClassLoader createClassLoader(List<Archive> archives) throws Exception
353
349
@ SuppressWarnings ("unchecked" )
354
350
private ClassLoader wrapWithCustomClassLoader (ClassLoader parent ,
355
351
String loaderClassName ) throws Exception {
356
-
357
352
Class <ClassLoader > loaderClass = (Class <ClassLoader >) Class
358
353
.forName (loaderClassName , true , parent );
359
354
@@ -363,15 +358,13 @@ private ClassLoader wrapWithCustomClassLoader(ClassLoader parent,
363
358
catch (NoSuchMethodException ex ) {
364
359
// Ignore and try with URLs
365
360
}
366
-
367
361
try {
368
362
return loaderClass .getConstructor (URL [].class , ClassLoader .class )
369
363
.newInstance (new URL [0 ], parent );
370
364
}
371
365
catch (NoSuchMethodException ex ) {
372
366
// Ignore and try without any arguments
373
367
}
374
-
375
368
return loaderClass .newInstance ();
376
369
}
377
370
@@ -384,21 +377,18 @@ private String getProperty(String propertyKey, String manifestKey) throws Except
384
377
manifestKey = propertyKey .replace ("." , "-" );
385
378
manifestKey = toCamelCase (manifestKey );
386
379
}
387
-
388
380
String property = SystemPropertyUtils .getProperty (propertyKey );
389
381
if (property != null ) {
390
382
String value = SystemPropertyUtils .resolvePlaceholders (property );
391
383
log ("Property '" + propertyKey + "' from environment: " + value );
392
384
return value ;
393
385
}
394
-
395
386
if (this .properties .containsKey (propertyKey )) {
396
387
String value = SystemPropertyUtils
397
388
.resolvePlaceholders (this .properties .getProperty (propertyKey ));
398
389
log ("Property '" + propertyKey + "' from properties: " + value );
399
390
return value ;
400
391
}
401
-
402
392
try {
403
393
// Prefer home dir for MANIFEST if there is one
404
394
Manifest manifest = new ExplodedArchive (this .home , false ).getManifest ();
@@ -412,7 +402,6 @@ private String getProperty(String propertyKey, String manifestKey) throws Except
412
402
catch (IllegalStateException ex ) {
413
403
// Ignore
414
404
}
415
-
416
405
// Otherwise try the parent archive
417
406
Manifest manifest = createArchive ().getManifest ();
418
407
if (manifest != null ) {
@@ -478,7 +467,7 @@ private Archive getArchive(File file) throws IOException {
478
467
return null ;
479
468
}
480
469
481
- private Archive getNestedArchive (final String root ) throws Exception {
470
+ private Archive getNestedArchive (String root ) throws Exception {
482
471
if (root .startsWith ("/" )
483
472
|| this .parent .getUrl ().equals (this .home .toURI ().toURL ())) {
484
473
// If home dir is same as parent archive, no need to add it twice.
@@ -628,40 +617,84 @@ private void log(String message) {
628
617
}
629
618
}
630
619
620
+ /**
621
+ * Convenience class for finding nested archives that have a prefix in their file path
622
+ * (e.g. "lib/").
623
+ */
624
+ private static final class PrefixMatchingArchiveFilter implements EntryFilter {
625
+
626
+ private final String prefix ;
627
+
628
+ private final ArchiveEntryFilter filter = new ArchiveEntryFilter ();
629
+
630
+ private PrefixMatchingArchiveFilter (String prefix ) {
631
+ this .prefix = prefix ;
632
+ }
633
+
634
+ @ Override
635
+ public boolean matches (Entry entry ) {
636
+ return entry .getName ().startsWith (this .prefix ) && this .filter .matches (entry );
637
+ }
638
+
639
+ }
640
+
631
641
/**
632
642
* Convenience class for finding nested archives (archive entries that can be
633
643
* classpath entries).
634
644
*/
635
645
private static final class ArchiveEntryFilter implements EntryFilter {
636
646
637
- private static final AsciiBytes DOT_JAR = new AsciiBytes ( ".jar" ) ;
647
+ private static final String DOT_JAR = ".jar" ;
638
648
639
- private static final AsciiBytes DOT_ZIP = new AsciiBytes ( ".zip" ) ;
649
+ private static final String DOT_ZIP = ".zip" ;
640
650
641
651
@ Override
642
652
public boolean matches (Entry entry ) {
643
653
return entry .getName ().endsWith (DOT_JAR ) || entry .getName ().endsWith (DOT_ZIP );
644
654
}
655
+
645
656
}
646
657
647
658
/**
648
- * Convenience class for finding nested archives that have a prefix in their file path
649
- * (e.g. "lib/").
659
+ * Decorator to apply an {@link Archive.EntryFilter} to an existing {@link Archive}.
650
660
*/
651
- private static final class PrefixMatchingArchiveFilter implements EntryFilter {
661
+ private static class FilteredArchive implements Archive {
652
662
653
- private final AsciiBytes prefix ;
663
+ private final Archive parent ;
654
664
655
- private final ArchiveEntryFilter filter = new ArchiveEntryFilter () ;
665
+ private final EntryFilter filter ;
656
666
657
- private PrefixMatchingArchiveFilter (String prefix ) {
658
- this .prefix = new AsciiBytes (prefix );
667
+ FilteredArchive (Archive parent , EntryFilter filter ) {
668
+ this .parent = parent ;
669
+ this .filter = filter ;
659
670
}
660
671
661
672
@ Override
662
- public boolean matches (Entry entry ) {
663
- return entry .getName ().startsWith (this .prefix ) && this .filter .matches (entry );
673
+ public URL getUrl () throws MalformedURLException {
674
+ return this .parent .getUrl ();
675
+ }
676
+
677
+ @ Override
678
+ public Manifest getManifest () throws IOException {
679
+ return this .parent .getManifest ();
680
+ }
681
+
682
+ @ Override
683
+ public Iterator <Entry > iterator () {
684
+ throw new UnsupportedOperationException ();
685
+ }
686
+
687
+ @ Override
688
+ public List <Archive > getNestedArchives (final EntryFilter filter )
689
+ throws IOException {
690
+ return this .parent .getNestedArchives (new EntryFilter () {
691
+ @ Override
692
+ public boolean matches (Entry entry ) {
693
+ return FilteredArchive .this .filter .matches (entry )
694
+ && filter .matches (entry );
695
+ }
696
+ });
664
697
}
665
- }
666
698
699
+ }
667
700
}
0 commit comments