]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14009 SVN configuration in SQ server does not work
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 22 Oct 2020 15:01:41 +0000 (10:01 -0500)
committersonartech <sonartech@sonarsource.com>
Thu, 22 Oct 2020 20:08:30 +0000 (20:08 +0000)
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java
sonar-core/src/test/java/org/sonar/core/config/SvnPropertiesTest.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scm/svn/SvnScmSupport.java
sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnConfigurationTest.java
sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmSupportTest.java

index d7f9950d0091ba7c928ec07724f0f1753d17b7ba..b473fe63ffcff575fc90629ff1e9b8780f66c103 100644 (file)
@@ -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 (file)
index 0000000..5c9baf2
--- /dev/null
@@ -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<PropertyDefinition> 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());
+  }
+}
index c126792a0af51ddc320f58b9a6f916a3e22e91c1..234a374ca599f4f384836dc1eda72eb6430c913f 100644 (file)
@@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest {
   @Test
   public void all() {
     List<PropertyDefinition> 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 (file)
index 0000000..9503dd0
--- /dev/null
@@ -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();
+  }
+}
index 83e0cc7641c175931699d6bb28334da7cb8cc1b8..d62d5b399cddab611fc0ec064043b290a3e2c691 100644 (file)
 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<PropertyDefinition> 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);
   }
-
 }
index 1e44f89c63f029251f451d2b1938e0e051844606..c39e06c16c976131b51425544494217ea01b8792 100644 (file)
@@ -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()) {
index 03182cde230221b08b59e69243cae1198ff35c30..6bd598c3c9f6c47cc2595e25d472fc2e5587c1b9 100644 (file)
@@ -56,7 +56,7 @@ public class SvnScmSupport {
     return Arrays.asList(SvnScmProvider.class,
       SvnBlameCommand.class,
       SvnConfiguration.class,
-      FindFork.class,
-      SvnConfiguration.getProperties());
+      FindFork.class
+    );
   }
 }
index 7a765b28160c12dcb60aa05e58df9e24d8da35c8..e7b0d44c9dab4a6d6faa847707403b2459fe1903 100644 (file)
@@ -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");
index 33c3bd37ac992a1d06b4467c6db555bc7d729e71..c5e4b4eb375812734134d53f490bbc40bbeb1854 100644 (file)
@@ -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();