[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Add my aspect to different projects
|
Hello Mike.
I have a few questions:
- How are you using the aspect in your code? Do you compile the whole code with the AspectJ compiler (Ajc) or is the aspect in a separate JAR and used via LTW?
- How do you intend to use it for other products? LTW? Binary post-compile weaving? Compilation with Ajc? I guess it depends on what you mean by "other products" and whether they are in-house or 3rd party.
- What do you need the stacktraces for? Please elaborate and explain as detailed as possible.
- Is your intention to find usages of your own deprecated methods or that of 3rd party code, maybe even JRE/JDK?
- Have you considered using the AspectJ features "declare error" or "declare warning" and just get rid of deprecated class/method usage right during compilation instead of during runtime, using expensive stacktrace analysis?
- As for your original question, the answer could be anything from implementing an interface as you suggest to using an abstract base aspect. But really, this looks like a "declare warning" use case to me.
- Would you mind giving us a full picture with the stacktrace helper class and some simple sample code? An [SSCCE](http://sscce.org/) maybe?
Sorry, many questions, I know. But your question is not trivial and I do not like to make suggestions based on too many assumptions and educated guesses.
Kind regards
--
Alexander Kriegisch
https://scrum-master.de
Mikael Petterson schrieb am 15.03.2018 21:35:
I have created an aspect that can be used to track calls to deprecated methods in your product. It is currently implemented in "our product" but I want to make a library out of it so we can use it for other products.
The aspect currently looks something like:
aspect DeprecatedMethodLogger {
pointcut includeDeprecated():execution(public * *.*(..)) && @annotation(Deprecated);
pointcut excludeBeta():execution(public * *.*(..)) && !@annotation(com.google.common.annotations.Beta);
pointcut deprecatedMethods(): includeDeprecated() && excludeBeta();
before() :deprecatedMethods() {
if (thisJoinPoint.getTarget() != null) {
String targetClass = thisJoinPoint.getTarget().getClass().getName();
List<StackTraceElement> stackTraceElements = Arrays.asList(Thread.currentThread().getStackTrace());
StackTraceHelper stackTraceHelper = new StackTraceHelper(stackTraceElements);
DeprecatedMethodData deprecatedMethodData = stackTraceHelper.extractData(targetClass);
//There is also some additional connections to db and other tools here.
}
In stackTraceHelper there are a number of settings that can be done what is relevant in the trace when we try to find the calling class.
These settings I want to to publish so they can be set for each product using this library.
So question is if I in all products using it need to create another aspect that inherits this one and can set the relevant properties.
so my aspect above would have:
aspect DeprecatedMethodLogger implements DeprecatedMethodLoggerApi {
}
DeprecatedMethodLoggerApi contains setting that can be done.
Then in the products I create:
aspect MyDepreactedMethodLogger extends DeprecatedMethodLogger {
}
Or is there a better way? Suggestions welcome.