From 417fcdff6d906d42520070236a7858d469044275 Mon Sep 17 00:00:00 2001
From: Tomasz Strzelecki
Date: Fri, 25 Oct 2024 15:03:39 +0200
Subject: [PATCH] Fix SonarLint support
---
README.md | 3 +-
local-docker-image/conf/sonar.properties | 449 ++++++++++++++++++
local-docker-image/docker-compose.yml | 4 +-
pom.xml | 36 +-
.../com/vml/aemrules/AemRulesSonarPlugin.java | 14 +-
.../vml/aemrules/htl/HtlFilesAnalyzer.java | 4 +-
.../java/com/vml/aemrules/htl/HtlProfile.java | 8 +-
.../aemrules/htl/checks/CamelCaseCheck.java | 3 +-
.../PlaceTemplatesInSeparateFilesCheck.java | 2 +-
.../aemrules/htl/lex/AbstractTokenizer.java | 36 +-
.../aemrules/htl/lex/CommentTokenizer.java | 5 +-
.../aemrules/htl/lex/ElementTokenizer.java | 12 +-
.../com/vml/aemrules/htl/lex/HtlLexer.java | 7 +-
.../vml/aemrules/htl/lex/TextTokenizer.java | 11 +-
.../rules/HtlRulesDefinition.java} | 27 +-
...HtlCheckClasses.java => HtlRulesList.java} | 4 +-
.../AdministrativeAccessUsageCheck.java | 14 +-
.../checks/AnnotationsConstantsCheck.java | 17 +-
.../aemrules/java/checks/ConstantsCheck.java | 17 +-
...ntentResourceShouldBeNullCheckedCheck.java | 14 +-
.../checks/ModifiableValueMapUsageCheck.java | 17 +-
.../checks/PreferSlingServletAnnotation.java | 13 +-
.../java/checks/SessionShouldBeLoggedOut.java | 17 +-
.../checks/SynchronizedKeywordUsageCheck.java | 22 +-
.../java/checks/ThreadSafeFieldCheck.java | 16 +-
.../aemrules/java/checks/package-info.java | 20 +
.../close/ResourceResolverShouldBeClosed.java | 17 +-
...ResourceResolverTryWithResourcesCheck.java | 24 +-
.../resourceresolver/close/package-info.java | 20 +
...faultInjectionStrategyAnnotationCheck.java | 17 +-
.../java/checks/slingmodels/package-info.java | 20 +
.../SlingQueryImplicitStrategyCheck.java | 13 +-
.../java/checks/slingquery/package-info.java | 20 +
.../java/checks/visitors/package-info.java | 20 +
.../aemrules/java/rules/JavaCheckClasses.java | 91 ----
.../java/rules/JavaCheckRegistrar.java | 67 +++
.../java/rules/JavaRulesDefinition.java | 49 ++
.../aemrules/java/rules/JavaRulesList.java | 78 +++
.../vml/aemrules/java/rules/package-info.java | 20 +
.../vml/aemrules/java/util/package-info.java | 20 +
.../vml/aemrules/matcher/package-info.java | 20 +
.../vml/aemrules/metadata/package-info.java | 20 +
.../java/com/vml/aemrules/package-info.java | 20 +
.../com/vml/aemrules/rules/package-info.java | 20 +
src/main/java/com/vml/aemrules/tag/Tags.java | 4 -
.../com/vml/aemrules/tag/package-info.java | 20 +
.../com/vml/aemrules/utils/package-info.java | 20 +
.../vml/aemrules/version/package-info.java | 20 +
src/main/resources/metadata/AEM-19.json | 5 -
.../sonar/l10n/java/rules/java/AEM-1.html} | 14 +-
.../org/sonar/l10n/java/rules/java/AEM-1.json | 14 +
.../sonar/l10n/java/rules/java/AEM-11.html | 37 ++
.../sonar/l10n/java/rules/java/AEM-11.json | 14 +
.../sonar/l10n/java/rules/java/AEM-15.html} | 61 ++-
.../sonar/l10n/java/rules/java/AEM-15.json | 15 +
.../sonar/l10n/java/rules/java/AEM-16.html} | 18 +-
.../sonar/l10n/java/rules/java/AEM-16.json | 15 +
.../sonar/l10n/java/rules/java/AEM-17.html | 29 ++
.../sonar/l10n/java/rules/java/AEM-17.json | 14 +
.../sonar/l10n/java/rules/java/AEM-18.html | 37 ++
.../sonar/l10n/java/rules/java/AEM-18.json | 14 +
.../sonar/l10n/java/rules/java/AEM-19.html | 23 +
.../sonar/l10n/java/rules/java/AEM-19.json | 14 +
.../sonar/l10n/java/rules/java/AEM-2.html} | 14 +-
.../org/sonar/l10n/java/rules/java/AEM-2.json | 14 +
.../sonar/l10n/java/rules/java/AEM-20.html | 36 ++
.../sonar/l10n/java/rules/java/AEM-20.json | 14 +
.../org/sonar/l10n/java/rules/java/AEM-3.html | 30 ++
.../org/sonar/l10n/java/rules/java/AEM-3.json | 15 +
.../sonar/l10n/java/rules/java/AEM-6.html} | 28 +-
.../org/sonar/l10n/java/rules/java/AEM-6.json | 14 +
.../sonar/l10n/java/rules/java/AEM-7.html} | 19 +-
.../org/sonar/l10n/java/rules/java/AEM-7.json | 14 +
.../sonar/l10n/java/rules/java/AEM-8.html} | 15 +-
.../org/sonar/l10n/java/rules/java/AEM-8.json | 14 +
src/main/resources/rules/AEM-11.md | 30 --
src/main/resources/rules/AEM-17.md | 28 --
src/main/resources/rules/AEM-18.md | 37 --
src/main/resources/rules/AEM-19.md | 23 -
src/main/resources/rules/AEM-20.md | 34 --
src/main/resources/rules/AEM-3.md | 24 -
.../java/AdministrativeAccessUsageCheck.java | 0
.../java/AnnotationsConstantsCheck.java | 0
.../java/AutoclosableResourceResolver.java | 0
.../java/ConstantsCheck.java | 0
...ntentResourceShouldBeNullCheckedCheck.java | 0
...faultInjectionStrategyAnnotationCheck.java | 0
...tegyAnnotationCheckMultipleAdaptables.java | 0
...LongResourceResolverEvenListenerError.java | 0
.../java/LongSessionEventListener.java | 0
.../java/LongSessionEventListenerError.java | 0
.../java/LongSessionService.java | 0
.../java/ModifiableValueMapUsageCheck.java | 0
.../java/ResourceResolverConsumer.java | 0
.../java/SampleServlet.java | 0
.../java/SessionLogoutEight.java | 0
.../java/SessionLogoutFive.java | 0
.../java/SessionLogoutFour.java | 0
.../java/SessionLogoutOne.java | 0
.../java/SessionLogoutSeven.java | 0
.../java/SessionLogoutSix.java | 0
.../java/SessionLogoutThree.java | 0
.../java/SessionLogoutTwo.java | 0
.../java/SlingQueryImplicitStrategyCheck.java | 0
.../java/SlingServletOne.java | 0
.../java/SlingServletThree.java | 0
.../java/SlingServletTwo.java | 0
.../SlingServletWithStandardAnnotations.java | 0
.../java/SynchronizedKeywordUsageCheck.java | 0
...adSafeFieldCheckDsComponentAnnotation.java | 0
.../ThreadSafeFieldCheckEventHandler.java | 0
.../java/ThreadSafeFieldCheckFilter.java | 0
...dSafeFieldCheckScrComponentAnnotation.java | 0
.../java/ThreadSafeFieldCheckServlet.java | 0
...dSafeFieldCheckSlingServletAnnotation.java | 0
.../vml/aemrules/AemRulesSonarPluginTest.java | 2 +-
.../vml/aemrules/htl/AbstractBaseTest.java | 6 +-
.../com/vml/aemrules/htl/HtlSensorTest.java | 10 +-
.../AdministrativeAccessUsageCheckTest.java | 2 +-
.../checks/AnnotationsConstantsCheckTest.java | 2 +-
.../java/checks/ConstantsCheckTest.java | 2 +-
...tResourceShouldBeNullCheckedCheckTest.java | 2 +-
...tInjectionStrategyAnnotationCheckTest.java | 4 +-
.../ModifiableValueMapUsageCheckTest.java | 2 +-
.../PreferSlingServletAnnotationTest.java | 8 +-
.../ResourceResolverShouldBeClosedTest.java | 10 +-
.../ResourceResolverTryWithResourcesTest.java | 2 +-
.../checks/SessionShouldBeLoggedOutTest.java | 20 +-
.../SlingQueryImplicitStrategyCheckTest.java | 2 +-
.../SynchronizedKeywordUsageCheckTest.java | 2 +-
.../java/checks/ThreadSafeFieldCheckTest.java | 12 +-
.../vml/aemrules/rules/RulesLoaderTest.java | 21 +-
...esLoaderTest.RuleWithOnlyNameAttribute.md} | 0
133 files changed, 1571 insertions(+), 677 deletions(-)
create mode 100644 local-docker-image/conf/sonar.properties
rename src/main/java/com/vml/aemrules/{rules/AemRulesRulesDefinition.java => htl/rules/HtlRulesDefinition.java} (51%)
rename src/main/java/com/vml/aemrules/htl/rules/{HtlCheckClasses.java => HtlRulesList.java} (98%)
create mode 100644 src/main/java/com/vml/aemrules/java/checks/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/java/checks/slingmodels/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/java/checks/slingquery/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/java/checks/visitors/package-info.java
delete mode 100644 src/main/java/com/vml/aemrules/java/rules/JavaCheckClasses.java
create mode 100644 src/main/java/com/vml/aemrules/java/rules/JavaCheckRegistrar.java
create mode 100644 src/main/java/com/vml/aemrules/java/rules/JavaRulesDefinition.java
create mode 100644 src/main/java/com/vml/aemrules/java/rules/JavaRulesList.java
create mode 100644 src/main/java/com/vml/aemrules/java/rules/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/java/util/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/matcher/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/metadata/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/rules/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/tag/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/utils/package-info.java
create mode 100644 src/main/java/com/vml/aemrules/version/package-info.java
delete mode 100644 src/main/resources/metadata/AEM-19.json
rename src/main/resources/{rules/AEM-1.md => org/sonar/l10n/java/rules/java/AEM-1.html} (69%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-1.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-11.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-11.json
rename src/main/resources/{rules/AEM-15.md => org/sonar/l10n/java/rules/java/AEM-15.html} (53%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.json
rename src/main/resources/{rules/AEM-16.md => org/sonar/l10n/java/rules/java/AEM-16.html} (62%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-17.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-17.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-18.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-18.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-19.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-19.json
rename src/main/resources/{rules/AEM-2.md => org/sonar/l10n/java/rules/java/AEM-2.html} (80%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-2.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-20.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-20.json
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-3.html
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-3.json
rename src/main/resources/{rules/AEM-6.md => org/sonar/l10n/java/rules/java/AEM-6.html} (53%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-6.json
rename src/main/resources/{rules/AEM-7.md => org/sonar/l10n/java/rules/java/AEM-7.html} (55%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-7.json
rename src/main/resources/{rules/AEM-8.md => org/sonar/l10n/java/rules/java/AEM-8.html} (72%)
create mode 100644 src/main/resources/org/sonar/l10n/java/rules/java/AEM-8.json
delete mode 100644 src/main/resources/rules/AEM-11.md
delete mode 100644 src/main/resources/rules/AEM-17.md
delete mode 100644 src/main/resources/rules/AEM-18.md
delete mode 100644 src/main/resources/rules/AEM-19.md
delete mode 100644 src/main/resources/rules/AEM-20.md
delete mode 100644 src/main/resources/rules/AEM-3.md
rename src/test/{resources => files}/java/AdministrativeAccessUsageCheck.java (100%)
rename src/test/{resources => files}/java/AnnotationsConstantsCheck.java (100%)
rename src/test/{resources => files}/java/AutoclosableResourceResolver.java (100%)
rename src/test/{resources => files}/java/ConstantsCheck.java (100%)
rename src/test/{resources => files}/java/ContentResourceShouldBeNullCheckedCheck.java (100%)
rename src/test/{resources => files}/java/DefaultInjectionStrategyAnnotationCheck.java (100%)
rename src/test/{resources => files}/java/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java (100%)
rename src/test/{resources => files}/java/LongResourceResolverEvenListenerError.java (100%)
rename src/test/{resources => files}/java/LongSessionEventListener.java (100%)
rename src/test/{resources => files}/java/LongSessionEventListenerError.java (100%)
rename src/test/{resources => files}/java/LongSessionService.java (100%)
rename src/test/{resources => files}/java/ModifiableValueMapUsageCheck.java (100%)
rename src/test/{resources => files}/java/ResourceResolverConsumer.java (100%)
rename src/test/{resources => files}/java/SampleServlet.java (100%)
rename src/test/{resources => files}/java/SessionLogoutEight.java (100%)
rename src/test/{resources => files}/java/SessionLogoutFive.java (100%)
rename src/test/{resources => files}/java/SessionLogoutFour.java (100%)
rename src/test/{resources => files}/java/SessionLogoutOne.java (100%)
rename src/test/{resources => files}/java/SessionLogoutSeven.java (100%)
rename src/test/{resources => files}/java/SessionLogoutSix.java (100%)
rename src/test/{resources => files}/java/SessionLogoutThree.java (100%)
rename src/test/{resources => files}/java/SessionLogoutTwo.java (100%)
rename src/test/{resources => files}/java/SlingQueryImplicitStrategyCheck.java (100%)
rename src/test/{resources => files}/java/SlingServletOne.java (100%)
rename src/test/{resources => files}/java/SlingServletThree.java (100%)
rename src/test/{resources => files}/java/SlingServletTwo.java (100%)
rename src/test/{resources => files}/java/SlingServletWithStandardAnnotations.java (100%)
rename src/test/{resources => files}/java/SynchronizedKeywordUsageCheck.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckDsComponentAnnotation.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckEventHandler.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckFilter.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckScrComponentAnnotation.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckServlet.java (100%)
rename src/test/{resources => files}/java/ThreadSafeFieldCheckSlingServletAnnotation.java (100%)
rename src/test/resources/rules/{com.cognifide.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute.md => com.vml.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute.md} (100%)
diff --git a/README.md b/README.md
index 7447050d..8e5606e7 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,7 @@
![Builds Status](https://github.com/wttech/AEM-Rules-for-SonarQube/actions/workflows/build.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/Cognifide/AEM-Rules-for-SonarQube/badge.svg?branch=master)](https://coveralls.io/github/Cognifide/AEM-Rules-for-SonarQube?branch=master)
+[](https://www.sonarlint.org/)
[](https://sonarcloud.io)
[](https://www.sonarqube.org/)
# About AEM Rules for SonarQube
@@ -46,8 +47,6 @@ Use of the plugin does not differ much from regular SonarQube analysis. However,
Each rule defines supported AEM version or version range. Most of the rules are universal.
-Rules are not available in [](https://www.sonarlint.org/)
-
### Running analysis
When running analysis, pass `sonarRunner.aemVersion` property with your AEM version. The format is as follows:
diff --git a/local-docker-image/conf/sonar.properties b/local-docker-image/conf/sonar.properties
new file mode 100644
index 00000000..e431a470
--- /dev/null
+++ b/local-docker-image/conf/sonar.properties
@@ -0,0 +1,449 @@
+#
+# #%L
+# AEM Rules for SonarQube
+# %%
+# Copyright (C) 2015-2024 VML
+# %%
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# #L%
+#
+
+#--------------------------------------------------------------------------------------------------
+# IMPORTANT:
+# This file will *not* be reloaded upon hitting the "Restart" button in the UI, or using the
+# api/system/restart endpoint.
+# In order for any change made to this file to be taken into account, you must perform a full
+# restart of the main SonarQube service.
+#--------------------------------------------------------------------------------------------------
+
+# Property values can:
+# - be overridden by environment variables. The name of the corresponding environment variable is the
+# upper-cased name of the property where all the dot ('.') and dash ('-') characters are replaced by
+# underscores ('_'). For example, to override 'sonar.web.systemPasscode' use 'SONAR_WEB_SYSTEMPASSCODE'.
+# - be encrypted. See https://docs.sonarqube.org/latest/instance-administration/security/#settings-encryption
+
+#--------------------------------------------------------------------------------------------------
+# DATABASE
+#
+# IMPORTANT:
+# - The embedded H2 database is used by default. It is recommended for tests but not for
+# production use. Supported databases are Oracle, PostgreSQL and Microsoft SQLServer.
+# - Changes to database connection URL (sonar.jdbc.url) can affect SonarSource licensed products.
+
+# User credentials.
+# Permissions to create tables, indices and triggers must be granted to JDBC user.
+# The schema must be created first.
+#sonar.jdbc.username=
+#sonar.jdbc.password=
+
+#----- Embedded Database (default)
+# H2 embedded database server listening port, defaults to 9092
+#sonar.embeddedDatabase.port=9092
+
+
+#----- Oracle 19c/21c
+# The Oracle JDBC driver must be copied into the directory extensions/jdbc-driver/oracle/.
+# Only the thin client is supported, and we recommend using the latest Oracle JDBC driver. See
+# https://jira.sonarsource.com/browse/SONAR-9758 for more details.
+# If you need to set the schema, please refer to http://jira.sonarsource.com/browse/SONAR-5000
+#sonar.jdbc.url=jdbc:oracle:thin:@localhost:1521/XE
+
+
+#----- PostgreSQL 11 or greater
+# By default the schema named "public" is used. It can be overridden with the parameter "currentSchema".
+#sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube?currentSchema=my_schema
+
+
+#----- Microsoft SQLServer 2014/2016/2017/2019/2022 and SQL Azure
+# A database named sonar must exist and its collation must be case-sensitive (CS) and accent-sensitive (AS)
+# Use the following connection string if you want to use integrated security with Microsoft Sql Server
+# Do not set sonar.jdbc.username or sonar.jdbc.password property if you are using Integrated Security
+# For Integrated Security to work, you have to download the Microsoft SQL JDBC Auth 11.2.2 package from
+# https://github.com/microsoft/mssql-jdbc/releases/download/v11.2.2/mssql-jdbc_auth.zip
+# and 'mssql-jdbc_auth-11.2.2.x64.dll' to your path.
+#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar;integratedSecurity=true
+
+# Use the following connection string if you want to use SQL Auth while connecting to MS Sql Server.
+# Set the sonar.jdbc.username and sonar.jdbc.password appropriately.
+#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
+
+
+#----- Connection pool settings
+# The maximum number of active connections that can be allocated
+# at the same time, or negative for no limit.
+# The recommended value is 1.2 * max sizes of HTTP pools. For example if HTTP ports are
+# enabled with default sizes (50, see property sonar.web.http.maxThreads)
+# then sonar.jdbc.maxActive should be 1.2 * 50 = 60.
+#sonar.jdbc.maxActive=60
+
+# The minimum number of connections that can remain idle in the pool,
+# without extra ones being created, or zero to create none.
+#sonar.jdbc.minIdle=10
+
+# The maximum number of milliseconds that the pool will wait (when there
+# are no available connections) for a connection to be returned before
+# throwing an exception, or <= 0 to wait indefinitely.
+#sonar.jdbc.maxWait=8000
+
+
+#--------------------------------------------------------------------------------------------------
+# WEB SERVER
+# Web server is executed in a dedicated Java process. By default heap size is 512MB.
+# Use the following property to customize JVM options.
+# Recommendations:
+#
+# The HotSpot Server VM is recommended. The property -server should be added if server mode
+# is not enabled by default on your environment:
+# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
+#
+# Startup can be long if entropy source is short of entropy. Adding
+# -Djava.security.egd=file:/dev/./urandom is an option to resolve the problem.
+# See https://wiki.apache.org/tomcat/HowTo/FasterStartUp#Entropy_Source
+#
+#sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
+
+# Same as previous property, but allows to not repeat all other settings like -Xmx
+#sonar.web.javaAdditionalOpts=
+
+# Binding IP address. For servers with more than one IP address, this property specifies which
+# address will be used for listening on the specified ports.
+# By default, ports will be used on all IP addresses associated with the server.
+#sonar.web.host=0.0.0.0
+
+# Web context. When set, it must start with forward slash (for example /sonarqube).
+# Changing this value and restarting the server can have unexpected consequences for logged in users,
+# as they may end up with multiple conflicting browser cookies. If your users experience odd
+# behaviors after you changed this value and restarted the server, ask them to clear their browser's
+# cookies and log in again.
+# The default value is root context (empty value).
+#sonar.web.context=
+# TCP port for incoming HTTP connections. Default value is 9000.
+#sonar.web.port=9000
+
+
+# The maximum number of connections that the server will accept and process at any given time.
+# When this number has been reached, the server will not accept any more connections until
+# the number of connections falls below this value. The operating system may still accept connections
+# based on the sonar.web.connections.acceptCount property. The default value is 50.
+#sonar.web.http.maxThreads=50
+
+# The minimum number of threads always kept running. The default value is 5.
+#sonar.web.http.minThreads=5
+
+# The maximum queue length for incoming connection requests when all possible request processing
+# threads are in use. Any requests received when the queue is full will be refused.
+# The default value is 25.
+#sonar.web.http.acceptCount=25
+
+# The number of milliseconds this Connector will wait for another HTTP request before closing the
+# connection. The default value is to use the value that has been set for the connectionTimeout
+# attribute. Use a value of -1 to indicate no (i.e. infinite) timeout.
+# The default value is 60000 (ms).
+#sonar.web.http.keepAliveTimeout=60000
+
+# By default users are logged out and sessions closed when server is restarted.
+# If you prefer keeping user sessions open, a secret should be defined. Value is
+# HS256 key encoded with base64. It must be unique for each installation of SonarQube.
+# Example of command-line:
+# echo -n "type_what_you_want" | openssl dgst -sha256 -hmac "key" -binary | base64
+#sonar.auth.jwtBase64Hs256Secret=
+
+# The inactivity timeout duration of user sessions, in minutes. After the configured
+# period of time, the user is logged out.
+# The default value is set to 3 days (4320 minutes).
+# It must be set between 6 minutes and 3 months (129600 minutes).
+# Value must be strictly positive.
+#sonar.web.sessionTimeoutInMinutes=4320
+
+# A passcode can be defined to access some web services from monitoring
+# tools without having to use the credentials of a system administrator.
+# Check the Web API documentation to know which web services are supporting this authentication mode.
+# The passcode should be provided in HTTP requests with the header "X-Sonar-Passcode".
+# By default feature is disabled.
+#sonar.web.systemPasscode=
+
+
+#--------------------------------------------------------------------------------------------------
+# SSO AUTHENTICATION
+
+# Enable authentication using HTTP headers
+#sonar.web.sso.enable=false
+
+# Name of the header to get the user login.
+# Only alphanumeric, '.' and '@' characters are allowed
+#sonar.web.sso.loginHeader=X-Forwarded-Login
+
+# Name of the header to get the user name
+#sonar.web.sso.nameHeader=X-Forwarded-Name
+
+# Name of the header to get the user email (optional)
+#sonar.web.sso.emailHeader=X-Forwarded-Email
+
+# Name of the header to get the list of user groups, separated by comma (optional).
+# If the sonar.sso.groupsHeader is set, the user will belong to those groups if groups exist in SonarQube.
+# If none of the provided groups exists in SonarQube, the user will only belong to the default group.
+# Note that the default group will always be set.
+#sonar.web.sso.groupsHeader=X-Forwarded-Groups
+
+# Interval used to know when to refresh name, email and groups.
+# During this interval, if for instance the name of the user is changed in the header, it will only be updated after X minutes.
+#sonar.web.sso.refreshIntervalInMinutes=5
+
+#--------------------------------------------------------------------------------------------------
+# LDAP CONFIGURATION
+
+# Enable the LDAP feature
+# sonar.security.realm=LDAP
+
+# Set to true when connecting to a LDAP server using a case-insensitive setup.
+# sonar.authenticator.downcase=true
+
+# URL of the LDAP server. Note that if you are using ldaps, then you should install the server certificate into the Java truststore.
+# ldap.url=ldap://localhost:10389
+
+# Bind DN is the username of an LDAP user to connect (or bind) with. Leave this blank for anonymous access to the LDAP directory (optional)
+# ldap.bindDn=cn=sonar,ou=users,o=mycompany
+
+# Bind Password is the password of the user to connect with. Leave this blank for anonymous access to the LDAP directory (optional)
+# ldap.bindPassword=secret
+
+# Possible values: simple | CRAM-MD5 | DIGEST-MD5 | GSSAPI See http://java.sun.com/products/jndi/tutorial/ldap/security/auth.html (default: simple)
+# ldap.authentication=simple
+
+# See :
+# * http://java.sun.com/products/jndi/tutorial/ldap/security/digest.html
+# * http://java.sun.com/products/jndi/tutorial/ldap/security/crammd5.html
+# (optional)
+# ldap.realm=example.org
+
+# Context factory class (optional)
+# ldap.contextFactoryClass=com.sun.jndi.ldap.LdapCtxFactory
+
+# Enable usage of StartTLS (default : false)
+# ldap.StartTLS=true
+
+# Follow or not referrals. See http://docs.oracle.com/javase/jndi/tutorial/ldap/referral/jndi.html (default: true)
+# ldap.followReferrals=false
+
+# USER MAPPING
+
+# Distinguished Name (DN) of the root node in LDAP from which to search for users (mandatory)
+# ldap.user.baseDn=cn=users,dc=example,dc=org
+
+# LDAP user request. (default: (&(objectClass=inetOrgPerson)(uid={login})) )
+# ldap.user.request=(&(objectClass=user)(sAMAccountName={login}))
+
+# Attribute in LDAP defining the user?s real name. (default: cn)
+# ldap.user.realNameAttribute=name
+
+# Attribute in LDAP defining the user?s email. (default: mail)
+# ldap.user.emailAttribute=email
+
+# GROUP MAPPING
+
+# Distinguished Name (DN) of the root node in LDAP from which to search for groups. (optional, default: empty)
+# ldap.group.baseDn=cn=groups,dc=example,dc=org
+
+# LDAP group request (default: (&(objectClass=groupOfUniqueNames)(uniqueMember={dn})) )
+# ldap.group.request=(&(objectClass=group)(member={dn}))
+
+# Property used to specifiy the attribute to be used for returning the list of user groups in the compatibility mode. (default: cn)
+# ldap.group.idAttribute=sAMAccountName
+
+#--------------------------------------------------------------------------------------------------
+# COMPUTE ENGINE
+# The Compute Engine is responsible for processing background tasks.
+# Compute Engine is executed in a dedicated Java process. Default heap size is 512MB.
+# Use the following property to customize JVM options.
+# Recommendations:
+#
+# The HotSpot Server VM is recommended. The property -server should be added if server mode
+# is not enabled by default on your environment:
+# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
+#
+#sonar.ce.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
+
+# Same as previous property, but allows to not repeat all other settings like -Xmx
+#sonar.ce.javaAdditionalOpts=
+
+
+#--------------------------------------------------------------------------------------------------
+# ELASTICSEARCH
+# Elasticsearch is used to facilitate fast and accurate information retrieval.
+# It is executed in a dedicated Java process. Default maximum heap size is 512MB.
+# It is recommended to also set MaxDirectMemorySize (-XX:MaxDirectMemorySize) and set it to half the maximum heap size.
+#
+# --------------------------------------------------
+# Word of caution for Linux users on 64bits systems
+# --------------------------------------------------
+# Please ensure Virtual Memory on your system is correctly configured for Elasticsearch to run properly
+# (see https://www.elastic.co/guide/en/elasticsearch/reference/5.5/vm-max-map-count.html for details).
+#
+# When SonarQube runs standalone, a warning such as the following may appear in logs/es.log:
+# "max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]"
+# When SonarQube runs as a cluster, however, Elasticsearch will refuse to start.
+#
+
+# JVM options of Elasticsearch process
+#sonar.search.javaOpts=-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError
+
+# Same as previous property, but allows to not repeat all other settings like -Xmx
+#sonar.search.javaAdditionalOpts=
+
+# Elasticsearch port for incoming HTTP connections. Default is 9001. Use 0 to get a free port.
+# As a security precaution, should be blocked by a firewall and not exposed to the Internet.
+#sonar.search.port=9001
+
+# Elasticsearch TCP transport port that is bound to loopback address. When nothing is set, a random port will be chosen.
+# As a security precaution, your OS configuration should not expose this port for external access.
+#sonar.es.port=
+
+# Elasticsearch host. The search server will bind this address and the search client will connect to it.
+# Default is loopback address.
+# As a security precaution, should NOT be set to a publicly available address.
+#sonar.search.host=
+
+
+#--------------------------------------------------------------------------------------------------
+# UPDATE CENTER
+
+# Update Center requires an internet connection to request https://update.sonarsource.org
+# It is enabled by default.
+#sonar.updatecenter.activate=true
+
+# HTTP proxy (default none)
+#http.proxyHost=
+#http.proxyPort=
+# HTTPS proxy (defaults are values of http.proxyHost and http.proxyPort)
+#https.proxyHost=
+#https.proxyPort=
+
+# NT domain name if NTLM proxy is used
+#http.auth.ntlm.domain=
+
+# SOCKS proxy (default none)
+#socksProxyHost=
+#socksProxyPort=
+
+# Proxy authentication (used for HTTP, HTTPS and SOCKS proxies)
+#http.proxyUser=
+#http.proxyPassword=
+
+# Proxy exceptions: list of hosts that can be accessed without going through the proxy
+# separated by the '|' character, wildcard character '*' can be used for pattern matching
+# used for HTTP and HTTPS (default none)
+# (note: localhost and its literal notations (127.0.0.1, ...) are always excluded)
+#http.nonProxyHosts=
+
+
+#--------------------------------------------------------------------------------------------------
+# LOGGING
+
+# SonarQube produces logs in 4 logs files located in the same directory (see property sonar.path.logs below),
+# one per process:
+# Main process (aka. App) logs in sonar.log
+# Web Server (aka. Web) logs in web.log
+# Compute Engine (aka. CE) logs in ce.log
+# Elasticsearch (aka. ES) logs in es.log
+#
+# Depending on the startup, all 4 files follow the same rolling policy (see sonar.log.rollingPolicy and sonar.log.maxFiles) but it applies
+# individually (eg. if sonar.log.maxFiles=4, there can be at most 4 of each files, ie. 16 files in total).
+#
+# All 4 files have logs in the same format:
+# 1 2 3 4 5 6
+# |-----------------| |---| |-|--------------------||------------------------------| |------------------------------------------------------------------------------------------------------------------------------|
+# 2016.11.16 16:47:00 INFO ce[AVht0dNXFcyiYejytc3m][o.s.s.c.t.CeWorkerCallableImpl] Executed task | project=org.sonarqube:example-java-maven | type=REPORT | id=AVht0dNXFcyiYejytc3m | submitter=admin | time=1699ms
+#
+# 1: timestamp. Format is YYYY.MM.DD HH:MM:SS
+# YYYY: year on 4 digits
+# MM: month on 2 digits
+# DD: day on 2 digits
+# HH: hour of day on 2 digits in 24 hours format
+# MM: minutes on 2 digits
+# SS: seconds on 2 digits
+# 2: log level.
+# Possible values (in order of descending criticality): ERROR, WARN, INFO, DEBUG and TRACE
+# 3: process identifier. Possible values: app (main), web (Web Server), ce (Compute Engine) and es (Elasticsearch)
+# 4: SQ thread identifier. Can be empty.
+# In the Web Server, if present, it will be the HTTP request ID.
+# In the Compute Engine, if present, it will be the task ID.
+# 5: logger name. Usually a class canonical name.
+# Package names are truncated to keep the whole field to 20 characters max
+# 6: log payload. Content of this field does not follow any specific format, can vary in length and include line returns.
+# Some logs, however, will follow the convention to provide data in payload in the format " | key=value"
+# Especially, log of profiled pieces of code will end with " | time=XXXXms".
+
+# Global level of logs (applies to all 4 processes).
+# Supported values are INFO (default), DEBUG and TRACE
+#sonar.log.level=INFO
+
+# Level of logs of each process can be controlled individually with their respective properties.
+# When specified, they overwrite the level defined at global level.
+# Supported values are INFO, DEBUG and TRACE
+#sonar.log.level.app=INFO
+#sonar.log.level.web=INFO
+#sonar.log.level.ce=INFO
+#sonar.log.level.es=INFO
+
+# Path to log files. Can be absolute or relative to installation directory.
+# Default is /logs
+#sonar.path.logs=logs
+
+# Rolling policy of log files
+# - based on time if value starts with "time:", for example by day ("time:yyyy-MM-dd")
+# or by month ("time:yyyy-MM")
+# - based on size if value starts with "size:", for example "size:10MB"
+# - disabled if value is "none". That needs logs to be managed by an external system like logrotate.
+#sonar.log.rollingPolicy=time:yyyy-MM-dd
+
+# Maximum number of files to keep if a rolling policy is enabled.
+# - maximum value is 20 on size rolling policy
+# - unlimited on time rolling policy. Set to zero to disable old file purging.
+#sonar.log.maxFiles=7
+
+# Access log is the list of all the HTTP requests received by server. If enabled, it is stored
+# in the file {sonar.path.logs}/access.log. This file follows the same rolling policy as other log file
+# (see sonar.log.rollingPolicy and sonar.log.maxFiles).
+#sonar.web.accessLogs.enable=true
+
+# Format of access log. It is ignored if sonar.web.accessLogs.enable=false. Possible values are:
+# - "common" is the Common Log Format, shortcut to: %h %l %u %user %date "%r" %s %b
+# - "combined" is another format widely recognized, shortcut to: %h %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"
+# - else a custom pattern. See http://logback.qos.ch/manual/layouts.html#AccessPatternLayout.
+# The login of authenticated user is not implemented with "%u" but with "%reqAttribute{LOGIN}" (since version 6.1).
+# The value displayed for anonymous users is "-".
+# The SonarQube's HTTP request ID can be added to the pattern with "%reqAttribute{ID}" (since version 6.2).
+# If SonarQube is behind a reverse proxy, then the following value allows to display the correct remote IP address:
+#sonar.web.accessLogs.pattern=%i{X-Forwarded-For} %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}" "%reqAttribute{ID}"
+# Default value (which was "combined" before version 6.2) is equivalent to "combined + SQ HTTP request ID":
+#sonar.web.accessLogs.pattern=%h %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}" "%reqAttribute{ID}"
+
+
+#--------------------------------------------------------------------------------------------------
+# OTHERS
+
+# Delay in seconds between processing of notification queue. Default is 60 seconds.
+#sonar.notifications.delay=60
+
+# Paths to persistent data files (embedded database and search index) and temporary files.
+# Can be absolute or relative to installation directory.
+# Defaults are respectively /data and /temp
+#sonar.path.data=data
+#sonar.path.temp=temp
+
+# Telemetry - Share anonymous SonarQube statistics
+# By sharing anonymous SonarQube statistics, you help us understand how SonarQube is used so we can improve the product to work even better for you.
+# We don't collect source code or IP addresses. And we don't share the data with anyone else.
+#sonar.telemetry.enable=true
+
+sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
diff --git a/local-docker-image/docker-compose.yml b/local-docker-image/docker-compose.yml
index 2a0dd27e..6ce85cef 100644
--- a/local-docker-image/docker-compose.yml
+++ b/local-docker-image/docker-compose.yml
@@ -22,11 +22,13 @@ name: sonar-local
services:
sonar-local:
- image: sonarqube:10.7.0-community
+ image: sonarqube:9.9-community
build:
context: .
ports:
- "9000:9000"
+ - "5005:5005"
restart: unless-stopped
volumes:
- ./extensions/plugins:/opt/sonarqube/extensions/plugins:ro
+ - ./conf:/opt/sonarqube/conf:ro
diff --git a/pom.xml b/pom.xml
index ace6bc35..a777dc7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,11 +106,11 @@
1.1.2-1.4.0
- 3.3.0.2534
+ 3.15.0.51077.30.1.34514UTF-8
- 10.11.0.2468
- 10.3.0.82913
+ 10.11.0.2468
+ 10.3.0.8291310.7.0.963277.30.1.3451411
@@ -136,7 +136,7 @@
sonar-plugin-apiorg.sonarsource.api.pluginprovided
- ${sonar.apiVersion}
+ ${sonar.pluginApiVersion}sonar-html-plugin
@@ -257,7 +257,7 @@
sonar-plugin-api-implorg.sonarsource.sonarqubetest
- ${sonar.apiImplVersion}
+ ${sonar.pluginApiImplVersion}java-checks-testkit
@@ -365,9 +365,28 @@
https://github.com/wttech/AEM-Rules-for-SonarQube/tree/${tagName}
https://github.com/wttech/AEM-Rules-for-SonarQube
- false
+ true
+ true
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+ org.apache.maven.pluginsmaven-compiler-plugin
@@ -414,11 +433,6 @@
**.xmlassets/**src/test/resources/htl/HtlCommentsCheck.html
- src/main/js/**
- conf/**
- scripts/**
- .cirrus.yml
- **.yml
diff --git a/src/main/java/com/vml/aemrules/AemRulesSonarPlugin.java b/src/main/java/com/vml/aemrules/AemRulesSonarPlugin.java
index 12084013..19a08295 100644
--- a/src/main/java/com/vml/aemrules/AemRulesSonarPlugin.java
+++ b/src/main/java/com/vml/aemrules/AemRulesSonarPlugin.java
@@ -23,8 +23,9 @@
import com.vml.aemrules.htl.Htl;
import com.vml.aemrules.htl.HtlProfile;
import com.vml.aemrules.htl.HtlSensor;
-import com.vml.aemrules.java.rules.JavaCheckClasses;
-import com.vml.aemrules.rules.AemRulesRulesDefinition;
+import com.vml.aemrules.htl.rules.HtlRulesDefinition;
+import com.vml.aemrules.java.rules.JavaCheckRegistrar;
+import com.vml.aemrules.java.rules.JavaRulesDefinition;
import org.sonar.api.Plugin;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.resources.Qualifiers;
@@ -57,12 +58,17 @@ private static List pluginProperties() {
@Override
public void define(Context context) {
+ context.addExtensions(
+ JavaRulesDefinition.class,
+ JavaCheckRegistrar.class
+ );
+
context.addExtensions(
Htl.class,
- AemRulesRulesDefinition.class,
- JavaCheckClasses.class,
+ HtlRulesDefinition.class,
HtlProfile.class,
HtlSensor.class);
+
context.addExtensions(pluginProperties());
}
}
diff --git a/src/main/java/com/vml/aemrules/htl/HtlFilesAnalyzer.java b/src/main/java/com/vml/aemrules/htl/HtlFilesAnalyzer.java
index f98536c7..3ce8f836 100644
--- a/src/main/java/com/vml/aemrules/htl/HtlFilesAnalyzer.java
+++ b/src/main/java/com/vml/aemrules/htl/HtlFilesAnalyzer.java
@@ -20,7 +20,7 @@
package com.vml.aemrules.htl;
import com.vml.aemrules.htl.api.ParsingErrorRule;
-import com.vml.aemrules.htl.rules.HtlCheckClasses;
+import com.vml.aemrules.htl.rules.HtlRulesList;
import com.vml.aemrules.utils.Throwables;
import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException;
import org.sonar.api.batch.fs.InputFile;
@@ -46,7 +46,7 @@ public abstract class HtlFilesAnalyzer {
public HtlFilesAnalyzer(CheckFactory checkFactory) {
this.checks = HtlChecks.createHtlCheck(checkFactory)
- .addChecks(HtlCheckClasses.REPOSITORY_KEY, HtlCheckClasses.getCheckClasses());
+ .addChecks(HtlRulesList.REPOSITORY_KEY, HtlRulesList.getCheckClasses());
this.parsingErrorRuleKey = setupParsingErrorRuleKey(checks);
}
diff --git a/src/main/java/com/vml/aemrules/htl/HtlProfile.java b/src/main/java/com/vml/aemrules/htl/HtlProfile.java
index c36b8458..9d975421 100644
--- a/src/main/java/com/vml/aemrules/htl/HtlProfile.java
+++ b/src/main/java/com/vml/aemrules/htl/HtlProfile.java
@@ -19,7 +19,7 @@
*/
package com.vml.aemrules.htl;
-import com.vml.aemrules.htl.rules.HtlCheckClasses;
+import com.vml.aemrules.htl.rules.HtlRulesList;
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition;
import org.sonar.check.Rule;
@@ -33,11 +33,11 @@ public class HtlProfile implements BuiltInQualityProfilesDefinition {
public void define(Context context) {
NewBuiltInQualityProfile htl = context
.createBuiltInQualityProfile(QUALITY_PROFILE_NAME, Htl.KEY);
- HtlCheckClasses.getCheckClasses().stream()
- .map(HtlCheckClasses::getRule)
+ HtlRulesList.getCheckClasses().stream()
+ .map(HtlRulesList::getRule)
.map(Rule::key)
.filter(Objects::nonNull)
- .forEach(ruleKey -> htl.activateRule(HtlCheckClasses.REPOSITORY_KEY, ruleKey));
+ .forEach(ruleKey -> htl.activateRule(HtlRulesList.REPOSITORY_KEY, ruleKey));
htl.done();
}
}
diff --git a/src/main/java/com/vml/aemrules/htl/checks/CamelCaseCheck.java b/src/main/java/com/vml/aemrules/htl/checks/CamelCaseCheck.java
index e78adb2e..cbb399c2 100644
--- a/src/main/java/com/vml/aemrules/htl/checks/CamelCaseCheck.java
+++ b/src/main/java/com/vml/aemrules/htl/checks/CamelCaseCheck.java
@@ -23,7 +23,8 @@
import com.vml.aemrules.metadata.Metadata;
import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.scripting.sightly.compiler.expression.Expression;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
diff --git a/src/main/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheck.java b/src/main/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheck.java
index a67645aa..1f1c2473 100644
--- a/src/main/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheck.java
+++ b/src/main/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheck.java
@@ -22,7 +22,7 @@
import com.vml.aemrules.metadata.Metadata;
import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.scripting.sightly.compiler.expression.Expression;
import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier;
diff --git a/src/main/java/com/vml/aemrules/htl/lex/AbstractTokenizer.java b/src/main/java/com/vml/aemrules/htl/lex/AbstractTokenizer.java
index ba38f055..dd72a087 100644
--- a/src/main/java/com/vml/aemrules/htl/lex/AbstractTokenizer.java
+++ b/src/main/java/com/vml/aemrules/htl/lex/AbstractTokenizer.java
@@ -19,16 +19,18 @@
*/
package com.vml.aemrules.htl.lex;
-import org.sonar.channel.Channel;
-import org.sonar.channel.CodeReader;
-import org.sonar.channel.EndMatcher;
import org.sonar.plugins.html.node.Node;
+import org.sonar.sslr.channel.Channel;
+import org.sonar.sslr.channel.CodeReader;
+import org.sonar.sslr.channel.EndMatcher;
+import java.util.Arrays;
import java.util.List;
abstract class AbstractTokenizer> extends Channel {
private final char[] endChars;
+
private final char[] startChars;
public AbstractTokenizer(String startChars, String endChars) {
@@ -50,6 +52,16 @@ protected static boolean equalsIgnoreCase(char[] a, char[] b) {
return true;
}
+ protected static String popTo(CodeReader codeReader, EndMatcher endMatcher, StringBuilder stringBuilder) {
+ boolean shouldContinue = codeReader.peek() != -1;
+ while (shouldContinue) {
+ stringBuilder.append((char) codeReader.pop());
+ shouldContinue = !endMatcher.match(codeReader.peek()) && codeReader.peek() != -1;
+ }
+
+ return stringBuilder.toString();
+ }
+
protected void addNode(List nodeList, Node node) {
nodeList.add(node);
}
@@ -61,7 +73,7 @@ public boolean consume(CodeReader codeReader, T nodeList) {
setStartPosition(codeReader, node);
StringBuilder stringBuilder = new StringBuilder();
- codeReader.popTo(getEndMatcher(codeReader), stringBuilder);
+ popTo(codeReader, getEndMatcher(codeReader), stringBuilder);
for (int i = 0; i < endChars.length; i++) {
codeReader.pop(stringBuilder);
}
@@ -104,20 +116,22 @@ private EndTokenMatcher(CodeReader codeReader) {
@Override
public boolean match(int endFlag) {
- boolean result = false;
if (endFlag == '"') {
quoting = !quoting;
}
if (!quoting) {
- if (equalsIgnoreCase(codeReader.peek(startChars.length), startChars)) {
+ boolean started = equalsIgnoreCase(codeReader.peek(startChars.length), startChars);
+ if (started) {
nesting++;
- } else if (equalsIgnoreCase(codeReader.peek(endChars.length), endChars)) {
- nesting--;
- result = nesting < 0;
+ } else {
+ boolean ended = Arrays.equals(codeReader.peek(endChars.length), endChars);
+ if (ended) {
+ nesting--;
+ return nesting < 0;
+ }
}
}
-
- return result;
+ return false;
}
}
diff --git a/src/main/java/com/vml/aemrules/htl/lex/CommentTokenizer.java b/src/main/java/com/vml/aemrules/htl/lex/CommentTokenizer.java
index d3def5ea..eca3f259 100644
--- a/src/main/java/com/vml/aemrules/htl/lex/CommentTokenizer.java
+++ b/src/main/java/com/vml/aemrules/htl/lex/CommentTokenizer.java
@@ -19,10 +19,11 @@
*/
package com.vml.aemrules.htl.lex;
-import org.sonar.channel.CodeReader;
-import org.sonar.channel.EndMatcher;
+
import org.sonar.plugins.html.node.CommentNode;
import org.sonar.plugins.html.node.Node;
+import org.sonar.sslr.channel.CodeReader;
+import org.sonar.sslr.channel.EndMatcher;
import java.util.List;
diff --git a/src/main/java/com/vml/aemrules/htl/lex/ElementTokenizer.java b/src/main/java/com/vml/aemrules/htl/lex/ElementTokenizer.java
index 6e1d7b4b..88ba1f68 100644
--- a/src/main/java/com/vml/aemrules/htl/lex/ElementTokenizer.java
+++ b/src/main/java/com/vml/aemrules/htl/lex/ElementTokenizer.java
@@ -20,11 +20,11 @@
package com.vml.aemrules.htl.lex;
import org.apache.commons.lang3.StringUtils;
-import org.sonar.channel.CodeReader;
-import org.sonar.channel.EndMatcher;
import org.sonar.plugins.html.node.Attribute;
import org.sonar.plugins.html.node.Node;
import org.sonar.plugins.html.node.TagNode;
+import org.sonar.sslr.channel.CodeReader;
+import org.sonar.sslr.channel.EndMatcher;
import java.util.ArrayDeque;
import java.util.Deque;
@@ -77,13 +77,13 @@ private static void handleBeforeAttributeValue(CodeReader codeReader, TagNode el
if (isQuote((char) ch)) {
codeReader.pop();
if (codeReader.peek() != ch) {
- codeReader.popTo(new QuoteMatcher((char) ch), sbValue);
+ popTo(codeReader, new QuoteMatcher((char) ch), sbValue);
attribute.setValue(unescapeQuotes(sbValue.toString(), (char) ch));
}
codeReader.pop();
attribute.setQuoteChar((char) ch);
} else {
- codeReader.popTo(END_UNQUOTED_ATTRIBUTE_MATCHER, sbValue);
+ popTo(codeReader, END_UNQUOTED_ATTRIBUTE_MATCHER, sbValue);
attribute.setValue(sbValue.toString().trim());
}
}
@@ -92,7 +92,7 @@ private static void handleBeforeAttributeValue(CodeReader codeReader, TagNode el
private static void handleBeforeAttributeName(CodeReader codeReader, TagNode element) {
Attribute attribute;
StringBuilder sbQName = new StringBuilder();
- codeReader.popTo(END_Q_NAME_MATCHER, sbQName);
+ popTo(codeReader, END_Q_NAME_MATCHER, sbQName);
attribute = new Attribute(sbQName.toString().trim());
attribute.setLine(codeReader.getLinePosition() + element.getStartLinePosition() - 1);
element.getAttributes().add(attribute);
@@ -100,7 +100,7 @@ private static void handleBeforeAttributeName(CodeReader codeReader, TagNode ele
private static void handleBeforeNodeName(CodeReader codeReader, TagNode element) {
StringBuilder sbNodeName = new StringBuilder();
- codeReader.popTo(END_TOKEN_MATCHER, sbNodeName);
+ popTo(codeReader, END_TOKEN_MATCHER, sbNodeName);
element.setNodeName(sbNodeName.toString());
}
diff --git a/src/main/java/com/vml/aemrules/htl/lex/HtlLexer.java b/src/main/java/com/vml/aemrules/htl/lex/HtlLexer.java
index a2d59ce6..7da874ec 100644
--- a/src/main/java/com/vml/aemrules/htl/lex/HtlLexer.java
+++ b/src/main/java/com/vml/aemrules/htl/lex/HtlLexer.java
@@ -20,12 +20,13 @@
package com.vml.aemrules.htl.lex;
import org.apache.sling.scripting.sightly.impl.compiler.Syntax;
-import org.sonar.channel.Channel;
-import org.sonar.channel.ChannelDispatcher;
-import org.sonar.channel.CodeReader;
+
import org.sonar.plugins.html.node.Node;
import org.sonar.plugins.html.node.NodeType;
import org.sonar.plugins.html.node.TagNode;
+import org.sonar.sslr.channel.Channel;
+import org.sonar.sslr.channel.ChannelDispatcher;
+import org.sonar.sslr.channel.CodeReader;
import java.io.Reader;
import java.util.ArrayList;
diff --git a/src/main/java/com/vml/aemrules/htl/lex/TextTokenizer.java b/src/main/java/com/vml/aemrules/htl/lex/TextTokenizer.java
index 36f00e0a..2773f227 100644
--- a/src/main/java/com/vml/aemrules/htl/lex/TextTokenizer.java
+++ b/src/main/java/com/vml/aemrules/htl/lex/TextTokenizer.java
@@ -19,12 +19,13 @@
*/
package com.vml.aemrules.htl.lex;
-import org.sonar.channel.CodeReader;
-import org.sonar.channel.EndMatcher;
+
import org.sonar.plugins.html.node.Node;
import org.sonar.plugins.html.node.NodeType;
import org.sonar.plugins.html.node.TagNode;
import org.sonar.plugins.html.node.TextNode;
+import org.sonar.sslr.channel.CodeReader;
+import org.sonar.sslr.channel.EndMatcher;
import java.util.List;
@@ -53,9 +54,9 @@ public boolean consume(CodeReader codeReader, List nodeList) {
StringBuilder stringBuilder = new StringBuilder();
if (inScript(nodeList)) {
- codeReader.popTo(new EndScriptMatcher(codeReader), stringBuilder);
+ popTo(codeReader, new EndScriptMatcher(codeReader), stringBuilder);
} else {
- codeReader.popTo(new EndTokenMatcher(codeReader), stringBuilder);
+ popTo(codeReader, new EndTokenMatcher(codeReader), stringBuilder);
}
node.setCode(stringBuilder.toString());
setEndPosition(codeReader, node);
@@ -111,4 +112,4 @@ public boolean match(int endFlag) {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/vml/aemrules/rules/AemRulesRulesDefinition.java b/src/main/java/com/vml/aemrules/htl/rules/HtlRulesDefinition.java
similarity index 51%
rename from src/main/java/com/vml/aemrules/rules/AemRulesRulesDefinition.java
rename to src/main/java/com/vml/aemrules/htl/rules/HtlRulesDefinition.java
index 64b528d8..8339a8e4 100644
--- a/src/main/java/com/vml/aemrules/rules/AemRulesRulesDefinition.java
+++ b/src/main/java/com/vml/aemrules/htl/rules/HtlRulesDefinition.java
@@ -17,37 +17,22 @@
* limitations under the License.
* #L%
*/
-package com.vml.aemrules.rules;
+package com.vml.aemrules.htl.rules;
import com.vml.aemrules.htl.Htl;
-import com.vml.aemrules.htl.rules.HtlCheckClasses;
-import com.vml.aemrules.java.rules.JavaCheckClasses;
+import com.vml.aemrules.rules.RulesLoader;
import org.sonar.api.server.rule.RulesDefinition;
-public class AemRulesRulesDefinition implements RulesDefinition {
+public class HtlRulesDefinition implements RulesDefinition {
private static final RulesLoader rulesLoader = new RulesLoader();
@Override
public void define(Context context) {
- defineJavaRepository(context);
- defineHtlRepository(context);
- }
-
- private void defineHtlRepository(Context context) {
NewRepository repo = context
- .createRepository(HtlCheckClasses.REPOSITORY_KEY, Htl.KEY)
- .setName(HtlCheckClasses.REPOSITORY_NAME);
- rulesLoader.load(repo, HtlCheckClasses.getCheckClasses());
+ .createRepository(HtlRulesList.REPOSITORY_KEY, Htl.KEY)
+ .setName(HtlRulesList.REPOSITORY_NAME);
+ rulesLoader.load(repo, HtlRulesList.getCheckClasses());
repo.done();
}
-
- private void defineJavaRepository(Context context) {
- NewRepository repo = context
- .createRepository(JavaCheckClasses.REPOSITORY_KEY, "java")
- .setName(JavaCheckClasses.REPOSITORY_NAME);
- rulesLoader.load(repo, JavaCheckClasses.CHECK_CLASSES);
- repo.done();
- }
-
}
diff --git a/src/main/java/com/vml/aemrules/htl/rules/HtlCheckClasses.java b/src/main/java/com/vml/aemrules/htl/rules/HtlRulesList.java
similarity index 98%
rename from src/main/java/com/vml/aemrules/htl/rules/HtlCheckClasses.java
rename to src/main/java/com/vml/aemrules/htl/rules/HtlRulesList.java
index be2868f9..8926c63d 100644
--- a/src/main/java/com/vml/aemrules/htl/rules/HtlCheckClasses.java
+++ b/src/main/java/com/vml/aemrules/htl/rules/HtlRulesList.java
@@ -44,7 +44,7 @@
import java.util.List;
import java.util.Optional;
-public final class HtlCheckClasses {
+public final class HtlRulesList {
public static final String REPOSITORY_KEY = Htl.KEY;
@@ -70,7 +70,7 @@ public final class HtlCheckClasses {
ExplicitNamesInLoopsCheck.class
);
- private HtlCheckClasses() {
+ private HtlRulesList() {
//private constructor
}
diff --git a/src/main/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheck.java b/src/main/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheck.java
index 889f2aa5..4c955a8e 100644
--- a/src/main/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheck.java
@@ -41,18 +41,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-@Rule(
- key = AdministrativeAccessUsageCheck.RULE_KEY,
- name = AdministrativeAccessUsageCheck.RULE_MESSAGE,
- priority = Priority.MAJOR,
- tags = Tags.AEM
-)
-@AemVersion(
- from = "6.0"
-)
-@Metadata(
- technicalDebt = "30min"
-)
+@Rule(key = AdministrativeAccessUsageCheck.RULE_KEY)
+@AemVersion(from = "6.0")
public class AdministrativeAccessUsageCheck extends IssuableSubscriptionVisitor {
public static final String RULE_KEY = "AEM-11";
diff --git a/src/main/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheck.java b/src/main/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheck.java
index a978f089..06721772 100644
--- a/src/main/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheck.java
@@ -20,11 +20,8 @@
package com.vml.aemrules.java.checks;
import com.vml.aemrules.java.util.ConstantsChecker;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
import org.apache.commons.lang3.StringUtils;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -33,18 +30,8 @@
import org.sonar.plugins.java.api.tree.LiteralTree;
import org.sonar.plugins.java.api.tree.Tree.Kind;
-@Rule(
- key = AnnotationsConstantsCheck.RULE_KEY,
- name = AnnotationsConstantsCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "5min"
-)
+@Rule(key = AnnotationsConstantsCheck.RULE_KEY)
+@AemVersion(all = true)
public class AnnotationsConstantsCheck extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-1";
diff --git a/src/main/java/com/vml/aemrules/java/checks/ConstantsCheck.java b/src/main/java/com/vml/aemrules/java/checks/ConstantsCheck.java
index 0e8e4ea6..78f0bcc6 100644
--- a/src/main/java/com/vml/aemrules/java/checks/ConstantsCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/ConstantsCheck.java
@@ -20,11 +20,8 @@
package com.vml.aemrules.java.checks;
import com.vml.aemrules.java.util.ConstantsChecker;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
import org.apache.commons.lang3.StringUtils;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.LiteralTree;
@@ -33,18 +30,8 @@
import java.util.List;
-@Rule(
- key = ConstantsCheck.RULE_KEY,
- name = ConstantsCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "5min"
-)
+@Rule(key = ConstantsCheck.RULE_KEY)
+@AemVersion(all = true)
public class ConstantsCheck extends IssuableSubscriptionVisitor {
public static final String RULE_MESSAGE = "Use predefined constant instead of hardcoded value.";
diff --git a/src/main/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheck.java b/src/main/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheck.java
index f81934f8..177a2593 100644
--- a/src/main/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheck.java
@@ -47,18 +47,8 @@
import static org.sonar.plugins.java.api.tree.Tree.Kind.EQUAL_TO;
import static org.sonar.plugins.java.api.tree.Tree.Kind.NOT_EQUAL_TO;
-@Rule(
- key = ContentResourceShouldBeNullCheckedCheck.RULE_KEY,
- name = ContentResourceShouldBeNullCheckedCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "5min"
-)
+@Rule(key = ContentResourceShouldBeNullCheckedCheck.RULE_KEY)
+@AemVersion(all = true)
public class ContentResourceShouldBeNullCheckedCheck extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-18";
diff --git a/src/main/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheck.java b/src/main/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheck.java
index 2264c2c1..75de7bc6 100644
--- a/src/main/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheck.java
@@ -19,10 +19,7 @@
*/
package com.vml.aemrules.java.checks;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -40,18 +37,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-@Rule(
- key = ModifiableValueMapUsageCheck.RULE_KEY,
- name = ModifiableValueMapUsageCheck.RULE_MESSAGE,
- priority = Priority.CRITICAL,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "10min"
-)
+@Rule(key = ModifiableValueMapUsageCheck.RULE_KEY)
+@AemVersion(all = true)
public class ModifiableValueMapUsageCheck extends BaseTreeVisitor implements JavaFileScanner {
protected static final String RULE_KEY = "AEM-17";
diff --git a/src/main/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotation.java b/src/main/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotation.java
index a64512d6..70581e3b 100644
--- a/src/main/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotation.java
+++ b/src/main/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotation.java
@@ -19,11 +19,8 @@
*/
package com.vml.aemrules.java.checks;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
import org.apache.commons.lang3.StringUtils;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -46,19 +43,11 @@
import static org.sonar.plugins.java.api.tree.Tree.Kind.MEMBER_SELECT;
import static org.sonar.plugins.java.api.tree.Tree.Kind.STRING_LITERAL;
-@Rule(
- key = PreferSlingServletAnnotation.RULE_KEY,
- name = PreferSlingServletAnnotation.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = Tags.AEM
-)
+@Rule(key = PreferSlingServletAnnotation.RULE_KEY)
@AemVersion(
from = "6.0",
to = "6.2"
)
-@Metadata(
- technicalDebt = "10min"
-)
public class PreferSlingServletAnnotation extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-8";
diff --git a/src/main/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOut.java b/src/main/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOut.java
index d0a0169f..368fb6e1 100644
--- a/src/main/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOut.java
+++ b/src/main/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOut.java
@@ -22,10 +22,7 @@
import com.vml.aemrules.java.checks.visitors.CheckLoggedOutVisitor;
import com.vml.aemrules.java.checks.visitors.FinallyBlockVisitor;
import com.vml.aemrules.java.checks.visitors.FindSessionDeclarationVisitor;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -41,18 +38,8 @@
import java.util.List;
import java.util.Set;
-@Rule(
- key = SessionShouldBeLoggedOut.RULE_KEY,
- name = SessionShouldBeLoggedOut.RULE_MESSAGE,
- priority = Priority.CRITICAL,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "10min"
-)
+@Rule(key = SessionShouldBeLoggedOut.RULE_KEY)
+@AemVersion(all = true)
public class SessionShouldBeLoggedOut extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-7";
diff --git a/src/main/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheck.java b/src/main/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheck.java
index 93e823db..93bddd4e 100644
--- a/src/main/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheck.java
@@ -19,10 +19,7 @@
*/
package com.vml.aemrules.java.checks;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.BaseTreeVisitor;
@@ -35,26 +32,13 @@
import java.util.Arrays;
import java.util.List;
-@Rule(
- key = SynchronizedKeywordUsageCheck.RULE_KEY,
- name = SynchronizedKeywordUsageCheck.MESSAGE,
- description = SynchronizedKeywordUsageCheck.DESCRIPTION,
- priority = Priority.INFO,
- tags = {Tags.MULTI_THREADING, Tags.PERFORMANCE}
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "30min"
-)
+@Rule(key = SynchronizedKeywordUsageCheck.RULE_KEY)
+@AemVersion(all = true)
public class SynchronizedKeywordUsageCheck extends IssuableSubscriptionVisitor {
- protected static final String MESSAGE = "Usage of 'synchronized' keyword should be avoided if possible.";
-
protected static final String RULE_KEY = "AEM-15";
- protected static final String DESCRIPTION = "Check if using 'synchronized' can be replaced with more sophisticated solution.";
+ protected static final String MESSAGE = "Usage of 'synchronized' keyword should be avoided if possible.";
private static final List ACCEPTED_NODE_KINDS = Arrays.asList(Kind.SYNCHRONIZED_STATEMENT, Kind.METHOD);
diff --git a/src/main/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheck.java b/src/main/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheck.java
index 021fd09f..8446128e 100644
--- a/src/main/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheck.java
@@ -39,22 +39,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-@Rule(
- key = ThreadSafeFieldCheck.RULE_KEY,
- name = ThreadSafeFieldCheck.RULE_NAME,
- priority = Priority.CRITICAL,
- tags = {Tags.BUG, Tags.AEM}
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "1h"
-)
+@Rule(key = ThreadSafeFieldCheck.RULE_KEY)
+@AemVersion(all = true)
public class ThreadSafeFieldCheck extends BaseTreeVisitor implements JavaFileScanner {
- public static final String RULE_NAME = "Non-thread safe object used as a field of Servlet / Filter etc.";
-
public static final String RULE_KEY = "AEM-3";
public static final String RULE_MESSAGE = "Usage of %s as a field is not thread safe.";
diff --git a/src/main/java/com/vml/aemrules/java/checks/package-info.java b/src/main/java/com/vml/aemrules/java/checks/package-info.java
new file mode 100644
index 00000000..d3f88dcd
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/checks/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.checks;
diff --git a/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverShouldBeClosed.java b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverShouldBeClosed.java
index ab444913..2e09b020 100644
--- a/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverShouldBeClosed.java
+++ b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverShouldBeClosed.java
@@ -21,10 +21,7 @@
import com.vml.aemrules.java.checks.visitors.CheckClosedVisitor;
import com.vml.aemrules.java.checks.visitors.FinallyBlockVisitor;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -40,18 +37,8 @@
import java.util.List;
import java.util.Set;
-@Rule(
- key = ResourceResolverShouldBeClosed.RULE_KEY,
- name = ResourceResolverShouldBeClosed.RULE_MESSAGE,
- priority = Priority.CRITICAL,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "15min"
-)
+@Rule(key = ResourceResolverShouldBeClosed.RULE_KEY)
+@AemVersion(all = true)
public class ResourceResolverShouldBeClosed extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-6";
diff --git a/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverTryWithResourcesCheck.java b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverTryWithResourcesCheck.java
index 3f32ee95..2567fe35 100644
--- a/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverTryWithResourcesCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/ResourceResolverTryWithResourcesCheck.java
@@ -19,10 +19,7 @@
*/
package com.vml.aemrules.java.checks.resourceresolver.close;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -35,19 +32,8 @@
import java.util.ArrayList;
import java.util.List;
-@Rule(
- key = ResourceResolverTryWithResourcesCheck.RULE_KEY,
- name = ResourceResolverTryWithResourcesCheck.RULE_MESSAGE,
- priority = Priority.INFO,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "10min"
-)
-
+@Rule(key = ResourceResolverTryWithResourcesCheck.RULE_KEY)
+@AemVersion(all = true)
public class ResourceResolverTryWithResourcesCheck extends BaseTreeVisitor implements
JavaFileScanner {
@@ -56,15 +42,11 @@ public class ResourceResolverTryWithResourcesCheck extends BaseTreeVisitor imple
protected static final String RULE_MESSAGE = "ResourceResolver can be closed using try-with-resources Java 7 feature.";
private static final String SLING_RESOURCE_RESOLVER = "org.apache.sling.api.resource.ResourceResolver";
-
+ private final List resourceResolversInTryWithResources = new ArrayList<>();
private boolean insideTryStatement = false;
-
private boolean insideLambdaExpression = false;
-
private JavaFileScannerContext context;
- private final List resourceResolversInTryWithResources = new ArrayList<>();
-
public void scanFile(JavaFileScannerContext javaFileScannerContext) {
context = javaFileScannerContext;
scan(context.getTree());
diff --git a/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/package-info.java b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/package-info.java
new file mode 100644
index 00000000..9f0ac103
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/checks/resourceresolver/close/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.checks.resourceresolver.close;
diff --git a/src/main/java/com/vml/aemrules/java/checks/slingmodels/DefaultInjectionStrategyAnnotationCheck.java b/src/main/java/com/vml/aemrules/java/checks/slingmodels/DefaultInjectionStrategyAnnotationCheck.java
index 4f708434..9c3770aa 100644
--- a/src/main/java/com/vml/aemrules/java/checks/slingmodels/DefaultInjectionStrategyAnnotationCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/slingmodels/DefaultInjectionStrategyAnnotationCheck.java
@@ -19,10 +19,7 @@
*/
package com.vml.aemrules.java.checks.slingmodels;
-import com.vml.aemrules.metadata.Metadata;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -38,18 +35,8 @@
import java.util.List;
-@Rule(
- key = DefaultInjectionStrategyAnnotationCheck.RULE_KEY,
- name = DefaultInjectionStrategyAnnotationCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = {Tags.AEM, Tags.SLING_MODELS}
-)
-@AemVersion(
- all = true
-)
-@Metadata(
- technicalDebt = "5min"
-)
+@Rule(key = DefaultInjectionStrategyAnnotationCheck.RULE_KEY)
+@AemVersion(all = true)
public class DefaultInjectionStrategyAnnotationCheck extends BaseTreeVisitor implements JavaFileScanner {
public static final String RULE_KEY = "AEM-16";
diff --git a/src/main/java/com/vml/aemrules/java/checks/slingmodels/package-info.java b/src/main/java/com/vml/aemrules/java/checks/slingmodels/package-info.java
new file mode 100644
index 00000000..26194cfa
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/checks/slingmodels/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.checks.slingmodels;
diff --git a/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java b/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java
index 0c51517c..f2ec9f10 100644
--- a/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java
+++ b/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java
@@ -19,9 +19,7 @@
*/
package com.vml.aemrules.java.checks.slingquery;
-import com.vml.aemrules.tag.Tags;
import com.vml.aemrules.version.AemVersion;
-import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.JavaFileScanner;
import org.sonar.plugins.java.api.JavaFileScannerContext;
@@ -35,15 +33,8 @@
import java.util.HashMap;
import java.util.Map;
-@Rule(
- key = SlingQueryImplicitStrategyCheck.RULE_KEY,
- name = SlingQueryImplicitStrategyCheck.RULE_MESSAGE,
- priority = Priority.MINOR,
- tags = Tags.AEM
-)
-@AemVersion(
- all = true
-)
+@Rule(key = SlingQueryImplicitStrategyCheck.RULE_KEY)
+@AemVersion(all = true)
public class SlingQueryImplicitStrategyCheck extends BaseTreeVisitor implements JavaFileScanner {
protected static final String RULE_KEY = "AEM-19";
diff --git a/src/main/java/com/vml/aemrules/java/checks/slingquery/package-info.java b/src/main/java/com/vml/aemrules/java/checks/slingquery/package-info.java
new file mode 100644
index 00000000..3755e4b6
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/checks/slingquery/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.checks.slingquery;
diff --git a/src/main/java/com/vml/aemrules/java/checks/visitors/package-info.java b/src/main/java/com/vml/aemrules/java/checks/visitors/package-info.java
new file mode 100644
index 00000000..a8592450
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/checks/visitors/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.checks.visitors;
diff --git a/src/main/java/com/vml/aemrules/java/rules/JavaCheckClasses.java b/src/main/java/com/vml/aemrules/java/rules/JavaCheckClasses.java
deleted file mode 100644
index 566f43c5..00000000
--- a/src/main/java/com/vml/aemrules/java/rules/JavaCheckClasses.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * #%L
- * AEM Rules for SonarQube
- * %%
- * Copyright (C) 2015-2024 VML
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * #L%
- */
-package com.vml.aemrules.java.rules;
-
-import com.vml.aemrules.java.checks.AdministrativeAccessUsageCheck;
-import com.vml.aemrules.java.checks.AnnotationsConstantsCheck;
-import com.vml.aemrules.java.checks.ConstantsCheck;
-import com.vml.aemrules.java.checks.ContentResourceShouldBeNullCheckedCheck;
-import com.vml.aemrules.java.checks.ModifiableValueMapUsageCheck;
-import com.vml.aemrules.java.checks.PreferSlingServletAnnotation;
-import com.vml.aemrules.java.checks.SessionShouldBeLoggedOut;
-import com.vml.aemrules.java.checks.SynchronizedKeywordUsageCheck;
-import com.vml.aemrules.java.checks.ThreadSafeFieldCheck;
-import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverShouldBeClosed;
-import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverTryWithResourcesCheck;
-import com.vml.aemrules.java.checks.slingmodels.DefaultInjectionStrategyAnnotationCheck;
-import com.vml.aemrules.java.checks.slingquery.SlingQueryImplicitStrategyCheck;
-import com.vml.aemrules.version.AemVersion;
-import com.vml.aemrules.version.VersionSupportChecker;
-import org.sonar.api.config.Configuration;
-import org.sonar.plugins.java.api.CheckRegistrar;
-import org.sonar.plugins.java.api.JavaCheck;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-public class JavaCheckClasses implements CheckRegistrar {
-
- public static final String REPOSITORY_KEY = "AEM Rules";
-
- public static final String REPOSITORY_NAME = "AEM Rules";
-
- public static final List> CHECK_CLASSES = Arrays.asList(
- AdministrativeAccessUsageCheck.class,
- AnnotationsConstantsCheck.class,
- ConstantsCheck.class,
- PreferSlingServletAnnotation.class,
- ResourceResolverShouldBeClosed.class,
- SessionShouldBeLoggedOut.class,
- SynchronizedKeywordUsageCheck.class,
- ThreadSafeFieldCheck.class,
- DefaultInjectionStrategyAnnotationCheck.class,
- ModifiableValueMapUsageCheck.class,
- ContentResourceShouldBeNullCheckedCheck.class,
- SlingQueryImplicitStrategyCheck.class,
- ResourceResolverTryWithResourcesCheck.class
- );
-
- private final Configuration configuration;
-
- public JavaCheckClasses(Configuration configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public void register(RegistrarContext registrarContext) {
- String aemVersion = configuration.get(VersionSupportChecker.VERSION_PROPERTY)
- .orElse(VersionSupportChecker.DEFAULT_AEM_VERSION);
- List> checkClassesToRegister = CHECK_CLASSES.stream()
- .filter(checkClass -> shouldRegister(aemVersion, checkClass))
- .collect(Collectors.toList());
- registrarContext.registerClassesForRepository(REPOSITORY_KEY, checkClassesToRegister,
- Collections.emptyList());
- }
-
- private boolean shouldRegister(String aemVersion, Class extends JavaCheck> checkClass) {
- return Optional.ofNullable(checkClass.getAnnotation(AemVersion.class))
- .map(supportedVersion -> VersionSupportChecker.create(supportedVersion).supports(aemVersion))
- .orElse(true);
- }
-}
diff --git a/src/main/java/com/vml/aemrules/java/rules/JavaCheckRegistrar.java b/src/main/java/com/vml/aemrules/java/rules/JavaCheckRegistrar.java
new file mode 100644
index 00000000..613c1e60
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/rules/JavaCheckRegistrar.java
@@ -0,0 +1,67 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.rules;
+
+import com.vml.aemrules.version.AemVersion;
+import com.vml.aemrules.version.VersionSupportChecker;
+import org.sonar.api.config.Configuration;
+import org.sonar.plugins.java.api.CheckRegistrar;
+import org.sonar.plugins.java.api.JavaCheck;
+import org.sonarsource.api.sonarlint.SonarLintSide;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static com.vml.aemrules.java.rules.JavaRulesDefinition.REPOSITORY_KEY;
+
+@SonarLintSide
+public class JavaCheckRegistrar implements CheckRegistrar {
+
+ private final String aemVersion;
+
+ public JavaCheckRegistrar(Configuration configuration) {
+ this.aemVersion = configuration.get(VersionSupportChecker.VERSION_PROPERTY)
+ .orElse(VersionSupportChecker.DEFAULT_AEM_VERSION);
+ }
+
+ @Override
+ public void register(RegistrarContext registrarContext) {
+ registrarContext.registerClassesForRepository(REPOSITORY_KEY, checkClasses(), testCheckClasses());
+ }
+
+ private List> checkClasses() {
+ return JavaRulesList.getJavaChecks().stream()
+ .filter(checkClass -> shouldRegister(aemVersion, checkClass))
+ .collect(Collectors.toList());
+ }
+
+ private List> testCheckClasses() {
+ return JavaRulesList.getJavaTestChecks().stream()
+ .filter(checkClass -> shouldRegister(aemVersion, checkClass))
+ .collect(Collectors.toList());
+ }
+
+ private boolean shouldRegister(String aemVersion, Class extends JavaCheck> checkClass) {
+ return Optional.ofNullable(checkClass.getAnnotation(AemVersion.class))
+ .map(supportedVersion -> VersionSupportChecker.create(supportedVersion).supports(aemVersion))
+ .orElse(true);
+ }
+}
diff --git a/src/main/java/com/vml/aemrules/java/rules/JavaRulesDefinition.java b/src/main/java/com/vml/aemrules/java/rules/JavaRulesDefinition.java
new file mode 100644
index 00000000..0ff1663a
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/rules/JavaRulesDefinition.java
@@ -0,0 +1,49 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.rules;
+
+import org.sonar.api.SonarRuntime;
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonarsource.analyzer.commons.RuleMetadataLoader;
+
+import java.util.ArrayList;
+
+public class JavaRulesDefinition implements RulesDefinition {
+
+ public static final String REPOSITORY_KEY = "AEM-Rules";
+
+ public static final String REPOSITORY_NAME = "AEM Rules";
+
+ private static final String RESOURCE_BASE_PATH = "org/sonar/l10n/java/rules/java";
+
+ private final SonarRuntime runtime;
+
+ public JavaRulesDefinition(SonarRuntime runtime) {
+ this.runtime = runtime;
+ }
+
+ @Override
+ public void define(Context context) {
+ NewRepository repository = context.createRepository(REPOSITORY_KEY, "java").setName(REPOSITORY_NAME);
+ RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, runtime);
+ ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(JavaRulesList.getChecks()));
+ repository.done();
+ }
+}
diff --git a/src/main/java/com/vml/aemrules/java/rules/JavaRulesList.java b/src/main/java/com/vml/aemrules/java/rules/JavaRulesList.java
new file mode 100644
index 00000000..c0384e00
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/rules/JavaRulesList.java
@@ -0,0 +1,78 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.rules;
+
+import com.vml.aemrules.java.checks.AdministrativeAccessUsageCheck;
+import com.vml.aemrules.java.checks.AnnotationsConstantsCheck;
+import com.vml.aemrules.java.checks.ConstantsCheck;
+import com.vml.aemrules.java.checks.ContentResourceShouldBeNullCheckedCheck;
+import com.vml.aemrules.java.checks.ModifiableValueMapUsageCheck;
+import com.vml.aemrules.java.checks.PreferSlingServletAnnotation;
+import com.vml.aemrules.java.checks.SessionShouldBeLoggedOut;
+import com.vml.aemrules.java.checks.SynchronizedKeywordUsageCheck;
+import com.vml.aemrules.java.checks.ThreadSafeFieldCheck;
+import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverShouldBeClosed;
+import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverTryWithResourcesCheck;
+import com.vml.aemrules.java.checks.slingmodels.DefaultInjectionStrategyAnnotationCheck;
+import com.vml.aemrules.java.checks.slingquery.SlingQueryImplicitStrategyCheck;
+import org.sonar.plugins.java.api.JavaCheck;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class JavaRulesList {
+
+ private JavaRulesList() {
+ //private constructor
+ }
+
+ public static List> getChecks() {
+ List> checks = new ArrayList<>();
+ checks.addAll(getJavaChecks());
+ checks.addAll(getJavaTestChecks());
+ return Collections.unmodifiableList(checks);
+ }
+
+ public static List> getJavaChecks() {
+ return Collections.unmodifiableList(Arrays.asList(
+ AdministrativeAccessUsageCheck.class,
+ AnnotationsConstantsCheck.class,
+ ConstantsCheck.class,
+ PreferSlingServletAnnotation.class,
+ ResourceResolverShouldBeClosed.class,
+ SessionShouldBeLoggedOut.class,
+ SynchronizedKeywordUsageCheck.class,
+ ThreadSafeFieldCheck.class,
+ DefaultInjectionStrategyAnnotationCheck.class,
+ ModifiableValueMapUsageCheck.class,
+ ContentResourceShouldBeNullCheckedCheck.class,
+ SlingQueryImplicitStrategyCheck.class,
+ ResourceResolverTryWithResourcesCheck.class
+ )
+ );
+ }
+
+ public static List> getJavaTestChecks() {
+ return Collections.emptyList();
+ }
+
+}
diff --git a/src/main/java/com/vml/aemrules/java/rules/package-info.java b/src/main/java/com/vml/aemrules/java/rules/package-info.java
new file mode 100644
index 00000000..9304dde4
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/rules/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.rules;
diff --git a/src/main/java/com/vml/aemrules/java/util/package-info.java b/src/main/java/com/vml/aemrules/java/util/package-info.java
new file mode 100644
index 00000000..5498bc43
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/java/util/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.java.util;
diff --git a/src/main/java/com/vml/aemrules/matcher/package-info.java b/src/main/java/com/vml/aemrules/matcher/package-info.java
new file mode 100644
index 00000000..0d0f582c
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/matcher/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.matcher;
diff --git a/src/main/java/com/vml/aemrules/metadata/package-info.java b/src/main/java/com/vml/aemrules/metadata/package-info.java
new file mode 100644
index 00000000..568e62d6
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/metadata/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.metadata;
diff --git a/src/main/java/com/vml/aemrules/package-info.java b/src/main/java/com/vml/aemrules/package-info.java
new file mode 100644
index 00000000..1ff90b10
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules;
diff --git a/src/main/java/com/vml/aemrules/rules/package-info.java b/src/main/java/com/vml/aemrules/rules/package-info.java
new file mode 100644
index 00000000..4d38d5a7
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/rules/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.rules;
diff --git a/src/main/java/com/vml/aemrules/tag/Tags.java b/src/main/java/com/vml/aemrules/tag/Tags.java
index 7fba177c..9c7ef1f5 100644
--- a/src/main/java/com/vml/aemrules/tag/Tags.java
+++ b/src/main/java/com/vml/aemrules/tag/Tags.java
@@ -27,10 +27,6 @@ public class Tags {
public static final String PERFORMANCE = "performance";
- public static final String MULTI_THREADING = "multi-threading";
-
- public static final String SLING_MODELS = "sling-models";
-
private Tags() {
throw new AssertionError();
}
diff --git a/src/main/java/com/vml/aemrules/tag/package-info.java b/src/main/java/com/vml/aemrules/tag/package-info.java
new file mode 100644
index 00000000..ecd1bd0e
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/tag/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.tag;
diff --git a/src/main/java/com/vml/aemrules/utils/package-info.java b/src/main/java/com/vml/aemrules/utils/package-info.java
new file mode 100644
index 00000000..54633649
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/utils/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.utils;
diff --git a/src/main/java/com/vml/aemrules/version/package-info.java b/src/main/java/com/vml/aemrules/version/package-info.java
new file mode 100644
index 00000000..7af9e9e7
--- /dev/null
+++ b/src/main/java/com/vml/aemrules/version/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * #%L
+ * AEM Rules for SonarQube
+ * %%
+ * Copyright (C) 2015-2024 VML
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+package com.vml.aemrules.version;
diff --git a/src/main/resources/metadata/AEM-19.json b/src/main/resources/metadata/AEM-19.json
deleted file mode 100644
index 2027a78a..00000000
--- a/src/main/resources/metadata/AEM-19.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "remediation": {
- "constantCost": "30min"
- }
-}
diff --git a/src/main/resources/rules/AEM-1.md b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-1.html
similarity index 69%
rename from src/main/resources/rules/AEM-1.md
rename to src/main/resources/org/sonar/l10n/java/rules/java/AEM-1.html
index f32de86d..a60e46bc 100644
--- a/src/main/resources/rules/AEM-1.md
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-1.html
@@ -1,13 +1,13 @@
-Use constants available in AEM instead of repeating inline literals.
-== Noncompliant Code Example
-``
+
Use predefined constant in annotation instead of hardcoded value.
+
Noncompliant Code Example
+
public static final String JCR_CONTENT = "jcr:content"; // Noncompliant; Use predefined constant available in com.day.cq.commons.jcr.JcrConstants
// ...
Resource resource = resourceResolver.getResource(resourcePath + JCR_CONTENT);
-``
-== Compliant Solution
-``
+
+ Administrative access to the resource tree and JCR Repository by means of usage of ResourceResolverFactory.getAdministrativeResourceResolver
+ and SlingRepository.loginAdministrative has been deprecated.
+ Use ResourceResolverFactory.getServiceResourceResolver or SlingRepository.loginService
+ respectively.
+
+ResourceResolverFactory
+ Javadoc
+Service Authentication
diff --git a/src/main/resources/org/sonar/l10n/java/rules/java/AEM-11.json b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-11.json
new file mode 100644
index 00000000..57a721cf
--- /dev/null
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-11.json
@@ -0,0 +1,14 @@
+{
+ "title": "Do not use deprecated administrative access methods",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "30min"
+ },
+ "tags": [
+ "aem"
+ ],
+ "defaultSeverity": "Major",
+ "sqKey": "AEM-11"
+}
diff --git a/src/main/resources/rules/AEM-15.md b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.html
similarity index 53%
rename from src/main/resources/rules/AEM-15.md
rename to src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.html
index 80c73940..3a70237d 100644
--- a/src/main/resources/rules/AEM-15.md
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.html
@@ -1,67 +1,67 @@
-Usage of ``synchronized`` keyword should be avoided if possible. Check if using ``synchronized`` can be replaced with more sophisticated solution.
+
+ Usage of synchronized keyword should be avoided if possible. Check if using synchronized
+ can be replaced with more sophisticated solution.
+
-== Noncompliant Code Example
-
-``
+
Noncompliant Code Example
+
import java.util.ArrayList;
import java.util.List;
(...)
-private final List list = new ArrayList<>(16);
+private final List<String> list = new ArrayList<>(16);
public synchronized void addElement(String s) { // Noncompliant
list.add(s);
}
-``
-or
-``
+
+
or
+
import java.util.ArrayList;
import java.util.List;
(...)
-private final List list = new ArrayList<>(16);
+private final List<String> list = new ArrayList<>(16);
public void removeElement(String s) {
synchronized(list) { // Noncompliant
list.remove(s);
}
}
-``
-or
-``
+
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
(...)
-private final List list = new CopyOnWriteArrayList<>(16);
+private final ListList<String> list = new CopyOnWriteArrayList<>(16);
// use java.util.concurrent.ConcurrentHashMap for Map
public void addElement(String s) {
list.add(s);
}
-``
-or
-``
+
+
or
+
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
(...)
-private final List list = Collections.synchronizedList(new ArrayList<>(16));
+private final List<String> list = Collections.synchronizedList(new ArrayList<>(16));
// Collections object contains also synchronizedMap function
public void addElement(String s) {
list.add(s);
}
-``
-or
-``
+
+
or
+
import java.util.concurrent.atomic.AtomicInteger
java.util.concurrent.atomic.LongAdder // from java 8
(...)
@@ -72,9 +72,8 @@
counter.addAndGet(1);
meter.increment();
}
-``
-
-== See
-More details:
-[Java 7 java.util.concurrent javadoc](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html)
-[Java 8 java.util.concurrent javadoc](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html)
\ No newline at end of file
+
+
See
+Java 7 java.util.concurrent javadoc
+
+Java 8 java.util.concurrent javadoc
diff --git a/src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.json b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.json
new file mode 100644
index 00000000..71fc3357
--- /dev/null
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-15.json
@@ -0,0 +1,15 @@
+{
+ "title": "Check if using 'synchronized' can be replaced with more sophisticated solution.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "30min"
+ },
+ "tags": [
+ "multi-threading",
+ "performance"
+ ],
+ "defaultSeverity": "Info",
+ "sqKey": "AEM-15"
+}
diff --git a/src/main/resources/rules/AEM-16.md b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.html
similarity index 62%
rename from src/main/resources/rules/AEM-16.md
rename to src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.html
index e229a8b7..a202baa8 100644
--- a/src/main/resources/rules/AEM-16.md
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.html
@@ -1,8 +1,9 @@
-Usage of ``@Optional`` is redundant, ``defaultInjectionStrategy`` is defined as ``OPTIONAL``
+
+ Usage of @Optional is redundant, defaultInjectionStrategy is defined as OPTIONAL
+
@Model(adaptables = Resource.class , defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class SampleModel {
@Inject // Compliant
private String str1;
(...)
-``
+
diff --git a/src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.json b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.json
new file mode 100644
index 00000000..afc53f77
--- /dev/null
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-16.json
@@ -0,0 +1,15 @@
+{
+ "title": "Check if using 'synchronized' can be replaced with more sophisticated solution.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+ "aem",
+ "sling-models"
+ ],
+ "defaultSeverity": "Minor",
+ "sqKey": "AEM-16"
+}
diff --git a/src/main/resources/org/sonar/l10n/java/rules/java/AEM-17.html b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-17.html
new file mode 100644
index 00000000..fc49a908
--- /dev/null
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-17.html
@@ -0,0 +1,29 @@
+
+ The ModifiableValueMap
+ is an extension of the ValueMap which allows to modify and persist properties.
+ It is checking user permissions and returns `null` if the user has no permission to write.
+
+ The modifiable value map is only changeable through any of the following methods:
+
+
put(String, Object)
+
putAll(java.util.Map)
+
remove(Object)
+
+
+If none of the above methods is called, ValueMap should be used instead.
+
+
+
Noncompliant Code Example
+
+public Object getProperty(Resource resource) {
+ ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant ValueMap should be used
+ return createdResourceProperties.get("propertyName");
+}
+
+ The page.getContentResource()
+ is a method of the Page class
+ which allows you to get a Resource from the page.
+
+ It is possible to get a null if a jcr:content node does not exist in the repository.
+
+
+ Lack of jrc:content is a quite common situation and occurs when one publishes a deeply nested page without publishing its parents first.
+ In that case parent pages will be published without jrc:content node.
+
+
+ Therefore, you should always null check the return value of getContentResource()
+
+ It is not safe to keep session based object as a field in Servlet, Filter, or EventHandler.
+ As well as any Declarative Services component. Rule checks for the occurrence of any instance or static fields of
+ following types:
+
diff --git a/src/main/resources/org/sonar/l10n/java/rules/java/AEM-3.json b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-3.json
new file mode 100644
index 00000000..f1f9af9f
--- /dev/null
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-3.json
@@ -0,0 +1,15 @@
+{
+ "title": "Non-thread safe object used as a field of Servlet / Filter etc.",
+ "type": "CODE_SMELL",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "1h"
+ },
+ "tags": [
+ "bug",
+ "aem"
+ ],
+ "defaultSeverity": "Critical",
+ "sqKey": "AEM-3"
+}
diff --git a/src/main/resources/rules/AEM-6.md b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-6.html
similarity index 53%
rename from src/main/resources/rules/AEM-6.md
rename to src/main/resources/org/sonar/l10n/java/rules/java/AEM-6.html
index a1e33b9d..5720a379 100644
--- a/src/main/resources/rules/AEM-6.md
+++ b/src/main/resources/org/sonar/l10n/java/rules/java/AEM-6.html
@@ -1,23 +1,29 @@
-Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory methods and ends with calling the ``close()`` method. It is very important to call the ``close()`` method once the resource resolver is not used any more to ensure any system resources are properly clean up.
-== Noncompliant Code Example
-``
+
+ Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory
+ methods and ends with calling the close() method. It is very important to call the close()
+ method once the resource resolver is not used any more to ensure any system resources are properly clean up.
+
+
+
Noncompliant Code Example
+
try {
ResourceResolver resolver = resourceResolverFactory.getResourceResolver(authenticationInfoMap); // Noncompliant; resourceResolver should be closed in finally block
// ...
} catch (Exception e) {
// ...
}
-``
-``
+
+
+
try {
ResourceResolver resolver = resourceResolverFactory.getResourceResolver(authenticationInfoMap); // Noncompliant; resourceResolver should be closed in finally block
resolver.close();
} catch (Exception e) {
// ...
}
-``
-== Compliant Solution
-``
+