Skip to content

Commit 59384d1

Browse files
matteo-mara-sonarsourcesonartech
authored andcommitted
NO-JIRA Fix deprecations after commons.lang3 dependency upgrade
1 parent 2a9726f commit 59384d1

File tree

60 files changed

+197
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+197
-167
lines changed

server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.sonar.api.server.ServerSide;
4343
import org.sonar.server.exceptions.NotFoundException;
4444

45-
import static org.apache.commons.lang3.StringUtils.removeEnd;
45+
import static org.apache.commons.lang3.Strings.CS;
4646

4747
@ServerSide
4848
public class BitbucketCloudRestClient {
@@ -169,7 +169,7 @@ private Request createAccessTokenRequest(String clientId, String clientSecret) {
169169
}
170170

171171
protected HttpUrl buildUrl(String relativeUrl) {
172-
return HttpUrl.parse(removeEnd(bitbucketCloudEndpoint, "/") + "/" + VERSION + relativeUrl);
172+
return HttpUrl.parse(CS.removeEnd(bitbucketCloudEndpoint, "/") + "/" + VERSION + relativeUrl);
173173
}
174174

175175
protected <G> G doGet(String accessToken, HttpUrl url, Function<Response, G> handler) {

server/sonar-alm-client/src/main/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
4848
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
4949
import static java.util.Locale.ENGLISH;
50-
import static org.apache.commons.lang3.StringUtils.removeEnd;
50+
import static org.apache.commons.lang3.Strings.CS;
5151

5252
@ServerSide
5353
public class BitbucketServerRestClient {
@@ -117,7 +117,7 @@ protected static HttpUrl buildUrl(@Nullable String serverUrl, String relativeUrl
117117
if (serverUrl == null || !(serverUrl.toLowerCase(ENGLISH).startsWith("http://") || serverUrl.toLowerCase(ENGLISH).startsWith("https://"))) {
118118
throw new IllegalArgumentException("url must start with http:// or https://");
119119
}
120-
return HttpUrl.parse(removeEnd(serverUrl, "/") + relativeUrl);
120+
return HttpUrl.parse(CS.removeEnd(serverUrl, "/") + relativeUrl);
121121
}
122122

123123
protected <G> G doGet(String token, HttpUrl url, Function<String, G> handler) {

server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ private static boolean isValidGitHubUrl(URI apiEndpoint) {
144144
if (host == null) {
145145
return false;
146146
}
147-
147+
148148
String lowerCaseHost = host.toLowerCase(Locale.ENGLISH);
149149
// GitHub.com (official public GitHub)
150150
if ("api.github.com".equals(lowerCaseHost)) {
151151
return true;
152152
}
153-
153+
154154
// GitHub Enterprise Server - standard format: https://github.company.com/api/v3/
155155
if (path != null && path.toLowerCase(Locale.ENGLISH).startsWith("/api/v3")) {
156156
return true;
157157
}
158-
158+
159159
// GitHub Enterprise Cloud with data residency - official format: https://api.company.ghe.com
160160
return lowerCaseHost.startsWith("api.") && lowerCaseHost.endsWith(".ghe.com");
161-
}
161+
}
162162

163163
@Override
164164
public void checkAppPermissions(GithubAppConfiguration githubAppConfiguration) {
@@ -349,9 +349,9 @@ public UserAccessToken createUserAccessToken(String appUrl, String clientId, Str
349349

350350
Optional<String> content = response.getContent();
351351
Optional<UserAccessToken> accessToken = content.flatMap(c -> Arrays.stream(c.split("&"))
352-
.filter(t -> t.startsWith("access_token="))
353-
.map(t -> t.split("=")[1])
354-
.findAny())
352+
.filter(t -> t.startsWith("access_token="))
353+
.map(t -> t.split("=")[1])
354+
.findAny())
355355
.map(UserAccessToken::new);
356356

357357
if (accessToken.isPresent()) {

server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/LdapGroupMapping.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.apache.commons.lang3.StringUtils;
2727
import org.sonar.api.config.Configuration;
2828

29+
import static org.apache.commons.lang3.Strings.CS;
30+
2931
/**
3032
* @author Evgeny Mandrikov
3133
*/
@@ -49,7 +51,7 @@ public LdapGroupMapping(Configuration config, String settingsPrefix) {
4951
String req = config.get(settingsPrefix + ".group.request").orElse(DEFAULT_REQUEST);
5052
this.requiredUserAttributes = StringUtils.substringsBetween(req, "{", "}");
5153
for (int i = 0; i < requiredUserAttributes.length; i++) {
52-
req = StringUtils.replace(req, "{" + requiredUserAttributes[i] + "}", "{" + i + "}");
54+
req = CS.replace(req, "{" + requiredUserAttributes[i] + "}", "{" + i + "}");
5355
}
5456
this.request = req;
5557
}

server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/LdapUserMapping.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
package org.sonar.auth.ldap;
2121

22-
import org.apache.commons.lang3.StringUtils;
2322
import org.sonar.api.config.Configuration;
2423

24+
import static org.apache.commons.lang3.Strings.CS;
2525
import static org.sonar.auth.ldap.LdapSettingsManager.MANDATORY_LDAP_PROPERTY_ERROR;
2626

2727
/**
@@ -48,7 +48,7 @@ public LdapUserMapping(Configuration config, String settingsPrefix) {
4848
this.emailAttribute = config.get(settingsPrefix + ".user.emailAttribute").orElse(DEFAULT_EMAIL_ATTRIBUTE);
4949

5050
String req = config.get(settingsPrefix + ".user.request").orElse(DEFAULT_REQUEST);
51-
req = StringUtils.replace(req, "{login}", "{0}");
51+
req = CS.replace(req, "{login}", "{0}");
5252
this.request = req;
5353
}
5454

server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
import static com.google.common.base.Preconditions.checkArgument;
4040
import static java.lang.String.format;
4141
import static java.util.Objects.requireNonNull;
42-
import static org.apache.commons.lang3.StringUtils.removeStart;
4342
import static org.apache.commons.lang3.StringUtils.trimToNull;
43+
import static org.apache.commons.lang3.Strings.CS;
4444
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
4545

4646
public class ComponentTreeBuilder {
@@ -195,7 +195,7 @@ private ComponentImpl buildDirectory(String parentPath, String path, List<Compon
195195
.setUuid(uuidSupplier.apply(key))
196196
.setKey(key)
197197
.setName(path)
198-
.setShortName(removeStart(removeStart(path, parentPath), "/"))
198+
.setShortName(CS.removeStart(CS.removeStart(path, parentPath), "/"))
199199
.setStatus(convertStatus(FileStatus.UNAVAILABLE))
200200
.setReportAttributes(createAttributesBuilder(null, path, scmBasePath).build())
201201
.addChildren(children)

server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectPersister.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
*/
2020
package org.sonar.ce.task.projectanalysis.component;
2121

22-
import org.apache.commons.lang3.StringUtils;
23-
import org.sonar.db.component.ComponentQualifiers;
2422
import org.sonar.api.utils.System2;
2523
import org.sonar.db.DbClient;
2624
import org.sonar.db.DbSession;
25+
import org.sonar.db.component.ComponentQualifiers;
2726
import org.sonar.db.project.ProjectDto;
2827

28+
import static org.apache.commons.lang3.Strings.CS;
29+
2930
/**
3031
* Creates or updates the data in table {@code PROJECTS} for the current root.
3132
*/
@@ -60,8 +61,8 @@ private static boolean shouldSkip(Component rootComponent) {
6061
}
6162

6263
private static boolean hasChanged(ProjectDto dbProject, ProjectDto newProject) {
63-
return !StringUtils.equals(dbProject.getName(), newProject.getName()) ||
64-
!StringUtils.equals(dbProject.getDescription(), newProject.getDescription());
64+
return !CS.equals(dbProject.getName(), newProject.getName()) ||
65+
!CS.equals(dbProject.getDescription(), newProject.getDescription());
6566
}
6667

6768
private ProjectDto toProjectDto(Component root, ProjectDto projectDtoFromDatabase) {

server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SimpleOpenIssuesCounter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ public void add(DefaultIssue issue) {
4242
public int getCount() {
4343
return count;
4444
}
45-
}
45+
}

server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Set;
2727
import java.util.function.Function;
2828
import java.util.stream.Collectors;
29-
import org.apache.commons.lang3.StringUtils;
3029
import org.sonar.api.utils.System2;
3130
import org.sonar.ce.task.projectanalysis.component.BranchPersister;
3231
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -46,6 +45,7 @@
4645
import org.sonar.db.component.ComponentUpdateDto;
4746

4847
import static java.util.Optional.ofNullable;
48+
import static org.apache.commons.lang3.Strings.CS;
4949
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
5050
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
5151
import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
@@ -358,17 +358,17 @@ private static void setUuids(ComponentDto componentDto, PathAwareVisitor.Path<Co
358358
}
359359

360360
private static Optional<ComponentUpdateDto> compareForUpdate(ComponentDto existing, ComponentDto target) {
361-
boolean hasDifferences = !StringUtils.equals(existing.getCopyComponentUuid(), target.getCopyComponentUuid()) ||
362-
!StringUtils.equals(existing.description(), target.description()) ||
363-
!StringUtils.equals(existing.getKey(), target.getKey()) ||
361+
boolean hasDifferences = !CS.equals(existing.getCopyComponentUuid(), target.getCopyComponentUuid()) ||
362+
!CS.equals(existing.description(), target.description()) ||
363+
!CS.equals(existing.getKey(), target.getKey()) ||
364364
!existing.isEnabled() ||
365-
!StringUtils.equals(existing.getUuidPath(), target.getUuidPath()) ||
366-
!StringUtils.equals(existing.language(), target.language()) ||
367-
!StringUtils.equals(existing.longName(), target.longName()) ||
368-
!StringUtils.equals(existing.name(), target.name()) ||
369-
!StringUtils.equals(existing.path(), target.path()) ||
370-
!StringUtils.equals(existing.scope(), target.scope()) ||
371-
!StringUtils.equals(existing.qualifier(), target.qualifier());
365+
!CS.equals(existing.getUuidPath(), target.getUuidPath()) ||
366+
!CS.equals(existing.language(), target.language()) ||
367+
!CS.equals(existing.longName(), target.longName()) ||
368+
!CS.equals(existing.name(), target.name()) ||
369+
!CS.equals(existing.path(), target.path()) ||
370+
!CS.equals(existing.scope(), target.scope()) ||
371+
!CS.equals(existing.qualifier(), target.qualifier());
372372

373373
ComponentUpdateDto update = null;
374374
if (hasDifferences) {

server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Properties;
3131
import java.util.Set;
3232
import javax.sql.DataSource;
33-
import org.apache.commons.lang3.StringUtils;
3433
import org.slf4j.Logger;
3534
import org.slf4j.LoggerFactory;
3635
import org.sonar.api.config.internal.Settings;
@@ -43,6 +42,7 @@
4342

4443
import static com.google.common.base.Preconditions.checkState;
4544
import static java.lang.String.format;
45+
import static org.apache.commons.lang3.Strings.CS;
4646
import static org.sonar.process.ProcessProperties.Property.JDBC_EMBEDDED_PORT;
4747
import static org.sonar.process.ProcessProperties.Property.JDBC_MAX_IDLE_TIMEOUT;
4848
import static org.sonar.process.ProcessProperties.Property.JDBC_MAX_KEEP_ALIVE_TIME;
@@ -228,7 +228,7 @@ static Properties extractCommonsHikariProperties(Properties properties) {
228228
}
229229
continue;
230230
}
231-
if (StringUtils.startsWith(key, SONAR_JDBC)) {
231+
if (CS.startsWith(key, SONAR_JDBC)) {
232232
String resolvedKey = toHikariPropertyKey(key);
233233
String existingValue = (String) result.setProperty(resolvedKey, (String) entry.getValue());
234234
checkState(existingValue == null || existingValue.equals(entry.getValue()),
@@ -250,7 +250,7 @@ private static String toHikariPropertyKey(String key) {
250250
return SONAR_JDBC_TO_HIKARI_PROPERTY_MAPPINGS.get(key);
251251
}
252252

253-
return StringUtils.removeStart(key, SONAR_JDBC);
253+
return CS.removeStart(key, SONAR_JDBC);
254254
}
255255

256256
@Override

0 commit comments

Comments
 (0)