001/* 002 * SonarQube 003 * Copyright (C) 2009-2018 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 java.io.File; 023import java.nio.file.Path; 024import java.util.Set; 025import javax.annotation.Nullable; 026import org.sonar.api.CoreProperties; 027import org.sonar.api.ExtensionPoint; 028import org.sonar.api.batch.InstantiationStrategy; 029import org.sonar.api.batch.ScannerSide; 030 031/** 032 * See {@link CoreProperties#LINKS_SOURCES_DEV} to get old Maven URL format. 033 * @since 5.0 034 */ 035@ScannerSide 036@InstantiationStrategy(InstantiationStrategy.PER_BATCH) 037@ExtensionPoint 038public abstract class ScmProvider { 039 040 /** 041 * Unique identifier of the provider. Can be passed to {@link CoreProperties#SCM_PROVIDER_KEY} 042 * Can be used in SCM URL to define the provider to use. 043 */ 044 public abstract String key(); 045 046 /** 047 * Whether this provider is able to manage files located in this directory. 048 * Used by autodetection. Not considered if user has forced the provider key. 049 * @return false by default 050 */ 051 public boolean supports(File baseDir) { 052 return false; 053 } 054 055 public BlameCommand blameCommand() { 056 throw new UnsupportedOperationException(formatUnsupportedMessage("Blame command")); 057 } 058 059 /** 060 * Return absolute path of the files changed in the current branch, compared to the provided target branch. 061 * @return null if SCM provider was not able to compute the list of files. 062 */ 063 @Nullable 064 public Set<Path> branchChangedFiles(String targetBranchName, Path rootBaseDir) { 065 return null; 066 } 067 068 /** 069 * The relative path from SCM root 070 */ 071 public Path relativePathFromScmRoot(Path path) { 072 throw new UnsupportedOperationException(formatUnsupportedMessage("Getting relative path from SCM root")); 073 } 074 075 /** 076 * The current revision id of the analyzed code, 077 * for example the SHA1 of the current HEAD in a Git branch. 078 */ 079 public String revisionId(Path path) { 080 throw new UnsupportedOperationException(formatUnsupportedMessage("Getting revision id")); 081 } 082 083 private String formatUnsupportedMessage(String prefix) { 084 return prefix + " is not supported by " + key() + " provider"; 085 } 086}