Skip to content

Commit 4f3cf5a

Browse files
authored
Improve consistency with unified code format/imports (#3156)
Configures the spring-javaformat plugin to enforce and apply code formatting as part of the build. Applies the formatting to existing code. Also adds to editorconfig configuration for import order and updates all imports. There is no generic support for Java import order configuration in editorconfig, so an IntelliJ specific configuration is used.
1 parent d8b06e7 commit 4f3cf5a

File tree

679 files changed

+13655
-12263
lines changed

Some content is hidden

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

679 files changed

+13655
-12263
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ insert_final_newline = true
77
indent_style = space
88
indent_size = 4
99
continuation_indent_size = 8
10+
ij_java_imports_layout = *,|,javax.**,java.**,|,$*
11+
ij_java_class_count_to_use_import_on_demand = 5
12+
ij_java_names_count_to_use_import_on_demand = 3

.springjavaformatconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
java-baseline=8
2+
indentation-style=spaces

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ The wrapper can be used with a command, for example, `./gradlew check` to build
4242

4343
This repository should be imported as a Gradle project into your IDE of choice.
4444

45+
## Code formatting
46+
47+
The [spring-javaformat plugin](https://github.com/spring-io/spring-javaformat) is configured to check and apply consistent formatting in the codebase through the build.
48+
The `checkFormat` task checks the formatting as part of the `check` task.
49+
Apply formatting with the `format` task.
50+
You should rely on the formatting the `format` task applies instead of your IDE's configured formatting.
51+
4552
## Testing changes locally
4653

4754
Specific modules or a test class can be run from your IDE for convenience.

benchmarks/benchmarks-core/src/jmh/java/io/micrometer/benchmark/compare/CompareCountersWithOtherLibraries.java

+25-11
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
@OutputTimeUnit(TimeUnit.NANOSECONDS)
3838
@Threads(16)
3939
public class CompareCountersWithOtherLibraries {
40+
4041
@State(Scope.Benchmark)
4142
public static class DropwizardState {
43+
4244
com.codahale.metrics.MetricRegistry registry;
45+
4346
com.codahale.metrics.Counter counter;
4447

4548
@Setup(Level.Trial)
@@ -52,12 +55,16 @@ public void setup() {
5255
public void tearDown(Blackhole hole) {
5356
hole.consume(counter.getCount());
5457
}
58+
5559
}
5660

5761
@State(Scope.Benchmark)
5862
public static class MicrometerState {
63+
5964
io.micrometer.core.instrument.MeterRegistry registry;
65+
6066
io.micrometer.core.instrument.Counter counter;
67+
6168
io.micrometer.core.instrument.Counter counterWithTags;
6269

6370
@Setup(Level.Trial)
@@ -75,13 +82,16 @@ public void tearDown(Blackhole hole) {
7582
}
7683
}
7784
}
85+
7886
}
7987

8088
@State(Scope.Benchmark)
8189
public static class Dropwizard5State {
8290

8391
io.dropwizard.metrics5.MetricRegistry registry;
92+
8493
io.dropwizard.metrics5.Counter counter;
94+
8595
io.dropwizard.metrics5.Counter counterWithTags;
8696

8797
@Setup(Level.Trial)
@@ -100,39 +110,44 @@ public void tearDown(Blackhole hole) {
100110
hole.consume(c.getCount());
101111
}
102112
}
113+
103114
}
104115

105116
@State(Scope.Benchmark)
106117
public static class PrometheusState {
118+
107119
io.prometheus.client.Counter counter;
120+
108121
io.prometheus.client.Counter counterWithTags;
109122

110123
@Setup(Level.Trial)
111124
public void setup() {
112125
counter = io.prometheus.client.Counter.build().name("counter").help("A counter").create();
113-
counterWithTags = io.prometheus.client.Counter.build().name("counter").help("Counter with two tags declared").labelNames("key1", "key2").register();
126+
counterWithTags = io.prometheus.client.Counter.build().name("counter")
127+
.help("Counter with two tags declared").labelNames("key1", "key2").register();
114128
}
129+
115130
}
116131

117-
// @Benchmark
132+
// @Benchmark
118133
public void dropwizard5Counter(Dropwizard5State state) {
119134
state.counter.inc();
120135
}
121136

122-
// @Benchmark
137+
// @Benchmark
123138
public void dropwizard5CounterFixedTags(Dropwizard5State state) {
124139
state.counterWithTags.inc();
125140
}
126141

127-
// @Benchmark
142+
// @Benchmark
128143
public void dropwizard5CounterTags(Dropwizard5State state) {
129144
Map<String, String> tags = new HashMap<>();
130145
tags.put("key1", "value1");
131146
tags.put("key2", "value2");
132147
state.registry.counter(new io.dropwizard.metrics5.MetricName("tagged", tags)).inc();
133148
}
134149

135-
// @Benchmark
150+
// @Benchmark
136151
public void micrometerCounter(MicrometerState state) {
137152
state.counter.increment();
138153
}
@@ -142,12 +157,12 @@ public void micrometerCounterTags(MicrometerState state) {
142157
state.registry.counter("dynamicTags", "key1", "value1", "key2", "value2").increment();
143158
}
144159

145-
// @Benchmark
160+
// @Benchmark
146161
public void micrometerCounterFixedTags(MicrometerState state) {
147162
state.counterWithTags.increment();
148163
}
149164

150-
// @Benchmark
165+
// @Benchmark
151166
public void prometheusCounter(PrometheusState state) {
152167
state.counter.inc();
153168
}
@@ -158,10 +173,9 @@ public void prometheusCounterWithTags(PrometheusState state) {
158173
}
159174

160175
public static void main(String[] args) throws RunnerException {
161-
Options opt = new OptionsBuilder()
162-
.include(CompareCountersWithOtherLibraries.class.getSimpleName())
163-
.addProfiler(GCProfiler.class)
164-
.build();
176+
Options opt = new OptionsBuilder().include(CompareCountersWithOtherLibraries.class.getSimpleName())
177+
.addProfiler(GCProfiler.class).build();
165178
new Runner(opt).run();
166179
}
180+
167181
}

