Skip to content

Commit

Permalink
[NO JIRA] Split java-checks into 2 modules to improve goals caching
Browse files Browse the repository at this point in the history
* Extract AWS checks and test sources into separate modules

* disable background build scan uploading for CI and capture goal input files
  • Loading branch information
leveretka authored Nov 16, 2023
1 parent ac75ee7 commit 295074d
Show file tree
Hide file tree
Showing 2,395 changed files with 2,804 additions and 1,122 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ sanity_task:
sanity_script:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- mvn clean install -Dmaven.test.skip=true
- mvn verify -f java-checks/pom.xml -Psanity -Dtest=SanityTest
- mvn clean install -DskipTests=true
- mvn verify -f sonar-java-plugin/pom.xml -Psanity -Dtest=SanityTest
cleanup_before_cache_script: cleanup_maven_repository

ruling_task:
Expand Down
6 changes: 6 additions & 0 deletions .mvn/gradle-enterprise.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
</remote>
<requireClean>false</requireClean>
</buildCache>
<buildScan>
<backgroundBuildScanUpload>#{env['CIRRUS_CI'] == null}</backgroundBuildScanUpload>
<capture>
<goalInputFiles>true</goalInputFiles>
</capture>
</buildScan>
</gradleEnterprise>
4 changes: 2 additions & 2 deletions its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public void javaCheckTestSources() throws Exception {
.setProjectName(PROJECT_NAME)
.setProjectVersion("0.1.0-SNAPSHOT")
.setSourceEncoding("UTF-8")
.setSourceDirs("src/main/java/")
.setTestDirs("src/test/java/")
.setSourceDirs("aws/src/main/java/,default/src/main/java/")
.setTestDirs("default/src/test/java/")
.setProperty("sonar.java.source", "17")
// common properties
.setProperty("sonar.cpd.exclusions", "**/*")
Expand Down
6 changes: 3 additions & 3 deletions its/ruling/src/test/resources/autoscan/diffs/diff_S1181.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ruleKey": "S1181",
"hasTruePositives": false,
"falseNegatives": 10,
"hasTruePositives": true,
"falseNegatives": 2,
"falsePositives": 0
}
}
140 changes: 140 additions & 0 deletions java-checks-aws/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonarsource.java</groupId>
<artifactId>java</artifactId>
<version>7.29.0-SNAPSHOT</version>
</parent>

<artifactId>java-checks-aws</artifactId>

<name>SonarQube Java :: AWS Checks</name>

<dependencies>
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api-test-fixtures</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>java-frontend</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>java-checks-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>java-checks-testkit</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>sonar-analyzer-recognizers</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<executions>
<execution>
<id>forbid-junit4</id>
<goals>
<goal>testCheck</goal>
</goals>
<configuration>
<signaturesFiles>
<signaturesFile>../forbid_junit4.txt</signaturesFile>
</signaturesFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<!-- Tests HttpRequestsHotspotCheck_java9.java and HttpRequestsHotspotCheck_java10.java require the jdk.incubator.httpclient module,
as the module is not part of java standard modules, it needs to be added to maven-surefire-plugin when compiling/running tests with JDK 9 or JDK 10 -->
<profiles>
<profile>
<id>jdk-9-10</id>
<activation>
<jdk>[9,11)</jdk>
</activation>
<properties>
<argLine>-Xmx512m --add-modules jdk.incubator.httpclient</argLine>
</properties>
</profile>
<profile>
<id>sanity</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<force.sanity.test>true</force.sanity.test>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SonarQube Java
* Copyright (C) 2012-2023 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 GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.java.checks.security;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SonarQube Java
* Copyright (C) 2012-2023 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 GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.java.checks;

import org.sonar.java.checks.verifier.FilesUtils;

import java.io.File;
import java.util.List;
import java.util.Optional;

public class CommonConstants {

public static final String AWS_MODULE = "aws";

public static final String AWS_TEST_JARS_DIRECTORY = "../java-checks-test-sources/aws/target/test-jars";
public static final String AWS_TEST_CLASSES_DIRECTORY = "../java-checks-test-sources/aws/target/classes";


public static final List<File> AWS_CLASSPATH = FilesUtils.getClassPath(AWS_TEST_JARS_DIRECTORY);

static {
Optional.of(new File(AWS_TEST_CLASSES_DIRECTORY)).filter(File::exists).ifPresent(AWS_CLASSPATH::add);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.verifier.TestUtils.nonCompilingTestSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;
import static org.sonar.java.checks.verifier.TestUtils.nonCompilingTestSourcesPathInModule;

class AwsConsumerBuilderUsageCheckTest {

@Test
void test() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/aws/AwsConsumerBuilderUsageCheck.java"))
.onFile(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsConsumerBuilderUsageCheck.java"))
.withCheck(new AwsConsumerBuilderUsageCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}

@Test
void non_compiling() {
CheckVerifier.newVerifier()
.onFile(nonCompilingTestSourcesPath("checks/aws/AwsConsumerBuilderUsageCheck.java"))
.onFile(nonCompilingTestSourcesPathInModule(AWS_MODULE, "checks/aws/AwsConsumerBuilderUsageCheck.java"))
.withCheck(new AwsConsumerBuilderUsageCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;


class AwsCredentialsShouldBeSetExplicitlyCheckTest {
@Test
void test() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/aws/AwsCredentialsShouldBeSetExplicitlyCheck.java"))
.onFile(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsCredentialsShouldBeSetExplicitlyCheck.java"))
.withCheck(new AwsCredentialsShouldBeSetExplicitlyCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;

class AwsLambdaSyncCallCheckTest {

@Test
void test() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/aws/AwsLambdaSyncCallCheck.java"))
.onFile(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsLambdaSyncCallCheck.java"))
.withCheck(new AwsLambdaSyncCallCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;

class AwsLongTermAccessKeysCheckTest {
@Test
void test() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/aws/AwsLongTermAccessKeysCheck.java"))
.onFile(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsLongTermAccessKeysCheck.java"))
.withCheck(new AwsLongTermAccessKeysCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;

class AwsRegionSetterCheckTest {

@Test
void test() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/aws/AwsRegionSetterCheck.java"))
.onFile(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsRegionSetterCheck.java"))
.withCheck(new AwsRegionSetterCheck())
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
import org.junit.jupiter.api.Test;
import org.sonar.java.checks.verifier.CheckVerifier;

import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPath;
import static org.sonar.java.checks.CommonConstants.AWS_CLASSPATH;
import static org.sonar.java.checks.CommonConstants.AWS_MODULE;
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;

class AwsRegionShouldBeSetExplicitlyCheckTest {
@Test
void test() {
CheckVerifier.newVerifier()
.withCheck(new AwsRegionShouldBeSetExplicitlyCheck())
.onFiles(mainCodeSourcesPath("checks/aws/AwsRegionShouldBeSetExplicitlyCheck.java"))
.onFiles(mainCodeSourcesPathInModule(AWS_MODULE, "checks/aws/AwsRegionShouldBeSetExplicitlyCheck.java"))
.withClassPath(AWS_CLASSPATH)
.verifyIssues();
}
}
Loading

0 comments on commit 295074d

Please sign in to comment.