Skip to content

Commit f2282f8

Browse files
PLUGINAPI-172 Fix deprecated usage SQ issues
1 parent 3921562 commit f2282f8

File tree

17 files changed

+73
-52
lines changed

17 files changed

+73
-52
lines changed

plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Map;
2929
import javax.annotation.CheckForNull;
3030
import org.apache.commons.lang3.StringUtils;
31+
import org.apache.commons.lang3.Strings;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334
import org.sonar.api.rule.RuleKey;
@@ -184,7 +185,7 @@ private static Field getField(Object check, String key) {
184185
List<Field> fields = FieldUtils2.getFields(check.getClass(), true);
185186
for (Field field : fields) {
186187
RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class);
187-
if (propertyAnnotation != null && (StringUtils.equals(key, field.getName()) || StringUtils.equals(key, propertyAnnotation.key()))) {
188+
if (propertyAnnotation != null && (Strings.CS.equals(key, field.getName()) || Strings.CS.equals(key, propertyAnnotation.key()))) {
188189
return field;
189190
}
190191
}

plugin-api/src/main/java/org/sonar/api/config/Category.java

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

22-
import org.apache.commons.lang3.StringUtils;
23-
2422
import java.util.Locale;
23+
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.Strings;
2525

2626
/**
2727
* @since 3.7
@@ -62,7 +62,7 @@ public boolean equals(Object obj) {
6262
if (!(obj instanceof Category)) {
6363
return false;
6464
}
65-
return StringUtils.equalsIgnoreCase(((Category) obj).originalKey, this.originalKey);
65+
return Strings.CI.equals(((Category) obj).originalKey, this.originalKey);
6666
}
6767

6868
@Override

plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.annotation.CheckForNull;
3232
import javax.annotation.Nullable;
3333
import org.apache.commons.lang3.StringUtils;
34+
import org.apache.commons.lang3.Strings;
3435
import org.apache.commons.lang3.math.NumberUtils;
3536
import org.apache.commons.validator.routines.EmailValidator;
3637
import org.sonar.api.ExtensionPoint;
@@ -219,7 +220,7 @@ private static EnumMap<PropertyType, Function<String, Result>> createValidations
219220

220221
private static Function<String, Result> validateBoolean() {
221222
return value -> {
222-
if (!StringUtils.equalsIgnoreCase(value, "true") && !StringUtils.equalsIgnoreCase(value, "false")) {
223+
if (!Strings.CI.equals(value, "true") && !Strings.CI.equals(value, "false")) {
223224
return Result.newError("notBoolean");
224225
}
225226
return Result.SUCCESS;
@@ -680,7 +681,7 @@ public PropertyDefinition build() {
680681
private void fixType(String key, PropertyType type) {
681682
// Auto-detect passwords and licenses for old versions of plugins that
682683
// do not declare property types
683-
if (type == PropertyType.STRING && StringUtils.endsWith(key, ".password.secured")) {
684+
if (type == PropertyType.STRING && Strings.CS.endsWith(key, ".password.secured")) {
684685
this.type = PropertyType.PASSWORD;
685686
}
686687
}

plugin-api/src/main/java/org/sonar/api/server/profile/BuiltInQualityProfileAnnotationLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
package org.sonar.api.server.profile;
2121

22-
import org.apache.commons.lang3.StringUtils;
22+
import org.apache.commons.lang3.Strings;
2323
import org.sonar.api.rules.RuleAnnotationUtils;
2424
import org.sonar.api.server.ServerSide;
2525
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInActiveRule;
@@ -43,7 +43,7 @@ public void load(BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile built
4343

4444
void loadActiveRule(BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile profile, String repositoryKey, Class<?> clazz) {
4545
BelongsToProfile belongsToProfile = clazz.getAnnotation(BelongsToProfile.class);
46-
if ((belongsToProfile != null) && StringUtils.equals(belongsToProfile.title(), profile.name())) {
46+
if ((belongsToProfile != null) && Strings.CS.equals(belongsToProfile.title(), profile.name())) {
4747
String ruleKey = RuleAnnotationUtils.getRuleKey(clazz);
4848
NewBuiltInActiveRule activeRule = profile.activateRule(repositoryKey, ruleKey);
4949
activeRule.overrideSeverity(belongsToProfile.priority().name());

plugin-api/src/main/java/org/sonar/api/server/rule/internal/DefaultRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.annotation.Nullable;
2828
import javax.annotation.concurrent.Immutable;
2929
import org.apache.commons.lang3.StringUtils;
30+
import org.apache.commons.lang3.Strings;
3031
import org.sonar.api.server.rule.RulesDefinition;
3132
import org.sonar.api.utils.log.Loggers;
3233

@@ -48,8 +49,8 @@ public DefaultRepository(DefaultNewRepository newRepository, @Nullable RulesDefi
4849
this.isExternal = newRepository.isExternal();
4950
Map<String, RulesDefinition.Rule> ruleBuilder = new HashMap<>();
5051
if (mergeInto != null) {
51-
if (!StringUtils.equals(newRepository.language(), mergeInto.language()) || !StringUtils.equals(newRepository.key(), mergeInto.key())) {
52-
throw new IllegalArgumentException(format("Bug - language and key of the repositories to be merged should be the sames: %s and %s", newRepository, mergeInto));
52+
if (!Strings.CS.equals(newRepository.language(), mergeInto.language()) || !Strings.CS.equals(newRepository.key(), mergeInto.key())) {
53+
throw new IllegalArgumentException(format("Bug - language and key of the repositories to be merged should be the same: %s and %s", newRepository, mergeInto));
5354
}
5455
this.name = StringUtils.defaultIfBlank(mergeInto.name(), newRepository.name());
5556
for (RulesDefinition.Rule rule : mergeInto.rules()) {

plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.commons.io.FilenameUtils;
4040
import org.apache.commons.io.IOUtils;
4141
import org.apache.commons.lang3.StringUtils;
42+
import org.apache.commons.lang3.Strings;
4243
import org.sonar.api.ExtensionPoint;
4344
import org.sonar.api.server.ServerSide;
4445
import org.sonar.api.utils.log.Logger;
@@ -140,7 +141,7 @@ private NewController(Context context, String path) {
140141
if (StringUtils.isBlank(path)) {
141142
throw new IllegalArgumentException("WS controller path must not be empty");
142143
}
143-
if (StringUtils.startsWith(path, "/") || StringUtils.endsWith(path, "/")) {
144+
if (Strings.CS.startsWith(path, "/") || Strings.CS.endsWith(path, "/")) {
144145
throw new IllegalArgumentException("WS controller path must not start or end with slash: " + path);
145146
}
146147
this.context = context;
@@ -315,6 +316,7 @@ public NewAction setHandler(RequestHandler h) {
315316

316317
/**
317318
* Sets content type of the response. This is optional to do.
319+
*
318320
* @since 10.8
319321
*/
320322
public NewAction setContentType(Enum<Response.ContentType> contentType) {

plugin-api/src/main/java/org/sonar/api/user/UserQuery.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
*/
2020
package org.sonar.api.user;
2121

22-
import org.apache.commons.lang3.StringUtils;
23-
24-
import javax.annotation.CheckForNull;
25-
import javax.annotation.Nullable;
2622
import java.util.Arrays;
2723
import java.util.Collection;
24+
import javax.annotation.CheckForNull;
25+
import javax.annotation.Nullable;
26+
import org.apache.commons.lang3.StringUtils;
27+
import org.apache.commons.lang3.Strings;
2828

2929
/**
3030
* @since 3.6
@@ -53,8 +53,8 @@ private UserQuery(Builder builder) {
5353
private static String searchTextToSql(@Nullable String s) {
5454
String sql = null;
5555
if (s != null) {
56-
sql = StringUtils.replace(s, "%", "/%");
57-
sql = StringUtils.replace(sql, "_", "/_");
56+
sql = Strings.CS.replace(s, "%", "/%");
57+
sql = Strings.CS.replace(sql, "_", "/_");
5858
sql = "%" + sql + "%";
5959
}
6060
return sql;

plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import java.util.regex.Pattern;
2626
import javax.annotation.Nullable;
2727
import javax.annotation.concurrent.ThreadSafe;
28-
29-
import org.apache.commons.lang3.StringUtils;
28+
import org.apache.commons.lang3.Strings;
3029

3130
/**
3231
* Implementation of Ant-style matching patterns.
@@ -125,7 +124,7 @@ private static boolean isSlash(char ch) {
125124

126125
/**
127126
* Returns string representation of this pattern.
128-
*
127+
*
129128
* @since 2.5
130129
*/
131130
@Override
@@ -137,14 +136,14 @@ public String toString() {
137136
* Returns true if specified value matches this pattern.
138137
*/
139138
public boolean match(String value) {
140-
value = StringUtils.removeStart(value, "/");
141-
value = StringUtils.removeEnd(value, "/");
139+
value = Strings.CS.removeStart(value, "/");
140+
value = Strings.CS.removeEnd(value, "/");
142141
return pattern.matcher(value).matches();
143142
}
144143

145144
/**
146145
* Returns true if specified value matches one of specified patterns.
147-
*
146+
*
148147
* @since 2.4
149148
*/
150149
public static boolean match(WildcardPattern[] patterns, String value) {
@@ -158,7 +157,7 @@ public static boolean match(WildcardPattern[] patterns, String value) {
158157

159158
/**
160159
* Creates pattern with "/" as a directory separator.
161-
*
160+
*
162161
* @see #create(String, String)
163162
*/
164163
public static WildcardPattern create(String pattern) {
@@ -167,7 +166,7 @@ public static WildcardPattern create(String pattern) {
167166

168167
/**
169168
* Creates array of patterns with "/" as a directory separator.
170-
*
169+
*
171170
* @see #create(String, String)
172171
*/
173172
public static WildcardPattern[] create(@Nullable String[] patterns) {
@@ -187,12 +186,12 @@ public static WildcardPattern[] create(@Nullable String[] patterns) {
187186
* This is used to match Java-classes, i.e. <code>org.foo.Bar</code> against <code>org/**</code>.
188187
* <b>However usage of character other than "/" as a directory separator is misleading and should be avoided,
189188
* so method {@link #create(String)} is preferred over this one.</b>
190-
*
189+
*
191190
* <p>
192191
* Also note that no matter whether forward or backward slashes were used in the <code>antPattern</code>
193192
* the returned pattern will use <code>directorySeparator</code>.
194193
* Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed.
195-
*
194+
*
196195
*/
197196
public static WildcardPattern create(String pattern, String directorySeparator) {
198197
String key = pattern + directorySeparator;

plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CategoryTest {
2727

2828
@Test
2929
public void category_key_is_case_insentive() {
30+
assertThat(new Category("licenses")).isEqualTo(new Category("licenses"));
3031
assertThat(new Category("Licenses")).isEqualTo(new Category("licenses"));
3132

3233
// Just to raise coverage

plugin-api/src/test/java/org/sonar/api/config/ConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import java.util.Optional;
2525
import java.util.Random;
2626
import java.util.function.BiFunction;
27-
import org.apache.commons.lang3.RandomStringUtils;
2827
import org.apache.commons.lang3.StringUtils;
2928
import org.junit.Test;
3029

30+
import static org.apache.commons.lang3.RandomStringUtils.secure;
3131
import static org.assertj.core.api.Assertions.assertThat;
3232

3333
public class ConfigurationTest {
@@ -101,7 +101,7 @@ public void getDouble() {
101101
}
102102

103103
private <T> void verifySupportHeadAndOrTrailingWhitespaces(T value, BiFunction<Configuration, String, Optional<T>> t) {
104-
String randomKey = RandomStringUtils.randomAlphabetic(3);
104+
String randomKey = secure().nextAlphabetic(3);
105105
String randomNumberOfWhitespaces = StringUtils.repeat(" ", 1 + new Random().nextInt(10));
106106

107107
assertThat(t.apply(underTest.put(randomKey, randomNumberOfWhitespaces + value), randomKey)).isEqualTo(Optional.of(value));

0 commit comments

Comments
 (0)