-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
SONARJAVA-5383 Lookup Spring-web dependency version to filter out visitors #5053
Open
romainbrenguier
wants to merge
5
commits into
master
Choose a base branch
from
romain/SONARJAVA-5383-MPV
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d43908
Add Version and version inference classes
romainbrenguier bb1ee74
Introduce DependencyVersionAware interface to filter visitors
romainbrenguier b9cee2a
Make SpringComposedRequestMappingCheck implement DependencyVersionAware
romainbrenguier 5456fa5
Add test sample for SpringComposedRequestMappingCheck
leonardo-pilastri-sonarsource 73266fd
Exclude new example module from analysis like Mend
romainbrenguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.sonarsource.java</groupId> | ||
<artifactId>java-checks-test-sources</artifactId> | ||
<version>8.11.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-web-4.0</artifactId> | ||
<name>SonarQube Java :: Checks Test Sources :: Spring Web 4.0</name> | ||
|
||
<properties> | ||
<sonar.skip>true</sonar.skip> | ||
<forbiddenapis.skip>true</forbiddenapis.skip> | ||
<skipTests>true</skipTests> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>4.0.0.RELEASE</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>analyze-tests</id> | ||
<properties> | ||
<sonar.skip>false</sonar.skip> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<release>22</release> | ||
<source>22</source> | ||
<target>22</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<argLine>--enable-preview</argLine> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.simplify4u.plugins</groupId> | ||
<artifactId>sign-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-jar</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-install</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<configuration> | ||
<licenseSets> | ||
<licenseSet> | ||
<excludes> | ||
<exclude>src/main/java/**</exclude> | ||
<exclude>src/test/java/**</exclude> | ||
</excludes> | ||
</licenseSet> | ||
</licenseSets> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
...-sources/spring-web-4.0/src/main/java/checks/SpringComposedRequestMappingCheckSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package checks; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static org.springframework.web.bind.annotation.RequestMethod.POST; | ||
|
||
|
||
/** | ||
* This class serves as a sample for older spring-web version (4.0) where @GetMapping, @PostMapping and so on were not present | ||
* hence no issues are expected to be reported here when using the generic @RequestMapping | ||
*/ | ||
@RestController | ||
@RequestMapping("/home") | ||
public class SpringComposedRequestMappingCheckSample { | ||
|
||
@RequestMapping(method = RequestMethod.GET) | ||
String m2() { | ||
return ""; | ||
} | ||
|
||
@RequestMapping(method = {POST}) | ||
String m3() { | ||
return ""; | ||
} | ||
|
||
@RequestMapping(method = {RequestMethod.PUT}) | ||
String m4() { | ||
return ""; | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.PATCH) | ||
String m5() { | ||
return ""; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
java-frontend/src/main/java/org/sonar/java/classpath/DependencyVersionInference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SonarQube Java | ||
* Copyright (C) 2012-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonar.java.classpath; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class DependencyVersionInference { | ||
|
||
/** Cache for dependency retrieval. Indexed by artifactId. */ | ||
private final Map<String, Optional<Version>> dependencyVersionsCache = new HashMap<>(); | ||
|
||
static Pattern makeJarPattern(String artifactId) { | ||
return Pattern.compile(artifactId + "-" + Version.VERSION_REGEX + "\\.jar"); | ||
} | ||
|
||
public Optional<Version> infer(String artifactId, List<File> classpath) { | ||
return dependencyVersionsCache | ||
.computeIfAbsent(artifactId, key -> infer(makeJarPattern(key), classpath)); | ||
} | ||
|
||
private static Optional<Version> infer(Pattern jarPattern, List<File> classpath) { | ||
for (File file : classpath) { | ||
Matcher matcher = jarPattern.matcher(file.getName()); | ||
if (matcher.matches()) { | ||
return Optional.of(Version.matcherToVersion(matcher)); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the root folder of sonar-java we have the .cirrus.yml file where in some parts we exclude test source modules to avoid FPs on Mend for instance, at line 89 of this yml file for instance
We will need to add this new module in such places as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just at line 89 and 121