Skip to content

Commit 23d08bb

Browse files
authored
Merge pull request #3174 from cloudfoundry/rewrite-202411
Code cleanup
2 parents 37724e8 + f44d679 commit 23d08bb

File tree

1,210 files changed

+35197
-34783
lines changed

Some content is hidden

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

1,210 files changed

+35197
-34783
lines changed

build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

33
import java.nio.file.Files
4-
import java.nio.file.Paths
4+
import java.nio.file.Path
55

66
buildscript {
77
apply(from: "dependencies.gradle")
@@ -115,8 +115,9 @@ subprojects {
115115
retry {
116116
def failOnPassedAfterRetrySystemProperty = Boolean.parseBoolean(
117117
System.getProperty("failOnPassedAfterRetry", "false"));
118-
if (!failOnPassedAfterRetrySystemProperty)
118+
if (!failOnPassedAfterRetrySystemProperty) {
119119
logger.warn("retry: Flaky tests will not make the test run fail because failOnPassedAfterRetry is false.")
120+
}
120121

121122
// Configure the retry extension
122123
failOnPassedAfterRetry = failOnPassedAfterRetrySystemProperty
@@ -199,19 +200,19 @@ cargo {
199200
}
200201

201202
local {
202-
configHomeDir = file(Paths.get(System.getProperty("java.io.tmpdir") + "/uaa-${applicationPort}"))
203+
configHomeDir = file(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
203204
startStopTimeout = Integer.parseInt(System.getProperty("startStopTimeout", "540000"))
204205
rmiPort = applicationPort + 10
205206

206207
jvmArgs = ""
207208
jvmArgs = String.format("%s -DCLOUDFOUNDRY_CONFIG_PATH='%s'", jvmArgs, file("scripts/cargo").getAbsolutePath())
208209
jvmArgs = String.format("%s -Dlogging.config='%s'", jvmArgs, file("scripts/cargo/log4j2.properties").getAbsolutePath())
209210
jvmArgs = String.format("%s -Dstatsd.enabled=true", jvmArgs)
211+
210212
String activeSpringProfiles = System.getProperty("spring.profiles.active", "").split(',');
211213
if (activeSpringProfiles.contains("debugs") || Boolean.valueOf(System.getProperty("xdebugs"))) {
212214
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", jvmArgs)
213-
}
214-
else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
215+
} else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
215216
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", jvmArgs)
216217
}
217218

@@ -222,6 +223,7 @@ cargo {
222223
.matching { include 'jacocoagent.jar' }.singleFile)
223224
into(layout.buildDirectory.dir("jacoco"))
224225
}
226+
225227
String jacocoBuildPath = layout.buildDirectory.dir("jacoco").get().asFile.path
226228
jvmArgs = String.format(
227229
"%s -javaagent:%s/jacocoagent.jar=destfile=%s/cargo.exec",
@@ -299,9 +301,9 @@ tasks.register('manifests', Copy) {
299301
}
300302

301303
tasks.register('cleanCargoConfDir') {
302-
delete(file(System.getProperty("java.io.tmpdir") + "/cargo/uaa-${applicationPort}"))
304+
delete(Path.of(System.getProperty("java.io.tmpdir"), "cargo", "uaa-${applicationPort}"))
303305
try {
304-
Files.createDirectory(Paths.get(System.getProperty("java.io.tmpdir") + "/uaa-${applicationPort}"))
306+
Files.createDirectory(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
305307
} catch (ignored) {
306308
}
307309
}

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ libraries.hsqldb = "org.hsqldb:hsqldb"
6666
libraries.jacksonAnnotations = "com.fasterxml.jackson.core:jackson-annotations:${versions.jacksonVersion}"
6767
libraries.jacksonDatabind = "com.fasterxml.jackson.core:jackson-databind:${versions.jacksonVersion}"
6868
libraries.jacksonDataformatYaml = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jacksonVersion}"
69+
libraries.jakartaAnnotationApi = "jakarta.annotation:jakarta.annotation-api:1.3.5"
6970
libraries.javaxServlet = "javax.servlet:jstl"
7071
libraries.javaxValidationApi = "javax.validation:validation-api"
7172
libraries.javaxXmlBindApi = "javax.xml.bind:jaxb-api"

k8s/image/tomcat/conf/server.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<Engine defaultHost='localhost' name='Catalina'>
77
<Valve className='org.apache.catalina.valves.RemoteIpValve' protocolHeader='x-forwarded-proto'/>
88
<Valve className='org.cloudfoundry.tomcat.logging.access.CloudFoundryAccessLoggingValve'
9-
pattern='[ACCESS] %h %l %u %t &quot;%m %U %H&quot; %s %{Content-Length}i %b &quot;X-Vcap-Request-Id: %{X-Vcap-Request-Id}i&quot; %I'
10-
enabled='${access.logging.enabled}'/>
9+
pattern='[ACCESS] %h %l %u %t &quot;%m %U %H&quot; %s %{Content-Length}i %b &quot;X-Vcap-Request-Id: %{X-Vcap-Request-Id}i&quot; %I'
10+
enabled='${access.logging.enabled}'/>
1111
<Host name='localhost'
12-
failCtxIfServletStartFails='true'>
12+
failCtxIfServletStartFails='true'>
1313
<Listener className='org.cloudfoundry.tomcat.lifecycle.ApplicationStartupFailureDetectingLifecycleListener'/>
1414
<Valve className='org.apache.catalina.valves.ErrorReportValve' showReport='false' showServerInfo='false'/>
1515
</Host>

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/metrics/MetricsQueue.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232

3333
@JsonIgnoreProperties(ignoreUnknown = true)
3434
@JsonInclude(NON_NULL)
35-
public class MetricsQueue {
35+
public class MetricsQueue {
3636

3737
public static final int MAX_ENTRIES = 5;
3838

3939
private ConcurrentLinkedDeque<RequestMetric> queue;
4040
private Map<StatusCodeGroup, RequestMetricSummary> statistics;
4141

4242
public MetricsQueue() {
43-
this(null,null);
43+
this(null, null);
4444
}
4545

4646
@JsonCreator
4747
public MetricsQueue(@JsonProperty("lastRequests") ConcurrentLinkedDeque<RequestMetric> queue,
48-
@JsonProperty("detailed") Map<StatusCodeGroup, RequestMetricSummary> statistics) {
48+
@JsonProperty("detailed") Map<StatusCodeGroup, RequestMetricSummary> statistics) {
4949
this.queue = ofNullable(queue).orElse(new ConcurrentLinkedDeque<>());
5050
this.statistics = ofNullable(statistics).orElse(new ConcurrentHashMap<>());
5151
}
@@ -64,11 +64,11 @@ public boolean offer(RequestMetric metric) {
6464
RequestMetricSummary totals = statistics.get(statusCode);
6565
long time = metric.getRequestCompleteTime() - metric.getRequestStartTime();
6666
totals.add(time,
67-
time < metric.getUriGroup().getLimit(),
68-
metric.getNrOfDatabaseQueries(),
69-
metric.getDatabaseQueryTime(),
70-
metric.getQueries().stream().filter(QueryMetric::isIntolerable).count(),
71-
metric.getQueries().stream().filter(QueryMetric::isIntolerable).mapToLong(q -> q.getRequestCompleteTime()-q.getRequestStartTime()).sum()
67+
time < metric.getUriGroup().getLimit(),
68+
metric.getNrOfDatabaseQueries(),
69+
metric.getDatabaseQueryTime(),
70+
metric.getQueries().stream().filter(QueryMetric::isIntolerable).count(),
71+
metric.getQueries().stream().filter(QueryMetric::isIntolerable).mapToLong(q -> q.getRequestCompleteTime() - q.getRequestStartTime()).sum()
7272
);
7373
return true;
7474
}
@@ -111,27 +111,27 @@ public RequestMetricSummary getTotals() {
111111
averageDatabaseQueryTime.get(),
112112
summary.getDatabaseQueryCount(),
113113
summary.getAverageDatabaseQueryTime()
114-
)
114+
)
115115
);
116116
databaseQueryCount.add(summary.getDatabaseQueryCount());
117117

118118
averageDatabaseIntolerableQueryTime.set(addAverages(databaseIntolerableQueryCount.get(),
119119
averageDatabaseIntolerableQueryTime.get(),
120120
summary.getDatabaseIntolerableQueryCount(),
121121
summary.getAverageDatabaseIntolerableQueryTime()
122-
)
122+
)
123123
);
124124
databaseIntolerableQueryCount.add(summary.getDatabaseIntolerableQueryCount());
125125

126126
});
127127
return new RequestMetricSummary(count.get(),
128-
averageTime.get(),
129-
intolerableCount.get(),
130-
averageIntolerableTime.get(),
131-
databaseQueryCount.get(),
132-
averageDatabaseQueryTime.get(),
133-
databaseIntolerableQueryCount.get(),
134-
averageDatabaseIntolerableQueryTime.get());
128+
averageTime.get(),
129+
intolerableCount.get(),
130+
averageIntolerableTime.get(),
131+
databaseQueryCount.get(),
132+
averageDatabaseQueryTime.get(),
133+
databaseIntolerableQueryCount.get(),
134+
averageDatabaseIntolerableQueryTime.get());
135135
}
136136

