aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 10:30:48 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 10:30:48 +0200
commitbda94bc8f7e26da995a56418cbe55f422b1396b3 (patch)
tree180770628d2610d2f1bd143e03be6e7564ecdc1a
parent1fd2e682bfe5b6732e9097d0d3e57495da9e058c (diff)
downloadsonarqube-bda94bc8f7e26da995a56418cbe55f422b1396b3.tar.gz
sonarqube-bda94bc8f7e26da995a56418cbe55f422b1396b3.zip
SONAR-4898 delete directory server/process
-rw-r--r--server/process/pom.xml19
-rw-r--r--server/process/sonar-dummy-app/pom.xml98
-rw-r--r--server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java83
-rw-r--r--server/process/sonar-dummy-app/src/main/resources/org/sonar/application/logback.xml24
-rw-r--r--server/process/sonar-process/pom.xml85
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/AesCipher.java133
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java35
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Cipher.java27
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java70
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Encryption.java64
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java80
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java71
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/MessageException.java36
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java86
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java149
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java169
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java41
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java53
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java27
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/ProcessUtils.java92
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java375
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Props.java120
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/Terminable.java30
-rw-r--r--server/process/sonar-process/src/main/java/org/sonar/process/package-info.java23
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/AesCipherTest.java185
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessTest.java59
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessWrapperTest.java118
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java95
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java84
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java59
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java125
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java51
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java102
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/MonitorTestBase.java78
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java185
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java61
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java32
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process/PropsTest.java137
-rw-r--r--server/process/sonar-process/src/test/java/org/sonar/process2/MonitorTest.java23
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/aes_secret_key.txt1
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/bad_secret_key.txt1
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/non_trimmed_secret_key.txt3
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/other_secret_key.txt1
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/LoggingTest/logback-access.xml1
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/ProcessTest/sonar.properties212
-rw-r--r--server/process/sonar-process/src/test/resources/org/sonar/process/PropsTest/sonar.properties3
-rw-r--r--server/process/sonar-process/src/test/resources/sonar-dummy-app.jarbin854048 -> 0 bytes
47 files changed, 0 insertions, 3606 deletions
diff --git a/server/process/pom.xml b/server/process/pom.xml
deleted file mode 100644
index 5bd42b26e46..00000000000
--- a/server/process/pom.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?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/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>server</artifactId>
- <version>4.5-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>process</artifactId>
- <packaging>pom</packaging>
- <name>SonarQube :: Process :: Parent</name>
-
- <modules>
- <module>sonar-dummy-app</module>
- <module>sonar-process</module>
- </modules>
-</project>
diff --git a/server/process/sonar-dummy-app/pom.xml b/server/process/sonar-dummy-app/pom.xml
deleted file mode 100644
index 606087bf511..00000000000
--- a/server/process/sonar-dummy-app/pom.xml
+++ /dev/null
@@ -1,98 +0,0 @@
-<?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/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>process</artifactId>
- <version>4.5-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>sonar-dummy-app</artifactId>
- <packaging>jar</packaging>
- <name>SonarQube :: Process :: DummyApp</name>
- <description>Dummy Application to test sonar-process</description>
-
- <dependencies>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-process</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <scope>provided</scope>
- </dependency>
-
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>runtime</scope>
- </dependency>
-
- <!-- testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easytesting</groupId>
- <artifactId>fest-assert</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>false</addClasspath>
- <mainClass>org.sonar.application.DummyOkProcess</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>2.3</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
- <minimizeJar>true</minimizeJar>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <properties>
- <sonar.exclusions>**/*.java</sonar.exclusions>
- </properties>
-</project>
diff --git a/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java b/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java
deleted file mode 100644
index b25dfccc236..00000000000
--- a/server/process/sonar-dummy-app/src/main/java/org/sonar/application/DummyOkProcess.java
+++ /dev/null
@@ -1,83 +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.application;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.process.MonitoredProcess;
-import org.sonar.process.Props;
-
-import java.io.File;
-import java.util.Properties;
-
-public class DummyOkProcess extends MonitoredProcess {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(DummyOkProcess.class);
-
- private boolean isReady = false;
- private boolean isRunning = true;
- private boolean isSuccess = true;
-
- protected DummyOkProcess(Props props) {
- super(props);
- try {
- File.createTempFile("hello", ".tmp");
- } catch (Exception e) {
- LOGGER.error("Could not create file", e);
- isSuccess = false;
- }
- }
-
- @Override
- protected void doStart() {
- isReady = true;
- LOGGER.info("Starting Dummy OK Process");
- while (isRunning) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- isRunning = false;
- }
- }
- }
-
- @Override
- protected void doTerminate() {
- LOGGER.info("Terminating Dummy OK Process");
- this.isRunning = false;
- }
-
- @Override
- protected boolean doIsReady() {
- return isReady;
- }
-
- private boolean isSuccess() {
- return isSuccess;
- }
-
- public static int main(String[] args) {
- Props props = new Props(new Properties());
- props.set(MonitoredProcess.NAME_PROPERTY, DummyOkProcess.class.getSimpleName());
- DummyOkProcess process = new DummyOkProcess(props);
- process.start();
- return (process.isSuccess()) ? 1 : 0;
- }
-}
diff --git a/server/process/sonar-dummy-app/src/main/resources/org/sonar/application/logback.xml b/server/process/sonar-dummy-app/src/main/resources/org/sonar/application/logback.xml
deleted file mode 100644
index 933930557b9..00000000000
--- a/server/process/sonar-dummy-app/src/main/resources/org/sonar/application/logback.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<!--
- Configuration for default logger. Only used while embedded server is starting,
- before proper logging configuration is loaded.
-
- See http://logback.qos.ch/manual/configuration.html
--->
-<configuration debug="false">
- <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
-
- <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <pattern>
- %d{yyyy.MM.dd HH:mm:ss} %-5level %msg%n
- </pattern>
- </encoder>
- </appender>
-
- <root>
- <level value="DEBUG"/>
- <appender-ref ref="CONSOLE"/>
- </root>
-</configuration>
diff --git a/server/process/sonar-process/pom.xml b/server/process/sonar-process/pom.xml
deleted file mode 100644
index 48e39182b18..00000000000
--- a/server/process/sonar-process/pom.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?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/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>process</artifactId>
- <version>4.5-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>sonar-process</artifactId>
- <packaging>jar</packaging>
- <name>SonarQube :: Process</name>
-
- <dependencies>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
-
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easytesting</groupId>
- <artifactId>fest-assert</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/AesCipher.java b/server/process/sonar-process/src/main/java/org/sonar/process/AesCipher.java
deleted file mode 100644
index 204ae1a6b6b..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/AesCipher.java
+++ /dev/null
@@ -1,133 +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.process;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-
-import javax.annotation.Nullable;
-import javax.crypto.KeyGenerator;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-import java.io.File;
-import java.io.IOException;
-import java.security.Key;
-import java.security.SecureRandom;
-
-final class AesCipher implements Cipher {
-
- // Can't be increased because of Java 6 policy files :
- // https://confluence.terena.org/display/~visser/No+256+bit+ciphers+for+Java+apps
- // http://java.sun.com/javase/6/webnotes/install/jre/README
- public static final int KEY_SIZE_IN_BITS = 128;
-
- private static final String CRYPTO_KEY = "AES";
-
- /**
- * Duplication from CoreProperties.ENCRYPTION_SECRET_KEY_PATH
- */
- static final String ENCRYPTION_SECRET_KEY_PATH = "sonar.secretKeyPath";
-
- private String pathToSecretKey;
-
- AesCipher(@Nullable String pathToSecretKey) {
- this.pathToSecretKey = pathToSecretKey;
- }
-
- @Override
- public String encrypt(String clearText) {
- try {
- javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
- cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile());
- return new String(Base64.encodeBase64(cipher.doFinal(clearText.getBytes("UTF-8"))));
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public String decrypt(String encryptedText) {
- try {
- javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
- cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile());
- byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText)));
- return new String(cipherData);
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- /**
- * This method checks the existence of the file, but not the validity of the contained key.
- */
- boolean hasSecretKey() {
- String path = getPathToSecretKey();
- if (StringUtils.isNotBlank(path)) {
- File file = new File(path);
- return file.exists() && file.isFile();
- }
- return false;
- }
-
- private Key loadSecretFile() throws IOException {
- String path = getPathToSecretKey();
- return loadSecretFileFromFile(path);
- }
-
- Key loadSecretFileFromFile(String path) throws IOException {
- if (StringUtils.isBlank(path)) {
- throw new IllegalStateException("Secret key not found. Please set the property " + ENCRYPTION_SECRET_KEY_PATH);
- }
- File file = new File(path);
- if (!file.exists() || !file.isFile()) {
- throw new IllegalStateException("The property " + ENCRYPTION_SECRET_KEY_PATH + " does not link to a valid file: " + path);
- }
- String s = FileUtils.readFileToString(file);
- if (StringUtils.isBlank(s)) {
- throw new IllegalStateException("No secret key in the file: " + path);
- }
- return new SecretKeySpec(Base64.decodeBase64(StringUtils.trim(s)), CRYPTO_KEY);
- }
-
- String generateRandomSecretKey() {
- try {
- KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_KEY);
- keyGen.init(KEY_SIZE_IN_BITS, new SecureRandom());
- SecretKey secretKey = keyGen.generateKey();
- return new String(Base64.encodeBase64(secretKey.getEncoded()));
-
- } catch (Exception e) {
- throw new IllegalStateException("Fail to generate secret key", e);
- }
- }
-
- String getPathToSecretKey() {
- if (StringUtils.isBlank(pathToSecretKey)) {
- pathToSecretKey = new File(FileUtils.getUserDirectoryPath(), ".sonar/sonar-secret.txt").getPath();
- }
- return pathToSecretKey;
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java b/server/process/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
deleted file mode 100644
index 5eb3eecd541..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
+++ /dev/null
@@ -1,35 +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.process;
-
-import org.apache.commons.codec.binary.Base64;
-
-final class Base64Cipher implements Cipher {
- @Override
- public String encrypt(String clearText) {
- return new String(Base64.encodeBase64(clearText.getBytes()));
- }
-
- @Override
- public String decrypt(String encryptedText) {
- return new String(Base64.decodeBase64(encryptedText));
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Cipher.java b/server/process/sonar-process/src/main/java/org/sonar/process/Cipher.java
deleted file mode 100644
index 4c437057757..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Cipher.java
+++ /dev/null
@@ -1,27 +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.process;
-
-interface Cipher {
- String encrypt(String clearText);
-
- String decrypt(String encryptedText);
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java b/server/process/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
deleted file mode 100644
index 355b6f885a2..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java
+++ /dev/null
@@ -1,70 +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.process;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.text.StrSubstitutor;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Properties;
-
-public final class ConfigurationUtils {
-
- private ConfigurationUtils() {
- // Utility class
- }
-
- public static Properties interpolateVariables(Properties properties, Map<String, String> variables) {
- Properties result = new Properties();
- Enumeration keys = properties.keys();
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- String value = (String) properties.get(key);
- String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}");
- result.setProperty(key, interpolatedValue);
- }
- return result;
- }
-
- public static Props loadPropsFromCommandLineArgs(String[] args) {
- if (args.length != 1) {
- throw new IllegalArgumentException("Only a single command-line argument is accepted " +
- "(absolute path to configuration file)");
- }
-
- File propertyFile = new File(args[0]);
- Properties properties = new Properties();
- FileReader reader = null;
- try {
- reader = new FileReader(propertyFile);
- properties.load(reader);
- } catch (Exception e) {
- throw new IllegalStateException("Could not read properties from file: " + args[0], e);
- } finally {
- IOUtils.closeQuietly(reader);
- FileUtils.deleteQuietly(propertyFile);
- }
- return new Props(properties);
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Encryption.java b/server/process/sonar-process/src/main/java/org/sonar/process/Encryption.java
deleted file mode 100644
index cca05e6c780..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Encryption.java
+++ /dev/null
@@ -1,64 +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.process;
-
-import javax.annotation.Nullable;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @since 3.0
- */
-public final class Encryption {
-
- private static final String BASE64_ALGORITHM = "b64";
-
- private static final String AES_ALGORITHM = "aes";
- private final AesCipher aesCipher;
-
- private final Map<String, Cipher> ciphers = new HashMap<String, Cipher>();
- private static final Pattern ENCRYPTED_PATTERN = Pattern.compile("\\{(.*?)\\}(.*)");
-
- public Encryption(@Nullable String pathToSecretKey) {
- aesCipher = new AesCipher(pathToSecretKey);
- ciphers.put(BASE64_ALGORITHM, new Base64Cipher());
- ciphers.put(AES_ALGORITHM, aesCipher);
- }
-
- public boolean isEncrypted(String value) {
- return value.indexOf('{') == 0 && value.indexOf('}') > 1;
- }
-
- public String decrypt(String encryptedText) {
- Matcher matcher = ENCRYPTED_PATTERN.matcher(encryptedText);
- if (matcher.matches()) {
- Cipher cipher = ciphers.get(matcher.group(1).toLowerCase(Locale.ENGLISH));
- if (cipher != null) {
- return cipher.decrypt(matcher.group(2));
- }
- }
- return encryptedText;
- }
-
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java b/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java
deleted file mode 100644
index 58ffb3af3e0..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/JmxUtils.java
+++ /dev/null
@@ -1,80 +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.process;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.remote.JMXServiceURL;
-
-import java.lang.management.ManagementFactory;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.MalformedURLException;
-
-public class JmxUtils {
-
- private JmxUtils() {
- // only static stuff
- }
-
- public static final String DOMAIN = "org.sonar";
- public static final String NAME_PROPERTY = "name";
-
- public static final String WEB_SERVER_NAME = "web";
- public static final String SEARCH_SERVER_NAME = "search";
-
- public static ObjectName objectName(String name) {
- try {
- return new ObjectName(DOMAIN, NAME_PROPERTY, name);
- } catch (MalformedObjectNameException e) {
- throw new IllegalStateException("Cannot create ObjectName for " + name, e);
- }
- }
-
- public static void registerMBean(Object mbean, String name) {
- try {
- MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- // Check if already registered in JVM (might run multiple instance in JUnits)
- if (mbeanServer.isRegistered(objectName(name))) {
- mbeanServer.unregisterMBean(objectName(name));
- }
- mbeanServer.registerMBean(mbean, objectName(name));
- } catch (RuntimeException re) {
- throw re;
- } catch (Exception e) {
- throw new IllegalStateException("Fail to register JMX MBean named " + name, e);
- }
- }
-
- public static JMXServiceURL serviceUrl(InetAddress host, int port) {
- String address = host.getHostAddress();
- if (host instanceof Inet6Address) {
- // See http://docs.oracle.com/javase/7/docs/api/javax/management/remote/JMXServiceURL.html
- // "The host is a host name, an IPv4 numeric host address, or an IPv6 numeric address enclosed in square brackets."
- address = String.format("[%s]", address);
- }
- try {
- return new JMXServiceURL("rmi", address, port, String.format("/jndi/rmi://%s:%d/jmxrmi", address, port));
- } catch (MalformedURLException e) {
- throw new IllegalStateException("JMX url does not look well formed", e);
- }
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java b/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java
deleted file mode 100644
index 17366850be3..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/LoopbackAddress.java
+++ /dev/null
@@ -1,71 +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.process;
-
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
-
-public class LoopbackAddress {
-
- private static InetAddress instance;
-
- private LoopbackAddress() {
- // only static stuff
- }
-
- /**
- * Quite similar to InetAddress.getLoopbackAddress() which was introduced in Java 7. This
- * method aims to support Java 6. It returns an IPv4 address, but not IPv6 in order to
- * support -Djava.net.preferIPv4Stack=true recommended for Elasticsearch
- */
- public static InetAddress get() {
- if (instance == null) {
- try {
- instance = doGet(NetworkInterface.getNetworkInterfaces());
- } catch (SocketException e) {
- throw new IllegalStateException("Fail to browse network interfaces", e);
- }
-
- }
- return instance;
- }
-
- static InetAddress doGet(Enumeration<NetworkInterface> ifaces) {
- InetAddress result = null;
- while (ifaces.hasMoreElements() && result == null) {
- NetworkInterface iface = ifaces.nextElement();
- Enumeration<InetAddress> addresses = iface.getInetAddresses();
- while (addresses.hasMoreElements()) {
- InetAddress addr = addresses.nextElement();
- if (addr.isLoopbackAddress() && addr instanceof Inet4Address) {
- result = addr;
- break;
- }
- }
- }
- if (result == null) {
- throw new IllegalStateException("Impossible to get a IPv4 loopback address");
- }
- return result;
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MessageException.java b/server/process/sonar-process/src/main/java/org/sonar/process/MessageException.java
deleted file mode 100644
index 5b86ef66c64..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/MessageException.java
+++ /dev/null
@@ -1,36 +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.process;
-
-public class MessageException extends RuntimeException {
- public MessageException(String message) {
- super(message);
- }
-
- /**
- * Does not fill in the stack trace
- *
- * @see Throwable#fillInStackTrace()
- */
- @Override
- public synchronized Throwable fillInStackTrace() {
- return this;
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java b/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java
deleted file mode 100644
index 2389fa5aa18..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/MinimumViableSystem.java
+++ /dev/null
@@ -1,86 +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.process;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-public class MinimumViableSystem {
-
- private final Map<String, String> requiredJavaOptions = new HashMap<String, String>();
-
- public MinimumViableSystem setRequiredJavaOption(String propertyKey, String expectedValue) {
- requiredJavaOptions.put(propertyKey, expectedValue);
- return this;
- }
-
- /**
- * Entry point for all checks
- */
- public void check() {
- checkJavaVersion();
- checkJavaOptions();
- checkWritableTempDir();
- }
-
- /**
- * Verify that temp directory is writable
- */
- private void checkWritableTempDir() {
- checkWritableDir(System.getProperty("java.io.tmpdir"));
- }
-
- void checkWritableDir(String tempPath) {
- try {
- File tempFile = File.createTempFile("check", "tmp", new File(tempPath));
- FileUtils.deleteQuietly(tempFile);
- } catch (IOException e) {
- throw new IllegalStateException(String.format("Temp directory is not writable: %s", tempPath), e);
- }
- }
-
- void checkJavaOptions() {
- for (Map.Entry<String, String> entry : requiredJavaOptions.entrySet()) {
- String value = System.getProperty(entry.getKey());
- if (!StringUtils.equals(value, entry.getValue())) {
- throw new MessageException(String.format(
- "JVM option '%s' must be set to '%s'. Got '%s'", entry.getKey(), entry.getValue(), StringUtils.defaultString(value)));
- }
- }
- }
-
- void checkJavaVersion() {
- String javaVersion = System.getProperty("java.specification.version");
- checkJavaVersion(javaVersion);
- }
-
- void checkJavaVersion(String javaVersion) {
- if (!javaVersion.startsWith("1.6") && !javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) {
- // still better than "java.lang.UnsupportedClassVersionError: Unsupported major.minor version 49.0
- throw new MessageException(String.format("Supported versions of Java are 1.6, 1.7 and 1.8. Got %s.", javaVersion));
- }
- }
-
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java b/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java
deleted file mode 100644
index baa0f00791c..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Monitor.java
+++ /dev/null
@@ -1,149 +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.process;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
-public class Monitor extends Thread implements Terminable {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(Monitor.class);
-
- private static final long PING_DELAY_MS = 3000L;
-
- private long pingDelayMs = PING_DELAY_MS;
- private final List<ProcessWrapper> processes = new CopyOnWriteArrayList<ProcessWrapper>();
- private final ScheduledFuture<?> watch;
- private final ScheduledExecutorService monitorExecutionService;
-
- /**
- * Starts another thread to send ping to all registered processes
- */
- public Monitor() {
- super("Process Monitor");
- monitorExecutionService = Executors.newScheduledThreadPool(1);
- watch = monitorExecutionService.scheduleAtFixedRate(new ProcessWatch(), 0L, getPingDelayMs(), TimeUnit.MILLISECONDS);
- }
-
- private long getPingDelayMs() {
- return pingDelayMs;
- }
-
- public Monitor setPingDelayMs(long pingDelayMs) {
- this.pingDelayMs = pingDelayMs;
- return this;
- }
-
- private class ProcessWatch extends Thread {
- private ProcessWatch() {
- super("Process Ping");
- }
-
- @Override
- public void run() {
- for (ProcessWrapper process : processes) {
- LOGGER.debug("Pinging process[{}]", process.getName());
- try {
- ProcessMXBean mBean = process.getProcessMXBean();
- if (mBean != null) {
- mBean.ping();
- }
- } catch (Exception e) {
- LOGGER.debug("Could not ping process[{}]", process.getName());
- LOGGER.trace("Ping failure", e);
- }
- }
- }
- }
-
- /**
- * Registers and monitors process. Note that process is probably not ready yet.
- */
- public void monitor(ProcessWrapper process) throws InterruptedException {
- LOGGER.info("Monitoring process[{}]", process.getName());
- // starts a monitoring thread
- process.start();
- processes.add(process);
- }
-
- /**
- * Check continuously that registered processes are still up. If any process is down or does not answer to pings
- * during the max allowed period, then thread exits.
- */
- @Override
- public void run() {
- try {
- boolean ok = true;
- while (isRunning && ok) {
- LOGGER.debug("Monitoring {} processes.", processes.size());
- for (ProcessWrapper process : processes) {
- if (!ProcessUtils.isAlive(process.process())) {
- LOGGER.info("{} is down, stopping all other processes", process.getName());
- ok = false;
- interrupt();
- }
- }
- if (ok) {
- Thread.sleep(PING_DELAY_MS);
- }
- }
- } catch (InterruptedException e) {
- LOGGER.debug("Monitoring thread is interrupted");
- } finally {
- terminate();
- }
- }
-
- volatile Boolean isRunning = true;
-
- @Override
- public synchronized void terminate() {
-
- LOGGER.debug("Monitoring thread is terminating");
-
- if (!monitorExecutionService.isShutdown()) {
- monitorExecutionService.shutdownNow();
- }
- if (!watch.isCancelled()) {
- watch.cancel(true);
- }
-
- processes.clear();
- interruptAndWait();
- }
-
- private void interruptAndWait() {
- this.interrupt();
- try {
- if (this.isAlive()) {
- this.join();
- }
- } catch (InterruptedException e) {
- // Expected to be interrupted :)
- }
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
deleted file mode 100644
index 5ad365ee338..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
+++ /dev/null
@@ -1,169 +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.process;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
-public abstract class MonitoredProcess implements ProcessMXBean {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class);
-
- private static final long AUTOKILL_TIMEOUT_MS = 30000L;
- private static final long AUTOKILL_CHECK_DELAY_MS = 2000L;
- public static final String NAME_PROPERTY = "pName";
-
- private Long lastPing;
- private final String name;
- private boolean terminated = false;
- private long timeout = AUTOKILL_TIMEOUT_MS;
- private long checkDelay = AUTOKILL_CHECK_DELAY_MS;
-
- protected final Props props;
- private ScheduledFuture<?> pingTask = null;
-
- private ScheduledExecutorService monitor;
- private final boolean isMonitored;
-
- protected MonitoredProcess(Props props) {
- this(props, !ProcessUtils.isJvmDebugEnabled());
- }
-
- protected MonitoredProcess(Props props, boolean monitor) {
- this.isMonitored = monitor;
- this.props = props;
- this.name = props.nonNullValue(NAME_PROPERTY);
-
- JmxUtils.registerMBean(this, name);
- ProcessUtils.addSelfShutdownHook(this);
- }
-
- public MonitoredProcess setTimeout(long timeout) {
- this.timeout = timeout;
- return this;
- }
-
- private long getTimeout() {
- return timeout;
- }
-
- public MonitoredProcess setCheckDelay(long checkDelay) {
- this.checkDelay = checkDelay;
- return this;
- }
-
- private long getCheckDelay() {
- return checkDelay;
- }
-
- public final void start() {
- if (monitor != null) {
- throw new IllegalStateException("Already started");
- }
- LOGGER.debug("Process[{}] starting", name);
- scheduleAutokill(isMonitored);
- try {
- doStart();
- } catch (Exception e) {
- LOGGER.error("Could not start process: {}", e);
- this.terminate();
- }
- LOGGER.debug("Process[{}] started", name);
- }
-
- /**
- * If the process does not receive pings during the max allowed period, then
- * process auto-kills
- */
- private void scheduleAutokill(final boolean isMonitored) {
- final Runnable breakOnMissingPing = new Runnable() {
- @Override
- public void run() {
- long time = System.currentTimeMillis();
- if (time - lastPing > getTimeout()) {
- LoggerFactory.getLogger(getClass()).info(String.format(
- "Did not receive any ping during %d seconds. Shutting down.", getTimeout() / 1000));
- if (isMonitored) {
- terminate();
- }
- }
- }
- };
- lastPing = System.currentTimeMillis();
- monitor = Executors.newScheduledThreadPool(1);
- pingTask = monitor.scheduleAtFixedRate(breakOnMissingPing, getCheckDelay(), getCheckDelay(), TimeUnit.MILLISECONDS);
- }
-
- @Override
- public final long ping() {
- this.lastPing = System.currentTimeMillis();
- return lastPing;
- }
-
- @Override
- public final synchronized void terminate() {
- if (monitor != null) {
- LOGGER.debug("Process[{}] terminating", name);
- try {
- doTerminate();
- } catch (Exception e) {
- LOGGER.error("Fail to terminate " + name, e);
- // do not propagate exception
- }
- monitor.shutdownNow();
- monitor = null;
- if (pingTask != null) {
- pingTask.cancel(true);
- pingTask = null;
- }
- LOGGER.debug("Process[{}] terminated", name);
- terminated = true;
- }
- }
-
- public boolean isTerminated() {
- return terminated && monitor == null;
- }
-
- public boolean isMonitored() {
- return this.isMonitored;
- }
-
- @Override
- public final boolean isReady() {
- try {
- return doIsReady();
- } catch (Exception ignored) {
- LOGGER.trace("Exception while checking if ready", ignored);
- return false;
- }
- }
-
- protected abstract void doStart();
-
- protected abstract void doTerminate();
-
- protected abstract boolean doIsReady();
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java b/server/process/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
deleted file mode 100644
index 516c57c497a..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/NetworkUtils.java
+++ /dev/null
@@ -1,41 +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.process;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-
-public class NetworkUtils {
-
- private NetworkUtils() {
- // only static stuff
- }
-
- public static int freePort() {
- try {
- ServerSocket s = new ServerSocket(0);
- int port = s.getLocalPort();
- s.close();
- return port;
- } catch (IOException e) {
- throw new IllegalStateException("Can not find an open network port", e);
- }
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java b/server/process/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java
deleted file mode 100644
index dacddd91847..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java
+++ /dev/null
@@ -1,53 +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.process;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.util.StatusPrinter;
-import org.slf4j.LoggerFactory;
-
-public class ProcessLogging {
-
- private static final String PATH_LOGS_PROPERTY = "sonar.path.logs";
-
- public void configure(Props props, String logbackXmlResource) {
- LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
- try {
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(context);
- context.reset();
- context.putProperty(PATH_LOGS_PROPERTY, props.nonNullValue(PATH_LOGS_PROPERTY));
- doConfigure(configurator, logbackXmlResource);
- } catch (JoranException ignored) {
- // StatusPrinter will handle this
- }
- StatusPrinter.printInCaseOfErrorsOrWarnings(context);
-
- }
-
- /**
- * Extracted only for unit testing
- */
- void doConfigure(JoranConfigurator configurator, String logbackXmlResource) throws JoranException {
- configurator.doConfigure(getClass().getResource(logbackXmlResource));
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java b/server/process/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java
deleted file mode 100644
index d212c08ccdd..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessMXBean.java
+++ /dev/null
@@ -1,27 +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.process;
-
-public interface ProcessMXBean extends Terminable {
-
- boolean isReady();
-
- long ping();
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessUtils.java b/server/process/sonar-process/src/main/java/org/sonar/process/ProcessUtils.java
deleted file mode 100644
index e47c24682d4..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessUtils.java
+++ /dev/null
@@ -1,92 +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.process;
-
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nullable;
-
-import java.lang.management.ManagementFactory;
-
-public class ProcessUtils {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ProcessUtils.class);
-
- private ProcessUtils() {
- // only static stuff
- }
-
- /**
- * Do not abuse to this method. It uses exceptions to get status.
- * @return false if process is null or terminated, else true.
- */
- public static boolean isAlive(@Nullable Process process) {
- boolean alive = false;
- if (process != null) {
- try {
- process.exitValue();
- } catch (IllegalThreadStateException ignored) {
- alive = true;
- }
- }
- return alive;
- }
-
- /**
- * Destroys process (equivalent to kill -9) if alive
- * @return true if the process was destroyed, false if process is null or already destroyed.
- */
- public static boolean destroyQuietly(@Nullable Process process) {
- boolean destroyed = false;
- if (isAlive(process)) {
- try {
- process.destroy();
- destroyed = true;
- } catch (Exception e) {
- LoggerFactory.getLogger(ProcessUtils.class).error("Fail to destroy " + process);
- }
- }
- return destroyed;
- }
-
- public static void addSelfShutdownHook(final Terminable terminable) {
- Thread shutdownHook = new Thread(new Runnable() {
- @Override
- public void run() {
- terminable.terminate();
- }
- });
- Runtime.getRuntime().addShutdownHook(shutdownHook);
- }
-
- public static void closeStreams(@Nullable Process process) {
- if (process != null) {
- IOUtils.closeQuietly(process.getInputStream());
- IOUtils.closeQuietly(process.getOutputStream());
- IOUtils.closeQuietly(process.getErrorStream());
- }
- }
-
- public static boolean isJvmDebugEnabled() {
- return ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java b/server/process/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
deleted file mode 100644
index 869867a6e34..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
+++ /dev/null
@@ -1,375 +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.process;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Fork and monitor a new process
- */
-public class ProcessWrapper extends Thread implements Terminable {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(ProcessWrapper.class);
-
- public static final long READY_TIMEOUT_MS = 300000L;
-
- private String processName, className;
- private int jmxPort = -1;
- private final List<String> javaOpts = new ArrayList<String>();
- private final List<String> classpath = new ArrayList<String>();
- private final Map<String, String> envProperties = new HashMap<String, String>();
- private final Properties properties = new Properties();
- private File workDir;
- private Process process;
- private StreamGobbler errorGobbler;
- private StreamGobbler outputGobbler;
- private ProcessMXBean processMXBean;
- private final Object terminationLock = new Object();
-
- public ProcessWrapper(String processName) {
- super(processName);
- this.processName = processName;
- }
-
- public ProcessWrapper setClassName(String s) {
- this.className = s;
- return this;
- }
-
- public ProcessWrapper setEnvProperty(String key, String value) {
- envProperties.put(key, value);
- return this;
- }
-
- public ProcessWrapper addProperties(Properties p) {
- properties.putAll(p);
- return this;
- }
-
- public ProcessWrapper addProperty(String key, String value) {
- properties.setProperty(key, value);
- return this;
- }
-
- public ProcessWrapper addJavaOpts(String s) {
- Collections.addAll(javaOpts, s.split(" "));
- return this;
- }
-
- public ProcessWrapper addClasspath(String s) {
- classpath.add(s);
- return this;
- }
-
- public ProcessWrapper setJmxPort(int i) {
- this.jmxPort = i;
- return this;
- }
-
- public ProcessWrapper setWorkDir(File d) {
- this.workDir = d;
- return this;
- }
-
- public ProcessWrapper setTempDirectory(File tempDirectory) {
- this.setEnvProperty("java.io.tmpdir", tempDirectory.getAbsolutePath());
- return this;
- }
-
- public ProcessWrapper setLogDir(File logDirectory) {
- this.setEnvProperty("sonar.path.logs", logDirectory.getAbsolutePath());
- return this;
- }
-
- @CheckForNull
- public Process process() {
- return process;
- }
-
- /**
- * Execute command-line and connects to JMX RMI.
- *
- * @return true on success, false if bad command-line or process failed to start JMX RMI
- */
- public boolean execute() {
- List<String> command = new ArrayList<String>();
- try {
- command.add(buildJavaCommand());
- command.addAll(javaOpts);
- command.addAll(buildJMXOptions());
- command.addAll(buildClasspath());
- command.add(className);
- command.add(buildPropertiesFile().getAbsolutePath());
-
- ProcessBuilder processBuilder = new ProcessBuilder();
- processBuilder.command(command);
- processBuilder.directory(workDir);
- processBuilder.environment().putAll(envProperties);
- LOGGER.info("starting {}: {}", getName(), StringUtils.join(command, " "));
- process = processBuilder.start();
- errorGobbler = new StreamGobbler(process.getErrorStream(), this.getName() + "-ERROR");
- outputGobbler = new StreamGobbler(process.getInputStream(), this.getName());
- outputGobbler.start();
- errorGobbler.start();
- processMXBean = waitForJMX();
- if (processMXBean == null) {
- terminate();
- return false;
- }
- return true;
- } catch (Exception e) {
- throw new IllegalStateException("Fail to start command: " + StringUtils.join(command, " "), e);
- }
- }
-
- @Override
- public void run() {
- try {
- if (ProcessUtils.isAlive(process)) {
- process.waitFor();
- }
- } catch (Exception e) {
- LOGGER.info("ProcessThread has been interrupted. Killing node.");
- LOGGER.trace("Process exception", e);
- }
- }
-
- public boolean isReady() {
- return processMXBean != null && processMXBean.isReady();
- }
-
- public ProcessMXBean getProcessMXBean() {
- return processMXBean;
- }
-
- private String buildJavaCommand() {
- String separator = System.getProperty("file.separator");
- return new File(new File(System.getProperty("java.home")),
- "bin" + separator + "java").getAbsolutePath();
- }
-
- private List<String> buildJMXOptions() {
- if (jmxPort < 1) {
- throw new IllegalStateException("JMX port is not set");
- }
- return Arrays.asList(
- "-Dcom.sun.management.jmxremote",
- "-Dcom.sun.management.jmxremote.port=" + jmxPort,
- "-Dcom.sun.management.jmxremote.authenticate=false",
- "-Dcom.sun.management.jmxremote.ssl=false",
- "-Djava.rmi.server.hostname=" + LoopbackAddress.get().getHostAddress());
- }
-
- private List<String> buildClasspath() {
- return Arrays.asList("-cp", StringUtils.join(classpath, System.getProperty("path.separator")));
- }
-
- private File buildPropertiesFile() {
- File propertiesFile = null;
- try {
- propertiesFile = File.createTempFile("sq-conf", "properties");
- Properties props = new Properties();
- props.putAll(properties);
- props.put(MonitoredProcess.NAME_PROPERTY, processName);
- OutputStream out = new FileOutputStream(propertiesFile);
- props.store(out, "Temporary properties file for Process [" + getName() + "]");
- out.close();
- return propertiesFile;
- } catch (IOException e) {
- throw new IllegalStateException("Cannot write temporary settings to " + propertiesFile, e);
- }
- }
-
- /**
- * Wait for JMX RMI to be ready. Return <code>null</code>
- */
- @CheckForNull
- private ProcessMXBean waitForJMX() {
- JMXServiceURL jmxUrl = JmxUtils.serviceUrl(LoopbackAddress.get(), jmxPort);
- for (int i = 0; i < 5; i++) {
- try {
- Thread.sleep(1000L);
- JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, null);
- jmxConnector.addConnectionNotificationListener(new NotificationListener() {
- @Override
- public void handleNotification(Notification notification, Object handback) {
- LOGGER.debug("JMX Connection Notification:{}", notification.getMessage());
- }
- }, null, null);
- MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection();
- return JMX.newMBeanProxy(mBeanServer, JmxUtils.objectName(processName), ProcessMXBean.class);
- } catch (Exception ignored) {
- LOGGER.info(String.format("Could not connect to JMX (attempt %d). Trying again.", i), ignored);
- }
- }
- // failed to connect
- return null;
- }
-
- @Override
- public void terminate() {
- synchronized (terminationLock) {
- if (processMXBean != null && process != null) {
- LOGGER.info("{} stopping", getName());
- // Send the terminate command to process in order to gracefully shutdown.
- // Then hardly kill it if it didn't terminate in 30 seconds
- ScheduledExecutorService killer = Executors.newScheduledThreadPool(1);
- try {
- Runnable killerTask = new Runnable() {
- @Override
- public void run() {
- ProcessUtils.destroyQuietly(process);
- }
- };
-
- ScheduledFuture killerFuture = killer.schedule(killerTask, 30, TimeUnit.SECONDS);
- processMXBean.terminate();
- this.join();
- killerFuture.cancel(true);
- LOGGER.info("{} stopped", getName());
-
- } catch (Exception ignored) {
- LOGGER.trace("Could not terminate process", ignored);
- } finally {
- killer.shutdownNow();
- interruptAndWait();
- }
- } else {
- // process is not monitored through JMX, but killing it though
- ProcessUtils.destroyQuietly(process);
- }
- processMXBean = null;
- }
- }
-
- public boolean waitForReady() throws InterruptedException {
- long now = 0;
- long wait = 500L;
- while (now < READY_TIMEOUT_MS) {
- try {
- if (processMXBean == null) {
- return false;
- }
- if (processMXBean.isReady()) {
- return true;
- }
- } catch (Exception e) {
- LOGGER.trace("Process is not ready yet", e);
- }
- Thread.sleep(wait);
- now += wait;
- }
- return false;
- }
-
- private void interruptAndWait() {
- try {
- //after being interrupted, finalize the goblins
- if (outputGobbler != null && outputGobbler.isAlive()) {
- waitUntilFinish(outputGobbler);
- }
-
- if (errorGobbler != null && errorGobbler.isAlive()) {
- waitUntilFinish(errorGobbler);
- }
- if (process != null) {
- ProcessUtils.closeStreams(process);
- }
-
- //Join while the main thread terminates
- if (this.isAlive()) {
- this.join();
- }
- } catch (InterruptedException e) {
- // Expected to be interrupted :)
- }
- }
-
- private void waitUntilFinish(@Nullable Thread thread) {
- if (thread != null && thread.isAlive()) {
- try {
- thread.join();
- } catch (InterruptedException e) {
- LOGGER.error("InterruptedException while waiting finish of " + thread.getName() + " in process '" + getName() + "'", e);
- }
- }
- }
-
-
- private static class StreamGobbler extends Thread {
- private final InputStream is;
- private final Logger logger;
-
- StreamGobbler(InputStream is, String name) {
- super(name + "_ProcessStreamGobbler");
- this.is = is;
- this.logger = LoggerFactory.getLogger(name);
- }
-
- @Override
- public void run() {
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- try {
- String line;
- while ((line = br.readLine()) != null) {
- logger.info(line);
- }
- } catch (Exception ignored) {
- logger.trace("Error while Gobbling", ignored);
- } finally {
- IOUtils.closeQuietly(br);
- IOUtils.closeQuietly(isr);
- }
- }
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Props.java b/server/process/sonar-process/src/main/java/org/sonar/process/Props.java
deleted file mode 100644
index b868702eafc..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Props.java
+++ /dev/null
@@ -1,120 +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.process;
-
-import org.apache.commons.lang.StringUtils;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.io.File;
-import java.util.Properties;
-
-public class Props {
-
- private final Properties properties;
- private final Encryption encryption;
-
- public Props(Properties props) {
- this.properties = props;
- this.encryption = new Encryption(props.getProperty(AesCipher.ENCRYPTION_SECRET_KEY_PATH));
- }
-
- public boolean contains(String key) {
- return properties.containsKey(key);
- }
-
- @CheckForNull
- public String value(String key) {
- String value = properties.getProperty(key);
- if (value != null && encryption.isEncrypted(value)) {
- value = encryption.decrypt(value);
- }
- return value;
- }
-
- public String nonNullValue(String key) {
- String value = value(key);
- if (value == null) {
- throw new IllegalArgumentException("Missing property: " + key);
- }
- return value;
- }
-
- @CheckForNull
- public String value(String key, @Nullable String defaultValue) {
- String s = value(key);
- return s == null ? defaultValue : s;
- }
-
- public boolean valueAsBoolean(String key) {
- String s = value(key);
- return s != null && Boolean.parseBoolean(s);
- }
-
- public boolean valueAsBoolean(String key, boolean defaultValue) {
- String s = value(key);
- return s != null ? Boolean.parseBoolean(s) : defaultValue;
- }
-
- public File nonNullValueAsFile(String key) {
- String s = value(key);
- if (s == null) {
- throw new IllegalArgumentException("Property " + key + " is missing");
- }
- return new File(s);
- }
-
- @CheckForNull
- public Integer valueAsInt(String key) {
- String s = value(key);
- if (s != null && !"".equals(s)) {
- try {
- return Integer.parseInt(s);
- } catch (NumberFormatException e) {
- throw new IllegalStateException("Value of property " + key + " is not an integer: " + s, e);
- }
- }
- return null;
- }
-
- public int valueAsInt(String key, int defaultValue) {
- Integer i = valueAsInt(key);
- return i == null ? defaultValue : i;
- }
-
- public Properties rawProperties() {
- return properties;
- }
-
- public Props set(String key, @Nullable String value) {
- if (value != null) {
- properties.setProperty(key, value);
- }
- return this;
- }
-
- public void setDefault(String key, String value) {
- String s = properties.getProperty(key);
- if (StringUtils.isBlank(s)) {
- properties.setProperty(key, value);
- }
- }
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/Terminable.java b/server/process/sonar-process/src/main/java/org/sonar/process/Terminable.java
deleted file mode 100644
index 109e91c42da..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/Terminable.java
+++ /dev/null
@@ -1,30 +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.process;
-
-/**
- * This term "terminate" is used in order to not conflict with {@link Thread#stop()}.
- */
-public interface Terminable {
- /**
- * Stops pending work. Must <b>not</b> throw an exception on error.
- */
- void terminate();
-}
diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/package-info.java b/server/process/sonar-process/src/main/java/org/sonar/process/package-info.java
deleted file mode 100644
index 09da5ce266d..00000000000
--- a/server/process/sonar-process/src/main/java/org/sonar/process/package-info.java
+++ /dev/null
@@ -1,23 +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.process;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/AesCipherTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/AesCipherTest.java
deleted file mode 100644
index 8350eafaa3e..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/AesCipherTest.java
+++ /dev/null
@@ -1,185 +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.process;
-
-import com.google.common.io.Resources;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang.StringUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import javax.crypto.BadPaddingException;
-import java.io.File;
-import java.security.InvalidKeyException;
-import java.security.Key;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-
-public class AesCipherTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void generateRandomSecretKey() {
- AesCipher cipher = new AesCipher(null);
-
- String key = cipher.generateRandomSecretKey();
-
- assertThat(StringUtils.isNotBlank(key)).isTrue();
- assertThat(Base64.isArrayByteBase64(key.getBytes())).isTrue();
- }
-
- @Test
- public void encrypt() throws Exception {
- AesCipher cipher = new AesCipher(pathToSecretKey());
-
- String encryptedText = cipher.encrypt("this is a secret");
-
- assertThat(StringUtils.isNotBlank(encryptedText)).isTrue();
- assertThat(Base64.isArrayByteBase64(encryptedText.getBytes())).isTrue();
- }
-
- @Test
- public void encrypt_bad_key() throws Exception {
- thrown.expect(RuntimeException.class);
- thrown.expectMessage("Invalid AES key");
-
- AesCipher cipher = new AesCipher(getPath("bad_secret_key.txt"));
-
- cipher.encrypt("this is a secret");
- }
-
- @Test
- public void decrypt() throws Exception {
- AesCipher cipher = new AesCipher(pathToSecretKey());
-
- // the following value has been encrypted with the key /org/sonar/api/config/AesCipherTest/aes_secret_key.txt
- String clearText = cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=");
-
- assertThat(clearText).isEqualTo("this is a secret");
- }
-
- @Test
- public void decrypt_bad_key() throws Exception {
- AesCipher cipher = new AesCipher(getPath("bad_secret_key.txt"));
-
- try {
- cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=");
- fail();
-
- } catch (RuntimeException e) {
- assertThat(e.getCause()).isInstanceOf(InvalidKeyException.class);
- }
- }
-
- @Test
- public void decrypt_other_key() throws Exception {
- AesCipher cipher = new AesCipher(getPath("other_secret_key.txt"));
-
- try {
- // text encrypted with another key
- cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=");
- fail();
-
- } catch (RuntimeException e) {
- assertThat(e.getCause()).isInstanceOf(BadPaddingException.class);
- }
- }
-
- @Test
- public void encryptThenDecrypt() throws Exception {
- AesCipher cipher = new AesCipher(pathToSecretKey());
-
- assertThat(cipher.decrypt(cipher.encrypt("foo"))).isEqualTo("foo");
- }
-
- @Test
- public void testDefaultPathToSecretKey() {
- AesCipher cipher = new AesCipher(null);
-
- String path = cipher.getPathToSecretKey();
-
- assertThat(StringUtils.isNotBlank(path)).isTrue();
- assertThat(new File(path).getName()).isEqualTo("sonar-secret.txt");
- }
-
- @Test
- public void loadSecretKeyFromFile() throws Exception {
- AesCipher cipher = new AesCipher(null);
- Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey());
- assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
- assertThat(secretKey.getEncoded().length).isGreaterThan(10);
- }
-
- @Test
- public void loadSecretKeyFromFile_trim_content() throws Exception {
- String path = getPath("non_trimmed_secret_key.txt");
- AesCipher cipher = new AesCipher(null);
-
- Key secretKey = cipher.loadSecretFileFromFile(path);
-
- assertThat(secretKey.getAlgorithm()).isEqualTo("AES");
- assertThat(secretKey.getEncoded().length).isGreaterThan(10);
- }
-
- @Test
- public void loadSecretKeyFromFile_file_does_not_exist() throws Exception {
- thrown.expect(IllegalStateException.class);
-
- AesCipher cipher = new AesCipher(null);
- cipher.loadSecretFileFromFile("/file/does/not/exist");
- }
-
- @Test
- public void loadSecretKeyFromFile_no_property() throws Exception {
- thrown.expect(IllegalStateException.class);
-
- AesCipher cipher = new AesCipher(null);
- cipher.loadSecretFileFromFile(null);
- }
-
- @Test
- public void hasSecretKey() throws Exception {
- AesCipher cipher = new AesCipher(pathToSecretKey());
-
- assertThat(cipher.hasSecretKey()).isTrue();
- }
-
- @Test
- public void doesNotHaveSecretKey() throws Exception {
- AesCipher cipher = new AesCipher("/my/twitter/id/is/SimonBrandhof");
-
- assertThat(cipher.hasSecretKey()).isFalse();
- }
-
- private static String getPath(String file) {
- return Resources.getResource(AesCipherTest.class, "AesCipherTest/" + file).getPath();
- }
-
- private static String pathToSecretKey() throws Exception {
- return getPath("aes_secret_key.txt");
- }
-
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessTest.java
deleted file mode 100644
index 2045cd4516d..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessTest.java
+++ /dev/null
@@ -1,59 +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.process;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.ServerSocket;
-
-public abstract class BaseProcessTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- public static final String DUMMY_OK_APP = "org.sonar.application.DummyOkProcess";
-
- int freePort;
- File dummyAppJar;
- Process proc;
-
- @Before
- public void setup() throws IOException {
- ServerSocket socket = new ServerSocket(0);
- freePort = socket.getLocalPort();
- socket.close();
-
- dummyAppJar = FileUtils.toFile(getClass().getResource("/sonar-dummy-app.jar"));
- }
-
- @After
- public void tearDown() {
- if (proc != null) {
- ProcessUtils.destroyQuietly(proc);
- }
- }
-
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessWrapperTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessWrapperTest.java
deleted file mode 100644
index b217edb2584..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessWrapperTest.java
+++ /dev/null
@@ -1,118 +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.process;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.junit.Test;
-
-import java.io.File;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-
-public class BaseProcessWrapperTest extends BaseProcessTest {
-
- @Test
- public void has_dummy_app() {
- assertThat(dummyAppJar).isFile();
- assertThat(dummyAppJar).exists();
- }
-
- private void assertCanStart(ProcessWrapper process) {
- assertThat(process.execute()).isTrue();
- proc = process.process();
- }
-
- private void assertCanBeReady(ProcessWrapper process) throws InterruptedException {
- int count = 0;
- while (!process.isReady() && count < 5) {
- Thread.sleep(500);
- }
- assertThat(process.getProcessMXBean().isReady()).isTrue();
- }
-
- private void assertPing(ProcessWrapper process) {
- long now = System.currentTimeMillis();
- long ping = process.getProcessMXBean().ping();
- assertThat(ping - now).isLessThan(3000L);
- }
-
-
- @Test
- public void execute_dummy_app() throws Exception {
-
- ProcessWrapper process = new ProcessWrapper("DummyOkProcess")
- .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkProcess")
- .addClasspath(dummyAppJar.getAbsolutePath())
- .setWorkDir(temp.getRoot())
- .setTempDirectory(temp.getRoot())
- .setJmxPort(freePort)
- .setClassName(DUMMY_OK_APP);
-
- assertThat(process.isAlive()).isFalse();
- assertCanStart(process);
- process.start();
- assertCanBeReady(process);
- assertThat(process.isAlive()).isTrue();
- assertPing(process);
- process.terminate();
- try {
- assertPing(process);
- fail();
- } catch (Exception e) {
-
- }
- }
-
-
- @Test
- public void execute_dummy_in_space_folder_app() throws Exception {
-
- // 0 create a home with space...
- File home = temp.newFolder("t est");
- assertThat(home.canWrite()).isTrue();
- File lib = new File(home, "lib");
- File tempdir = new File(home, "temp");
- FileUtils.copyFileToDirectory(dummyAppJar, lib);
-
- // 1 Create Properties
- Props props = new Props(new Properties());
- props.set("spaceHome", home.getAbsolutePath());
-
- // 3 start dummy app
- File effectiveHome = props.nonNullValueAsFile("spaceHome");
-
- String cp = FilenameUtils.concat(new File(effectiveHome, "lib").getAbsolutePath(), "*");
- System.out.println("cp = " + cp);
- ProcessWrapper process = new ProcessWrapper("DummyOkProcess")
- .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkProcess")
- .setTempDirectory(tempdir)
- .addClasspath(cp)
- .setWorkDir(home)
- .setJmxPort(freePort)
- .setClassName(DUMMY_OK_APP);
-
- assertThat(process.isAlive()).isFalse();
- assertCanStart(process);
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
deleted file mode 100644
index de928b93850..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
+++ /dev/null
@@ -1,95 +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.process;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.io.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class ConfigurationUtilsTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Test
- public void shouldInterpolateVariables() {
- Properties input = new Properties();
- input.setProperty("hello", "world");
- input.setProperty("url", "${env:SONAR_JDBC_URL}");
- input.setProperty("do_not_change", "${SONAR_JDBC_URL}");
- Map<String, String> variables = Maps.newHashMap();
- variables.put("SONAR_JDBC_URL", "jdbc:h2:mem");
-
- Properties output = ConfigurationUtils.interpolateVariables(input, variables);
-
- assertThat(output).hasSize(3);
- assertThat(output.getProperty("hello")).isEqualTo("world");
- assertThat(output.getProperty("url")).isEqualTo("jdbc:h2:mem");
- assertThat(output.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");
-
- // input is not changed
- assertThat(input).hasSize(3);
- assertThat(input.getProperty("hello")).isEqualTo("world");
- assertThat(input.getProperty("url")).isEqualTo("${env:SONAR_JDBC_URL}");
- assertThat(input.getProperty("do_not_change")).isEqualTo("${SONAR_JDBC_URL}");
- }
-
- @Test
- public void loadPropsFromCommandLineArgs_missing_argument() throws Exception {
- try {
- ConfigurationUtils.loadPropsFromCommandLineArgs(new String[0]);
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).startsWith("Only a single command-line argument is accepted");
- }
- }
-
- @Test
- public void loadPropsFromCommandLineArgs_load_properties_from_file() throws Exception {
- File propsFile = temp.newFile();
- FileUtils.write(propsFile, "foo=bar");
-
- Props result = ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()});
- assertThat(result.value("foo")).isEqualTo("bar");
- assertThat(result.rawProperties()).hasSize(1);
- }
-
- @Test
- public void loadPropsFromCommandLineArgs_file_does_not_exist() throws Exception {
- File propsFile = temp.newFile();
- FileUtils.deleteQuietly(propsFile);
-
- try {
- ConfigurationUtils.loadPropsFromCommandLineArgs(new String[]{propsFile.getAbsolutePath()});
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Could not read properties from file: " + propsFile.getAbsolutePath());
- }
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java b/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java
deleted file mode 100644
index f16c61fd93c..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/DummyProcess.java
+++ /dev/null
@@ -1,84 +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.process;
-
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.util.Properties;
-
-public class DummyProcess extends MonitoredProcess {
-
- public static final String NAME = "DummyName";
- public static final String CHECKFILE_NAME = "check.tmp";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(DummyProcess.class);
-
- private boolean isReady = false;
- private boolean isRunning = true;
- private File checkFile;
-
-
- protected DummyProcess(Props props, boolean monitored) throws Exception {
- super(props, monitored);
- }
-
- protected DummyProcess(Props props) throws Exception {
- super(props);
- }
-
- @Override
- protected void doStart() {
- isReady = true;
- checkFile = new File(FileUtils.getTempDirectory(), CHECKFILE_NAME);
- LOGGER.info("Starting Dummy OK Process");
- while (isRunning) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- isRunning = false;
- }
- }
- }
-
- @Override
- protected void doTerminate() {
- LOGGER.info("Terminating Dummy OK Process");
- this.isRunning = false;
- }
-
- @Override
- protected boolean doIsReady() {
- return isReady;
- }
-
- public static void main(String[] args) throws Exception {
- Props props = new Props(new Properties());
- props.set(MonitoredProcess.NAME_PROPERTY, DummyProcess.class.getSimpleName());
- new DummyProcess(props).start();
- System.exit(1);
- }
-
- public File getCheckFile() {
- return checkFile;
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java
deleted file mode 100644
index 0c11856b0fa..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java
+++ /dev/null
@@ -1,59 +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.process;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class EncryptionTest {
-
- @Test
- public void isEncrypted() {
- Encryption encryption = new Encryption(null);
- assertThat(encryption.isEncrypted("{aes}ADASDASAD"), is(true));
- assertThat(encryption.isEncrypted("{b64}ADASDASAD"), is(true));
- assertThat(encryption.isEncrypted("{abc}ADASDASAD"), is(true));
-
- assertThat(encryption.isEncrypted("{}"), is(false));
- assertThat(encryption.isEncrypted("{foo"), is(false));
- assertThat(encryption.isEncrypted("foo{aes}"), is(false));
- }
-
- @Test
- public void decrypt() {
- Encryption encryption = new Encryption(null);
- assertThat(encryption.decrypt("{b64}Zm9v"), is("foo"));
- }
-
- @Test
- public void decrypt_unknown_algorithm() {
- Encryption encryption = new Encryption(null);
- assertThat(encryption.decrypt("{xxx}Zm9v"), is("{xxx}Zm9v"));
- }
-
- @Test
- public void decrypt_uncrypted_text() {
- Encryption encryption = new Encryption(null);
- assertThat(encryption.decrypt("foo"), is("foo"));
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java
deleted file mode 100644
index d2ab21157ef..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/JmxUtilsTest.java
+++ /dev/null
@@ -1,125 +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.process;
-
-import org.junit.Test;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.remote.JMXServiceURL;
-
-import java.lang.management.ManagementFactory;
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class JmxUtilsTest {
-
- class MyBean implements ProcessMXBean {
-
- @Override
- public boolean isReady() {
- return false;
- }
-
- @Override
- public long ping() {
- return 0;
- }
-
- @Override
- public void terminate() {
-
- }
- }
-
- @Test
- public void construct_jmx_objectName() throws Exception {
- MyBean mxBean = new MyBean();
- ObjectName objectName = JmxUtils.objectName(mxBean.getClass().getSimpleName());
- assertThat(objectName).isNotNull();
- assertThat(objectName.getDomain()).isEqualTo(JmxUtils.DOMAIN);
- assertThat(objectName.getKeyProperty(JmxUtils.NAME_PROPERTY)).isEqualTo(mxBean.getClass().getSimpleName());
- }
-
- @Test
- public void fail_jmx_objectName() throws Exception {
- try {
- JmxUtils.objectName(":");
- fail();
- } catch (Exception e) {
- assertThat(e.getMessage()).isEqualTo("Cannot create ObjectName for :");
- }
- }
-
- @Test
- public void testRegisterMBean() throws Exception {
-
- // 0 Get mbServer and create out test MXBean
- MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- MyBean mxBean = new MyBean();
- ObjectName objectName = JmxUtils.objectName(mxBean.getClass().getSimpleName());
-
- // 1 assert that mxBean gets registered
- assertThat(mbeanServer.isRegistered(objectName)).isFalse();
- JmxUtils.registerMBean(mxBean, mxBean.getClass().getSimpleName());
- assertThat(mbeanServer.isRegistered(objectName)).isTrue();
-
- // 2 assert that we can over-register
- assertThat(mbeanServer.isRegistered(objectName)).isTrue();
- JmxUtils.registerMBean(mxBean, mxBean.getClass().getSimpleName());
- assertThat(mbeanServer.isRegistered(objectName)).isTrue();
- }
-
- @Test
- public void serviceUrl_ipv4() throws Exception {
- JMXServiceURL url = JmxUtils.serviceUrl(ip(Inet4Address.class), 1234);
- assertThat(url).isNotNull();
- assertThat(url.getPort()).isEqualTo(1234);
- }
-
- @Test
- public void serviceUrl_ipv6() throws Exception {
- JMXServiceURL url = JmxUtils.serviceUrl(ip(Inet6Address.class), 1234);
- assertThat(url).isNotNull();
- assertThat(url.getPort()).isEqualTo(1234);
- }
-
- private static InetAddress ip(Class inetAddressClass) throws SocketException {
- Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
- while (ifaces.hasMoreElements()) {
- NetworkInterface iface = ifaces.nextElement();
- Enumeration<InetAddress> addresses = iface.getInetAddresses();
- while (addresses.hasMoreElements()) {
- InetAddress addr = addresses.nextElement();
- if (addr.getClass().isAssignableFrom(inetAddressClass)) {
- return addr;
- }
- }
- }
- throw new IllegalStateException("no ipv4 address");
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
deleted file mode 100644
index 6a8819c3a81..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/LoopbackAddressTest.java
+++ /dev/null
@@ -1,51 +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.process;
-
-import com.google.common.collect.Iterators;
-import org.junit.Test;
-
-import java.net.NetworkInterface;
-import java.util.Collections;
-import java.util.Enumeration;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class LoopbackAddressTest {
-
- @Test
- public void get() throws Exception {
- assertThat(LoopbackAddress.get()).isNotNull();
- assertThat(LoopbackAddress.get().isLoopbackAddress()).isTrue();
- assertThat(LoopbackAddress.get().getHostAddress()).isNotNull();
- }
-
- @Test
- public void fail_to_get_loopback_address() throws Exception {
- Enumeration<NetworkInterface> ifaces = Iterators.asEnumeration(Collections.<NetworkInterface>emptyList().iterator());
- try {
- LoopbackAddress.doGet(ifaces);
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Impossible to get a IPv4 loopback address");
- }
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java
deleted file mode 100644
index 83841c79952..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java
+++ /dev/null
@@ -1,102 +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.process;
-
-import org.fest.assertions.Assertions;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-
-import static org.fest.assertions.Fail.fail;
-
-public class MinimumViableSystemTest {
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- /**
- * Verifies that all checks can be verified without error.
- * Test environment does not necessarily follows all checks.
- */
- @Test
- public void check() throws Exception {
- MinimumViableSystem mve = new MinimumViableSystem();
-
- try {
- mve.check();
- // ok
- } catch (MessageException e) {
- // also ok. All other exceptions are errors.
- }
- }
-
- @Test
- public void checkJavaVersion() throws Exception {
- MinimumViableSystem mve = new MinimumViableSystem();
-
- // yes, sources are compiled with a supported Java version!
- mve.checkJavaVersion();
- mve.checkJavaVersion("1.6");
-
- try {
- mve.checkJavaVersion("1.9");
- fail();
- } catch (MessageException e) {
- Assertions.assertThat(e).hasMessage("Supported versions of Java are 1.6, 1.7 and 1.8. Got 1.9.");
- }
- }
-
- @Test
- public void checkJavaOption() throws Exception {
- String key = "MinimumViableEnvironmentTest.test.prop";
- MinimumViableSystem mve = new MinimumViableSystem()
- .setRequiredJavaOption(key, "true");
-
- try {
- System.setProperty(key, "false");
- mve.checkJavaOptions();
- fail();
- } catch (MessageException e) {
- Assertions.assertThat(e).hasMessage("JVM option '" + key + "' must be set to 'true'. Got 'false'");
- }
-
- System.setProperty(key, "true");
- mve.checkJavaOptions();
- // do not fail
- }
-
- @Test
- public void checkWritableTempDir() throws Exception {
- File dir = temp.newFolder();
- MinimumViableSystem mve = new MinimumViableSystem();
-
- mve.checkWritableDir(dir.getAbsolutePath());
-
- dir.delete();
- try {
- mve.checkWritableDir(dir.getAbsolutePath());
- fail();
- } catch (IllegalStateException e) {
- Assertions.assertThat(e).hasMessage("Temp directory is not writable: " + dir.getAbsolutePath());
- }
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MonitorTestBase.java b/server/process/sonar-process/src/test/java/org/sonar/process/MonitorTestBase.java
deleted file mode 100644
index fb9c818d017..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/MonitorTestBase.java
+++ /dev/null
@@ -1,78 +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.process;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class MonitorTestBase extends BaseProcessTest {
-
-
- Monitor monitor;
-
- @Before
- public void setUpMonitor() throws Exception {
- monitor = new Monitor();
- }
-
- @After
- public void downMonitor() throws Exception {
- if (monitor != null) {
- monitor.interrupt();
- monitor = null;
- }
- }
-
- @Test
- public void monitor_can_start_and_stop() {
- assertThat(monitor.isAlive()).isFalse();
- monitor.start();
- assertThat(monitor.isAlive()).isTrue();
- monitor.terminate();
- assertThat(monitor.isAlive()).isFalse();
- }
-
- @Test(timeout = 2500L)
- public void monitor_should_interrupt_process() throws Exception {
- // 0 start the dummyProcess
- ProcessWrapper process = new ProcessWrapper("DummyOkProcess")
- .addProperty(MonitoredProcess.NAME_PROPERTY, "DummyOkProcess")
- .addClasspath(dummyAppJar.getAbsolutePath())
- .setWorkDir(temp.getRoot())
- .setTempDirectory(temp.getRoot())
- .setJmxPort(freePort)
- .setClassName(DUMMY_OK_APP);
-
- assertThat(process.execute());
-
-
- // 1 start my monitor & register process
- monitor.start();
- monitor.monitor(process);
-
- // 2 terminate monitor, assert process is terminated
- monitor.terminate();
- assertThat(monitor.isAlive()).isFalse();
- assertThat(process.isAlive()).isFalse();
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java
deleted file mode 100644
index c753bd00422..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java
+++ /dev/null
@@ -1,185 +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.process;
-
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class MonitoredProcessTest {
-
- @Test
- public void fail_on_missing_name() throws Exception {
- Properties properties = new Properties();
-
- try {
- new DummyProcess(new Props(properties), true);
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage()).isEqualTo("Missing property: pName");
- }
-
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- DummyProcess dummyProcess = new DummyProcess(new Props(properties), true);
- assertThat(dummyProcess).isNotNull();
- }
-
- @Test
- public void should_not_monitor_debug() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- DummyProcess dummyProcess = new DummyProcess(new Props(properties), false);
-
- assertThat(dummyProcess.isMonitored()).isFalse();
- }
-
- @Test
- public void should_monitor_by_default() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- properties.setProperty("sonar.search.javaOpts", "hello world");
- DummyProcess dummyProcess = new DummyProcess(new Props(properties));
-
- assertThat(dummyProcess.isMonitored()).isTrue();
- }
-
- @Test(timeout = 3000L)
- public void monitor_dies_when_no_pings() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- final DummyProcess dummyProcess = new DummyProcess(new Props(properties), true);
- dummyProcess.setTimeout(1000L)
- .setCheckDelay(500L);
- Thread process = new Thread(new Runnable() {
- @Override
- public void run() {
- dummyProcess.start();
- }
- });
- assertProcessNotYetRunning(dummyProcess);
- process.start();
- Thread.sleep(100);
-
- assertProcessRunning(dummyProcess);
- assertJoinAndTerminate(dummyProcess, process);
- }
-
- @Test(timeout = 3000L)
- public void monitor_dies_after_stopping_to_ping() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- final DummyProcess dummyProcess = new DummyProcess(new Props(properties), true);
- dummyProcess.setTimeout(1000L)
- .setCheckDelay(500L);
- Thread process = new Thread(new Runnable() {
- @Override
- public void run() {
- dummyProcess.start();
- }
- });
- assertProcessNotYetRunning(dummyProcess);
- process.start();
- Thread.sleep(100);
-
- int count = 0;
- for (int i = 0; i < 3; i++) {
- dummyProcess.ping();
- assertProcessRunning(dummyProcess);
- Thread.sleep(300);
- count++;
- }
- assertThat(count).isEqualTo(3);
- assertJoinAndTerminate(dummyProcess, process);
- }
-
- @Test(timeout = 3000L)
- public void monitor_explicitly_shutdown() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
- final DummyProcess dummyProcess = new DummyProcess(new Props(properties), true);
- dummyProcess.setTimeout(Long.MAX_VALUE).setCheckDelay(500L);
- Thread process = new Thread(new Runnable() {
- @Override
- public void run() {
- dummyProcess.start();
- }
- });
- assertProcessNotYetRunning(dummyProcess);
- process.start();
- Thread.sleep(100);
- assertProcessRunning(dummyProcess);
- dummyProcess.terminate();
- Thread.sleep(100);
- assertProcessTerminated(dummyProcess);
- }
-
- @Test(timeout = 1000L)
- public void process_does_not_die_when_debugged() throws Exception {
- Properties properties = new Properties();
- properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
-
- final DummyProcess dummyProcess = new DummyProcess(new Props(properties), false);
- assertThat(dummyProcess.isMonitored()).isFalse();
-
- dummyProcess.setTimeout(100L).setCheckDelay(100L);
- Thread process = new Thread(new Runnable() {
- @Override
- public void run() {
- dummyProcess.start();
- }
- });
- process.start();
- Thread.sleep(600);
-
- assertProcessRunning(dummyProcess);
- dummyProcess.terminate();
- assertProcessTerminated(dummyProcess);
- }
-
- private void assertJoinAndTerminate(DummyProcess dummyProcess, Thread process) throws InterruptedException {
- process.join();
- assertProcessTerminated(dummyProcess);
- }
-
- private void assertProcessTerminated(DummyProcess dummyProcess) {
- assertThat(dummyProcess.isReady()).isTrue();
- assertThat(dummyProcess.isTerminated()).isTrue();
- assertProcessCreatedFile(dummyProcess);
- }
-
- private void assertProcessNotYetRunning(DummyProcess dummyProcess) {
- assertThat(dummyProcess.isReady()).isFalse();
- assertThat(dummyProcess.isTerminated()).isFalse();
- }
-
- private void assertProcessRunning(DummyProcess dummyProcess) throws InterruptedException {
- assertThat(dummyProcess.isReady()).isTrue();
- assertThat(dummyProcess.isTerminated()).isFalse();
- }
-
- private void assertProcessCreatedFile(DummyProcess dummyProcess) {
- assertThat(dummyProcess.getCheckFile()).isNotNull();
- assertThat(dummyProcess.getCheckFile().getName()).isEqualTo(DummyProcess.CHECKFILE_NAME);
- }
-
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
deleted file mode 100644
index 09f6a597209..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/NetworkUtilsTest.java
+++ /dev/null
@@ -1,61 +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.process;
-
-import org.junit.Test;
-
-import java.net.ServerSocket;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class NetworkUtilsTest {
-
-
- @Test
- public void find_free_port() throws Exception {
- int port = NetworkUtils.freePort();
- assertThat(port).isGreaterThan(1024);
- }
-
- @Test
- public void find_multiple_free_port() throws Exception {
- int port1 = NetworkUtils.freePort();
- int port2 = NetworkUtils.freePort();
-
- assertThat(port1).isGreaterThan(1024);
- assertThat(port2).isGreaterThan(1024);
-
- assertThat(port1).isNotSameAs(port2);
- }
-
- @Test
- public void find_multiple_free_non_adjacent_port() throws Exception {
- int port1 = NetworkUtils.freePort();
-
- ServerSocket socket = new ServerSocket(port1 + 1);
-
- int port2 = NetworkUtils.freePort();
-
- assertThat(port1).isGreaterThan(1024);
- assertThat(port2).isGreaterThan(1024);
-
- assertThat(port1).isNotSameAs(port2);
- }
-} \ No newline at end of file
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
deleted file mode 100644
index e508f5a57f9..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/ProcessUtilsTest.java
+++ /dev/null
@@ -1,32 +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.process;
-
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ProcessUtilsTest {
-
- @Test
- public void isJvmDebugEnabled() {
- assertThat(ProcessUtils.isJvmDebugEnabled()).isFalse();
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/PropsTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/PropsTest.java
deleted file mode 100644
index 6985b0ba086..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process/PropsTest.java
+++ /dev/null
@@ -1,137 +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.process;
-
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class PropsTest {
-
- @Test
- public void value() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "bar");
- Props props = new Props(p);
-
- assertThat(props.value("foo")).isEqualTo("bar");
- assertThat(props.value("foo", "default value")).isEqualTo("bar");
- assertThat(props.value("unknown")).isNull();
- assertThat(props.value("unknown", "default value")).isEqualTo("default value");
- }
-
- @Test
- public void valueAsInt() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "33");
- p.setProperty("blank", "");
- Props props = new Props(p);
-
- assertThat(props.valueAsInt("foo")).isEqualTo(33);
- assertThat(props.valueAsInt("foo", 44)).isEqualTo(33);
- assertThat(props.valueAsInt("blank")).isNull();
- assertThat(props.valueAsInt("blank", 55)).isEqualTo(55);
- assertThat(props.valueAsInt("unknown")).isNull();
- assertThat(props.valueAsInt("unknown", 44)).isEqualTo(44);
- }
-
- @Test
- public void valueAsInt_not_integer() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "bar");
- Props props = new Props(p);
-
- try {
- props.valueAsInt("foo");
- fail();
- } catch (IllegalStateException e) {
- assertThat(e).hasMessage("Value of property foo is not an integer: bar");
- }
- }
-
- @Test
- public void valueAsBoolean() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "True");
- p.setProperty("bar", "false");
- Props props = new Props(p);
-
- assertThat(props.valueAsBoolean("foo")).isTrue();
- assertThat(props.valueAsBoolean("bar")).isFalse();
- assertThat(props.valueAsBoolean("unknown")).isFalse();
- }
-
- @Test
- public void valueAsBoolean_default_value() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "true");
- p.setProperty("bar", "false");
- Props props = new Props(p);
-
- assertThat(props.valueAsBoolean("unset", false)).isFalse();
- assertThat(props.valueAsBoolean("unset", true)).isTrue();
- assertThat(props.valueAsBoolean("foo", false)).isTrue();
- assertThat(props.valueAsBoolean("bar", true)).isFalse();
- }
-
- @Test
- public void setDefault() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "foo_value");
- Props props = new Props(p);
- props.setDefault("foo", "foo_def");
- props.setDefault("bar", "bar_def");
-
- assertThat(props.value("foo")).isEqualTo("foo_value");
- assertThat(props.value("bar")).isEqualTo("bar_def");
- assertThat(props.value("other")).isNull();
- }
-
- @Test
- public void set() throws Exception {
- Properties p = new Properties();
- p.setProperty("foo", "old_foo");
- Props props = new Props(p);
- props.set("foo", "new_foo");
- props.set("bar", "new_bar");
- props.set("null", null);
-
- assertThat(props.value("foo")).isEqualTo("new_foo");
- assertThat(props.value("bar")).isEqualTo("new_bar");
- assertThat(props.value("null")).isNull();
- }
-
- @Test
- public void raw_properties() throws Exception {
- Properties p = new Properties();
- p.setProperty("encrypted_prop", "{aes}abcde");
- p.setProperty("clear_prop", "foo");
- Props props = new Props(p);
-
- assertThat(props.rawProperties()).hasSize(2);
- // do not decrypt
- assertThat(props.rawProperties().get("encrypted_prop")).isEqualTo("{aes}abcde");
- assertThat(props.rawProperties().get("clear_prop")).isEqualTo("foo");
-
- }
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process2/MonitorTest.java b/server/process/sonar-process/src/test/java/org/sonar/process2/MonitorTest.java
deleted file mode 100644
index baaed0fe374..00000000000
--- a/server/process/sonar-process/src/test/java/org/sonar/process2/MonitorTest.java
+++ /dev/null
@@ -1,23 +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.process2;
-
-public class MonitorTest {
-}
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/aes_secret_key.txt b/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/aes_secret_key.txt
deleted file mode 100644
index 65b98c522da..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/aes_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-0PZz+G+f8mjr3sPn4+AhHg== \ No newline at end of file
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/bad_secret_key.txt b/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/bad_secret_key.txt
deleted file mode 100644
index b33e179e5c8..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/bad_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-badbadbad== \ No newline at end of file
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/non_trimmed_secret_key.txt b/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/non_trimmed_secret_key.txt
deleted file mode 100644
index ab83e4adc03..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/non_trimmed_secret_key.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-
- 0PZz+G+f8mjr3sPn4+AhHg==
-
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/other_secret_key.txt b/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/other_secret_key.txt
deleted file mode 100644
index 23f5ecf5104..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/AesCipherTest/other_secret_key.txt
+++ /dev/null
@@ -1 +0,0 @@
-IBxEUxZ41c8XTxyaah1Qlg== \ No newline at end of file
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/LoggingTest/logback-access.xml b/server/process/sonar-process/src/test/resources/org/sonar/process/LoggingTest/logback-access.xml
deleted file mode 100644
index 298193e01fa..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/LoggingTest/logback-access.xml
+++ /dev/null
@@ -1 +0,0 @@
-<configuration/>
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/ProcessTest/sonar.properties b/server/process/sonar-process/src/test/resources/org/sonar/process/ProcessTest/sonar.properties
deleted file mode 100644
index 1577a214b3b..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/ProcessTest/sonar.properties
+++ /dev/null
@@ -1,212 +0,0 @@
-# This file must contain only ISO 8859-1 characters
-# see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)
-#
-# To use an environment variable, use the following syntax : ${env:NAME_OF_ENV_VARIABLE}
-# For example:
-# sonar.jdbc.url= ${env:SONAR_JDBC_URL}
-#
-#
-# See also the file conf/wrapper.conf for JVM advanced settings
-
-
-
-#--------------------------------------------------------------------------------------------------
-# DATABASE
-#
-# IMPORTANT: the embedded H2 database is used by default. It is recommended for tests only.
-# Please use a production-ready database. Supported databases are MySQL, Oracle, PostgreSQL
-# and Microsoft SQLServer.
-
-# Permissions to create tables, indices and triggers must be granted to JDBC user.
-# The schema must be created first.
-sonar.jdbc.username=sonar
-sonar.jdbc.password=sonar
-
-#----- Embedded database H2
-# Note: it does not accept connections from remote hosts, so the
-# SonarQube server and the maven plugin must be executed on the same host.
-
-# Comment the following line to deactivate the default embedded database.
-sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar
-
-# directory containing H2 database files. By default it's the /data directory in the SonarQube installation.
-#sonar.embeddedDatabase.dataDir=
-# H2 embedded database server listening port, defaults to 9092
-#sonar.embeddedDatabase.port=9092
-
-
-#----- MySQL 5.x
-# Comment the embedded database and uncomment the following line to use MySQL
-#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
-
-
-#----- Oracle 10g/11g
-# To connect to Oracle database:
-#
-# - It's recommended to use the latest version of the JDBC driver (ojdbc6.jar).
-# Download it in http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
-# - Copy the driver to the directory extensions/jdbc-driver/oracle/
-# - If you need to set the schema, please refer to http://jira.codehaus.org/browse/SONAR-5000
-# - Comment the embedded database and uncomment the following line:
-#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
-
-
-#----- PostgreSQL 8.x/9.x
-# Comment the embedded database and uncomment the following property to use PostgreSQL.
-# If you don't use the schema named "public", please refer to http://jira.codehaus.org/browse/SONAR-5000
-#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
-
-
-#----- Microsoft SQLServer
-# The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net
-#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
-
-
-#----- Connection pool settings
-sonar.jdbc.maxActive=20
-sonar.jdbc.maxIdle=5
-sonar.jdbc.minIdle=2
-sonar.jdbc.maxWait=5000
-sonar.jdbc.minEvictableIdleTimeMillis=600000
-sonar.jdbc.timeBetweenEvictionRunsMillis=30000
-
-
-
-#--------------------------------------------------------------------------------------------------
-# WEB SERVER
-
-# Binding IP address. For servers with more than one IP address, this property specifies which
-# address will be used for listening on the specified ports.
-# By default, ports will be used on all IP addresses associated with the server.
-#sonar.web.host=0.0.0.0
-
-# Web context. When set, it must start with forward slash (for example /sonarqube).
-# The default value is root context (empty value).
-#sonar.web.context=
-
-# TCP port for incoming HTTP connections. Disabled when value is -1.
-#sonar.web.port=9000
-
-# TCP port for incoming HTTPS connections. Disabled when value is -1 (default).
-#sonar.web.https.port=-1
-
-# HTTPS - the alias used to for the server certificate in the keystore.
-# If not specified the first key read in the keystore is used.
-#sonar.web.https.keyAlias=
-
-# HTTPS - the password used to access the server certificate from the
-# specified keystore file. The default value is "changeit".
-#sonar.web.https.keyPass=changeit
-
-# HTTPS - the pathname of the keystore file where is stored the server certificate.
-# By default, the pathname is the file ".keystore" in the user home.
-# If keystoreType doesn't need a file use empty value.
-#sonar.web.https.keystoreFile=
-
-# HTTPS - the password used to access the specified keystore file. The default
-# value is the value of sonar.web.https.keyPass.
-#sonar.web.https.keystorePass=
-
-# HTTPS - the type of keystore file to be used for the server certificate.
-# The default value is JKS (Java KeyStore).
-#sonar.web.https.keystoreType=JKS
-
-# HTTPS - the name of the keystore provider to be used for the server certificate.
-# If not specified, the list of registered providers is traversed in preference order
-# and the first provider that supports the keystore type is used (see sonar.web.https.keystoreType).
-#sonar.web.https.keystoreProvider=
-
-# HTTPS - the pathname of the truststore file which contains trusted certificate authorities.
-# By default, this would be the cacerts file in your JRE.
-# If truststoreFile doesn't need a file use empty value.
-#sonar.web.https.truststoreFile=
-
-# HTTPS - the password used to access the specified truststore file.
-#sonar.web.https.truststorePass=
-
-# HTTPS - the type of truststore file to be used.
-# The default value is JKS (Java KeyStore).
-#sonar.web.https.truststoreType=JKS
-
-# HTTPS - the name of the truststore provider to be used for the server certificate.
-# If not specified, the list of registered providers is traversed in preference order
-# and the first provider that supports the truststore type is used (see sonar.web.https.truststoreType).
-#sonar.web.https.truststoreProvider=
-
-# HTTPS - whether to enable client certificate authentication.
-# The default is false (client certificates disabled).
-# Other possible values are 'want' (certificates will be requested, but not required),
-# and 'true' (certificates are required).
-#sonar.web.https.clientAuth=false
-
-# The maximum number of connections that the server will accept and process at any given time.
-# When this number has been reached, the server will not accept any more connections until
-# the number of connections falls below this value. The operating system may still accept connections
-# based on the sonar.web.connections.acceptCount property. The default value is 50 for each
-# enabled connector.
-#sonar.web.http.maxThreads=50
-#sonar.web.https.maxThreads=50
-
-# The minimum number of threads always kept running. The default value is 5 for each
-# enabled connector.
-#sonar.web.http.minThreads=5
-#sonar.web.https.minThreads=5
-
-# The maximum queue length for incoming connection requests when all possible request processing
-# threads are in use. Any requests received when the queue is full will be refused.
-# The default value is 25 for each enabled connector.
-#sonar.web.http.acceptCount=25
-#sonar.web.https.acceptCount=25
-
-# Access logs are generated in the file logs/access.log. This file is rolled over when it's 5Mb.
-# An archive of 3 files is kept in the same directory.
-# Access logs are enabled by default.
-#sonar.web.accessLogs.enable=true
-
-# TCP port for incoming AJP connections. Disabled when value is -1.
-# sonar.ajp.port=9009
-
-
-
-#--------------------------------------------------------------------------------------------------
-# UPDATE CENTER
-
-# The Update Center requires an internet connection to request http://update.sonarsource.org
-# It is enabled by default.
-#sonar.updatecenter.activate=true
-
-# HTTP proxy (default none)
-#http.proxyHost=
-#http.proxyPort=
-
-# NT domain name if NTLM proxy is used
-#http.auth.ntlm.domain=
-
-# SOCKS proxy (default none)
-#socksProxyHost=
-#socksProxyPort=
-
-# proxy authentication. The 2 following properties are used for HTTP and SOCKS proxies.
-#http.proxyUser=
-#http.proxyPassword=
-
-
-#--------------------------------------------------------------------------------------------------
-# NOTIFICATIONS
-
-# Delay in seconds between processing of notification queue. Default is 60.
-#sonar.notifications.delay=60
-
-
-#--------------------------------------------------------------------------------------------------
-# PROFILING
-# Level of information displayed in the logs: NONE (default), BASIC (functional information) and FULL (functional and technical details)
-#sonar.log.profilingLevel=NONE
-
-
-#--------------------------------------------------------------------------------------------------
-# DEVELOPMENT MODE
-# Only for debugging
-
-# Set to true to apply Ruby on Rails code changes on the fly
-#sonar.rails.dev=false
diff --git a/server/process/sonar-process/src/test/resources/org/sonar/process/PropsTest/sonar.properties b/server/process/sonar-process/src/test/resources/org/sonar/process/PropsTest/sonar.properties
deleted file mode 100644
index 5c06e58a32e..00000000000
--- a/server/process/sonar-process/src/test/resources/org/sonar/process/PropsTest/sonar.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-hello: world
-foo=bar
-java.io.tmpdir=/should/be/overridden
diff --git a/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar b/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar
deleted file mode 100644
index 6dfd458329a..00000000000
--- a/server/process/sonar-process/src/test/resources/sonar-dummy-app.jar
+++ /dev/null
Binary files differ