Skip to content

Commit

Permalink
Issue #502: update to LTS 9.9; cleanup deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Mar 2, 2024
1 parent 8462c9e commit a5cde4e
Show file tree
Hide file tree
Showing 43 changed files with 353 additions and 1,165 deletions.
73 changes: 8 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,17 @@
version: 2

jobs:
build-project:
sonarcloud:
docker:
- image: cimg/openjdk:11.0.16
- image: cimg/openjdk:17.0

steps:
- checkout
- run: mvn -e --no-transfer-progress package -Pno-validations
- persist_to_workspace:
root: /home/circleci
paths:
- project

execute-sonar:
docker:
- image: sonarqube:9.0-community
working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m

steps:
- attach_workspace:
at: /root
- run: |
sudo apt-get update
sudo apt-get install -y jq
- run:
name: Install packages
command: apk add maven
- run:
name: Copy jar
command: |
cp /root/project/target/checkstyle-sonar-plugin*.jar \
/opt/sonarqube/extensions/plugins/
- run:
name: Start SonarQube web service and execute maven SonarQube build
command: |
# start SonarQube web server
cd /opt/sonarqube/
./bin/run.sh &
until grep "SonarQube is up" logs/sonar.log; \
do sleep 10 && echo "Waiting for web server to come up..."; \
done
# Note that we cannot separate "start SonarQube web server" above from
# this step, as we would kill web server when step is complete.
cd /root/project
mvn -e --no-transfer-progress sonar:sonar -Dsonar.login=admin -Dsonar.password=admin
- store_artifacts:
path: /root/project/target/sonar/checkstyle-result.xml
- run:
name: Check logs for error
command: grep "ERROR" /opt/sonarqube/logs/* || test $? = 1

sonarqube:
docker:
- image: checkstyle/jdk-11-groovy-git-mvn:11.0.13__3.0.9__2.25.1__3.6.3

steps:
- checkout
- run: apt-get install -y jq
- run:
name: Run sonarqube
name: Run Sonarcloud analysis
command: |
export PR_NUMBER=$CIRCLE_PR_NUMBER
export PR_BRANCH_NAME=$CIRCLE_BRANCH
Expand All @@ -71,15 +21,8 @@ jobs:
workflows:
version: 2

sonarqube:
sonarcloud-analysis:
jobs:
- sonarqube:
- sonarcloud:
context:
- sonarqube

build-sonar:
jobs:
- build-project
- execute-sonar:
requires:
- build-project
94 changes: 73 additions & 21 deletions .github/workflows/sonar-checkstyle-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,88 @@ on:
pull_request:

jobs:
mvn-install-java-11:
mvn-install:
name: Maven Install
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
java-version: ['11', '17']

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 11
- name: install
run: "./.ci/ci.sh install"
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

- run: "./.ci/ci.sh install"

# depreacted for now since SQ removed the application ZIP files needed for the integration tests
# integration-tests:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Set up JDK 11
# uses: actions/setup-java@v1
# with:
# java-version: 11
# - name: run integration tests
# run: "./.ci/ci.sh integration-tests"

integration-tests:
nondex:
name: Maven Nondex
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
java-version: ['11', '17']

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 11
- name: run integration tests
run: "./.ci/ci.sh integration-tests"
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

nondex:
- run: "./.ci/ci.sh nondex"

execute-sonarqube-plugin:
name: Execute SonarQube Plugin
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 11
- name: install
run: "./.ci/ci.sh nondex"
java-version: '17'
distribution: 'temurin'

- name: Build Jar
run: mvn -e --no-transfer-progress package -Pno-validations

- name: Run SonarQube
run: docker run -d --name sonarqube -p 9000:9000 -v ${{ github.workspace }}/repo/target/:/opt/sonarqube/extensions/plugins/ sonarqube:9.9-community
- name: Check SonarQube is Up
run: |
while [[ ! `curl -s http://localhost:9000/api/system/status` =~ "UP" ]]; do
echo "Waiting for web server to come up..."
sleep 10
done
- name: Execute SonarQube analysis
run: |
mvn -e --no-transfer-progress sonar:sonar -Dsonar.login=admin -Dsonar.password=admin
- name: Check logs for error
run: docker logs sonarqube | grep "ERROR" || test $? = 1

- name: Cleanup
run: docker stop sonarqube
2 changes: 1 addition & 1 deletion config/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<allow class="com.puppycrawl.tools.checkstyle.api.AuditEvent"/>
<allow class="com.puppycrawl.tools.checkstyle.api.AuditListener"/>
<allow class="com.puppycrawl.tools.checkstyle.api.AutomaticBean"/>
<allow class="com.puppycrawl.tools.checkstyle.AbstractAutomaticBean"/>
<allow class="com.puppycrawl.tools.checkstyle.api.CheckstyleException"/>
<allow class="com.puppycrawl.tools.checkstyle.api.Configuration"/>
<allow class="com.puppycrawl.tools.checkstyle.api.SeverityLevel"/>
Expand Down
3 changes: 0 additions & 3 deletions config/sevntu-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<suppress checks="AvoidModifiersForTypes" files=".*[\\/]src[\\/]main[\\/]"/>
<!-- END of legacy code -->


<!-- parsing of xml imply reference attribute names, does not make sense to move all to special variables -->
<suppress checks="MultipleStringLiteralsExtended" files="CheckstyleProfileImporter\.java"/>
<!-- till https://github.com/checkstyle/sonar-checkstyle/issues/135 -->
<suppress checks="MultipleStringLiteralsExtended" files="CheckstylePlugin\.java"/>

Expand Down
2 changes: 0 additions & 2 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<suppress checks="IllegalCatch" files=".*[\\/]src[\\/]main[\\/]"/>
<!-- END of legacy code -->

<!-- parsing of xml imply reference attribute names, does not make sense to move all to special variables -->
<suppress checks="MultipleStringLiterals" files="CheckstyleProfileImporter\.java"/>
<!-- till https://github.com/checkstyle/sonar-checkstyle/issues/135 -->
<suppress checks="MultipleStringLiterals" files=".*[\\/]CheckstylePlugin\.java"/>
<!-- messing test code with such optimization does not make sense , readability will decrease -->
Expand Down
34 changes: 11 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@

<properties>
<checkstyle.version>10.12.5</checkstyle.version>
<sonar.version>8.9.0.43852</sonar.version>
<sonar-java.version>7.2.0.26923</sonar-java.version>
<sonar.version>9.9.4.87374</sonar.version>
<sonar.api-version>9.9.0.229</sonar.api-version>
<maven.sevntu.checkstyle.plugin.version>1.44.1</maven.sevntu.checkstyle.plugin.version>
<!-- it should be a version of checkstyle that is compatible/compiled with sevntu -->
<maven.sevntu.checkstyle.plugin.checkstyle.version>
Expand Down Expand Up @@ -158,9 +158,9 @@
<version>32.0.0-jre</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.version}</version>
<version>${sonar.api-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -558,6 +558,13 @@
<goal>report</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
Expand All @@ -573,7 +580,6 @@
<exclude>org.sonar.plugins.checkstyle.CheckstyleExecutor</exclude>
<exclude>org.sonar.plugins.checkstyle.CheckstyleSeverityUtils</exclude>
<exclude>org.sonar.plugins.checkstyle.CheckstyleConfiguration</exclude>
<exclude>org.sonar.plugins.checkstyle.CheckstyleProfileImporter</exclude>
<exclude>org.sonar.plugins.checkstyle.CheckstyleRulesDefinition</exclude>
<exclude>org.sonar.plugins.checkstyle.metadata.CheckstyleMetadata</exclude>
<exclude>org.sonar.plugins.checkstyle.metadata.CheckUtil</exclude>
Expand Down Expand Up @@ -682,24 +688,6 @@
</limit>
</limits>
</rule>
<rule>
<element>CLASS</element>
<includes>
<include>org.sonar.plugins.checkstyle.CheckstyleProfileImporter</include>
</includes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>1.0</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.96</minimum>
</limit>
</limits>
</rule>
<rule>
<element>CLASS</element>
<includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ExtensionPoint;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRule;
Expand All @@ -34,6 +33,7 @@
import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.batch.sensor.issue.NewIssueLocation;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.scanner.ScannerSide;

import com.google.common.annotations.VisibleForTesting;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ExtensionPoint;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.scanner.ScannerSide;

import com.google.common.annotations.VisibleForTesting;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
Expand All @@ -59,6 +59,17 @@ public class CheckstyleConfiguration {
private final FileSystem fileSystem;

public CheckstyleConfiguration(
org.sonar.api.config.Configuration conf,
ActiveRules activeRules,
FileSystem fileSystem) {
this.conf = conf;
confExporter = new CheckstyleProfileExporter(conf);
this.activeRules = activeRules;
this.fileSystem = fileSystem;
}

// used for unit testing
protected CheckstyleConfiguration(
org.sonar.api.config.Configuration conf,
CheckstyleProfileExporter confExporter,
ActiveRules activeRules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.ExtensionPoint;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.scanner.ScannerSide;

import com.google.common.annotations.VisibleForTesting;
import com.puppycrawl.tools.checkstyle.AbstractAutomaticBean;
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;

@ExtensionPoint
@ScannerSide
Expand Down Expand Up @@ -98,16 +97,16 @@ private void executeWithClassLoader() {
LOG.info("Checkstyle output report: {}", xmlReport.getAbsolutePath());
xmlOutput = FileUtils.openOutputStream(xmlReport);
checker.addListener(
new XMLLogger(xmlOutput, AutomaticBean.OutputStreamOptions.CLOSE));
new XMLLogger(xmlOutput, AbstractAutomaticBean.OutputStreamOptions.CLOSE));
}

checker.setCharset(configuration.getCharset().name());
checker.configure(configuration.getCheckstyleConfiguration());
checker.process(configuration
.getSourceFiles()
.stream()
.map(InputFile::file)
.collect(Collectors.toList()));
.stream()
.map(inputFile -> new File(inputFile.uri()))
.collect(Collectors.toList()));
}
catch (Exception ex) {
throw new IllegalStateException("Can not execute Checkstyle", ex);
Expand Down
Loading

0 comments on commit a5cde4e

Please sign in to comment.