Skip to content

Commit 3d093f0

Browse files
authored
Merge pull request #37044 from FroMage/apt
Better support for APT in dev mode
2 parents 1a1bce7 + b1f9947 commit 3d093f0

File tree

35 files changed

+1055
-59
lines changed

35 files changed

+1055
-59
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/CompilationProvider.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Context {
5151
private final List<String> compilePluginArtifacts;
5252
private final List<String> compilerPluginOptions;
5353
private final boolean ignoreModuleInfo;
54+
private final File generatedSourcesDirectory;
55+
private final Set<File> annotationProcessorPaths;
56+
private final List<String> annotationProcessors;
5457

5558
public Context(
5659
String name,
@@ -65,7 +68,11 @@ public Context(
6568
String sourceJavaVersion,
6669
String targetJvmVersion,
6770
List<String> compilePluginArtifacts,
68-
List<String> compilerPluginOptions, String ignoreModuleInfo) {
71+
List<String> compilerPluginOptions,
72+
File generatedSourcesDirectory,
73+
Set<File> annotationProcessorPaths,
74+
List<String> annotationProcessors,
75+
String ignoreModuleInfo) {
6976
this.name = name;
7077
this.classpath = classpath;
7178
this.reloadableClasspath = reloadableClasspath;
@@ -80,6 +87,9 @@ public Context(
8087
this.compilePluginArtifacts = compilePluginArtifacts;
8188
this.compilerPluginOptions = compilerPluginOptions;
8289
this.ignoreModuleInfo = Boolean.parseBoolean(ignoreModuleInfo);
90+
this.generatedSourcesDirectory = generatedSourcesDirectory;
91+
this.annotationProcessorPaths = annotationProcessorPaths;
92+
this.annotationProcessors = annotationProcessors;
8393
}
8494

8595
public String getName() {
@@ -94,6 +104,14 @@ public Set<File> getReloadableClasspath() {
94104
return reloadableClasspath;
95105
}
96106

107+
public Set<File> getAnnotationProcessorPaths() {
108+
return annotationProcessorPaths;
109+
}
110+
111+
public List<String> getAnnotationProcessors() {
112+
return annotationProcessors;
113+
}
114+
97115
public File getProjectDirectory() {
98116
return projectDirectory;
99117
}
@@ -137,5 +155,9 @@ public List<String> getCompilerPluginOptions() {
137155
public boolean ignoreModuleInfo() {
138156
return ignoreModuleInfo;
139157
}
158+
159+
public File getGeneratedSourcesDirectory() {
160+
return generatedSourcesDirectory;
161+
}
140162
}
141163
}

core/deployment/src/main/java/io/quarkus/deployment/dev/CompilerFlags.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ public class CompilerFlags {
1919
private final String releaseJavaVersion; //can be null
2020
private final String sourceJavaVersion; //can be null
2121
private final String targetJavaVersion; //can be null
22+
private final List<String> annotationProcessors; //can be null
2223

2324
public CompilerFlags(
2425
Set<String> defaultFlags,
2526
Collection<String> userFlags,
2627
String releaseJavaVersion,
2728
String sourceJavaVersion,
28-
String targetJavaVersion) {
29+
String targetJavaVersion,
30+
List<String> annotationProcessors) {
2931

3032
this.defaultFlags = defaultFlags == null ? new LinkedHashSet<>() : new LinkedHashSet<>(defaultFlags);
3133
this.userFlags = userFlags == null ? new ArrayList<>() : new ArrayList<>(userFlags);
3234
this.releaseJavaVersion = releaseJavaVersion;
3335
this.sourceJavaVersion = sourceJavaVersion;
3436
this.targetJavaVersion = targetJavaVersion;
37+
this.annotationProcessors = annotationProcessors;
3538
}
3639

3740
public List<String> toList() {
@@ -61,6 +64,11 @@ public List<String> toList() {
6164
}
6265
}
6366

67+
if (annotationProcessors != null && !annotationProcessors.isEmpty()) {
68+
flagList.add("-processor");
69+
flagList.add(String.join(",", annotationProcessors));
70+
}
71+
6472
flagList.addAll(userFlags);
6573

6674
return flagList;

core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeContext.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class DevModeContext implements Serializable {
3030

3131
private static final long serialVersionUID = 4688502145533897982L;
3232

33-
public static final CompilationUnit EMPTY_COMPILATION_UNIT = new CompilationUnit(PathList.of(), null, null, null);
33+
public static final CompilationUnit EMPTY_COMPILATION_UNIT = new CompilationUnit(PathList.of(), null, null, null, null);
3434

3535
public static final String ENABLE_PREVIEW_FLAG = "--enable-preview";
3636

@@ -64,6 +64,9 @@ public class DevModeContext implements Serializable {
6464
private String baseName;
6565
private final Set<ArtifactKey> localArtifacts = new HashSet<>();
6666

67+
private Set<File> processorPaths;
68+
private List<String> processors;
69+
6770
public boolean isLocalProjectDiscovery() {
6871
return localProjectDiscovery;
6972
}
@@ -239,6 +242,22 @@ public Set<ArtifactKey> getLocalArtifacts() {
239242
return localArtifacts;
240243
}
241244

245+
public void setAnnotationProcessorPaths(Set<File> processorPaths) {
246+
this.processorPaths = processorPaths;
247+
}
248+
249+
public Set<File> getAnnotationProcessorPaths() {
250+
return processorPaths;
251+
}
252+
253+
public void setAnnotationProcessors(List<String> processors) {
254+
this.processors = processors;
255+
}
256+
257+
public List<String> getAnnotationProcessors() {
258+
return processors;
259+
}
260+
242261
public static class ModuleInfo implements Serializable {
243262

244263
private static final long serialVersionUID = -1376678003747618410L;
@@ -259,11 +278,13 @@ public static class ModuleInfo implements Serializable {
259278
this.projectDirectory = builder.projectDirectory;
260279
this.main = new CompilationUnit(builder.sourcePaths, builder.classesPath,
261280
builder.resourcePaths,
262-
builder.resourcesOutputPath);
281+
builder.resourcesOutputPath,
282+
builder.generatedSourcesPath);
263283

264284
if (builder.testClassesPath != null) {
285+
// FIXME: do tests have generated sources?
265286
this.test = new CompilationUnit(builder.testSourcePaths,
266-
builder.testClassesPath, builder.testResourcePaths, builder.testResourcesOutputPath);
287+
builder.testClassesPath, builder.testResourcePaths, builder.testResourcesOutputPath, null);
267288
} else {
268289
this.test = null;
269290
}
@@ -328,6 +349,7 @@ public static class Builder {
328349
private String classesPath;
329350
private PathCollection resourcePaths = PathList.of();
330351
private String resourcesOutputPath;
352+
private String generatedSourcesPath;
331353

332354
private String preBuildOutputDir;
333355
private PathCollection sourceParents = PathList.of();
@@ -408,6 +430,11 @@ public Builder setTestResourcesOutputPath(String testResourcesOutputPath) {
408430
return this;
409431
}
410432

433+
public Builder setGeneratedSourcesPath(String generatedSourcesPath) {
434+
this.generatedSourcesPath = generatedSourcesPath;
435+
return this;
436+
}
437+
411438
public ModuleInfo build() {
412439
return new ModuleInfo(this);
413440
}
@@ -422,13 +449,15 @@ public static class CompilationUnit implements Serializable {
422449
private final String classesPath;
423450
private final PathCollection resourcePaths;
424451
private final String resourcesOutputPath;
452+
private final String generatedSourcesPath;
425453

426454
public CompilationUnit(PathCollection sourcePaths, String classesPath, PathCollection resourcePaths,
427-
String resourcesOutputPath) {
455+
String resourcesOutputPath, String generatedSourcesPath) {
428456
this.sourcePaths = sourcePaths;
429457
this.classesPath = classesPath;
430458
this.resourcePaths = resourcePaths;
431459
this.resourcesOutputPath = resourcesOutputPath;
460+
this.generatedSourcesPath = generatedSourcesPath;
432461
}
433462

434463
public PathCollection getSourcePaths() {
@@ -446,6 +475,10 @@ public PathCollection getResourcePaths() {
446475
public String getResourcesOutputPath() {
447476
return resourcesOutputPath;
448477
}
478+
479+
public String getGeneratedSourcesPath() {
480+
return generatedSourcesPath;
481+
}
449482
}
450483

451484
public boolean isEnablePreview() {

core/deployment/src/main/java/io/quarkus/deployment/dev/IDEDevModeMain.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private void terminateIfRunning() {
8686
private DevModeContext.ModuleInfo toModule(ResolvedDependency module) throws BootstrapGradleException {
8787

8888
String classesDir = null;
89+
String generatedSourcesDir = null;
8990
final Set<Path> sourceParents = new LinkedHashSet<>();
9091
final PathList.Builder srcPaths = PathList.builder();
9192
final ArtifactSources sources = module.getSources();
@@ -99,6 +100,9 @@ private DevModeContext.ModuleInfo toModule(ResolvedDependency module) throws Boo
99100
if (classesDir == null) {
100101
classesDir = src.getOutputDir().toString();
101102
}
103+
if (generatedSourcesDir == null && src.getAptSourcesDir() != null) {
104+
generatedSourcesDir = src.getAptSourcesDir().toString();
105+
}
102106
}
103107

104108
String resourceDirectory = null;
@@ -120,6 +124,7 @@ private DevModeContext.ModuleInfo toModule(ResolvedDependency module) throws Boo
120124
.setProjectDirectory(module.getWorkspaceModule().getModuleDir().getPath())
121125
.setSourcePaths(srcPaths.build())
122126
.setClassesPath(classesDir)
127+
.setGeneratedSourcesPath(generatedSourcesDir)
123128
.setResourcePaths(resourcesPaths.build())
124129
.setResourcesOutputPath(resourceDirectory)
125130
.setSourceParents(PathList.from(sourceParents))

core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,14 @@ public void run() {
459459
}, "Quarkus Shutdown Thread");
460460
Runtime.getRuntime().addShutdownHook(shutdownThread);
461461
} catch (Exception e) {
462-
close();
463-
throw (e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e));
462+
RuntimeException toThrow = (e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e));
463+
try {
464+
close();
465+
} catch (IllegalStateException x) {
466+
// not sure which is the most important, but let's not silence the original exception
467+
toThrow.addSuppressed(x);
468+
}
469+
throw toThrow;
464470
}
465471
}
466472
}

core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public void compile(Set<File> filesToCompile, CompilationProvider.Context contex
6363
context.getCompilerOptions(PROVIDER_KEY),
6464
context.getReleaseJavaVersion(),
6565
context.getSourceJavaVersion(),
66-
context.getTargetJvmVersion()).toList();
66+
context.getTargetJvmVersion(),
67+
context.getAnnotationProcessors()).toList();
6768
}
6869

6970
final JavaCompiler compiler = this.compiler;
@@ -74,7 +75,9 @@ public void compile(Set<File> filesToCompile, CompilationProvider.Context contex
7475

7576
final QuarkusFileManager.Context sourcesContext = new QuarkusFileManager.Context(
7677
context.getClasspath(), context.getReloadableClasspath(),
77-
context.getOutputDirectory(), context.getSourceEncoding(),
78+
context.getOutputDirectory(), context.getGeneratedSourcesDirectory(),
79+
context.getAnnotationProcessorPaths(),
80+
context.getSourceEncoding(),
7881
context.ignoreModuleInfo());
7982

8083
if (this.fileManager == null) {
@@ -183,4 +186,4 @@ public Path getSourceFileForClass(final Path classFilePath) {
183186
return null;
184187
}
185188
}
186-
}
189+
}

core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusCompiler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public void setupSourceCompilationContext(DevModeContext context,
210210
context.getTargetJvmVersion(),
211211
context.getCompilerPluginArtifacts(),
212212
context.getCompilerPluginsOptions(),
213+
compilationUnit.getGeneratedSourcesPath() == null ? null
214+
: new File(compilationUnit.getGeneratedSourcesPath()),
215+
context.getAnnotationProcessorPaths(),
216+
context.getAnnotationProcessors(),
213217
context.getBuildSystemProperties().getOrDefault("quarkus.live-reload.ignore-module-info",
214218
"true")));
215219
}

