Skip to content

Commit

Permalink
Source > Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Nov 2, 2023
1 parent 07c2f49 commit a942bf6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/github/classgraph/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,8 @@ protected void toString(final boolean useSimpleNames, final StringBuilder buf) {
final boolean initialBufEmpty = buf.length() == 0;
if (annotationInfo != null) {
for (final AnnotationInfo annotation : annotationInfo) {
if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ' && buf.charAt(buf.length() - 1) != '(') {
if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' '
&& buf.charAt(buf.length() - 1) != '(') {
buf.append(' ');
}
annotation.toString(useSimpleNames, buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ ClassfileReader openClassfile() throws IOException {
@Override
public URI getURI() {
try {
ModuleReaderProxy localModuleReaderProxy = moduleReaderProxyRecycler.acquire();
final ModuleReaderProxy localModuleReaderProxy = moduleReaderProxyRecycler.acquire();
try {
return localModuleReaderProxy.find(resourcePath);
} finally {
moduleReaderProxyRecycler.recycle(localModuleReaderProxy);
}
} catch (IOException e) {
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/classgraph/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ void toString(final boolean includeModifiers, final boolean useSimpleNames, fina
if (annotationInfo != null) {
for (final AnnotationInfo annotation : annotationInfo) {
// There can be a paren in the previous position if this field is a record parameter
if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ' && buf.charAt(buf.length() - 1) != '(') {
if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' '
&& buf.charAt(buf.length() - 1) != '(') {
buf.append(' ');
}
annotation.toString(useSimpleNames, buf);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/github/classgraph/ModuleReaderProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,12 @@ public void release(final ByteBuffer byteBuffer) {
* If the module cannot be accessed.
*/
public URI find(final String path) {
final Object /* Optional<URI> */ optionalURI = reflectionUtils.invokeMethod(/* throwException = */ true, moduleReader, "find", String.class,
path);
final Object /* Optional<URI> */ optionalURI = reflectionUtils.invokeMethod(/* throwException = */ true,
moduleReader, "find", String.class, path);
if (optionalURI == null) {
throw new IllegalArgumentException("Got null result from ModuleReader#find(String)");
}
final URI uri = (URI) reflectionUtils.invokeMethod(/* throwException = */ true,
optionalURI, "get");
final URI uri = (URI) reflectionUtils.invokeMethod(/* throwException = */ true, optionalURI, "get");
if (uri == null) {
throw new IllegalArgumentException("Got null result from ModuleReader#find(String).get()");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public Object getFieldVal(final boolean throwException, final Object obj, final
return reflectionDriver.getField(obj, reflectionDriver.findInstanceField(obj, fieldName));
} catch (final Throwable e) {
if (throwException) {
throw new IllegalArgumentException(
"Can't read field " + obj.getClass().getName() + "." + fieldName, e);
throw new IllegalArgumentException("Can't read field " + obj.getClass().getName() + "." + fieldName,
e);
}
}
return null;
Expand Down Expand Up @@ -188,8 +188,7 @@ public Object getStaticFieldVal(final boolean throwException, final Class<?> cls
return reflectionDriver.getStaticField(reflectionDriver.findStaticField(cls, fieldName));
} catch (final Throwable e) {
if (throwException) {
throw new IllegalArgumentException(
"Can't read field " + cls.getName() + "." + fieldName, e);
throw new IllegalArgumentException("Can't read field " + cls.getName() + "." + fieldName, e);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,50 @@
*/
public class Issue804Test {

private static final String NESTED_EXAMPLE_CLASS = "org.springframework.util.ResourceUtils";
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");
@Test
void scanningNestedJarsInPathsContainingSpacesShouldNeverFail(@TempDir final Path tempDir) throws IOException {
final Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory with spaces");

try (ScanResult scanResult = scanJar(targetJar)) {
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull();
}
}
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");
@Test
void scanningNestedJarsInPathsContainingHashesShouldNeverFail(@TempDir final Path tempDir) throws IOException {
final Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory-without-spaces#123");

try (ScanResult scanResult = scanJar(targetJar)) {
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull();
}
}
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");
@Test
void scanningNestedJarsInPathsContainingSpacesAndHashesShouldNeverFail(@TempDir final Path tempDir)
throws IOException {
final Path targetJar = createSpringBootJarInExampleDirectory(tempDir, "directory with spaces #123");

try (ScanResult scanResult = scanJar(targetJar)) {
assertThat(scanResult.getClassInfo(NESTED_EXAMPLE_CLASS)).isNotNull();
}
}
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 Path createSpringBootJarInExampleDirectory(final Path temporaryDirectory, final String directoryName)
throws IOException {
final Path directoryWithSpaces = temporaryDirectory.resolve(directoryName);
Files.createDirectories(directoryWithSpaces);
final 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();
}
private ScanResult scanJar(final Path targetJar) {
return new ClassGraph().enableClassInfo().overrideClasspath(targetJar.toUri()).scan();
}

}

0 comments on commit a942bf6

Please sign in to comment.