dependency 'org.apache.commons:commons-csv:1.10.0'
dependency 'org.apache.commons:commons-lang3:3.14.0'
dependency 'org.apache.commons:commons-email:1.6.0'
+ dependency 'org.apache.commons:commons-text:1.11.0'
dependency 'com.zaxxer:HikariCP:5.1.0'
dependency('org.apache.httpcomponents:httpclient:4.5.14') {
exclude 'commons-logging:commons-logging'
private final String saslMaxbuf;
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.authentication = config.get(settingsPrefix + ".authentication").orElse(DEFAULT_AUTHENTICATION);
+ this.factory = config.get(settingsPrefix + ".contextFactoryClass").orElse(DEFAULT_FACTORY);
this.realm = config.get(settingsPrefix + ".realm").orElse(null);
this.providerUrl = ldapUrl;
this.startTLS = config.getBoolean(settingsPrefix + ".StartTLS").orElse(false);
*/
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);
+ this.idAttribute = config.get(settingsPrefix + ".group.idAttribute").orElse(DEFAULT_ID_ATTRIBUTE);
- String req = StringUtils.defaultString(config.get(settingsPrefix + ".group.request").orElse(null), DEFAULT_REQUEST);
+ String req = config.get(settingsPrefix + ".group.request").orElse(DEFAULT_REQUEST);
this.requiredUserAttributes = StringUtils.substringsBetween(req, "{", "}");
for (int i = 0; i < requiredUserAttributes.length; i++) {
req = StringUtils.replace(req, "{" + requiredUserAttributes[i] + "}", "{" + i + "}");
public LdapUserMapping(Configuration config, String settingsPrefix) {
String userBaseDnSettingKey = settingsPrefix + ".user.baseDn";
this.baseDn = config.get(userBaseDnSettingKey).orElseThrow(() -> new LdapException(String.format(MANDATORY_LDAP_PROPERTY_ERROR, userBaseDnSettingKey)));
- 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);
+ this.realNameAttribute = config.get(settingsPrefix + ".user.realNameAttribute").orElse(DEFAULT_NAME_ATTRIBUTE);
+ this.emailAttribute = config.get(settingsPrefix + ".user.emailAttribute").orElse(DEFAULT_EMAIL_ATTRIBUTE);
- String req = StringUtils.defaultString(config.get(settingsPrefix + ".user.request").orElse(null), DEFAULT_REQUEST);
+ String req = config.get(settingsPrefix + ".user.request").orElse(DEFAULT_REQUEST);
req = StringUtils.replace(req, "{login}", "{0}");
this.request = req;
}
api 'commons-codec:commons-codec'
api 'commons-io:commons-io'
api 'org.apache.commons:commons-lang3'
+ implementation 'org.apache.commons:commons-text'
api 'com.google.code.gson:gson'
api 'com.google.guava:guava'
api 'com.google.code.findbugs:jsr305'
package org.sonar.ce.task.projectanalysis.source;
import java.util.List;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.ObjectUtils;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
boolean binaryDataUpdated = !dataHash.equals(previousDto.getDataHash());
boolean srcHashUpdated = !srcHash.equals(previousDto.getSrcHash());
String revision = computeRevision(latestChangeWithRevision);
- boolean revisionUpdated = !ObjectUtils.equals(revision, previousDto.getRevision());
+ boolean revisionUpdated = !Objects.equals(revision, previousDto.getRevision());
boolean lineHashesVersionUpdated = previousDto.getLineHashesVersion() != lineHashesVersion;
if (binaryDataUpdated || srcHashUpdated || revisionUpdated || lineHashesVersionUpdated) {
FileSourceDto updatedDto = new FileSourceDto()
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
xml.append("<b s=\"").append(textBlock.getStart())
.append("\" l=\"").append(length)
.append("\" t=\"").append(disableLink)
- .append("\" r=\"").append(StringEscapeUtils.escapeXml(componentDbKey))
+ .append("\" r=\"").append(StringEscapeUtils.escapeXml10(componentDbKey))
.append("\"/>");
}
}
* priority is always given to the task that is waiting longer - to avoid starvation
*/
private Optional<CeQueueDto> submitOldest(DbSession session, String workerUuid, @Nullable CeTaskDtoLight eligibleForPeek, @Nullable CeTaskDtoLight eligibleForPeekInParallel) {
- CeTaskDtoLight oldest = (CeTaskDtoLight) ObjectUtils.min(eligibleForPeek, eligibleForPeekInParallel);
+ CeTaskDtoLight oldest = ObjectUtils.min(eligibleForPeek, eligibleForPeekInParallel);
Optional<CeQueueDto> ceQueueDto = ceQueueDao.tryToPeek(session, oldest.getCeTaskUuid(), workerUuid);
if (!Objects.equals(oldest, eligibleForPeek)) {
ceQueueDto.ifPresent(t -> LOG.info("Task [uuid = " + t.getUuid() + "] will be run concurrently with other tasks for the same project"));
*/
package org.sonar.db.audit.model;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.ObjectUtils;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.project.ProjectDto;
addField(sb, "\"qualifier\": ", getQualifier(qualifier), true);
addField(sb, "\"description\": ", this.description, true);
addField(sb, "\"path\": ", this.path, true);
- addField(sb, "\"isPrivate\": ", ObjectUtils.toString(this.isPrivate), false);
- addField(sb, "\"isEnabled\": ", ObjectUtils.toString(this.isEnabled), false);
+ addField(sb, "\"isPrivate\": ", Objects.toString(this.isPrivate, ""), false);
+ addField(sb, "\"isEnabled\": ", Objects.toString(this.isEnabled, ""), false);
endString(sb);
return sb.toString();
}
*/
package org.sonar.db.audit.model;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.ObjectUtils;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
import org.sonar.db.project.ProjectDto;
addField(sb, "\"projectName\": ", this.projectName, true);
addField(sb, "\"almRepo\": ", this.almRepo, true);
addField(sb, "\"almSlug\": ", this.almSlug, true);
- addField(sb, "\"isSummaryCommentEnabled\": ", ObjectUtils.toString(this.isSummaryCommentEnabled), false);
- addField(sb, "\"isMonorepo\": ", ObjectUtils.toString(this.isMonorepo), false);
+ addField(sb, "\"isSummaryCommentEnabled\": ", Objects.toString(this.isSummaryCommentEnabled, ""), false);
+ addField(sb, "\"isMonorepo\": ", Objects.toString(this.isMonorepo, ""), false);
endString(sb);
return sb.toString();
}
*/
package org.sonar.db.audit.model;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.ObjectUtils;
import org.sonar.db.permission.template.PermissionTemplateDto;
public class PermissionTemplateNewValue extends NewValue {
addField(sb, "\"userLogin\": ", this.userLogin, true);
addField(sb, "\"groupUuid\": ", this.groupUuid, true);
addField(sb, "\"groupName\": ", this.groupName, true);
- addField(sb, "\"withProjectCreator\": ", ObjectUtils.toString(this.withProjectCreator), false);
+ addField(sb, "\"withProjectCreator\": ", Objects.toString(this.withProjectCreator, ""), false);
endString(sb);
return sb.toString();
}
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.ObjectUtils;
import org.sonar.api.utils.DateUtils;
import org.sonar.db.user.UserDto;
addField(sb, "\"userLogin\": ", this.userLogin, true);
addField(sb, "\"name\": ", this.name, true);
addField(sb, "\"email\": ", this.email, true);
- addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
+ addField(sb, "\"isActive\": ", Objects.toString(this.isActive, ""), false);
addField(sb, "\"scmAccounts\": ", String.join(",", scmAccounts), true);
addField(sb, "\"externalId\": ", this.externalId, true);
addField(sb, "\"externalLogin\": ", this.externalLogin, true);
addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true);
- addField(sb, "\"local\": ", ObjectUtils.toString(this.local), false);
+ addField(sb, "\"local\": ", Objects.toString(this.local, ""), false);
addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ?
"" : DateUtils.formatDateTime(this.lastConnectionDate), true);
endString(sb);
private void setSubject(Email email, EmailMessage emailMessage) {
String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "")
- + StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
+ + Objects.toString(emailMessage.getSubject(), SUBJECT_DEFAULT);
email.setSubject(subject);
}
*/
package org.sonar.server.authentication;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.slf4j.MDC;
import org.sonar.server.user.UserSession;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
-import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE;
import static org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY;
import static org.sonar.api.utils.DateUtils.formatDateTime;
}
threadLocalSession.set(session);
checkTokenUserSession(response, session);
- request.setAttribute(ACCESS_LOG_LOGIN, defaultString(session.getLogin(), "-"));
- MDC.put(USER_LOGIN_MDC_KEY, defaultString(session.getLogin(), "-"));
+ request.setAttribute(ACCESS_LOG_LOGIN, Objects.toString(session.getLogin(), "-"));
+ MDC.put(USER_LOGIN_MDC_KEY, Objects.toString(session.getLogin(), "-"));
}
private static void checkTokenUserSession(HttpResponse response, UserSession session) {
implementation 'com.github.erosb:json-sKema'
api 'io.prometheus:simpleclient_common'
api 'io.prometheus:simpleclient_servlet'
+ implementation 'org.apache.commons:commons-text'
api project(':server:sonar-ce-common')
api project(':server:sonar-ce-task')
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.text.StrSubstitutor;
+import org.apache.commons.text.StringSubstitutor;
import org.sonar.api.measures.Metric;
import org.sonar.api.server.ServerSide;
.put(PARAMETER_LABEL, label)
.put(PARAMETER_VALUE, value)
.build();
- StrSubstitutor strSubstitutor = new StrSubstitutor(values);
+ StringSubstitutor strSubstitutor = new StringSubstitutor(values);
return strSubstitutor.replace(badgeTemplate);
}
Map<String, String> values = ImmutableMap.of(
PARAMETER_TOTAL_WIDTH, valueOf(MARGIN + computeWidth(error) + MARGIN),
PARAMETER_LABEL, error);
- StrSubstitutor strSubstitutor = new StrSubstitutor(values);
+ StringSubstitutor strSubstitutor = new StringSubstitutor(values);
return strSubstitutor.replace(errorTemplate);
}
public void handle(Request request, Response response) {
String fileKey = request.mandatoryParam("key");
int from = Math.max(request.mandatoryParamAsInt("from"), 1);
- int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
+ int to = ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
boolean commitsByLine = request.mandatoryParamAsBoolean("commits_by_line");
try (DbSession dbSession = dbClient.openSession(false)) {
public void handle(Request request, Response response) {
String fileKey = request.mandatoryParam("key");
int from = Math.max(request.paramAsInt("from"), 1);
- int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
+ int to = ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto file = componentFinder.getByKey(dbSession, fileKey);
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.apache.commons.lang3.StringUtils;
import org.sonar.api.rule.RuleKey;
import static java.util.Comparator.comparing;
protected LineAndLineHashKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.line = trackable.getLine();
- this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
+ this.lineHash = Objects.toString(trackable.getLineHash(), "");
}
@Override
this.ruleKey = trackable.getRuleKey();
this.line = trackable.getLine();
this.message = trackable.getMessage();
- this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
+ this.lineHash = Objects.toString(trackable.getLineHash(), "");
}
@Override
LineHashAndMessageKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.message = trackable.getMessage();
- this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
+ this.lineHash = Objects.toString(trackable.getLineHash(), "");
}
@Override
LineHashKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
- this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
+ this.lineHash = Objects.toString(trackable.getLineHash(), "");
}
@Override
}
public NewRule setStatus(@Nullable RuleStatus s) {
- this.status = (RuleStatus) ObjectUtils.defaultIfNull(s, RuleStatus.defaultStatus());
+ this.status = ObjectUtils.defaultIfNull(s, RuleStatus.defaultStatus());
return this;
}
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
-import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.sonar.api.utils.Preconditions.checkArgument;
/**
public String param(String key) {
WebService.Param definition = action.param(key);
String rawValue = readParam(key, definition);
- String rawValueOrDefault = defaultString(rawValue, definition.defaultValue());
+ String rawValueOrDefault = Objects.toString(rawValue, definition.defaultValue());
String value = rawValueOrDefault == null ? null : trim(rawValueOrDefault);
validateRequiredValue(key, definition, rawValue);
if (value == null) {
@Override
public List<String> paramAsStrings(String key) {
WebService.Param definition = action.param(key);
- String value = defaultString(readParam(key, definition), definition.defaultValue());
+ String value = Objects.toString(readParam(key, definition), definition.defaultValue());
if (value == null) {
return null;
}
private String readParam(String key, @Nullable WebService.Param definition) {
checkArgument(definition != null, "BUG - parameter '%s' is undefined for action '%s'", key, action.key());
String deprecatedKey = definition.deprecatedKey();
- String param = deprecatedKey != null ? defaultString(readParam(deprecatedKey), readParam(key)) : readParam(key);
+ String param = deprecatedKey != null ? Objects.toString(readParam(deprecatedKey), readParam(key)) : readParam(key);
if (param != null && param.contains("\0")) {
throw new IllegalArgumentException("Request parameters are not allowed to contain NUL character");
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.api.impl.ws;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.sonar.api.server.ws.WebService;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ValidatingRequestTest {
+
+ ValidatingRequest underTest = Mockito.mock(ValidatingRequest.class, Mockito.CALLS_REAL_METHODS);
+ @Test
+ public void paramReturnsTheDefaultValue_whenDefaultIsSetAndValueIsNot() {
+ underTest.setAction(mock(WebService.Action.class));
+ WebService.Param param = mockParamWithDefaultValue("default");
+
+ when(underTest.action().param("param")).thenReturn(param);
+
+ assertThat(underTest.param("param")).isEqualTo("default");
+ }
+
+ @Test
+ public void paramAsStringsReturnsTheDefaultValues_whenDefaultIsSetAndValueIsNot() {
+ underTest.setAction(mock(WebService.Action.class));
+ WebService.Param param = mockParamWithDefaultValue("default,values");
+
+ when(underTest.action().param("param")).thenReturn(param);
+
+ assertThat(underTest.paramAsStrings("param")).containsExactly("default", "values");
+ }
+
+ private static WebService.Param mockParamWithDefaultValue(String defaultValue) {
+ WebService.Param param = mock(WebService.Param.class);
+ when(param.defaultValue()).thenReturn(defaultValue);
+ when(param.possibleValues()).thenReturn(null);
+ when(param.maximumLength()).thenReturn(10);
+ when(param.maximumLength()).thenReturn(10);
+ when(param.maximumValue()).thenReturn(null);
+ when(param.maxValuesAllowed()).thenReturn(2);
+ return param;
+ }
+}
api 'commons-codec:commons-codec'
api 'commons-io:commons-io'
api 'org.apache.commons:commons-lang3'
+ implementation 'org.apache.commons:commons-text'
api 'com.google.code.gson:gson'
api 'org.apache.commons:commons-csv'
api 'com.google.protobuf:protobuf-java'
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
}
static PathPattern[] prepareMainExclusions(String[] sourceExclusions, String[] testInclusions) {
- String[] patterns = (String[]) ArrayUtils.addAll(
+ String[] patterns = ArrayUtils.addAll(
sourceExclusions, testInclusions);
return PathPattern.create(patterns);
}
private static String formatGitSemanticVersion(String version) {
return semanticVersionDelimiter
.splitAsStream(version)
- .takeWhile(NumberUtils::isNumber)
+ .takeWhile(NumberUtils::isCreatable)
.collect(Collectors.joining("."));
}