@Test public void should_return_false_if_failed_to_build_node_command() throws Exception { context.fileSystem().add(new TestInputFileBuilder("moduleKey", "file.css") .setLanguage("css") .build()); NodeCommandBuilder nodeCommandBuilder = mock(NodeCommandBuilder.class, invocation -> { if (NodeCommandBuilder.class.equals(invocation.getMethod().getReturnType())) { return invocation.getMock(); } else { throw new NodeCommandException("msg"); } }); AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); cssAnalyzerBridgeServer = new CssAnalyzerBridgeServer(nodeCommandBuilder, TEST_TIMEOUT_SECONDS, new TestBundle(START_SERVER_SCRIPT), analysisWarnings); assertThat(cssAnalyzerBridgeServer.startServerLazily(context)).isFalse(); assertThat(logTester.logs(ERROR)).contains("CSS rules were not executed. msg"); verify(analysisWarnings).addUnique("CSS rules were not executed. msg"); }
public boolean startServerLazily(SensorContext context) throws IOException { if (failedToStart) { LOG.debug("Skipping start of css-bundle server due to the failure during first analysis"); LOG.debug("Skipping execution of CSS rules due to the problems with css-bundle server"); return false; } try { if (isAlive()) { LOG.debug("css-bundle server is up, no need to start."); return true; } deploy(context.fileSystem().workDir()); startServer(context); return true; } catch (NodeCommandException e) { failedToStart = true; processNodeCommandException(e, context); return false; } }
CssAnalyzerBridgeServer implements Startable { public boolean startServerLazily(SensorContext context) throws IOException { if (failedToStart) { LOG.debug("Skipping start of css-bundle server due to the failure during first analysis"); LOG.debug("Skipping execution of CSS rules due to the problems with css-bundle server"); return false; } try { if (isAlive()) { LOG.debug("css-bundle server is up, no need to start."); return true; } deploy(context.fileSystem().workDir()); startServer(context); return true; } catch (NodeCommandException e) { failedToStart = true; processNodeCommandException(e, context); return false; } } }
CssAnalyzerBridgeServer implements Startable { public boolean startServerLazily(SensorContext context) throws IOException { if (failedToStart) { LOG.debug("Skipping start of css-bundle server due to the failure during first analysis"); LOG.debug("Skipping execution of CSS rules due to the problems with css-bundle server"); return false; } try { if (isAlive()) { LOG.debug("css-bundle server is up, no need to start."); return true; } deploy(context.fileSystem().workDir()); startServer(context); return true; } catch (NodeCommandException e) { failedToStart = true; processNodeCommandException(e, context); return false; } } @SuppressWarnings("unused")  CssAnalyzerBridgeServer(Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); protected  CssAnalyzerBridgeServer(NodeCommandBuilder nodeCommandBuilder, int timeoutSeconds, Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); }
CssAnalyzerBridgeServer implements Startable { public boolean startServerLazily(SensorContext context) throws IOException { if (failedToStart) { LOG.debug("Skipping start of css-bundle server due to the failure during first analysis"); LOG.debug("Skipping execution of CSS rules due to the problems with css-bundle server"); return false; } try { if (isAlive()) { LOG.debug("css-bundle server is up, no need to start."); return true; } deploy(context.fileSystem().workDir()); startServer(context); return true; } catch (NodeCommandException e) { failedToStart = true; processNodeCommandException(e, context); return false; } } @SuppressWarnings("unused")  CssAnalyzerBridgeServer(Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); protected  CssAnalyzerBridgeServer(NodeCommandBuilder nodeCommandBuilder, int timeoutSeconds, Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); void deploy(File deployLocation); void startServer(SensorContext context); boolean startServerLazily(SensorContext context); Issue[] analyze(Request request); boolean isAlive(); String getCommandInfo(); @Override void start(); @Override void stop(); void setPort(int port); }
CssAnalyzerBridgeServer implements Startable { public boolean startServerLazily(SensorContext context) throws IOException { if (failedToStart) { LOG.debug("Skipping start of css-bundle server due to the failure during first analysis"); LOG.debug("Skipping execution of CSS rules due to the problems with css-bundle server"); return false; } try { if (isAlive()) { LOG.debug("css-bundle server is up, no need to start."); return true; } deploy(context.fileSystem().workDir()); startServer(context); return true; } catch (NodeCommandException e) { failedToStart = true; processNodeCommandException(e, context); return false; } } @SuppressWarnings("unused")  CssAnalyzerBridgeServer(Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); protected  CssAnalyzerBridgeServer(NodeCommandBuilder nodeCommandBuilder, int timeoutSeconds, Bundle bundle, @Nullable AnalysisWarnings analysisWarnings); void deploy(File deployLocation); void startServer(SensorContext context); boolean startServerLazily(SensorContext context); Issue[] analyze(Request request); boolean isAlive(); String getCommandInfo(); @Override void start(); @Override void stop(); void setPort(int port);  }