Skip to content

Commit

Permalink
SONARJAVA-5138 [Support Java 22] Update Eclipse Compiler for Java 3.3…
Browse files Browse the repository at this point in the history
…9.0 (#4894)
  • Loading branch information
alban-auzeill authored Oct 9, 2024
1 parent 6ec169b commit d91fd85
Show file tree
Hide file tree
Showing 41 changed files with 672 additions and 246 deletions.
28 changes: 14 additions & 14 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ container_definition: &CONTAINER_DEFINITION

container_with_docker_definition: &CONTAINER_WITH_DOCKER_DEFINITION
<<: *CONTAINER_DEFINITION
dockerfile: .cirrus/Dockerfile.jdk17And21
dockerfile: .cirrus/Dockerfile.jdk17AndLatest
builder_role: cirrus-builder
builder_image: docker-builder-v*
builder_instance_type: t3.small
Expand All @@ -52,7 +52,7 @@ only_sonarsource_qa: &ONLY_SONARSOURCE_QA
common_build_definition: &COMMON_BUILD_DEFINITION
eks_container:
<<: *CONTAINER_DEFINITION
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j21-latest
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j22-latest
cpu: 4
memory: 4G
env:
Expand Down Expand Up @@ -113,7 +113,7 @@ ws_scan_task:
whitesource_script:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- mvn clean install -Dmaven.test.skip=true -pl '!java-checks-test-sources,!java-checks-test-sources/default,!java-checks-test-sources/aws,!java-checks-test-sources/spring-3.2'
- mvn clean install --batch-mode -Dmaven.test.skip=true -pl '!java-checks-test-sources,!java-checks-test-sources/default,!java-checks-test-sources/aws,!java-checks-test-sources/spring-3.2'
- source ws_scan.sh
allow_failures: "true"
always:
Expand All @@ -122,7 +122,7 @@ ws_scan_task:

qa_os_win_task:
ec2_instance:
image: base-windows-jdk21-v*
image: base-windows-jdk22-v*
<<: *WINDOWS_VM_DEFINITION
maven_cache:
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
Expand Down Expand Up @@ -159,7 +159,7 @@ plugin_qa_task:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd its/plugin
- mvn package -Pit-plugin -Dsonar.runtimeVersion=${SQ_VERSION} -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=classes -DuseUnlimitedThreads=true
- mvn package --batch-mode -Pit-plugin -Dsonar.runtimeVersion=${SQ_VERSION} -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=classes -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository

sanity_task:
Expand All @@ -168,7 +168,7 @@ sanity_task:
<<: *ONLY_SONARSOURCE_QA
eks_container:
<<: *CONTAINER_DEFINITION
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j21-latest
image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j22-latest
cpu: 4
memory: 4G
maven_cache:
Expand All @@ -177,9 +177,9 @@ sanity_task:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd java-checks-test-sources
- mvn clean compile
- mvn clean compile --batch-mode
- cd ../
- mvn verify -f sonar-java-plugin/pom.xml -Psanity -Dtest=SanityTest
- mvn verify --batch-mode -f sonar-java-plugin/pom.xml -Psanity -Dtest=SanityTest
cleanup_before_cache_script: cleanup_maven_repository

ruling_task:
Expand Down Expand Up @@ -207,7 +207,7 @@ ruling_task:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd its/ruling
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[10.3] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[10.3] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository
on_failure:
actual_artifacts:
Expand Down Expand Up @@ -236,7 +236,7 @@ ruling_win_task:
- init_git_submodules its/sources
- git submodule update --init --recursive
- cd its/ruling
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[10.3] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
- mvn package --batch-mode "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[10.3] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository

autoscan_task:
Expand All @@ -246,9 +246,9 @@ autoscan_task:
eks_container:
<<: *CONTAINER_WITH_DOCKER_DEFINITION
# For now, this autoscan_task need to execute two mvn commands:
# * The build of java-checks-test-sources module which requires Java 21.
# * The tests using Orchestrator and SonarQube that, for now, fail to work using Java 21
# This is why we have a local Dockerfile that provide the 2 versions of Java, 17 and 21.
# * The build of java-checks-test-sources module which requires Java 22.
# * The tests using Orchestrator and SonarQube that, for now, fail to work using Java 22
# This is why we have a local Dockerfile that provide the 2 versions of Java, 17 and 22.
cpu: 14
memory: 6G
maven_cache:
Expand All @@ -260,7 +260,7 @@ autoscan_task:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd java-checks-test-sources
- JAVA_HOME="${JAVA_21_HOME}" mvn clean compile
- JAVA_HOME="${JAVA_LATEST_HOME}" mvn clean compile --batch-mode
- cd ../its/autoscan
- mvn clean package --batch-mode --errors --show-version --activate-profiles it-autoscan -Dsonar.runtimeVersion=LATEST_RELEASE[10.3] -Dmaven.test.redirectTestOutputToFile=false -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository
Expand Down
58 changes: 0 additions & 58 deletions .cirrus/Dockerfile.jdk17And21

This file was deleted.

50 changes: 50 additions & 0 deletions .cirrus/Dockerfile.jdk17AndLatest
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ARG CIRRUS_AWS_ACCOUNT=275878209202
FROM ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest

LABEL maintainer="JVM Squad at SonarSource"

USER root

ENV DEBIAN_FRONTEND=noninteractive

# The current image is `FROM public.ecr.aws/docker/library/eclipse-temurin:17-jammy`
# Use a similar method to install Java 22 copied from https://github.com/adoptium/containers/blob/main/22/jdk/ubuntu/jammy/Dockerfile

ENV JAVA_LATEST_HOME /opt/java/openjdk22
ENV JAVA_LATEST_VERSION jdk-22.0.2+9

RUN set -eux; \
ARCH="$(dpkg --print-architecture)"; \
case "${ARCH}" in \
amd64) \
ESUM='05cd9359dacb1a1730f7c54f57e0fed47942a5292eb56a3a0ee6b13b87457a43'; \
BINARY_URL='https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.2%2B9/OpenJDK22U-jdk_x64_linux_hotspot_22.0.2_9.tar.gz'; \
;; \
arm64) \
ESUM='dac62747b5158c4bf4c4636432e3bdb9dea47f80f0c9d1d007f19bd5483b7d29'; \
BINARY_URL='https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.2%2B9/OpenJDK22U-jdk_aarch64_linux_hotspot_22.0.2_9.tar.gz'; \
;; \
*) \
echo "Unsupported arch: ${ARCH}"; \
exit 1; \
;; \
esac; \
wget --progress=dot:giga -O /tmp/openjdk.tar.gz ${BINARY_URL}; \
echo "${ESUM} */tmp/openjdk.tar.gz" | sha256sum -c -; \
mkdir -p "${JAVA_LATEST_HOME}"; \
tar --extract \
--file /tmp/openjdk.tar.gz \
--directory "${JAVA_LATEST_HOME}" \
--strip-components 1 \
--no-same-owner \
; \
rm -f /tmp/openjdk.tar.gz "${JAVA_LATEST_HOME}/lib/src.zip"; \
# https://github.com/docker-library/openjdk/issues/331#issuecomment-498834472
find "${JAVA_LATEST_HOME}/lib" -name '*.so' -exec dirname '{}' ';' | sort -u > /etc/ld.so.conf.d/docker-openjdk.conf; \
ldconfig; \
# https://github.com/docker-library/openjdk/issues/212#issuecomment-420979840
# https://openjdk.java.net/jeps/341
java -Xshare:dump;

