Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scan all versions in multi-version-jar #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public void initialize() throws IOException {
} catch (FileSystemAlreadyExistsException e) {
this.fs = FileSystems.getFileSystem(uri);
}
this.releasePath = this.fs.getPath("/", "META-INF", "versions", this.compliance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (!Files.exists(this.releasePath)) {
this.releasePath = null;
for (int version = Integer.parseInt(this.compliance); version >= 9; version--) {
this.releasePath = this.fs.getPath("/", "META-INF", "versions", String.valueOf(version)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to
https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files
all versions down to 9 have to be checked.
this.compliance should be always a major version accroding to the spec, so parseInt should work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it would be good to parse the compliance only once (same below) and cache it in a field?

if (Files.exists(this.releasePath)) {
break;
} else {
this.releasePath = null;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ private static IModule extractModuleFromArchive(File file, Classpath pathEntry,
try {
zipFile = new ZipFile(file);
if (release != null) {
String releasePath = "META-INF/versions/" + release + "/" + path; //$NON-NLS-1$ //$NON-NLS-2$
ZipEntry entry = zipFile.getEntry(releasePath);
if (entry != null) {
path = releasePath;
for (int version = Integer.parseInt(release); version >= 9; version--) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is practically the same code as above.

String releasePath = "META-INF/versions/" + version + "/" + path; //$NON-NLS-1$ //$NON-NLS-2$
ZipEntry entry = zipFile.getEntry(releasePath);
if (entry != null) {
path = releasePath;
break;
}
}
}
ClassFileReader reader = ClassFileReader.read(zipFile, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,18 @@ IModule initializeModule() {
ZipFile file = null;
try {
file = new ZipFile(this.zipFilename);
String releasePath = "META-INF/versions/" + this.compliance + '/' + IModule.MODULE_INFO_CLASS; //$NON-NLS-1$
ClassFileReader classfile = null;
try {
classfile = ClassFileReader.read(file, releasePath);
} catch (Exception e) {
e.printStackTrace();
// move on to the default
for (int version = Integer.parseInt(this.compliance); version >= 9; version--) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here, we search for the module-info.class, which should be the fix for the bug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why It's being done in ClasspathJar instead of org.eclipse.jdt.internal.core.builder.ClasspathMultiReleaseJar ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarthana Do you mean, why I have made this change or why this code is here at all?

IMHO it sounds logical, if this is handled in ClasspathMultiReleaseJar as it does not require to have duplicate code.
(But I'm really not the expert to do such refactoring in this project)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just wondering about having this in the super class ClasspathJar but in case of the compiler.batch package, you have made it in the subclass ClasspathMultiReleaseJar. Haven't looked at the code in detail, but IIRC, we had similar code and hierarchy in both the compiler.batch and core.builder packages.

String releasePath = "META-INF/versions/" + version + '/' + IModule.MODULE_INFO_CLASS; //$NON-NLS-1$
try {
classfile = ClassFileReader.read(file, releasePath);
if (classfile != null) {
break;
}
} catch (Exception e) {
e.printStackTrace();
// move on to the next or default
}
}
if (classfile == null) {
classfile = ClassFileReader.read(file, IModule.MODULE_INFO_CLASS); // FIXME: use jar cache
Expand Down