137137
}

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/metrics/MetricsUtil.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package org.cloudfoundry.identity.uaa.metrics;
1717

18-
public class MetricsUtil {
18+
public final class MetricsUtil {
1919
public static final String GLOBAL_GROUP = "uaa.global.metrics";
2020

2121
// Utility classes should not have public constructors
@@ -24,28 +24,28 @@ private MetricsUtil() {
2424
}
2525

2626
public static double addAverages(double oldCount,
27-
double oldAverage,
28-
double newCount,
29-
double newAverage) {
30-
if (newCount==0) {
27+
double oldAverage,
28+
double newCount,
29+
double newAverage) {
30+
if (newCount == 0) {
3131
return oldAverage;
3232
}
3333
return
34-
((oldCount) / (newCount + oldCount) * oldAverage) +
35-
(newCount / (newCount + oldCount) * newAverage);
34+
(oldCount / (newCount + oldCount) * oldAverage) +
35+
(newCount / (newCount + oldCount) * newAverage);
3636
}
3737

3838
public static double addToAverage(double oldCount,
39-
double oldAverage,
40-
double newCount,
41-
double newTotalTime) {
42-
if (newCount==0) {
39+
double oldAverage,
40+
double newCount,
41+
double newTotalTime) {
42+
if (newCount == 0) {
4343
return oldAverage;
4444
}
4545
double newAverage = newTotalTime / newCount;
4646
return
47-
((oldCount) / (newCount + oldCount) * oldAverage) +
48-
(newCount / (newCount + oldCount) * newAverage);
47+
(oldCount / (newCount + oldCount) * oldAverage) +
48+
(newCount / (newCount + oldCount) * newAverage);
4949
}
5050

5151
public static class MutableLong {
@@ -69,7 +69,7 @@ public void add(long value) {
6969

7070
@Override
7171
public String toString() {
72-
return Long.valueOf(get()).toString();
72+
return Long.toString(get());
7373
}
7474
}
7575

@@ -94,7 +94,7 @@ public void add(double value) {
9494

9595
@Override
9696
public String toString() {
97-
return Double.valueOf(get()).toString();
97+
return Double.toString(get());
9898
}
9999
}
100100
}

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/metrics/RequestMetricSummary.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@
2222

2323
@JsonIgnoreProperties(ignoreUnknown = true)
2424
public class RequestMetricSummary {
25-
long count = 0;
25+
long count;
2626
double averageTime = 0;
27-
long intolerableCount = 0;
27+
long intolerableCount;
2828
double averageIntolerableTime = 0;
29-
long databaseQueryCount = 0;
29+
long databaseQueryCount;
3030
double averageDatabaseQueryTime = 0;
31-
long databaseIntolerableQueryCount = 0;
31+
long databaseIntolerableQueryCount;
3232
double averageDatabaseIntolerableQueryTime = 0;
3333

3434
public RequestMetricSummary() {
3535
}
3636

3737
@JsonCreator
3838
public RequestMetricSummary(@JsonProperty("count") long count,
39-
@JsonProperty("averageTime") double averageTime,
40-
@JsonProperty("intolerableCount") long intolerableCount,
41-
@JsonProperty("averageIntolerableTime") double averageIntolerableTime,
42-
@JsonProperty("databaseQueryCount") long databaseQueryCount,
43-
@JsonProperty("averageDatabaseQueryTime") double averageDatabaseQueryTime,
44-
@JsonProperty("databaseIntolerableQueryCount") long databaseIntolerableQueryCount,
45-
@JsonProperty("averageDatabaseIntolerableQueryTime") double averageDatabaseIntolerableQueryTime) {
39+
@JsonProperty("averageTime") double averageTime,
40+
@JsonProperty("intolerableCount") long intolerableCount,
41+
@JsonProperty("averageIntolerableTime") double averageIntolerableTime,
42+
@JsonProperty("databaseQueryCount") long databaseQueryCount,
43+
@JsonProperty("averageDatabaseQueryTime") double averageDatabaseQueryTime,
44+
@JsonProperty("databaseIntolerableQueryCount") long databaseIntolerableQueryCount,
45+
@JsonProperty("averageDatabaseIntolerableQueryTime") double averageDatabaseIntolerableQueryTime) {
4646
this.count = count;
4747
this.averageTime = averageTime;
4848
this.intolerableCount = intolerableCount;

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/metrics/StatusCodeGroup.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
package org.cloudfoundry.identity.uaa.metrics;
1717

1818
public enum StatusCodeGroup {
19-
INFORMATIONAL("1xx",1),
20-
SUCCESS("2xx",2),
21-
REDIRECT("3xx",3),
22-
CLIENT_ERROR("4xx",4),
23-
SERVER_ERROR("5xx",5);
19+
INFORMATIONAL("1xx", 1),
20+
SUCCESS("2xx", 2),
21+
REDIRECT("3xx", 3),
22+
CLIENT_ERROR("4xx", 4),
23+
SERVER_ERROR("5xx", 5);
2424

2525
private final String name;
2626
private final int value;

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/metrics/UrlGroup.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public UrlGroup setCategory(String category) {
6565
}
6666

6767
@JsonIgnore
68-
public Map<String,Object> getMap() {
68+
public Map<String, Object> getMap() {
6969
HashMap<String, Object> map = new HashMap<>();
7070
map.put("pattern", getPattern());
7171
map.put("group", getGroup());
@@ -74,11 +74,11 @@ public Map<String,Object> getMap() {
7474
return map;
7575
}
7676

77-
public static UrlGroup from(Map<String,Object> map) {
77+
public static UrlGroup from(Map<String, Object> map) {
7878
return new UrlGroup()
79-
.setPattern((String) map.get("pattern"))
80-
.setGroup((String) map.get("group"))
81-
.setCategory((String) map.get("category"))
82-
.setLimit(((Number) map.get("limit")).longValue());
79+
.setPattern((String) map.get("pattern"))
80+
.setGroup((String) map.get("group"))
81+
.setCategory((String) map.get("category"))
82+
.setLimit(((Number) map.get("limit")).longValue());
8383
}
8484
}

metrics-data/src/main/java/org/cloudfoundry/identity/uaa/util/JsonUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.databind.ObjectMapper;
2323

2424
import java.io.IOException;
25+
import java.io.Serial;
2526
import java.util.Date;
2627
import java.util.Map;
2728

@@ -134,6 +135,7 @@ public static JsonNode readTree(String s) {
134135
}
135136

136137
public static class JsonUtilException extends RuntimeException {
138+
@Serial
137139
private static final long serialVersionUID = -4804245225960963421L;
138140

139141
public JsonUtilException(Throwable cause) {
@@ -143,13 +145,15 @@ public JsonUtilException(Throwable cause) {
143145

144146
public static String serializeExcludingProperties(Object object, String... propertiesToExclude) {
145147
String serialized = JsonUtils.writeValueAsString(object);
146-
Map<String, Object> properties = JsonUtils.readValue(serialized, new TypeReference<>() {});
148+
Map<String, Object> properties = JsonUtils.readValue(serialized, new TypeReference<>() {
149+
});
147150
for (String property : propertiesToExclude) {
148151
if (property.contains(".")) {
149152
String[] split = property.split("\\.", 2);
150153
if (properties != null && properties.containsKey(split[0])) {
151154
Object inner = properties.get(split[0]);
152-
properties.put(split[0], JsonUtils.readValue(serializeExcludingProperties(inner, split[1]), new TypeReference<Map<String, Object>>() {}));
155+
properties.put(split[0], JsonUtils.readValue(serializeExcludingProperties(inner, split[1]), new TypeReference<Map<String, Object>>() {
156+
}));
153157
}
154158
} else {
155159
if (properties != null) {
@@ -190,7 +194,7 @@ public static Map<String, Object> getNodeAsMap(JsonNode node) {
190194
}
191195

192196
public static boolean hasLength(CharSequence str) {
193-
return !(str == null || str.length() == 0);
197+
return !(str == null || str.isEmpty());
194198
}
195199

196200
public static boolean hasText(CharSequence str) {

0 commit comments

Comments
 (0)