Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load CodeGenProvider services once instead of once per module
- Loading branch information
1 parent
bccd9a1
commit 6b7f1ff
Showing
8 changed files
with
179 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
core/deployment/src/main/java/io/quarkus/deployment/dev/CodeGenWatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.deployment.dev; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.bootstrap.app.CuratedApplication; | ||
import io.quarkus.bootstrap.classloading.QuarkusClassLoader; | ||
import io.quarkus.bootstrap.prebuild.CodeGenException; | ||
import io.quarkus.deployment.CodeGenerator; | ||
import io.quarkus.deployment.codegen.CodeGenData; | ||
import io.quarkus.deployment.util.FSWatchUtil; | ||
import io.quarkus.runtime.LaunchMode; | ||
|
||
class CodeGenWatcher { | ||
|
||
private static final Logger log = Logger.getLogger(CodeGenWatcher.class); | ||
|
||
private final QuarkusClassLoader deploymentClassLoader; | ||
private final FSWatchUtil fsWatchUtil; | ||
|
||
CodeGenWatcher(CuratedApplication curatedApplication, DevModeContext context) throws CodeGenException { | ||
final QuarkusClassLoader deploymentClassLoader = curatedApplication.createDeploymentClassLoader(); | ||
final List<CodeGenData> codeGens = CodeGenerator.init(deploymentClassLoader, context.getAllModules()); | ||
if (codeGens.isEmpty()) { | ||
fsWatchUtil = null; | ||
this.deploymentClassLoader = null; | ||
deploymentClassLoader.close(); | ||
} else { | ||
final Collection<FSWatchUtil.Watcher> watchers = new ArrayList<>(codeGens.size()); | ||
final Properties properties = new Properties(); | ||
properties.putAll(context.getBuildSystemProperties()); | ||
for (CodeGenData codeGen : codeGens) { | ||
watchers.add(new FSWatchUtil.Watcher(codeGen.sourceDir, codeGen.provider.inputExtension(), | ||
modifiedPaths -> { | ||
try { | ||
CodeGenerator.trigger(deploymentClassLoader, | ||
codeGen, | ||
curatedApplication.getApplicationModel(), properties, LaunchMode.DEVELOPMENT, false); | ||
} catch (Exception any) { | ||
log.warn("Code generation failed", any); | ||
} | ||
})); | ||
} | ||
fsWatchUtil = new FSWatchUtil(); | ||
fsWatchUtil.observe(watchers, 500); | ||
this.deploymentClassLoader = deploymentClassLoader; | ||
} | ||
} | ||
|
||
void shutdown() { | ||
if (fsWatchUtil != null) { | ||
fsWatchUtil.shutdown(); | ||
} | ||
if (deploymentClassLoader != null) { | ||
deploymentClassLoader.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.