5151import org .springframework .core .io .DefaultResourceLoader ;
5252import org .springframework .core .io .FileSystemResource ;
5353import org .springframework .core .io .Resource ;
54+ import org .springframework .core .io .UrlResource ;
5455import org .springframework .util .ClassUtils ;
5556import org .springframework .util .FileSystemUtils ;
57+ import org .springframework .util .ResourceUtils ;
5658import org .springframework .util .StreamUtils ;
5759import org .springframework .util .StringUtils ;
5860
@@ -133,6 +135,7 @@ void encodedHashtagInPath() throws IOException {
133135 assertExactFilenames ("classpath*:scanned/*.txt" , "resource#test1.txt" , "resource#test2.txt" );
134136 }
135137
138+
136139 @ Nested
137140 class WithHashtagsInTheirFilenames {
138141
@@ -299,6 +302,7 @@ void rootPatternRetrievalInJarFiles() throws IOException {
299302 }
300303 }
301304
305+
302306 @ Nested
303307 class ClassPathManifestEntries {
304308
@@ -313,8 +317,8 @@ void javaDashJarFindsClassPathManifestEntries() throws Exception {
313317 writeApplicationJar (this .temp .resolve ("app.jar" ));
314318 String java = ProcessHandle .current ().info ().command ().get ();
315319 Process process = new ProcessBuilder (java , "-jar" , "app.jar" )
316- .directory (this .temp .toFile ())
317- .start ();
320+ .directory (this .temp .toFile ())
321+ .start ();
318322 assertThat (process .waitFor ()).isZero ();
319323 String result = StreamUtils .copyToString (process .getInputStream (), StandardCharsets .UTF_8 );
320324 assertThat (result .replace ("\\ " , "/" )).contains ("!!!!" ).contains ("/lib/asset.jar!/assets/file.txt" );
@@ -328,6 +332,8 @@ private void writeAssetJar(Path path) throws Exception {
328332 StreamUtils .copy ("test" , StandardCharsets .UTF_8 , jar );
329333 jar .closeEntry ();
330334 }
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 ();
331337 }
332338
333339 private void writeApplicationJar (Path path ) throws Exception {
@@ -338,8 +344,7 @@ private void writeApplicationJar(Path path) throws Exception {
338344 mainAttributes .put (Name .MANIFEST_VERSION , "1.0" );
339345 try (JarOutputStream jar = new JarOutputStream (new FileOutputStream (path .toFile ()), manifest )) {
340346 String appClassResource = ClassUtils .convertClassNameToResourcePath (
341- ClassPathManifestEntriesTestApplication .class .getName ())
342- + ClassUtils .CLASS_FILE_SUFFIX ;
347+ ClassPathManifestEntriesTestApplication .class .getName ()) + ClassUtils .CLASS_FILE_SUFFIX ;
343348 String folder = "" ;
344349 for (String name : appClassResource .split ("/" )) {
345350 if (!name .endsWith (ClassUtils .CLASS_FILE_SUFFIX )) {
@@ -356,18 +361,19 @@ private void writeApplicationJar(Path path) throws Exception {
356361 }
357362 }
358363 }
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 ();
359366 }
360367
361368 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" );
364371 }
365372
366- private String copyClasses (Class <?> sourceClass , String destinationName )
367- throws URISyntaxException , IOException {
373+ private String copyClasses (Class <?> sourceClass , String destinationName ) throws URISyntaxException , IOException {
368374 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 ;
371377 URL resource = getClass ().getClassLoader ().getResource (resourcePath );
372378 URL url = new URL (resource .toString ().replace (resourcePath , "" ));
373379 URLConnection connection = url .openConnection ();
@@ -393,7 +399,6 @@ private String copyClasses(Class<?> sourceClass, String destinationName)
393399 }
394400 return destinationName + "/ " ;
395401 }
396-
397402 }
398403
399404
0 commit comments