Skip to content

Commit

Permalink
Source > Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Aug 7, 2023
1 parent 7aac7f4 commit 06ca78c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/github/classgraph/ClasspathElementDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ private void scanPathRecursively(final Path path, final LogNode log) {
// Ignore versioned sections in exploded jars -- they are only supposed to be used in jars.
// TODO: is it necessary to support multi-versioned exploded jars anyway? If so, all the paths in a
// directory classpath entry will have to be pre-scanned and masked, as happens in ClasspathElementZip.
if (!scanSpec.enableMultiReleaseVersions && dirRelativePathStr.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (!scanSpec.enableMultiReleaseVersions
&& dirRelativePathStr.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (log != null) {
log.log("Found unexpected nested versioned entry in directory classpath element -- skipping: "
+ dirRelativePathStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ void scanPaths(final LogNode log) {
// contain a path like "META-INF/versions/{version}/META-INF/versions/{version}/", which cannot
// be valid (META-INF should only ever exist in the module root), and the nested versioned section
// should be ignored.
if (!scanSpec.enableMultiReleaseVersions && relativePath.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (!scanSpec.enableMultiReleaseVersions
&& relativePath.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (subLog != null) {
subLog.log(
"Found unexpected nested versioned entry in module -- skipping: " + relativePath);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/classgraph/ClasspathElementZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ void scanPaths(final LogNode log) {
// jar, in which case zipEntry.entryNameUnversioned has the version prefix stripped, or this is an
// unversioned jar (e.g. the multi-version flag is not set in the manifest file) and there are some
// spurious files in a multi-version path (in which case, they should be ignored).
if (!scanSpec.enableMultiReleaseVersions && relativePath.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (!scanSpec.enableMultiReleaseVersions
&& relativePath.startsWith(LogicalZipFile.MULTI_RELEASE_PATH_PREFIX)) {
if (subLog != null) {
if (VersionFinder.JAVA_MAJOR_VERSION < 9) {
subLog.log("Skipping versioned entry in jar, because JRE version "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public ZipFileSlice newInstance(final FastZipEntry childZipEntry, final LogNode
public LogicalZipFile newInstance(final ZipFileSlice zipFileSlice, final LogNode log)
throws IOException, InterruptedException {
// Read the central directory for the zipfile
return new LogicalZipFile(zipFileSlice, NestedJarHandler.this, log, scanSpec.enableMultiReleaseVersions);
return new LogicalZipFile(zipFileSlice, NestedJarHandler.this, log,
scanSpec.enableMultiReleaseVersions);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ public void enableMultiReleaseVersions() throws Exception {
.scan()) {
final ResourceList java8ClassResource = scanResult.getResourcesWithPath("mrj/Cls.class");
assertThat(java8ClassResource).hasSize(1);
final ResourceList java9ClassResource = scanResult.getResourcesWithPath("META-INF/versions/9/mrj/Cls.class");
final ResourceList java9ClassResource = scanResult
.getResourcesWithPath("META-INF/versions/9/mrj/Cls.class");
assertThat(java9ClassResource).hasSize(1);
assertThat(java8ClassResource.get(0).load()).isNotEqualTo(java9ClassResource.get(0).load());

final ResourceList java8Resource = scanResult.getResourcesWithPath("resource.txt");
assertThat(java8Resource.size()).isEqualTo(1);
java8Resource.forEachByteArrayThrowingIOException(
(resource, byteArray) -> assertThat(new String(byteArray).trim()).isEqualTo("8"));
final ResourceList java9Resource = scanResult.getResourcesWithPath("META-INF/versions/9/resource.txt");
final ResourceList java9Resource = scanResult
.getResourcesWithPath("META-INF/versions/9/resource.txt");
assertThat(java9Resource.size()).isEqualTo(1);
java9Resource.forEachByteArrayThrowingIOException(
(resource, byteArray) -> assertThat(new String(byteArray).trim()).isEqualTo("9"));
Expand All @@ -128,7 +130,7 @@ public void enableMultiReleaseVersionsWithClassInfo() throws Exception {
final ResourceList java8ClassResource = scanResult.getResourcesWithPath("mrj/Cls.class");
assertThat(java8ClassResource).hasSize(1);
assertThatThrownBy(() -> scanResult.getClassInfo("mrj.Cls"))
.isInstanceOfAny(IllegalArgumentException.class);
.isInstanceOfAny(IllegalArgumentException.class);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.github.classgraph.issues.issue780;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;

public class Issue780Test {
/**
Expand Down

0 comments on commit 06ca78c

Please sign in to comment.