diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-04-11 13:23:23 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-04-11 13:37:27 +0200 |
commit | e87f05efbc57e816503f74811bde44859c8f009b (patch) | |
tree | 688f63525a6fc2d4ed555be724e7c6d728efc9b5 /src/main/java/org | |
parent | 7a1c1f3bdff7193e448f3d5746bde3c82a9f6a4d (diff) | |
download | sonar-scanner-cli-e87f05efbc57e816503f74811bde44859c8f009b.tar.gz sonar-scanner-cli-e87f05efbc57e816503f74811bde44859c8f009b.zip |
SQSCANNER-17 Remove unused interactive mode
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Cli.java | 14 | ||||
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Main.java | 77 | ||||
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Shutdown.java | 92 |
3 files changed, 15 insertions, 168 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java index 6544cc2..3b110ef 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Cli.java +++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java @@ -27,7 +27,6 @@ class Cli { private boolean debugEnabled = false; private boolean displayVersionOnly = false; private boolean displayStackTrace = false; - private boolean interactive = false; private final Properties props = new Properties(); private final Exit exit; private final Logs logger; @@ -49,10 +48,6 @@ class Cli { return displayStackTrace; } - boolean isInteractive() { - return interactive; - } - Properties properties() { return props; } @@ -93,9 +88,6 @@ class Cli { arg = arg.substring(2); appendPropertyTo(arg, props); - } else if ("-i".equals(arg) || "--interactive".equals(arg)) { - interactive = true; - } else { printError("Unrecognized option: " + arg); } @@ -104,12 +96,6 @@ class Cli { return this; } - public void verify() { - if ("fork".equals(props.getProperty("sonarRunner.mode")) && isInteractive()) { - printError("Cannot run interactively in fork mode."); - } - } - private void reset() { props.clear(); debugEnabled = false; diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index 0f6c1eb..fc7be85 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -19,10 +19,7 @@ */ package org.sonarsource.scanner.cli; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; import java.util.Properties; import org.sonarsource.scanner.api.EmbeddedScanner; @@ -40,16 +37,15 @@ import org.sonarsource.scanner.api.EmbeddedScanner; */ public class Main { - private final Shutdown shutdown; + private final Exit exit; private final Cli cli; private final Conf conf; private EmbeddedScanner runner; - private BufferedReader inputReader; private ScannerFactory runnerFactory; private Logs logger; - Main(Shutdown shutdown, Cli cli, Conf conf, ScannerFactory runnerFactory, Logs logger) { - this.shutdown = shutdown; + Main(Exit exit, Cli cli, Conf conf, ScannerFactory runnerFactory, Logs logger) { + this.exit = exit; this.cli = cli; this.conf = conf; this.runnerFactory = runnerFactory; @@ -57,56 +53,37 @@ public class Main { } public static void main(String[] args) { - Exit exit = new Exit(); Logs logs = new Logs(System.out, System.err); + Exit exit = new Exit(); Cli cli = new Cli(exit, logs).parse(args); - cli.verify(); - Shutdown shutdown = new Shutdown(exit, cli.isInteractive()); - Main main = new Main(shutdown, cli, new Conf(cli, logs), new ScannerFactory(logs), logs); + Main main = new Main(exit, cli, new Conf(cli, logs), new ScannerFactory(logs), logs); main.execute(); } void execute() { Stats stats = new Stats(logger).start(); - + try { Properties p = conf.properties(); configureLogging(p); init(p); runner.start(); logger.info("SonarQube server " + runner.serverVersion()); - - if (cli.isInteractive()) { - interactiveLoop(p); - } else { - runAnalysis(stats, p); - } + runAnalysis(stats, p); } catch (Exception e) { displayExecutionResult(stats, "FAILURE"); showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace() || cli.isDebugEnabled()); - shutdown.exit(Exit.ERROR); + exit.exit(Exit.ERROR); } runner.stop(); - shutdown.exit(Exit.SUCCESS); - } - - private void interactiveLoop(Properties p) throws IOException { - do { - Stats stats = new Stats(logger).start(); - try { - runAnalysis(stats, p); - } catch (Exception e) { - displayExecutionResult(stats, "FAILURE"); - showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace() || cli.isDebugEnabled()); - } - } while (waitForUser()); + exit.exit(Exit.SUCCESS); } private void init(Properties p) throws IOException { SystemInfo.print(logger); if (cli.isDisplayVersionOnly()) { - shutdown.exit(Exit.SUCCESS); + exit.exit(Exit.SUCCESS); } if (cli.isDisplayStackTrace()) { @@ -117,14 +94,14 @@ public class Main { } private void configureLogging(Properties props) throws IOException { - if("true".equals(props.getProperty("sonar.verbose")) - || "DEBUG".equalsIgnoreCase(props.getProperty("sonar.log.level")) - || "TRACE".equalsIgnoreCase(props.getProperty("sonar.log.level")) ) { + if ("true".equals(props.getProperty("sonar.verbose")) + || "DEBUG".equalsIgnoreCase(props.getProperty("sonar.log.level")) + || "TRACE".equalsIgnoreCase(props.getProperty("sonar.log.level"))) { logger.setDebugEnabled(true); logger.setDisplayStackTrace(true); } - - if(cli.isDisplayStackTrace()) { + + if (cli.isDisplayStackTrace()) { logger.setDisplayStackTrace(true); } } @@ -134,30 +111,6 @@ public class Main { displayExecutionResult(stats, "SUCCESS"); } - private boolean waitForUser() throws IOException { - if (inputReader == null) { - inputReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); - } - - shutdown.signalReady(true); - if (shutdown.shouldExit()) { - // exit before displaying message - return false; - } - - System.out.println(""); - System.out.println("<Press enter to restart analysis or Ctrl+C to exit the interactive mode>"); - String line = inputReader.readLine(); - shutdown.signalReady(false); - - return line != null; - } - - // Visible for testing - void setInputReader(BufferedReader inputReader) { - this.inputReader = inputReader; - } - private void displayExecutionResult(Stats stats, String resultMsg) { logger.info("------------------------------------------------------------------------"); logger.info("EXECUTION " + resultMsg); diff --git a/src/main/java/org/sonarsource/scanner/cli/Shutdown.java b/src/main/java/org/sonarsource/scanner/cli/Shutdown.java deleted file mode 100644 index d2746b1..0000000 --- a/src/main/java/org/sonarsource/scanner/cli/Shutdown.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube Scanner - * Copyright (C) 2011-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.sonarsource.scanner.cli; - -class Shutdown { - static final int SUCCESS = 0; - static final int ERROR = 1; - private static final long DEFAULT_MAX_WAIT = 10_000; - - private long maxWait; - ShutdownHook hook = new ShutdownHook(); - private boolean isReady = false; - private boolean exiting = false; - private Object lock = new Object(); - private Exit exit; - - Shutdown(Exit exit, boolean isInteractive) { - this(exit, isInteractive, DEFAULT_MAX_WAIT); - } - - Shutdown(Exit exit, boolean isInteractive, long maxWait) { - this.maxWait = maxWait; - this.exit = exit; - if (isInteractive) { - Runtime.getRuntime().addShutdownHook(hook); - } - } - - void exit(int status) { - synchronized (lock) { - signalReady(true); - } - exit.exit(status); - } - - void signalReady(boolean ready) { - synchronized (lock) { - this.isReady = ready; - lock.notifyAll(); - } - } - - boolean shouldExit() { - synchronized (lock) { - return exiting; - } - } - - class ShutdownHook extends Thread { - private ShutdownHook() { - this.setName("shutdown-hook"); - } - - @Override - public void run() { - long startTime = System.currentTimeMillis(); - synchronized (lock) { - exiting = true; - - while (!isReady) { - long waitTime = startTime + maxWait - System.currentTimeMillis(); - if (waitTime <= 0) { - break; - } - - try { - lock.wait(waitTime); - } catch (InterruptedException e) { - // continue - } - } - } - } - } -} |