benchmarks/benchmarks-core/src/jmh/java/io/micrometer/benchmark/compare/CompareHistogramsWithOtherLibraries.java

+30-29
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//CHECKSTYLE:OFF
2323
import com.google.common.collect.Iterators;
2424
import com.google.common.primitives.Doubles;
25-
////CHECKSTYLE:ON
25+
//CHECKSTYLE:ON
2626
import io.micrometer.core.instrument.Clock;
2727
import io.micrometer.core.instrument.DistributionSummary;
2828
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
@@ -63,30 +63,30 @@ public static class Data {
6363
@Setup(Level.Iteration)
6464
public void setup() {
6565
final Random r = new Random(1234567891L);
66-
dataIterator = Iterators.cycle(
67-
Stream.generate(() -> Math.round(Math.exp(2.0 + r.nextGaussian()))).limit(1048576)
68-
.collect(Collectors.toList()));
66+
dataIterator = Iterators.cycle(Stream.generate(() -> Math.round(Math.exp(2.0 + r.nextGaussian())))
67+
.limit(1048576).collect(Collectors.toList()));
6968
}
69+
7070
}
7171

7272
@State(Scope.Benchmark)
7373
public static class DropwizardState {
7474

7575
MetricRegistry registry;
76+
7677
Histogram histogram;
78+
7779
Histogram histogramSlidingTimeWindow;
80+
7881
Histogram histogramUniform;
7982

8083
@Setup(Level.Iteration)
8184
public void setup() {
8285
registry = new MetricRegistry();
8386
histogram = registry.histogram("histogram");
84-
histogramSlidingTimeWindow =
85-
registry.register("slidingTimeWindowHistogram",
86-
new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS)));
87-
histogramUniform =
88-
registry.register("uniformHistogram",
89-
new Histogram(new UniformReservoir()));
87+
histogramSlidingTimeWindow = registry.register("slidingTimeWindowHistogram",
88+
new Histogram(new SlidingTimeWindowReservoir(10, TimeUnit.SECONDS)));
89+
histogramUniform = registry.register("uniformHistogram", new Histogram(new UniformReservoir()));
9090
}
9191

