]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Aug 2014 16:28:55 +0000 (18:28 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Aug 2014 16:45:51 +0000 (18:45 +0200)
24 files changed:
server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
server/process/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java
server/process/sonar-process/src/main/java/org/sonar/process/Props.java
server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessTest.java [new file with mode: 0644]
server/process/sonar-process/src/test/java/org/sonar/process/BaseProcessWrapperTest.java [new file with mode: 0644]
server/process/sonar-process/src/test/java/org/sonar/process/ConfigurationUtilsTest.java
server/process/sonar-process/src/test/java/org/sonar/process/MonitorTest.java [deleted file]
server/process/sonar-process/src/test/java/org/sonar/process/MonitorTestBase.java [new file with mode: 0644]
server/process/sonar-process/src/test/java/org/sonar/process/MonitoredProcessTest.java
server/process/sonar-process/src/test/java/org/sonar/process/ProcessTest.java [deleted file]
server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java [deleted file]
server/process/sonar-process/src/test/java/org/sonar/process/PropsTest.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-server/src/main/java/org/sonar/server/app/Connectors.java
server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
server/sonar-server/src/main/java/org/sonar/server/app/Logging.java
server/sonar-server/src/main/java/org/sonar/server/app/Webapp.java
sonar-application/src/main/java/org/sonar/application/App.java
sonar-application/src/main/java/org/sonar/application/DefaultSettings.java
sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
sonar-application/src/main/java/org/sonar/application/PropsBuilder.java
sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java
sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java

index d9187c3e6d40d674a0b7492773cadf4ba82623b8..5f0c03bea7a95eb413944a7ba7d000f381ba0def 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.process;
 
-import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,7 +34,6 @@ public abstract class MonitoredProcess implements ProcessMXBean {
   private static final long AUTOKILL_TIMEOUT_MS = 30000L;
   private static final long AUTOKILL_CHECK_DELAY_MS = 2000L;
   public static final String NAME_PROPERTY = "pName";
-  public static final String MISSING_NAME_ARGUMENT = "Missing Name argument";
 
   private Long lastPing;
   private final String name;
@@ -56,12 +54,7 @@ public abstract class MonitoredProcess implements ProcessMXBean {
   protected MonitoredProcess(Props props, boolean monitor) {
     this.isMonitored = monitor;
     this.props = props;
-    this.name = props.of(NAME_PROPERTY);
-
-    // Testing required properties
-    if (StringUtils.isEmpty(name)) {
-      throw new IllegalStateException(MISSING_NAME_ARGUMENT);
-    }
+    this.name = props.nonNullValue(NAME_PROPERTY);
 
     JmxUtils.registerMBean(this, name);
     ProcessUtils.addSelfShutdownHook(this);
index 6b2e49e55fd4626dce434ef4e9a5bc37dbc41d41..dacddd91847109b5e14b18e33beb784b7e94dd07 100644 (file)
@@ -35,7 +35,7 @@ public class ProcessLogging {
       JoranConfigurator configurator = new JoranConfigurator();
       configurator.setContext(context);
       context.reset();
-      context.putProperty(PATH_LOGS_PROPERTY, props.of(PATH_LOGS_PROPERTY));
+      context.putProperty(PATH_LOGS_PROPERTY, props.nonNullValue(PATH_LOGS_PROPERTY));
       doConfigure(configurator, logbackXmlResource);
     } catch (JoranException ignored) {
       // StatusPrinter will handle this
index d6e2795a597120a6280ed587a1bab329391c36fe..b868702eafc22432cf15f7d76246a55a372cbf9c 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.io.File;
 import java.util.Properties;
 
@@ -41,7 +42,7 @@ public class Props {
   }
 
   @CheckForNull
-  public String of(String key) {
+  public String value(String key) {
     String value = properties.getProperty(key);
     if (value != null && encryption.isEncrypted(value)) {
       value = encryption.decrypt(value);
@@ -49,29 +50,41 @@ public class Props {
     return value;
   }
 
-  public String of(String key, @Nullable String defaultValue) {
-    String s = of(key);
+  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 booleanOf(String key) {
-    String s = of(key);
+  public boolean valueAsBoolean(String key) {
+    String s = value(key);
     return s != null && Boolean.parseBoolean(s);
   }
 
-  public boolean booleanOf(String key, boolean defaultValue) {
-    String s = of(key);
+  public boolean valueAsBoolean(String key, boolean defaultValue) {
+    String s = value(key);
     return s != null ? Boolean.parseBoolean(s) : defaultValue;
   }
 
-  @CheckForNull
-  public File fileOf(String key) {
-    String s = of(key);
-    return s != null ? new File(s) : null;
+  public File nonNullValueAsFile(String key) {
+    String s = value(key);
+    if (s == null) {
+      throw new IllegalArgumentException("Property " + key + " is missing");
+    }
+    return new File(s);
   }
 
-  public Integer intOf(String key) {
-    String s = of(key);
+  @CheckForNull
+  public Integer valueAsInt(String key) {
+    String s = value(key);
     if (s != null && !"".equals(s)) {
       try {
         return Integer.parseInt(s);
@@ -82,8 +95,8 @@ public class Props {
     return null;
   }
 
-  public int intOf(String key, int defaultValue) {
-    Integer i = intOf(key);
+  public int valueAsInt(String key, int defaultValue) {
+    Integer i = valueAsInt(key);
     return i == null ? defaultValue : i;
   }
 
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
new file mode 100644 (file)
index 0000000..2045cd4
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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
new file mode 100644 (file)
index 0000000..b217edb
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * 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);
+  }
+}
index 405856429546eec4bfa6cac176d5fdf545d6a0b4..de928b9385077b92e507f4832b16bb98e5989275 100644 (file)
@@ -76,7 +76,7 @@ public class ConfigurationUtilsTest {
     FileUtils.write(propsFile, "foo=bar");
 
     Props result = ConfigurationUtils.loadPropsFromCommandLineArgs(new String[] {propsFile.getAbsolutePath()});
-    assertThat(result.of("foo")).isEqualTo("bar");
+    assertThat(result.value("foo")).isEqualTo("bar");
     assertThat(result.rawProperties()).hasSize(1);
   }
 
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/MonitorTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/MonitorTest.java
deleted file mode 100644 (file)
index e10a158..0000000
+++ /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 MonitorTest extends ProcessTest {
-
-
-  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.registerProcess(process);
-
-    // 2 terminate monitor, assert process is terminated
-    monitor.terminate();
-    assertThat(monitor.isAlive()).isFalse();
-    assertThat(process.isAlive()).isFalse();
-  }
-}
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..0980251
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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.registerProcess(process);
+
+    // 2 terminate monitor, assert process is terminated
+    monitor.terminate();
+    assertThat(monitor.isAlive()).isFalse();
+    assertThat(process.isAlive()).isFalse();
+  }
+}
index ef0379925c8ff36000e7ec74c0d02274dc70cb0c..c753bd00422372a5acf3acffd8de6c4b30c7e03e 100644 (file)
@@ -35,8 +35,8 @@ public class MonitoredProcessTest {
     try {
       new DummyProcess(new Props(properties), true);
       fail();
-    } catch (Exception e) {
-      assertThat(e.getMessage()).isEqualTo("Missing Name argument");
+    } catch (IllegalArgumentException e) {
+      assertThat(e.getMessage()).isEqualTo("Missing property: pName");
     }
 
     properties.setProperty(MonitoredProcess.NAME_PROPERTY, DummyProcess.NAME);
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/ProcessTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessTest.java
deleted file mode 100644 (file)
index f8b9430..0000000
+++ /dev/null
@@ -1,60 +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 ProcessTest {
-
-  @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) {
-      proc.destroy();
-    }
-  }
-
-}
diff --git a/server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java b/server/process/sonar-process/src/test/java/org/sonar/process/ProcessWrapperTest.java
deleted file mode 100644 (file)
index 2a7f10c..0000000
+++ /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 ProcessWrapperTest extends ProcessTest {
-
-  @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.fileOf("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);
-  }
-}
\ No newline at end of file
index 2af69ef1ca09c047f5de74c89c0c2d66baf38af5..5d283b44f8f63bdf06d2af89ffc2b9049af14b73 100644 (file)
@@ -34,10 +34,10 @@ public class PropsTest {
     p.setProperty("foo", "bar");
     Props props = new Props(p);
 
-    assertThat(props.of("foo")).isEqualTo("bar");
-    assertThat(props.of("foo", "default value")).isEqualTo("bar");
-    assertThat(props.of("unknown")).isNull();
-    assertThat(props.of("unknown", "default value")).isEqualTo("default value");
+    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
@@ -47,12 +47,12 @@ public class PropsTest {
     p.setProperty("blank", "");
     Props props = new Props(p);
 
-    assertThat(props.intOf("foo")).isEqualTo(33);
-    assertThat(props.intOf("foo", 44)).isEqualTo(33);
-    assertThat(props.intOf("blank")).isNull();
-    assertThat(props.intOf("blank", 55)).isEqualTo(55);
-    assertThat(props.intOf("unknown")).isNull();
-    assertThat(props.intOf("unknown", 44)).isEqualTo(44);
+    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
@@ -62,7 +62,7 @@ public class PropsTest {
     Props props = new Props(p);
 
     try {
-      props.intOf("foo");
+      props.valueAsInt("foo");
       fail();
     } catch (IllegalStateException e) {
       assertThat(e).hasMessage("Value of property foo is not an integer: bar");
@@ -76,9 +76,9 @@ public class PropsTest {
     p.setProperty("bar", "false");
     Props props = new Props(p);
 
-    assertThat(props.booleanOf("foo")).isTrue();
-    assertThat(props.booleanOf("bar")).isFalse();
-    assertThat(props.booleanOf("unknown")).isFalse();
+    assertThat(props.valueAsBoolean("foo")).isTrue();
+    assertThat(props.valueAsBoolean("bar")).isFalse();
+    assertThat(props.valueAsBoolean("unknown")).isFalse();
   }
 
   @Test
@@ -88,10 +88,10 @@ public class PropsTest {
     p.setProperty("bar", "false");
     Props props = new Props(p);
 
-    assertThat(props.booleanOf("unset", false)).isFalse();
-    assertThat(props.booleanOf("unset", true)).isTrue();
-    assertThat(props.booleanOf("foo", false)).isTrue();
-    assertThat(props.booleanOf("bar", true)).isFalse();
+    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
@@ -102,9 +102,9 @@ public class PropsTest {
     props.setDefault("foo", "foo_def");
     props.setDefault("bar", "bar_def");
 
-    assertThat(props.of("foo")).isEqualTo("foo_value");
-    assertThat(props.of("bar")).isEqualTo("bar_def");
-    assertThat(props.of("other")).isNull();
+    assertThat(props.value("foo")).isEqualTo("foo_value");
+    assertThat(props.value("bar")).isEqualTo("bar_def");
+    assertThat(props.value("other")).isNull();
   }
 
   @Test
@@ -115,8 +115,8 @@ public class PropsTest {
     props.set("foo", "new_foo");
     props.set("bar", "new_bar");
 
-    assertThat(props.of("foo")).isEqualTo("new_foo");
-    assertThat(props.of("bar")).isEqualTo("new_bar");
+    assertThat(props.value("foo")).isEqualTo("new_foo");
+    assertThat(props.value("bar")).isEqualTo("new_bar");
   }
 
   @Test
index 873e8b95ab057f9e1ecbbfd1d275d0362d144fb5..6988264f15f216bab40e9e1b92ecf0fce0242fbb 100644 (file)
@@ -66,7 +66,7 @@ public class SearchServer extends MonitoredProcess {
     this.isBlocking = blocking;
     new MinimumViableSystem().check();
 
-    String esNodesInets = props.of(ES_CLUSTER_INET);
+    String esNodesInets = props.value(ES_CLUSTER_INET);
     if (StringUtils.isNotEmpty(esNodesInets)) {
       Collections.addAll(nodes, esNodesInets.split(","));
     }
@@ -77,7 +77,7 @@ public class SearchServer extends MonitoredProcess {
     this.isBlocking = true;
     new MinimumViableSystem().check();
 
-    String esNodesInets = props.of(ES_CLUSTER_INET);
+    String esNodesInets = props.value(ES_CLUSTER_INET);
     if (StringUtils.isNotEmpty(esNodesInets)) {
       Collections.addAll(nodes, esNodesInets.split(","));
     }
@@ -94,9 +94,8 @@ public class SearchServer extends MonitoredProcess {
 
   @Override
   protected void doStart() {
-
-    Integer port = props.intOf(ES_PORT_PROPERTY);
-    String clusterName = props.of(ES_CLUSTER_PROPERTY);
+    Integer port = props.valueAsInt(ES_PORT_PROPERTY);
+    String clusterName = props.value(ES_CLUSTER_PROPERTY);
 
     LoggerFactory.getLogger(SearchServer.class).info("Starting ES[{}] on port: {}", clusterName, port);
 
@@ -105,7 +104,7 @@ public class SearchServer extends MonitoredProcess {
       // Disable MCast
       .put("discovery.zen.ping.multicast.enabled", "false")
 
-        // Index storage policies
+      // Index storage policies
       .put("index.merge.policy.max_merge_at_once", "200")
       .put("index.merge.policy.segments_per_tier", "200")
       .put("index.number_of_shards", "1")
@@ -114,15 +113,15 @@ public class SearchServer extends MonitoredProcess {
       .put("indices.store.throttle.type", "merge")
       .put("indices.store.throttle.max_bytes_per_sec", "200mb")
 
-        // Install our own listUpdate scripts
+      // Install our own listUpdate scripts
       .put("script.default_lang", "native")
       .put("script.native." + ListUpdate.NAME + ".type", ListUpdate.UpdateListScriptFactory.class.getName())
 
-        // Node is pure transport
+      // Node is pure transport
       .put("transport.tcp.port", port)
       .put("http.enabled", false)
 
-        // Setting up ES paths
+      // Setting up ES paths
       .put("path.data", esDataDir().getAbsolutePath())
       .put("path.work", esWorkDir().getAbsolutePath())
       .put("path.logs", esLogDir().getAbsolutePath());
@@ -140,10 +139,10 @@ public class SearchServer extends MonitoredProcess {
 
     // Set cluster coordinates
     esSettings.put("cluster.name", clusterName);
-    esSettings.put("node.rack_id", StringUtils.defaultIfEmpty(props.of(SONAR_NODE_NAME), "unknown"));
+    esSettings.put("node.rack_id", props.value(SONAR_NODE_NAME, "unknown"));
     esSettings.put("cluster.routing.allocation.awareness.attributes", "rack_id");
     if (props.contains(SONAR_NODE_NAME)) {
-      esSettings.put("node.name", props.of(SONAR_NODE_NAME));
+      esSettings.put("node.name", props.value(SONAR_NODE_NAME));
     } else {
       try {
         esSettings.put("node.name", InetAddress.getLocalHost().getHostName());
@@ -184,40 +183,40 @@ public class SearchServer extends MonitoredProcess {
       // Disallow dynamic mapping (too expensive)
       .put("index.mapper.dynamic", false)
 
-        // Sortable text analyzer
+      // Sortable text analyzer
       .put("index.analysis.analyzer.sortable.type", "custom")
       .put("index.analysis.analyzer.sortable.tokenizer", "keyword")
       .putArray("index.analysis.analyzer.sortable.filter", "trim", "lowercase", "truncate")
 
-        // Edge NGram index-analyzer
+      // Edge NGram index-analyzer
       .put("index.analysis.analyzer.index_grams.type", "custom")
       .put("index.analysis.analyzer.index_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.index_grams.filter", "trim", "lowercase", "gram_filter")
 
-        // Edge NGram search-analyzer
+      // Edge NGram search-analyzer
       .put("index.analysis.analyzer.search_grams.type", "custom")
       .put("index.analysis.analyzer.search_grams.tokenizer", "whitespace")
       .putArray("index.analysis.analyzer.search_grams.filter", "trim", "lowercase")
 
-        // Word index-analyzer
+      // Word index-analyzer
       .put("index.analysis.analyzer.index_words.type", "custom")
       .put("index.analysis.analyzer.index_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.index_words.filter",
         "standard", "word_filter", "lowercase", "stop", "asciifolding", "porter_stem")
 
-        // Word search-analyzer
+      // Word search-analyzer
       .put("index.analysis.analyzer.search_words.type", "custom")
       .put("index.analysis.analyzer.search_words.tokenizer", "standard")
       .putArray("index.analysis.analyzer.search_words.filter",
         "standard", "lowercase", "stop", "asciifolding", "porter_stem")
 
-        // Edge NGram filter
+      // Edge NGram filter
       .put("index.analysis.filter.gram_filter.type", "edgeNGram")
       .put("index.analysis.filter.gram_filter.min_gram", 2)
       .put("index.analysis.filter.gram_filter.max_gram", 15)
       .putArray("index.analysis.filter.gram_filter.token_chars", "letter", "digit", "punctuation", "symbol")
 
-        // Word filter
+      // Word filter
       .put("index.analysis.filter.word_filter.type", "word_delimiter")
       .put("index.analysis.filter.word_filter.generate_word_parts", true)
       .put("index.analysis.filter.word_filter.catenate_words", true)
@@ -228,46 +227,38 @@ public class SearchServer extends MonitoredProcess {
       .put("index.analysis.filter.word_filter.split_on_numerics", true)
       .put("index.analysis.filter.word_filter.stem_english_possessive", true)
 
-        // Path Analyzer
+      // Path Analyzer
       .put("index.analysis.analyzer.path_analyzer.type", "custom")
       .put("index.analysis.analyzer.path_analyzer.tokenizer", "path_hierarchy");
 
   }
 
   private File esHomeDir() {
-    String homeDir = props.of(SONAR_PATH_HOME);
-    if (StringUtils.isEmpty(homeDir)) {
-      throw new IllegalStateException("property 'sonar.path.home' is required");
-    } else {
-      return new File(homeDir);
-    }
+    return props.nonNullValueAsFile(SONAR_PATH_HOME);
   }
 
   private File esDataDir() {
-    String dataDir = props.of(SONAR_PATH_DATA);
+    String dataDir = props.value(SONAR_PATH_DATA);
     if (StringUtils.isNotEmpty(dataDir)) {
       return new File(dataDir, "es");
-    } else {
-      return new File(esHomeDir(), "data/es");
     }
+    return new File(esHomeDir(), "data/es");
   }
 
   private File esLogDir() {
-    String logDir = props.of(SONAR_PATH_LOG);
+    String logDir = props.value(SONAR_PATH_LOG);
     if (StringUtils.isNotEmpty(logDir)) {
       return new File(logDir);
-    } else {
-      return new File(esHomeDir(), "log");
     }
+    return new File(esHomeDir(), "log");
   }
 
   private File esWorkDir() {
-    String workDir = props.of(SONAR_PATH_TEMP);
+    String workDir = props.value(SONAR_PATH_TEMP);
     if (StringUtils.isNotEmpty(workDir)) {
       return new File(workDir);
-    } else {
-      return new File(esHomeDir(), "temp");
     }
+    return new File(esHomeDir(), "temp");
   }
 
   @Override
index 13276f34dbf142ee1a5ee999cb02351e53479d01..340c3b3ccbf64ade80c804dd783bf10b974056ac 100644 (file)
@@ -70,7 +70,7 @@ class Connectors {
   private static Connector newHttpConnector(Props props) {
     Connector connector = null;
     // Not named "sonar.web.http.port" to keep backward-compatibility
-    int port = props.intOf("sonar.web.port", 9000);
+    int port = props.valueAsInt("sonar.web.port", 9000);
     if (port > DISABLED_PORT) {
       connector = newConnector(props, HTTP_PROTOCOL, "http");
       connector.setPort(port);
@@ -82,7 +82,7 @@ class Connectors {
   @Nullable
   private static Connector newAjpConnector(Props props) {
     Connector connector = null;
-    int port = props.intOf("sonar.ajp.port", DISABLED_PORT);
+    int port = props.valueAsInt("sonar.ajp.port", DISABLED_PORT);
     if (port > DISABLED_PORT) {
       connector = newConnector(props, AJP_PROTOCOL, "http");
       connector.setPort(port);
@@ -94,24 +94,24 @@ class Connectors {
   @Nullable
   private static Connector newHttpsConnector(Props props) {
     Connector connector = null;
-    int port = props.intOf("sonar.web.https.port", DISABLED_PORT);
+    int port = props.valueAsInt("sonar.web.https.port", DISABLED_PORT);
     if (port > DISABLED_PORT) {
       connector = newConnector(props, HTTP_PROTOCOL, "https");
       connector.setPort(port);
       connector.setSecure(true);
       connector.setScheme("https");
-      setConnectorAttribute(connector, "keyAlias", props.of("sonar.web.https.keyAlias"));
-      String keyPassword = props.of("sonar.web.https.keyPass", "changeit");
+      setConnectorAttribute(connector, "keyAlias", props.value("sonar.web.https.keyAlias"));
+      String keyPassword = props.value("sonar.web.https.keyPass", "changeit");
       setConnectorAttribute(connector, "keyPass", keyPassword);
-      setConnectorAttribute(connector, "keystorePass", props.of("sonar.web.https.keystorePass", keyPassword));
-      setConnectorAttribute(connector, "keystoreFile", props.of("sonar.web.https.keystoreFile"));
-      setConnectorAttribute(connector, "keystoreType", props.of("sonar.web.https.keystoreType", "JKS"));
-      setConnectorAttribute(connector, "keystoreProvider", props.of("sonar.web.https.keystoreProvider"));
-      setConnectorAttribute(connector, "truststorePass", props.of("sonar.web.https.truststorePass", "changeit"));
-      setConnectorAttribute(connector, "truststoreFile", props.of("sonar.web.https.truststoreFile"));
-      setConnectorAttribute(connector, "truststoreType", props.of("sonar.web.https.truststoreType", "JKS"));
-      setConnectorAttribute(connector, "truststoreProvider", props.of("sonar.web.https.truststoreProvider"));
-      setConnectorAttribute(connector, "clientAuth", props.of("sonar.web.https.clientAuth", "false"));
+      setConnectorAttribute(connector, "keystorePass", props.value("sonar.web.https.keystorePass", keyPassword));
+      setConnectorAttribute(connector, "keystoreFile", props.value("sonar.web.https.keystoreFile"));
+      setConnectorAttribute(connector, "keystoreType", props.value("sonar.web.https.keystoreType", "JKS"));
+      setConnectorAttribute(connector, "keystoreProvider", props.value("sonar.web.https.keystoreProvider"));
+      setConnectorAttribute(connector, "truststorePass", props.value("sonar.web.https.truststorePass", "changeit"));
+      setConnectorAttribute(connector, "truststoreFile", props.value("sonar.web.https.truststoreFile"));
+      setConnectorAttribute(connector, "truststoreType", props.value("sonar.web.https.truststoreType", "JKS"));
+      setConnectorAttribute(connector, "truststoreProvider", props.value("sonar.web.https.truststoreProvider"));
+      setConnectorAttribute(connector, "clientAuth", props.value("sonar.web.https.clientAuth", "false"));
       setConnectorAttribute(connector, "sslProtocol", "TLS");
       setConnectorAttribute(connector, "SSLEnabled", true);
       info("HTTPS connector is enabled on port " + port);
@@ -122,7 +122,7 @@ class Connectors {
   private static Connector newConnector(Props props, String protocol, String scheme) {
     Connector connector = new Connector(protocol);
     connector.setURIEncoding("UTF-8");
-    connector.setProperty("address", props.of("sonar.web.host", "0.0.0.0"));
+    connector.setProperty("address", props.value("sonar.web.host", "0.0.0.0"));
     configurePool(props, connector, scheme);
     configureCompression(connector);
     return connector;
@@ -130,9 +130,9 @@ class Connectors {
 
   private static void configurePool(Props props, Connector connector, String scheme) {
     connector.setProperty("acceptorThreadCount", String.valueOf(2));
-    connector.setProperty("minSpareThreads", String.valueOf(props.intOf("sonar.web." + scheme + ".minThreads", 5)));
-    connector.setProperty("maxThreads", String.valueOf(props.intOf("sonar.web." + scheme + ".maxThreads", 50)));
-    connector.setProperty("acceptCount", String.valueOf(props.intOf("sonar.web." + scheme + ".acceptCount", 25)));
+    connector.setProperty("minSpareThreads", String.valueOf(props.valueAsInt("sonar.web." + scheme + ".minThreads", 5)));
+    connector.setProperty("maxThreads", String.valueOf(props.valueAsInt("sonar.web." + scheme + ".maxThreads", 50)));
+    connector.setProperty("acceptCount", String.valueOf(props.valueAsInt("sonar.web." + scheme + ".acceptCount", 25)));
   }
 
   private static void configureCompression(Connector connector) {
index f86e5cc369d3b672a9b6c0134090e3aff1f373f0..8a80a6c05ec439a973e07910cf37a267bd8b0dfa 100644 (file)
@@ -80,7 +80,7 @@ class EmbeddedTomcat implements Terminable {
   }
 
   private File tomcatBasedir() {
-    return new File(props.of("sonar.path.temp"), "tc");
+    return new File(props.value("sonar.path.temp"), "tc");
   }
 
   boolean isReady() {
index 0610bcdd7ed1d5d01f92ba8ceb39961fbc7e133e..777a06883cb551c4dc1f4a64687e4972f4087318 100644 (file)
@@ -66,11 +66,11 @@ class Logging {
    * Configure Logback from classpath, with configuration from sonar.properties
    */
   private static void configureLogback(Props props) {
-    String configProfilingLevel = props.of(Profiling.CONFIG_PROFILING_LEVEL, "NONE");
+    String configProfilingLevel = props.value(Profiling.CONFIG_PROFILING_LEVEL, "NONE");
     Profiling.Level profilingLevel = Profiling.Level.fromConfigString(configProfilingLevel);
-    String consoleEnabled = props.of(CONFIG_LOG_CONSOLE, "false");
+    String consoleEnabled = props.value(CONFIG_LOG_CONSOLE, "false");
     Map<String, String> variables = ImmutableMap.of(
-      "sonar.path.logs", props.of("sonar.path.logs"),
+      "sonar.path.logs", props.nonNullValue("sonar.path.logs"),
       "LOGFILE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT,
       "CONSOLE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? CONSOLE_FULL_LOGGING_FORMAT : CONSOLE_STANDARD_LOGGING_FORMAT,
       "CONSOLE_ENABLED", consoleEnabled);
@@ -84,10 +84,10 @@ class Logging {
   }
 
   private static void configureLogbackAccess(Tomcat tomcat, Props props) {
-    if (props.booleanOf(PROPERTY_ENABLE_ACCESS_LOGS, true)) {
+    if (props.valueAsBoolean(PROPERTY_ENABLE_ACCESS_LOGS, true)) {
       LogbackValve valve = new LogbackValve();
       valve.setQuiet(true);
-      valve.setFilename(new File(props.of("sonar.path.web"), ACCESS_RELATIVE_PATH).getAbsolutePath());
+      valve.setFilename(new File(props.nonNullValue("sonar.path.web"), ACCESS_RELATIVE_PATH).getAbsolutePath());
       tomcat.getHost().getPipeline().addValve(valve);
     }
   }
index 45b5be863a886f5dbd17988e37462c454af15b1e..006bbafd237ed5ed31204db3849b0189513bc3a0 100644 (file)
@@ -70,7 +70,7 @@ class Webapp {
   }
 
   static String getContextPath(Props props) {
-    String context = props.of(PROPERTY_CONTEXT, "");
+    String context = props.value(PROPERTY_CONTEXT, "");
     if ("/".equals(context)) {
       context = "";
     } else if (!"".equals(context) && !context.startsWith("/")) {
@@ -81,10 +81,10 @@ class Webapp {
 
   static void configureRails(Props props, Context context) {
     // sonar.dev is kept for backward-compatibility
-    if (props.booleanOf("sonar.dev", false)) {
+    if (props.valueAsBoolean("sonar.dev", false)) {
       props.set("sonar.web.dev", "true");
     }
-    if (props.booleanOf("sonar.web.dev", false)) {
+    if (props.valueAsBoolean("sonar.web.dev", false)) {
       context.addParameter(RAILS_ENV, "development");
       context.addParameter(JRUBY_MAX_RUNTIMES, "3");
       LoggerFactory.getLogger(Webapp.class).warn("WEB DEVELOPMENT MODE IS ENABLED - DO NOT USE FOR PRODUCTION USAGE");
@@ -95,9 +95,9 @@ class Webapp {
   }
 
   static String webappPath(Props props) {
-    String webDir = props.of("sonar.web.dev.sources");
+    String webDir = props.value("sonar.web.dev.sources");
     if (StringUtils.isEmpty(webDir)) {
-      webDir = new File(props.of("sonar.path.home"), "web").getAbsolutePath();
+      webDir = new File(props.value("sonar.path.home"), "web").getAbsolutePath();
     }
     LoggerFactory.getLogger(Webapp.class).info(String.format("Webapp directory: %s", webDir));
     return webDir;
index 43c192bf7165983cc2796941fa5c4d8adc2146be..784d75ef299e8ce7cfd0d24eeb6a6dc8b30fdb29 100644 (file)
@@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory;
 import org.sonar.process.JmxUtils;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.Monitor;
-import org.sonar.process.MonitoredProcess;
 import org.sonar.process.ProcessLogging;
 import org.sonar.process.ProcessMXBean;
 import org.sonar.process.ProcessUtils;
@@ -35,8 +34,6 @@ import org.sonar.process.Props;
 import org.sonar.search.SearchServer;
 
 import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.Properties;
 
 /**
@@ -60,13 +57,13 @@ public class App implements ProcessMXBean {
 
       monitor.start();
 
-      File homeDir = props.fileOf("sonar.path.home");
-      File tempDir = props.fileOf("sonar.path.temp");
+      File homeDir = props.nonNullValueAsFile("sonar.path.home");
+      File tempDir = props.nonNullValueAsFile("sonar.path.temp");
       elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME);
       elasticsearch
         .setWorkDir(homeDir)
-        .setJmxPort(props.intOf(DefaultSettings.SEARCH_JMX_PORT))
-        .addJavaOpts(props.of(DefaultSettings.SEARCH_JAVA_OPTS))
+        .setJmxPort(props.valueAsInt(DefaultSettings.SEARCH_JMX_PORT))
+        .addJavaOpts(props.value(DefaultSettings.SEARCH_JAVA_OPTS))
         .setTempDirectory(tempDir.getAbsoluteFile())
         .setClassName("org.sonar.search.SearchServer")
         .addProperties(props.rawProperties())
@@ -78,19 +75,19 @@ public class App implements ProcessMXBean {
           logger.info("search server is up");
 
           // do not yet start SQ in cluster mode. See SONAR-5483 & SONAR-5391
-          if (StringUtils.isEmpty(props.of(DefaultSettings.CLUSTER_MASTER, null))) {
+          if (StringUtils.isEmpty(props.value(DefaultSettings.CLUSTER_MASTER))) {
             server = new ProcessWrapper(JmxUtils.WEB_SERVER_NAME)
               .setWorkDir(homeDir)
-              .setJmxPort(props.intOf(DefaultSettings.WEB_JMX_PORT))
-              .addJavaOpts(props.of(DefaultSettings.WEB_JAVA_OPTS))
+              .setJmxPort(props.valueAsInt(DefaultSettings.WEB_JMX_PORT))
+              .addJavaOpts(props.nonNullValue(DefaultSettings.WEB_JAVA_OPTS))
               .setTempDirectory(tempDir.getAbsoluteFile())
-                // required for logback tomcat valve
-              .setLogDir(props.fileOf("sonar.path.logs"))
+              // required for logback tomcat valve
+              .setLogDir(props.nonNullValueAsFile("sonar.path.logs"))
               .setClassName("org.sonar.server.app.WebServer")
               .addProperties(props.rawProperties())
               .addClasspath("./lib/common/*")
               .addClasspath("./lib/server/*");
-            String driverPath = props.of(JdbcSettings.PROPERTY_DRIVER_PATH);
+            String driverPath = props.value(JdbcSettings.PROPERTY_DRIVER_PATH);
             if (driverPath != null) {
               server.addClasspath(driverPath);
             }
@@ -150,27 +147,23 @@ public class App implements ProcessMXBean {
   }
 
   public static void main(String[] args) {
-
     new MinimumViableSystem().check();
     CommandLineParser cli = new CommandLineParser();
     Properties rawProperties = cli.parseArguments(args);
-    Props props = null;
+    Props props;
 
     try {
       props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
       new ProcessLogging().configure(props, "/org/sonar/application/logback.xml");
-    } catch (IOException e) {
-      throw new IllegalStateException(e.getMessage());
-    } catch (URISyntaxException e) {
-      throw new IllegalStateException(e.getMessage());
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
     }
 
     App app = new App();
-
     try {
       // start and wait for shutdown command
       if (props.contains(SearchServer.ES_CLUSTER_INET)) {
-        LoggerFactory.getLogger(App.class).info("SonarQube slave configured to join SonarQube master : {}", props.of(SearchServer.ES_CLUSTER_INET));
+        LoggerFactory.getLogger(App.class).info("SonarQube slave configured to join SonarQube master : {}", props.value(SearchServer.ES_CLUSTER_INET));
       }
       app.start(props);
     } catch (InterruptedException e) {
index e6d737487ac1da5db51229471187ea19b0323a40..0a85182cc21efe1ad517b6aebef338f48024cf82 100644 (file)
@@ -55,7 +55,7 @@ class DefaultSettings {
     // init ports
     for (Map.Entry<String, Integer> entry : defaultPorts().entrySet()) {
       String key = entry.getKey();
-      int port = props.intOf(key, -1);
+      int port = props.valueAsInt(key, -1);
       if (port == -1) {
         // default port
         props.set(key, String.valueOf((int) entry.getValue()));
index 300de2421dde61e9ded027a26d8e37b234dbf350..ff88ae0f9c0b2579ed2be89c6654ac05e766f6f7 100644 (file)
@@ -50,7 +50,7 @@ public class JdbcSettings {
   }
 
   public void checkAndComplete(File homeDir, Props props) {
-    String url = props.of(DefaultSettings.JDBC_URL);
+    String url = props.value(DefaultSettings.JDBC_URL);
     Provider provider = driverProvider(url);
     checkUrlParameters(provider, url);
     String driverPath = driverPath(homeDir, provider);
index 0793a314163c2a4a16555bffbc605b1c4d558150..f736658db7b28d85d006f9fbb4f62e853cf96fba 100644 (file)
@@ -111,7 +111,7 @@ class PropsBuilder {
   }
 
   private File configureDir(Props props, String propKey, String defaultRelativePath) {
-    String path = props.of(propKey, defaultRelativePath);
+    String path = props.value(propKey, defaultRelativePath);
     File d = new File(path);
     if (!d.isAbsolute()) {
       d = new File(homeDir, path);
index 15892f29942e80d23ddf0f74e9e49d95b8ee8e7f..16a9cc9f1f89b0694ba92ae7a1012b502ece95e0 100644 (file)
@@ -33,10 +33,10 @@ public class DefaultSettingsTest {
     Props props = new Props(new Properties());
     DefaultSettings.init(props);
 
-    assertThat(props.of("sonar.search.javaOpts")).contains("-Xmx");
-    assertThat(props.intOf("sonar.web.jmxPort")).isEqualTo(9003);
-    assertThat(props.intOf("sonar.search.jmxPort")).isEqualTo(9002);
-    assertThat(props.of("sonar.jdbc.username")).isEqualTo("sonar");
+    assertThat(props.value("sonar.search.javaOpts")).contains("-Xmx");
+    assertThat(props.valueAsInt("sonar.web.jmxPort")).isEqualTo(9003);
+    assertThat(props.valueAsInt("sonar.search.jmxPort")).isEqualTo(9002);
+    assertThat(props.value("sonar.jdbc.username")).isEqualTo("sonar");
   }
 
   @Test
@@ -46,7 +46,7 @@ public class DefaultSettingsTest {
     Props props = new Props(p);
     DefaultSettings.init(props);
 
-    assertThat(props.of("sonar.jdbc.username")).isEqualTo("angela");
+    assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
   }
 
   @Test
@@ -56,6 +56,6 @@ public class DefaultSettingsTest {
     Props props = new Props(p);
 
     DefaultSettings.init(props);
-    assertThat(props.intOf("sonar.web.jmxPort")).isGreaterThan(0);
+    assertThat(props.valueAsInt("sonar.web.jmxPort")).isGreaterThan(0);
   }
 }
index d7c44d3caf4aa0346acd414cef6b7b01ba855dca..ad603c4e45357e1382281296ae0870870d0ab84b 100644 (file)
@@ -89,7 +89,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:oracle:thin:@localhost/XE");
     settings.checkAndComplete(home, props);
-    assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
@@ -98,7 +98,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar");
     settings.checkAndComplete(home, props);
-    assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isNull();
+    assertThat(props.value(JdbcSettings.PROPERTY_DRIVER_PATH)).isNull();
   }
 
   @Test
@@ -110,7 +110,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
     settings.checkAndComplete(home, props);
-    assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
@@ -122,7 +122,7 @@ public class JdbcSettingsTest {
     Props props = new Props(new Properties());
     props.set("sonar.jdbc.url", "jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor");
     settings.checkAndComplete(home, props);
-    assertThat(props.fileOf(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
+    assertThat(props.nonNullValueAsFile(JdbcSettings.PROPERTY_DRIVER_PATH)).isEqualTo(driverFile);
   }
 
   @Test
index 0c89e72dd97714b3993e8f4dbe0411ab2b460cd8..be6387c212c2e83c42105337538960c11d79cee8 100644 (file)
@@ -60,20 +60,20 @@ public class PropsBuilderTest {
 
     Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
 
-    assertThat(props.fileOf("sonar.path.logs")).isEqualTo(logsDir);
-    assertThat(props.fileOf("sonar.path.home")).isEqualTo(homeDir);
+    assertThat(props.nonNullValueAsFile("sonar.path.logs")).isEqualTo(logsDir);
+    assertThat(props.nonNullValueAsFile("sonar.path.home")).isEqualTo(homeDir);
 
     // create <HOME>/temp
-    File tempDir = props.fileOf("sonar.path.temp");
+    File tempDir = props.nonNullValueAsFile("sonar.path.temp");
     assertThat(tempDir).isDirectory().exists();
     assertThat(tempDir.getName()).isEqualTo("temp");
     assertThat(tempDir.getParentFile()).isEqualTo(homeDir);
 
-    assertThat(props.of("foo")).isEqualTo("bar");
-    assertThat(props.of("unknown")).isNull();
+    assertThat(props.value("foo")).isEqualTo("bar");
+    assertThat(props.value("unknown")).isNull();
 
     // default properties
-    assertThat(props.intOf("sonar.search.port")).isEqualTo(9001);
+    assertThat(props.valueAsInt("sonar.search.port")).isEqualTo(9001);
   }
 
   @Test
@@ -113,8 +113,8 @@ public class PropsBuilderTest {
     rawProperties.setProperty("sonar.origin", "raw");
     Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
 
-    assertThat(props.of("sonar.jdbc.username")).isEqualTo("angela");
+    assertThat(props.value("sonar.jdbc.username")).isEqualTo("angela");
     // command-line arguments override sonar.properties file
-    assertThat(props.of("sonar.origin")).isEqualTo("raw");
+    assertThat(props.value("sonar.origin")).isEqualTo("raw");
   }
 }