Skip to content

Commit

Permalink
SONARPHP-625 Upgrade to SonarQube 5.6 LTS (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandalbosco authored and vilchik-elena committed Sep 20, 2016
1 parent eab8b93 commit 802650d
Show file tree
Hide file tree
Showing 297 changed files with 1,593 additions and 2,265 deletions.
8 changes: 4 additions & 4 deletions its/plugin/plugins/php-custom-rules-plugin/pom.xml
Expand Up @@ -17,7 +17,7 @@

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
</dependency>
<dependency>
Expand All @@ -32,7 +32,7 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
Expand All @@ -44,8 +44,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -19,18 +19,13 @@
*/
package org.sonar.samples.php;

import com.google.common.collect.ImmutableList;
import org.sonar.api.SonarPlugin;
import org.sonar.api.Plugin;

import java.util.List;

public class CustomPHPRulesPlugin extends SonarPlugin {
public class CustomPHPRulesPlugin implements Plugin {

@Override
public List getExtensions() {
return ImmutableList.of(
CustomPHPRulesDefinition.class
);
public void define(Context context) {
context.addExtension(CustomPHPRulesDefinition.class);
}

}
Expand Up @@ -20,23 +20,19 @@
package org.sonar.samples.php;

import com.google.common.collect.ImmutableList;
import org.sonar.api.server.rule.RulesDefinition;
import java.util.List;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.php.api.tree.Tree;
import org.sonar.plugins.php.api.tree.Tree.Kind;
import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;

import java.util.List;

@Rule(
key = "subscription",
priority = Priority.MINOR,
name = "PHP subscription visitor check",
description = "desc")
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.SECURITY_FEATURES)
@SqaleConstantRemediation("10min")
public class CustomPHPSubscriptionCheck extends PHPSubscriptionCheck {

Expand Down
Expand Up @@ -19,20 +19,17 @@
*/
package org.sonar.samples.php;

import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.plugins.php.api.tree.expression.FunctionExpressionTree;
import org.sonar.plugins.php.api.visitors.PHPVisitorCheck;
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
import org.sonar.squidbridge.annotations.SqaleSubCharacteristic;

@Rule(
key = "visitor",
priority = Priority.MINOR,
name = "PHP visitor check",
description = "desc")
@SqaleSubCharacteristic(RulesDefinition.SubCharacteristics.SECURITY_FEATURES)
@SqaleConstantRemediation("5min")
public class CustomPHPVisitorCheck extends PHPVisitorCheck {

Expand Down
Expand Up @@ -22,15 +22,13 @@
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import org.junit.Assume;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.issue.IssueQuery;

import java.io.File;

import static org.fest.assertions.Assertions.assertThat;

public class CommonRulesTest {
Expand All @@ -50,7 +48,7 @@ public static void startServer() throws Exception {

createReportsWithAbsolutePath();

SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(PROJECT_DIR)
.setProjectKey("project")
.setProjectName("project")
Expand Down
Expand Up @@ -19,18 +19,16 @@
*/
package com.sonar.it.php;

import org.junit.ClassRule;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.issue.IssueQuery;

import java.util.List;

import static org.fest.assertions.Assertions.assertThat;

public class CustomRulesTest {
Expand All @@ -43,7 +41,7 @@ public class CustomRulesTest {
@BeforeClass
public static void prepare() throws InterruptedException {
orchestrator.resetData();
SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(Tests.projectDirectoryFor("custom_rules"))
.setProjectKey("custom-rules")
.setProjectName("Custom Rules")
Expand Down
Expand Up @@ -20,7 +20,7 @@
package com.sonar.it.php;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.locator.FileLocation;
import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -47,7 +47,7 @@ public static void startServer() throws IOException, URISyntaxException, Interru
orchestrator.resetData();
sonar = orchestrator.getServer().getWsClient();

SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectKey("project")
.setProjectName("project")
.setProjectVersion("1")
Expand All @@ -58,8 +58,6 @@ public static void startServer() throws IOException, URISyntaxException, Interru
.setProperty("sonar.exclusions", "**/Component/**/*.php");

orchestrator.executeBuild(build);
// Thread.sleep(Integer.MAX_VALUE);

}

@Test
Expand Down
13 changes: 6 additions & 7 deletions its/plugin/tests/src/test/java/com/sonar/it/php/PHPTest.java
Expand Up @@ -20,7 +20,9 @@
package com.sonar.it.php;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.IOException;
import java.net.URISyntaxException;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -29,9 +31,6 @@
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

import java.io.IOException;
import java.net.URISyntaxException;

import static org.fest.assertions.Assertions.assertThat;

public class PHPTest {
Expand All @@ -55,7 +54,7 @@ public static void startServer() throws IOException, URISyntaxException {
*/
@Test
public void should_import_sources_with_user_defined_file_suffixes() {
SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(Tests.projectDirectoryFor("project-with-several-extensions"))
.setProfile("it-profile")
.setProperty("sonar.php.file.suffixes", "php,php3,php4,myphp,html");
Expand All @@ -66,13 +65,12 @@ public void should_import_sources_with_user_defined_file_suffixes() {
assertThat(getResource(getResourceKey(SEVERAL_EXTENSIONS_PROJECT_KEY, "Math3.pgp"))).isNull();
}


/**
* SONARPLUGINS-943
*/
@Test
public void should_support_multimodule_projects() {
SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(Tests.projectDirectoryFor("multimodule"))
.setProfile("it-profile");
orchestrator.executeBuild(build);
Expand All @@ -89,6 +87,7 @@ private String getResourceKey(String projectKey, String fileName) {
private Resource getResource(String resourceKey) {
return sonar.find(ResourceQuery.create(resourceKey));
}

private Measure getResourceMeasure(String resourceKey, String metricKey) {
Resource resource = sonar.find(ResourceQuery.createForMetrics(resourceKey, metricKey.trim()));
return resource == null ? null : resource.getMeasure(metricKey.trim());
Expand Down
18 changes: 9 additions & 9 deletions its/plugin/tests/src/test/java/com/sonar/it/php/PHPUnitTest.java
Expand Up @@ -22,7 +22,7 @@
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import org.junit.BeforeClass;
import org.junit.ClassRule;
Expand All @@ -45,12 +45,12 @@ public class PHPUnitTest {
private static final String REPORTS_DIR = "reports";

@BeforeClass
public static void sspotartServer() throws Exception {
public static void startServer() throws Exception {
orchestrator.resetData();

createReportsWithAbsolutePath();

SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(PROJECT_DIR)
.setProjectKey("project")
.setProjectName("project")
Expand All @@ -73,22 +73,22 @@ public void tests() throws Exception {

@Test
public void coverage() throws Exception {
assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(3);
assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(1);
assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(6);
assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(2);
assertThat(getProjectMeasure("conditions_to_cover")).isNull();
assertThat(getProjectMeasure("uncovered_conditions")).isNull();
}

@Test
public void it_coverage() throws Exception {
assertThat(getProjectMeasure("it_lines_to_cover").getValue()).isEqualTo(3);
assertThat(getProjectMeasure("it_uncovered_lines").getValue()).isEqualTo(1);
assertThat(getProjectMeasure("it_lines_to_cover").getValue()).isEqualTo(6);
assertThat(getProjectMeasure("it_uncovered_lines").getValue()).isEqualTo(2);
}

@Test
public void overall_coverage() throws Exception {
assertThat(getProjectMeasure("overall_lines_to_cover").getValue()).isEqualTo(3);
assertThat(getProjectMeasure("overall_uncovered_lines").getValue()).isEqualTo(1);
assertThat(getProjectMeasure("overall_lines_to_cover").getValue()).isEqualTo(6);
assertThat(getProjectMeasure("overall_uncovered_lines").getValue()).isEqualTo(2);
}

private Measure getProjectMeasure(String metricKey) {
Expand Down
Expand Up @@ -21,13 +21,11 @@

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Test;

import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import java.util.regex.Pattern;
import org.junit.ClassRule;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

Expand All @@ -41,7 +39,7 @@ public class ReportWithUnresolvedPathTest {
@Test
public void should_log_a_warning() throws Exception {
orchestrator.resetData();
SonarRunner build = SonarRunner.create()
SonarScanner build = SonarScanner.create()
.setProjectDir(PROJECT_DIR)
.setProjectKey("project")
.setProjectName("project")
Expand Down
8 changes: 2 additions & 6 deletions its/plugin/tests/src/test/java/com/sonar/it/php/Tests.java
Expand Up @@ -19,18 +19,14 @@
*/
package com.sonar.it.php;

import com.google.common.collect.Iterables;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.locator.FileLocation;
import java.io.File;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;

@RunWith(Suite.class)
@Suite.SuiteClasses({
PHPTest.class,
Expand All @@ -43,7 +39,7 @@
public class Tests {

public static final String PROJECT_ROOT_DIR = "../projects/";
private static final String PLUGIN_KEY = "php";

private static final String RESOURCE_DIRECTORY = "/com/sonar/it/php/";

@ClassRule
Expand Down
16 changes: 6 additions & 10 deletions its/ruling/src/test/java/org/sonar/php/it/PHPRulingTest.java
Expand Up @@ -19,18 +19,14 @@
*/
package org.sonar.php.it;

import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.locator.FileLocation;
import org.junit.ClassRule;
import org.junit.Test;

import java.io.File;
import java.io.FilenameFilter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.junit.ClassRule;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
Expand All @@ -54,7 +50,7 @@ public void test() throws Exception {
ORCHESTRATOR.getConfiguration().getSonarVersion().isGreaterThanOrEquals("5.1"));
ORCHESTRATOR.getServer().provisionProject("project", "project");
ORCHESTRATOR.getServer().associateProjectToQualityProfile("project", "php", "rules");
SonarRunner build = SonarRunner.create(FileLocation.of("../sources/src").getFile())
SonarScanner build = SonarScanner.create(FileLocation.of("../sources/src").getFile())
.setProjectKey("project")
.setProjectName("project")
.setProjectVersion("1")
Expand All @@ -65,8 +61,8 @@ public void test() throws Exception {
.setProperty("dump.old", FileLocation.of("src/test/resources/expected").getFile().getAbsolutePath())
.setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath())
.setProperty("sonar.cpd.skip", "true")
.setProperty("lits.differences", LITS_DIFFERENCES_FILE.getAbsolutePath())
.setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx1000m");
.setProperty("lits.differences", LITS_DIFFERENCES_FILE.getAbsolutePath());
build.setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx1000m");
ORCHESTRATOR.executeBuild(build);

assertThat(Files.toString(LITS_DIFFERENCES_FILE, StandardCharsets.UTF_8)).isEmpty();
Expand Down

0 comments on commit 802650d

Please sign in to comment.