All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.server.qualitygate.changeevent.QGChangeEvent Maven / Gradle / Ivy

There is a newer version: 7.2.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2018 SonarSource SA
 * mailto:info 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.server.qualitygate.changeevent;

import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.config.Configuration;
import org.sonar.api.measures.Metric;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.server.qualitygate.EvaluatedQualityGate;

import static java.util.Objects.requireNonNull;

@Immutable
public class QGChangeEvent {
  private final ComponentDto project;
  private final BranchDto branch;
  private final SnapshotDto analysis;
  private final Configuration projectConfiguration;
  private final Metric.Level previousStatus;
  private final Supplier> qualityGateSupplier;

  public QGChangeEvent(ComponentDto project, BranchDto branch, SnapshotDto analysis, Configuration projectConfiguration,
    @Nullable Metric.Level previousStatus, Supplier> qualityGateSupplier) {
    this.project = requireNonNull(project, "project can't be null");
    this.branch = requireNonNull(branch, "branch can't be null");
    this.analysis = requireNonNull(analysis, "analysis can't be null");
    this.projectConfiguration = requireNonNull(projectConfiguration, "projectConfiguration can't be null");
    this.previousStatus = previousStatus;
    this.qualityGateSupplier = requireNonNull(qualityGateSupplier, "qualityGateSupplier can't be null");
  }

  public BranchDto getBranch() {
    return branch;
  }

  public ComponentDto getProject() {
    return project;
  }

  public SnapshotDto getAnalysis() {
    return analysis;
  }

  public Configuration getProjectConfiguration() {
    return projectConfiguration;
  }

  public Optional getPreviousStatus() {
    return Optional.ofNullable(previousStatus);
  }

  public Supplier> getQualityGateSupplier() {
    return qualityGateSupplier;
  }

  @Override
  public String toString() {
    return "QGChangeEvent{" +
      "project=" + toString(project) +
      ", branch=" + toString(branch) +
      ", analysis=" + toString(analysis) +
      ", projectConfiguration=" + projectConfiguration +
      ", previousStatus=" + previousStatus +
      ", qualityGateSupplier=" + qualityGateSupplier +
      '}';
  }

  private static String toString(ComponentDto project) {
    return project.uuid() + ":" + project.getKey();
  }

  private static String toString(BranchDto branch) {
    return branch.getBranchType() + ":" + branch.getUuid() + ":" + branch.getProjectUuid() + ":" + branch.getMergeBranchUuid();
  }

  private static String toString(SnapshotDto analysis) {
    return analysis.getUuid() + ":" + analysis.getCreatedAt();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy