aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfork.sh24
-rw-r--r--plugins/sonar-core-plugin/pom.xml7
-rw-r--r--plugins/sonar-cpd-plugin/pom.xml14
-rw-r--r--plugins/sonar-dbcleaner-plugin/pom.xml8
-rw-r--r--plugins/sonar-l10n-en-plugin/pom.xml7
-rw-r--r--pom.xml58
-rw-r--r--server/sonar-process-monitor/pom.xml12
-rw-r--r--server/sonar-process/pom.xml8
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java2
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java2
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java2
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java4
-rw-r--r--server/sonar-search/pom.xml12
-rw-r--r--server/sonar-server/pom.xml7
-rw-r--r--server/sonar-web/pom.xml3
-rw-r--r--server/sonar-ws-client/pom.xml7
-rw-r--r--sonar-application/pom.xml7
-rw-r--r--sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java2
-rw-r--r--sonar-batch-protocol/pom.xml12
-rw-r--r--sonar-batch/pom.xml19
-rw-r--r--sonar-check-api/pom.xml12
-rw-r--r--sonar-duplications/pom.xml12
-rw-r--r--sonar-graph/pom.xml12
-rw-r--r--sonar-java-api/pom.xml12
-rw-r--r--sonar-markdown/pom.xml11
-rw-r--r--sonar-maven-plugin/pom.xml12
-rw-r--r--sonar-testing-harness/pom.xml27
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/api/server/ws/package-info.java22
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java29
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatcher.java57
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatchers.java40
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java46
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/channel/package-info.java24
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java15
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java44
35 files changed, 341 insertions, 251 deletions
diff --git a/fork.sh b/fork.sh
deleted file mode 100755
index 47e751c592b..00000000000
--- a/fork.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-mvn clean install -DskipTests -pl :sonar-server,:sonar-search,:sonar-process -amd
-
-if [[ "$OSTYPE" == "darwin"* ]]; then
- OS='macosx-universal-64'
-else
- OS='linux-x86-64'
-fi
-
-cd sonar-application/target/
-if ! ls sonarqube-*/bin/$OS/sonar.sh &> /dev/null; then
- unzip sonarqube-*.zip
-fi
-
-cd sonarqube-*
-touch logs/application.log
-touch logs/search.log
-touch logs/sonar.log
-
-tmux new-session "tmux split-window -v 'tail -f logs/sonar.log'; tmux split-window -h 'tail -f logs/search.log'; java -jar lib/sonar-application*.jar -Dsonar.node.name=forky"
-#tmux new-session "tmux split-window -h 'tail -f logs/search.log'; java -jar lib/sonar-application*.jar"
-
-#tmux new-session "tmux split-window -v 'tail -f logs/sonar.log'; tmux split-window -h 'tail -f logs/search.log'; tail -f logs/application.log"
diff --git a/plugins/sonar-core-plugin/pom.xml b/plugins/sonar-core-plugin/pom.xml
index d7a5edda624..d2b40030663 100644
--- a/plugins/sonar-core-plugin/pom.xml
+++ b/plugins/sonar-core-plugin/pom.xml
@@ -89,6 +89,13 @@
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/plugins/sonar-cpd-plugin/pom.xml b/plugins/sonar-cpd-plugin/pom.xml
index 6755e7ccd4f..468405d744f 100644
--- a/plugins/sonar-cpd-plugin/pom.xml
+++ b/plugins/sonar-cpd-plugin/pom.xml
@@ -59,6 +59,13 @@
<artifactId>sonar-xoo-plugin</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
@@ -80,6 +87,13 @@
<pluginClass>org.sonar.plugins.cpd.CpdPlugin</pluginClass>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/plugins/sonar-dbcleaner-plugin/pom.xml b/plugins/sonar-dbcleaner-plugin/pom.xml
index fa2302a61ac..d4d5b3d5544 100644
--- a/plugins/sonar-dbcleaner-plugin/pom.xml
+++ b/plugins/sonar-dbcleaner-plugin/pom.xml
@@ -81,6 +81,14 @@
<pluginClass>org.sonar.plugins.dbcleaner.DbCleanerPlugin</pluginClass>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
</project>
diff --git a/plugins/sonar-l10n-en-plugin/pom.xml b/plugins/sonar-l10n-en-plugin/pom.xml
index 35bbff6ab1f..95b855352af 100644
--- a/plugins/sonar-l10n-en-plugin/pom.xml
+++ b/plugins/sonar-l10n-en-plugin/pom.xml
@@ -69,6 +69,13 @@
<pluginDescription><![CDATA[Language pack for English]]></pluginDescription>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/pom.xml b/pom.xml
index 5e8be1145e8..04ae3872fdb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar</groupId>
@@ -83,6 +84,10 @@
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
+ <skipBatchTests>false</skipBatchTests>
+ <skipServerTests>false</skipServerTests>
+ <skipWebTests>false</skipWebTests>
+
<!-- To configure animal-sniffer to check API compat -->
<animal-sniffer.signature.groupId>org.codehaus.mojo.signature</animal-sniffer.signature.groupId>
<animal-sniffer.signature.artifactId>java16</animal-sniffer.signature.artifactId>
@@ -1348,7 +1353,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
<pluginExecution>
@@ -1361,7 +1366,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
<pluginExecution>
@@ -1375,7 +1380,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
<pluginExecution>
@@ -1388,7 +1393,7 @@
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
</pluginExecutions>
@@ -1427,6 +1432,49 @@
</plugins>
</build>
</profile>
+
+
+ <!--
+ The following profiles optimize the build for each team, according to their
+ stack layers (batch, server and web teams)
+ -->
+ <profile>
+ <!-- disable all tests -->
+ <id>skipTests</id>
+ <activation>
+ <property>
+ <name>skipTests</name>
+ </property>
+ </activation>
+ <properties>
+ <skipWebTests>true</skipWebTests>
+ <skipBatchTests>true</skipBatchTests>
+ <skipServerTests>true</skipServerTests>
+ </properties>
+ </profile>
+ <profile>
+ <id>batch</id>
+ <properties>
+ <skipServerTests>true</skipServerTests>
+ <skipWebTests>true</skipWebTests>
+ </properties>
+ </profile>
+ <profile>
+ <id>server</id>
+ <properties>
+ <skipBatchTests>true</skipBatchTests>
+ <skipWebTests>true</skipWebTests>
+ </properties>
+ </profile>
+ <profile>
+ <id>web</id>
+ <properties>
+ <!-- the web team does not care about java tests -->
+ <skipBatchTests>true</skipBatchTests>
+ <skipServerTests>true</skipServerTests>
+ <skipTests>true</skipTests>
+ </properties>
+ </profile>
</profiles>
</project>
diff --git a/server/sonar-process-monitor/pom.xml b/server/sonar-process-monitor/pom.xml
index c169c7b0f29..af327fb1a60 100644
--- a/server/sonar-process-monitor/pom.xml
+++ b/server/sonar-process-monitor/pom.xml
@@ -82,4 +82,16 @@
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/server/sonar-process/pom.xml b/server/sonar-process/pom.xml
index 333cae57e6f..0e6a50a9f23 100644
--- a/server/sonar-process/pom.xml
+++ b/server/sonar-process/pom.xml
@@ -91,6 +91,14 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
</project>
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
index 4aa072a6eb3..cd92bbf4e7e 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
@@ -96,6 +96,6 @@ public class ConfigurationUtilsTest {
@Test
public void private_constructor() throws Exception {
- TestUtils.assertPrivateConstructor(ConfigurationUtils.class);
+ assertThat(TestUtils.hasOnlyPrivateConstructors(ConfigurationUtils.class)).isTrue();
}
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java b/server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
index b612e24342d..8ccafff1f66 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
@@ -52,6 +52,6 @@ public class LoopbackAddressTest {
@Test
public void private_constructor() throws Exception {
- TestUtils.assertPrivateConstructor(LoopbackAddress.class);
+ assertThat(TestUtils.hasOnlyPrivateConstructors(LoopbackAddress.class)).isTrue();
}
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
index 0462f76707a..052c67d94fe 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
@@ -42,6 +42,6 @@ public class NetworkUtilsTest {
@Test
public void private_constructor() throws Exception {
- TestUtils.assertPrivateConstructor(NetworkUtils.class);
+ assertThat(TestUtils.hasOnlyPrivateConstructors(NetworkUtils.class)).isTrue();
}
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
index ae1f53b2653..1a18d5983ae 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
@@ -22,10 +22,12 @@ package org.sonar.process;
import org.junit.Test;
import org.sonar.test.TestUtils;
+import static org.fest.assertions.Assertions.assertThat;
+
public class ProcessUtilsTest {
@Test
public void private_constructor() throws Exception {
- TestUtils.assertPrivateConstructor(ProcessUtils.class);
+ assertThat(TestUtils.hasOnlyPrivateConstructors(ProcessUtils.class)).isTrue();
}
}
diff --git a/server/sonar-search/pom.xml b/server/sonar-search/pom.xml
index b35a7502868..93551819322 100644
--- a/server/sonar-search/pom.xml
+++ b/server/sonar-search/pom.xml
@@ -67,4 +67,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml
index 09bc1cd3431..0313612ad69 100644
--- a/server/sonar-server/pom.xml
+++ b/server/sonar-server/pom.xml
@@ -267,6 +267,13 @@
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
</plugins>
</build>
diff --git a/server/sonar-web/pom.xml b/server/sonar-web/pom.xml
index 94de3994edf..0ba63fae775 100644
--- a/server/sonar-web/pom.xml
+++ b/server/sonar-web/pom.xml
@@ -173,7 +173,8 @@
<id>js-tests</id>
<activation>
<property>
- <name>!skipTests</name>
+ <name>skipWebTests</name>
+ <value>false</value>
</property>
</activation>
<build>
diff --git a/server/sonar-ws-client/pom.xml b/server/sonar-ws-client/pom.xml
index b31b7c407ff..05b51b7ae1f 100644
--- a/server/sonar-ws-client/pom.xml
+++ b/server/sonar-ws-client/pom.xml
@@ -172,6 +172,13 @@
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml
index c63b6cf0142..2245914d1cc 100644
--- a/sonar-application/pom.xml
+++ b/sonar-application/pom.xml
@@ -265,6 +265,13 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
</plugins>
</build>
<profiles>
diff --git a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
index 49a66bc590c..82969821f62 100644
--- a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
@@ -60,6 +60,6 @@ public class DefaultSettingsTest {
@Test
public void private_constructor() throws Exception {
- TestUtils.assertPrivateConstructor(DefaultSettings.class);
+ assertThat(TestUtils.hasOnlyPrivateConstructors(DefaultSettings.class)).isTrue();
}
}
diff --git a/sonar-batch-protocol/pom.xml b/sonar-batch-protocol/pom.xml
index 5337b6c424b..17d373e2956 100644
--- a/sonar-batch-protocol/pom.xml
+++ b/sonar-batch-protocol/pom.xml
@@ -38,4 +38,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml
index 6e184f70b00..36432454d76 100644
--- a/sonar-batch/pom.xml
+++ b/sonar-batch/pom.xml
@@ -104,6 +104,13 @@
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
@@ -155,4 +162,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-check-api/pom.xml b/sonar-check-api/pom.xml
index b4d3d132f84..41dc566df00 100644
--- a/sonar-check-api/pom.xml
+++ b/sonar-check-api/pom.xml
@@ -18,4 +18,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-duplications/pom.xml b/sonar-duplications/pom.xml
index df1ad8f043c..60df2ebcf22 100644
--- a/sonar-duplications/pom.xml
+++ b/sonar-duplications/pom.xml
@@ -79,4 +79,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-graph/pom.xml b/sonar-graph/pom.xml
index 904169a532e..79e70ee3d92 100644
--- a/sonar-graph/pom.xml
+++ b/sonar-graph/pom.xml
@@ -37,4 +37,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-java-api/pom.xml b/sonar-java-api/pom.xml
index cb1a4d26675..6c2dd964eba 100644
--- a/sonar-java-api/pom.xml
+++ b/sonar-java-api/pom.xml
@@ -25,4 +25,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-markdown/pom.xml b/sonar-markdown/pom.xml
index 53ba70a81da..a6045e5ca46 100644
--- a/sonar-markdown/pom.xml
+++ b/sonar-markdown/pom.xml
@@ -47,4 +47,15 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-maven-plugin/pom.xml b/sonar-maven-plugin/pom.xml
index 984ae7f960f..1a932ff36de 100644
--- a/sonar-maven-plugin/pom.xml
+++ b/sonar-maven-plugin/pom.xml
@@ -57,4 +57,16 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipBatchTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml
index bd91b11daed..e474953c6b0 100644
--- a/sonar-testing-harness/pom.xml
+++ b/sonar-testing-harness/pom.xml
@@ -20,10 +20,6 @@
<artifactId>jsonassert</artifactId>
</dependency>
<dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -32,21 +28,22 @@
<artifactId>hamcrest-all</artifactId>
</dependency>
<dependency>
- <!-- used only for org.sonar.test.channel classes -->
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-channel</artifactId>
- <optional>true</optional>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
</dependency>
<dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-plugin-api</artifactId>
- <version>${project.version}</version>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-plugin-api</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>
</project>
diff --git a/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/package-info.java b/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/package-info.java
deleted file mode 100644
index a216dca3631..00000000000
--- a/sonar-testing-harness/src/main/java/org/sonar/api/server/ws/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.api.server.ws;
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java
index 0a5d8fcaef0..c8522ec3ed8 100644
--- a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java
+++ b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java
@@ -27,9 +27,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.net.URL;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
/**
* Utilities for unit tests
*
@@ -73,14 +70,24 @@ public final class TestUtils {
return getResource(resourcePath);
}
- public static void assertPrivateConstructor(Class clazz) {
- try {
- Constructor constructor = clazz.getDeclaredConstructor();
- assertThat(Modifier.isPrivate(constructor.getModifiers())).isTrue();
- constructor.setAccessible(true);
- constructor.newInstance();
- } catch (Exception e) {
- fail("Fail to instantiate " + clazz, e);
+ /**
+ * Asserts that all constructors are private, usually for helper classes with
+ * only static methods. If a constructor does not have any parameters, then
+ * it's instantiated.
+ */
+ public static boolean hasOnlyPrivateConstructors(Class clazz) {
+ boolean ok = true;
+ for (Constructor constructor : clazz.getDeclaredConstructors()) {
+ ok &= Modifier.isPrivate(constructor.getModifiers());
+ if (constructor.getParameterTypes().length == 0) {
+ constructor.setAccessible(true);
+ try {
+ constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to instantiate %s", clazz), e);
+ }
+ }
}
+ return ok;
}
}
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatcher.java
deleted file mode 100644
index c262cbca65e..00000000000
--- a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatcher.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.test.channel;
-
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.sonar.channel.Channel;
-import org.sonar.channel.CodeReader;
-
-public class ChannelMatcher<O> extends BaseMatcher<Channel<O>> {
-
- private final String sourceCode;
- private final O output;
- private final CodeReader reader;
-
- public ChannelMatcher(String sourceCode, O output) {
- this.sourceCode = sourceCode;
- this.output = output;
- this.reader = new CodeReader(sourceCode);
- }
-
- public ChannelMatcher(CodeReader reader, O output) {
- this.output = output;
- this.sourceCode = new String(reader.peek(30));
- this.reader = reader;
- }
-
- public boolean matches(Object arg0) {
- if ( !(arg0 instanceof Channel)) {
- return false;
- }
- Channel<O> channel = (Channel<O>) arg0;
- return channel.consume(reader, output);
- }
-
- public void describeTo(Description description) {
- description.appendText("Channel consumes '" + sourceCode + "'");
- }
-
-}
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatchers.java b/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatchers.java
deleted file mode 100644
index b3bce24c591..00000000000
--- a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatchers.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.test.channel;
-
-import org.sonar.channel.CodeReader;
-
-public final class ChannelMatchers {
-
- private ChannelMatchers() {
- }
-
- public static <O> ChannelMatcher<O> consume(String sourceCode, O output) {
- return new ChannelMatcher<O>(sourceCode, output);
- }
-
- public static <O> ChannelMatcher<O> consume(CodeReader codeReader, O output) {
- return new ChannelMatcher<O>(codeReader, output);
- }
-
- public static ReaderHasNextCharMatcher hasNextChar(char nextChar) {
- return new ReaderHasNextCharMatcher(nextChar);
- }
-}
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java
deleted file mode 100644
index 477dc89a29b..00000000000
--- a/sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.test.channel;
-
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.sonar.channel.CodeReader;
-
-public class ReaderHasNextCharMatcher extends BaseMatcher<CodeReader> {
-
- private final char nextChar;
-
- public ReaderHasNextCharMatcher(char nextChar) {
- this.nextChar = nextChar;
- }
-
- public boolean matches(Object arg0) {
- if ( !(arg0 instanceof CodeReader)) {
- return false;
- }
- CodeReader reader = (CodeReader) arg0;
- return reader.peek() == nextChar;
- }
-
- public void describeTo(Description description) {
- description.appendText("next char is '" + nextChar + "'");
- }
-
-}
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/channel/package-info.java b/sonar-testing-harness/src/main/java/org/sonar/test/channel/package-info.java
deleted file mode 100644
index 482c6191040..00000000000
--- a/sonar-testing-harness/src/main/java/org/sonar/test/channel/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.test.channel;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java
index 3bc97ec8e44..360685bec9b 100644
--- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java
+++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.test.TestUtils;
import java.io.File;
+import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -49,7 +50,7 @@ public final class I18nMatchers {
* Checks that all the translation bundles found on the classpath are up to date with the corresponding default ones found in the classpath.
*/
public static void assertBundlesUpToDate() {
- File bundleFolder = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH);
+ File bundleFolder = getResource(BundleSynchronizedMatcher.L10N_PATH);
if (bundleFolder == null || !bundleFolder.isDirectory()) {
fail("No bundle found in: " + BundleSynchronizedMatcher.L10N_PATH);
}
@@ -77,4 +78,16 @@ public final class I18nMatchers {
fail(message.toString());
}
}
+
+ private static File getResource(String path) {
+ String resourcePath = path;
+ if (!resourcePath.startsWith("/")) {
+ resourcePath = "/" + resourcePath;
+ }
+ URL url = TestUtils.class.getResource(resourcePath);
+ if (url != null) {
+ return FileUtils.toFile(url);
+ }
+ return null;
+ }
}
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java
index 54a0d903357..f06d434441c 100644
--- a/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
import java.io.File;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.sonar.test.TestUtils.getResource;
public class TestUtilsTest {
@@ -45,4 +46,47 @@ public class TestUtilsTest {
File file = getResource("org/sonar/test/TestUtilsTest/unknown.txt");
assertThat(file).isNull();
}
+
+ @Test
+ public void hasOnlyPrivateConstructors() {
+ assertThat(TestUtils.hasOnlyPrivateConstructors(TestUtils.class)).isTrue();
+ assertThat(TestUtils.hasOnlyPrivateConstructors(OnlyPrivateConstructors.class)).isTrue();
+ assertThat(TestUtils.hasOnlyPrivateConstructors(MixOfPublicAndPrivateConstructors.class)).isFalse();
+ try {
+ TestUtils.hasOnlyPrivateConstructors(FailToInstantiate.class);
+ fail();
+ } catch (IllegalStateException e) {
+ // ok
+ }
+ }
+
+ public static class OnlyPrivateConstructors {
+ private OnlyPrivateConstructors() {
+ }
+
+ private OnlyPrivateConstructors(int i) {
+ }
+
+ public static void foo() {
+
+ }
+ }
+
+ public static class MixOfPublicAndPrivateConstructors {
+ private MixOfPublicAndPrivateConstructors() {
+ }
+
+ public MixOfPublicAndPrivateConstructors(int i) {
+ }
+
+ public static void foo() {
+
+ }
+ }
+
+ public static class FailToInstantiate {
+ private FailToInstantiate() {
+ throw new IllegalArgumentException();
+ }
+ }
}