9292
@TearDown(Level.Iteration)
@@ -95,33 +95,34 @@ public void tearDown(Blackhole hole) {
9595
hole.consume(histogramSlidingTimeWindow.getSnapshot().getMedian());
9696
hole.consume(histogramUniform.getSnapshot().getMedian());
9797
}
98+
9899
}
99100

100101
@State(Scope.Benchmark)
101102
public static class MicrometerState {
102103

103104
io.micrometer.core.instrument.MeterRegistry registry;
105+
104106
io.micrometer.core.instrument.DistributionSummary summary;
105107

106108
@Setup(Level.Iteration)
107109
public void setup() {
108-
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(),
109-
Clock.SYSTEM);
110-
summary = DistributionSummary.builder("summary")
111-
.publishPercentileHistogram()
112-
.register(registry);
110+
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(), Clock.SYSTEM);
111+
summary = DistributionSummary.builder("summary").publishPercentileHistogram().register(registry);
113112
}
114113

115114
@TearDown(Level.Iteration)
116115
public void tearDown(Blackhole hole) {
117116
hole.consume(summary.takeSnapshot().count());
118117
}
118+
119119
}
120120

121121
@State(Scope.Benchmark)
122122
public static class MicrometerPlainSummaryState {
123123

124124
io.micrometer.core.instrument.MeterRegistry registry;
125+
125126
io.micrometer.core.instrument.DistributionSummary summary;
126127

127128
@Setup(Level.Iteration)
@@ -134,6 +135,7 @@ public void setup() {
134135
public void tearDown(Blackhole hole) {
135136
hole.consume(summary.takeSnapshot().count());
136137
}
138+
137139
}
138140

139141
@State(Scope.Benchmark)
@@ -143,55 +145,54 @@ public static class PrometheusState {
143145

144146
@Setup(Level.Trial)
145147
public void setup() {
146-
double[] micrometerBuckets =
147-
Doubles.toArray(PercentileHistogramBuckets.buckets(
148-
DistributionStatisticConfig.builder().minimumExpectedValue(0.0).maximumExpectedValue(Double.POSITIVE_INFINITY)
149-
.percentilesHistogram(true).build()));
150-
histogram = io.prometheus.client.Histogram.build("histogram", "A histogram")
151-
.buckets(micrometerBuckets).create();
148+
double[] micrometerBuckets = Doubles.toArray(
149+
PercentileHistogramBuckets.buckets(DistributionStatisticConfig.builder().minimumExpectedValue(0.0)
150+
.maximumExpectedValue(Double.POSITIVE_INFINITY).percentilesHistogram(true).build()));
151+
histogram = io.prometheus.client.Histogram.build("histogram", "A histogram").buckets(micrometerBuckets)
152+
.create();
152153
}
153154

154155
@TearDown(Level.Iteration)
155156
public void tearDown(Blackhole hole) {
156157
hole.consume(histogram.collect());
157158
}
159+
158160
}
159161

160162
@Benchmark
161163
public void micrometerPlainHistogram(MicrometerPlainSummaryState state, Data data) {
162164
state.summary.record(1);
163165
}
164166

165-
// @Benchmark
167+
// @Benchmark
166168
public void micrometerHistogram(MicrometerState state, Data data) {
167169
state.summary.record(data.dataIterator.next());
168170
}
169171

170-
// @Benchmark
172+
// @Benchmark
171173
public void dropwizardHistogram(DropwizardState state, Data data) {
172174
state.histogram.update(data.dataIterator.next());
173175
}
174176

175177
// This benchmark is likely broken, results vary wildly between runs.
176-
// @Benchmark
178+
// @Benchmark
177179
public void dropwizardHistogramSlidingTimeWindow(DropwizardState state, Data data) {
178180
state.histogramSlidingTimeWindow.update(data.dataIterator.next());
179181
}
180182

181-
// @Benchmark
183+
// @Benchmark
182184
public void dropwizardHistogramUniform(DropwizardState state, Data data) {
183185
state.histogramUniform.update(data.dataIterator.next());
184186
}
185187

186-
// @Benchmark
188+
// @Benchmark
187189
public void prometheusHistogram(PrometheusState state, Data data) {
188190
state.histogram.observe(data.dataIterator.next());
189191
}
190192

191193
public static void main(String[] args) throws RunnerException {
192-
Options opt = new OptionsBuilder()
193-
.include(CompareHistogramsWithOtherLibraries.class.getSimpleName())
194-
.build();
194+
Options opt = new OptionsBuilder().include(CompareHistogramsWithOtherLibraries.class.getSimpleName()).build();
195195
new Runner(opt).run();
196196
}
197+
197198
}

