Skip to content

Commit cd86849

Browse files
wettedmicronaut-buildtimyates
authored
Fix java 21 build (#421)
* Update common files * build plugin to 6.6.0 * Revert "add import" This reverts commit e9a0b15. * Ensure lock is unlocked * Poke CI * Fix smells --------- Co-authored-by: micronaut-build <[email protected]> Co-authored-by: Tim Yates <[email protected]>
1 parent e62a711 commit cd86849

File tree

6 files changed

+81
-68
lines changed

6 files changed

+81
-68
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ end_of_line = lf
1212
[{*.bat,*.cmd}]
1313
end_of_line = crlf
1414

15+
[{*.mustache,*.ftl}]
16+
insert_final_newline = false
17+
1518
[*.java]
1619
indent_size = 4
1720
tab_width = 4

.github/workflows/graalvm-latest.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
runs-on: ubuntu-latest
3535
strategy:
3636
max-parallel: 6
37-
matrix: ${{ fromJson(needs.build_matrix.outputs.matrix) }}
37+
matrix:
38+
java: ['17', '21']
39+
native_test_task: ${{ fromJson(needs.build_matrix.outputs.matrix).native_test_task }}
3840
env:
3941
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
4042
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
@@ -46,7 +48,7 @@ jobs:
4648
id: pre-build
4749
with:
4850
distribution: 'graalvm'
49-
java: '17'
51+
java: ${{ matrix.java }}
5052
- name: Build Steps
5153
uses: micronaut-projects/github-actions/graalvm/build@master
5254
id: build
@@ -60,4 +62,4 @@ jobs:
6062
uses: micronaut-projects/github-actions/graalvm/post-build@master
6163
id: post-build
6264
with:
63-
java: '17'
65+
java: ${{ matrix.java }}

.github/workflows/gradle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
java: ['17']
22+
java: ['17', '21']
2323
env:
2424
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
2525
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
@@ -64,7 +64,7 @@ jobs:
6464
./gradlew check --no-daemon --continue
6565
6666
- name: "🔎 Run static analysis"
67-
if: env.SONAR_TOKEN != ''
67+
if: env.SONAR_TOKEN != '' && matrix.java == '17'
6868
run: |
6969
./gradlew sonar
7070

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pluginManagement {
99
}
1010

1111
plugins {
12-
id 'io.micronaut.build.shared.settings' version '6.5.6'
12+
id 'io.micronaut.build.shared.settings' version '6.6.0'
1313
}
1414
rootProject.name = 'testresources-parent'
1515

test-resources-server/src/test/resources/logback.xml

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
<root level="info">
1212
<appender-ref ref="STDOUT" />
1313
</root>
14+
<logger name="io.micronaut.testresources.server" level="debug" />
15+
<logger name="io.micronaut.testresources.testcontainers" level="trace" />
1416
</configuration>

test-resources-testcontainers/src/main/java/io/micronaut/testresources/testcontainers/TestContainers.java

+68-62
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ private TestContainers() {
5252

5353
}
5454

55+
private static <B> B withLock(String description, Supplier<B> supplier) {
56+
LOCK.lock();
57+
if (LOGGER.isTraceEnabled()) {
58+
LOGGER.trace("Locked for {}", description);
59+
}
60+
try {
61+
return supplier.get();
62+
} finally {
63+
if (LOGGER.isTraceEnabled()) {
64+
LOGGER.trace("Unlocked for {}", description);
65+
}
66+
LOCK.unlock();
67+
}
68+
}
69+
5570
/**
5671
* Returns a test container and caches it, so that if the same owner
5772
* and properties are requested, we can return an existing container.
@@ -71,19 +86,18 @@ static <T extends GenericContainer<? extends T>> T getOrCreate(String requestedP
7186
Map<String, Object> query,
7287
Supplier<T> creator) {
7388
Key key = Key.of(owner, name, Scope.from(query), query);
74-
LOCK.lock();
75-
@SuppressWarnings("unchecked")
76-
T container = (T) CONTAINERS_BY_KEY.get(key);
77-
if (container == null) {
78-
container = creator.get();
79-
LOGGER.info("Starting test container {}", name);
80-
container.start();
81-
CONTAINERS_BY_KEY.put(key, container);
82-
}
83-
CONTAINERS_BY_PROPERTY.computeIfAbsent(requestedProperty, e -> new LinkedHashSet<>())
84-
.add(container);
85-
LOCK.unlock();
86-
return container;
89+
return withLock("getOrCreate", () -> {
90+
T container = (T) CONTAINERS_BY_KEY.get(key);
91+
if (container == null) {
92+
container = creator.get();
93+
LOGGER.info("Starting test container {}", name);
94+
container.start();
95+
CONTAINERS_BY_KEY.put(key, container);
96+
}
97+
CONTAINERS_BY_PROPERTY.computeIfAbsent(requestedProperty, e -> new LinkedHashSet<>())
98+
.add(container);
99+
return container;
100+
});
87101
}
88102

89103
/**
@@ -101,9 +115,8 @@ public static Map<Scope, List<GenericContainer<?>>> listByScope(String id) {
101115
}
102116

103117
private static Map<Scope, List<GenericContainer<?>>> listByScope(Scope scope) {
104-
LOCK.lock();
105-
try {
106-
return CONTAINERS_BY_KEY.entrySet()
118+
return withLock("listByScope", () ->
119+
CONTAINERS_BY_KEY.entrySet()
107120
.stream()
108121
.filter(entry -> scope.includes(entry.getKey().scope))
109122
.collect(Collectors.groupingBy(
@@ -112,45 +125,41 @@ private static Map<Scope, List<GenericContainer<?>>> listByScope(Scope scope) {
112125
Map.Entry::getValue,
113126
Collectors.toList()
114127
)
115-
));
116-
} finally {
117-
LOCK.unlock();
118-
}
128+
))
129+
);
119130
}
120131

132+
@SuppressWarnings("java:S6204") // toList() breaks the return type
121133
private static List<GenericContainer<?>> filterByScope(Scope scope, Set<GenericContainer<?>> containers) {
122134
if (containers.isEmpty()) {
123135
return Collections.emptyList();
124136
}
125-
LOCK.lock();
126-
try {
127-
return CONTAINERS_BY_KEY.entrySet()
137+
return withLock("filterByScope", () ->
138+
CONTAINERS_BY_KEY.entrySet()
128139
.stream()
129140
.filter(entry -> containers.contains(entry.getValue()) && scope.includes(entry.getKey().scope))
130141
.map(Map.Entry::getValue)
131-
.collect(Collectors.toList());
132-
} finally {
133-
LOCK.unlock();
134-
}
142+
.collect(Collectors.toList())
143+
);
135144
}
136145

137146
public static Network network(String name) {
138147
return NETWORKS_BY_KEY.computeIfAbsent(name, k -> Network.newNetwork());
139148
}
140149

141150
public static boolean closeAll() {
142-
LOCK.lock();
143-
boolean closed = false;
144-
for (GenericContainer<?> container : CONTAINERS_BY_KEY.values()) {
145-
container.close();
146-
closed = true;
147-
}
148-
CONTAINERS_BY_KEY.clear();
149-
CONTAINERS_BY_PROPERTY.clear();
150-
NETWORKS_BY_KEY.values().forEach(Network::close);
151-
NETWORKS_BY_KEY.clear();
152-
LOCK.unlock();
153-
return closed;
151+
return withLock("closeAll", () -> {
152+
boolean closed = false;
153+
for (GenericContainer<?> container : CONTAINERS_BY_KEY.values()) {
154+
container.close();
155+
closed = true;
156+
}
157+
CONTAINERS_BY_KEY.clear();
158+
CONTAINERS_BY_PROPERTY.clear();
159+
NETWORKS_BY_KEY.values().forEach(Network::close);
160+
NETWORKS_BY_KEY.clear();
161+
return closed;
162+
});
154163
}
155164

156165
public static Map<String, Network> getNetworks() {
@@ -159,44 +168,41 @@ public static Map<String, Network> getNetworks() {
159168

160169
public static boolean closeScope(String id) {
161170
Scope scope = Scope.of(id);
162-
LOCK.lock();
163-
boolean closed = false;
164-
Iterator<Map.Entry<Key, GenericContainer<?>>> iterator = CONTAINERS_BY_KEY.entrySet().iterator();
165-
while (iterator.hasNext()) {
166-
Map.Entry<Key, GenericContainer<?>> entry = iterator.next();
167-
var existingScope = entry.getKey().scope;
168-
if (scope.includes(existingScope)) {
169-
iterator.remove();
170-
GenericContainer<?> container = entry.getValue();
171-
LOGGER.debug("Stopping container {}", container.getContainerId());
172-
container.close();
173-
closed = true;
174-
for (Set<GenericContainer<?>> value : CONTAINERS_BY_PROPERTY.values()) {
175-
value.remove(container);
171+
return withLock("closeScope", () -> {
172+
boolean closed = false;
173+
Iterator<Map.Entry<Key, GenericContainer<?>>> iterator = CONTAINERS_BY_KEY.entrySet().iterator();
174+
while (iterator.hasNext()) {
175+
Map.Entry<Key, GenericContainer<?>> entry = iterator.next();
176+
var existingScope = entry.getKey().scope;
177+
if (scope.includes(existingScope)) {
178+
iterator.remove();
179+
GenericContainer<?> container = entry.getValue();
180+
LOGGER.debug("Stopping container {}", container.getContainerId());
181+
container.close();
182+
closed = true;
183+
for (Set<GenericContainer<?>> value : CONTAINERS_BY_PROPERTY.values()) {
184+
value.remove(container);
185+
}
176186
}
177187
}
178-
}
179-
LOCK.unlock();
180-
return closed;
188+
return closed;
189+
});
181190
}
182191

183192
public static List<GenericContainer<?>> findByRequestedProperty(Scope scope, String property) {
184-
LOCK.lock();
185-
try {
193+
return withLock("findByRequestedProperty", () -> {
186194
Set<GenericContainer<?>> byProperty = CONTAINERS_BY_PROPERTY.getOrDefault(property, Collections.emptySet());
187195
LOGGER.debug("Found {} containers for property {}. All properties: {}", byProperty.size(), property, CONTAINERS_BY_PROPERTY.keySet());
188196
return filterByScope(scope, byProperty);
189-
} finally {
190-
LOCK.unlock();
191-
}
197+
});
192198
}
193199

194200
private static final class Key {
195201
private final Class<?> type;
196202
private final String name;
197-
private final Scope scope;
198203
private final Map<String, String> properties;
199204
private final int hashCode;
205+
final Scope scope;
200206

201207
private Key(Class<?> type, String name, Scope scope, Map<String, String> properties) {
202208
this.type = type;

0 commit comments

Comments
 (0)