Skip to content

Merge FileImageDescriptor into URLImageDescriptor and clean it up #2899

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HannesWell
Copy link
Member

@HannesWell HannesWell commented Apr 9, 2025

In it's core the FileImageDescriptor queries the given context class for a resource at the given path and then operates on the returned URL or directly fetches the resource's stream. By optaining the resource's URL immediately and using an URLImageDescriptor with it a lot of similar code and logic from the FileImageDescriptor can be saved.

Additionally apply a few minor code clean-ups and remove a unused internal method.

@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from e6c5232 to a1eada2 Compare April 9, 2025 17:58
@laeubi
Copy link
Contributor

laeubi commented Apr 9, 2025

Honestly this now feels it become completely unmaintainable and hardly understandable, can we not simply use an abstract base-class to share code instead of all this inlined lamda and hype-generic method calls?

Copy link
Contributor

github-actions bot commented Apr 9, 2025

Test Results

 1 824 files  ±0   1 824 suites  ±0   1h 35m 42s ⏱️ + 1m 54s
 7 918 tests ±0   7 690 ✅ ±0  228 💤 ±0  0 ❌ ±0 
23 841 runs  ±0  23 093 ✅ ±0  748 💤 ±0  0 ❌ ±0 

Results for commit 1f8f8eb. ± Comparison against base commit 9a586ab.

♻️ This comment has been updated with latest results.

@HannesWell
Copy link
Member Author

Honestly this now feels it become completely unmaintainable and hardly understandable, can we not simply use an abstract base-class to share code instead of all this inlined lamda and hype-generic method calls?

I'm not so sure if that becomes much simpler, but I can have a look.
Actually this was intended as up-front work to reduce the duplicated changes for #2593. But maybe it's simpler to complete that first and make this a follow-up. Then we also know better was is needed for that.

@HannesWell HannesWell marked this pull request as draft April 10, 2025 22:36
@HannesWell
Copy link
Member Author

While looking at both classes again I got the impression that actually the FileImageDescriptor class could be fully replaced by URLImageDescriptor. There are probably some corner cases that still have to be handled (e.g. resource not found), but in general I didn't saw reason to keep the FileImageDescriptor.
Do you or anybody else know one?

@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from bd58803 to 1289fc9 Compare April 11, 2025 22:43
@HannesWell HannesWell changed the title Unify logic of FileImageDescriptor and URLImageDescriptor Merge FileImageDescriptor into URLImageDescriptor and clean it up Apr 11, 2025
@HannesWell
Copy link
Member Author

While looking at both classes again I got the impression that actually the FileImageDescriptor class could be fully replaced by URLImageDescriptor.

I have now taken this path further and didn't found a reason speaking against it. The tests should now pass as well.

@HannesWell HannesWell marked this pull request as ready for review April 11, 2025 23:08
@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from 1289fc9 to 3d2506d Compare April 15, 2025 06:18
In it's core the FileImageDescriptor queries the given context class for
a resource at the given path and then operates on the returned URL or
directly fetches the resource's stream. By optaining the resource's URL
immediately and using an URLImageDescriptor with it a lot of similar
code and logic from the FileImageDescriptor can be saved.

Additionally apply a few minor code clean-ups and remove a unused
internal method.
@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from 3d2506d to 1f8f8eb Compare April 15, 2025 17:22
@HannesWell
Copy link
Member Author

This contains now much less, i.e. just one additional lambda in the zoom-image computation and is, from my side, ready for submission.
Does anybody want to review this?
If there are no objection respectively to request for more time to review, I plan to submit this tomorrow.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

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

I really like this simplification. I did not check in detail whether everything the FileImageDescriptor did is properly captured by the URLImageDescriptor as well. So far, I just found one place where I am not sure if behavior is properly preserved.

If you want me to do a more in-depth review, let me know, but I am not sure how soon I will find the time for it. So from my side, feel free to further process this PR if you are confident that everything works as expected.

@@ -84,7 +87,11 @@ protected ImageDescriptor() {
* @return a new image descriptor
*/
public static ImageDescriptor createFromFile(Class<?> location, String filename) {
return new FileImageDescriptor(location, filename);
URL url = location != null ? location.getResource(filename) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

There was some more complex logic for retrieving the URL, in particular for the case that location was null. Is it intended to remove that?

return null;
}

private static <R> R getZoomedImage(URL url, String urlString, int zoom, Function<URL, R> getImage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this does actually not return an image (as indicated by the method name), but something depending on the type parameter, such as some image data or even just a path to the image. But I have to admit that I have no better generic name to propose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants