Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sonarqube 8.9 compatibility #218

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<htl.version>1.1.2-1.4.0</htl.version>
<sonar.version>7.9.2</sonar.version>
<sonar.version>8.9.6.50800</sonar.version>
<sonar.html.version>3.0.1.1444</sonar.html.version>
<sonar.java.plugin>6.2.0.21135</sonar.java.plugin>
<sonar.java.plugin>7.6.0.28201</sonar.java.plugin>
<sonar-java-checks-testkit-version>7.6.0.28201</sonar-java-checks-testkit-version>
<coveralls.repo.token>4rVf3NGV0jyQ3EGrc8L86oEDoHWm6MgDD</coveralls.repo.token>
<tagName>v${project.version}</tagName>
</properties>
Expand All @@ -133,12 +134,21 @@
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
<version>${htl.version}</version>
</dependency>

<!-- sonarsource version -->
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>${sonar.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
Expand Down Expand Up @@ -212,7 +222,7 @@
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
<version>${sonar.java.plugin}</version>
<version>${sonar-java-checks-testkit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -299,6 +309,12 @@
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public List<Tree.Kind> nodesToVisit() {

@Override
public void visitNode(Tree tree) {
if (this.hasSemantic()) {
matchers.forEach(invocationMatcher -> this.checkInvocation(tree, invocationMatcher));
}
matchers.forEach(invocationMatcher -> this.checkInvocation(tree, invocationMatcher));
}

private void checkInvocation(Tree tree, MethodMatcher invocationMatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.junit.Test;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinition.NewRepository;
import org.sonar.api.server.rule.RulesDefinition.RepositoryImpl;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void setUp() {
public void shouldLoadRuleWithAllSettings() {
givenRulesLoaded(Arrays.asList(RuleWithAllSettings.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);

Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
Expand All @@ -90,7 +89,7 @@ public void shouldLoadRuleWithAllSettings() {
public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() {
givenRulesLoaded(Arrays.asList(RuleWithoutMetadataAnnotation.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);

Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
Expand All @@ -104,7 +103,7 @@ public void shouldNotSetTechnicalDebtWhenAnnotationNotPresent() {
public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() {
givenRulesLoaded(Arrays.asList(RuleWithEmptyTechnicalDebt.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);

Assert.assertThat(rule.markdownDescription(), is(RULE_MARKDOWN_TEST_DESCRIPTION));
Expand All @@ -118,7 +117,7 @@ public void shouldNotSetTechnicalDebtWhenTechnicalDebtNotSetInMetadata() {
public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() {
givenRulesLoaded(Arrays.asList(RuleWithoutRuleAnnotation.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);

Assert.assertThat(rule, is(nullValue()));
Expand All @@ -129,7 +128,7 @@ public void shouldNotLoadRuleWhenRuleAnnotationIsNotPresent() {
public void shouldSetDefaultValuesWhenRuleAttributeWithNameOnly() {
givenRulesLoaded(Arrays.asList(RuleWithOnlyNameAttribute.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule("com.cognifide.aemrules.extensions.RulesLoaderTest.RuleWithOnlyNameAttribute");

Assert.assertThat(rule.markdownDescription(), is("No description yet."));
Expand All @@ -148,7 +147,7 @@ public void shouldThrowExceptionWhenRuleNameNotProvide() {
public void shouldLoadRuleWithProperty() {
givenRulesLoaded(Arrays.asList(RuleWithRuleProperty.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);
RulesDefinition.Param param = rule.param(RULE_PROPERTY_KEY);

Expand All @@ -161,7 +160,7 @@ public void shouldLoadRuleWithProperty() {
public void shouldLoadRuleWithPropertyWithoutAttributes() {
givenRulesLoaded(Arrays.asList(RuleWithRulePropertyWithoutAttributes.class));

RepositoryImpl repository = (RepositoryImpl) context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Repository repository = context.repository(JavaCheckClasses.REPOSITORY_KEY);
RulesDefinition.Rule rule = repository.rule(RULE_KEY);
RulesDefinition.Param param = rule.param("testProperty");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.internal.google.common.io.Files;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.sonar.java.checks.verifier.JavaCheckVerifier;
import org.sonar.java.checks.verifier.CheckVerifier;
import org.sonar.plugins.java.api.JavaFileScanner;

public abstract class AbstractBaseTest {
Expand Down Expand Up @@ -66,13 +66,23 @@ protected void verify() {

protected void verify(boolean withJarClassPath) {
if (withJarClassPath) {
JavaCheckVerifier.verify(filename, check, CLASSPATH_JAR);
CheckVerifier.newVerifier()
.onFile(filename)
.withCheck(check)
.withClassPath(CLASSPATH_JAR)
.verifyIssues();
} else {
JavaCheckVerifier.verify(filename, check);
CheckVerifier.newVerifier()
.onFile(filename)
.withCheck(check)
.verifyIssues();
}
}

protected void verifyNoIssues() {
JavaCheckVerifier.verifyNoIssue(filename, check);
CheckVerifier.newVerifier()
.onFile(filename)
.withCheck(check)
.verifyNoIssues();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.sonar.java.model.JParser;
import org.sonar.java.model.JParserConfig;
import org.sonar.plugins.java.api.tree.ClassTree;
import org.sonar.plugins.java.api.tree.CompilationUnitTree;
import org.sonar.plugins.java.api.tree.ExpressionStatementTree;
Expand Down Expand Up @@ -161,7 +162,7 @@ private void givenMethodInvocationTree(String codeToParse) {

private CompilationUnitTree parse(String source) {
List<File> classpath = Arrays.asList(new File(TEST_CLASSES_FILEPATH), new File(CLASSES_FILEPATH));
return JParser.parse(JAVA_VERSION, UNIT_NAME, source, classpath);
return JParser.parse(JParserConfig.Mode.FILE_BY_FILE.create(JAVA_VERSION, classpath).astParser(), JAVA_VERSION, UNIT_NAME, source);
}

}
Expand Down