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

Switch to stream-based loading #11479

Merged
merged 16 commits into from
Jul 17, 2024
Merged

Switch to stream-based loading #11479

merged 16 commits into from
Jul 17, 2024

Conversation

koppor
Copy link
Member

@koppor koppor commented Jul 10, 2024

Uses ProtectedTermsLoader.class.getResourceAsStream instead of ProtectedTermsLoader.class.getResource.

Refs #11298 (comment)

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@koppor koppor added this to the 6.0-alpha milestone Jul 10, 2024
if (!Files.exists(path)) {
LOGGER.warn("Could not read terms from file {}", path);
return;
}
try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) {
Copy link
Member

Choose a reason for hiding this comment

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

Files lines does not work with graal? Tbh this looks like a major drawback here.

Copy link
Member

Choose a reason for hiding this comment

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

BufferedReader#lines seems to be somewhat of an equivalent here...

Copy link
Member Author

Choose a reason for hiding this comment

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

In line 60, I use exactly this function.

This call is only a wrapper for the call if a user supplies a file!

GraalVM does not support .class.getResource( with hacks. See oracle/graal#7682 for a longer discussion. Especially oracle/graal#7682 (comment)

The reason NativeImageFileSystem behaves like JarFileSystem, not like UnixFileSystem, is that, unlike UnixFileSystem, you can't, for example, delete a file (resource) on both NativeImageFileSystem and JarFileSystem. The resources in NativeImageFileSystem are baked into the read-only section of the image heap

@koppor
Copy link
Member Author

koppor commented Jul 10, 2024

... and the tests fail... OMG

Test readProtectedTermsListFromFileReadsDescription() FAILED

LOGGER.error("");
description = descriptionString;
location = resourceFileName;
try (InputStream inputStream = ProtectedTermsLoader.class.getResourceAsStream(Objects.requireNonNull(resourceFileName))) {
Copy link
Member

@Siedlerchr Siedlerchr Jul 10, 2024

Choose a reason for hiding this comment

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

You need to use getClassLoader() first, don't ask me why but for getResourceAsStream it does not work otherwise

LOGGER.error("");
description = descriptionString;
location = resourceFileName;
try (InputStream inputStream = ProtectedTermsLoader.class.getResourceAsStream(Objects.requireNonNull(resourceFileName))) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try (InputStream inputStream = ProtectedTermsLoader.class.getResourceAsStream(Objects.requireNonNull(resourceFileName))) {
try (InputStream inputStream = ProtectedTermsLoader.class.getClassLoader().getResourceAsStream(Objects.requireNonNull(resourceFileName))) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Works without here.

Copy link
Member

Choose a reason for hiding this comment

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

But might not work at runtime

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried with ./gradlew run and then protected terms. Worked.

@koppor
Copy link
Member Author

koppor commented Jul 11, 2024

For full GraalVM, we would maybe to patch CSL.java:

            // try to find style in classpath
            url = CSL.class.getResource(styleName);

However, I added a workaround, because this branch is only taken if the provided String is not an XML file.

@koppor
Copy link
Member Author

koppor commented Jul 11, 2024

Assuming that JavaFX can perfectly deal with URLs coming from the classpath, we have one class left to "really" change:

org.jabref.logic.citationstyle.CitationStyle#discoverCitationStyles: Here, the list could be generated during compilation time

@@ -38,7 +41,7 @@ public static String parse(XMLStreamReader reader) {
Source xmlSource = new StreamSource(new StringReader(xmlContent));

// No SystemId required, because no relative URLs need to be resolved
Source xsltSource = new StreamSource(xsltResource);
Source xsltSource = new StreamSource(xsltResource, MathMLParser.class.getResource(XSLT_FILE_PATH).toExternalForm());
Copy link
Member Author

Choose a reason for hiding this comment

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

OK for a workaround. - Can we do add a fake path here? Maybe, #future work

@koppor
Copy link
Member Author

koppor commented Jul 12, 2024

Proposal: Get this in to see whether there are issues. As follow up the "difficult" conversions.

@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 12, 2024
@koppor koppor enabled auto-merge July 15, 2024 20:10
@Siedlerchr Siedlerchr disabled auto-merge July 15, 2024 20:11
@Siedlerchr
Copy link
Member

Use the binary to test it!

Copy link
Contributor

github-actions bot commented Jul 15, 2024

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

@koppor
Copy link
Member Author

koppor commented Jul 16, 2024

Tested. Protected terms works. Think, more users should test it and we can revert if needed ^^.

Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Lets move forward here.

@Siedlerchr Siedlerchr added this pull request to the merge queue Jul 17, 2024
@calixtus calixtus added the type: code-quality Issues related to code or architecture decisions label Jul 17, 2024
Merged via the queue into main with commit 4a8404c Jul 17, 2024
24 of 25 checks passed
@Siedlerchr Siedlerchr deleted the switch-to-stream branch July 17, 2024 18:36
Siedlerchr added a commit to subhramit/jabref that referenced this pull request Jul 19, 2024
* upstream/main:
  Fix NPE when saving preferences (JabRef#11509)
  Switch to stream-based loading (JabRef#11479)
  Save unlinked local files dialog prefs (JabRef#11493)
  Add minimal support for biblatex data annotations (JabRef#11506)
  Fix handling of relative-file storage and auto linking (JabRef#11492)
  New Crowdin updates (JabRef#11504)
  Add missing issue numbers
  CSL4LibreOffice - A [GSoC '24] (JabRef#11477)
  Bump src/main/resources/csl-styles from `b2be5ae` to `fd6cb3e` (JabRef#11501)
  Bump gittools/actions from 1.1.1 to 1.2.0 (JabRef#11500)
  Bump com.kohlschutter.junixsocket:junixsocket-core from 2.9.1 to 2.10.0 (JabRef#11498)
  Bump commons-logging:commons-logging from 1.3.2 to 1.3.3 (JabRef#11499)
  Bump org.jsoup:jsoup from 1.17.2 to 1.18.1 (JabRef#11497)
  Bump com.kohlschutter.junixsocket:junixsocket-mysql from 2.9.1 to 2.10.0 (JabRef#11496)
  Bump org.openrewrite.recipe:rewrite-recipe-bom from 2.14.0 to 2.15.0 (JabRef#11495)
  FAQ updates (JabRef#11486)
  Update Gradle Wrapper from 8.8 to 8.9.
  Fix Chocolate.bib (JabRef#11491)

# Conflicts:
#	src/main/java/org/jabref/gui/openoffice/OOBibBase.java
#	src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
#	src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java
#	src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java
#	src/main/java/org/jabref/preferences/JabRefPreferences.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers type: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants