Skip to content
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
50 changes: 0 additions & 50 deletions .cix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ TEST:

SQ_VERSION:
- LTS
- 5.2
- 5.3
- DEV
- LATEST_RELEASE

Expand All @@ -21,12 +19,6 @@ exclude:
- TEST: plugin
SLAVE: performance
SQ_VERSION: LTS
- TEST: plugin
SLAVE: performance
SQ_VERSION: 5.2
- TEST: plugin
SLAVE: performance
SQ_VERSION: 5.3
- TEST: plugin
SLAVE: performance
SQ_VERSION: DEV
Expand All @@ -37,25 +29,13 @@ exclude:
- TEST: plugin
SLAVE: windows
SQ_VERSION: LTS
- TEST: plugin
SLAVE: windows
SQ_VERSION: 5.2
- TEST: plugin
SLAVE: windows
SQ_VERSION: 5.3
- TEST: plugin
SLAVE: windows
SQ_VERSION: DEV
#exclude ruling tests on performance slaves
- TEST: ruling
SLAVE: performance
SQ_VERSION: LTS
- TEST: ruling
SLAVE: performance
SQ_VERSION: 5.2
- TEST: ruling
SLAVE: performance
SQ_VERSION: 5.3
- TEST: ruling
SLAVE: performance
SQ_VERSION: DEV
Expand All @@ -66,38 +46,20 @@ exclude:
- TEST: ruling
SLAVE: linux
SQ_VERSION: LTS
- TEST: ruling
SLAVE: linux
SQ_VERSION: 5.2
- TEST: ruling
SLAVE: linux
SQ_VERSION: 5.3
- TEST: ruling
SLAVE: linux
SQ_VERSION: DEV
#exclude all ruling jobs other than on LATEST_RELEASE on windows
- TEST: ruling
SLAVE: windows
SQ_VERSION: LTS
- TEST: ruling
SLAVE: windows
SQ_VERSION: 5.2
- TEST: ruling
SLAVE: windows
SQ_VERSION: 5.3
- TEST: ruling
SLAVE: windows
SQ_VERSION: DEV
#exclude all performances jobs on linux slaves
- TEST: performancing
SLAVE: linux
SQ_VERSION: LTS
- TEST: performancing
SLAVE: linux
SQ_VERSION: 5.2
- TEST: performancing
SLAVE: linux
SQ_VERSION: 5.3
- TEST: performancing
SLAVE: linux
SQ_VERSION: DEV
Expand All @@ -108,12 +70,6 @@ exclude:
- TEST: performancing
SLAVE: windows
SQ_VERSION: LTS
- TEST: performancing
SLAVE: windows
SQ_VERSION: 5.2
- TEST: performancing
SLAVE: windows
SQ_VERSION: 5.3
- TEST: performancing
SLAVE: windows
SQ_VERSION: DEV
Expand All @@ -124,12 +80,6 @@ exclude:
- TEST: performancing
SLAVE: performance
SQ_VERSION: LTS
- TEST: performancing
SLAVE: performance
SQ_VERSION: 5.2
- TEST: performancing
SLAVE: performance
SQ_VERSION: 5.3
- TEST: performancing
SLAVE: performance
SQ_VERSION: DEV
7 changes: 6 additions & 1 deletion its/plugin/plugins/java-extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.version}</version>
<scope>provided</scope>
Expand All @@ -33,6 +33,11 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion its/plugin/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.version}</version>
<scope>test</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ public void should_support_the_old_binaries_and_libraries_properties() {
SonarRunner runner = ditProjectSonarRunner();
runner.setProperty("sonar.binaries", "target/classes");
runner.setProperty("sonar.libraries", guavaJarPath);
String logs = ORCHESTRATOR.executeBuild(runner).getLogs();
BuildResult buildResult = ORCHESTRATOR.executeBuildQuietly(runner);

assertThat(logs).contains("sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin," +
assertThat(buildResult.getLogs()).contains("sonar.binaries and sonar.libraries are not supported since version 4.0 of sonar-java-plugin," +
" please use sonar.java.binaries and sonar.java.libraries instead");
assertThat(getNumberOfViolations()).isEqualTo(2);
assertThat(buildResult.isSuccess()).isFalse();
}

@Test
public void should_not_log_warnings_if_properties_not_set() {
SonarRunner runner = ditProjectSonarRunner();
String logs = ORCHESTRATOR.executeBuild(runner).getLogs();

assertThat(logs).doesNotContain("sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin," +
assertThat(logs).doesNotContain("sonar.binaries and sonar.libraries are not supported since version 4.0 of sonar-java-plugin," +
" please use sonar.java.binaries and sonar.java.libraries instead");
assertThat(getNumberOfViolations()).isEqualTo(0);
}
Expand All @@ -144,11 +144,7 @@ public void no_source_files_should_not_validate_binaries_for_backward_compatibil
.setProperty("sonar.profile", "dit-check")
.setProperty("sonar.dynamicAnalysis", "false");
int status = ORCHESTRATOR.executeBuildQuietly(build).getStatus();
if (JavaTestSuite.sonarqube_version_is_prior_to_5_0()) {
assertThat(status).isEqualTo(0);
} else {
assertThat(status).isGreaterThan(0);
}
assertThat(status).isGreaterThan(0);
}

private static void buildDitProject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
import com.sonar.orchestrator.locator.MavenLocation;
import com.sonar.orchestrator.locator.MavenLocator;
import com.sonar.orchestrator.version.Version;

import org.fest.assertions.Condition;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueClient;
import org.sonar.wsclient.issue.IssueQuery;
Expand All @@ -46,7 +44,6 @@
import java.util.List;

import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;

public class JavaTest {

Expand Down Expand Up @@ -142,27 +139,6 @@ public void multiple_package_in_directory_should_not_fail() throws Exception {

}

/**
* SONAR-3228
*/
@Test
public void shouldPersistMetricsEvenIfZero() {
assumeTrue(JavaTestSuite.sonarqube_version_is_prior_to_5_2());
MavenBuild build = MavenBuild.create()
.setPom(TestUtils.projectPom("zero-value-metric-project"))
.setCleanPackageSonarGoals();
orchestrator.executeBuild(build);

Sonar wsClient = orchestrator.getServer().getWsClient();

Resource project = wsClient.find(ResourceQuery.createForMetrics("com.sonarsource.it.projects:zero-value-metric-project",
"package_cycles", "package_feedback_edges", "package_tangles"));

assertThat(project.getMeasureIntValue("package_cycles")).isEqualTo(0);
assertThat(project.getMeasureIntValue("package_feedback_edges")).isEqualTo(0);
assertThat(project.getMeasureIntValue("package_tangles")).isEqualTo(0);
}

/**
* SONARJAVA-19
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ public class JavaTestSuite {
ORCHESTRATOR = orchestratorBuilder.build();
}

public static boolean sonarqube_version_is_prior_to_5_0() {
return !ORCHESTRATOR.getServer().version().isGreaterThanOrEquals("5.0");
}
public static boolean sonarqube_version_is_prior_to_5_2() {
return !ORCHESTRATOR.getServer().version().isGreaterThanOrEquals("5.2");
}

public static String keyFor(String projectKey, String pkgDir, String cls) {
return projectKey + ":src/main/java/" + pkgDir + cls;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.Date;

import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;

public class Struts139Test {

Expand Down Expand Up @@ -235,22 +234,6 @@ public void shouldNotPersistComplexityDistributionsOnFiles() {
assertThat(orchestrator.getServer().getWsClient().find(query).getMeasures().size()).isEqualTo(0);
}

@Test
public void designMeasures() {
assumeTrue(JavaTestSuite.sonarqube_version_is_prior_to_5_2());
setCurrentProjectWithAccessors();
assertThat(getCoreModuleMeasure("package_cycles").getIntValue()).isGreaterThan(10);
assertThat(getCoreModuleMeasure("package_cycles").getIntValue()).isLessThan(50);

assertThat(getCoreModuleMeasure("package_feedback_edges").getIntValue()).isGreaterThan(3);
assertThat(getCoreModuleMeasure("package_feedback_edges").getIntValue()).isLessThan(10);

assertThat(getCoreModuleMeasure("package_tangles").getIntValue()).isGreaterThan(10);
assertThat(getCoreModuleMeasure("package_tangles").getIntValue()).isLessThan(50);

assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(PROJECT_STRUTS, "dit", "noc")).getMeasures().size()).isEqualTo(0);
}

@Test
public void shouldGetDetailsOfCoverageHits() {
setCurrentProjectWithAccessors();
Expand Down
13 changes: 12 additions & 1 deletion its/ruling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-ws-client</artifactId>
<version>${sonar.version}</version>
<version>4.5.7</version>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should rely on same version of sonar as the plugin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.sonarsource.orchestrator</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.wsclient.SonarClient;

import javax.annotation.Nullable;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless file modification.

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class JavaRulingTest {

private static final Logger LOG = LoggerFactory.getLogger(JavaRulingTest.class);
Expand Down
5 changes: 5 additions & 0 deletions java-checks-testkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>fest-assert</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
5 changes: 4 additions & 1 deletion java-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-testing-harness</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
package org.sonar.java.checks;

import com.google.common.collect.ImmutableList;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.ClassTree;
import org.sonar.plugins.java.api.tree.MethodTree;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.VariableTree;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Rule(key = "S3306")
public class ConstructorInjectionCheck extends IssuableSubscriptionVisitor {
Expand All @@ -46,18 +44,14 @@ public void visitNode(Tree tree) {
return;
}
List<Tree> members = ((ClassTree) tree).members();
List<MethodTree> constructors = filterByKind(members, Tree.Kind.CONSTRUCTOR);
for (MethodTree constructor : constructors) {
if (isPrivateConstructor(constructor)) {
return;
}
}
List<VariableTree> fields = filterByKind(members, Tree.Kind.VARIABLE);
for (VariableTree field : fields) {
if (isAnnotatedWithInject(field)) {
reportIssue(field.simpleName(), "Use constructor injection for this field.");
}
Optional<Tree> first = members.stream().filter(t -> t.is(Tree.Kind.CONSTRUCTOR) && isPrivateConstructor((MethodTree) t)).findFirst();
if(first.isPresent()) {
return;
}
members.stream()
.filter(t -> t.is(Tree.Kind.VARIABLE) && isAnnotatedWithInject((VariableTree) t))
.forEach(field -> reportIssue(((VariableTree) field).simpleName(), "Use constructor injection for this field.")
);
}

private static boolean isPrivateConstructor(MethodTree constructor) {
Expand All @@ -68,16 +62,4 @@ private static boolean isAnnotatedWithInject(VariableTree field) {
return field.symbol().metadata().isAnnotatedWith("javax.inject.Inject");
}

@SuppressWarnings("unchecked")
private static <X extends Tree> List<X> filterByKind(List<? extends Tree> list, final Tree.Kind kind) {
List<Tree> filteredList = new ArrayList<>(list);
CollectionUtils.filter(filteredList, new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((Tree) object).is(kind);
}
});
return (List<X>) filteredList;
}

}
Loading