]> source.dussan.org Git - sonarqube.git/commitdiff
Maven profiles for each technical stack
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 29 Sep 2014 22:07:03 +0000 (00:07 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 29 Sep 2014 22:07:03 +0000 (00:07 +0200)
and remove sonar-channel helpers from sonar-testing-harness

35 files changed:
fork.sh [deleted file]
plugins/sonar-core-plugin/pom.xml
plugins/sonar-cpd-plugin/pom.xml
plugins/sonar-dbcleaner-plugin/pom.xml
plugins/sonar-l10n-en-plugin/pom.xml
pom.xml
server/sonar-process-monitor/pom.xml
server/sonar-process/pom.xml
server/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
server/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
server/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
server/sonar-search/pom.xml
server/sonar-server/pom.xml
server/sonar-web/pom.xml
server/sonar-ws-client/pom.xml
sonar-application/pom.xml
sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
sonar-batch-protocol/pom.xml
sonar-batch/pom.xml
sonar-check-api/pom.xml
sonar-duplications/pom.xml
sonar-graph/pom.xml
sonar-java-api/pom.xml
sonar-markdown/pom.xml
sonar-maven-plugin/pom.xml
sonar-testing-harness/pom.xml
sonar-testing-harness/src/main/java/org/sonar/api/server/ws/package-info.java [deleted file]
sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java
sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatcher.java [deleted file]
sonar-testing-harness/src/main/java/org/sonar/test/channel/ChannelMatchers.java [deleted file]
sonar-testing-harness/src/main/java/org/sonar/test/channel/ReaderHasNextCharMatcher.java [deleted file]
sonar-testing-harness/src/main/java/org/sonar/test/channel/package-info.java [deleted file]
sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java
sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java

diff --git a/fork.sh b/fork.sh
deleted file mode 100755 (executable)
index 47e751c..0000000
--- 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"
index d7a5edda624a20dad960bbf3ef7ab1a38c923c53..d2b4003066327a9929872a41930d2a438341bd5a 100644 (file)
       <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>
index 6755e7ccd4fe5baf2670bd30a718761e25897896..468405d744f967b8513c36b56487537e15e3e228 100644 (file)
       <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>
           <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>
index fa2302a61acffd3bd13aed43ab64d48025c1f8d9..d4d5b3d5544cde9594b3c4cd884c35d6febfd3ea 100644 (file)
           <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>
index 35bbff6ab1f6c9ebd859598771475c56de9e41fa..95b855352afe728ecfca3581f18b1a28e1d0a849 100644 (file)
           <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 5e8be1145e88dda06fd68dd09456203c41d75e54..04ae3872fdb44731716516c920a63a5cd7073da1 100644 (file)
--- 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>
     <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>
                         </goals>
                       </pluginExecutionFilter>
                       <action>
-                        <ignore />
+                        <ignore/>
                       </action>
                     </pluginExecution>
                     <pluginExecution>
                         </goals>
                       </pluginExecutionFilter>
                       <action>
-                        <ignore />
+                        <ignore/>
                       </action>
                     </pluginExecution>
                     <pluginExecution>
                         </goals>
                       </pluginExecutionFilter>
                       <action>
-                        <ignore />
+                        <ignore/>
                       </action>
                     </pluginExecution>
                     <pluginExecution>
                         </goals>
                       </pluginExecutionFilter>
                       <action>
-                        <ignore />
+                        <ignore/>
                       </action>
                     </pluginExecution>
                   </pluginExecutions>
         </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>
index c169c7b0f2942f81c6149f970612415b64c6aa68..af327fb1a60c39cd4242b47ff1910b10df671cc6 100644 (file)
     </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>
index 333cae57e6f1417f70716343dec5622b0fff0ade..0e6a50a9f239d5b8385b222767f26aaab8f2d061 100644 (file)
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>${skipServerTests}</skipTests>
+        </configuration>
+      </plugin>
+
     </plugins>
   </build>
 </project>
index 4aa072a6eb38bdd7a2435c13fb3ea36a0ba114cf..cd92bbf4e7eaeffae82144193d1af089eeb7889a 100644 (file)
@@ -96,6 +96,6 @@ public class ConfigurationUtilsTest {
 
   @Test
   public void private_constructor() throws Exception {
-    TestUtils.assertPrivateConstructor(ConfigurationUtils.class);
+    assertThat(TestUtils.hasOnlyPrivateConstructors(ConfigurationUtils.class)).isTrue();
   }
 }
index b612e24342db49dc3c25501fa948e1694a8bf991..8ccafff1f66460f89d0ada68ae0cfbb974987f80 100644 (file)
@@ -52,6 +52,6 @@ public class LoopbackAddressTest {
 
   @Test
   public void private_constructor() throws Exception {
-    TestUtils.assertPrivateConstructor(LoopbackAddress.class);
+    assertThat(TestUtils.hasOnlyPrivateConstructors(LoopbackAddress.class)).isTrue();
   }
 }
index 0462f76707acda0a5c72f02a780926fc14e2b517..052c67d94feeb2d4905998919a3c0d30f97901e5 100644 (file)
@@ -42,6 +42,6 @@ public class NetworkUtilsTest {
 
   @Test
   public void private_constructor() throws Exception {
-    TestUtils.assertPrivateConstructor(NetworkUtils.class);
+    assertThat(TestUtils.hasOnlyPrivateConstructors(NetworkUtils.class)).isTrue();
   }
 }
index ae1f53b2653b30a1bc6e462a12e107af0beb89a8..1a18d5983ae18571e3637aaf98ee852079510b5b 100644 (file)
@@ -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();
   }
 }
