diff --git a/.gitignore b/.gitignore index 5ff0ad19..b4c123c6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node/ sonar-example-plugin.iml .java-version local-docker-image/extensions/plugins/* +*.iml # Eclipse .classpath diff --git a/pom.xml b/pom.xml index ce3b3936..7b613230 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ 1.1.2-1.4.0 - 3.0.1.1444 + 3.3.0.2534 8.5.0.37199 UTF-8 10.11.0.2468 @@ -136,7 +136,6 @@ ${sonar.apiVersion} provided - org.sonarsource.html sonar-html-plugin @@ -148,7 +147,6 @@ - org.sonarsource.sslr-squid-bridge sslr-squid-bridge @@ -176,7 +174,6 @@ - org.sonarsource.java sonar-java-plugin @@ -189,9 +186,7 @@ - - org.apache.commons commons-lang3 3.17.0 @@ -201,20 +196,18 @@ commons-io 2.17.0 - org.jetbrains annotations 26.0.1 - org.apache.sling org.apache.sling.scripting.sightly.compiler ${htl.version} - + org.sonarsource.sonarqube @@ -228,6 +221,24 @@ 4.13.2 test + + org.mockito + mockito-core + 5.12.0 + test + + + org.assertj + assertj-core + 3.26.0 + test + + + org.easytesting + fest-assert + 1.4 + test + org.hamcrest hamcrest-all @@ -240,6 +251,98 @@ 32.0.0-jre test + + org.sonarsource.sonarqube + sonar-plugin-api-impl + 10.6.0.92116 + test + + + org.sonarsource.java + java-checks-testkit + 8.4.0.37032 + test + + + org.sonarsource.analyzer-commons + sonar-analyzer-commons + 2.14.0.3087 + test + + + ch.qos.logback + logback-classic + 1.2.13 + test + + + com.adobe.aem + aem-api + 6.0.0.1 + test + + + javax.jcr + jcr + 2.0 + test + + + javax.servlet + servlet-api + 2.5 + test + + + org.apache.felix + org.apache.felix.scr.annotations + 1.12.0 + test + + + + org.apache.sling + org.apache.sling.servlets.resolver + 2.3.2 + test + + + + org.apache.sling + org.apache.sling.api + 2.4.0 + test + + + org.apache.sling + org.apache.sling.models.api + 1.3.8 + test + + + org.apache.sling + org.apache.sling.query + 4.0.2 + test + + + org.osgi + org.osgi.core + 6.0.0 + test + + + org.osgi + org.osgi.compendium + 5.0.0 + test + + + org.osgi + org.osgi.service.component.annotations + 1.5.0 + test + diff --git a/src/main/java/com/cognifide/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java b/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java similarity index 92% rename from src/main/java/com/cognifide/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java rename to src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java index 421bc159..0c51517c 100644 --- a/src/main/java/com/cognifide/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java +++ b/src/main/java/com/vml/aemrules/java/checks/slingquery/SlingQueryImplicitStrategyCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,12 +17,10 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks.slingquery; +package com.vml.aemrules.java.checks.slingquery; -import com.cognifide.aemrules.tag.Tags; -import com.cognifide.aemrules.version.AemVersion; -import java.util.HashMap; -import java.util.Map; +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; @@ -34,14 +32,17 @@ import org.sonar.plugins.java.api.tree.Tree; import org.sonar.plugins.java.api.tree.VariableTree; +import java.util.HashMap; +import java.util.Map; + @Rule( - key = SlingQueryImplicitStrategyCheck.RULE_KEY, - name = SlingQueryImplicitStrategyCheck.RULE_MESSAGE, - priority = Priority.MINOR, - tags = Tags.AEM + key = SlingQueryImplicitStrategyCheck.RULE_KEY, + name = SlingQueryImplicitStrategyCheck.RULE_MESSAGE, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) public class SlingQueryImplicitStrategyCheck extends BaseTreeVisitor implements JavaFileScanner { @@ -58,11 +59,8 @@ public class SlingQueryImplicitStrategyCheck extends BaseTreeVisitor implements private static final String SLING_QUERY = "SlingQuery"; private static final String DOLLAR_SIGN = "$"; - + private final Map slingQueries = new HashMap<>(); private String currentSlingQueryVariableName = null; - - private Map slingQueries = new HashMap<>(); - private boolean findMethodUsed = false; private boolean searchStrategyMethodUsed = false; @@ -173,4 +171,4 @@ private enum SlingQueryStates { STRATEGY_USED, ISSUE_RETURNED } -} \ No newline at end of file +} diff --git a/src/main/java/com/vml/aemrules/rules/RulesLoader.java b/src/main/java/com/vml/aemrules/rules/RulesLoader.java index 20188558..6cc6b0a1 100644 --- a/src/main/java/com/vml/aemrules/rules/RulesLoader.java +++ b/src/main/java/com/vml/aemrules/rules/RulesLoader.java @@ -20,6 +20,7 @@ package com.vml.aemrules.rules; import com.vml.aemrules.metadata.Metadata; + import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; diff --git a/src/test/files/checks/java/ContentResourceShouldBeNullCheckedCheck.java b/src/test/files/checks/java/ContentResourceShouldBeNullCheckedCheck.java deleted file mode 100644 index e1477451..00000000 --- a/src/test/files/checks/java/ContentResourceShouldBeNullCheckedCheck.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * #%L - * AEM Rules for SonarQube - * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology - * %% - * 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.example; - -import com.adobe.cq.commerce.common.ValueMapDecorator; -import com.day.cq.wcm.api.Page; -import java.util.HashMap; -import java.util.Objects; -import java.util.Optional; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.sling.api.resource.ModifiableValueMap; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ValueMap; - -public class ContentResourceShouldBeNullCheckedCheck { - - private void contentResourceNotNullCheckedBeforeUsage(Resource resource) { - Page page = resource.adaptTo(Page.class); - Resource contentResourceA = page.getContentResource(); - Iterable children = contentResourceA.getChildren(); // Noncompliant - } - - private void notSafeUseOfResourceAfterIfWithNullCheck(Resource resource) { - Page page = resource.adaptTo(Page.class); - Resource contentResource = page.getContentResource("test"); - if (contentResource != null) { - // do something - } - Iterable children = contentResource.getChildren(); // Noncompliant - } - - private void nullCheckUsedOnDifferentResourceThanCheckedInIfStatement(Resource resource1, - Resource resource2) { - Page page1 = resource1.adaptTo(Page.class); - Page page2 = resource2.adaptTo(Page.class); - Resource contentResource1 = page1.getContentResource(); - Resource contentResource2 = page2.getContentResource("test"); - if (contentResource1 != null) { - Iterable children = contentResource2.getChildren(); // Noncompliant - } - } - - private void correctlyNullCheckedContentResource(Resource resource1, Resource resource2) { - Page page1 = resource1.adaptTo(Page.class); - Page page2 = resource2.adaptTo(Page.class); - Resource contentResource1 = page1.getContentResource(); - Resource contentResource2 = page2.getContentResource(); - Iterable children = null; - if (contentResource1 != null) { - children = contentResource1.getChildren(); - if (contentResource2 != null) { - children = contentResource1.getChildren(); - } - children = contentResource1.getChildren(); - } else if (contentResource2 != null) { - children = contentResource2.getChildren(); - } - } - - private void directlyCallMethodOnGetContentResourceReturn(Resource resource) { - Page page = resource.adaptTo(Page.class); - ValueMap map = page.getContentResource().getValueMap(); // Noncompliant - ModifiableValueMap modifiableValueMap = page.getContentResource().adaptTo(ModifiableValueMap.class); // Noncompliant - } - - private void useOfOptionalInCaseOfNullContentResource(Resource resource) { - Page page = resource.adaptTo(Page.class); - Optional contentResourceOptional = Optional.ofNullable(page.getContentResource()); - Iterable children = contentResourceOptional.get().getChildren(); - } - - private boolean contentResourceNullCheckWithImmediateReturn(Resource resource) { - Page page = resource.adaptTo(Page.class); - Resource contentResource = page.getContentResource(); - if (contentResource == null) { - return false; - } - contentResource.getValueMap(); - return true; - } - - private ValueMap checkForNullWithObjectsNonNull(Resource resource) { - ValueMap result = new ValueMapDecorator(new HashMap<>()); - Page page = resource.adaptTo(Page.class); - Resource pageResource = page.getContentResource("test"); - if (Objects.nonNull(pageResource)) { - result = pageResource.getValueMap(); - } - return result; - } - - private ValueMap checkForNullWithObjectsIsNull(Resource resource) { - ValueMap result = new ValueMapDecorator(new HashMap<>()); - Page page = resource.adaptTo(Page.class); - Resource pageResource = page.getContentResource("test"); - if (Objects.isNull(pageResource)) { - return result; - } else { - return pageResource.getValueMap(); - } - } - - private ValueMap checkForNullWithCommonsObjectUtilsAllNotNull(Resource resource) { - ValueMap result = new ValueMapDecorator(new HashMap<>()); - Page page = resource.adaptTo(Page.class); - Resource pageResource = page.getContentResource("test"); - if (ObjectUtils.allNotNull(pageResource)) { - result = pageResource.getValueMap(); - } - return result; - } - - private ValueMap checkForNonNullWithCommonsObjectUtilsAllNotNullMultipleResources(Resource resource) { - ValueMap result = new ValueMapDecorator(new HashMap<>()); - Page page = resource.adaptTo(Page.class); - Resource pageResource = page.getContentResource("test"); - Resource pageResource2 = page.getContentResource("test"); - Resource pageResource3 = page.getContentResource("test"); - if (ObjectUtils.allNotNull(pageResource, pageResource2)) { - result = pageResource.getValueMap(); - result = pageResource2.getValueMap(); - result = pageResource3.getValueMap(); // Noncompliant - } - return result; - } -} diff --git a/src/test/java/com/cognifide/aemrules/AemRulesSonarPluginTest.java b/src/test/java/com/vml/aemrules/AemRulesSonarPluginTest.java similarity index 88% rename from src/test/java/com/cognifide/aemrules/AemRulesSonarPluginTest.java rename to src/test/java/com/vml/aemrules/AemRulesSonarPluginTest.java index 6118d6e7..04a89a73 100644 --- a/src/test/java/com/cognifide/aemrules/AemRulesSonarPluginTest.java +++ b/src/test/java/com/vml/aemrules/AemRulesSonarPluginTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules; - -import static org.fest.assertions.Assertions.assertThat; +package com.vml.aemrules; import org.junit.Test; import org.sonar.api.Plugin; @@ -28,6 +26,8 @@ import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; +import static org.assertj.core.api.Assertions.assertThat; + public class AemRulesSonarPluginTest { @Test @@ -37,5 +37,4 @@ public void webPluginTester() { new AemRulesSonarPlugin().define(context); assertThat(context.getExtensions()).hasSize(7); } - -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/AbstractBaseTest.java b/src/test/java/com/vml/aemrules/htl/AbstractBaseTest.java similarity index 80% rename from src/test/java/com/cognifide/aemrules/htl/AbstractBaseTest.java rename to src/test/java/com/vml/aemrules/htl/AbstractBaseTest.java index a2ac1aae..45015e4c 100644 --- a/src/test/java/com/cognifide/aemrules/htl/AbstractBaseTest.java +++ b/src/test/java/com/vml/aemrules/htl/AbstractBaseTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,20 +17,14 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; -import com.cognifide.aemrules.htl.api.HtlCheck; -import com.cognifide.aemrules.htl.checks.AbstractHtlCheck; -import com.cognifide.aemrules.htl.lex.HtlLexer; -import com.cognifide.aemrules.htl.rules.HtlCheckClasses; -import com.cognifide.aemrules.htl.visitors.HtlScanner; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; - -import com.cognifide.aemrules.utils.Throwables; +import com.vml.aemrules.htl.api.HtlCheck; +import com.vml.aemrules.htl.checks.AbstractHtlCheck; +import com.vml.aemrules.htl.lex.HtlLexer; +import com.vml.aemrules.htl.rules.HtlCheckClasses; +import com.vml.aemrules.htl.visitors.HtlScanner; +import com.vml.aemrules.utils.Throwables; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.rule.RuleKey; @@ -40,6 +34,12 @@ import org.sonar.plugins.html.node.CommentNode; import org.sonar.plugins.html.visitor.HtmlSourceCode; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; + public abstract class AbstractBaseTest { protected AbstractHtlCheck check; @@ -48,12 +48,12 @@ public abstract class AbstractBaseTest { private static HtmlSourceCode createSourceCode(File file) { return new HtmlSourceCode( - new TestInputFileBuilder("key", file.getPath()) - .setLanguage(HtmlConstants.LANGUAGE_KEY) - .setType(InputFile.Type.MAIN) - .setModuleBaseDir(new File(".").toPath()) - .setCharset(StandardCharsets.UTF_8) - .build() + new TestInputFileBuilder("key", file.getPath()) + .setLanguage(HtmlConstants.LANGUAGE_KEY) + .setType(InputFile.Type.MAIN) + .setModuleBaseDir(new File(".").toPath()) + .setCharset(StandardCharsets.UTF_8) + .build() ); } diff --git a/src/test/java/com/cognifide/aemrules/htl/HtlProfileTest.java b/src/test/java/com/vml/aemrules/htl/HtlProfileTest.java similarity index 79% rename from src/test/java/com/cognifide/aemrules/htl/HtlProfileTest.java rename to src/test/java/com/vml/aemrules/htl/HtlProfileTest.java index 733fc0e5..fe81953c 100644 --- a/src/test/java/com/cognifide/aemrules/htl/HtlProfileTest.java +++ b/src/test/java/com/vml/aemrules/htl/HtlProfileTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,22 +17,23 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; -import static org.fest.assertions.Assertions.assertThat; -import java.util.Collection; -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.Function; -import java.util.stream.Collectors; import org.junit.Before; import org.junit.Test; -import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.Context; +import java.util.Collection; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.fest.assertions.Assertions.assertThat; + public class HtlProfileTest { private HtlProfile profile; @@ -42,7 +43,7 @@ public class HtlProfileTest { @Before public void setUp() { profile = new HtlProfile(); - this.context = new BuiltInQualityProfilesDefinition.Context(); + this.context = new Context(); } @@ -67,13 +68,13 @@ public void rulesLoaded() { private Map getActiveRulesByRuleKey(Context context) { return context.profilesByLanguageAndName().entrySet().stream() - .map(Entry::getValue) - .map(Map::entrySet) - .flatMap(Collection::stream) - .map(Entry::getValue) - .map(BuiltInQualityProfile::rules) - .flatMap(Collection::stream) - .collect(Collectors.toMap(BuiltInActiveRule::ruleKey, Function.identity())); + .map(Entry::getValue) + .map(Map::entrySet) + .flatMap(Collection::stream) + .map(Entry::getValue) + .map(BuiltInQualityProfile::rules) + .flatMap(Collection::stream) + .collect(Collectors.toMap(BuiltInActiveRule::ruleKey, Function.identity())); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/HtlSensorTest.java b/src/test/java/com/vml/aemrules/htl/HtlSensorTest.java similarity index 87% rename from src/test/java/com/cognifide/aemrules/htl/HtlSensorTest.java rename to src/test/java/com/vml/aemrules/htl/HtlSensorTest.java index c12383d4..f3ff286e 100644 --- a/src/test/java/com/cognifide/aemrules/htl/HtlSensorTest.java +++ b/src/test/java/com/vml/aemrules/htl/HtlSensorTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,22 +17,11 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.cognifide.aemrules.extensions.AemRulesRulesDefinition; -import com.cognifide.aemrules.htl.checks.HtlAttributesShouldBeAtTheEndCheck; -import com.cognifide.aemrules.htl.rules.HtlCheckClasses; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import com.vml.aemrules.htl.checks.HtlAttributesShouldBeAtTheEndCheck; +import com.vml.aemrules.htl.rules.HtlCheckClasses; +import com.vml.aemrules.rules.AemRulesRulesDefinition; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -53,6 +42,18 @@ import org.sonar.api.server.rule.RulesDefinition.Repository; import org.sonar.plugins.html.api.HtmlConstants; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class HtlSensorTest { @@ -67,7 +68,7 @@ public void setUp() { RulesDefinition rulesDefinition = new AemRulesRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); - RulesDefinition.Repository htlRepository = context.repository(HtlCheckClasses.REPOSITORY_KEY); + Repository htlRepository = context.repository(HtlCheckClasses.REPOSITORY_KEY); FileLinesContextFactory fileLinesContextFactory = getMockedFileLinesContextFactory(); Configuration configuration = getMockedConfiguration(); @@ -105,10 +106,10 @@ public void checkIncorrectFile_issuesFound() throws Exception { sensor.execute(tester); assertThat(tester.allIssues()).isNotEmpty(); List issuesRules = tester.allIssues().stream() - .map(Issue::ruleKey) - .map(RuleKey::rule) - .distinct() - .collect(Collectors.toList()); + .map(Issue::ruleKey) + .map(RuleKey::rule) + .distinct() + .collect(Collectors.toList()); assertThat(issuesRules).contains(HtlAttributesShouldBeAtTheEndCheck.RULE_KEY); } @@ -166,12 +167,12 @@ public void checkDescriptorConfiguration() { private DefaultInputFile createInputFile(File dir, String fileName) throws IOException { return new TestInputFileBuilder("key", fileName) - .setModuleBaseDir(dir.toPath()) - .setLanguage(HtmlConstants.LANGUAGE_KEY) - .setType(InputFile.Type.MAIN) - .initMetadata(new String(Files.readAllBytes(new File(dir, fileName).toPath()), StandardCharsets.UTF_8)) - .setCharset(StandardCharsets.UTF_8) - .build(); + .setModuleBaseDir(dir.toPath()) + .setLanguage(HtmlConstants.LANGUAGE_KEY) + .setType(InputFile.Type.MAIN) + .initMetadata(new String(Files.readAllBytes(new File(dir, fileName).toPath()), StandardCharsets.UTF_8)) + .setCharset(StandardCharsets.UTF_8) + .build(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/HtlTest.java b/src/test/java/com/vml/aemrules/htl/HtlTest.java similarity index 84% rename from src/test/java/com/cognifide/aemrules/htl/HtlTest.java rename to src/test/java/com/vml/aemrules/htl/HtlTest.java index 146e3475..d56b6ae3 100644 --- a/src/test/java/com/cognifide/aemrules/htl/HtlTest.java +++ b/src/test/java/com/vml/aemrules/htl/HtlTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,12 +17,12 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; +import org.junit.Test; -import static org.fest.assertions.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; public class HtlTest { @@ -31,4 +31,4 @@ public void shouldReturnEmptyArrayOfDefaultFileSuffixes() { Htl htl = new Htl(); assertThat(htl.getFileSuffixes()).isEmpty(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifier.java b/src/test/java/com/vml/aemrules/htl/HtmlCheckVerifier.java similarity index 90% rename from src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifier.java rename to src/test/java/com/vml/aemrules/htl/HtmlCheckVerifier.java index 0354d166..2292f5f2 100644 --- a/src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifier.java +++ b/src/test/java/com/vml/aemrules/htl/HtmlCheckVerifier.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,23 +17,23 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; - -import static org.junit.Assert.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItem; +import org.apache.commons.lang3.StringUtils; +import org.sonar.plugins.html.checks.HtmlIssue; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; -import org.sonar.plugins.html.checks.HtmlIssue; + +import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.hasItem; public class HtmlCheckVerifier { public static final String ISSUE_MARKER = ""; - private Set expectedIssuesLines; + private final Set expectedIssuesLines; public HtmlCheckVerifier() { this.expectedIssuesLines = new HashSet<>(); @@ -48,8 +48,8 @@ public void collectExpectedIssues(String comment, int startLine) { public void checkIssues(List issues) { Set issuesLines = issues.stream() - .map(HtmlIssue::line) - .collect(Collectors.toSet()); + .map(HtmlIssue::line) + .collect(Collectors.toSet()); for (HtmlIssue issue : issues) { assertThat("No issues expected in line: " + issue.line() + ", but got: " + issue.ruleKey(), expectedIssuesLines, hasItem(issue.line())); diff --git a/src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifierTest.java b/src/test/java/com/vml/aemrules/htl/HtmlCheckVerifierTest.java similarity index 91% rename from src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifierTest.java rename to src/test/java/com/vml/aemrules/htl/HtmlCheckVerifierTest.java index c2082bc4..bacd6eea 100644 --- a/src/test/java/com/cognifide/aemrules/htl/HtmlCheckVerifierTest.java +++ b/src/test/java/com/vml/aemrules/htl/HtmlCheckVerifierTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,19 +17,19 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl; +package com.vml.aemrules.htl; - -import java.util.ArrayList; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.plugins.html.checks.HtmlIssue; +import java.util.ArrayList; +import java.util.List; + public class HtmlCheckVerifierTest { - private HtmlCheckVerifier htmlCheckVerifier = new HtmlCheckVerifier(); + private final HtmlCheckVerifier htmlCheckVerifier = new HtmlCheckVerifier(); @Before public void setUp() { @@ -62,4 +62,4 @@ private HtmlIssue createLineIssue(Integer line) { RuleKey rule = RuleKey.of("r", "r"); return new HtmlIssue(rule, line, ""); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/AbstractHtlCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/AbstractHtlCheckTest.java similarity index 68% rename from src/test/java/com/cognifide/aemrules/htl/checks/AbstractHtlCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/AbstractHtlCheckTest.java index 27b825e9..c2ad9998 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/AbstractHtlCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/AbstractHtlCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,35 +17,48 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import static org.fest.assertions.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.io.File; -import java.util.List; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Before; import org.junit.Test; +import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.plugins.html.api.HtmlConstants; import org.sonar.plugins.html.checks.HtmlIssue; import org.sonar.plugins.html.visitor.HtmlSourceCode; -public class AbstractHtlCheckTest { +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class AbstractHtlCheckTest extends AbstractBaseTest { private AbstractHtlCheck check; private HtmlSourceCode htmlSourceCode; - private static HtmlSourceCode createHtmlSourceCode(String relativePath) { - return new HtmlSourceCode(new TestInputFileBuilder("key", relativePath).setModuleBaseDir(new File(".").toPath()).build()); + private static HtmlSourceCode createHtmlSourceCode(File file) { + return new HtmlSourceCode( + new TestInputFileBuilder("key", file.getPath()) + .setLanguage(HtmlConstants.LANGUAGE_KEY) + .setType(InputFile.Type.MAIN) + .setModuleBaseDir(new File(".").toPath()) + .setCharset(StandardCharsets.UTF_8) + .build() + ); } @Before public void setUp() { this.check = new AbstractHtlCheck(); - this.htmlSourceCode = createHtmlSourceCode("/"); + File file = new File("src/test/resources/htl/Empty.html"); + this.htmlSourceCode = createHtmlSourceCode(file); check.setSourceCode(htmlSourceCode); } @@ -78,5 +91,4 @@ public void creatingViolations() { assertNull(issues.get(1).cost()); } - -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java index b4231a1f..db3bf3d5 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/AvoidExtraSlyTagsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class AvoidExtraSlyTagsCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class AvoidExtraSlyTagsCheckTest extends AbstractBaseTest { @Test public void avoidExtraSlyTags() { check = new AvoidExtraSlyTagsCheck(); - filename = "src/test/files/checks/htl/AvoidExtraSlyTagsCheck.html"; + filename = "src/test/resources/htl/AvoidExtraSlyTagsCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java index f216d3bf..fe696dc3 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/AvoidUsingUnsafeDisplayContextCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class AvoidUsingUnsafeDisplayContextCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class AvoidUsingUnsafeDisplayContextCheckTest extends AbstractBaseTest { @Test public void checkAllDataAttributesContainsDisplayContext() { check = new AvoidUsingUnsafeDisplayContextCheck(); - filename = "src/test/files/checks/htl/AvoidUsingUnsafeDisplayContextCheck.html"; + filename = "src/test/resources/htl/AvoidUsingUnsafeDisplayContextCheck.html"; verify(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/CamelCaseCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/CamelCaseCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/CamelCaseCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/CamelCaseCheckTest.java index 30068220..d7267e6d 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/CamelCaseCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/CamelCaseCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class CamelCaseCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class CamelCaseCheckTest extends AbstractBaseTest { @Test public void checkCapitalization() { check = new CamelCaseCheck(); - filename = "src/test/files/checks/htl/CamelCaseCheck.html"; + filename = "src/test/resources/htl/CamelCaseCheck.html"; verify(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/DefaultDisplayContextCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/DefaultDisplayContextCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/DefaultDisplayContextCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/DefaultDisplayContextCheckTest.java index c5dd1d08..8d21e228 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/DefaultDisplayContextCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/DefaultDisplayContextCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class DefaultDisplayContextCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class DefaultDisplayContextCheckTest extends AbstractBaseTest { @Test public void checkDefaultDisplayContext() { check = new DefaultDisplayContextCheck(); - filename = "src/test/files/checks/htl/UseDefaultDisplayContextCheck.html"; + filename = "src/test/resources/htl/UseDefaultDisplayContextCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java index 461f3a47..aa3dce19 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextInConditionalCommentsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class DisplayContextInConditionalCommentsCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class DisplayContextInConditionalCommentsCheckTest extends AbstractBaseTe @Test public void checkContextInConditionalComments() { check = new DisplayContextInConditionalCommentsCheck(); - filename = "src/test/files/checks/htl/DisplayContextInConditionalCommentsCheck.html"; + filename = "src/test/resources/htl/DisplayContextInConditionalCommentsCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java index 74785993..a8f13e08 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryForInlineStylesCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class DisplayContextIsMandatoryForInlineStylesCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class DisplayContextIsMandatoryForInlineStylesCheckTest extends AbstractB @Test public void checkInlineStyleDisplayContext() { check = new InlineStyleMandatoryDisplayContextCheck(); - filename = "src/test/files/checks/htl/DefineDisplayContextInInlineStylesCheck.html"; + filename = "src/test/resources/htl/DefineDisplayContextInInlineStylesCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java rename to src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java index baa923ce..0a8407d1 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInEventAttributesTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class DisplayContextIsMandatoryInEventAttributesTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class DisplayContextIsMandatoryInEventAttributesTest extends AbstractBase @Test public void checkEventAttributeDisplayContext() { check = new EventMandatoryDisplayContextCheck(); - filename = "src/test/files/checks/htl/DefineDisplayContextInEventAttributes.html"; + filename = "src/test/resources/htl/DefineDisplayContextInEventAttributes.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java index 42cd0b35..c1a28e3e 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/DisplayContextIsMandatoryInScriptsAndStylesCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class DisplayContextIsMandatoryInScriptsAndStylesCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class DisplayContextIsMandatoryInScriptsAndStylesCheckTest extends Abstra @Test public void checkScriptsAndStyleDisplayContext() { check = new ScriptsAndStyleMandatoryDisplayContextCheck(); - filename = "src/test/files/checks/htl/DefineDisplayContextInScriptsAndStylesCheck.html"; + filename = "src/test/resources/htl/DefineDisplayContextInScriptsAndStylesCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java similarity index 67% rename from src/test/java/com/cognifide/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java index 2b457dfa..865d3917 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/ExplicitNamesInLoopsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,17 +17,17 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class ExplicitNamesInLoopsCheckTest extends AbstractBaseTest { - @Test - public void ExplicitNamesInLoopsCheck() { - check = new ExplicitNamesInLoopsCheck(); - filename = "src/test/files/checks/htl/ExplicitNamesInLoopsCheck.html"; - verify(); - } + @Test + public void ExplicitNamesInLoopsCheck() { + check = new ExplicitNamesInLoopsCheck(); + filename = "src/test/resources/htl/ExplicitNamesInLoopsCheck.html"; + verify(); + } } \ No newline at end of file diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java index ab26cd7b..9b86a578 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/HtlAttributesShouldBeAtTheEndCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class HtlAttributesShouldBeAtTheEndCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class HtlAttributesShouldBeAtTheEndCheckTest extends AbstractBaseTest { @Test public void checkHtlAttributesOrder() { check = new HtlAttributesShouldBeAtTheEndCheck(); - filename = "src/test/files/checks/htl/HtlAttributesShouldBeAtTheEndCheck.html"; + filename = "src/test/resources/htl/HtlAttributesShouldBeAtTheEndCheck.html"; verify(); } } \ No newline at end of file diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/HtlCommentsCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/HtlCommentsCheckTest.java similarity index 68% rename from src/test/java/com/cognifide/aemrules/htl/checks/HtlCommentsCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/HtlCommentsCheckTest.java index c54b8923..c72d5267 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/HtlCommentsCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/HtlCommentsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -18,17 +18,17 @@ * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class HtlCommentsCheckTest extends AbstractBaseTest { - @Test - public void checkHTLStyleOfCommenting() { - check = new HtlCommentsCheck(); - filename = "src/test/files/checks/htl/HtlCommentsCheck.html"; - verify(); - } + @Test + public void checkHTLStyleOfCommenting() { + check = new HtlCommentsCheck(); + filename = "src/test/resources/htl/HtlCommentsCheck.html"; + verify(); + } } \ No newline at end of file diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java index 3cc1e444..0255260e 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/NamingAndReusingConditionsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class NamingAndReusingConditionsCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class NamingAndReusingConditionsCheckTest extends AbstractBaseTest { @Test public void checkHtlAttributesOrder() { check = new NamingAndReusingConditionsCheck(); - filename = "src/test/files/checks/htl/NamingAndReusingConditionsCheck.html"; + filename = "src/test/resources/htl/NamingAndReusingConditionsCheck.html"; verify(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java index 6fb90fcf..9f25ccd9 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/PlaceTemplatesInSeparateFilesCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class PlaceTemplatesInSeparateFilesCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class PlaceTemplatesInSeparateFilesCheckTest extends AbstractBaseTest { @Test public void checkHtlAttributesOrder() { check = new PlaceTemplatesInSeparateFilesCheck(); - filename = "src/test/files/checks/htl/PlaceTemplatesInSeparateFilesCheck.html"; + filename = "src/test/resources/htl/PlaceTemplatesInSeparateFilesCheck.html"; verify(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java index eda5d43c..036d2c0a 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/SlyElementsAreAutomaticallyUnwrappedCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class SlyElementsAreAutomaticallyUnwrappedCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class SlyElementsAreAutomaticallyUnwrappedCheckTest extends AbstractBaseT @Test public void checkRedundantUnwrapAttributes() { check = new SlyElementsAreAutomaticallyUnwrappedCheck(); - filename = "src/test/files/checks/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html"; + filename = "src/test/resources/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java index 283dc890..6d79445c 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/UseMostRestrictiveHtlContextCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class UseMostRestrictiveHtlContextCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class UseMostRestrictiveHtlContextCheckTest extends AbstractBaseTest { @Test public void checkAllDataAttributesContainsDisplayContext() { check = new UseMostRestrictiveHtlContextCheck(); - filename = "src/test/files/checks/htl/UseMostRestrictiveHtlContextCheck.html"; + filename = "src/test/resources/htl/UseMostRestrictiveHtlContextCheck.html"; verify(); } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java b/src/test/java/com/vml/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java rename to src/test/java/com/vml/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java index 62fc2ace..0f575e1f 100644 --- a/src/test/java/com/cognifide/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java +++ b/src/test/java/com/vml/aemrules/htl/checks/UseSlyTagsOverRedundantMarkupCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.checks; +package com.vml.aemrules.htl.checks; -import com.cognifide.aemrules.htl.AbstractBaseTest; +import com.vml.aemrules.htl.AbstractBaseTest; import org.junit.Test; public class UseSlyTagsOverRedundantMarkupCheckTest extends AbstractBaseTest { @@ -27,7 +27,7 @@ public class UseSlyTagsOverRedundantMarkupCheckTest extends AbstractBaseTest { @Test public void checkRedundantSlyTags() { check = new UseSlyTagsOverRedundantMarkupCheck(); - filename = "src/test/files/checks/htl/UseSlyTagsOverRedundantMarkupCheck.html"; + filename = "src/test/resources/htl/UseSlyTagsOverRedundantMarkupCheck.html"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/htl/visitors/HtlNodeCounterVisitor.java b/src/test/java/com/vml/aemrules/htl/visitors/HtlNodeCounterVisitor.java similarity index 95% rename from src/test/java/com/cognifide/aemrules/htl/visitors/HtlNodeCounterVisitor.java rename to src/test/java/com/vml/aemrules/htl/visitors/HtlNodeCounterVisitor.java index 94509b5e..05a0ef8e 100644 --- a/src/test/java/com/cognifide/aemrules/htl/visitors/HtlNodeCounterVisitor.java +++ b/src/test/java/com/vml/aemrules/htl/visitors/HtlNodeCounterVisitor.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,11 +17,8 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.visitors; +package com.vml.aemrules.htl.visitors; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.sling.scripting.sightly.compiler.expression.Expression; import org.sonar.plugins.html.node.CommentNode; import org.sonar.plugins.html.node.DirectiveNode; @@ -31,11 +28,15 @@ import org.sonar.plugins.html.node.TextNode; import org.sonar.plugins.html.visitor.HtmlSourceCode; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class HtlNodeCounterVisitor implements DefaultHtlVisitor { private HtmlSourceCode sourceCode = null; - private Map counterMap; + private final Map counterMap; public HtlNodeCounterVisitor() { counterMap = new HashMap<>(); diff --git a/src/test/java/com/cognifide/aemrules/htl/visitors/HtlScannerTest.java b/src/test/java/com/vml/aemrules/htl/visitors/HtlScannerTest.java similarity index 89% rename from src/test/java/com/cognifide/aemrules/htl/visitors/HtlScannerTest.java rename to src/test/java/com/vml/aemrules/htl/visitors/HtlScannerTest.java index 80e7a33b..75236bc2 100644 --- a/src/test/java/com/cognifide/aemrules/htl/visitors/HtlScannerTest.java +++ b/src/test/java/com/vml/aemrules/htl/visitors/HtlScannerTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,30 +17,30 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.htl.visitors; +package com.vml.aemrules.htl.visitors; -import static org.junit.Assert.assertEquals; - -import com.cognifide.aemrules.htl.lex.HtlLexer; -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.nio.charset.StandardCharsets; -import java.util.List; - -import com.cognifide.aemrules.utils.Throwables; +import com.google.common.io.Files; +import com.vml.aemrules.htl.lex.HtlLexer; +import com.vml.aemrules.utils.Throwables; import org.apache.sling.scripting.sightly.compiler.expression.Expression; import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import com.google.common.io.Files; import org.sonar.plugins.html.api.HtmlConstants; import org.sonar.plugins.html.node.CommentNode; import org.sonar.plugins.html.node.Node; import org.sonar.plugins.html.node.TagNode; import org.sonar.plugins.html.visitor.HtmlSourceCode; +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import static org.junit.Assert.assertEquals; + public class HtlScannerTest { private HtlNodeCounterVisitor counterVisitor; @@ -73,9 +73,9 @@ public void checkVisitedNode() { private HtmlSourceCode createHtmlSourceCode(String relativePath) { return new HtmlSourceCode(new TestInputFileBuilder("key", relativePath) - .setLanguage(HtmlConstants.LANGUAGE_KEY) - .setModuleBaseDir(new File(".").toPath()) - .build() + .setLanguage(HtmlConstants.LANGUAGE_KEY) + .setModuleBaseDir(new File(".").toPath()) + .build() ); } @@ -88,4 +88,4 @@ private Reader readFile(String fileName) { throw new IllegalArgumentException("Cannot read " + fileName, e); } } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/java/checks/AbstractBaseTest.java b/src/test/java/com/vml/aemrules/java/checks/AbstractBaseTest.java similarity index 96% rename from src/test/java/com/cognifide/aemrules/java/checks/AbstractBaseTest.java rename to src/test/java/com/vml/aemrules/java/checks/AbstractBaseTest.java index 5f997fed..708426c6 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/AbstractBaseTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/AbstractBaseTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,16 +17,16 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; +package com.vml.aemrules.java.checks; import org.apache.commons.lang3.StringUtils; import org.sonar.java.checks.verifier.CheckVerifier; import org.sonar.plugins.java.api.JavaFileScanner; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + public abstract class AbstractBaseTest { /** diff --git a/src/test/java/com/cognifide/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java index 861a7304..f70d2f08 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/AdministrativeAccessUsageCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,7 +26,7 @@ public class AdministrativeAccessUsageCheckTest extends AbstractBaseTest { @Test public void administrativeAccessUsageCheck() { check = new AdministrativeAccessUsageCheck(); - filename = "src/test/files/checks/java/AdministrativeAccessUsageCheck.java"; + filename = "src/test/resources/java/AdministrativeAccessUsageCheck.java"; verify(); } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/AnnotationsConstantsCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheckTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/java/checks/AnnotationsConstantsCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheckTest.java index 11086eb1..b56805d9 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/AnnotationsConstantsCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/AnnotationsConstantsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,7 +26,7 @@ public class AnnotationsConstantsCheckTest extends AbstractBaseTest { @Test public void checkConstantsInAnnotations() { check = new AnnotationsConstantsCheck(); - filename = "src/test/files/checks/java/AnnotationsConstantsCheck.java"; + filename = "src/test/resources/java/AnnotationsConstantsCheck.java"; verify(false); } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ConstantsCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/ConstantsCheckTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/java/checks/ConstantsCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/ConstantsCheckTest.java index 56b3725a..e2870d51 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ConstantsCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ConstantsCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,7 +26,7 @@ public class ConstantsCheckTest extends AbstractBaseTest { @Test public void checkConstants() { check = new ConstantsCheck(); - filename = "src/test/files/checks/java/ConstantsCheck.java"; + filename = "src/test/resources/java/ConstantsCheck.java"; verify(false); } } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java similarity index 67% rename from src/test/java/com/cognifide/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java index 48416ff0..0c5d61aa 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ContentResourceShouldBeNullCheckedCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,16 +17,16 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; -public class ContentResourceShouldBeNullCheckedCheckTest extends AbstractBaseTest { +public class ContentResourceShouldBeNullCheckedCheckTest extends AbstractBaseTest { - @Test - public void checkIfContentResourceIsNotNull() { - check = new ContentResourceShouldBeNullCheckedCheck(); - filename = "src/test/files/checks/java/ContentResourceShouldBeNullCheckedCheck.java"; - verify(); - } + @Test + public void checkIfContentResourceIsNotNull() { + check = new ContentResourceShouldBeNullCheckedCheck(); + filename = "src/test/resources/java/ContentResourceShouldBeNullCheckedCheck.java"; + verify(); + } } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java similarity index 70% rename from src/test/java/com/cognifide/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java index af66fc05..05fd5291 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/DefaultInjectionStrategyAnnotationCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,9 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; -import com.cognifide.aemrules.java.checks.slingmodels.DefaultInjectionStrategyAnnotationCheck; +import com.vml.aemrules.java.checks.slingmodels.DefaultInjectionStrategyAnnotationCheck; import org.junit.Test; public class DefaultInjectionStrategyAnnotationCheckTest extends AbstractBaseTest { @@ -27,14 +27,14 @@ public class DefaultInjectionStrategyAnnotationCheckTest extends AbstractBaseTes @Test public void checkAnnotation() { check = new DefaultInjectionStrategyAnnotationCheck(); - filename = "src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheck.java"; + filename = "src/test/resources/java/DefaultInjectionStrategyAnnotationCheck.java"; verify(); } @Test public void checkMultipleAdaptablesAnnotation() { check = new DefaultInjectionStrategyAnnotationCheck(); - filename = "src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java"; + filename = "src/test/resources/java/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java"; verify(); } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java index 16298d6e..fe49ac9e 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ModifiableValueMapUsageCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,7 +26,7 @@ public class ModifiableValueMapUsageCheckTest extends AbstractBaseTest { @Test public void checkIfMVMIsUsedToRetrievePropertiesFromResource() { check = new ModifiableValueMapUsageCheck(); - filename = "src/test/files/checks/java/ModifiableValueMapUsageCheck.java"; + filename = "src/test/resources/java/ModifiableValueMapUsageCheck.java"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/PreferSlingServletAnnotationTest.java b/src/test/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotationTest.java similarity index 73% rename from src/test/java/com/cognifide/aemrules/java/checks/PreferSlingServletAnnotationTest.java rename to src/test/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotationTest.java index b0fdcb95..f6f0b36b 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/PreferSlingServletAnnotationTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/PreferSlingServletAnnotationTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,28 +26,28 @@ public class PreferSlingServletAnnotationTest extends AbstractBaseTest { @Test public void checkLackOfAnnotation() { check = new PreferSlingServletAnnotation(); - filename = "src/test/files/checks/java/slingservlet/SlingServletOne.java"; + filename = "src/test/resources/java/SlingServletOne.java"; verify(); } @Test public void checkMixedAnnotations() { check = new PreferSlingServletAnnotation(); - filename = "src/test/files/checks/java/slingservlet/SlingServletTwo.java"; + filename = "src/test/resources/java/SlingServletTwo.java"; verify(); } @Test public void checkRedundantProperties() { check = new PreferSlingServletAnnotation(); - filename = "src/test/files/checks/java/slingservlet/SlingServletThree.java"; + filename = "src/test/resources/java/SlingServletThree.java"; verify(); } @Test public void checkStandardAnnotations() { check = new PreferSlingServletAnnotation(); - filename = "src/test/files/checks/java/slingservlet/SlingServletWithStandardAnnotations.java"; + filename = "src/test/resources/java/SlingServletWithStandardAnnotations.java"; verifyNoIssues(); } } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java b/src/test/java/com/vml/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java similarity index 75% rename from src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java rename to src/test/java/com/vml/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java index 171ddf94..0e470e04 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ResourceResolverShouldBeClosedTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,46 +17,45 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; +import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverShouldBeClosed; import org.junit.Test; -import com.cognifide.aemrules.java.checks.resourceresolver.close.ResourceResolverShouldBeClosed; - public class ResourceResolverShouldBeClosedTest extends AbstractBaseTest { @Test public void checkInjectorNotClosedInFinallyBlock() { check = new ResourceResolverShouldBeClosed(); - filename = "src/test/files/checks/java/SampleServlet.java"; + filename = "src/test/resources/java/SampleServlet.java"; verify(); } @Test public void checkResourceResolverNotClosedInFinallyBlockWhenResourceResolverComesFromDifferentClass() { check = new ResourceResolverShouldBeClosed(); - filename = "src/test/files/checks/java/ResourceResolverConsumer.java"; + filename = "src/test/resources/java/ResourceResolverConsumer.java"; verifyNoIssues(); } @Test public void checkResourceResolverNotClosedWhenItIsOpenedInActivateAndClosedInDeactivate() { check = new ResourceResolverShouldBeClosed(); - filename = "src/test/files/checks/java/LongSessionService.java"; + filename = "src/test/resources/java/LongSessionService.java"; verifyNoIssues(); } @Test public void checkResourceResolverClosedInDeactivateMethod() { check = new ResourceResolverShouldBeClosed(); - filename = "src/test/files/checks/java/LongSessionEventListener.java"; + filename = "src/test/resources/java/LongSessionEventListener.java"; verifyNoIssues(); } @Test public void checkResourceResolverClosedInDeactivateMethodError() { check = new ResourceResolverShouldBeClosed(); - filename = "src/test/files/checks/java/LongResourceResolverEvenListenerError.java"; + filename = "src/test/resources/java/LongResourceResolverEvenListenerError.java"; verify(); } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java b/src/test/java/com/vml/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java similarity index 61% rename from src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java rename to src/test/java/com/vml/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java index 57e9d722..50ede946 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ResourceResolverTryWithResourcesTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,18 +17,18 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; -import com.cognifide.aemrules.java.checks.resourceresolver.close.ResourceResolverTryWithResourcesCheck; +import com.vml.aemrules.java.checks.resourceresolver.close.ResourceResolverTryWithResourcesCheck; import org.junit.Test; public class ResourceResolverTryWithResourcesTest extends AbstractBaseTest { - @Test - public void checkResourceResolverUsesTryWithResourcesBlock() { - check = new ResourceResolverTryWithResourcesCheck(); - filename = "src/test/files/checks/java/resourceresolver/AutoclosableResourceResolver.java"; - verify(); - } + @Test + public void checkResourceResolverUsesTryWithResourcesBlock() { + check = new ResourceResolverTryWithResourcesCheck(); + filename = "src/test/resources/java/AutoclosableResourceResolver.java"; + verify(); + } -} \ No newline at end of file +} diff --git a/src/test/java/com/cognifide/aemrules/java/checks/SessionShouldBeLoggedOutTest.java b/src/test/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOutTest.java similarity index 63% rename from src/test/java/com/cognifide/aemrules/java/checks/SessionShouldBeLoggedOutTest.java rename to src/test/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOutTest.java index 68350c12..b51ce907 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/SessionShouldBeLoggedOutTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/SessionShouldBeLoggedOutTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,42 +17,42 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; - -import java.util.Arrays; -import java.util.Collection; +package com.vml.aemrules.java.checks; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.util.Arrays; +import java.util.Collection; + @RunWith(Parameterized.class) public class SessionShouldBeLoggedOutTest extends AbstractBaseTest { + private final boolean expectFailure; + + public SessionShouldBeLoggedOutTest(Object fn, Object expectFailure) { + filename = (String) fn; + this.expectFailure = ((Boolean) expectFailure).booleanValue(); + } + // format is filename, failure expected @Parameterized.Parameters public static Collection data() { return Arrays.asList(new Object[][]{ - {"src/test/files/checks/java/SessionLogoutOne.java", false}, - {"src/test/files/checks/java/SessionLogoutTwo.java", false}, - {"src/test/files/checks/java/SessionLogoutThree.java", false}, - {"src/test/files/checks/java/SessionLogoutFour.java", true}, - {"src/test/files/checks/java/SessionLogoutFive.java", true}, - {"src/test/files/checks/java/SessionLogoutSix.java", true}, - {"src/test/files/checks/java/SessionLogoutSeven.java", true}, - {"src/test/files/checks/java/SessionLogoutEight.java", false}, - {"src/test/files/checks/java/LongSessionEventListener.java", false}, - {"src/test/files/checks/java/LongSessionEventListenerError.java", true} + {"src/test/resources/java/SessionLogoutOne.java", false}, + {"src/test/resources/java/SessionLogoutTwo.java", false}, + {"src/test/resources/java/SessionLogoutThree.java", false}, + {"src/test/resources/java/SessionLogoutFour.java", true}, + {"src/test/resources/java/SessionLogoutFive.java", true}, + {"src/test/resources/java/SessionLogoutSix.java", true}, + {"src/test/resources/java/SessionLogoutSeven.java", true}, + {"src/test/resources/java/SessionLogoutEight.java", false}, + {"src/test/resources/java/LongSessionEventListener.java", false}, + {"src/test/resources/java/LongSessionEventListenerError.java", true} }); } - private boolean expectFailure; - - public SessionShouldBeLoggedOutTest(Object fn, Object expectFailure) { - filename = (String) fn; - this.expectFailure = ((Boolean) expectFailure).booleanValue(); - } - @Test public void checkInjectorNotClosedInFinallyBlock() { check = new SessionShouldBeLoggedOut(); diff --git a/src/test/java/com/cognifide/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java similarity index 65% rename from src/test/java/com/cognifide/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java index 0cd0c3c2..b063eca1 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/SlingQueryImplicitStrategyCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,18 +17,18 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; -import com.cognifide.aemrules.java.checks.slingquery.SlingQueryImplicitStrategyCheck; +import com.vml.aemrules.java.checks.slingquery.SlingQueryImplicitStrategyCheck; import org.junit.Test; public class SlingQueryImplicitStrategyCheckTest extends AbstractBaseTest { - @Test - public void checkImplicitSearches() { - check = new SlingQueryImplicitStrategyCheck(); - filename = "src/test/files/checks/slingquery/SlingQueryImplicitStrategyCheck.java"; - verify(); - } + @Test + public void checkImplicitSearches() { + check = new SlingQueryImplicitStrategyCheck(); + filename = "src/test/resources/java/SlingQueryImplicitStrategyCheck.java"; + verify(); + } } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java index dddbecf9..7c479d81 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/SynchronizedKeywordUsageCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,7 +26,7 @@ public class SynchronizedKeywordUsageCheckTest extends AbstractBaseTest { @Test public void checkThreadSafeFieldsInServlet() { check = new SynchronizedKeywordUsageCheck(); - filename = "src/test/files/checks/java/SynchronizedKeywordUsageCheck.java"; + filename = "src/test/resources/java/SynchronizedKeywordUsageCheck.java"; verify(); } diff --git a/src/test/java/com/cognifide/aemrules/java/checks/ThreadSafeFieldCheckTest.java b/src/test/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheckTest.java similarity index 70% rename from src/test/java/com/cognifide/aemrules/java/checks/ThreadSafeFieldCheckTest.java rename to src/test/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheckTest.java index a95c23b8..c74a2659 100644 --- a/src/test/java/com/cognifide/aemrules/java/checks/ThreadSafeFieldCheckTest.java +++ b/src/test/java/com/vml/aemrules/java/checks/ThreadSafeFieldCheckTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,7 +17,7 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.java.checks; +package com.vml.aemrules.java.checks; import org.junit.Test; @@ -26,42 +26,42 @@ public class ThreadSafeFieldCheckTest extends AbstractBaseTest { @Test public void checkThreadSafeFieldsInServlet() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckServlet.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckServlet.java"; verify(); } @Test public void checkThreadSafeFieldsInFilter() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckFilter.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckFilter.java"; verify(); } @Test public void checkThreadSafeFieldsInEventHandler() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckEventHandler.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckEventHandler.java"; verify(); } @Test public void checkThreadSafeFieldsInScrComponent() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckScrComponentAnnotation.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckScrComponentAnnotation.java"; verify(); } @Test public void checkThreadSafeFieldsInDsComponent() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckDsComponentAnnotation.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckDsComponentAnnotation.java"; verify(); } @Test public void checkThreadSafeFieldsInSlingServletAnnotated() { check = new ThreadSafeFieldCheck(); - filename = "src/test/files/checks/java/ThreadSafeFieldCheckSlingServletAnnotation.java"; + filename = "src/test/resources/java/ThreadSafeFieldCheckSlingServletAnnotation.java"; verify(); } } diff --git a/src/test/java/com/cognifide/aemrules/matcher/MethodMatcherTest.java b/src/test/java/com/vml/aemrules/matcher/MethodMatcherTest.java similarity index 66% rename from src/test/java/com/cognifide/aemrules/matcher/MethodMatcherTest.java rename to src/test/java/com/vml/aemrules/matcher/MethodMatcherTest.java index 53ff84f8..23e56685 100644 --- a/src/test/java/com/cognifide/aemrules/matcher/MethodMatcherTest.java +++ b/src/test/java/com/vml/aemrules/matcher/MethodMatcherTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,12 +17,13 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.matcher; +package com.vml.aemrules.matcher; import org.junit.Assert; import org.junit.Test; import org.sonar.java.model.JParser; import org.sonar.java.model.JParserConfig; +import org.sonar.java.model.JavaVersionImpl; import org.sonar.plugins.java.api.tree.ClassTree; import org.sonar.plugins.java.api.tree.CompilationUnitTree; import org.sonar.plugins.java.api.tree.ExpressionStatementTree; @@ -38,36 +39,27 @@ public class MethodMatcherTest { - private static final String CODE_TO_PARSE_METHOD_SELECT_KIND_IDENTIFIER = "package com.cognifide.test; " - + "class MyClass1 {}" - + "class MyClass2 {}" - + "class TestClass { " - + "void test(MyClass1 m1, MyClass2 m2){}" - + "void bar(){MyClass1 m1 = new MyClass1(); MyClass2 m2 = new MyClass2(); test(m1, m2);} " - + "}"; - - private static final String CODE_TO_PARSE_METHOD_SELECT_KIND_MEMBER_SELECT = "package com.cognifide.test; " - + "class MyClass1 {}" - + "class MyClass2 {}" - + "class TestClass { " - + "void test(MyClass1 m1, MyClass2 m2){}" - + "void bar(){MyClass1 m1 = new MyClass1(); MyClass2 m2 = new MyClass2(); this.test(m1, m2);} " - + "}"; - - private static final int CLASS_INDEX = 2; - - private static final int CLASS_METHOD_INDEX = 1; - - private static final int METHOD_INVOCATION_INDEX = 2; - public static final String CLASSES_FILEPATH = "target/classes"; - public static final String TEST_CLASSES_FILEPATH = "target/test-classes"; - public static final String JAVA_VERSION = "1.8"; - public static final String UNIT_NAME = "test"; - + private static final String CODE_TO_PARSE_METHOD_SELECT_KIND_IDENTIFIER = "package com.vml.test; " + + "class MyClass1 {}" + + "class MyClass2 {}" + + "class TestClass { " + + "void test(MyClass1 m1, MyClass2 m2){}" + + "void bar(){MyClass1 m1 = new MyClass1(); MyClass2 m2 = new MyClass2(); test(m1, m2);} " + + "}"; + private static final String CODE_TO_PARSE_METHOD_SELECT_KIND_MEMBER_SELECT = "package com.vml.test; " + + "class MyClass1 {}" + + "class MyClass2 {}" + + "class TestClass { " + + "void test(MyClass1 m1, MyClass2 m2){}" + + "void bar(){MyClass1 m1 = new MyClass1(); MyClass2 m2 = new MyClass2(); this.test(m1, m2);} " + + "}"; + private static final int CLASS_INDEX = 2; + private static final int CLASS_METHOD_INDEX = 1; + private static final int METHOD_INVOCATION_INDEX = 2; private MethodInvocationTree methodInvocationTree; @Test @@ -75,10 +67,10 @@ public void shouldMatchMethodWhenMethodNameAndOwnerClassAndMethodParametersMatch givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_IDENTIFIER); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is(UNIT_NAME), - OwnerTypePredicate.is("com.cognifide.test.TestClass"), - ParameterTypePredicate.is("com.cognifide.test.MyClass1"), - ParameterTypePredicate.is("com.cognifide.test.MyClass2") + MethodNamePredicate.is(UNIT_NAME), + OwnerTypePredicate.is("com.vml.test.TestClass"), + ParameterTypePredicate.is("com.vml.test.MyClass1"), + ParameterTypePredicate.is("com.vml.test.MyClass2") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(true)); @@ -89,10 +81,10 @@ public void shouldMatchMethodWhenMethodNameAndOwnerClassAndOnlySecondParameterMa givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_MEMBER_SELECT); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is(UNIT_NAME), - OwnerTypePredicate.is("com.cognifide.test.TestClass"), - ParameterTypePredicate.anyParameterType(), - ParameterTypePredicate.is("com.cognifide.test.MyClass2") + MethodNamePredicate.is(UNIT_NAME), + OwnerTypePredicate.is("com.vml.test.TestClass"), + ParameterTypePredicate.anyParameterType(), + ParameterTypePredicate.is("com.vml.test.MyClass2") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(true)); @@ -103,10 +95,10 @@ public void shouldNotMatchMethodWhenMethodNameDoesNotMatch() { givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_IDENTIFIER); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is("different"), - OwnerTypePredicate.is("com.cognifide.test.TestClass"), - ParameterTypePredicate.is("com.cognifide.test.MyClass1"), - ParameterTypePredicate.is("com.cognifide.test.MyClass2") + MethodNamePredicate.is("different"), + OwnerTypePredicate.is("com.vml.test.TestClass"), + ParameterTypePredicate.is("com.vml.test.MyClass1"), + ParameterTypePredicate.is("com.vml.test.MyClass2") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(false)); @@ -117,9 +109,9 @@ public void shouldNotMatchMethodWhenNumberOfMethodParametersDoesNotMatch() { givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_MEMBER_SELECT); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is(UNIT_NAME), - OwnerTypePredicate.is("com.cognifide.test.TestClass"), - ParameterTypePredicate.is("com.cognifide.test.MyClass1") + MethodNamePredicate.is(UNIT_NAME), + OwnerTypePredicate.is("com.vml.test.TestClass"), + ParameterTypePredicate.is("com.vml.test.MyClass1") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(false)); @@ -130,10 +122,10 @@ public void shouldNotMatchMethodWhenMethodOwnerClassDoesNotMatch() { givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_IDENTIFIER); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is(UNIT_NAME), - OwnerTypePredicate.is("com.cognifide.test.Different"), - ParameterTypePredicate.is("com.cognifide.test.MyClass1"), - ParameterTypePredicate.is("com.cognifide.test.MyClass2") + MethodNamePredicate.is(UNIT_NAME), + OwnerTypePredicate.is("com.vml.test.Different"), + ParameterTypePredicate.is("com.vml.test.MyClass1"), + ParameterTypePredicate.is("com.vml.test.MyClass2") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(false)); @@ -144,10 +136,10 @@ public void shouldNotMatchMethodWhenMethodParameterTypesDoNotMatch() { givenMethodInvocationTree(CODE_TO_PARSE_METHOD_SELECT_KIND_MEMBER_SELECT); MethodMatcher methodMatcher = MethodMatcher.create( - MethodNamePredicate.is(UNIT_NAME), - OwnerTypePredicate.is("com.cognifide.test.TestClass"), - ParameterTypePredicate.is("com.cognifide.test.Different1"), - ParameterTypePredicate.is("com.cognifide.test.MyClass2") + MethodNamePredicate.is(UNIT_NAME), + OwnerTypePredicate.is("com.vml.test.TestClass"), + ParameterTypePredicate.is("com.vml.test.Different1"), + ParameterTypePredicate.is("com.vml.test.MyClass2") ); Assert.assertThat(methodMatcher.matches(methodInvocationTree), is(false)); @@ -162,8 +154,7 @@ private void givenMethodInvocationTree(String codeToParse) { private CompilationUnitTree parse(String source) { List classpath = Arrays.asList(new File(TEST_CLASSES_FILEPATH), new File(CLASSES_FILEPATH)); - return JParser.parse(JParserConfig.Mode.FILE_BY_FILE.create(JAVA_VERSION, classpath).astParser(), JAVA_VERSION, UNIT_NAME, source); + return JParser.parse(JParserConfig.Mode.FILE_BY_FILE.create(new JavaVersionImpl(17), classpath).astParser(), JAVA_VERSION, UNIT_NAME, source); } } - diff --git a/src/test/java/com/cognifide/aemrules/extensions/RulesLoaderTest.java b/src/test/java/com/vml/aemrules/rules/RulesLoaderTest.java similarity index 78% rename from src/test/java/com/cognifide/aemrules/extensions/RulesLoaderTest.java rename to src/test/java/com/vml/aemrules/rules/RulesLoaderTest.java index 7c1db604..ecc913e1 100644 --- a/src/test/java/com/cognifide/aemrules/extensions/RulesLoaderTest.java +++ b/src/test/java/com/vml/aemrules/rules/RulesLoaderTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,18 +17,12 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.extensions; +package com.vml.aemrules.rules; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; - -import com.cognifide.aemrules.java.rules.JavaCheckClasses; -import com.cognifide.aemrules.metadata.Metadata; -import com.cognifide.aemrules.tag.Tags; -import com.cognifide.aemrules.version.AemVersion; - -import java.util.Arrays; -import java.util.List; +import com.vml.aemrules.java.rules.JavaCheckClasses; +import com.vml.aemrules.metadata.Metadata; +import com.vml.aemrules.tag.Tags; +import com.vml.aemrules.version.AemVersion; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,6 +36,11 @@ import org.sonar.plugins.java.api.JavaFileScannerContext; import org.sonar.plugins.java.api.tree.BaseTreeVisitor; +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; + public class RulesLoaderTest { private static final String RULE_KEY = "AEM-TEST"; @@ -73,7 +72,7 @@ public void setUp() { @Test public void shouldLoadRuleWithAllSettings() { - givenRulesLoaded(Arrays.asList(RuleWithAllSettings.class)); + givenRulesLoaded(List.of(RuleWithAllSettings.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -87,7 +86,7 @@ public void shouldLoadRuleWithAllSettings() { @Test public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() { - givenRulesLoaded(Arrays.asList(RuleWithoutMetadataAnnotation.class)); + givenRulesLoaded(List.of(RuleWithoutMetadataAnnotation.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -101,7 +100,7 @@ public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() { @Test public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() { - givenRulesLoaded(Arrays.asList(RuleWithEmptyTechnicalDebt.class)); + givenRulesLoaded(List.of(RuleWithEmptyTechnicalDebt.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -115,7 +114,7 @@ public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() { @Test public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() { - givenRulesLoaded(Arrays.asList(RuleWithoutRuleAnnotation.class)); + givenRulesLoaded(List.of(RuleWithoutRuleAnnotation.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -126,10 +125,10 @@ public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() { @Test public void shouldSetDefaultValuesWhenRuleAttributeWithNameOnly() { - givenRulesLoaded(Arrays.asList(RuleWithOnlyNameAttribute.class)); + givenRulesLoaded(List.of(RuleWithOnlyNameAttribute.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); - RulesDefinition.Rule rule = repository.rule("com.cognifide.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute"); + RulesDefinition.Rule rule = repository.rule("com.vml.aemrules.rules.RulesLoaderTest.RuleWithOnlyNameAttribute"); Assert.assertThat(rule.markdownDescription(), is("No description yet.")); Assert.assertThat(rule.name(), is(RULE_NAME)); @@ -140,12 +139,12 @@ public void shouldSetDefaultValuesWhenRuleAttributeWithNameOnly() { @Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenRuleNameNotProvide() { - givenRulesLoaded(Arrays.asList(RuleWithoutNameAttributeSet.class)); + givenRulesLoaded(List.of(RuleWithoutNameAttributeSet.class)); } @Test public void shouldLoadRuleWithProperty() { - givenRulesLoaded(Arrays.asList(RuleWithRuleProperty.class)); + givenRulesLoaded(List.of(RuleWithRuleProperty.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -158,7 +157,7 @@ public void shouldLoadRuleWithProperty() { @Test public void shouldLoadRuleWithPropertyWithoutAttributes() { - givenRulesLoaded(Arrays.asList(RuleWithRulePropertyWithoutAttributes.class)); + givenRulesLoaded(List.of(RuleWithRulePropertyWithoutAttributes.class)); RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY); RulesDefinition.Rule rule = repository.rule(RULE_KEY); @@ -176,16 +175,16 @@ private void givenRulesLoaded(List> annotationClasses } @Rule( - key = RULE_KEY, - name = RULE_NAME, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + name = RULE_NAME, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithAllSettings extends BaseTreeVisitor implements JavaFileScanner { @@ -196,13 +195,13 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - key = RULE_KEY, - name = RULE_NAME, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + name = RULE_NAME, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) private class RuleWithoutMetadataAnnotation extends BaseTreeVisitor implements JavaFileScanner { @@ -213,16 +212,16 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - key = RULE_KEY, - name = RULE_NAME, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + name = RULE_NAME, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = "" + technicalDebt = "" ) private class RuleWithEmptyTechnicalDebt extends BaseTreeVisitor implements JavaFileScanner { @@ -233,10 +232,10 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithoutRuleAnnotation extends BaseTreeVisitor implements JavaFileScanner { @@ -247,13 +246,13 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - name = RULE_NAME + name = RULE_NAME ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithOnlyNameAttribute extends BaseTreeVisitor implements JavaFileScanner { @@ -264,15 +263,15 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - key = RULE_KEY, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithoutNameAttributeSet extends BaseTreeVisitor implements JavaFileScanner { @@ -283,24 +282,24 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - key = RULE_KEY, - name = RULE_NAME, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + name = RULE_NAME, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithRuleProperty extends BaseTreeVisitor implements JavaFileScanner { @RuleProperty( - key = RULE_PROPERTY_KEY, - description = RULE_PROPERTY_DESCRIPTION, - defaultValue = RULES_PROPERTY_DEFAULT_VALUE, - type = RULES_PROPERTY_TYPE + key = RULE_PROPERTY_KEY, + description = RULE_PROPERTY_DESCRIPTION, + defaultValue = RULES_PROPERTY_DEFAULT_VALUE, + type = RULES_PROPERTY_TYPE ) private String testProperty; @@ -311,16 +310,16 @@ public void scanFile(JavaFileScannerContext javaFileScannerContext) { } @Rule( - key = RULE_KEY, - name = RULE_NAME, - priority = Priority.MINOR, - tags = Tags.AEM + key = RULE_KEY, + name = RULE_NAME, + priority = Priority.MINOR, + tags = Tags.AEM ) @AemVersion( - all = true + all = true ) @Metadata( - technicalDebt = TECHNICAL_DEBT + technicalDebt = TECHNICAL_DEBT ) private class RuleWithRulePropertyWithoutAttributes extends BaseTreeVisitor implements JavaFileScanner { diff --git a/src/test/java/com/cognifide/aemrules/version/VersionSupportCheckerTest.java b/src/test/java/com/vml/aemrules/version/VersionSupportCheckerTest.java similarity index 82% rename from src/test/java/com/cognifide/aemrules/version/VersionSupportCheckerTest.java rename to src/test/java/com/vml/aemrules/version/VersionSupportCheckerTest.java index abf2b0b8..66c17027 100644 --- a/src/test/java/com/cognifide/aemrules/version/VersionSupportCheckerTest.java +++ b/src/test/java/com/vml/aemrules/version/VersionSupportCheckerTest.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,21 +17,21 @@ * limitations under the License. * #L% */ -package com.cognifide.aemrules.version; - -import static com.cognifide.aemrules.version.VersionSupportChecker.DEFAULT_AEM_VERSION; -import static com.cognifide.aemrules.version.VersionSupportChecker.create; -import static org.hamcrest.CoreMatchers.is; +package com.vml.aemrules.version; import org.junit.Assert; import org.junit.Test; +import static com.vml.aemrules.version.VersionSupportChecker.DEFAULT_AEM_VERSION; +import static com.vml.aemrules.version.VersionSupportChecker.create; +import static org.hamcrest.CoreMatchers.is; + public class VersionSupportCheckerTest { @Test public void shouldSupportAllVersionsWhenAllSet() { VersionSupportChecker versionSupportChecker = create( - CheckSupportingAllVersions.class.getAnnotation(AemVersion.class)); + CheckSupportingAllVersions.class.getAnnotation(AemVersion.class)); Assert.assertThat(versionSupportChecker.supports("6.3"), is(true)); Assert.assertThat(versionSupportChecker.supports("2.1"), is(true)); Assert.assertThat(versionSupportChecker.supports("2.0"), is(true)); @@ -40,7 +40,7 @@ public void shouldSupportAllVersionsWhenAllSet() { @Test public void shouldSupportAllVersionsBetweenFromAndTo() { VersionSupportChecker versionSupportChecker = create( - CheckSupportingVersionsFromTo.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsFromTo.class.getAnnotation(AemVersion.class)); Assert.assertThat(versionSupportChecker.supports("6.1"), is(true)); Assert.assertThat(versionSupportChecker.supports("5.2"), is(true)); Assert.assertThat(versionSupportChecker.supports("5.1"), is(true)); @@ -52,7 +52,7 @@ public void shouldSupportAllVersionsBetweenFromAndTo() { @Test public void shouldSupportAllVersionsFrom() { VersionSupportChecker versionSupportChecker = create( - CheckSupportingVersionsFrom.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsFrom.class.getAnnotation(AemVersion.class)); Assert.assertThat(versionSupportChecker.supports("100.1"), is(true)); Assert.assertThat(versionSupportChecker.supports("10.1"), is(true)); Assert.assertThat(versionSupportChecker.supports("17.2"), is(true)); @@ -63,7 +63,7 @@ public void shouldSupportAllVersionsFrom() { @Test public void shouldSupportAllVersionsTo() { VersionSupportChecker supportedVersions = create( - CheckSupportingVersionsTo.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsTo.class.getAnnotation(AemVersion.class)); Assert.assertThat(supportedVersions.supports("1.1"), is(true)); Assert.assertThat(supportedVersions.supports("10.1"), is(true)); Assert.assertThat(supportedVersions.supports("0.2"), is(true)); @@ -75,7 +75,7 @@ public void shouldSupportAllVersionsTo() { @Test public void shouldSupportAllProvidedVersions() { VersionSupportChecker supportedVersions = create( - CheckSupportingVersionsIncluded.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsIncluded.class.getAnnotation(AemVersion.class)); Assert.assertThat(supportedVersions.supports("6.1"), is(true)); Assert.assertThat(supportedVersions.supports("2.1"), is(true)); Assert.assertThat(supportedVersions.supports("4.8"), is(true)); @@ -86,7 +86,7 @@ public void shouldSupportAllProvidedVersions() { @Test public void shouldSupportAllVersionsExcludingProvided() { VersionSupportChecker supportedVersions = create( - CheckSupportingVersionsExcluded.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsExcluded.class.getAnnotation(AemVersion.class)); Assert.assertThat(supportedVersions.supports("6.1"), is(false)); Assert.assertThat(supportedVersions.supports("2.1"), is(false)); Assert.assertThat(supportedVersions.supports("4.8"), is(false)); @@ -97,7 +97,7 @@ public void shouldSupportAllVersionsExcludingProvided() { @Test public void shouldUseDefaultVersionWhenProvidedVersionIsEmptyOrNull() { VersionSupportChecker supportedVersions = create( - CheckSupportingDefaultVersion.class.getAnnotation(AemVersion.class)); + CheckSupportingDefaultVersion.class.getAnnotation(AemVersion.class)); Assert.assertThat(supportedVersions.supports(DEFAULT_AEM_VERSION), is(true)); Assert.assertThat(supportedVersions.supports(""), is(true)); Assert.assertThat(supportedVersions.supports(null), is(true)); @@ -106,7 +106,7 @@ public void shouldUseDefaultVersionWhenProvidedVersionIsEmptyOrNull() { @Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenVersionToSupportIsIncorrect() { VersionSupportChecker supportedVersions = create( - CheckSupportingVersionsExcluded.class.getAnnotation(AemVersion.class)); + CheckSupportingVersionsExcluded.class.getAnnotation(AemVersion.class)); supportedVersions.supports("f.1"); } @@ -122,68 +122,68 @@ public void shouldThrowExceptionWhenVersionIncorrectProvided2() { @AemVersion( - all = true + all = true ) private class CheckSupportingAllVersions { } @AemVersion( - from = "5.1", - to = "6.4" + from = "5.1", + to = "6.4" ) private class CheckSupportingVersionsFromTo { } @AemVersion( - from = "10.1" + from = "10.1" ) private class CheckSupportingVersionsFrom { } @AemVersion( - to = "10.1" + to = "10.1" ) private class CheckSupportingVersionsTo { } @AemVersion( - included = {"6.1", "2.1", "4.8"} + included = {"6.1", "2.1", "4.8"} ) private class CheckSupportingVersionsIncluded { } @AemVersion( - all = true, - excluded = {"6.1", "2.1", "4.8"} + all = true, + excluded = {"6.1", "2.1", "4.8"} ) private class CheckSupportingVersionsExcluded { } @AemVersion( - from = "5.6.7" + from = "5.6.7" ) private class CheckWithIncorrectVersion1 { } @AemVersion( - included = "a.b" + included = "a.b" ) private class CheckWithIncorrectVersion2 { } @AemVersion( - included = {DEFAULT_AEM_VERSION} + included = {DEFAULT_AEM_VERSION} ) private class CheckSupportingDefaultVersion { } -} \ No newline at end of file +} diff --git a/src/test/files/checks/htl/AvoidExtraSlyTagsCheck.html b/src/test/resources/htl/AvoidExtraSlyTagsCheck.html similarity index 100% rename from src/test/files/checks/htl/AvoidExtraSlyTagsCheck.html rename to src/test/resources/htl/AvoidExtraSlyTagsCheck.html diff --git a/src/test/files/checks/htl/AvoidUsingUnsafeDisplayContextCheck.html b/src/test/resources/htl/AvoidUsingUnsafeDisplayContextCheck.html similarity index 96% rename from src/test/files/checks/htl/AvoidUsingUnsafeDisplayContextCheck.html rename to src/test/resources/htl/AvoidUsingUnsafeDisplayContextCheck.html index 0e3cea22..fdce9c34 100644 --- a/src/test/files/checks/htl/AvoidUsingUnsafeDisplayContextCheck.html +++ b/src/test/resources/htl/AvoidUsingUnsafeDisplayContextCheck.html @@ -31,9 +31,7 @@ diff --git a/src/test/files/checks/htl/CamelCaseCheck.html b/src/test/resources/htl/CamelCaseCheck.html similarity index 100% rename from src/test/files/checks/htl/CamelCaseCheck.html rename to src/test/resources/htl/CamelCaseCheck.html diff --git a/src/test/files/checks/htl/DefineDisplayContextInEventAttributes.html b/src/test/resources/htl/DefineDisplayContextInEventAttributes.html similarity index 100% rename from src/test/files/checks/htl/DefineDisplayContextInEventAttributes.html rename to src/test/resources/htl/DefineDisplayContextInEventAttributes.html diff --git a/src/test/files/checks/htl/DefineDisplayContextInInlineStylesCheck.html b/src/test/resources/htl/DefineDisplayContextInInlineStylesCheck.html similarity index 100% rename from src/test/files/checks/htl/DefineDisplayContextInInlineStylesCheck.html rename to src/test/resources/htl/DefineDisplayContextInInlineStylesCheck.html diff --git a/src/test/files/checks/htl/DefineDisplayContextInScriptsAndStylesCheck.html b/src/test/resources/htl/DefineDisplayContextInScriptsAndStylesCheck.html similarity index 100% rename from src/test/files/checks/htl/DefineDisplayContextInScriptsAndStylesCheck.html rename to src/test/resources/htl/DefineDisplayContextInScriptsAndStylesCheck.html diff --git a/src/test/files/checks/htl/DisplayContextInConditionalCommentsCheck.html b/src/test/resources/htl/DisplayContextInConditionalCommentsCheck.html similarity index 100% rename from src/test/files/checks/htl/DisplayContextInConditionalCommentsCheck.html rename to src/test/resources/htl/DisplayContextInConditionalCommentsCheck.html diff --git a/src/test/resources/htl/Empty.html b/src/test/resources/htl/Empty.html new file mode 100644 index 00000000..e69de29b diff --git a/src/test/files/checks/htl/ExplicitNamesInLoopsCheck.html b/src/test/resources/htl/ExplicitNamesInLoopsCheck.html similarity index 100% rename from src/test/files/checks/htl/ExplicitNamesInLoopsCheck.html rename to src/test/resources/htl/ExplicitNamesInLoopsCheck.html diff --git a/src/test/files/checks/htl/HtlAttributesShouldBeAtTheEndCheck.html b/src/test/resources/htl/HtlAttributesShouldBeAtTheEndCheck.html similarity index 100% rename from src/test/files/checks/htl/HtlAttributesShouldBeAtTheEndCheck.html rename to src/test/resources/htl/HtlAttributesShouldBeAtTheEndCheck.html diff --git a/src/test/files/checks/htl/HtlCommentsCheck.html b/src/test/resources/htl/HtlCommentsCheck.html similarity index 100% rename from src/test/files/checks/htl/HtlCommentsCheck.html rename to src/test/resources/htl/HtlCommentsCheck.html diff --git a/src/test/files/checks/htl/NamingAndReusingConditionsCheck.html b/src/test/resources/htl/NamingAndReusingConditionsCheck.html similarity index 100% rename from src/test/files/checks/htl/NamingAndReusingConditionsCheck.html rename to src/test/resources/htl/NamingAndReusingConditionsCheck.html diff --git a/src/test/files/checks/htl/PlaceTemplatesInSeparateFilesCheck.html b/src/test/resources/htl/PlaceTemplatesInSeparateFilesCheck.html similarity index 100% rename from src/test/files/checks/htl/PlaceTemplatesInSeparateFilesCheck.html rename to src/test/resources/htl/PlaceTemplatesInSeparateFilesCheck.html diff --git a/src/test/files/checks/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html b/src/test/resources/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html similarity index 100% rename from src/test/files/checks/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html rename to src/test/resources/htl/SlyElementsAreAutomaticallyUnwrappedCheck.html diff --git a/src/test/files/checks/htl/UseDefaultDisplayContextCheck.html b/src/test/resources/htl/UseDefaultDisplayContextCheck.html similarity index 94% rename from src/test/files/checks/htl/UseDefaultDisplayContextCheck.html rename to src/test/resources/htl/UseDefaultDisplayContextCheck.html index f57025a7..d98b8835 100644 --- a/src/test/files/checks/htl/UseDefaultDisplayContextCheck.html +++ b/src/test/resources/htl/UseDefaultDisplayContextCheck.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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. diff --git a/src/test/files/checks/htl/UseMostRestrictiveHtlContextCheck.html b/src/test/resources/htl/UseMostRestrictiveHtlContextCheck.html similarity index 92% rename from src/test/files/checks/htl/UseMostRestrictiveHtlContextCheck.html rename to src/test/resources/htl/UseMostRestrictiveHtlContextCheck.html index 739de14a..b8a5753b 100644 --- a/src/test/files/checks/htl/UseMostRestrictiveHtlContextCheck.html +++ b/src/test/resources/htl/UseMostRestrictiveHtlContextCheck.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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. diff --git a/src/test/files/checks/htl/UseSlyTagsOverRedundantMarkupCheck.html b/src/test/resources/htl/UseSlyTagsOverRedundantMarkupCheck.html similarity index 100% rename from src/test/files/checks/htl/UseSlyTagsOverRedundantMarkupCheck.html rename to src/test/resources/htl/UseSlyTagsOverRedundantMarkupCheck.html diff --git a/src/test/files/checks/java/AdministrativeAccessUsageCheck.java b/src/test/resources/java/AdministrativeAccessUsageCheck.java similarity index 97% rename from src/test/files/checks/java/AdministrativeAccessUsageCheck.java rename to src/test/resources/java/AdministrativeAccessUsageCheck.java index 4719aea2..058dad75 100644 --- a/src/test/files/checks/java/AdministrativeAccessUsageCheck.java +++ b/src/test/resources/java/AdministrativeAccessUsageCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,9 +17,11 @@ * limitations under the License. * #L% */ + import java.util.Map; import javax.jcr.RepositoryException; import javax.jcr.Session; + import org.apache.felix.scr.annotations.Reference; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; diff --git a/src/test/files/checks/java/AnnotationsConstantsCheck.java b/src/test/resources/java/AnnotationsConstantsCheck.java similarity index 93% rename from src/test/files/checks/java/AnnotationsConstantsCheck.java rename to src/test/resources/java/AnnotationsConstantsCheck.java index 94caf06c..f7ef8462 100644 --- a/src/test/files/checks/java/AnnotationsConstantsCheck.java +++ b/src/test/resources/java/AnnotationsConstantsCheck.java @@ -48,8 +48,7 @@ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse throws ServletException, IOException { } - @Override("service.description") - // Noncompliant {{Use constant SERVICE_DESCRIPTION from interface org.osgi.framework.Constants instead of hardcoded value.}} + @Override("service.description") // Noncompliant {{Use constant SERVICE_DESCRIPTION from interface org.osgi.framework.Constants instead of hardcoded value.}} protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { } diff --git a/src/test/files/checks/java/resourceresolver/AutoclosableResourceResolver.java b/src/test/resources/java/AutoclosableResourceResolver.java similarity index 97% rename from src/test/files/checks/java/resourceresolver/AutoclosableResourceResolver.java rename to src/test/resources/java/AutoclosableResourceResolver.java index c5162c9b..74fb5c39 100644 --- a/src/test/files/checks/java/resourceresolver/AutoclosableResourceResolver.java +++ b/src/test/resources/java/AutoclosableResourceResolver.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,7 +19,6 @@ */ package com.example; -import java.util.Map; import java.util.List; import java.awt.Event; import jdk.nashorn.internal.ir.annotations.Reference; diff --git a/src/test/files/checks/java/ConstantsCheck.java b/src/test/resources/java/ConstantsCheck.java similarity index 100% rename from src/test/files/checks/java/ConstantsCheck.java rename to src/test/resources/java/ConstantsCheck.java diff --git a/src/test/resources/java/ContentResourceShouldBeNullCheckedCheck.java b/src/test/resources/java/ContentResourceShouldBeNullCheckedCheck.java new file mode 100644 index 00000000..20de3cb0 --- /dev/null +++ b/src/test/resources/java/ContentResourceShouldBeNullCheckedCheck.java @@ -0,0 +1,144 @@ +/*- + * #%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.example; + +import com.adobe.cq.commerce.common.ValueMapDecorator; +import com.day.cq.wcm.api.Page; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.sling.api.resource.ModifiableValueMap; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; + +import java.util.HashMap; +import java.util.Objects; +import java.util.Optional; + +public class ContentResourceShouldBeNullCheckedCheck { + + private void contentResourceNotNullCheckedBeforeUsage(Resource resource) { + Page page = resource.adaptTo(Page.class); + Resource contentResourceA = page.getContentResource(); + Iterable children = contentResourceA.getChildren(); // Noncompliant + } + + private void notSafeUseOfResourceAfterIfWithNullCheck(Resource resource) { + Page page = resource.adaptTo(Page.class); + Resource contentResource = page.getContentResource("test"); + if (contentResource != null) { + // do something + } + Iterable children = contentResource.getChildren(); // Noncompliant + } + + private void nullCheckUsedOnDifferentResourceThanCheckedInIfStatement(Resource resource1, + Resource resource2) { + Page page1 = resource1.adaptTo(Page.class); + Page page2 = resource2.adaptTo(Page.class); + Resource contentResource1 = page1.getContentResource(); + Resource contentResource2 = page2.getContentResource("test"); + if (contentResource1 != null) { + Iterable children = contentResource2.getChildren(); // Noncompliant + } + } + + private void correctlyNullCheckedContentResource(Resource resource1, Resource resource2) { + Page page1 = resource1.adaptTo(Page.class); + Page page2 = resource2.adaptTo(Page.class); + Resource contentResource1 = page1.getContentResource(); + Resource contentResource2 = page2.getContentResource(); + Iterable children = null; + if (contentResource1 != null) { + children = contentResource1.getChildren(); + if (contentResource2 != null) { + children = contentResource1.getChildren(); + } + children = contentResource1.getChildren(); + } else if (contentResource2 != null) { + children = contentResource2.getChildren(); + } + } + + private void directlyCallMethodOnGetContentResourceReturn(Resource resource) { + Page page = resource.adaptTo(Page.class); + ValueMap map = page.getContentResource().getValueMap(); // Noncompliant + ModifiableValueMap modifiableValueMap = page.getContentResource().adaptTo(ModifiableValueMap.class); // Noncompliant + } + + private void useOfOptionalInCaseOfNullContentResource(Resource resource) { + Page page = resource.adaptTo(Page.class); + Optional contentResourceOptional = Optional.ofNullable(page.getContentResource()); + Iterable children = contentResourceOptional.get().getChildren(); + } + + private boolean contentResourceNullCheckWithImmediateReturn(Resource resource) { + Page page = resource.adaptTo(Page.class); + Resource contentResource = page.getContentResource(); + if (contentResource == null) { + return false; + } + contentResource.getValueMap(); + return true; + } + + private ValueMap checkForNullWithObjectsNonNull(Resource resource) { + ValueMap result = new ValueMapDecorator(new HashMap<>()); + Page page = resource.adaptTo(Page.class); + Resource pageResource = page.getContentResource("test"); + if (Objects.nonNull(pageResource)) { + result = pageResource.getValueMap(); + } + return result; + } + + private ValueMap checkForNullWithObjectsIsNull(Resource resource) { + ValueMap result = new ValueMapDecorator(new HashMap<>()); + Page page = resource.adaptTo(Page.class); + Resource pageResource = page.getContentResource("test"); + if (Objects.isNull(pageResource)) { + return result; + } else { + return pageResource.getValueMap(); + } + } + + private ValueMap checkForNullWithCommonsObjectUtilsAllNotNull(Resource resource) { + ValueMap result = new ValueMapDecorator(new HashMap<>()); + Page page = resource.adaptTo(Page.class); + Resource pageResource = page.getContentResource("test"); + if (ObjectUtils.allNotNull(pageResource)) { + result = pageResource.getValueMap(); + } + return result; + } + + private ValueMap checkForNonNullWithCommonsObjectUtilsAllNotNullMultipleResources(Resource resource) { + ValueMap result = new ValueMapDecorator(new HashMap<>()); + Page page = resource.adaptTo(Page.class); + Resource pageResource = page.getContentResource("test"); + Resource pageResource2 = page.getContentResource("test"); + Resource pageResource3 = page.getContentResource("test"); + if (ObjectUtils.allNotNull(pageResource, pageResource2)) { + result = pageResource.getValueMap(); + result = pageResource2.getValueMap(); + result = pageResource3.getValueMap(); // Noncompliant + } + return result; + } +} diff --git a/src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheck.java b/src/test/resources/java/DefaultInjectionStrategyAnnotationCheck.java similarity index 96% rename from src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheck.java rename to src/test/resources/java/DefaultInjectionStrategyAnnotationCheck.java index 24bc03d0..eeeb310c 100644 --- a/src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheck.java +++ b/src/test/resources/java/DefaultInjectionStrategyAnnotationCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.inject.Inject; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Optional; +import javax.inject.Inject; + @Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class DefaultInjectionStrategyAnnotationCheck { diff --git a/src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java b/src/test/resources/java/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java similarity index 96% rename from src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java rename to src/test/resources/java/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java index 10839aaa..8981dadc 100644 --- a/src/test/files/checks/java/slingmodels/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java +++ b/src/test/resources/java/DefaultInjectionStrategyAnnotationCheckMultipleAdaptables.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.inject.Inject; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Optional; +import javax.inject.Inject; + @Model(adaptables = {Resource.class, SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class DefaultInjectionStrategyAnnotationCheckMultipleAdaptables { diff --git a/src/test/files/checks/java/LongResourceResolverEvenListenerError.java b/src/test/resources/java/LongResourceResolverEvenListenerError.java similarity index 97% rename from src/test/files/checks/java/LongResourceResolverEvenListenerError.java rename to src/test/resources/java/LongResourceResolverEvenListenerError.java index 1f1b31a8..5b6b61a8 100644 --- a/src/test/files/checks/java/LongResourceResolverEvenListenerError.java +++ b/src/test/resources/java/LongResourceResolverEvenListenerError.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,11 +19,6 @@ */ package com.example; -import java.util.Map; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -33,6 +28,12 @@ import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import java.util.Map; + @Component public class LongResourceResolverEvenListenerError implements EventListener { diff --git a/src/test/files/checks/java/LongSessionEventListener.java b/src/test/resources/java/LongSessionEventListener.java similarity index 97% rename from src/test/files/checks/java/LongSessionEventListener.java rename to src/test/resources/java/LongSessionEventListener.java index a231e0dc..68fb18f4 100644 --- a/src/test/files/checks/java/LongSessionEventListener.java +++ b/src/test/resources/java/LongSessionEventListener.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,6 @@ */ package com.example; -import java.util.Map; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; -import javax.jcr.observation.ObservationManager; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -34,6 +28,13 @@ import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import javax.jcr.observation.ObservationManager; +import java.util.Map; + @Component public class LongSessionEventListener implements EventListener { diff --git a/src/test/files/checks/java/LongSessionEventListenerError.java b/src/test/resources/java/LongSessionEventListenerError.java similarity index 97% rename from src/test/files/checks/java/LongSessionEventListenerError.java rename to src/test/resources/java/LongSessionEventListenerError.java index 2f4334a0..5a5f96e8 100644 --- a/src/test/files/checks/java/LongSessionEventListenerError.java +++ b/src/test/resources/java/LongSessionEventListenerError.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,18 +19,19 @@ */ package com.example; -import java.util.Map; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; -import javax.jcr.observation.ObservationManager; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import javax.jcr.observation.ObservationManager; +import java.util.Map; + @Component public class LongSessionEventListenerError implements EventListener { diff --git a/src/test/files/checks/java/LongSessionService.java b/src/test/resources/java/LongSessionService.java similarity index 98% rename from src/test/files/checks/java/LongSessionService.java rename to src/test/resources/java/LongSessionService.java index e0e2d7ee..89e6a4cd 100644 --- a/src/test/files/checks/java/LongSessionService.java +++ b/src/test/resources/java/LongSessionService.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,6 @@ */ package com.example; -import java.util.Map; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.observation.EventIterator; -import javax.jcr.observation.EventListener; -import javax.servlet.http.HttpServletRequest; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -37,6 +31,13 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import javax.servlet.http.HttpServletRequest; +import java.util.Map; + @Component public class LongSessionService implements EventListener { diff --git a/src/test/files/checks/java/ModifiableValueMapUsageCheck.java b/src/test/resources/java/ModifiableValueMapUsageCheck.java similarity index 91% rename from src/test/files/checks/java/ModifiableValueMapUsageCheck.java rename to src/test/resources/java/ModifiableValueMapUsageCheck.java index bb79ba3e..8fdfc95b 100644 --- a/src/test/files/checks/java/ModifiableValueMapUsageCheck.java +++ b/src/test/resources/java/ModifiableValueMapUsageCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,10 +19,11 @@ */ package com.example; -import java.util.Map; import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.Resource; +import java.util.Map; + public class ModifiableValueMapUsageCheck { public Resource setProperty(Resource resource) { @@ -40,12 +41,12 @@ public Resource removeProperty(Resource resource) { } public Object getPropertyFromResource(Resource resource) { - ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant ValueMap should be used + ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant return createdResourceProperties.get("propName"); } public Object getProperty(Resource resource) { - ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant ValueMap should be used + ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant return getPropertyFromValueMap("propName", createdResourceProperties); } diff --git a/src/test/files/checks/java/ResourceResolverConsumer.java b/src/test/resources/java/ResourceResolverConsumer.java similarity index 97% rename from src/test/files/checks/java/ResourceResolverConsumer.java rename to src/test/resources/java/ResourceResolverConsumer.java index 2b399259..9eb074cc 100644 --- a/src/test/files/checks/java/ResourceResolverConsumer.java +++ b/src/test/resources/java/ResourceResolverConsumer.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -27,9 +27,10 @@ import com.day.cq.workflow.WorkflowSession; import com.day.cq.workflow.exec.WorkItem; import com.day.cq.workflow.metadata.MetaDataMap; -import javax.jcr.Session; import org.apache.sling.api.resource.ResourceResolver; +import javax.jcr.Session; + public class ResourceResolverConsumer extends AbstractAssetWorkflowProcess { private final ResourceResolverProducer resourceResolverProducer; diff --git a/src/test/files/checks/java/SampleServlet.java b/src/test/resources/java/SampleServlet.java similarity index 94% rename from src/test/files/checks/java/SampleServlet.java rename to src/test/resources/java/SampleServlet.java index 1383679b..55ad626e 100644 --- a/src/test/files/checks/java/SampleServlet.java +++ b/src/test/resources/java/SampleServlet.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,9 +19,6 @@ */ package com.example; -import java.io.IOException; -import java.util.Map; -import javax.servlet.ServletException; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.sling.SlingServlet; import org.apache.sling.api.SlingHttpServletRequest; @@ -34,6 +31,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Map; + @SlingServlet(paths = "somePath", methods = {HttpConstants.METHOD_GET}) public class SampleServlet extends SlingAllMethodsServlet { @@ -42,34 +43,11 @@ public class SampleServlet extends SlingAllMethodsServlet { @Reference private ResourceResolverFactory resourceResolverFactory; - @Override - protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) - throws ServletException, IOException { - ResourceResolver resourceResolver = null; // Noncompliant {{ResourceResolver should be closed in finally block.}} - try { - resourceResolver = resourceResolverFactory.getServiceResourceResolver(null); - } catch (LoginException e) { - LOGGER.error("Error during getting instance of ResourceResolver class", e); - } finally { - if (resourceResolver != null) { - //resourceResolver.close(); - } - } - } - - @Override - protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) - throws ServletException, IOException { - ResourceResolver resourceResolver = null; - resourceResolver = request.getResourceResolver(); - // do sth - } - /** * Create a new session for specified user (impersonating). */ public static ResourceResolver getResourceResolverForUser(ResourceResolverFactory factory, String userId) - throws LoginException { + throws LoginException { ResourceResolver resolver; if (userId != null) { Map authenticationInfo = new HashMap<>(); @@ -82,24 +60,47 @@ public static ResourceResolver getResourceResolverForUser(ResourceResolverFactor } public static ResourceResolver getResourceResolverForUserNested(ResourceResolverFactory factory, String userId) - throws LoginException { + throws LoginException { ResourceResolver resolver; resolver = getResourceResolverForUser(resourceResolverFactory, userId); return resolver; } public static ResourceResolver getResourceResolverForUserInit(ResourceResolverFactory factory) - throws LoginException { + throws LoginException { ResourceResolver resolver = factory.getServiceResourceResolver(null); return resolver; } public static ResourceResolver getResourceResolverForUserNestedInit(ResourceResolverFactory factory) - throws LoginException { + throws LoginException { ResourceResolver resolver = getResourceResolverForUserInit(resourceResolverFactory); return resolver; } + @Override + protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) + throws ServletException, IOException { + ResourceResolver resourceResolver = null; // Noncompliant {{ResourceResolver should be closed in finally block.}} + try { + resourceResolver = resourceResolverFactory.getServiceResourceResolver(null); + } catch (LoginException e) { + LOGGER.error("Error during getting instance of ResourceResolver class", e); + } finally { + if (resourceResolver != null) { + //resourceResolver.close(); + } + } + } + + @Override + protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) + throws ServletException, IOException { + ResourceResolver resourceResolver = null; + resourceResolver = request.getResourceResolver(); + // do sth + } + public void checkCorrectJumpMethod() { ResourceResolver resourceResolver = null; try { diff --git a/src/test/files/checks/java/SessionLogoutEight.java b/src/test/resources/java/SessionLogoutEight.java similarity index 95% rename from src/test/files/checks/java/SessionLogoutEight.java rename to src/test/resources/java/SessionLogoutEight.java index 53cd2a38..09cc4a7e 100644 --- a/src/test/files/checks/java/SessionLogoutEight.java +++ b/src/test/resources/java/SessionLogoutEight.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutFive.java b/src/test/resources/java/SessionLogoutFive.java similarity index 95% rename from src/test/files/checks/java/SessionLogoutFive.java rename to src/test/resources/java/SessionLogoutFive.java index 2fba3ba3..9e2c4b1f 100644 --- a/src/test/files/checks/java/SessionLogoutFive.java +++ b/src/test/resources/java/SessionLogoutFive.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutFour.java b/src/test/resources/java/SessionLogoutFour.java similarity index 96% rename from src/test/files/checks/java/SessionLogoutFour.java rename to src/test/resources/java/SessionLogoutFour.java index 03b53f92..b7a7f206 100644 --- a/src/test/files/checks/java/SessionLogoutFour.java +++ b/src/test/resources/java/SessionLogoutFour.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutOne.java b/src/test/resources/java/SessionLogoutOne.java similarity index 96% rename from src/test/files/checks/java/SessionLogoutOne.java rename to src/test/resources/java/SessionLogoutOne.java index cc661303..72798db3 100644 --- a/src/test/files/checks/java/SessionLogoutOne.java +++ b/src/test/resources/java/SessionLogoutOne.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutSeven.java b/src/test/resources/java/SessionLogoutSeven.java similarity index 96% rename from src/test/files/checks/java/SessionLogoutSeven.java rename to src/test/resources/java/SessionLogoutSeven.java index 5896c209..fa56046e 100644 --- a/src/test/files/checks/java/SessionLogoutSeven.java +++ b/src/test/resources/java/SessionLogoutSeven.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutSix.java b/src/test/resources/java/SessionLogoutSix.java similarity index 96% rename from src/test/files/checks/java/SessionLogoutSix.java rename to src/test/resources/java/SessionLogoutSix.java index ce7ef077..95ac9484 100644 --- a/src/test/files/checks/java/SessionLogoutSix.java +++ b/src/test/resources/java/SessionLogoutSix.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,13 +19,14 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.commons.lang3.StringUtils; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutThree.java b/src/test/resources/java/SessionLogoutThree.java similarity index 95% rename from src/test/files/checks/java/SessionLogoutThree.java rename to src/test/resources/java/SessionLogoutThree.java index 8dadd251..6651e92e 100644 --- a/src/test/files/checks/java/SessionLogoutThree.java +++ b/src/test/resources/java/SessionLogoutThree.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/java/SessionLogoutTwo.java b/src/test/resources/java/SessionLogoutTwo.java similarity index 95% rename from src/test/files/checks/java/SessionLogoutTwo.java rename to src/test/resources/java/SessionLogoutTwo.java index 652cadf2..92133555 100644 --- a/src/test/files/checks/java/SessionLogoutTwo.java +++ b/src/test/resources/java/SessionLogoutTwo.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,12 +19,13 @@ */ package com.example; -import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.jcr.api.SlingRepository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + @Component(immediate = true) public class SessionLogout { diff --git a/src/test/files/checks/slingquery/SlingQueryImplicitStrategyCheck.java b/src/test/resources/java/SlingQueryImplicitStrategyCheck.java similarity index 72% rename from src/test/files/checks/slingquery/SlingQueryImplicitStrategyCheck.java rename to src/test/resources/java/SlingQueryImplicitStrategyCheck.java index 51f09008..c77b3667 100644 --- a/src/test/files/checks/slingquery/SlingQueryImplicitStrategyCheck.java +++ b/src/test/resources/java/SlingQueryImplicitStrategyCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -17,13 +17,8 @@ * limitations under the License. * #L% */ -package com.cognifide.statistics.accelerator.foundation.datasource; +package com.vml.statistics.accelerator.foundation.datasource; -import static org.apache.sling.query.SlingQuery.$; - -import java.io.IOException; -import java.util.Optional; -import javax.servlet.ServletException; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; @@ -33,12 +28,18 @@ import org.apache.sling.query.api.SearchStrategy; import org.apache.tools.ant.taskdefs.optional.Script; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Optional; + +import static org.apache.sling.query.SlingQuery.$; + public class SlingQueryImplicitStrategyCheck extends SlingAllMethodsServlet { private static final String SOMETHING = "something"; protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { Resource resource = request.getResource(); strategyNotDefined(resource); strategyDefined(resource); @@ -70,7 +71,7 @@ private void strategyDefined(Resource resource) { SlingQuery.$(resource).searchStrategy(SearchStrategy.BFS).find("").find(); $(resource).searchStrategy(SearchStrategy.QUERY).find("res_type").asList().stream() - .map(r -> r.adaptTo(SlingQueryImplicitStrategyCheck.class).toString()).filter(StringUtils::isNotEmpty).iterator(); + .map(r -> r.adaptTo(SlingQueryImplicitStrategyCheck.class).toString()).filter(StringUtils::isNotEmpty).iterator(); } public void casesThatShouldBeIgnored() { @@ -81,33 +82,33 @@ public void casesThatShouldBeIgnored() { } GroupPage groupPage = repository.find(queryModel.getSolrCore(), - queryModel.getPreparedQuery(), - queryModel.getGroupLimit(), - queryModel.getSortType(), - queryModel.getFiltersQueryModel().getFiltersCriteria()); + queryModel.getPreparedQuery(), + queryModel.getGroupLimit(), + queryModel.getSortType(), + queryModel.getFiltersQueryModel().getFiltersCriteria()); } public void testVer1() { this.variable = Optional.of(resource.getResourceMetadata()) - .map(metadata -> metadata.get(ResourceMetadata.RESOLUTION_PATH)) - .filter(String.class::isInstance) - .map(String::valueOf) - .map(path -> resource.getResourceResolver().getResource(path)) - .map(r -> $(r).searchStrategy(SearchStrategy.QUERY).find(SOMETHING).asList()) - .map(list -> list.get(0)); + .map(metadata -> metadata.get(ResourceMetadata.RESOLUTION_PATH)) + .filter(String.class::isInstance) + .map(String::valueOf) + .map(path -> resource.getResourceResolver().getResource(path)) + .map(r -> $(r).searchStrategy(SearchStrategy.QUERY).find(SOMETHING).asList()) + .map(list -> list.get(0)); } public void testVer2() { this.variable = Optional.of(resource.getResourceMetadata()) - .map(metadata -> metadata.get(ResourceMetadata.RESOLUTION_PATH)) - .filter(String.class::isInstance) - .map(String::valueOf) - .map(path -> resource.getResourceResolver().getResource(path)) - .map(r -> $(r).find(SOMETHING).asList()) // Noncompliant - .map(list -> list.get(0)); + .map(metadata -> metadata.get(ResourceMetadata.RESOLUTION_PATH)) + .filter(String.class::isInstance) + .map(String::valueOf) + .map(path -> resource.getResourceResolver().getResource(path)) + .map(r -> $(r).find(SOMETHING).asList()) // Noncompliant + .map(list -> list.get(0)); } private Resource test2() { return resource = Iterables.getFirst($(configurationResource).find(MapConfigurationModel.RESOURCE_TYPE), null); // Noncompliant } -} \ No newline at end of file +} diff --git a/src/test/files/checks/java/slingservlet/SlingServletOne.java b/src/test/resources/java/SlingServletOne.java similarity index 82% rename from src/test/files/checks/java/slingservlet/SlingServletOne.java rename to src/test/resources/java/SlingServletOne.java index 59a67002..5d07d2cc 100644 --- a/src/test/files/checks/java/slingservlet/SlingServletOne.java +++ b/src/test/resources/java/SlingServletOne.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,8 +19,6 @@ */ package com.example; -import java.io.IOException; -import javax.servlet.ServletException; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; @@ -30,17 +28,20 @@ import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import javax.servlet.ServletException; +import java.io.IOException; + @Component // Noncompliant {{Prefer cleaner @SlingServlet annotation.}} @Service(value = javax.servlet.Servlet.class) @Properties({@Property(name = "sling.servlet.resourceTypes", value = {"sling/servlet/default"}), - @Property(name = "sling.servlet.selectors", value = {"selector"}), - @Property(name = "sling.servlet.extensions", value = {"tab"}), - @Property(name = "sling.servlet.methods", value = {HttpConstants.METHOD_GET})}) + @Property(name = "sling.servlet.selectors", value = {"selector"}), + @Property(name = "sling.servlet.extensions", value = {"tab"}), + @Property(name = "sling.servlet.methods", value = {HttpConstants.METHOD_GET})}) public class SlingTestOne extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { //do sth } } diff --git a/src/test/files/checks/java/slingservlet/SlingServletThree.java b/src/test/resources/java/SlingServletThree.java similarity index 64% rename from src/test/files/checks/java/slingservlet/SlingServletThree.java rename to src/test/resources/java/SlingServletThree.java index b6cafcfa..06bc32ec 100644 --- a/src/test/files/checks/java/slingservlet/SlingServletThree.java +++ b/src/test/resources/java/SlingServletThree.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,10 +19,6 @@ */ package com.example; -import static org.apache.sling.servlets.resolver.internal.ServletResolverConstants.SLING_SERVLET_EXTENSIONS; - -import java.io.IOException; -import javax.servlet.ServletException; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.sling.SlingServlet; @@ -31,19 +27,24 @@ import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.apache.sling.servlets.resolver.internal.ServletResolverConstants; +import javax.servlet.ServletException; +import java.io.IOException; + +import static org.apache.sling.servlets.resolver.internal.ServletResolverConstants.SLING_SERVLET_EXTENSIONS; + @SlingServlet(methods = "GET") @Properties({ - @Property(name = Constants.SERVICE_VENDOR, value = "Cognifide"), - @Property(name = Constants.SERVICE_DESCRIPTION, value = "Some description"), - @Property(name = ServletResolverConstants.SLING_SERVLET_SELECTORS, value = "selector"), // Noncompliant {{Property SLING_SERVLET_SELECTORS can be handled by @SlingServlet annotation.}} - @Property(name = SLING_SERVLET_EXTENSIONS, value = "json"), // Noncompliant {{Property SLING_SERVLET_EXTENSIONS can be handled by @SlingServlet annotation.}} - @Property(name = "sling.servlet.resourceTypes", value = {"sling/servlet/default"}) // Noncompliant {{Property "sling.servlet.resourceTypes" can be handled by @SlingServlet annotation.}} + @Property(name = Constants.SERVICE_VENDOR, value = "Cognifide"), + @Property(name = Constants.SERVICE_DESCRIPTION, value = "Some description"), + @Property(name = ServletResolverConstants.SLING_SERVLET_SELECTORS, value = "selector"), // Noncompliant {{Property SLING_SERVLET_SELECTORS can be handled by @SlingServlet annotation.}} + @Property(name = SLING_SERVLET_EXTENSIONS, value = "json"), // Noncompliant {{Property SLING_SERVLET_EXTENSIONS can be handled by @SlingServlet annotation.}} + @Property(name = "sling.servlet.resourceTypes", value = {"sling/servlet/default"}) // Noncompliant {{Property "sling.servlet.resourceTypes" can be handled by @SlingServlet annotation.}} }) public class SlingTestThree extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { //do sth } } diff --git a/src/test/files/checks/java/slingservlet/SlingServletTwo.java b/src/test/resources/java/SlingServletTwo.java similarity index 85% rename from src/test/files/checks/java/slingservlet/SlingServletTwo.java rename to src/test/resources/java/SlingServletTwo.java index 8eae2661..20844279 100644 --- a/src/test/files/checks/java/slingservlet/SlingServletTwo.java +++ b/src/test/resources/java/SlingServletTwo.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,8 +19,6 @@ */ package com.example; -import java.io.IOException; -import javax.servlet.ServletException; import org.apache.felix.scr.annotations.Properties; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; @@ -29,16 +27,19 @@ import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import javax.servlet.ServletException; +import java.io.IOException; + @Service // Noncompliant {{@Component nor @Service annotation is not needed when @SlingServlet is used.}} @SlingServlet(resourceTypes = "sling/servlet/default", selectors = "someSelector", extensions = "json", methods = "GET") @Properties({ - @Property(name = Constants.SERVICE_VENDOR, value = "Cognifide"), - @Property(name = Constants.SERVICE_DESCRIPTION, value = "Some description")}) + @Property(name = Constants.SERVICE_VENDOR, value = "Cognifide"), + @Property(name = Constants.SERVICE_DESCRIPTION, value = "Some description")}) public class SlingTestTwo extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { //do sth } } diff --git a/src/test/files/checks/java/slingservlet/SlingServletWithStandardAnnotations.java b/src/test/resources/java/SlingServletWithStandardAnnotations.java similarity index 81% rename from src/test/files/checks/java/slingservlet/SlingServletWithStandardAnnotations.java rename to src/test/resources/java/SlingServletWithStandardAnnotations.java index 6f227fa3..0f10d3ab 100644 --- a/src/test/files/checks/java/slingservlet/SlingServletWithStandardAnnotations.java +++ b/src/test/resources/java/SlingServletWithStandardAnnotations.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,26 +19,27 @@ */ package com.example; -import java.io.IOException; -import javax.servlet.Servlet; -import javax.servlet.ServletException; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; + @Component(property = { // Compliant {{ OSGi standard annotations are OK}} - "sling.servlet.resourceTypes=sling/servlet/default", - "sling.servlet.selectors=selector", - "sling.servlet.extensions=tab", - "sling.servlet.methods=" + HttpConstants.METHOD_GET + "sling.servlet.resourceTypes=sling/servlet/default", + "sling.servlet.selectors=selector", + "sling.servlet.extensions=tab", + "sling.servlet.methods=" + HttpConstants.METHOD_GET }, service = Servlet.class) public class SlingServletWithStandardAnnotations extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { //do sth } } diff --git a/src/test/files/checks/java/SynchronizedKeywordUsageCheck.java b/src/test/resources/java/SynchronizedKeywordUsageCheck.java similarity index 96% rename from src/test/files/checks/java/SynchronizedKeywordUsageCheck.java rename to src/test/resources/java/SynchronizedKeywordUsageCheck.java index ab800086..a3ba0397 100644 --- a/src/test/files/checks/java/SynchronizedKeywordUsageCheck.java +++ b/src/test/resources/java/SynchronizedKeywordUsageCheck.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -25,6 +25,7 @@ public class SynchronizedKeywordUsageCheck { private final List list = new ArrayList<>(16); + private int counter = 0; public synchronized void addElement(String s) { // Noncompliant {{Usage of 'synchronized' keyword should be avoided if possible.}} list.add(s); @@ -36,8 +37,6 @@ public void removeElement(String s) { } } - private int counter = 0; - public synchronized void increment() { // Noncompliant counter++; } diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckDsComponentAnnotation.java b/src/test/resources/java/ThreadSafeFieldCheckDsComponentAnnotation.java similarity index 94% rename from src/test/files/checks/java/ThreadSafeFieldCheckDsComponentAnnotation.java rename to src/test/resources/java/ThreadSafeFieldCheckDsComponentAnnotation.java index 8628b041..898d280a 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckDsComponentAnnotation.java +++ b/src/test/resources/java/ThreadSafeFieldCheckDsComponentAnnotation.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,9 +19,10 @@ */ package com.example; -import javax.jcr.Session; import org.osgi.service.component.annotations.Component; +import javax.jcr.Session; + @Component public class ThreadSafeFieldCheckDsComponentAnnotationExample { diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckEventHandler.java b/src/test/resources/java/ThreadSafeFieldCheckEventHandler.java similarity index 94% rename from src/test/files/checks/java/ThreadSafeFieldCheckEventHandler.java rename to src/test/resources/java/ThreadSafeFieldCheckEventHandler.java index 470827a9..20568033 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckEventHandler.java +++ b/src/test/resources/java/ThreadSafeFieldCheckEventHandler.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,9 +19,10 @@ */ package com.example; -import javax.jcr.Session; import org.osgi.service.event.EventHandler; +import javax.jcr.Session; + public class ThreadSafeFieldCheckEventHandlerExample implements EventHandler { diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckFilter.java b/src/test/resources/java/ThreadSafeFieldCheckFilter.java similarity index 92% rename from src/test/files/checks/java/ThreadSafeFieldCheckFilter.java rename to src/test/resources/java/ThreadSafeFieldCheckFilter.java index 28d65824..75ebf878 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckFilter.java +++ b/src/test/resources/java/ThreadSafeFieldCheckFilter.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -21,18 +21,19 @@ import com.day.cq.tagging.TagManager; import com.day.cq.wcm.api.PageManager; -import java.io.IOException; +import org.apache.felix.scr.annotations.sling.SlingFilter; +import org.apache.felix.scr.annotations.sling.SlingFilterScope; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import org.apache.felix.scr.annotations.sling.SlingFilter; -import org.apache.felix.scr.annotations.sling.SlingFilterScope; +import java.io.IOException; @SlingFilter(scope = SlingFilterScope.COMPONENT, order = Integer.MAX_VALUE, metatype = true, label = - "label", description = "description") + "label", description = "description") public class ThreadSafeFieldCheckFilterExample implements Filter { private PageManager pageManager; // Noncompliant {{Usage of com.day.cq.wcm.api.PageManager as a field is not thread safe.}} @@ -46,7 +47,7 @@ public void init(FilterConfig filterConfig) throws ServletException { @Override public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) - throws IOException, ServletException { + throws IOException, ServletException { // filter } diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckScrComponentAnnotation.java b/src/test/resources/java/ThreadSafeFieldCheckScrComponentAnnotation.java similarity index 93% rename from src/test/files/checks/java/ThreadSafeFieldCheckScrComponentAnnotation.java rename to src/test/resources/java/ThreadSafeFieldCheckScrComponentAnnotation.java index 010d152e..ae9a508a 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckScrComponentAnnotation.java +++ b/src/test/resources/java/ThreadSafeFieldCheckScrComponentAnnotation.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,9 +19,10 @@ */ package com.example; -import javax.jcr.Session; import org.apache.felix.scr.annotations.Component; +import javax.jcr.Session; + @Component public class ThreadSafeFieldCheckComponentAnnotationExample { diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckServlet.java b/src/test/resources/java/ThreadSafeFieldCheckServlet.java similarity index 97% rename from src/test/files/checks/java/ThreadSafeFieldCheckServlet.java rename to src/test/resources/java/ThreadSafeFieldCheckServlet.java index 2b2298af..f266bf23 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckServlet.java +++ b/src/test/resources/java/ThreadSafeFieldCheckServlet.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. diff --git a/src/test/files/checks/java/ThreadSafeFieldCheckSlingServletAnnotation.java b/src/test/resources/java/ThreadSafeFieldCheckSlingServletAnnotation.java similarity index 93% rename from src/test/files/checks/java/ThreadSafeFieldCheckSlingServletAnnotation.java rename to src/test/resources/java/ThreadSafeFieldCheckSlingServletAnnotation.java index b945ca24..a670b840 100644 --- a/src/test/files/checks/java/ThreadSafeFieldCheckSlingServletAnnotation.java +++ b/src/test/resources/java/ThreadSafeFieldCheckSlingServletAnnotation.java @@ -2,7 +2,7 @@ * #%L * AEM Rules for SonarQube * %% - * Copyright (C) 2015-2019 Wunderman Thompson Technology + * 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. @@ -19,9 +19,10 @@ */ package com.example; -import javax.jcr.Session; import org.apache.felix.scr.annotations.sling.SlingServlet; +import javax.jcr.Session; + @SlingServlet public class ThreadSafeFieldCheckSlingServletExample { diff --git a/src/test/resources/scanner/testFile.html b/src/test/resources/scanner/testFile.html index ec8f57c8..aca99c8a 100644 --- a/src/test/resources/scanner/testFile.html +++ b/src/test/resources/scanner/testFile.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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. diff --git a/src/test/resources/sensor/error.html b/src/test/resources/sensor/error.html index 8973e548..29d61280 100644 --- a/src/test/resources/sensor/error.html +++ b/src/test/resources/sensor/error.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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. diff --git a/src/test/resources/sensor/nestedTags.html b/src/test/resources/sensor/nestedTags.html index b0a435cd..4e3f33d0 100644 --- a/src/test/resources/sensor/nestedTags.html +++ b/src/test/resources/sensor/nestedTags.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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. diff --git a/src/test/resources/sensor/test.html b/src/test/resources/sensor/test.html index ef26da5c..b99e99d5 100644 --- a/src/test/resources/sensor/test.html +++ b/src/test/resources/sensor/test.html @@ -3,7 +3,7 @@ #%L AEM Rules for SonarQube %% - Copyright (C) 2015-2019 Wunderman Thompson Technology + 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.