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

Add Dubbo Annotation Processor (Add deprecated method warn when called by user, #10850) #11513

Merged
merged 84 commits into from
Mar 24, 2023

Conversation

win120a
Copy link
Contributor

@win120a win120a commented Feb 9, 2023

What is the purpose of the change

Trying to provide a solution of #10850.

Brief changelog

Adds an annotation processor, which adds a line of code in every methods decorated by @Deprecated. Like getServiceName() in class URL of dubbo-common module (decompiled result):

@Deprecated
public String getServiceName() {
    DeprecatedMethodInvocationCounter.onDeprecatedMethodCalled("org.apache.dubbo.common.URL.getIntParameter(String key,int defaultValue)");
    return this.getServiceInterface();
}

Per suggestion from Albumen Kevin, the count of the deprecated method invocation is also recorded.

Verifying this change

Use a decomplier (like Java Decompiler, or FernFlower decompiler in IntelliJ IDEA) to see the result.

@win120a
Copy link
Contributor Author

win120a commented Feb 9, 2023

Related dubbo-website PR: apache/dubbo-website#2140

@win120a win120a marked this pull request as draft February 10, 2023 09:17
@win120a win120a marked this pull request as ready for review February 10, 2023 15:00
@win120a
Copy link
Contributor Author

win120a commented Feb 10, 2023

@AlbumenJ PTAL.

@AlbumenJ AlbumenJ changed the base branch from 3.1 to 3.2 February 14, 2023 01:46
Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Please rebase your branch onto 3.2

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Can the inserted code also inserted into xxx-source.jar?

@win120a
Copy link
Contributor Author

win120a commented Feb 14, 2023

Please rebase your branch onto 3.2 .

Rebased.

Just insert DeprecatedMethodCollector.collect(xxx) here. Log and count in DeprecatedMethodCollector.collect.

Moved all the logic to org.apache.dubbo.common.DeprecatedMethodInvocationCounter#onDeprecatedMethodCalled() .

Can the inserted code also inserted into xxx-source.jar?

Unfortunately, it can't. It works as a compiler addon (an annotation processor). It directly modifies the Abstract Syntax Tree (i.e. the .class file), the source code remains untouched. Since the source plugin in Maven just copies the source, the generated sources.jar will not appear the modified code.

@win120a win120a requested a review from AlbumenJ February 15, 2023 13:07
Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

@chickenlj PTAL

@AlbumenJ
Copy link
Member

AlbumenJ commented Mar 6, 2023

image

Please add excluede in FileTests

@win120a win120a force-pushed the 230123_insert_warn branch from 8da9c6e to 5c75a87 Compare March 6, 2023 10:31
@win120a win120a requested a review from AlbumenJ March 6, 2023 14:40
@win120a win120a force-pushed the 230123_insert_warn branch from 28c97e0 to 5a8653c Compare March 21, 2023 09:59
@win120a
Copy link
Contributor Author

win120a commented Mar 21, 2023

@AlbumenJ PTAL.

The scope configuration of pom.xml is required to import javac package (tools.jar), which causes 'bugs' in SonarLint.

@win120a win120a requested a review from AlbumenJ March 23, 2023 12:35
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 10 Code Smells

4.3% 4.3% Coverage
1.0% 1.0% Duplication

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

LGTM

@AlbumenJ AlbumenJ merged commit 0b6f2e4 into apache:3.3 Mar 24, 2023
@win120a win120a deleted the 230123_insert_warn branch March 27, 2023 03:47
CrazyHZM pushed a commit to CrazyHZM/dubbo that referenced this pull request May 17, 2023
chickenlj added a commit to chickenlj/incubator-dubbo that referenced this pull request Aug 9, 2023
chickenlj added a commit that referenced this pull request Aug 16, 2023
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