@@ -19,8 +19,7 @@ | |||
*/ | |||
package org.sonar.xoo; | |||
import java.util.Arrays; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.resources.Language; | |||
public class Xoo implements Language { | |||
@@ -30,10 +29,10 @@ public class Xoo implements Language { | |||
public static final String FILE_SUFFIXES_KEY = "sonar.xoo.file.suffixes"; | |||
public static final String DEFAULT_FILE_SUFFIXES = ".xoo"; | |||
private final Settings settings; | |||
private final Configuration config; | |||
public Xoo(Settings settings) { | |||
this.settings = settings; | |||
public Xoo(Configuration config) { | |||
this.config = config; | |||
} | |||
@Override | |||
@@ -48,6 +47,6 @@ public class Xoo implements Language { | |||
@Override | |||
public String[] getFileSuffixes() { | |||
return Arrays.stream(settings.getStringArray(FILE_SUFFIXES_KEY)).filter(s -> s != null && !s.trim().isEmpty()).toArray(String[]::new); | |||
return config.getStringArray(FILE_SUFFIXES_KEY); | |||
} | |||
} |
@@ -93,6 +93,7 @@ public class XooPlugin implements Plugin { | |||
.description("Comma-separated list of suffixes for files to analyze. To not filter, leave the list empty.") | |||
.subCategory("General") | |||
.onQualifiers(Qualifiers.PROJECT) | |||
.multiValues(true) | |||
.build(), | |||
// Used by DuplicationsTest and IssueFilterOnCommonRulesTest. If not declared it is not returned by api/settings | |||
PropertyDefinition.builder("sonar.cpd.xoo.minimumTokens") |
@@ -22,19 +22,12 @@ package org.sonar.xoo.extensions; | |||
import java.io.File; | |||
import org.sonar.api.batch.bootstrap.ProjectBuilder; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.config.Settings; | |||
public class XooProjectBuilder extends ProjectBuilder { | |||
private Settings settings; | |||
public XooProjectBuilder(Settings settings) { | |||
this.settings = settings; | |||
} | |||
@Override | |||
public void build(Context context) { | |||
if (!settings.getBoolean("sonar.xoo.enableProjectBuilder")) { | |||
if (!context.config().getBoolean("sonar.xoo.enableProjectBuilder").orElse(false)) { | |||
return; | |||
} | |||
ProjectDefinition root = context.projectReactor().getRoot(); |
@@ -50,7 +50,7 @@ public class ChecksSensor implements Sensor { | |||
@Override | |||
public void execute(SensorContext context) { | |||
Checks<Check> checks = checkFactory.create(XooRulesDefinition.XOO_REPOSITORY); | |||
checks.addAnnotatedChecks(Check.ALL); | |||
checks.addAnnotatedChecks((Object[]) Check.ALL); | |||
FilePredicates p = context.fileSystem().predicates(); | |||
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) { | |||
for (Check check : checks.all()) { |
@@ -53,7 +53,7 @@ public class CreateIssueByInternalKeySensor implements Sensor { | |||
private static void createIssues(InputFile file, SensorContext context) { | |||
ActiveRule rule = context.activeRules().findByInternalKey(XooRulesDefinition.XOO_REPOSITORY, | |||
context.settings().getString(INTERNAL_KEY_PROPERTY)); | |||
context.config().get(INTERNAL_KEY_PROPERTY).orElse(null)); | |||
if (rule != null) { | |||
NewIssue newIssue = context.newIssue(); | |||
newIssue |
@@ -67,7 +67,7 @@ public class HasTagSensor extends AbstractXooRuleSensor { | |||
NewIssue newIssue = context.newIssue(); | |||
newIssue | |||
.forRule(ruleKey) | |||
.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)) | |||
.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)) | |||
.at(newIssue.newLocation() | |||
.on(inputFile) | |||
.at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))) |
@@ -63,7 +63,7 @@ public class OneIssuePerLineSensor implements Sensor { | |||
private void createIssues(InputFile file, SensorContext context, String repo) { | |||
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); | |||
String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY); | |||
String severity = context.config().get(FORCE_SEVERITY_PROPERTY).orElse(null); | |||
for (int line = 1; line <= file.lines(); line++) { | |||
NewIssue newIssue = context.newIssue(); | |||
newIssue | |||
@@ -74,9 +74,9 @@ public class OneIssuePerLineSensor implements Sensor { | |||
.message("This issue is generated on each line")) | |||
.overrideSeverity(severity != null ? Severity.valueOf(severity) : null); | |||
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) { | |||
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)); | |||
newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); | |||
} else { | |||
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)); | |||
newIssue.gap(context.config().getDouble(EFFORT_TO_FIX_PROPERTY).orElse(null)); | |||
} | |||
newIssue.save(); | |||
} |
@@ -49,7 +49,7 @@ public class RandomAccessSensor implements Sensor { | |||
@Override | |||
public void execute(SensorContext context) { | |||
File f = new File(context.settings().getString(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS)); | |||
File f = new File(context.config().get(SONAR_XOO_RANDOM_ACCESS_ISSUE_PATHS).orElseThrow(() -> new IllegalStateException("Required property"))); | |||
FileSystem fs = context.fileSystem(); | |||
FilePredicates p = fs.predicates(); | |||
try { |
@@ -35,7 +35,6 @@ import javax.security.auth.login.Configuration; | |||
import javax.security.auth.login.LoginContext; | |||
import javax.security.auth.login.LoginException; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
@@ -75,15 +74,15 @@ public class LdapContextFactory { | |||
private final String realm; | |||
private final String referral; | |||
public LdapContextFactory(Settings settings, String settingsPrefix, String ldapUrl) { | |||
this.authentication = StringUtils.defaultString(settings.getString(settingsPrefix + ".authentication"), DEFAULT_AUTHENTICATION); | |||
this.factory = StringUtils.defaultString(settings.getString(settingsPrefix + ".contextFactoryClass"), DEFAULT_FACTORY); | |||
this.realm = settings.getString(settingsPrefix + ".realm"); | |||
public LdapContextFactory(org.sonar.api.config.Configuration config, String settingsPrefix, String ldapUrl) { | |||
this.authentication = StringUtils.defaultString(config.get(settingsPrefix + ".authentication").orElse(null), DEFAULT_AUTHENTICATION); | |||
this.factory = StringUtils.defaultString(config.get(settingsPrefix + ".contextFactoryClass").orElse(null), DEFAULT_FACTORY); | |||
this.realm = config.get(settingsPrefix + ".realm").orElse(null); | |||
this.providerUrl = ldapUrl; | |||
this.startTLS = settings.getBoolean(settingsPrefix + ".StartTLS"); | |||
this.username = settings.getString(settingsPrefix + ".bindDn"); | |||
this.password = settings.getString(settingsPrefix + ".bindPassword"); | |||
this.referral = getReferralsMode(settings, settingsPrefix + ".followReferrals"); | |||
this.startTLS = config.getBoolean(settingsPrefix + ".StartTLS").orElse(false); | |||
this.username = config.get(settingsPrefix + ".bindDn").orElse(null); | |||
this.password = config.get(settingsPrefix + ".bindPassword").orElse(null); | |||
this.referral = getReferralsMode(config, settingsPrefix + ".followReferrals"); | |||
} | |||
/** | |||
@@ -224,12 +223,9 @@ public class LdapContextFactory { | |||
return referral; | |||
} | |||
private static String getReferralsMode(Settings settings, String followReferralsSettingKey) { | |||
if (settings.hasKey(followReferralsSettingKey)) { | |||
return settings.getBoolean(followReferralsSettingKey) ? REFERRALS_FOLLOW_MODE : REFERRALS_IGNORE_MODE; | |||
} | |||
private static String getReferralsMode(org.sonar.api.config.Configuration config, String followReferralsSettingKey) { | |||
// By default follow referrals | |||
return REFERRALS_FOLLOW_MODE; | |||
return config.getBoolean(followReferralsSettingKey).orElse(true) ? REFERRALS_FOLLOW_MODE : REFERRALS_IGNORE_MODE; | |||
} | |||
@Override |
@@ -24,7 +24,7 @@ import javax.naming.NamingException; | |||
import javax.naming.directory.Attribute; | |||
import javax.naming.directory.SearchResult; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
/** | |||
* @author Evgeny Mandrikov | |||
@@ -42,11 +42,11 @@ public class LdapGroupMapping { | |||
/** | |||
* Constructs mapping from Sonar settings. | |||
*/ | |||
public LdapGroupMapping(Settings settings, String settingsPrefix) { | |||
this.baseDn = settings.getString(settingsPrefix + ".group.baseDn"); | |||
this.idAttribute = StringUtils.defaultString(settings.getString(settingsPrefix + ".group.idAttribute"), DEFAULT_ID_ATTRIBUTE); | |||
public LdapGroupMapping(Configuration config, String settingsPrefix) { | |||
this.baseDn = config.get(settingsPrefix + ".group.baseDn").orElse(null); | |||
this.idAttribute = StringUtils.defaultString(config.get(settingsPrefix + ".group.idAttribute").orElse(null), DEFAULT_ID_ATTRIBUTE); | |||
String req = StringUtils.defaultString(settings.getString(settingsPrefix + ".group.request"), DEFAULT_REQUEST); | |||
String req = StringUtils.defaultString(config.get(settingsPrefix + ".group.request").orElse(null), DEFAULT_REQUEST); | |||
this.requiredUserAttributes = StringUtils.substringsBetween(req, "{", "}"); | |||
for (int i = 0; i < requiredUserAttributes.length; i++) { | |||
req = StringUtils.replace(req, "{" + requiredUserAttributes[i] + "}", "{" + i + "}"); |
@@ -23,7 +23,7 @@ import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
@@ -42,7 +42,7 @@ public class LdapSettingsManager { | |||
private static final String LDAP_SERVERS_PROPERTY = "ldap.servers"; | |||
private static final String LDAP_PROPERTY_PREFIX = "ldap"; | |||
private static final String DEFAULT_LDAP_SERVER_KEY = "<default>"; | |||
private final Settings settings; | |||
private final Configuration config; | |||
private final LdapAutodiscovery ldapAutodiscovery; | |||
private Map<String, LdapUserMapping> userMappings = null; | |||
private Map<String, LdapGroupMapping> groupMappings = null; | |||
@@ -51,10 +51,10 @@ public class LdapSettingsManager { | |||
/** | |||
* Create an instance of the settings manager. | |||
* | |||
* @param settings The settings to use. | |||
* @param config The config to use. | |||
*/ | |||
public LdapSettingsManager(Settings settings, LdapAutodiscovery ldapAutodiscovery) { | |||
this.settings = settings; | |||
public LdapSettingsManager(Configuration config, LdapAutodiscovery ldapAutodiscovery) { | |||
this.config = config; | |||
this.ldapAutodiscovery = ldapAutodiscovery; | |||
} | |||
@@ -68,10 +68,10 @@ public class LdapSettingsManager { | |||
if (userMappings == null) { | |||
// Use linked hash map to preserve order | |||
userMappings = new LinkedHashMap<>(); | |||
String[] serverKeys = settings.getStringArray(LDAP_SERVERS_PROPERTY); | |||
String[] serverKeys = config.getStringArray(LDAP_SERVERS_PROPERTY); | |||
if (serverKeys.length > 0) { | |||
for (String serverKey : serverKeys) { | |||
LdapUserMapping userMapping = new LdapUserMapping(settings, LDAP_PROPERTY_PREFIX + "." + serverKey); | |||
LdapUserMapping userMapping = new LdapUserMapping(config, LDAP_PROPERTY_PREFIX + "." + serverKey); | |||
if (StringUtils.isNotBlank(userMapping.getBaseDn())) { | |||
LOG.info("User mapping for server {}: {}", serverKey, userMapping); | |||
userMappings.put(serverKey, userMapping); | |||
@@ -81,7 +81,7 @@ public class LdapSettingsManager { | |||
} | |||
} else { | |||
// Backward compatibility with single server configuration | |||
LdapUserMapping userMapping = new LdapUserMapping(settings, LDAP_PROPERTY_PREFIX); | |||
LdapUserMapping userMapping = new LdapUserMapping(config, LDAP_PROPERTY_PREFIX); | |||
if (StringUtils.isNotBlank(userMapping.getBaseDn())) { | |||
LOG.info("User mapping: {}", userMapping); | |||
userMappings.put(DEFAULT_LDAP_SERVER_KEY, userMapping); | |||
@@ -103,10 +103,10 @@ public class LdapSettingsManager { | |||
if (groupMappings == null) { | |||
// Use linked hash map to preserve order | |||
groupMappings = new LinkedHashMap<>(); | |||
String[] serverKeys = settings.getStringArray(LDAP_SERVERS_PROPERTY); | |||
String[] serverKeys = config.getStringArray(LDAP_SERVERS_PROPERTY); | |||
if (serverKeys.length > 0) { | |||
for (String serverKey : serverKeys) { | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(settings, LDAP_PROPERTY_PREFIX + "." + serverKey); | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(config, LDAP_PROPERTY_PREFIX + "." + serverKey); | |||
if (StringUtils.isNotBlank(groupMapping.getBaseDn())) { | |||
LOG.info("Group mapping for server {}: {}", serverKey, groupMapping); | |||
groupMappings.put(serverKey, groupMapping); | |||
@@ -116,7 +116,7 @@ public class LdapSettingsManager { | |||
} | |||
} else { | |||
// Backward compatibility with single server configuration | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(settings, LDAP_PROPERTY_PREFIX); | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(config, LDAP_PROPERTY_PREFIX); | |||
if (StringUtils.isNotBlank(groupMapping.getBaseDn())) { | |||
LOG.info("Group mapping: {}", groupMapping); | |||
groupMappings.put(DEFAULT_LDAP_SERVER_KEY, groupMapping); | |||
@@ -138,7 +138,7 @@ public class LdapSettingsManager { | |||
if (contextFactories == null) { | |||
// Use linked hash map to preserve order | |||
contextFactories = new LinkedHashMap<>(); | |||
String[] serverKeys = settings.getStringArray(LDAP_SERVERS_PROPERTY); | |||
String[] serverKeys = config.getStringArray(LDAP_SERVERS_PROPERTY); | |||
if (serverKeys.length > 0) { | |||
initMultiLdapConfiguration(serverKeys); | |||
} else { | |||
@@ -149,9 +149,9 @@ public class LdapSettingsManager { | |||
} | |||
private void initSimpleLdapConfiguration() { | |||
String realm = settings.getString(LDAP_PROPERTY_PREFIX + ".realm"); | |||
String realm = config.get(LDAP_PROPERTY_PREFIX + ".realm").orElse(null); | |||
String ldapUrlKey = LDAP_PROPERTY_PREFIX + ".url"; | |||
String ldapUrl = settings.getString(ldapUrlKey); | |||
String ldapUrl = config.get(ldapUrlKey).orElse(null); | |||
if (ldapUrl == null && realm != null) { | |||
LOG.warn("Auto-discovery feature is deprecated, please use '{}' to specify LDAP url", ldapUrlKey); | |||
List<LdapSrvRecord> ldapServers = ldapAutodiscovery.getLdapServers(realm); | |||
@@ -162,7 +162,7 @@ public class LdapSettingsManager { | |||
for (LdapSrvRecord ldapSrvRecord : ldapServers) { | |||
if (StringUtils.isNotBlank(ldapSrvRecord.getServerUrl())) { | |||
LOG.info("Detected server: {}", ldapSrvRecord.getServerUrl()); | |||
LdapContextFactory contextFactory = new LdapContextFactory(settings, LDAP_PROPERTY_PREFIX, ldapSrvRecord.getServerUrl()); | |||
LdapContextFactory contextFactory = new LdapContextFactory(config, LDAP_PROPERTY_PREFIX, ldapSrvRecord.getServerUrl()); | |||
contextFactories.put(DEFAULT_LDAP_SERVER_KEY + index, contextFactory); | |||
index++; | |||
} | |||
@@ -171,24 +171,24 @@ public class LdapSettingsManager { | |||
if (StringUtils.isBlank(ldapUrl)) { | |||
throw new LdapException(String.format("The property '%s' is empty and no realm configured to try auto-discovery.", ldapUrlKey)); | |||
} | |||
LdapContextFactory contextFactory = new LdapContextFactory(settings, LDAP_PROPERTY_PREFIX, ldapUrl); | |||
LdapContextFactory contextFactory = new LdapContextFactory(config, LDAP_PROPERTY_PREFIX, ldapUrl); | |||
contextFactories.put(DEFAULT_LDAP_SERVER_KEY, contextFactory); | |||
} | |||
} | |||
private void initMultiLdapConfiguration(String[] serverKeys) { | |||
if (settings.hasKey("ldap.url") || settings.hasKey("ldap.realm")) { | |||
if (config.hasKey("ldap.url") || config.hasKey("ldap.realm")) { | |||
throw new LdapException("When defining multiple LDAP servers with the property '" + LDAP_SERVERS_PROPERTY + "', " | |||
+ "all LDAP properties must be linked to one of those servers. Please remove properties like 'ldap.url', 'ldap.realm', ..."); | |||
} | |||
for (String serverKey : serverKeys) { | |||
String prefix = LDAP_PROPERTY_PREFIX + "." + serverKey; | |||
String ldapUrlKey = prefix + ".url"; | |||
String ldapUrl = settings.getString(ldapUrlKey); | |||
String ldapUrl = config.get(ldapUrlKey).orElse(null); | |||
if (StringUtils.isBlank(ldapUrl)) { | |||
throw new LdapException(String.format("The property '%s' property is empty while it is mandatory.", ldapUrlKey)); | |||
} | |||
LdapContextFactory contextFactory = new LdapContextFactory(settings, prefix, ldapUrl); | |||
LdapContextFactory contextFactory = new LdapContextFactory(config, prefix, ldapUrl); | |||
contextFactories.put(serverKey, contextFactory); | |||
} | |||
} |
@@ -20,7 +20,7 @@ | |||
package org.sonar.auth.ldap; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
@@ -43,11 +43,11 @@ public class LdapUserMapping { | |||
/** | |||
* Constructs mapping from Sonar settings. | |||
*/ | |||
public LdapUserMapping(Settings settings, String settingsPrefix) { | |||
public LdapUserMapping(Configuration config, String settingsPrefix) { | |||
String usesrBaseDnSettingKey = settingsPrefix + ".user.baseDn"; | |||
String usersBaseDn = settings.getString(usesrBaseDnSettingKey); | |||
String usersBaseDn = config.get(usesrBaseDnSettingKey).orElse(null); | |||
if (usersBaseDn == null) { | |||
String realm = settings.getString(settingsPrefix + ".realm"); | |||
String realm = config.get(settingsPrefix + ".realm").orElse(null); | |||
if (realm != null) { | |||
LOG.warn("Auto-discovery feature is deprecated, please use '{}' to specify user search dn", usesrBaseDnSettingKey); | |||
usersBaseDn = LdapAutodiscovery.getDnsDomainDn(realm); | |||
@@ -55,10 +55,10 @@ public class LdapUserMapping { | |||
} | |||
this.baseDn = usersBaseDn; | |||
this.realNameAttribute = StringUtils.defaultString(settings.getString(settingsPrefix + ".user.realNameAttribute"), DEFAULT_NAME_ATTRIBUTE); | |||
this.emailAttribute = StringUtils.defaultString(settings.getString(settingsPrefix + ".user.emailAttribute"), DEFAULT_EMAIL_ATTRIBUTE); | |||
this.realNameAttribute = StringUtils.defaultString(config.get(settingsPrefix + ".user.realNameAttribute").orElse(null), DEFAULT_NAME_ATTRIBUTE); | |||
this.emailAttribute = StringUtils.defaultString(config.get(settingsPrefix + ".user.emailAttribute").orElse(null), DEFAULT_EMAIL_ATTRIBUTE); | |||
String req = StringUtils.defaultString(settings.getString(settingsPrefix + ".user.request"), DEFAULT_REQUEST); | |||
String req = StringUtils.defaultString(config.get(settingsPrefix + ".user.request").orElse(null), DEFAULT_REQUEST); | |||
req = StringUtils.replace(req, "{login}", "{0}"); | |||
this.request = req; | |||
} |
@@ -44,7 +44,7 @@ public class KerberosTest { | |||
@Test | |||
public void test() { | |||
MapSettings settings = configure(); | |||
LdapRealm ldapRealm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm ldapRealm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
ldapRealm.init(); | |||
@@ -61,7 +61,7 @@ public class KerberosTest { | |||
public void wrong_bind_password() { | |||
MapSettings settings = configure() | |||
.setProperty("ldap.bindPassword", "wrong_bind_password"); | |||
LdapRealm ldapRealm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm ldapRealm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
try { | |||
ldapRealm.init(); | |||
Assert.fail(); |
@@ -44,7 +44,7 @@ public class LdapAuthenticatorTest { | |||
public void testNoConnection() { | |||
exampleServer.disableAnonymousAccess(); | |||
try { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_SIMPLE), | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_SIMPLE).asConfig(), | |||
new LdapAutodiscovery()); | |||
LdapAuthenticator authenticator = new LdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
authenticator.authenticate("godin", "secret1"); | |||
@@ -55,7 +55,7 @@ public class LdapAuthenticatorTest { | |||
@Test | |||
public void testSimple() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_SIMPLE), | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_SIMPLE).asConfig(), | |||
new LdapAutodiscovery()); | |||
LdapAuthenticator authenticator = new LdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
@@ -74,7 +74,7 @@ public class LdapAuthenticatorTest { | |||
@Test | |||
public void testSimpleMultiLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_SIMPLE), new LdapAutodiscovery()); | |||
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_SIMPLE).asConfig(), new LdapAutodiscovery()); | |||
LdapAuthenticator authenticator = new LdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
assertThat(authenticator.authenticate("godin", "secret1")).isTrue(); | |||
@@ -95,7 +95,7 @@ public class LdapAuthenticatorTest { | |||
@Test | |||
public void testSasl() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_CRAM_MD5), | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(LdapSettingsFactory.generateAuthenticationSettings(exampleServer, null, LdapContextFactory.AUTH_METHOD_CRAM_MD5).asConfig(), | |||
new LdapAutodiscovery()); | |||
LdapAuthenticator authenticator = new LdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
@@ -111,7 +111,7 @@ public class LdapAuthenticatorTest { | |||
@Test | |||
public void testSaslMultipleLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_CRAM_MD5), new LdapAutodiscovery()); | |||
LdapSettingsFactory.generateAuthenticationSettings(exampleServer, infosupportServer, LdapContextFactory.AUTH_METHOD_CRAM_MD5).asConfig(), new LdapAutodiscovery()); | |||
LdapAuthenticator authenticator = new LdapAuthenticator(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
assertThat(authenticator.authenticate("godin", "secret1")).isTrue(); |
@@ -45,7 +45,7 @@ public class LdapAutoDiscoveryWarningLogTest { | |||
public void does_not_display_log_when_not_using_auto_discovery() { | |||
MapSettings settings = new MapSettings() | |||
.setProperty("ldap.url", server.getUrl()); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
assertThat(realm.getName()).isEqualTo("LDAP"); | |||
realm.init(); | |||
@@ -58,7 +58,7 @@ public class LdapAutoDiscoveryWarningLogTest { | |||
LdapAutodiscovery ldapAutodiscovery = mock(LdapAutodiscovery.class); | |||
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(singletonList(new LdapAutodiscovery.LdapSrvRecord(server.getUrl(), 1, 1))); | |||
// ldap.url setting is not set | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(new MapSettings().setProperty("ldap.realm", "example.org"), | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(new MapSettings().setProperty("ldap.realm", "example.org").asConfig(), | |||
ldapAutodiscovery)); | |||
realm.init(); | |||
@@ -70,7 +70,7 @@ public class LdapAutoDiscoveryWarningLogTest { | |||
public void display_warning_log_when_using_auto_discovery_to_detect_user_baseDn_on_single_server() { | |||
// ldap.user.baseDn setting is not set | |||
MapSettings settings = new MapSettings().setProperty("ldap.url", server.getUrl()).setProperty("ldap.realm", "example.org"); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
realm.init(); | |||
@@ -88,7 +88,7 @@ public class LdapAutoDiscoveryWarningLogTest { | |||
.setProperty("ldap.example.realm", "example.org") | |||
.setProperty("ldap.infosupport.url", server2.getUrl()) | |||
.setProperty("ldap.infosupport.realm", "infosupport.org"); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
realm.init(); | |||
@@ -28,7 +28,7 @@ public class LdapGroupMappingTest { | |||
@Test | |||
public void defaults() { | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(new MapSettings(), "ldap"); | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(new MapSettings().asConfig(), "ldap"); | |||
assertThat(groupMapping.getBaseDn()).isNull(); | |||
assertThat(groupMapping.getIdAttribute()).isEqualTo("cn"); | |||
@@ -46,7 +46,7 @@ public class LdapGroupMappingTest { | |||
public void custom_request() { | |||
MapSettings settings = new MapSettings() | |||
.setProperty("ldap.group.request", "(&(|(objectClass=posixGroup)(objectClass=groupOfUniqueNames))(|(memberUid={uid})(uniqueMember={dn})))"); | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(settings, "ldap"); | |||
LdapGroupMapping groupMapping = new LdapGroupMapping(settings.asConfig(), "ldap"); | |||
assertThat(groupMapping.getRequest()).isEqualTo("(&(|(objectClass=posixGroup)(objectClass=groupOfUniqueNames))(|(memberUid={0})(uniqueMember={1})))"); | |||
assertThat(groupMapping.getRequiredUserAttributes()).isEqualTo(new String[] {"uid", "dn"}); |
@@ -47,7 +47,7 @@ public class LdapGroupsProviderTest { | |||
public void defaults() { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, null); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; | |||
@@ -65,7 +65,7 @@ public class LdapGroupsProviderTest { | |||
public void defaultsMultipleLdap() { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; | |||
@@ -90,7 +90,7 @@ public class LdapGroupsProviderTest { | |||
public void posix() { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, null); | |||
settings.setProperty("ldap.group.request", "(&(objectClass=posixGroup)(memberUid={uid}))"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; | |||
@@ -104,7 +104,7 @@ public class LdapGroupsProviderTest { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
settings.setProperty("ldap.example.group.request", "(&(objectClass=posixGroup)(memberUid={uid}))"); | |||
settings.setProperty("ldap.infosupport.group.request", "(&(objectClass=posixGroup)(memberUid={uid}))"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; | |||
@@ -120,7 +120,7 @@ public class LdapGroupsProviderTest { | |||
public void mixed() { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
settings.setProperty("ldap.example.group.request", "(&(|(objectClass=groupOfUniqueNames)(objectClass=posixGroup))(|(uniqueMember={dn})(memberUid={uid})))"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; | |||
@@ -134,7 +134,7 @@ public class LdapGroupsProviderTest { | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
settings.setProperty("ldap.example.group.request", "(&(|(objectClass=groupOfUniqueNames)(objectClass=posixGroup))(|(uniqueMember={dn})(memberUid={uid})))"); | |||
settings.setProperty("ldap.infosupport.group.request", "(&(|(objectClass=groupOfUniqueNames)(objectClass=posixGroup))(|(uniqueMember={dn})(memberUid={uid})))"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapGroupsProvider groupsProvider = new LdapGroupsProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings(), settingsManager.getGroupMappings()); | |||
Collection<String> groups; |
@@ -40,7 +40,7 @@ public class LdapRealmTest { | |||
public void normal() { | |||
MapSettings settings = new MapSettings() | |||
.setProperty("ldap.url", server.getUrl()); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
assertThat(realm.getName()).isEqualTo("LDAP"); | |||
realm.init(); | |||
assertThat(realm.doGetAuthenticator()).isInstanceOf(LdapAuthenticator.class); | |||
@@ -53,7 +53,7 @@ public class LdapRealmTest { | |||
MapSettings settings = new MapSettings() | |||
.setProperty("ldap.url", "ldap://no-such-host") | |||
.setProperty("ldap.group.baseDn", "cn=groups,dc=example,dc=org"); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings, new LdapAutodiscovery())); | |||
LdapRealm realm = new LdapRealm(new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery())); | |||
assertThat(realm.getName()).isEqualTo("LDAP"); | |||
try { | |||
realm.init(); |
@@ -23,7 +23,7 @@ import java.util.Map; | |||
import javax.annotation.Nullable; | |||
import org.junit.ClassRule; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.auth.ldap.server.LdapServer; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -60,10 +60,10 @@ public class LdapReferralsTest { | |||
} | |||
private static Map<String, LdapContextFactory> createFactories(@Nullable String propertyKey, @Nullable String propertyValue) { | |||
Settings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(server, null); | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(server, null); | |||
if (propertyKey != null) { | |||
settings.setProperty(propertyKey, propertyValue); | |||
} | |||
return new LdapSettingsManager(settings, new LdapAutodiscovery()).getContextFactories(); | |||
return new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()).getContextFactories(); | |||
} | |||
} |
@@ -45,7 +45,7 @@ public class LdapSearchTest { | |||
@BeforeClass | |||
public static void init() { | |||
contextFactories = new LdapSettingsManager(LdapSettingsFactory.generateSimpleAnonymousAccessSettings(server, null), new LdapAutodiscovery()).getContextFactories(); | |||
contextFactories = new LdapSettingsManager(LdapSettingsFactory.generateSimpleAnonymousAccessSettings(server, null).asConfig(), new LdapAutodiscovery()).getContextFactories(); | |||
} | |||
@Test |
@@ -24,7 +24,6 @@ import java.util.Collections; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -39,9 +38,9 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void shouldFailWhenNoLdapUrl() { | |||
Settings settings = generateMultipleLdapSettingsWithUserAndGroupMapping(); | |||
MapSettings settings = generateMultipleLdapSettingsWithUserAndGroupMapping(); | |||
settings.removeProperty("ldap.example.url"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.example.url' property is empty while it is mandatory."); | |||
@@ -50,9 +49,9 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void shouldFailWhenMixingSingleAndMultipleConfiguration() { | |||
Settings settings = generateMultipleLdapSettingsWithUserAndGroupMapping(); | |||
MapSettings settings = generateMultipleLdapSettingsWithUserAndGroupMapping(); | |||
settings.setProperty("ldap.url", "ldap://foo"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown | |||
@@ -64,7 +63,7 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void testContextFactoriesWithSingleLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateSingleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
generateSingleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(1); | |||
} | |||
@@ -75,7 +74,7 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void testContextFactoriesWithMultipleLdap() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); | |||
// We do it twice to make sure the settings keep the same. | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); | |||
@@ -88,7 +87,7 @@ public class LdapSettingsManagerTest { | |||
LdapSrvRecord ldap2 = new LdapSrvRecord("ldap://localhost:1899", 1, 1); | |||
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Arrays.asList(ldap1, ldap2)); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateAutodiscoverSettings(), ldapAutodiscovery); | |||
generateAutodiscoverSettings().asConfig(), ldapAutodiscovery); | |||
assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); | |||
} | |||
@@ -97,7 +96,7 @@ public class LdapSettingsManagerTest { | |||
LdapAutodiscovery ldapAutodiscovery = mock(LdapAutodiscovery.class); | |||
when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Collections.emptyList()); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateAutodiscoverSettings(), ldapAutodiscovery); | |||
generateAutodiscoverSettings().asConfig(), ldapAutodiscovery); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.url' is empty and SonarQube is not able to auto-discover any LDAP server."); | |||
@@ -112,7 +111,7 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void testUserMappings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getUserMappings().size()).isEqualTo(2); | |||
// We do it twice to make sure the settings keep the same. | |||
assertThat(settingsManager.getUserMappings().size()).isEqualTo(2); | |||
@@ -125,7 +124,7 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void testGroupMappings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateMultipleLdapSettingsWithUserAndGroupMapping(), new LdapAutodiscovery()); | |||
generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); | |||
assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2); | |||
// We do it twice to make sure the settings keep the same. | |||
assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2); | |||
@@ -138,7 +137,7 @@ public class LdapSettingsManagerTest { | |||
@Test | |||
public void testEmptySettings() { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
new MapSettings(), new LdapAutodiscovery()); | |||
new MapSettings().asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.url' is empty and no realm configured to try auto-discovery."); |
@@ -28,7 +28,7 @@ public class LdapUserMappingTest { | |||
@Test | |||
public void defaults() { | |||
LdapUserMapping userMapping = new LdapUserMapping(new MapSettings(), "ldap"); | |||
LdapUserMapping userMapping = new LdapUserMapping(new MapSettings().asConfig(), "ldap"); | |||
assertThat(userMapping.getBaseDn()).isNull(); | |||
assertThat(userMapping.getRequest()).isEqualTo("(&(objectClass=inetOrgPerson)(uid={0}))"); | |||
assertThat(userMapping.getRealNameAttribute()).isEqualTo("cn"); | |||
@@ -47,7 +47,7 @@ public class LdapUserMappingTest { | |||
.setProperty("ldap.user.baseDn", "cn=users") | |||
.setProperty("ldap.user.request", "(&(objectClass=user)(sAMAccountName={0}))"); | |||
LdapUserMapping userMapping = new LdapUserMapping(settings, "ldap"); | |||
LdapUserMapping userMapping = new LdapUserMapping(settings.asConfig(), "ldap"); | |||
LdapSearch search = userMapping.createSearch(null, "tester"); | |||
assertThat(search.getBaseDn()).isEqualTo("cn=users"); | |||
assertThat(search.getRequest()).isEqualTo("(&(objectClass=user)(sAMAccountName={0}))"); | |||
@@ -68,7 +68,7 @@ public class LdapUserMappingTest { | |||
.setProperty("ldap.userObjectClass", "user") | |||
.setProperty("ldap.loginAttribute", "sAMAccountName"); | |||
LdapUserMapping userMapping = new LdapUserMapping(settings, "ldap"); | |||
LdapUserMapping userMapping = new LdapUserMapping(settings.asConfig(), "ldap"); | |||
assertThat(userMapping.getBaseDn()).isEqualTo("dc=example,dc=org"); | |||
} | |||
@@ -21,7 +21,7 @@ package org.sonar.auth.ldap; | |||
import org.junit.ClassRule; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.security.UserDetails; | |||
import org.sonar.auth.ldap.server.LdapServer; | |||
@@ -44,8 +44,8 @@ public class LdapUsersProviderTest { | |||
@Test | |||
public void test() { | |||
Settings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings, new LdapAutodiscovery()); | |||
MapSettings settings = LdapSettingsFactory.generateSimpleAnonymousAccessSettings(exampleServer, infosupportServer); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
LdapUsersProvider usersProvider = new LdapUsersProvider(settingsManager.getContextFactories(), settingsManager.getUserMappings()); | |||
UserDetails details; |
@@ -21,7 +21,7 @@ package org.sonar.ce.task.projectanalysis.analysis; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.ConfigurationBridge; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.component.BranchType; |
@@ -26,7 +26,7 @@ import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.ce.task.projectanalysis.component.Component; |
@@ -21,13 +21,14 @@ package org.sonar.ce.task.setting; | |||
import org.picocontainer.Startable; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.ce.task.container.EagerStart; | |||
import org.sonar.ce.task.container.TaskContainerImpl; | |||
import org.sonar.server.setting.ThreadLocalSettings; | |||
/** | |||
* Add this class as the first components in the {@link TaskContainerImpl} | |||
* to trigger loading of Thread local specific {@link org.sonar.api.config.Settings} in {@link ThreadLocalSettings}. | |||
* to trigger loading of Thread local specific {@link Settings} in {@link ThreadLocalSettings}. | |||
*/ | |||
@EagerStart | |||
@ComputeEngineSide |
@@ -31,7 +31,7 @@ import javax.sql.DataSource; | |||
import org.apache.commons.dbcp2.BasicDataSource; | |||
import org.apache.commons.dbcp2.BasicDataSourceFactory; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.db.dialect.Dialect; |
@@ -30,7 +30,7 @@ import javax.annotation.Nullable; | |||
import javax.sql.DataSource; | |||
import org.apache.commons.codec.digest.DigestUtils; | |||
import org.junit.AssumptionViolatedException; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; |
@@ -24,7 +24,7 @@ import com.sonar.orchestrator.db.DatabaseClient; | |||
import com.sonar.orchestrator.db.DatabaseFactory; | |||
import com.sonar.orchestrator.db.DefaultDatabase; | |||
import java.util.function.Consumer; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; |
@@ -28,7 +28,7 @@ import java.util.Properties; | |||
import org.apache.commons.io.FileUtils; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.commons.lang.text.StrSubstitutor; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import static org.apache.commons.lang.StringUtils.isEmpty; | |||
@@ -29,7 +29,7 @@ import org.apache.ibatis.io.Resources; | |||
import org.apache.ibatis.jdbc.ScriptRunner; | |||
import org.sonar.api.SonarEdition; | |||
import org.sonar.api.SonarQubeSide; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.internal.SonarRuntimeImpl; | |||
import org.sonar.api.utils.System2; |
@@ -28,7 +28,7 @@ import javax.annotation.Nullable; | |||
import org.apache.commons.codec.digest.DigestUtils; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.junit.AssumptionViolatedException; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.db.dialect.H2; | |||
import org.sonar.process.logging.LogbackHelper; | |||
@@ -25,7 +25,7 @@ import org.apache.commons.lang.ArrayUtils; | |||
import org.picocontainer.injectors.ProviderAdapter; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import static java.util.function.Function.identity; | |||
import static org.sonar.api.config.internal.MultivalueProperty.parseAsCsv; |
@@ -24,7 +24,7 @@ import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.ConfigurationBridge; | |||
import static java.util.Objects.requireNonNull; |
@@ -32,10 +32,10 @@ import java.util.stream.Stream; | |||
import org.apache.ibatis.exceptions.PersistenceException; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.core.util.SettingFormatter; |
@@ -25,7 +25,7 @@ import java.util.Set; | |||
import java.util.function.Function; | |||
import java.util.stream.Collectors; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; |
@@ -21,7 +21,7 @@ package org.sonar.server.platform; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.property.PropertyDto; |
@@ -24,7 +24,7 @@ import java.util.TreeMap; | |||
import org.sonar.api.PropertyType; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.process.systeminfo.Global; | |||
import org.sonar.process.systeminfo.SystemInfoSection; |
@@ -23,7 +23,7 @@ import org.junit.Test; | |||
import org.mockito.invocation.InvocationOnMock; | |||
import org.mockito.stubbing.Answer; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.notifications.Notification; | |||
import org.sonar.api.notifications.NotificationChannel; |
@@ -21,7 +21,7 @@ package org.sonar.server.platform; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbTester; |
@@ -23,7 +23,7 @@ import org.junit.Test; | |||
import org.sonar.api.PropertyType; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; | |||
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.server.setting.ws; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; |
@@ -19,8 +19,8 @@ | |||
*/ | |||
package org.sonar.server.setting.ws; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.server.setting.ws; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; |
@@ -26,7 +26,7 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.server.exceptions.ForbiddenException; |
@@ -27,7 +27,7 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.server.exceptions.BadRequestException; |
@@ -26,7 +26,7 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.server.exceptions.ForbiddenException; |
@@ -77,7 +77,6 @@ import org.sonar.api.batch.sensor.rule.internal.DefaultAdHocRule; | |||
import org.sonar.api.batch.sensor.symbol.NewSymbolTable; | |||
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.ConfigurationBridge; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.internal.MetadataLoader; | |||
@@ -105,7 +104,7 @@ import static java.util.Collections.unmodifiableMap; | |||
*/ | |||
public class SensorContextTester implements SensorContext { | |||
private Settings settings; | |||
private MapSettings settings; | |||
private DefaultFileSystem fs; | |||
private ActiveRules activeRules; | |||
private InMemorySensorStorage sensorStorage; | |||
@@ -132,8 +131,7 @@ public class SensorContextTester implements SensorContext { | |||
return new SensorContextTester(moduleBaseDir); | |||
} | |||
@Override | |||
public Settings settings() { | |||
public MapSettings settings() { | |||
return settings; | |||
} | |||
@@ -142,7 +140,7 @@ public class SensorContextTester implements SensorContext { | |||
return new ConfigurationBridge(settings); | |||
} | |||
public SensorContextTester setSettings(Settings settings) { | |||
public SensorContextTester setSettings(MapSettings settings) { | |||
this.settings = settings; | |||
return this; | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import java.io.File; | |||
import java.io.IOException; |
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import org.apache.commons.codec.binary.Base64; | |||
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
interface Cipher { | |||
String encrypt(String clearText); |
@@ -20,7 +20,6 @@ | |||
package org.sonar.api.config.internal; | |||
import java.util.Optional; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
/** |
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import java.util.HashMap; | |||
import java.util.Locale; |
@@ -23,9 +23,7 @@ import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import static java.util.Collections.unmodifiableMap; | |||
import static java.util.Objects.requireNonNull; |
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
@@ -32,6 +32,9 @@ import javax.annotation.Nullable; | |||
import org.apache.commons.lang.ArrayUtils; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.scanner.ScannerSide; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.api.utils.DateUtils; |
@@ -28,23 +28,22 @@ import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | |||
import org.sonar.api.batch.fs.internal.DefaultInputModule; | |||
import org.sonar.api.batch.fs.internal.DefaultTextPointer; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
import org.sonar.api.batch.rule.ActiveRules; | |||
import org.sonar.api.batch.rule.Severity; | |||
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; | |||
import org.sonar.api.batch.rule.internal.NewActiveRule; | |||
import org.sonar.api.batch.rule.Severity; | |||
import org.sonar.api.batch.sensor.error.AnalysisError; | |||
import org.sonar.api.batch.sensor.error.NewAnalysisError; | |||
import org.sonar.api.batch.sensor.highlighting.TypeOfText; | |||
import org.sonar.api.batch.sensor.issue.NewExternalIssue; | |||
import org.sonar.api.batch.sensor.issue.NewIssue; | |||
import org.sonar.api.batch.sensor.symbol.NewSymbolTable; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | |||
import org.sonar.api.batch.fs.internal.DefaultInputModule; | |||
import org.sonar.api.batch.fs.internal.DefaultTextPointer; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rules.RuleType; | |||
@@ -72,10 +71,10 @@ public class SensorContextTesterTest { | |||
@Test | |||
public void testSettings() { | |||
Settings settings = new MapSettings(); | |||
MapSettings settings = new MapSettings(); | |||
settings.setProperty("foo", "bar"); | |||
tester.setSettings(settings); | |||
assertThat(tester.settings().getString("foo")).isEqualTo("bar"); | |||
assertThat(tester.config().get("foo")).contains("bar"); | |||
} | |||
@Test |
@@ -17,21 +17,19 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import java.io.File; | |||
import java.net.URL; | |||
import java.security.InvalidKeyException; | |||
import java.security.Key; | |||
import javax.crypto.BadPaddingException; | |||
import org.apache.commons.codec.binary.Base64; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import javax.crypto.BadPaddingException; | |||
import java.io.File; | |||
import java.net.URL; | |||
import java.security.InvalidKeyException; | |||
import java.security.Key; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.junit.Assert.fail; | |||
@@ -65,7 +63,7 @@ public class AesCipherTest { | |||
thrown.expect(RuntimeException.class); | |||
thrown.expectMessage("Invalid AES key"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/bad_secret_key.txt"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/bad_secret_key.txt"); | |||
AesCipher cipher = new AesCipher(new File(resource.toURI()).getCanonicalPath()); | |||
cipher.encrypt("this is a secret"); | |||
@@ -75,7 +73,7 @@ public class AesCipherTest { | |||
public void decrypt() throws Exception { | |||
AesCipher cipher = new AesCipher(pathToSecretKey()); | |||
// the following value has been encrypted with the key /org/sonar/api/config/AesCipherTest/aes_secret_key.txt | |||
// the following value has been encrypted with the key /org/sonar/api/config/internal/AesCipherTest/aes_secret_key.txt | |||
String clearText = cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); | |||
assertThat(clearText).isEqualTo("this is a secret"); | |||
@@ -83,7 +81,7 @@ public class AesCipherTest { | |||
@Test | |||
public void decrypt_bad_key() throws Exception { | |||
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/bad_secret_key.txt"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/bad_secret_key.txt"); | |||
AesCipher cipher = new AesCipher(new File(resource.toURI()).getCanonicalPath()); | |||
try { | |||
@@ -97,7 +95,7 @@ public class AesCipherTest { | |||
@Test | |||
public void decrypt_other_key() throws Exception { | |||
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/other_secret_key.txt"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/other_secret_key.txt"); | |||
AesCipher cipher = new AesCipher(new File(resource.toURI()).getCanonicalPath()); | |||
try { | |||
@@ -137,7 +135,7 @@ public class AesCipherTest { | |||
@Test | |||
public void loadSecretKeyFromFile_trim_content() throws Exception { | |||
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/non_trimmed_secret_key.txt"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/non_trimmed_secret_key.txt"); | |||
String path = new File(resource.toURI()).getCanonicalPath(); | |||
AesCipher cipher = new AesCipher(null); | |||
@@ -178,7 +176,7 @@ public class AesCipherTest { | |||
} | |||
private String pathToSecretKey() throws Exception { | |||
URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/aes_secret_key.txt"); | |||
URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/aes_secret_key.txt"); | |||
return new File(resource.toURI()).getCanonicalPath(); | |||
} | |||
} |
@@ -17,7 +17,7 @@ | |||
* 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.config; | |||
package org.sonar.api.config.internal; | |||
import org.junit.Test; | |||
@@ -40,7 +40,6 @@ import org.sonar.api.Property; | |||
import org.sonar.api.PropertyType; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.DateUtils; | |||
import static java.util.Collections.singletonList; |
@@ -9,7 +9,6 @@ apply plugin: 'com.github.johnrengelman.shadow' | |||
dependencies { | |||
// please keep the list grouped by configuration and ordered by name | |||
compile 'commons-codec:commons-codec' | |||
compile 'commons-io:commons-io' | |||
compile 'commons-lang:commons-lang' | |||
compile 'com.google.code.gson:gson' |
@@ -20,6 +20,7 @@ | |||
package org.sonar.api.batch.bootstrap; | |||
import org.sonar.api.ExtensionPoint; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.scanner.ScannerSide; | |||
/** | |||
@@ -40,13 +41,15 @@ import org.sonar.api.scanner.ScannerSide; | |||
@Deprecated | |||
public abstract class ProjectBuilder { | |||
/** | |||
* Plugins can use the implementation {@link org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext} | |||
* for their unit tests. | |||
*/ | |||
@Deprecated | |||
public interface Context { | |||
ProjectReactor projectReactor(); | |||
/** | |||
* Global config (command line arguments, global scanner properties). | |||
* @since 8.3 Only as a replacement for injecting Settings | |||
*/ | |||
Configuration config(); | |||
} | |||
/** |
@@ -22,6 +22,7 @@ package org.sonar.api.batch.bootstrap.internal; | |||
import org.sonar.api.batch.bootstrap.ProjectBuilder; | |||
import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
import org.sonar.api.config.Configuration; | |||
/** | |||
* Context that is passed to {@link org.sonar.api.batch.bootstrap.ProjectBuilder} as parameter. | |||
@@ -34,9 +35,11 @@ import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
public class ProjectBuilderContext implements ProjectBuilder.Context { | |||
private final ProjectReactor reactor; | |||
private final Configuration configuration; | |||
public ProjectBuilderContext(ProjectReactor reactor) { | |||
public ProjectBuilderContext(ProjectReactor reactor, Configuration configuration) { | |||
this.reactor = reactor; | |||
this.configuration = configuration; | |||
} | |||
@Override | |||
@@ -44,4 +47,8 @@ public class ProjectBuilderContext implements ProjectBuilder.Context { | |||
return reactor; | |||
} | |||
@Override | |||
public Configuration config() { | |||
return configuration; | |||
} | |||
} |
@@ -22,7 +22,6 @@ package org.sonar.api.batch.postjob; | |||
import org.sonar.api.batch.AnalysisMode; | |||
import org.sonar.api.batch.postjob.issue.PostJobIssue; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
/** | |||
* See {@link PostJob#execute(PostJobContext)} | |||
@@ -30,12 +29,6 @@ import org.sonar.api.config.Settings; | |||
*/ | |||
public interface PostJobContext { | |||
/** | |||
* @deprecated since 6.5 use {@link #config()} | |||
*/ | |||
@Deprecated | |||
Settings settings(); | |||
/** | |||
* Get configuration of the current project. | |||
* @since 6.5 |
@@ -40,7 +40,6 @@ import org.sonar.api.batch.sensor.rule.AdHocRule; | |||
import org.sonar.api.batch.sensor.rule.NewAdHocRule; | |||
import org.sonar.api.batch.sensor.symbol.NewSymbolTable; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.scanner.fs.InputProject; | |||
import org.sonar.api.scanner.sensor.ProjectSensor; | |||
import org.sonar.api.utils.Version; | |||
@@ -52,12 +51,6 @@ import org.sonar.api.utils.Version; | |||
*/ | |||
public interface SensorContext { | |||
/** | |||
* @deprecated since 6.5 use {@link #config()} | |||
*/ | |||
@Deprecated | |||
Settings settings(); | |||
/** | |||
* Get settings of the project. | |||
* @since 6.5 |
@@ -22,7 +22,7 @@ package org.sonar.api.batch.bootstrap; | |||
import java.io.File; | |||
import org.junit.Test; | |||
import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -36,8 +36,11 @@ public class ProjectBuilderTest { | |||
// this reactor is created and provided by Sonar | |||
final ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create()); | |||
ProjectBuilder builder = new ProjectBuilderSample(new MapSettings()); | |||
builder.build(new ProjectBuilderContext(projectReactor)); | |||
ProjectBuilder builder = new ProjectBuilderSample(); | |||
final MapSettings settings = new MapSettings(); | |||
settings.setProperty("foo", "bar"); | |||
final Configuration configuration = settings.asConfig(); | |||
builder.build(new ProjectBuilderContext(projectReactor, configuration)); | |||
assertThat(projectReactor.getProjects().size(), is(2)); | |||
ProjectDefinition root = projectReactor.getRoot(); | |||
@@ -47,17 +50,12 @@ public class ProjectBuilderTest { | |||
} | |||
final static class ProjectBuilderSample extends ProjectBuilder { | |||
private Settings conf; | |||
public ProjectBuilderSample(Settings conf) { | |||
// A real implementation should for example use the settings | |||
this.conf = conf; | |||
} | |||
@Override | |||
protected void build(ProjectReactor reactor) { | |||
public void build(Context context) { | |||
assertThat(context.config().get("foo")).contains("bar"); | |||
// change name of root project | |||
ProjectDefinition root = reactor.getRoot(); | |||
ProjectDefinition root = context.projectReactor().getRoot(); | |||
root.setName("Name changed by plugin"); | |||
// add sub-project |
@@ -21,7 +21,7 @@ package org.sonar.scanner.bootstrap; | |||
import java.util.Map; | |||
import javax.annotation.concurrent.Immutable; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.scanner.config.DefaultConfiguration; | |||
@@ -24,7 +24,7 @@ import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.annotation.concurrent.Immutable; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
/** | |||
* Properties that are coming from scanner. |
@@ -26,7 +26,7 @@ import java.util.Optional; | |||
import javax.annotation.concurrent.Immutable; | |||
import org.apache.commons.lang.ArrayUtils; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.utils.log.Logger; |
@@ -23,25 +23,17 @@ import org.sonar.api.batch.AnalysisMode; | |||
import org.sonar.api.batch.postjob.PostJobContext; | |||
import org.sonar.api.batch.postjob.issue.PostJobIssue; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
public class DefaultPostJobContext implements PostJobContext { | |||
private final Configuration config; | |||
private final AnalysisMode analysisMode; | |||
private final Settings mutableSettings; | |||
public DefaultPostJobContext(Configuration config, Settings mutableSettings, AnalysisMode analysisMode) { | |||
public DefaultPostJobContext(Configuration config, AnalysisMode analysisMode) { | |||
this.config = config; | |||
this.mutableSettings = mutableSettings; | |||
this.analysisMode = analysisMode; | |||
} | |||
@Override | |||
public Settings settings() { | |||
return mutableSettings; | |||
} | |||
@Override | |||
public Configuration config() { | |||
return config; |
@@ -20,7 +20,7 @@ | |||
package org.sonar.scanner.scan; | |||
import java.util.Map; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.scanner.config.DefaultConfiguration; | |||
@@ -22,7 +22,7 @@ package org.sonar.scanner.scan; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import static java.util.Objects.requireNonNull; | |||
@@ -22,7 +22,7 @@ package org.sonar.scanner.scan; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.scanner.bootstrap.GlobalConfiguration; | |||
import static java.util.Objects.requireNonNull; |
@@ -27,25 +27,28 @@ import org.sonar.api.utils.MessageException; | |||
import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.api.utils.log.Profiler; | |||
import org.sonar.scanner.bootstrap.GlobalConfiguration; | |||
public class ProjectBuildersExecutor { | |||
private static final Logger LOG = Loggers.get(ProjectBuildersExecutor.class); | |||
private final GlobalConfiguration globalConfig; | |||
private final ProjectBuilder[] projectBuilders; | |||
public ProjectBuildersExecutor(ProjectBuilder... projectBuilders) { | |||
public ProjectBuildersExecutor(GlobalConfiguration globalConfig, ProjectBuilder... projectBuilders) { | |||
this.globalConfig = globalConfig; | |||
this.projectBuilders = projectBuilders; | |||
} | |||
public ProjectBuildersExecutor() { | |||
this(new ProjectBuilder[0]); | |||
public ProjectBuildersExecutor(GlobalConfiguration globalConfig) { | |||
this(globalConfig, new ProjectBuilder[0]); | |||
} | |||
public void execute(ProjectReactor reactor) { | |||
if (projectBuilders.length > 0) { | |||
Profiler profiler = Profiler.create(LOG).startInfo("Execute project builders"); | |||
ProjectBuilderContext context = new ProjectBuilderContext(reactor); | |||
ProjectBuilderContext context = new ProjectBuilderContext(reactor, globalConfig); | |||
for (ProjectBuilder projectBuilder : projectBuilders) { | |||
try { |
@@ -20,7 +20,7 @@ | |||
package org.sonar.scanner.scan; | |||
import java.util.Map; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.scanner.config.DefaultConfiguration; | |||
@@ -23,20 +23,19 @@ import javax.annotation.concurrent.ThreadSafe; | |||
import org.sonar.api.SonarRuntime; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.batch.fs.InputModule; | |||
import org.sonar.api.batch.fs.internal.DefaultInputProject; | |||
import org.sonar.api.batch.rule.ActiveRules; | |||
import org.sonar.api.batch.sensor.internal.SensorStorage; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.batch.fs.internal.DefaultInputProject; | |||
@ThreadSafe | |||
public class ModuleSensorContext extends ProjectSensorContext { | |||
private final InputModule module; | |||
public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, | |||
public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, FileSystem fs, ActiveRules activeRules, | |||
SensorStorage sensorStorage, SonarRuntime sonarRuntime) { | |||
super(project, config, mutableSettings, fs, activeRules, sensorStorage, sonarRuntime); | |||
super(project, config, fs, activeRules, sensorStorage, sonarRuntime); | |||
this.module = module; | |||
} | |||
@@ -50,7 +50,6 @@ import org.sonar.api.batch.sensor.rule.internal.DefaultAdHocRule; | |||
import org.sonar.api.batch.sensor.symbol.NewSymbolTable; | |||
import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.scanner.fs.InputProject; | |||
import org.sonar.api.utils.Version; | |||
import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError; | |||
@@ -60,7 +59,6 @@ public class ProjectSensorContext implements SensorContext { | |||
static final NoOpNewAnalysisError NO_OP_NEW_ANALYSIS_ERROR = new NoOpNewAnalysisError(); | |||
private final Settings mutableSettings; | |||
private final FileSystem fs; | |||
private final ActiveRules activeRules; | |||
private final SensorStorage sensorStorage; | |||
@@ -68,22 +66,16 @@ public class ProjectSensorContext implements SensorContext { | |||
private final SonarRuntime sonarRuntime; | |||
private final Configuration config; | |||
public ProjectSensorContext(DefaultInputProject project, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, | |||
public ProjectSensorContext(DefaultInputProject project, Configuration config, FileSystem fs, ActiveRules activeRules, | |||
SensorStorage sensorStorage, SonarRuntime sonarRuntime) { | |||
this.project = project; | |||
this.config = config; | |||
this.mutableSettings = mutableSettings; | |||
this.fs = fs; | |||
this.activeRules = activeRules; | |||
this.sensorStorage = sensorStorage; | |||
this.sonarRuntime = sonarRuntime; | |||
} | |||
@Override | |||
public Settings settings() { | |||
return mutableSettings; | |||
} | |||
@Override | |||
public Configuration config() { | |||
return config; |
@@ -24,7 +24,7 @@ import java.util.Arrays; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinition; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.PropertyFieldDefinition; |
@@ -24,7 +24,7 @@ import java.util.Map; | |||
import java.util.Set; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.scanner.config.DefaultConfiguration; |
@@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.config.Encryption; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.api.utils.log.LoggerLevel; |
@@ -23,7 +23,7 @@ import org.sonar.api.SonarEdition; | |||
import org.junit.Test; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.SonarQubeSide; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.internal.SonarRuntimeImpl; | |||
import org.sonar.api.utils.Version; |
@@ -24,7 +24,6 @@ import org.junit.Test; | |||
import org.sonar.api.batch.AnalysisMode; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
public class DefaultPostJobContextTest { | |||
@@ -36,12 +35,7 @@ public class DefaultPostJobContextTest { | |||
public void setUp() { | |||
settings = new MapSettings(); | |||
AnalysisMode analysisMode = mock(AnalysisMode.class); | |||
context = new DefaultPostJobContext(settings.asConfig(), settings, analysisMode); | |||
} | |||
@Test | |||
public void testSettings() { | |||
assertThat(context.settings()).isSameAs(settings); | |||
context = new DefaultPostJobContext(settings.asConfig(), analysisMode); | |||
} | |||
@Test(expected=UnsupportedOperationException.class) |
@@ -27,6 +27,7 @@ import org.sonar.api.batch.bootstrap.ProjectBuilder; | |||
import org.sonar.api.batch.bootstrap.ProjectBuilder.Context; | |||
import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.scanner.bootstrap.GlobalConfiguration; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.Mockito.doThrow; | |||
@@ -51,7 +52,7 @@ public class ProjectBuildersExecutorTest { | |||
exception.expectMessage("Failed to execute project builder: Mock for ProjectBuilder"); | |||
exception.expect(MessageException.class); | |||
new ProjectBuildersExecutor(projectBuilders).execute(reactor); | |||
new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor); | |||
} | |||
@Test | |||
@@ -61,7 +62,7 @@ public class ProjectBuildersExecutorTest { | |||
exception.expectMessage("Failed to execute project builder: org.sonar.scanner.scan.ProjectBuildersExecutorTest$MyProjectBuilder"); | |||
exception.expect(MessageException.class); | |||
new ProjectBuildersExecutor(projectBuilders).execute(reactor); | |||
new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor); | |||
} | |||
static class MyProjectBuilder extends ProjectBuilder { |
@@ -68,14 +68,13 @@ public class ModuleSensorContextTest { | |||
settings = new MapSettings(); | |||
sensorStorage = mock(SensorStorage.class); | |||
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); | |||
adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime); | |||
adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), fs, activeRules, sensorStorage, runtime); | |||
} | |||
@Test | |||
public void shouldProvideComponents() { | |||
assertThat(adaptor.activeRules()).isEqualTo(activeRules); | |||
assertThat(adaptor.fileSystem()).isEqualTo(fs); | |||
assertThat(adaptor.settings()).isEqualTo(settings); | |||
assertThat(adaptor.getSonarQubeVersion()).isEqualTo(Version.parse("5.5")); | |||
assertThat(adaptor.runtime()).isEqualTo(runtime); | |||