Skip to content

Remove usage of reflection in timeago-parser module#1288

Merged
Stypox merged 4 commits intoTeamNewPipe:devfrom
thigg:dev
Apr 8, 2025
Merged

Remove usage of reflection in timeago-parser module#1288
Stypox merged 4 commits intoTeamNewPipe:devfrom
thigg:dev

Conversation

@thigg
Copy link
Copy Markdown
Contributor

@thigg thigg commented Mar 26, 2025

We are trying to use the NewPipe extractor library for a native app for the mobile linux OS SailfishOS.
For this we intend to use graal's native-image.
When reflection is used, this needs an entry in a json file for each of the classes that may be used with reflection.

I created the put lines for the hashmap with a simple bashscript.
I think this should be totally equal (in terms of functionallity and maintainability) to the current solution without the drawback (for us) that it uses reflection.

  • I carefully read the contribution guidelines and agree to them.
  • I have tested the API against NewPipe.
  • I agree to create a pull request for NewPipe as soon as possible to make it compatible with the changed API.

@Stypox
Copy link
Copy Markdown
Member

Stypox commented Mar 27, 2025

Thank you! Yes it makes a lot of sense to remove reflection. All of the java files under the patterns/ folder were autogenerated by https://github.com/TeamNewPipe/NewPipeExtractor/blob/dev/timeago-parser/raw/java/GeneratePatternClasses.java, could you instead change that class to also autogenerate a java file which contains the hashmap, instead of manually hardcoding it?

@ShareASmile ShareASmile added enhancement New feature or request code quality Improvements to the codebase to improve the code quality labels Mar 27, 2025
@thigg
Copy link
Copy Markdown
Contributor Author

thigg commented Mar 27, 2025

Sure, sounds like no big deal.

…to generate the Localization files was extracted into its own submodule.

The generator now also creates a class that Holds a Map of all Localizations for the timeago-parser.
@thigg
Copy link
Copy Markdown
Contributor Author

thigg commented Mar 27, 2025

@Stypox I updated the PR to generate the map with the generator.
While working at the generator I also moved it into its own gradle submodule, I hope this was okay?

@gechoto
Copy link
Copy Markdown
Contributor

gechoto commented Mar 28, 2025

I guess this means the proguard rule mentioned in the readme can be removed:

-keep class org.schabi.newpipe.extractor.timeago.patterns.** { *; }

@thigg
Copy link
Copy Markdown
Contributor Author

thigg commented Mar 29, 2025

removed the line

@AudricV AudricV changed the title remove use of reflection in timeago Remove usage of reflection in timeago-parser module Mar 29, 2025
Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

Thank you! I tested importing the project in Android Studio and running the generator and everything worked without issues. I solved the two comments myself with two commits.

Comment thread timeago-generator/src/main/java/com/github/TeamNewPipe/Utils.java Outdated
Comment thread timeago-parser/src/main/java/org/schabi/newpipe/extractor/timeago/PatternMap.java Outdated
@Stypox Stypox merged commit 67f3301 into TeamNewPipe:dev Apr 8, 2025
4 checks passed
@thigg
Copy link
Copy Markdown
Contributor Author

thigg commented Apr 9, 2025

Thank you. That was pleasant :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvements to the codebase to improve the code quality enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants