diff --git a/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/ProjectNotFoundException.java b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/ProjectNotFoundException.java new file mode 100644 index 0000000..1eebb11 --- /dev/null +++ b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/ProjectNotFoundException.java @@ -0,0 +1,31 @@ +/* + * qualinsight-plugins-sonarqube-badges + * Copyright (c) 2015, QualInsight + * http://www.qualinsight.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, you can retrieve a copy + * from . + */ +package com.qualinsight.plugins.sonarqube.badges.internal; + +import java.io.IOException; + +public class ProjectNotFoundException extends IOException { + + /** + * + */ + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatus.java b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatus.java index 7964e44..8cb294e 100644 --- a/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatus.java +++ b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatus.java @@ -56,7 +56,13 @@ public enum QualityGateStatus { */ ERROR("failing", new Color(224, 93, 68, 255), - 44); + 44), + /** + * The project / view does not pass the quality gate due to gate errors. + */ + NOT_FOUND("not found", + new Color(224, 93, 68, 255), + 65); private final String displayText; diff --git a/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatusRetriever.java b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatusRetriever.java index 493afde..fe03983 100644 --- a/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatusRetriever.java +++ b/src/main/java/com/qualinsight/plugins/sonarqube/badges/internal/QualityGateStatusRetriever.java @@ -75,6 +75,8 @@ public String handleResponse(final HttpResponse response) throws IOException { if ((status >= 200) && (status < 300)) { final HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; + } else if (status == 404) { + throw new ProjectNotFoundException(); } else { throw new ClientProtocolException("Unexpected response status: " + status); } @@ -99,6 +101,8 @@ public QualityGateStatus retrieveFor(final String key) { QualityGateStatus status; try { status = statusFromReponseBody(responseBodyForKey(key)); + } catch (final ProjectNotFoundException e) { + status = QualityGateStatus.NOT_FOUND; } catch (URISyntaxException | IOException | JSONException e) { status = QualityGateStatus.SERVER_ERROR; // We do not want to spam server logs with malformed requests, therefore we only log in debug mode