aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-start
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-17 11:40:41 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-18 11:27:59 +0200
commitb4746359150e51cc9e8bfa2281739ae0fd614f93 (patch)
tree445ff32f3aa250357e69fa0de313fe97ac49ebec /sonar-start
parent85a1d650d2f671c8ff6397f36d47bca9d831305b (diff)
downloadsonarqube-b4746359150e51cc9e8bfa2281739ae0fd614f93.tar.gz
sonarqube-b4746359150e51cc9e8bfa2281739ae0fd614f93.zip
SONAR-4898 - Moved NetworkUtils to sonar-process
Diffstat (limited to 'sonar-start')
-rw-r--r--sonar-start/src/main/java/org/sonar/start/NetworkUtils.java43
-rw-r--r--sonar-start/src/test/java/org/sonar/start/NetworkUtilsTest.java61
2 files changed, 0 insertions, 104 deletions
diff --git a/sonar-start/src/main/java/org/sonar/start/NetworkUtils.java b/sonar-start/src/main/java/org/sonar/start/NetworkUtils.java
deleted file mode 100644
index e0c1caa5a46..00000000000
--- a/sonar-start/src/main/java/org/sonar/start/NetworkUtils.java
+++ /dev/null
@@ -1,43 +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.start;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-
-class NetworkUtils {
-
- static private int lastPort = -1;
-
- static int freePort() {
- try {
- ServerSocket s = new ServerSocket(lastPort + 1);
- int port = s.getLocalPort();
- s.close();
- return port;
- } catch (IOException e) {
- throw new IllegalStateException("Can not find an open network port", e);
- }
- }
-
- private static boolean isValidPort(int port) {
- return port > 1023;
- }
-}
diff --git a/sonar-start/src/test/java/org/sonar/start/NetworkUtilsTest.java b/sonar-start/src/test/java/org/sonar/start/NetworkUtilsTest.java
deleted file mode 100644
index 11cf6ee8267..00000000000
--- a/sonar-start/src/test/java/org/sonar/start/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.start;
-
-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