@@ -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) |
@@ -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()); | |||
} | |||
} |
@@ -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 |
@@ -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(); | |||
} | |||
} |
@@ -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<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); | |||
} | |||
} |
@@ -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()) { |
@@ -56,7 +56,7 @@ public class SvnScmSupport { | |||
return Arrays.asList(SvnScmProvider.class, | |||
SvnBlameCommand.class, | |||
SvnConfiguration.class, | |||
FindFork.class, | |||
SvnConfiguration.getProperties()); | |||
FindFork.class | |||
); | |||
} | |||
} |
@@ -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"); |
@@ -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(); |