001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch.scm;
021
022import org.sonar.api.batch.ScannerSide;
023import org.sonar.api.batch.InstantiationStrategy;
024import org.sonar.api.batch.fs.FileSystem;
025import org.sonar.api.batch.fs.InputFile;
026
027import java.util.List;
028
029/**
030 * This class should be implemented by SCM providers.
031 * @since 5.0
032 */
033@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
034@ScannerSide
035public abstract class BlameCommand {
036
037  /**
038   * Compute blame of the provided files. 
039   * Computation can be done in parallel if this is more efficient.
040   * If there is an error that prevent to blame a file then an exception should be raised. If 
041   * one file is new or contains local modifications then an exception should be raised.
042   * @see BlameOutput#blameResult(InputFile, List)
043   */
044  public abstract void blame(BlameInput input, BlameOutput output);
045
046  /**
047   * Callback for the provider to report results of blame per file.
048   */
049  public interface BlameInput {
050
051    /**
052     * Filesystem of the current (sub )project.
053     */
054    FileSystem fileSystem();
055
056    /**
057     * List of files that should be blamed.
058     */
059    Iterable<InputFile> filesToBlame();
060
061  }
062
063  /**
064   * Callback for the provider to report results of blame per file.
065   */
066  public interface BlameOutput {
067
068    /**
069     * Add result of the blame command for a single file. Number of lines should
070     * be consistent with {@link InputFile#lines()}. This method is thread safe.
071     * @param lines One entry per line in the file. <b>Every line must have a <code>non-null</code> date and revision </b>.
072     */
073    void blameResult(InputFile file, List<BlameLine> lines);
074
075  }
076
077}