1616
1717package org .springframework .experimental .boot .server .exec ;
1818
19+ import java .io .FileNotFoundException ;
1920import java .io .IOException ;
2021import java .nio .file .Files ;
2122import java .nio .file .Path ;
2223import java .util .Arrays ;
24+ import java .util .Collections ;
2325import java .util .List ;
2426import java .util .function .Function ;
2527import java .util .regex .Pattern ;
@@ -46,6 +48,8 @@ class ScanningClasspathEntry implements ClasspathEntry {
4648
4749 private final Function <String , String > renameResource ;
4850
51+ private Resource [] resources ;
52+
4953 private Path classpath ;
5054
5155 ScanningClasspathEntry (String baseDir ) {
@@ -69,17 +73,23 @@ Path getClasspath() {
6973
7074 @ Override
7175 public List <String > resolve () {
72- if (this .classpath == null ) {
73- this .classpath = createClasspath ();
76+ if (this .resources == null ) {
77+ this .resources = getResources ();
78+ this .classpath = createClasspath (this .resources );
7479 }
75- return Arrays .asList (this .classpath .toFile ().getAbsolutePath ());
80+ return this .classpath == null ? Collections .emptyList ()
81+ : Arrays .asList (this .classpath .toFile ().getAbsolutePath ());
7682 }
7783
78- private Path createClasspath () {
79- PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver ();
84+ private Path createClasspath (Resource [] resources ) {
85+ if (this .resources == null || this .resources .length == 0 ) {
86+ return null ;
87+ }
8088 try {
8189 Path classpath = TempDir .tempDir ();
82- Resource [] resources = resolver .getResources (this .resourcePattern );
90+ if (this .logger .isDebugEnabled ()) {
91+ this .logger .debug ("Found " + resources .length + " resources for pattern " + this .resourcePattern );
92+ }
8393 for (Resource resource : resources ) {
8494 String path = this .renameResource .apply (getPath (resource ));
8595 if (!path .endsWith ("/" ) && resource .isReadable ()) {
@@ -98,6 +108,19 @@ private Path createClasspath() {
98108 }
99109 }
100110
111+ private Resource [] getResources () {
112+ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver ();
113+ try {
114+ return resolver .getResources (this .resourcePattern );
115+ }
116+ catch (FileNotFoundException ex ) {
117+ return new Resource [0 ];
118+ }
119+ catch (IOException ex ) {
120+ throw new RuntimeException ("Failed to resolve " + this .resourcePattern , ex );
121+ }
122+ }
123+
101124 private String getPath (Resource resource ) {
102125 if (resource instanceof ClassPathResource classPathResource ) {
103126 return classPathResource .getPath ();
@@ -111,7 +134,9 @@ private String getPath(Resource resource) {
111134 @ Override
112135 public void cleanup () {
113136 try {
114- FileSystemUtils .deleteRecursively (this .classpath );
137+ if (this .classpath != null ) {
138+ FileSystemUtils .deleteRecursively (this .classpath );
139+ }
115140 }
116141 catch (IOException ex ) {
117142 throw new RuntimeException (ex );
0 commit comments