diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-11 01:18:48 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-11 01:18:48 +0200 |
commit | 46857ab0d1a26d3df99309c371b49def0d03e68c (patch) | |
tree | 4b596c330e4b436f57fd0986fb97c8ecc1c7f198 /sonar-start/src/main | |
parent | 3267bd73ae229bfb1c32791f6b3500dc52465b61 (diff) | |
download | sonarqube-46857ab0d1a26d3df99309c371b49def0d03e68c.tar.gz sonarqube-46857ab0d1a26d3df99309c371b49def0d03e68c.zip |
SONAR-4898 - Fixed free socket binding
Diffstat (limited to 'sonar-start/src/main')
-rw-r--r-- | sonar-start/src/main/java/org/sonar/start/NetworkUtils.java | 5 | ||||
-rw-r--r-- | sonar-start/src/main/java/org/sonar/start/StartServer.java | 5 |
2 files changed, 7 insertions, 3 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 index d9dd72e74b2..7876b8dddad 100644 --- a/sonar-start/src/main/java/org/sonar/start/NetworkUtils.java +++ b/sonar-start/src/main/java/org/sonar/start/NetworkUtils.java @@ -26,7 +26,10 @@ class NetworkUtils { static int freePort() { try { - return new ServerSocket(0).getLocalPort(); + 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/sonar-start/src/main/java/org/sonar/start/StartServer.java b/sonar-start/src/main/java/org/sonar/start/StartServer.java index 543a24b3387..3062343c563 100644 --- a/sonar-start/src/main/java/org/sonar/start/StartServer.java +++ b/sonar-start/src/main/java/org/sonar/start/StartServer.java @@ -25,10 +25,10 @@ import org.slf4j.LoggerFactory; import org.sonar.process.MonitorService; import org.sonar.process.ProcessWrapper; +import java.io.File; import java.io.IOException; import java.net.DatagramSocket; import java.net.URISyntaxException; -import java.nio.file.Paths; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -96,6 +96,7 @@ public final class StartServer { } public static void main(String... args) throws InterruptedException, IOException, URISyntaxException { - new StartServer(new Env(Paths.get(".").toFile())).start(); + File home = new File("."); + new StartServer(new Env(home)).start(); } }
\ No newline at end of file |