defs.addAll(PurgeProperties.all()); | defs.addAll(PurgeProperties.all()); | ||||
defs.addAll(EmailSettings.definitions()); | defs.addAll(EmailSettings.definitions()); | ||||
defs.addAll(ScannerProperties.all()); | defs.addAll(ScannerProperties.all()); | ||||
defs.addAll(SvnProperties.all()); | |||||
defs.addAll(asList( | defs.addAll(asList( | ||||
PropertyDefinition.builder(CoreProperties.MODULE_LEVEL_ARCHIVED_SETTINGS) | PropertyDefinition.builder(CoreProperties.MODULE_LEVEL_ARCHIVED_SETTINGS) |
/* | |||||
* 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()); | |||||
} | |||||
} |
@Test | @Test | ||||
public void all() { | public void all() { | ||||
List<PropertyDefinition> defs = CorePropertyDefinitions.all(); | List<PropertyDefinition> defs = CorePropertyDefinitions.all(); | ||||
assertThat(defs).hasSize(52); | |||||
assertThat(defs).hasSize(56); | |||||
} | } | ||||
@Test | @Test |
/* | |||||
* 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(); | |||||
} | |||||
} |
package org.sonar.scm.svn; | package org.sonar.scm.svn; | ||||
import java.io.File; | import java.io.File; | ||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import java.util.Optional; | import java.util.Optional; | ||||
import javax.annotation.CheckForNull; | 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.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; | 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; | private final Configuration config; | ||||
public SvnConfiguration(Configuration config) { | public SvnConfiguration(Configuration config) { | ||||
this.config = 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 | @CheckForNull | ||||
public String username() { | public String username() { | ||||
return config.get(USER_PROP_KEY).orElse(null); | return config.get(USER_PROP_KEY).orElse(null); | ||||
public String passPhrase() { | public String passPhrase() { | ||||
return config.get(PASSPHRASE_PROP_KEY).orElse(null); | return config.get(PASSPHRASE_PROP_KEY).orElse(null); | ||||
} | } | ||||
} | } |
@Override | @Override | ||||
public boolean supports(File baseDir) { | public boolean supports(File baseDir) { | ||||
File folder = baseDir; | File folder = baseDir; | ||||
while (folder != null) { | while (folder != null) { | ||||
if (new File(folder, ".svn").exists()) { | if (new File(folder, ".svn").exists()) { |
return Arrays.asList(SvnScmProvider.class, | return Arrays.asList(SvnScmProvider.class, | ||||
SvnBlameCommand.class, | SvnBlameCommand.class, | ||||
SvnConfiguration.class, | SvnConfiguration.class, | ||||
FindFork.class, | |||||
SvnConfiguration.getProperties()); | |||||
FindFork.class | |||||
); | |||||
} | } | ||||
} | } |
import org.sonar.api.config.PropertyDefinitions; | import org.sonar.api.config.PropertyDefinitions; | ||||
import org.sonar.api.config.internal.MapSettings; | import org.sonar.api.config.internal.MapSettings; | ||||
import org.sonar.api.utils.System2; | 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.assertThat; | ||||
import static org.assertj.core.api.Assertions.fail; | import static org.assertj.core.api.Assertions.fail; | ||||
public class SvnConfigurationTest { | public class SvnConfigurationTest { | ||||
@Rule | @Rule | ||||
public TemporaryFolder temp = new TemporaryFolder(); | public TemporaryFolder temp = new TemporaryFolder(); | ||||
@Test | @Test | ||||
public void sanityCheck() throws Exception { | 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()); | SvnConfiguration config = new SvnConfiguration(settings.asConfig()); | ||||
assertThat(config.username()).isNull(); | assertThat(config.username()).isNull(); | ||||
assertThat(config.password()).isNull(); | assertThat(config.password()).isNull(); | ||||
settings.setProperty(SvnConfiguration.USER_PROP_KEY, "foo"); | |||||
settings.setProperty(SvnProperties.USER_PROP_KEY, "foo"); | |||||
assertThat(config.username()).isEqualTo("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"); | 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.passPhrase()).isEqualTo("pass"); | ||||
assertThat(config.privateKey()).isNull(); | assertThat(config.privateKey()).isNull(); | ||||
File fakeKey = temp.newFile(); | 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); | 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 { | try { | ||||
config.privateKey(); | config.privateKey(); | ||||
fail("Expected exception"); | fail("Expected exception"); |
import static org.sonar.scm.svn.SvnScmSupport.newSvnClientManager; | import static org.sonar.scm.svn.SvnScmSupport.newSvnClientManager; | ||||
public class SvnScmSupportTest { | public class SvnScmSupportTest { | ||||
private SvnConfiguration config = mock(SvnConfiguration.class); | |||||
@Test | @Test | ||||
public void getExtensions() { | public void getExtensions() { | ||||
assertThat(SvnScmSupport.getObjects()).isNotEmpty(); | assertThat(SvnScmSupport.getObjects()).isNotEmpty(); | ||||
@Test | @Test | ||||
public void newSvnClientManager_with_auth() { | public void newSvnClientManager_with_auth() { | ||||
SvnConfiguration config = mock(SvnConfiguration.class); | |||||
when(config.password()).thenReturn("password"); | when(config.password()).thenReturn("password"); | ||||
when(config.passPhrase()).thenReturn("passPhrase"); | when(config.passPhrase()).thenReturn("passPhrase"); | ||||
assertThat(newSvnClientManager(config)).isNotNull(); | assertThat(newSvnClientManager(config)).isNotNull(); | ||||
@Test | @Test | ||||
public void newSvnClientManager_without_auth() { | public void newSvnClientManager_without_auth() { | ||||
SvnConfiguration config = mock(SvnConfiguration.class); | |||||
assertThat(config.password()).isNull(); | assertThat(config.password()).isNull(); | ||||
assertThat(config.passPhrase()).isNull(); | assertThat(config.passPhrase()).isNull(); | ||||
assertThat(newSvnClientManager(config)).isNotNull(); | assertThat(newSvnClientManager(config)).isNotNull(); |