Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
maven-args: >
--define maven.test.skip=true
--define sonar.skip=true
--projects !java-checks-test-sources/aws,!java-checks-test-sources/default,!java-checks-test-sources/java-17,!java-checks-test-sources/spring-3.2,!java-checks-test-sources/spring-web-4.0
--projects !java-checks-test-sources/aws,!java-checks-test-sources/default,!java-checks-test-sources/java-17,!java-checks-test-sources/spring-3.2,!java-checks-test-sources/spring-web-4.0,!java-checks-test-sources/spring-web-7.0

ruling-qa:
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void javaCheckTestSources() throws Exception {
.setProjectName(PROJECT_NAME)
.setProjectVersion("0.1.0-SNAPSHOT")
.setSourceEncoding("UTF-8")
.setSourceDirs("aws/src/main/java/,default/src/main/java/,java-17/src/main/java/,spring-3.2/src/main/java/,spring-web-4.0/src/main/java/")
.setSourceDirs("aws/src/main/java/,default/src/main/java/,java-17/src/main/java/,spring-3.2/src/main/java/,spring-web-4.0/src/main/java/,spring-web-7.0/src/main/java/")
.setTestDirs("default/src/test/java/,java-17/src/test/java/,test-classpath-reader/src/test/java")
.setProperty("sonar.java.source", "26")
// common properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ruleKey": "S6856",
"hasTruePositives": false,
"falseNegatives": 61,
"falseNegatives": 65,
"falsePositives": 0
}
2 changes: 1 addition & 1 deletion java-checks-test-sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is the right place when a sample:
* needs the classpath or dependencies prepared by `java-checks-test-sources`
* should be compiled as part of one of the dedicated test-source modules
* is intentionally non-compiling and should live under `src/main/files/non-compiling`
* targets a specific dedicated module such as `default`, `java-17`, `spring-3.2`, or `spring-web-4.0`
* targets a specific dedicated module such as `default`, `java-17`, `spring-3.2`, `spring-web-4.0`, or `spring-web-7.0`

Prefer `java-checks/src/test/files` only for fixtures that are not supposed to belong to one of these Maven modules,
for example parser-only inputs or other ad hoc verifier fixtures.
Expand Down
1 change: 1 addition & 0 deletions java-checks-test-sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>java-17</module>
<module>spring-3.2</module>
<module>spring-web-4.0</module>
<module>spring-web-7.0</module>

<!-- should be the last module to be able to test classpath files "target/test-classpath.txt" of the previous modules -->
<module>test-classpath-reader</module>
Expand Down
126 changes: 126 additions & 0 deletions java-checks-test-sources/spring-web-7.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?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.35.0-SNAPSHOT</version>
</parent>

<artifactId>spring-web-7.0</artifactId>
<name>SonarQube Java :: Checks Test Sources :: Spring Web 7.0</name>

<properties>
<spring-framework.version>7.0.8</spring-framework.version>
<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>${spring-framework.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring-framework.version}</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>17</release>
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package checks.spring.s6856;

import java.util.function.Predicate;
import org.springframework.http.server.RequestPath;
import org.springframework.web.servlet.config.annotation.ApiVersionConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

class ApiVersionPathConfiguration implements WebMvcConfigurer {

@Override
public void configureApiVersioning(ApiVersionConfigurer configurer) {
Predicate<RequestPath> versionedPaths = this::isVersionedPath;
configurer.usePathSegment(1, versionedPaths);
}

private boolean isVersionedPath(RequestPath requestPath) {
String path = requestPath.pathWithinApplication().value();
return path.startsWith("/api/");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package checks.spring.s6856;

import org.springframework.web.servlet.config.annotation.ApiVersionConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

class ApiVersionPathUnconditionalConfiguration implements WebMvcConfigurer {

@Override
public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.usePathSegment(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package checks.spring.s6856;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

public class MissingPathVariableAnnotationCheck_ApiVersionPath {

static class VersionedController {

@GetMapping(value = "/api/v{apiVersion}/resource/{id}", version = "2")
String valid(@PathVariable String id) {
return id;
}

@GetMapping(value = "/api/v{apiVersion}/resource/{id}", version = "2") // Noncompliant {{Bind template variable "id" to a method parameter.}}
String missingId() {
return "";
}

@GetMapping(value = "/api/v{major}.{minor}/resource", version = "2")
String multipleVariablesInVersionSegment() {
return "";
}

@GetMapping("/api/v{apiVersion}/unversioned") // Noncompliant {{Bind template variable "apiVersion" to a method parameter.}}
String versionlessMapping() {
return "";
}

@GetMapping(value = "/api/{*apiVersion}", version = "2") // Noncompliant {{Bind template variable "apiVersion" to a method parameter.}}
String catchAllVariable() {
return "";
}

@GetMapping(value = {"/api/v{apiVersion}/alternative", "/{apiVersion}/alternative"}, version = "2") // Noncompliant {{Bind template variable "apiVersion" to a method parameter.}}
String variableAtDifferentIndices() {
return "";
}
}

@RequestMapping("/api")
static class TypeLevelPathController {

@GetMapping(value = "/v{apiVersion}/resource/{id}", version = "2")
String valid(@PathVariable String id) {
return id;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class TestClasspathUtils {
public static final Module JAVA_17_MODULE = new Module("java-checks-test-sources/java-17");
public static final Module SPRING_32_MODULE = new Module("java-checks-test-sources/spring-3.2");
public static final Module SPRING_WEB_40_MODULE = new Module("java-checks-test-sources/spring-web-4.0");
public static final Module SPRING_WEB_70_MODULE = new Module("java-checks-test-sources/spring-web-7.0");
private static final Path testJarsPath = Path.of("java-checks-test-sources/target/test-jars");

public static List<File> getTestJars(List<String> jars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void test_modules_path() {
assertThat(Path.of(TestClasspathUtils.JAVA_17_MODULE.getPath())).exists();
assertThat(Path.of(TestClasspathUtils.SPRING_32_MODULE.getPath())).exists();
assertThat(Path.of(TestClasspathUtils.SPRING_WEB_40_MODULE.getPath())).exists();
assertThat(Path.of(TestClasspathUtils.SPRING_WEB_70_MODULE.getPath())).exists();

TestClasspathUtils.Module unknowModule = new TestClasspathUtils.Module("unknow");
assertThat(unknowModule.getPath()).isNull();
Expand All @@ -60,6 +61,7 @@ void test_modules_classpath() {
assertThat(TestClasspathUtils.JAVA_17_MODULE.getClassPath()).hasSizeGreaterThan(5);
assertThat(TestClasspathUtils.SPRING_32_MODULE.getClassPath()).hasSizeGreaterThan(15);
assertThat(TestClasspathUtils.SPRING_WEB_40_MODULE.getClassPath()).hasSizeGreaterThan(5);
assertThat(TestClasspathUtils.SPRING_WEB_70_MODULE.getClassPath()).hasSizeGreaterThan(5);

TestClasspathUtils.Module unknowModule = new TestClasspathUtils.Module("unknow");
assertThat(unknowModule.getClassPath()).isEmpty();
Expand Down
Loading