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

refactor: Config/Tests/misc rework #3746

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

IgorEisberg
Copy link
Contributor

@IgorEisberg IgorEisberg commented Dec 18, 2024

Config is now propagated to ResValue instead of being a globally accessible instance that gets set each time a new Config is instantiated. The old way violated every principle of an instance and even a singleton. This caused working with Tests extremely error-prone, because the Config had to be carefully reset to default for each Test to get the expected behavior, and ResValue was only aware of the global instance. Now, only Main and BaseTest are calling new Config(). BaseTest provides a fresh Config for every Test which turns the boilerplate into something shorter, predictable and more robust.

Config class is now encapsulated to give control over the values passed to it. Having both publicly modifiable fields and setters with the verifications was more of a dirty hack than proper coding principles.

General-purpose XML utilities extracted from ResXmlUtils into XmlUtils in the brut.xml library. It contains Document creation, parsing and saving. In addition, it has a generic evaluateXPath method that's now used more widely wherever manual looping over nodes was used, like in some tests.

ResXmlUtils reworked and cleaned, now takes advantage of XmlUtils. ResXmlUtils only retains methods relevant specifically to resource XMLs and Android Manifest.

Minor tweaks and code cleanup in various classes like ApktoolProperties and the main work classes (Framework, ApkDecoder, ApkBuilder, etc.), as well as utility classes like AaptInvoker and OS.

Fixed locks being held by certain ExtFiles to zips with loaded Directory, which prevented proper temp file cleanup during Test stage.

ExternalEntityTest resources ("doctype") moved to aapt1 as it's an aapt1-only test.

Overall, mainly a code refactor with no end-user changes, to make development less prone to errors.

IgorEisberg and others added 3 commits December 18, 2024 12:35
Config is now propagated to ResValue instead of being a globally
accessible instance that gets set each time a new Config is instantiated.
The old way violted every principle of an instance and even a singleton.
This caused working with Tests extremely error-prone, because the Config
had to be carefully reset to default for each Test to get the expected
behavior, and ResValue was only aware of the global instance.
Now, only Main and BaseTest are calling new Config().
BaseTest provides a fresh Config for every Test which turns the boilerplate
into something shorter, predictable and more robust.

Config class is now encapsulated to give control over the values passed
to it. Having both publically-modifyable fields and setters with the
verfications was more of a dirty hack than proper coding principles.

General-purpose XML utilities extracted from ResXmlUtils into XmlUtils
in the brut.xml library. It contains Document creation, parsing and saving.
In addition, it has a generic evaluateXPath method that's now used more
widely wherever manual looping over nodes was used, like in some tests.

ResXmlUtils reworked and cleaned, now takes advantage of XmlUtils.
ResXmlUtils only retains methods relevant specifically to resource XMLs
and Android Manifest.

Minor tweaks and code cleanup in various classed like ApktoolProperties
and the main work classes (Framework, ApkDecoder, ApkBuilder, etc.),
as well as utility classes like AaptInvoker and OS.

Fixed locks being held by certain ExtFiles to zips with loaded Directory,
which prevented proper temp file cleanup during Test stage.

ExternalEntityTest resources ("doctype") moved to aapt1 as it's an
aapt1-only test.

Overall, mainly a code refactor with no end-user changes,
to make development less prone to errors.
@iBotPeaches
Copy link
Owner

50 files to go... almost done

IgorEisberg and others added 7 commits December 20, 2024 21:10
We actually don't need to pass Config explicitly to all ResValue subtypes.
It's only needed by 3 subtypes of ResBagValue, so we get the Config
via ResBagValue's mParent.getPackage().getConfig().

Encapsulate ResConfigFlags.

Encapsulate ResID and make it a numeric and comparable type.

Sort resource specs by resource ID in generatePublicXml.

Duo is redundant, replace with Apache Common's Pair.

ResIdValue is redundant, it's never actually instantiated.

Tweak equals and hashCode overrides to standard formats.

Misc style and variable name tweaks.
@IgorEisberg
Copy link
Contributor Author

I think I'm done for now. I could go on, but it's solid enough of a refactor for the future of Apktool.
Let me know if you have any questions.

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.

2 participants