Skip to content

Commit

Permalink
Added configDir to AugmentPhase, Gradle built runners should include …
Browse files Browse the repository at this point in the history
…application.properties now
  • Loading branch information
stalep committed Mar 26, 2019
1 parent 26e4bef commit f474a0e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ public interface AugmentOutcome {
* @return directory containing generated classes
*/
Path getWiringClassesDir();

/**
* Directory containing config files used by the application
*
* @return directory containing config files
*/
Path getConfigDir();
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class AugmentPhase implements AppCreationPhase<AugmentPhase>, AugmentOutc
private Path appClassesDir;
private Path transformedClassesDir;
private Path wiringClassesDir;
private Path configDir;

/**
* Output directory for the outcome of this phase.
Expand Down Expand Up @@ -131,6 +132,17 @@ public AugmentPhase setWiringClassesDir(Path wiringClassesDir) {
return this;
}

/**
* Directory containing the configuration files.
*
* @param configDir directory the configuration files (application.properties)
* @return this phase instance
*/
public AugmentPhase setConfigDir(Path configDir) {
this.configDir = configDir;
return this;
}

@Override
public Path getAppClassesDir() {
return appClassesDir;
Expand All @@ -146,6 +158,11 @@ public Path getWiringClassesDir() {
return wiringClassesDir;
}

@Override
public Path getConfigDir() {
return configDir;
}

@Override
public void register(OutcomeProviderRegistration registration) throws AppCreatorException {
registration.provides(AugmentOutcome.class);
Expand All @@ -171,6 +188,10 @@ public void provideOutcome(AppCreator ctx) throws AppCreatorException {
IoUtils.recursiveDelete(metaInf.resolve("MANIFEST.MF"));
}

//lets default to appClassesDir for now
if (configDir == null)
configDir = appClassesDir;

transformedClassesDir = IoUtils
.mkdirs(transformedClassesDir == null ? outputDir.resolve("transformed-classes") : transformedClassesDir);
wiringClassesDir = IoUtils.mkdirs(wiringClassesDir == null ? outputDir.resolve("wiring-classes") : wiringClassesDir);
Expand All @@ -183,7 +204,7 @@ public void provideOutcome(AppCreator ctx) throws AppCreatorException {
private void doProcess(CurateOutcome appState) throws AppCreatorException {
//first lets look for some config, as it is not on the current class path
//and we need to load it to run the build process
Path config = appClassesDir.resolve("application.properties");
Path config = configDir.resolve("application.properties");
if (Files.exists(config)) {
try {
Config built = SmallRyeConfigProviderResolver.instance().getBuilder()
Expand Down Expand Up @@ -370,6 +391,7 @@ public AugmentPhase getTarget() {
.map("output", (AugmentPhase t, String value) -> t.setOutputDir(Paths.get(value)))
.map("classes", (AugmentPhase t, String value) -> t.setAppClassesDir(Paths.get(value)))
.map("transformed-classes", (AugmentPhase t, String value) -> t.setTransformedClassesDir(Paths.get(value)))
.map("wiring-classes", (AugmentPhase t, String value) -> t.setWiringClassesDir(Paths.get(value)));
.map("wiring-classes", (AugmentPhase t, String value) -> t.setWiringClassesDir(Paths.get(value)))
.map("config", (AugmentPhase t, String value) -> t.setConfigDir(Paths.get(value)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public void accept(Path path) {
});

copyFiles(augmentOutcome.getAppClassesDir(), runnerZipFs);
if (Files.exists(augmentOutcome.getConfigDir()))
copyFiles(augmentOutcome.getConfigDir(), runnerZipFs);
copyFiles(augmentOutcome.getTransformedClassesDir(), runnerZipFs);

generateManifest(runnerZipFs, classPath.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class QuarkusPluginExtension {

private String sourceDir;

private String outputConfigDirectory;

public QuarkusPluginExtension(Project project) {
this.project = project;
}
Expand All @@ -69,6 +71,18 @@ public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;
}

public File outputConfigDirectory() {
if (outputConfigDirectory == null)
outputConfigDirectory = project.getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets().getByName("main").getOutput().getResourcesDir().getAbsolutePath();

return new File(outputConfigDirectory);
}

public void setConfigOutputDirectory(String outputDirectory) {
this.outputConfigDirectory = outputDirectory;
}

public File sourceDir() {
if (sourceDir == null)
sourceDir = project.getConvention().getPlugin(JavaPluginConvention.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void buildQuarkus() {
// configure the build phases we want the app to go through
.addPhase(new AugmentPhase()
.setAppClassesDir(extension().outputDirectory().toPath())
.setConfigDir(extension().outputConfigDirectory().toPath())
.setTransformedClassesDir(getTransformedClassesDirectory().toPath())
.setWiringClassesDir(getWiringClassesDirectory().toPath()))
.addPhase(new RunnerJarPhase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ public Path getWiringClassesDir() {
// not relevant for this mojo
throw new UnsupportedOperationException();
}

@Override
public Path getConfigDir() {
return extension().outputConfigDirectory().toPath();
}
}).pushOutcome(RunnerJarOutcome.class, new RunnerJarOutcome() {
final Path runnerJar = getProject().getBuildDir().toPath().resolve(extension().finalName() + "-runner.jar");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void execute() throws MojoExecutionException {
// configure the build phases we want the app to go through
.addPhase(new AugmentPhase()
.setAppClassesDir(outputDirectory.toPath())
.setConfigDir(outputDirectory.toPath())
.setTransformedClassesDir(transformedClassesDirectory.toPath())
.setWiringClassesDir(wiringClassesDirectory.toPath()))
.addPhase(new RunnerJarPhase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public Path getWiringClassesDir() {
// not relevant for this mojo
throw new UnsupportedOperationException();
}

@Override
public Path getConfigDir() {
return classesDir;
}
})
.pushOutcome(RunnerJarOutcome.class, new RunnerJarOutcome() {
final Path runnerJar = buildDir.toPath().resolve(finalName + "-runner.jar");
Expand Down

0 comments on commit f474a0e

Please sign in to comment.