benchmarks/benchmarks-core/src/jmh/java/io/micrometer/benchmark/core/CounterBenchmark.java

+6
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,27 @@
3030
@State(Scope.Benchmark)
3131
@OutputTimeUnit(TimeUnit.MICROSECONDS)
3232
public class CounterBenchmark {
33+
3334
public static void main(String[] args) throws RunnerException {
35+
// @formatter:off
3436
Options opt = new OptionsBuilder()
3537
.include(CounterBenchmark.class.getSimpleName())
3638
.warmupIterations(5)
3739
.measurementIterations(10)
3840
.mode(Mode.SampleTime)
3941
.forks(1)
4042
.build();
43+
// @formatter:on
4144

4245
new Runner(opt).run();
4346
}
4447

4548
private int x = 923;
49+
4650
private int y = 123;
4751

4852
private MeterRegistry registry;
53+
4954
private Counter counter;
5055

5156
@Setup
@@ -70,4 +75,5 @@ public int countSumWithRegistryLookup() {
7075
public int sum() {
7176
return x + y;
7277
}
78+
7379
}

benchmarks/benchmarks-core/src/jmh/java/io/micrometer/benchmark/core/MeterRegistrationBenchmark.java

+5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
@State(Scope.Benchmark)
2929
@OutputTimeUnit(TimeUnit.MICROSECONDS)
3030
public class MeterRegistrationBenchmark {
31+
3132
public static void main(String[] args) throws RunnerException {
33+
// @formatter:off
3234
Options opt = new OptionsBuilder()
3335
.include(MeterRegistrationBenchmark.class.getSimpleName())
3436
.warmupIterations(2)
@@ -37,11 +39,13 @@ public static void main(String[] args) throws RunnerException {
3739
.timeUnit(TimeUnit.SECONDS)
3840
.forks(1)
3941
.build();
42+
// @formatter:on
4043

4144
new Runner(opt).run();
4245
}
4346

4447
private int x = 923;
48+
4549
private int y = 123;
4650

4751
@Benchmark
@@ -57,4 +61,5 @@ public int insert10_000() {
5761
public int sum() {
5862
return x + y;
5963
}
64+
6065
}

benchmarks/benchmarks-core/src/jmh/java/io/micrometer/benchmark/core/TagsBenchmark.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@BenchmarkMode(Mode.AverageTime)
3131
@OutputTimeUnit(TimeUnit.NANOSECONDS)
3232
public class TagsBenchmark {
33+
3334
@Threads(16)
3435
@Benchmark
3536
public void of() {
@@ -43,9 +44,8 @@ public void dotAnd() {
4344
}
4445

4546
public static void main(String[] args) throws RunnerException {
46-
Options opt = new OptionsBuilder()
47-
.include(TagsBenchmark.class.getSimpleName())
48-
.build();
47+
Options opt = new OptionsBuilder().include(TagsBenchmark.class.getSimpleName()).build();
4948
new Runner(opt).run();
5049
}
50+
5151
}

0 commit comments

Comments
 (0)