51
51
import org .springframework .core .io .DefaultResourceLoader ;
52
52
import org .springframework .core .io .FileSystemResource ;
53
53
import org .springframework .core .io .Resource ;
54
+ import org .springframework .core .io .UrlResource ;
54
55
import org .springframework .util .ClassUtils ;
55
56
import org .springframework .util .FileSystemUtils ;
57
+ import org .springframework .util .ResourceUtils ;
56
58
import org .springframework .util .StreamUtils ;
57
59
import org .springframework .util .StringUtils ;
58
60
@@ -133,6 +135,7 @@ void encodedHashtagInPath() throws IOException {
133
135
assertExactFilenames ("classpath*:scanned/*.txt" , "resource#test1.txt" , "resource#test2.txt" );
134
136
}
135
137
138
+
136
139
@ Nested
137
140
class WithHashtagsInTheirFilenames {
138
141
@@ -299,6 +302,7 @@ void rootPatternRetrievalInJarFiles() throws IOException {
299
302
}
300
303
}
301
304
305
+
302
306
@ Nested
303
307
class ClassPathManifestEntries {
304
308
@@ -313,8 +317,8 @@ void javaDashJarFindsClassPathManifestEntries() throws Exception {
313
317
writeApplicationJar (this .temp .resolve ("app.jar" ));
314
318
String java = ProcessHandle .current ().info ().command ().get ();
315
319
Process process = new ProcessBuilder (java , "-jar" , "app.jar" )
316
- .directory (this .temp .toFile ())
317
- .start ();
320
+ .directory (this .temp .toFile ())
321
+ .start ();
318
322
assertThat (process .waitFor ()).isZero ();
319
323
String result = StreamUtils .copyToString (process .getInputStream (), StandardCharsets .UTF_8 );
320
324
assertThat (result .replace ("\\ " , "/" )).contains ("!!!!" ).contains ("/lib/asset.jar!/assets/file.txt" );
@@ -328,6 +332,8 @@ private void writeAssetJar(Path path) throws Exception {
328
332
StreamUtils .copy ("test" , StandardCharsets .UTF_8 , jar );
329
333
jar .closeEntry ();
330
334
}
335
+ assertThat (new FileSystemResource (path ).exists ()).isTrue ();
336
+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
331
337
}
332
338
333
339
private void writeApplicationJar (Path path ) throws Exception {
@@ -338,8 +344,7 @@ private void writeApplicationJar(Path path) throws Exception {
338
344
mainAttributes .put (Name .MANIFEST_VERSION , "1.0" );
339
345
try (JarOutputStream jar = new JarOutputStream (new FileOutputStream (path .toFile ()), manifest )) {
340
346
String appClassResource = ClassUtils .convertClassNameToResourcePath (
341
- ClassPathManifestEntriesTestApplication .class .getName ())
342
- + ClassUtils .CLASS_FILE_SUFFIX ;
347
+ ClassPathManifestEntriesTestApplication .class .getName ()) + ClassUtils .CLASS_FILE_SUFFIX ;
343
348
String folder = "" ;
344
349
for (String name : appClassResource .split ("/" )) {
345
350
if (!name .endsWith (ClassUtils .CLASS_FILE_SUFFIX )) {
@@ -356,18 +361,19 @@ private void writeApplicationJar(Path path) throws Exception {
356
361
}
357
362
}
358
363
}
364
+ assertThat (new FileSystemResource (path ).exists ()).isTrue ();
365
+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
359
366
}
360
367
361
368
private String buildSpringClassPath () throws Exception {
362
- return copyClasses (PathMatchingResourcePatternResolver .class , "spring-core" )
363
- + copyClasses (LogFactory .class , "commons-logging" );
369
+ return copyClasses (PathMatchingResourcePatternResolver .class , "spring-core" ) +
370
+ copyClasses (LogFactory .class , "commons-logging" );
364
371
}
365
372
366
- private String copyClasses (Class <?> sourceClass , String destinationName )
367
- throws URISyntaxException , IOException {
373
+ private String copyClasses (Class <?> sourceClass , String destinationName ) throws URISyntaxException , IOException {
368
374
Path destination = this .temp .resolve (destinationName );
369
- String resourcePath = ClassUtils .convertClassNameToResourcePath (sourceClass . getName ())
370
- + ClassUtils .CLASS_FILE_SUFFIX ;
375
+ String resourcePath = ClassUtils .convertClassNameToResourcePath (
376
+ sourceClass . getName ()) + ClassUtils .CLASS_FILE_SUFFIX ;
371
377
URL resource = getClass ().getClassLoader ().getResource (resourcePath );
372
378
URL url = new URL (resource .toString ().replace (resourcePath , "" ));
373
379
URLConnection connection = url .openConnection ();
@@ -393,7 +399,6 @@ private String copyClasses(Class<?> sourceClass, String destinationName)
393
399
}
394
400
return destinationName + "/ " ;
395
401
}
396
-
397
402
}
398
403
399
404
0 commit comments