private boolean checkVersion(Server server) { if (server == null) { return false; } String version = server.getVersion(); return version != null && version.startsWith("2."); }
@Override public Server toModel(String json) { WSUtils utils = WSUtils.getINSTANCE(); Object map = utils.parse(json); Server server = new Server() .setId(utils.getString(map, "id")) .setVersion(utils.getString(map, "version")) .setStatusMessage(utils.getString(map, "status_msg")); String status = utils.getString(map, "status"); if (status != null) { server.setStatus(Server.Status.valueOf(status)); } return server; }
/** * {@inheritDoc} */ @Override public Map<String, Object> getContextMap(Map<String, Object> context) { if (LOGGER.isDebugEnabled()) { for (Entry<String, Object> entry : context.entrySet()) { LOGGER.debug("Context contains entry " + entry.getKey() + " of type: " + entry.getValue().getClass().getName()); } } SonarConfiguration config = getSonarConfigurationFromJobs(SonarTaskUtils.getJobsWithSonarTasks((Plan) context.get("plan"))); context.put(SONAR_CONFIGURATION_CONTEXT_KEY, config); try { Sonar sonar = clientFactory.create(config.getSonarHost()); context.put(SONAR_SERVER_INFO_CONTEXT_KEY, sonar.find(new ServerQuery())); } catch (Exception e) { LOGGER.debug(e); context.put(SONAR_SERVER_INFO_CONTEXT_KEY, new Server().setVersion("0.0")); } return context; }
private void connect() { try { LOG.info("Connect"); ServerQuery serverQuery = new ServerQuery(); Server server = find(serverQuery); available = checkVersion(server); LOG.info(available ? "Connected to " + server.getId() + "(" + server.getVersion() + ")" : "Unable to connect"); } catch (ConnectionException e) { available = false; LOG.error("Unable to connect", e); } }
/** * Getter for the Server major version * * @param serverInfo the {@link Server} information response * @return the major version int * @since 1.5.4 */ protected int getServerMajorVersion(Server serverInfo) { String[] parts = serverInfo.getVersion().split("\\."); return Integer.parseInt(parts[0]); }