USER sonarsource
WORKDIR /home/sonarsource
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void javaCheckTestSources() throws Exception {
.setSourceEncoding("UTF-8")
.setSourceDirs("aws/src/main/java/,default/src/main/java/,java-17/src/main/java/,spring-3.2/src/main/java/")
.setTestDirs("default/src/test/java/,test-classpath-reader/src/test/java")
.setProperty("sonar.java.source", "21")
.setProperty("sonar.java.source", "22")
// common properties
.setProperty("sonar.cpd.exclusions", "**/*")
.setProperty("sonar.skipPackageDesign", "true")
Expand Down
8 changes: 4 additions & 4 deletions java-checks-test-sources/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.10</version>
<version>1.9.22.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -1009,9 +1009,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>21</release>
<source>21</source>
<target>21</target>
<release>22</release>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ void doStuff() {
}

java.util.List<B> listOfB = java.util.Collections.singletonList(new B());
for (B b : listOfB) {
for (B _ : listOfB) {
}
for (A a : listOfB) {
for (A _ : listOfB) {
}
for (A a : listOfB) { // Noncompliant {{Change "A" to the type handled by the Collection.}}
// ^ ^^^^^^^<
B b = (B) a;
}
for (Object o : listOfB) {
for (Object _ : listOfB) {
}
for (Object o : listOfB) { // Noncompliant {{Change "Object" to the type handled by the Collection.}}
B b = (B) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void test() {
// edit@qf_supertype2 [[sc=40;ec=72]] {{TestObject::foo}}
Optional.of(new TestInteger()).map(testInteger -> TestNumber.foo(testInteger)); // Compliant, method reference is ambiguous
Optional.of(new TestInteger()).map(testInteger -> testInteger.spam()); // Compliant, method reference is ambiguous
Optional.of(new TestInteger()).map(testInteger -> (foo().length() % 23 == 0 ? testInteger : null).spam(testInteger)); // Compliant, method reference is ambiguous
Optional.of(new TestInteger()).map(testInteger -> (foo().length() % 23 == 0 ? testInteger : (TestObject) null).spam(testInteger)); // Compliant, method reference is ambiguous
Optional.of(new TestInteger()).map(testInteger -> testInteger.eggs()); // Compliant, method reference is ambiguous
consumeBoth((testInteger, s) -> testInteger.bar(s)); // Noncompliant [[quickfixes=qf_2args]]
// ^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void coverage(Object o, int i) {
}
switch (o) {
case Long l when l == 1 -> System.out.println("long");
case Double d -> System.out.println("double");
case String s -> System.out.println("string");
case Double _ -> System.out.println("double");
case String _ -> System.out.println("string");
default -> System.out.println("many");
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ void foo(Object o) {
default -> System.out.println("many");
}
}
case Integer i -> {
case Integer _ -> {
}
case String s -> {
if (s.length() == 2) { // Noncompliant {{Replace this "if" statement with a pattern match guard.}}
Expand Down
Loading

0 comments on commit d91fd85

Please sign in to comment.