Skip to content

Commit 1fb440c

Browse files
authored
Build log fix (helidon-io#7128)
* Explicitly set context class loader for Pico annotation processor, so we do not get slf4j warnings Add slf4j jdk library to Pico tools, so the binder is available * TypeName is now built, so equals and hashCode work as expected.
1 parent f57b450 commit 1fb440c

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

pico/processor/src/main/java/io/helidon/pico/processor/PicoAnnotationProcessor.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,23 @@ public void init(ProcessingEnvironment processingEnv) {
161161
}
162162

163163
@Override
164-
public boolean process(Set<? extends TypeElement> annotations,
164+
public final boolean process(Set<? extends TypeElement> annotations,
165165
RoundEnvironment roundEnv) {
166+
167+
Thread thread = Thread.currentThread();
168+
ClassLoader previousClassloader = thread.getContextClassLoader();
169+
thread.setContextClassLoader(PicoAnnotationProcessor.class.getClassLoader());
170+
171+
// we want everything to execute in the classloader of this type, so service loaders
172+
// use the classpath of the annotation processor, and not some "random" classloader, such as a maven one
173+
try {
174+
return doProcess(annotations, roundEnv);
175+
} finally {
176+
thread.setContextClassLoader(previousClassloader);
177+
}
178+
}
179+
180+
protected boolean doProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
166181
utils().roundEnv(roundEnv);
167182

168183
if (disableBaseProcessing && getClass() == PicoAnnotationProcessor.class) {
@@ -179,7 +194,8 @@ public boolean process(Set<? extends TypeElement> annotations,
179194
allElementsOfInterestInThisModule.addAll(elementsOfInterestInThisRound);
180195

181196
// cumulatively collect the types to process in the module
182-
gatherTypeInfosToProcessInThisModule(typeInfoToCreateActivatorsForInThisModule, allElementsOfInterestInThisModule);
197+
gatherTypeInfosToProcessInThisModule(typeInfoToCreateActivatorsForInThisModule,
198+
allElementsOfInterestInThisModule);
183199

184200
// optionally intercept and validate the model
185201
Set<TypeInfo> filtered = interceptorAndValidate(typeInfoToCreateActivatorsForInThisModule.values());

pico/tools/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<groupId>com.github.jknack</groupId>
6666
<artifactId>handlebars</artifactId>
6767
</dependency>
68+
<dependency>
69+
<!-- required as handlebars use slf4j -->
70+
<groupId>org.slf4j</groupId>
71+
<artifactId>slf4j-jdk14</artifactId>
72+
</dependency>
6873
<dependency>
6974
<groupId>io.github.classgraph</groupId>
7075
<artifactId>classgraph</artifactId>

pico/tools/src/main/java/io/helidon/pico/tools/InterceptorCreatorDefault.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,8 @@ private static TypeName toInterceptorTypeName(String serviceTypeName) {
10971097
TypeName typeName = TypeName.create(serviceTypeName);
10981098
return TypeName.builder()
10991099
.packageName(typeName.packageName())
1100-
.className(typeName.className() + INNER_INTERCEPTOR_CLASS_NAME);
1100+
.className(typeName.className() + INNER_INTERCEPTOR_CLASS_NAME)
1101+
.build();
11011102
}
11021103

11031104
/**

0 commit comments

Comments
 (0)