-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #805 from jwachter/fix/nested-with-space-and-hash-…
…path Handle paths with spaces and hashes especially with nested JARs
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/io/github/classgraph/issues/issue804/Issue804Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.github.classgraph.issues.issue804; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import io.github.classgraph.ClassGraph; | ||
import io.github.classgraph.ScanResult; | ||
|
||
/** | ||
* Issue 804. | ||
*/ | ||
public class Issue804Test { | ||
|
||
private static final String NESTED_EXAMPLE_CLASS = "org.springframework.util.ResourceUtils"; | ||
|
||
@Test | ||
void scanningNestedJarsInPathsContainingSpacesShouldNeverFail(@TempDir Path tempDir) throws IOException { | ||
Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory with spaces"); | ||
|
||
try (ScanResult scanResult = scanJar(targetJar)) { | ||
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull(); | ||
} | ||
} | ||
|
||
@Test | ||
void scanningNestedJarsInPathsContainingHashesShouldNeverFail(@TempDir Path tempDir) throws IOException { | ||
Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory-without-spaces#123"); | ||
|
||
try (ScanResult scanResult = scanJar(targetJar)) { | ||
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull(); | ||
} | ||
} | ||
|
||
@Test | ||
void scanningNestedJarsInPathsContainingSpacesAndHashesShouldNeverFail(@TempDir Path tempDir) throws IOException { | ||
Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory with spaces #123"); | ||
|
||
try (ScanResult scanResult = scanJar(targetJar)) { | ||
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull(); | ||
} | ||
} | ||
|
||
private Path createSpringBootJarInExampleDirectory(Path temporaryDirectory, String directoryName) | ||
throws IOException { | ||
Path directoryWithSpaces = temporaryDirectory.resolve(directoryName); | ||
Files.createDirectories(directoryWithSpaces); | ||
Path nestedJar = directoryWithSpaces.resolve("spring-boot-fully-executable-jar.jar"); | ||
try (InputStream nestedJarsExample = Issue804Test.class.getClassLoader() | ||
.getResourceAsStream("spring-boot-fully-executable-jar.jar")) { | ||
Files.copy(nestedJarsExample, nestedJar); | ||
} | ||
return nestedJar; | ||
} | ||
|
||
private ScanResult scanJar(Path targetJar) { | ||
return new ClassGraph().enableClassInfo().overrideClasspath(targetJar.toUri()).scan(); | ||
} | ||
|
||
} |