FrameworkInjector
is an AOP framework for Java which is managing pointcut configurations by json and performing code weaving with Javassist
.
At the begining, FrameworkInjector
is designed for AOP code weaving of Android framework. This is the origin of the name.
- Managing AOP pointcut configurations by JSON
- Perform code weaving on specified Java class method
- Support wildcard while matching class and method name
- [BUG][TODO] Skipping interface class so that interface currently would not perform code weaving.
source build.sh
Run build.sh
to compile by javac
and package by jar
. The final target is runnable jar.
The runnable jar of this program support parameters:
--pointcuts_json
Sets path of json that managing pointcut configurations-i
Sets the input jar file which performing weaving from-o
Sets the output jar file which is been injected-cplist
Class Path List for Javassist. In case of class that exists in the input jar is not able to found in system class path, passing the path of the class to Javassist with this params to help Javassist load it. Every path is concat by ':'(Check it on JDK specifications).
source build_and_run_sample.sh
build_and_run_sample.sh
contains a lot of steps. It will make this program by calling build.sh
. And then runs the inside sample(sample/sample.json
). The sample will make this program perform code weaving on the jar generated by build.sh
Perform code weaving on foo.jar:
java -jar frameworkinjector.jar -cplist "libs" -pointcuts_json myPointcuts.json -i foo.jar -o injected_foo.jar
When error like "Class NotFound" happends, it is useful that add class path:
java -Xbootclasspath/a:/path/myPath:<other> <...other cmd parts...>
- Run
build_and_run_sample.sh
, which will perform code weaving configed by sample.json - A new jar that is injected will be produced from step 1. It containes codes injected by this program. In the case of the sample, a new
System.out.println
call is injected which shown as below.
Copyright (C) <2022>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.