From 1f634cd0eef4659086318e17f97a198bce02b821 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Fri, 1 Apr 2016 14:18:56 +0200 Subject: [PATCH] SONAR-7488 add API PostTask --- .../org/sonar/api/ce/posttask/CeTask.java | 46 +++++ .../ce/posttask/PostProjectAnalysisTask.java | 74 +++++++++ .../org/sonar/api/ce/posttask/Project.java | 34 ++++ .../sonar/api/ce/posttask/QualityGate.java | 157 ++++++++++++++++++ .../sonar/api/ce/posttask/package-info.java | 23 +++ 5 files changed, 334 insertions(+) create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/CeTask.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Project.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/QualityGate.java create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/package-info.java diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/CeTask.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/CeTask.java new file mode 100644 index 00000000000..27d19b91c9e --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/CeTask.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-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.sonar.api.ce.posttask; + +import com.google.common.annotations.Beta; + +/** + * @since 5.5 + */ +@Beta +public interface CeTask { + /** + * Id of the Compute Engine task. + *

+ * This is the id under which the processing of the project analysis report has been added to the Compute Engine + * queue. + *

+ */ + String getId(); + + /** + * Indicates whether the Compute Engine task ended successfully or not. + */ + Status getStatus(); + + enum Status { + SUCCESS, FAILED + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java new file mode 100644 index 00000000000..630894008f3 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/PostProjectAnalysisTask.java @@ -0,0 +1,74 @@ +/* + * SonarQube + * Copyright (C) 2009-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.sonar.api.ce.posttask; + +import com.google.common.annotations.Beta; +import java.util.Date; +import javax.annotation.CheckForNull; +import org.sonar.api.ExtensionPoint; +import org.sonar.api.ce.ComputeEngineSide; + +/** + * Extension point of which any plugin can provide an implementation and will allow them to be notified whenever some + * analysis report processing ends in the Compute Engine. + * + * If more then one implementation of {@link PostProjectAnalysisTask} is found, they will be executed in no specific order. + * + * @since 5.5 + */ +@ExtensionPoint +@ComputeEngineSide +@Beta +public interface PostProjectAnalysisTask { + /** + * This method is called whenever the processing of a Project analysis has finished, whether successfully or not. + */ + void finished(ProjectAnalysis analysis); + + /** + * @since 5.5 + */ + @Beta + interface ProjectAnalysis { + /** + * Details of the Compute Engine task in which the project analysis was run. + */ + CeTask getCeTask(); + + /** + * Details of the analyzed project. + */ + Project getProject(); + + /** + * Status and details of the Quality Gate of the project (if any was configured on the project). + */ + @CheckForNull + QualityGate getQualityGate(); + + /** + * Date of the analysis. + *

+ * This date is the same as the date of the project analysis report and the snapshot. + *

+ */ + Date getDate(); + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Project.java new file mode 100644 index 00000000000..19a50cc3d7b --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/Project.java @@ -0,0 +1,34 @@ +/* + * SonarQube + * Copyright (C) 2009-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.sonar.api.ce.posttask; + +import com.google.common.annotations.Beta; + +/** + * @since 5.5 + */ +@Beta +public interface Project { + String getUuid(); + + String getKey(); + + String getName(); +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/QualityGate.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/QualityGate.java new file mode 100644 index 00000000000..9e3e14abdcf --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/QualityGate.java @@ -0,0 +1,157 @@ +/* + * SonarQube + * Copyright (C) 2009-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.sonar.api.ce.posttask; + +import com.google.common.annotations.Beta; +import java.util.Collection; +import javax.annotation.CheckForNull; +import org.sonar.api.measures.Metric; + +/** + * @since 5.5 + */ +@Beta +public interface QualityGate { + /** + * The unique identifier of the Quality Gate. + */ + String getId(); + + /** + * Name of the Quality Gate. + */ + String getName(); + + /** + * Status of the Quality Gate for the current project processing. + */ + Status getStatus(); + + /** + * Conditions of the Quality Gate. + */ + Collection getConditions(); + + @Beta + enum Status { + /** at least one threshold is defined, no threshold is reached */ + OK, + /** at least one warning threshold is reached, no error threshold is reached */ + WARN, + /** at least one error threshold is reached */ + ERROR + } + + @Beta + interface Condition { + /** + * Evaluation status of this condition + */ + EvaluationStatus getStatus(); + + /** + * The key of the metric this condition has been evaluated on. + *

+ * The {@link org.sonar.api.measures.Metric} for the returned key can be retrieved using a + * {@link org.sonar.api.measures.MetricFinder} instance. + *

+ * + * @see org.sonar.api.batch.measure.MetricFinder#findByKey(String) + */ + String getMetricKey(); + + /** + * The operator used to evaluate the error and/or warning thresholds against the value of the measure + */ + Operator getOperator(); + + /** + *

+ * At least one of {@link #getErrorThreshold()} and {@link #getWarningThreshold()} is guaranteed to be non {@code null}. + *

+ * + * @see #getWarningThreshold() + */ + @CheckForNull + String getErrorThreshold(); + + /** + * + *

+ * At least one of {@link #getErrorThreshold()} and {@link #getWarningThreshold()} is guaranteed to be non {@code null}. + *

+ * + * @see #getErrorThreshold() + */ + @CheckForNull + String getWarningThreshold(); + + /** + * Whether this condition is defined on the leak period or on an absolute value + */ + boolean isOnLeakPeriod(); + + /** + * The value of the measure. + *

+ * If the type of the metric (which key is provided by {@link #getMetricKey()}) is numerical, the value can be parsed + * using {@link Integer#valueOf(String)}, {@link Long#valueOf(String)} or {@link Double#valueOf(String)}. + *

+ * + * @throws IllegalStateException if {@link #getStatus()} is {@link EvaluationStatus#NO_VALUE} + * + * @see Metric#getType() + */ + String getValue(); + + } + + /** + * Quality Gate condition operator. + */ + @Beta + enum Operator { + EQUALS, NOT_EQUALS, GREATER_THAN, LESS_THAN + } + + /** + * Quality gate condition evaluation status. + */ + @Beta + enum EvaluationStatus { + /** + * No measure found or measure had no value. The condition has not been evaluated and therefor ignored in + * the computation of the Quality Gate status. + */ + NO_VALUE, + /** + * Condition evaluated as OK, neither error nor warning thresholds have been reached. + */ + OK, + /** + * Condition evaluated as WARN, only warning thresholds has been reached. + */ + WARN, + /** + * Condition evaluated as ERROR, error thresholds has been reached (and most likely warning thresholds too). + */ + ERROR + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/package-info.java new file mode 100644 index 00000000000..49c598278f9 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/posttask/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-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. + */ +@ParametersAreNonnullByDefault +package org.sonar.api.ce.posttask; + +import javax.annotation.ParametersAreNonnullByDefault; -- 2.39.5