Skip to content

Commit

Permalink
Use release if available for codegen compiler
Browse files Browse the repository at this point in the history
Switch hint log level to trace in maven plugin
Removed bad info log, added useful info log to maven plugin
  • Loading branch information
tomas-langer committed Nov 28, 2024
1 parent 11bb3ca commit e766a9e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import io.helidon.builder.api.Option;
import io.helidon.builder.api.Prototype;
Expand Down Expand Up @@ -77,6 +78,14 @@ interface CompilerOptionsBlueprint {
@Option.Default("21")
String target();

/**
* The compiler release.
* If not specified, {@link #source()} and {@link #target()} would be used.
*
* @return release for compilation
*/
Optional<String> release();

/**
* Target directory to generate class files to.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class JavaC {
private final List<String> commandLineArgs;
private final String source;
private final String target;
private final String release;
private final Path outputDirectory;
private final CodegenLogger logger;

Expand All @@ -54,6 +55,7 @@ private JavaC(CompilerOptions options) {
this.commandLineArgs = options.commandLineArguments();
this.source = options.source();
this.target = options.target();
this.release = options.release().orElse(null);
this.outputDirectory = options.outputDirectory();
this.logger = options.logger();
}
Expand Down Expand Up @@ -123,14 +125,20 @@ private void doCompile(Result result, Path[] sourceFilesToCompile) {
optionList.add("--source-path");
optionList.add(toSourcepath());
}
if (source != null) {
optionList.add("--source");
optionList.add(source);
}
if (target != null) {
optionList.add("--target");
optionList.add(target);
if (release == null) {
if (source != null) {
optionList.add("--source");
optionList.add(source);
}
if (target != null) {
optionList.add("--target");
optionList.add(target);
}
} else {
optionList.add("--release");
optionList.add(release);
}

optionList.addAll(commandLineArgs);
if (outputDirectory != null) {
optionList.add("-d");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void validate(WrappedServices services) {
Level level = switch (error.getSeverity()) {
case FATAL -> Level.ERROR;
case WARN -> Level.WARNING;
case HINT -> Level.INFO;
case HINT -> Level.TRACE;
};
logger.log(level, error.getSeverity() + " " + error.getSource() + ": " + error.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ abstract class CodegenAbstractMojo extends AbstractMojo {
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
try {
getLog().info("Started " + getClass().getSimpleName());
innerExecute();
} catch (MojoFailureException | MojoExecutionException e) {
if (failOnError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ abstract class CreateApplicationAbstractMojo extends CodegenAbstractMojo {
*/
@Parameter(property = "maven.compiler.source",
defaultValue = "21")
private String source;
/**
* The -target argument for the Java compiler.
* Note: using the same as maven-compiler for convenience and least astonishment.
*/
@Parameter(property = "maven.compiler.target",
defaultValue = "21")
private String target;
private String release;
/**
* Whether to validate the application when creating its bindings.
*/
Expand Down Expand Up @@ -147,8 +140,7 @@ void innerExecute() {
.classpath(List.copyOf(classpath))
.modulepath(List.copyOf(modulepath))
.sourcepath(sourceRootPaths())
.source(getSource())
.target(getTarget())
.release(javaRelease())
.commandLineArguments(getCompilerArgs())
.outputDirectory(outputDirectory())
.build();
Expand Down Expand Up @@ -219,6 +211,8 @@ void createMainClass(CompilerOptions compilerOptions,
.className(mainClassName)
.build();

getLog().info("Generating application main class: " + generatedType.fqName());

MainClassCreator creator = new MainClassCreator(scanContext, failOnError());
creator.create(scanContext, compilerOptions, services, generatedType);
}
Expand Down Expand Up @@ -253,10 +247,13 @@ void applicationBinding(MavenCodegenContext scanContext,
if (generateBinding) {
// get the binding generator only after services are initialized (we need to ignore any existing apps)
BindingGenerator creator = new BindingGenerator(scanContext, failOnError());
TypeName bindingTypeName = TypeName.create(packageName + "." + className);

getLog().info("Generating application binding: " + bindingTypeName.fqName());

creator.createBinding(services,
allServices,
TypeName.create(packageName + "." + className),
bindingTypeName,
moduleName,
compilerOptions);
}
Expand Down Expand Up @@ -381,12 +378,8 @@ URLClassLoader createClassLoader(Collection<Path> classPath,
return new URLClassLoader(urls.toArray(new URL[0]), parent);
}

String getSource() {
return source;
}

String getTarget() {
return target;
String javaRelease() {
return release;
}

LinkedHashSet<Path> getSourceClasspathElements() {
Expand Down
1 change: 1 addition & 0 deletions service/inject/maven-plugin/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
requires maven.plugin.annotations;
requires maven.plugin.api;
requires maven.project;
requires java.xml;
requires io.github.classgraph;
requires io.helidon.service.metadata;

Expand Down

0 comments on commit e766a9e

Please sign in to comment.