From: Janos Gyerik Date: Fri, 22 Sep 2017 15:15:31 +0000 (+0200) Subject: Drop ScmBranchProvider (blend it into ScmProvider) X-Git-Tag: 6.6-RC1~187 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3dec1d76c61bb37e5fbc2394cae766c02dcf8a9d;p=sonarqube.git Drop ScmBranchProvider (blend it into ScmProvider) --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmBranchProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmBranchProvider.java deleted file mode 100644 index 1cb4c476702..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmBranchProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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.api.batch.scm; - -import java.nio.file.Path; -import java.util.Set; -import javax.annotation.Nullable; -import org.sonar.api.ExtensionPoint; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.ScannerSide; - -/** - * A {@link ScmProvider} with the capability of finding out which files were changed in a branch. - * @since 6.6 - */ -@ScannerSide -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -@ExtensionPoint -public abstract class ScmBranchProvider extends ScmProvider { - - /** - * Return absolute path of the files changed in the current branch, compared to the provided target branch. - * @return null if SCM provider was not able to compute the list of files. - */ - @Nullable - public Set branchChangedFiles(String targetBranchName, Path rootBaseDir) { - return null; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java index dd23c59d8ab..e73d05a06cd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java @@ -19,12 +19,14 @@ */ package org.sonar.api.batch.scm; -import org.sonar.api.batch.ScannerSide; +import java.io.File; +import java.nio.file.Path; +import java.util.Set; +import javax.annotation.Nullable; import org.sonar.api.CoreProperties; import org.sonar.api.ExtensionPoint; import org.sonar.api.batch.InstantiationStrategy; - -import java.io.File; +import org.sonar.api.batch.ScannerSide; /** * See {@link CoreProperties#LINKS_SOURCES_DEV} to get old Maven URL format. @@ -54,4 +56,12 @@ public abstract class ScmProvider { throw new UnsupportedOperationException("Blame command is not supported by " + key() + " provider"); } + /** + * Return absolute path of the files changed in the current branch, compared to the provided target branch. + * @return null if SCM provider was not able to compute the list of files. + */ + @Nullable + public Set branchChangedFiles(String targetBranchName, Path rootBaseDir) { + return null; + } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java index aed26e03144..a3f6737fa62 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java @@ -25,7 +25,6 @@ import javax.annotation.CheckForNull; import org.picocontainer.annotations.Nullable; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; -import org.sonar.api.batch.scm.ScmBranchProvider; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -65,10 +64,9 @@ public class ScmChangedFilesProvider extends ProviderAdapter { private static Collection loadChangedFilesIfNeeded(ScmConfiguration scmConfiguration, BranchConfiguration branchConfiguration, Path rootBaseDir) { if (branchConfiguration.isShortLivingBranch()) { ScmProvider scmProvider = scmConfiguration.provider(); - if (scmProvider != null && (scmProvider instanceof ScmBranchProvider)) { + if (scmProvider != null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - ScmBranchProvider scmBranchProvider = (ScmBranchProvider) scmProvider; - Collection changedFiles = scmBranchProvider.branchChangedFiles(branchConfiguration.branchTarget(), rootBaseDir); + Collection changedFiles = scmProvider.branchChangedFiles(branchConfiguration.branchTarget(), rootBaseDir); profiler.stopInfo(); if (changedFiles != null) { LOG.debug("SCM reported {} {} changed in the branch", changedFiles.size(), pluralize("file", changedFiles.size())); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java index bf278fee6ce..eca414226bb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java @@ -30,7 +30,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; -import org.sonar.api.batch.scm.ScmBranchProvider; import org.sonar.api.batch.scm.ScmProvider; import org.sonar.scanner.scan.branch.BranchConfiguration; @@ -48,7 +47,7 @@ public class ScmChangedFilesProviderTest { @Mock private InputModuleHierarchy inputModuleHierarchy; @Mock - private ScmBranchProvider scmProvider; + private ScmProvider scmProvider; @Rule public ExpectedException exception = ExpectedException.none(); @@ -109,7 +108,13 @@ public class ScmChangedFilesProviderTest { @Test public void testLegacyScmProvider() { - ScmProvider legacy = mock(ScmProvider.class); + ScmProvider legacy = new ScmProvider() { + @Override + public String key() { + return null; + } + }; + when(scmConfiguration.provider()).thenReturn(legacy); when(branchConfiguration.isShortLivingBranch()).thenReturn(true); @@ -117,7 +122,6 @@ public class ScmChangedFilesProviderTest { assertThat(scmChangedFiles.get()).isNull(); verify(scmConfiguration).provider(); - verifyZeroInteractions(legacy); } @Test