core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusDevModeLauncher.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ public B compilerPluginOptions(List<String> options) {
181181
return (B) this;
182182
}
183183

184+
@SuppressWarnings("unchecked")
185+
public B annotationProcessorPaths(Set<File> processorPaths) {
186+
QuarkusDevModeLauncher.this.processorPaths = processorPaths;
187+
return (B) this;
188+
}
189+
190+
@SuppressWarnings("unchecked")
191+
public B annotationProcessors(List<String> processors) {
192+
QuarkusDevModeLauncher.this.processors = processors;
193+
return (B) this;
194+
}
195+
184196
@SuppressWarnings("unchecked")
185197
public B releaseJavaVersion(String releaseJavaVersion) {
186198
QuarkusDevModeLauncher.this.releaseJavaVersion = releaseJavaVersion;
@@ -317,6 +329,8 @@ public R build() throws Exception {
317329
private ModuleInfo main;
318330
private List<ModuleInfo> dependencies = new ArrayList<>(0);
319331
private LinkedHashMap<ArtifactKey, File> classpath = new LinkedHashMap<>();
332+
private Set<File> processorPaths;
333+
private List<String> processors;
320334

321335
protected QuarkusDevModeLauncher() {
322336
}
@@ -442,6 +456,12 @@ protected void prepare() throws Exception {
442456
if (compilerPluginOptions != null) {
443457
devModeContext.setCompilerPluginsOptions(compilerPluginOptions);
444458
}
459+
if (processorPaths != null) {
460+
devModeContext.setAnnotationProcessorPaths(processorPaths);
461+
}
462+
if (processors != null) {
463+
devModeContext.setAnnotationProcessors(processors);
464+
}
445465

446466
devModeContext.setReleaseJavaVersion(releaseJavaVersion);
447467
devModeContext.setSourceJavaVersion(sourceJavaVersion);

core/deployment/src/main/java/io/quarkus/deployment/dev/filesystem/QuarkusFileManager.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ protected QuarkusFileManager(StandardJavaFileManager fileManager, Context contex
1818
try {
1919
this.fileManager.setLocation(StandardLocation.CLASS_PATH, context.getClassPath());
2020
this.fileManager.setLocation(StandardLocation.CLASS_OUTPUT, List.of(context.getOutputDirectory()));
21+
if (context.getGeneratedSourcesDirectory() != null) {
22+
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, List.of(context.getGeneratedSourcesDirectory()));
23+
}
24+
if (context.getAnnotationProcessorPaths() != null) {
25+
this.fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, context.getAnnotationProcessorPaths());
26+
}
2127
} catch (IOException e) {
2228
throw new RuntimeException("Cannot initialize file manager", e);
2329
}
@@ -29,6 +35,12 @@ public void reset(Context context) {
2935
try {
3036
this.fileManager.setLocation(StandardLocation.CLASS_PATH, context.getClassPath());
3137
this.fileManager.setLocation(StandardLocation.CLASS_OUTPUT, List.of(context.getOutputDirectory()));
38+
if (context.getGeneratedSourcesDirectory() != null) {
39+
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, List.of(context.getGeneratedSourcesDirectory()));
40+
}
41+
if (context.getAnnotationProcessorPaths() != null) {
42+
this.fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, context.getAnnotationProcessorPaths());
43+
}
3244
} catch (IOException e) {
3345
throw new RuntimeException("Cannot reset file manager", e);
3446
}
@@ -45,14 +57,23 @@ public static class Context {
4557
private final File outputDirectory;
4658
private final Charset sourceEncoding;
4759
private final boolean ignoreModuleInfo;
60+
private final File generatedSourcesDirectory;
61+
private final Set<File> annotationProcessorPaths;
4862

4963
public Context(Set<File> classPath, Set<File> reloadableClassPath,
50-
File outputDirectory, Charset sourceEncoding, boolean ignoreModuleInfo) {
64+
File outputDirectory, File generatedSourcesDirectory, Set<File> annotationProcessorPaths,
65+
Charset sourceEncoding, boolean ignoreModuleInfo) {
5166
this.classPath = classPath;
5267
this.reloadableClassPath = reloadableClassPath;
5368
this.outputDirectory = outputDirectory;
5469
this.sourceEncoding = sourceEncoding;
5570
this.ignoreModuleInfo = ignoreModuleInfo;
71+
this.generatedSourcesDirectory = generatedSourcesDirectory;
72+
this.annotationProcessorPaths = annotationProcessorPaths;
73+
}
74+
75+
public Set<File> getAnnotationProcessorPaths() {
76+
return annotationProcessorPaths;
5677
}
5778

5879
public Set<File> getClassPath() {
@@ -74,5 +95,9 @@ public Charset getSourceEncoding() {
7495
public boolean ignoreModuleInfo() {
7596
return ignoreModuleInfo;
7697
}
98+
99+
public File getGeneratedSourcesDirectory() {
100+
return generatedSourcesDirectory;
101+
}
77102
}
78103
}

0 commit comments

Comments
 (0)