001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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.BatchComponent;
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)
034public abstract class BlameCommand implements BatchComponent {
035
036  /**
037   * Compute blame of the provided files. 
038   * Computation can be done in parallel if this is more efficient.
039   * If there is an error that prevent to blame a file then an exception should be raised. If 
040   * one file is new or contains local modifications then an exception should be raised.
041   */
042  public abstract void blame(BlameInput input, BlameOutput output);
043
044  /**
045   * Callback for the provider to report results of blame per file.
046   */
047  public static interface BlameInput {
048
049    /**
050     * Filesystem of the current (sub )project.
051     */
052    FileSystem fileSystem();
053
054    /**
055     * List of files that should be blamed.
056     */
057    Iterable<InputFile> filesToBlame();
058
059  }
060
061  /**
062   * Callback for the provider to report results of blame per file.
063   */
064  public static interface BlameOutput {
065
066    /**
067     * Add result of the blame command for a single file. Number of lines should
068     * be consistent with {@link InputFile#lines()}. This method is thread safe.
069     * @param lines One entry per line in the file.
070     */
071    void blameResult(InputFile file, List<BlameLine> lines);
072
073  }
074
075}