Skip to content

Commit 23711f3

Browse files
4.x: Metadata module and loading of files compatible with single jars (helidon-io#10660)
* Introduced Helidon metadata module. Updated all places where we read metadata files to use the new module. Support for manifest file or classpath scanning depending on deployment "shape" * Fix for windows - make sure we use / in location. * Simplified implementation, removed customization. * Fixes to updated behavior. * Fixed build issue - wrong javadoc. * Update to classpath scanning to avoid problems with closed jar file system. Updated packaging test to use fat jar (only SE-1) * Add debug for troubleshooting. * Fix pattern to pick up integration tests. * Removed troubleshooting log config. * Added fat jar tests to SE inject. Updated MP packaging tests to run no tests in the fat jar profile. * Update comments and javadocs --------- Co-authored-by: Romain Grecourt <romain.grecourt@oracle.com>
1 parent 32e9deb commit 23711f3

98 files changed

Lines changed: 2106 additions & 186 deletions

File tree

Some content is hidden

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

.github/workflows/validate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315
strategy:
316316
matrix:
317317
os: [ ubuntu-22.04, macos-14, windows-2022 ]
318-
packaging: [ jar, jlink ]
318+
packaging: [ jar, jlink, fat-jar ]
319319
include:
320320
- { os: ubuntu-22.04, platform: linux }
321321
- { os: macos-14, platform: macos }

all/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,10 @@
12731273
<groupId>io.helidon.declarative</groupId>
12741274
<artifactId>helidon-declarative-codegen</artifactId>
12751275
</dependency>
1276+
<dependency>
1277+
<groupId>io.helidon.metadata</groupId>
1278+
<artifactId>helidon-metadata</artifactId>
1279+
</dependency>
12761280
<dependency>
12771281
<groupId>io.helidon.metadata</groupId>
12781282
<artifactId>helidon-metadata-hson</artifactId>

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,11 @@
17211721
</dependency>
17221722

17231723
<!-- Metadata -->
1724+
<dependency>
1725+
<groupId>io.helidon.metadata</groupId>
1726+
<artifactId>helidon-metadata</artifactId>
1727+
<version>${helidon.version}</version>
1728+
</dependency>
17241729
<dependency>
17251730
<groupId>io.helidon.metadata</groupId>
17261731
<artifactId>helidon-metadata-hson</artifactId>

builder/codegen/src/main/java/io/helidon/builder/codegen/BuilderCodegen.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import io.helidon.common.types.Modifier;
4747
import io.helidon.common.types.TypeInfo;
4848
import io.helidon.common.types.TypeName;
49+
import io.helidon.metadata.MetadataConstants;
4950

5051
import static io.helidon.builder.codegen.Types.RUNTIME_PROTOTYPE;
5152

@@ -319,7 +320,11 @@ private static void generateCustomMethods(ClassModel.Builder classModel,
319320

320321
private void updateServiceLoaderResource() {
321322
CodegenFiler filer = ctx.filer();
322-
FilerTextResource serviceLoaderResource = filer.textResource("META-INF/helidon/service.loader");
323+
String moduleName = ctx.moduleName().orElse(null);
324+
String resourceLocation = MetadataConstants.LOCATION
325+
+ (moduleName == null ? "" : "/" + moduleName)
326+
+ "/" + MetadataConstants.SERVICE_LOADER_FILE;
327+
FilerTextResource serviceLoaderResource = filer.textResource(resourceLocation);
323328
List<String> lines = new ArrayList<>(serviceLoaderResource.lines());
324329
if (lines.isEmpty()) {
325330
lines.add("# List of service contracts we want to support either from service registry, or from service loader");
@@ -335,6 +340,8 @@ private void updateServiceLoaderResource() {
335340
if (modified) {
336341
serviceLoaderResource.lines(lines);
337342
serviceLoaderResource.write();
343+
filer.manifest()
344+
.add(resourceLocation);
338345
}
339346
}
340347

builder/codegen/src/main/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
requires io.helidon.common.types;
2424
requires io.helidon.codegen;
2525
requires io.helidon.codegen.classmodel;
26+
requires io.helidon.metadata;
2627

2728
exports io.helidon.builder.codegen;
2829

codegen/apt/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
</description>
3333

3434
<dependencies>
35+
<dependency>
36+
<groupId>io.helidon.common</groupId>
37+
<artifactId>helidon-common</artifactId>
38+
</dependency>
3539
<dependency>
3640
<groupId>io.helidon.common</groupId>
3741
<artifactId>helidon-common-types</artifactId>

codegen/apt/src/main/java/io/helidon/codegen/apt/AptContextImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,11 +70,12 @@ static AptContextImpl create(ProcessingEnvironment env, Set<Option<?>> supported
7070

7171
CodegenScope scope = guessScope(env, options);
7272
Optional<ModuleInfo> module = findModule(env.getFiler());
73+
AptFiler filer = new AptFiler(env, options);
7374

7475
return new AptContextImpl(env,
7576
options,
7677
supportedOptions,
77-
new AptFiler(env, options),
78+
filer,
7879
new AptLogger(env, options),
7980
scope,
8081
module.orElse(null));

codegen/apt/src/main/java/io/helidon/codegen/apt/AptFiler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,14 +39,17 @@
3939
import io.helidon.codegen.FilerResource;
4040
import io.helidon.codegen.FilerTextResource;
4141
import io.helidon.codegen.IndentType;
42+
import io.helidon.codegen.ManifestResource;
4243
import io.helidon.codegen.classmodel.ClassModel;
44+
import io.helidon.common.LazyValue;
4345
import io.helidon.common.types.TypeName;
4446

4547
import static java.nio.charset.StandardCharsets.UTF_8;
4648

4749
class AptFiler implements CodegenFiler {
4850
private final Filer filer;
4951
private final String indent;
52+
private final LazyValue<ManifestResource> manifestResource;
5053

5154
AptFiler(ProcessingEnvironment env, CodegenOptions options) {
5255
this.filer = env.getFiler();
@@ -55,6 +58,7 @@ class AptFiler implements CodegenFiler {
5558
int codegenRepeat = CodegenOptions.INDENT_COUNT.value(options);
5659

5760
this.indent = String.valueOf(value.character()).repeat(codegenRepeat);
61+
this.manifestResource = LazyValue.create(() -> ManifestResource.create(this));
5862
}
5963

6064
@Override
@@ -141,6 +145,11 @@ public FilerResource resource(String location, Object... originatingElements) {
141145
}
142146
}
143147

148+
@Override
149+
public ManifestResource manifest() {
150+
return manifestResource.get();
151+
}
152+
144153
private Object originatingElement(Element[] elements, Object alternative) {
145154
if (elements.length == 0) {
146155
return alternative;

codegen/apt/src/main/java/io/helidon/codegen/apt/AptProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private boolean doProcess(Set<? extends TypeElement> annotations, RoundEnvironme
128128

129129
if (roundEnv.processingOver()) {
130130
codegen.processingOver();
131+
ctx.filer().manifest().write();
131132
return annotations.isEmpty();
132133
}
133134

codegen/codegen/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
<groupId>io.helidon.common</groupId>
4040
<artifactId>helidon-common-types</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>io.helidon.metadata</groupId>
44+
<artifactId>helidon-metadata</artifactId>
45+
</dependency>
4246
<dependency>
4347
<groupId>io.helidon.codegen</groupId>
4448
<artifactId>helidon-codegen-class-model</artifactId>

0 commit comments

Comments
 (0)