Skip to content

Commit

Permalink
Update dependency on sonar-analyzer-commons to 1.14.1 (#775)
Browse files Browse the repository at this point in the history
* Update dependency on sonar-analyzer-commons to 1.14.1

* Adapt code to analyzer-commons version
  • Loading branch information
karim-ouerghemmi-sonarsource authored Apr 29, 2021
1 parent 4b7654e commit 44c7760
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String repositoryKey() {
}

@Override
public List<Class> checkClasses() {
public List<Class<?>> checkClasses() {
return Arrays.asList(CustomPHPVisitorCheck.class, CustomPHPSubscriptionCheck.class);
}
}
12 changes: 6 additions & 6 deletions php-checks/src/main/java/org/sonar/php/checks/CheckList.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class CheckList {
private CheckList() {
}

public static List<Class> getChecks() {
return ImmutableList.<Class>of(
public static List<Class<?>> getChecks() {
return ImmutableList.of(
AbortedTestCaseCheck.class,
AliasFunctionUsageCheck.class,
AllBranchesIdenticalCheck.class,
Expand Down Expand Up @@ -289,8 +289,8 @@ public static List<Class> getChecks() {
ZipEntryCheck.class);
}

public static Iterable<Class> getPhpIniChecks() {
return ImmutableList.<Class>of(
public static Iterable<Class<?>> getPhpIniChecks() {
return ImmutableList.of(
AllowUrlCheck.class,
CookiesSecureCheck.class,
CgiForceRedirectCheck.class,
Expand All @@ -302,8 +302,8 @@ public static Iterable<Class> getPhpIniChecks() {
SessionUseTransSidCheck.class);
}

public static Set<Class> getAllChecks() {
return ImmutableSet.<Class>builder()
public static Set<Class<?>> getAllChecks() {
return ImmutableSet.<Class<?>>builder()
.addAll(CheckList.getChecks())
.addAll(CheckList.getPhpIniChecks())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void count() {
*/
@Test
public void test() {
Set<Class> checks = CheckList.getAllChecks();
Set<Class<?>> checks = CheckList.getAllChecks();

for (Class<?> cls : checks) {
if (cls != ParsingErrorCheck.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.php.checks.utils;

import com.sonar.sslr.api.typed.ActionParser;
import com.sonarsource.checks.coverage.UtilityClass;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -49,6 +48,7 @@
import org.sonar.plugins.php.api.tree.statement.ExpressionStatementTree;
import org.sonar.plugins.php.api.tree.statement.ForStatementTree;
import org.sonar.plugins.php.api.tree.statement.StatementTree;
import org.sonarsource.analyzer.commons.checks.coverage.UtilityClass;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
package org.sonar.php.checks.utils;

import com.sonar.sslr.api.typed.ActionParser;
import com.sonarsource.checks.coverage.UtilityClass;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.junit.Test;
import org.sonar.php.parser.PHPLexicalGrammar;
import org.sonar.php.parser.PHPParserBuilder;
import org.sonar.plugins.php.api.tree.Tree;
import org.sonarsource.analyzer.commons.checks.coverage.UtilityClass;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.common.base.Preconditions;
import com.sonar.sslr.api.typed.ActionParser;
import com.sonarsource.checks.verifier.MultiFileVerifier;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -45,6 +44,7 @@
import org.sonar.plugins.php.api.visitors.PhpFile;
import org.sonar.plugins.php.api.visitors.PhpIssue;
import org.sonar.plugins.php.api.visitors.PreciseIssue;
import org.sonarsource.analyzer.commons.checks.verifier.MultiFileVerifier;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface PHPCustomRuleRepository {
/**
* List of the custom rules classes.
*/
List<Class> checkClasses();
List<Class<?>> checkClasses();

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<version.sslr>1.24.0.633</version.sslr>
<version.guava>30.1.1-jre</version.guava>
<version.sonarlint>4.7.0.12286</version.sonarlint>
<version.analyzer-commons>1.10.2.456</version.analyzer-commons>
<version.analyzer-commons>1.14.1.690</version.analyzer-commons>

<!-- Release: enable publication to Bintray -->
<artifactsToPublish>${project.groupId}:sonar-php-plugin:jar</artifactsToPublish>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
Expand All @@ -46,7 +47,7 @@ public static PHPChecks createPHPCheck(CheckFactory checkFactory) {
return new PHPChecks(checkFactory);
}

public PHPChecks addChecks(String repositoryKey, Iterable<Class> checkClass) {
public PHPChecks addChecks(String repositoryKey, Iterable<Class<?>> checkClass) {
checksByRepository.add(checkFactory
.<PHPCheck>create(repositoryKey)
.addAnnotatedChecks(checkClass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ public final class PHPProfileDefinition implements BuiltInQualityProfilesDefinit
public static final String SONAR_WAY_PROFILE = "Sonar way";
public static final String SONAR_WAY_PATH = "org/sonar/l10n/php/rules/php/Sonar_way_profile.json";

private final SonarRuntime sonarRuntime;

public PHPProfileDefinition(SonarRuntime sonarRuntime) {
this.sonarRuntime = sonarRuntime;
}

@Override
public void define(Context context) {
NewBuiltInQualityProfile sonarWay = context.createBuiltInQualityProfile(SONAR_WAY_PROFILE, Php.KEY);
sonarWay.activateRule("common-" + Php.KEY, "DuplicatedBlocks");
BuiltInQualityProfileJsonLoader.load(sonarWay, CheckList.REPOSITORY_KEY, SONAR_WAY_PATH, RESOURCE_BASE_PATH, sonarRuntime);
BuiltInQualityProfileJsonLoader.load(sonarWay, CheckList.REPOSITORY_KEY, SONAR_WAY_PATH);
getSecurityRuleKeys().forEach(key -> sonarWay.activateRule(key.repository(), key.rule()));
sonarWay.done();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.plugins.php;

import java.util.ArrayList;
import org.sonar.api.SonarRuntime;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.php.checks.CheckList;
import org.sonar.plugins.php.api.Php;
Expand All @@ -30,17 +29,12 @@ public class PHPRulesDefinition implements RulesDefinition {

private static final String REPOSITORY_NAME = "SonarAnalyzer";
static final String RESOURCE_BASE_PATH = "org/sonar/l10n/php/rules/php";
private final SonarRuntime sonarRuntime;

public PHPRulesDefinition(SonarRuntime sonarRuntime) {
this.sonarRuntime = sonarRuntime;
}

@Override
public void define(Context context) {
NewRepository repository = context.createRepository(CheckList.REPOSITORY_KEY, Php.KEY).setName(REPOSITORY_NAME);

RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, PHPProfileDefinition.SONAR_WAY_PATH, sonarRuntime);
RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RESOURCE_BASE_PATH, PHPProfileDefinition.SONAR_WAY_PATH);

ruleMetadataLoader.addRulesByAnnotatedClass(repository, new ArrayList<>(CheckList.getAllChecks()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public class PHPProfileDefinitionTest {
public void should_create_sonar_way_profile() {
ValidationMessages validation = ValidationMessages.create();

SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
PHPProfileDefinition definition = new PHPProfileDefinition(sonarRuntime);
PHPProfileDefinition definition = new PHPProfileDefinition();
definition.define(context);
BuiltInQualityProfilesDefinition.BuiltInQualityProfile profile = context.profile("php", "Sonar way");
assertThat(profile.language()).isEqualTo(Php.KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class PHPRulesDefinitionTest {

@Test
public void testActivationSonarLint() {
SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
PHPRulesDefinition rulesDefinition = new PHPRulesDefinition(sonarRuntime);
PHPRulesDefinition rulesDefinition = new PHPRulesDefinition();
RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
RulesDefinition.Repository repository = context.repository("php");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public String repositoryKey() {
}

@Override
public ImmutableList<Class> checkClasses() {
public ImmutableList<Class<?>> checkClasses() {
return ImmutableList.of(MyCustomRule.class);
}
}};
Expand Down

0 comments on commit 44c7760

Please sign in to comment.