private static Consumer<ProjectLifeCycleListener> safelyCallListener(Consumer<ProjectLifeCycleListener> task) { return listener -> { try { task.accept(listener); } catch (Error | Exception e) { LOG.error("Call on ProjectLifeCycleListener \"{}\" failed", listener.getClass(), e); } }; } }
private boolean attemptStartup() { try { startup(); return true; } catch (org.sonar.api.utils.MessageException | org.sonar.process.MessageException e) { LOG.error("Compute Engine startup failed: " + e.getMessage()); return false; } catch (Throwable e) { LOG.error("Compute Engine startup failed", e); return false; } }
public void clean() { try { if (tempDir.exists()) { Files.walkFileTree(tempDir.toPath(), DeleteRecursivelyFileVisitor.INSTANCE); } } catch (IOException e) { LOG.error("Failed to delete temp folder", e); } }
private void callListeners(Consumer<ExecutionListener> call) { listeners.forEach(listener -> { try { call.accept(listener); } catch (Throwable t) { LOG.error(format("Call to listener %s failed.", listener.getClass().getSimpleName()), t); } }); } }
private static void closeJar(@Nullable JarFile jar, String jarPath) { if (jar != null) { try { jar.close(); } catch (Exception e) { Loggers.get(ClassLoaderUtils.class).error("Fail to close JAR file: " + jarPath, e); } } }
private static void executeTask(ProjectAnalysisImpl projectAnalysis, PostProjectAnalysisTask postProjectAnalysisTask) { try { postProjectAnalysisTask.finished(projectAnalysis); } catch (Exception e) { LOG.error("Execution of task " + postProjectAnalysisTask.getClass() + " failed", e); } }
private Optional<CeTask> tryAndFindTaskToExecute() { try { return queue.peek(uuid); } catch (Exception e) { LOG.error("Failed to pop the queue of analysis reports", e); } return Optional.empty(); }
private void executeListener(boolean allStepsExecuted) { try { listener.finished(allStepsExecuted); } catch (Throwable e) { // any Throwable throws by the listener going up the stack might hide an Exception/Error thrown by the step and // cause it be swallowed. We don't wan't that => we catch Throwable LOGGER.error("Execution of listener failed", e); } }
@Override public void failure(Throwable t) { LOGGER.error("Background initialization failed. Stopping SonarQube", t); processCommandWrapper.requestStop(); this.running = false; }
@Override public void addToQueue(Runnable r) { requireNonNull(r); executorService.addToQueue(() -> { try { r.run(); } catch (Exception e) { LOG.error("Asynchronous task failed", e); } }); } }
@Override public void afterBulk(long executionId, BulkRequest request, Throwable e) { LOGGER.error("Fail to execute bulk index request: " + request, e); stopProfiler(request); }
private void processMeasure(FileLinesContext context, File measureFile, int lineNumber, String line) { try { String metricKey = StringUtils.substringBefore(line, ":"); String value = line.substring(metricKey.length() + 1); saveMeasure(context, metricKey, KeyValueFormat.parseIntInt(value)); } catch (Exception e) { LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e); } }
public void unload(Collection<Plugin> plugins) { for (Plugin plugin : plugins) { ClassLoader classLoader = plugin.getClass().getClassLoader(); if (classLoader instanceof Closeable && classLoader != classloaderFactory.baseClassLoader()) { try { ((Closeable) classLoader).close(); } catch (Exception e) { Loggers.get(getClass()).error("Fail to close classloader " + classLoader.toString(), e); } } } }
private Optional<FileBlocks> toFileBlocks(String componentKey, Collection<Block> fileBlocks) { DefaultInputFile component = (DefaultInputFile) componentStore.getByKey(componentKey); if (component == null) { LOG.error("Resource not found in component store: {}. Skipping CPD computation for it", componentKey); return Optional.empty(); } return Optional.of(new FileBlocks(component, fileBlocks)); }
@Override public void close() { try { stopComponents(); } catch (Throwable t) { Loggers.get(TaskContainerImpl.class).error("Cleanup of container failed", t); } } }
private static DistributedCall<Object> setLogLevelForNode(LoggerLevel level) { return () -> { try { ServerLogging.changeLevelFromHazelcastDistributedQuery(level); } catch (Exception e) { LOGGER.error("Setting log level to '" + level.name() + "' in this cluster node failed", e); throw new IllegalStateException("Setting log level to '" + level.name() + "' in this cluster node failed", e); } return null; }; } }
private void insertPermissionForAdministrators(DbSession dbSession, PermissionTemplateDto template) { Optional<GroupDto> admins = dbClient.groupDao().selectByName(dbSession, template.getOrganizationUuid(), DefaultGroups.ADMINISTRATORS); if (admins.isPresent()) { insertGroupPermission(dbSession, template, UserRole.ADMIN, admins.get()); insertGroupPermission(dbSession, template, UserRole.ISSUE_ADMIN, admins.get()); insertGroupPermission(dbSession, template, UserRole.SECURITYHOTSPOT_ADMIN, admins.get()); insertGroupPermission(dbSession, template, OrganizationPermission.APPLICATION_CREATOR.getKey(), admins.get()); insertGroupPermission(dbSession, template, OrganizationPermission.PORTFOLIO_CREATOR.getKey(), admins.get()); } else { LOG.error("Cannot setup default permission for group: " + DefaultGroups.ADMINISTRATORS); } }
private void attemptShutdown() { try { LOG.info("Compute Engine is stopping..."); computeEngine.shutdown(); LOG.info("Compute Engine is stopped"); } catch (Throwable e) { LOG.error("Compute Engine failed to stop", e); } finally { // release thread waiting for CeServer stopAwait(); } }
void terminate() { if (tomcat.getServer().getState().isAvailable()) { try { tomcat.stop(); tomcat.destroy(); } catch (Exception e) { Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e); } } deleteQuietly(tomcatBasedir()); }