From 0007fd406caa7802ef2a55715ff891cf3732042b Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 22 Oct 2020 10:01:41 -0500 Subject: [PATCH] SONAR-14009 SVN configuration in SQ server does not work --- .../core/config/CorePropertyDefinitions.java | 1 + .../org/sonar/core/config/SvnProperties.java | 80 +++++++++++++++++++ .../config/CorePropertyDefinitionsTest.java | 2 +- .../sonar/core/config/SvnPropertiesTest.java | 31 +++++++ .../org/sonar/scm/svn/SvnConfiguration.java | 60 ++------------ .../org/sonar/scm/svn/SvnScmProvider.java | 1 + .../java/org/sonar/scm/svn/SvnScmSupport.java | 4 +- .../sonar/scm/svn/SvnConfigurationTest.java | 14 ++-- .../org/sonar/scm/svn/SvnScmSupportTest.java | 4 +- 9 files changed, 130 insertions(+), 67 deletions(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java create mode 100644 sonar-core/src/test/java/org/sonar/core/config/SvnPropertiesTest.java diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index d7f9950d009..b473fe63ffc 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -53,6 +53,7 @@ public class CorePropertyDefinitions { defs.addAll(PurgeProperties.all()); defs.addAll(EmailSettings.definitions()); defs.addAll(ScannerProperties.all()); + defs.addAll(SvnProperties.all()); defs.addAll(asList( PropertyDefinition.builder(CoreProperties.MODULE_LEVEL_ARCHIVED_SETTINGS) diff --git a/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java b/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java new file mode 100644 index 00000000000..5c9baf26b9d --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.core.config; + +import java.util.Arrays; +import java.util.List; +import org.sonar.api.CoreProperties; +import org.sonar.api.PropertyType; +import org.sonar.api.config.PropertyDefinition; +import org.sonar.api.resources.Qualifiers; + +public class SvnProperties { + + private static final String CATEGORY_SVN = "SVN"; + public static final String USER_PROP_KEY = "sonar.svn.username"; + public static final String PRIVATE_KEY_PATH_PROP_KEY = "sonar.svn.privateKeyPath"; + public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured"; + public static final String PASSPHRASE_PROP_KEY = "sonar.svn.passphrase.secured"; + + private SvnProperties() { + //private only + } + + public static List all() { + return Arrays.asList( + PropertyDefinition.builder(USER_PROP_KEY) + .name("Username") + .description("Username to be used for SVN server or SVN+SSH authentication") + .type(PropertyType.STRING) + .onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_SCM) + .subCategory(CATEGORY_SVN) + .index(0) + .build(), + PropertyDefinition.builder(PASSWORD_PROP_KEY) + .name("Password") + .description("Password to be used for SVN server or SVN+SSH authentication") + .type(PropertyType.PASSWORD) + .onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_SCM) + .subCategory(CATEGORY_SVN) + .index(1) + .build(), + PropertyDefinition.builder(PRIVATE_KEY_PATH_PROP_KEY) + .name("Path to private key file") + .description("Can be used instead of password for SVN+SSH authentication") + .type(PropertyType.STRING) + .onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_SCM) + .subCategory(CATEGORY_SVN) + .index(2) + .build(), + PropertyDefinition.builder(PASSPHRASE_PROP_KEY) + .name("Passphrase") + .description("Optional passphrase of your private key file") + .type(PropertyType.PASSWORD) + .onQualifiers(Qualifiers.PROJECT) + .category(CoreProperties.CATEGORY_SCM) + .subCategory(CATEGORY_SVN) + .index(3) + .build()); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java index c126792a0af..234a374ca59 100644 --- a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java @@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest { @Test public void all() { List defs = CorePropertyDefinitions.all(); - assertThat(defs).hasSize(52); + assertThat(defs).hasSize(56); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/config/SvnPropertiesTest.java b/sonar-core/src/test/java/org/sonar/core/config/SvnPropertiesTest.java new file mode 100644 index 00000000000..9503dd0f794 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/config/SvnPropertiesTest.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.core.config; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SvnPropertiesTest { + @Test + public void creates_properties() { + assertThat(SvnProperties.all()).isNotEmpty(); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnConfiguration.java index 83e0cc7641c..d62d5b399cd 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnConfiguration.java @@ -20,72 +20,23 @@ package org.sonar.scm.svn; import java.io.File; -import java.util.Arrays; -import java.util.List; import java.util.Optional; import javax.annotation.CheckForNull; -import org.sonar.api.CoreProperties; -import org.sonar.api.PropertyType; import org.sonar.api.config.Configuration; -import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.scanner.ScannerSide; import org.sonar.api.utils.MessageException; -@ScannerSide -public class SvnConfiguration { +import static org.sonar.core.config.SvnProperties.PASSPHRASE_PROP_KEY; +import static org.sonar.core.config.SvnProperties.PASSWORD_PROP_KEY; +import static org.sonar.core.config.SvnProperties.PRIVATE_KEY_PATH_PROP_KEY; +import static org.sonar.core.config.SvnProperties.USER_PROP_KEY; - private static final String CATEGORY_SVN = "SVN"; - public static final String USER_PROP_KEY = "sonar.svn.username"; - public static final String PRIVATE_KEY_PATH_PROP_KEY = "sonar.svn.privateKeyPath"; - public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured"; - public static final String PASSPHRASE_PROP_KEY = "sonar.svn.passphrase.secured"; +public class SvnConfiguration { private final Configuration config; public SvnConfiguration(Configuration config) { this.config = config; } - public static List getProperties() { - return Arrays.asList( - PropertyDefinition.builder(USER_PROP_KEY) - .name("Username") - .description("Username to be used for SVN server or SVN+SSH authentication") - .type(PropertyType.STRING) - .onQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_SCM) - .subCategory(CATEGORY_SVN) - .index(0) - .build(), - PropertyDefinition.builder(PASSWORD_PROP_KEY) - .name("Password") - .description("Password to be used for SVN server or SVN+SSH authentication") - .type(PropertyType.PASSWORD) - .onQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_SCM) - .subCategory(CATEGORY_SVN) - .index(1) - .build(), - PropertyDefinition.builder(PRIVATE_KEY_PATH_PROP_KEY) - .name("Path to private key file") - .description("Can be used instead of password for SVN+SSH authentication") - .type(PropertyType.STRING) - .onQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_SCM) - .subCategory(CATEGORY_SVN) - .index(2) - .build(), - PropertyDefinition.builder(PASSPHRASE_PROP_KEY) - .name("Passphrase") - .description("Optional passphrase of your private key file") - .type(PropertyType.PASSWORD) - .onQualifiers(Qualifiers.PROJECT) - .category(CoreProperties.CATEGORY_SCM) - .subCategory(CATEGORY_SVN) - .index(3) - .build()); - } - @CheckForNull public String username() { return config.get(USER_PROP_KEY).orElse(null); @@ -113,5 +64,4 @@ public class SvnConfiguration { public String passPhrase() { return config.get(PASSPHRASE_PROP_KEY).orElse(null); } - } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmProvider.java index 1e44f89c63f..c39e06c16c9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmProvider.java @@ -69,6 +69,7 @@ public class SvnScmProvider extends ScmProvider { @Override public boolean supports(File baseDir) { + File folder = baseDir; while (folder != null) { if (new File(folder, ".svn").exists()) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmSupport.java b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmSupport.java index 03182cde230..6bd598c3c9f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmSupport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmSupport.java @@ -56,7 +56,7 @@ public class SvnScmSupport { return Arrays.asList(SvnScmProvider.class, SvnBlameCommand.class, SvnConfiguration.class, - FindFork.class, - SvnConfiguration.getProperties()); + FindFork.class + ); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnConfigurationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnConfigurationTest.java index 7a765b28160..e7b0d44c9da 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnConfigurationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnConfigurationTest.java @@ -26,38 +26,38 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.System2; +import org.sonar.core.config.SvnProperties; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; public class SvnConfigurationTest { - @Rule public TemporaryFolder temp = new TemporaryFolder(); @Test public void sanityCheck() throws Exception { - MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, SvnConfiguration.getProperties())); + MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, SvnProperties.all())); SvnConfiguration config = new SvnConfiguration(settings.asConfig()); assertThat(config.username()).isNull(); assertThat(config.password()).isNull(); - settings.setProperty(SvnConfiguration.USER_PROP_KEY, "foo"); + settings.setProperty(SvnProperties.USER_PROP_KEY, "foo"); assertThat(config.username()).isEqualTo("foo"); - settings.setProperty(SvnConfiguration.PASSWORD_PROP_KEY, "pwd"); + settings.setProperty(SvnProperties.PASSWORD_PROP_KEY, "pwd"); assertThat(config.password()).isEqualTo("pwd"); - settings.setProperty(SvnConfiguration.PASSPHRASE_PROP_KEY, "pass"); + settings.setProperty(SvnProperties.PASSPHRASE_PROP_KEY, "pass"); assertThat(config.passPhrase()).isEqualTo("pass"); assertThat(config.privateKey()).isNull(); File fakeKey = temp.newFile(); - settings.setProperty(SvnConfiguration.PRIVATE_KEY_PATH_PROP_KEY, fakeKey.getAbsolutePath()); + settings.setProperty(SvnProperties.PRIVATE_KEY_PATH_PROP_KEY, fakeKey.getAbsolutePath()); assertThat(config.privateKey()).isEqualTo(fakeKey); - settings.setProperty(SvnConfiguration.PRIVATE_KEY_PATH_PROP_KEY, "/not/exists"); + settings.setProperty(SvnProperties.PRIVATE_KEY_PATH_PROP_KEY, "/not/exists"); try { config.privateKey(); fail("Expected exception"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmSupportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmSupportTest.java index 33c3bd37ac9..c5e4b4eb375 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmSupportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmSupportTest.java @@ -27,6 +27,8 @@ import static org.mockito.Mockito.when; import static org.sonar.scm.svn.SvnScmSupport.newSvnClientManager; public class SvnScmSupportTest { + private SvnConfiguration config = mock(SvnConfiguration.class); + @Test public void getExtensions() { assertThat(SvnScmSupport.getObjects()).isNotEmpty(); @@ -34,7 +36,6 @@ public class SvnScmSupportTest { @Test public void newSvnClientManager_with_auth() { - SvnConfiguration config = mock(SvnConfiguration.class); when(config.password()).thenReturn("password"); when(config.passPhrase()).thenReturn("passPhrase"); assertThat(newSvnClientManager(config)).isNotNull(); @@ -42,7 +43,6 @@ public class SvnScmSupportTest { @Test public void newSvnClientManager_without_auth() { - SvnConfiguration config = mock(SvnConfiguration.class); assertThat(config.password()).isNull(); assertThat(config.passPhrase()).isNull(); assertThat(newSvnClientManager(config)).isNotNull(); -- 2.39.5