index b35a75028684649503ad5e9549e3b4b3f70fbb0c..93551819322a71f85d0e9f209d4faeb4b8a5f666 100644 (file)
       <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>
index 09bc1cd3431717ad52105340ab61b5dde361010b..0313612ad69096a6fa94f0d596b26bd001ab20bf 100644 (file)
           </archive>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>${skipServerTests}</skipTests>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index 94de3994edf156e9ddf18f3838fc8097e716ec69..0ba63fae7758a686b21bb9518e477a1f1f3048ec 100644 (file)
       <id>js-tests</id>
       <activation>
         <property>
-          <name>!skipTests</name>
+          <name>skipWebTests</name>
+          <value>false</value>
         </property>
       </activation>
       <build>
index b31b7c407ff5ae9f16bf1a6085e66874dc5902cf..05b51b7ae1fb53c987ff655a1b55dadd5041d990 100644 (file)
           </archive>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>${skipServerTests}</skipTests>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 </project>
index c63b6cf014243d9a96341b81ae8846a009d31d8b..2245914d1cce5c475fe5f582ec0c3e1f1ccb5554 100644 (file)
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>${skipServerTests}</skipTests>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
   <profiles>
index 49a66bc590cf560de16a740753d54251874b5955..82969821f62324a921accb55395be6ac1a199b9b 100644 (file)
@@ -60,6 +60,6 @@ public class DefaultSettingsTest {
 
   @Test
   public void private_constructor() throws Exception {
-    TestUtils.assertPrivateConstructor(DefaultSettings.class);
+    assertThat(TestUtils.hasOnlyPrivateConstructors(DefaultSettings.class)).isTrue();
   }
 }
index 5337b6c424be2da8f524e77e8bc18415943be198..17d373e2956b0b525e64dbf118ce8623b2917ee0 100644 (file)
       <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>
index 6e184f70b0092c378c542d83ab89dab7c154b9b7..36432454d768f880cc63cddc8cee91175387af65 100644 (file)
     </dependency>
 
     <!-- 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>
       <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>
index b4d3d132f842f3e0dbc6c12cca00abefcdeb7563..41dc566df00979bb15b843c591d94a697e0f555f 100644 (file)
       <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>
index df1ad8f043c4c6b5fdbbf482bc372c40b2306c4e..60df2ebcf22891860d25d56b8329dc4057ccce0c 100644 (file)
       <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>
index 904169a532e96a8e8fe4a2917003b7a4a560e35d..79e70ee3d923bdfdeb9082e58c280d23375c6caf 100644 (file)
       <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>
index cb1a4d26675818d3c8854cdac35b7e5148383748..6c2dd964eba20372ba412faba17c0f704d80127d 100644 (file)
       <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>
index 53ba70a81da9389bf1a1be8c835941e24733fe28..a6045e5ca460bf95cf7bde46a7a9aab2bc875b12 100644 (file)
     </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>
index 984ae7f960fdb6b026411bdc42c7a93deb78bd2c..1a932ff36de7a28de4b332629c5a0c8358595609 100644 (file)
       <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>
index bd91b11daed9b7f0af2d9b407b1b5f5f5a0c8b9b..e474953c6b0cbdde0f64a4dc000f7373d47dfa31 100644 (file)
       <groupId>org.skyscreamer</groupId>
       <artifactId>jsonassert</artifactId>
     </dependency>
-    <dependency>
-      <groupId>com.google.code.findbugs</groupId>
-      <artifactId>jsr305</artifactId>
-    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <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 (file)
index a216dca..0000000
+++ /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;
index 0a5d8fcaef013e19163ef66deffb063d637b6677..c8522ec3ed871034a6206e80b42af294f3d4c14d 100644 (file)
@@ -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 (file)
index c262cbc..0000000
+++ /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 (file)
index b3bce24..0000000
+++ /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 (file)
index 477dc89..0000000
+++ /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 (file)
index 482c619..0000000
+++ /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;
index 3bc97ec8e44f494612122574beb6887bb629914c..360685bec9ba57b17b67b57d72bcaba7cdb8705a 100644 (file)
@@ -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;
+  }
 }
index 54a0d903357f1f99cc3b18c4c9bafb989aba5cdd..f06d434441c4cb355abba42d3e686c8558531935 100644 (file)
@@ -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();
+    }
+  }
 }