Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate projects for Java 11 by default #8151

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ compileTestJava {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_${java_target}
targetCompatibility = JavaVersion.VERSION_${java_target}
}

Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>${java_target}</maven.compiler.source>
<maven.compiler.target>${java_target}</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>

<quarkus.platform.artifact-id>${bom_artifactId}</quarkus.platform.artifact-id>
Original file line number Diff line number Diff line change
@@ -36,15 +36,15 @@ allOpen {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_${java_target}
targetCompatibility = JavaVersion.VERSION_${java_target}
}

compileKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
kotlinOptions.jvmTarget = JavaVersion.VERSION_${java_target}
kotlinOptions.javaParameters = true
}

compileTestKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
kotlinOptions.jvmTarget = JavaVersion.VERSION_${java_target}
}
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>${java_target}</maven.compiler.source>
<maven.compiler.target>${java_target}</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>

<quarkus.platform.artifact-id>${bom_artifactId}</quarkus.platform.artifact-id>
@@ -107,7 +107,7 @@
</executions>
<configuration>
<javaParameters>true</javaParameters>
<jvmTarget>1.8</jvmTarget>
<jvmTarget>${java_target}</jvmTarget>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if grok this right this change is a change in the "api" of the code generation that means the templates now require java_target to be set which will not be the case if you are using 1.3.0 plugin (@aloubyansky correct me if i'm wrong on this here).

So 1.3.0 plugin will pick up latest 1.3.x platform and when generation happens it will fail.

To remedy this the various .ftl files should check if java_target is set.
if my freemarker syntax memory is right its something like ${java_target!"11"}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if grok this right this change is a change in the "api" of the code generation that means the templates now require java_target to be set which will not be the case if you are using 1.3.0 plugin (@aloubyansky correct me if i'm wrong on this here).

That is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should choose 1.8 as the default to have a consistent behavior. I'll go do that and test.

<!-- Soon to be replaced by plugin that will pre-configure all necessary annotations -->
<compilerPlugins>
<plugin>all-open</plugin>
Original file line number Diff line number Diff line change
@@ -21,5 +21,12 @@ group '${project_groupId}'
version '${project_version}'

compileScala {
scalaCompileOptions.encoding = 'UTF-8'
scalaCompileOptions.encoding = 'UTF-8'
sourceCompatibility = JavaVersion.VERSION_${java_target}
targetCompatibility = JavaVersion.VERSION_${java_target}
}

java {
sourceCompatibility = JavaVersion.VERSION_${java_target}
targetCompatibility = JavaVersion.VERSION_${java_target}
}
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>${java_target}</maven.compiler.source>
<maven.compiler.target>${java_target}</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>

<quarkus.platform.artifact-id>${bom_artifactId}</quarkus.platform.artifact-id>
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import static io.quarkus.generators.ProjectGenerator.CLASS_NAME;
import static io.quarkus.generators.ProjectGenerator.IS_SPRING;
import static io.quarkus.generators.ProjectGenerator.JAVA_TARGET;
import static io.quarkus.generators.ProjectGenerator.PROJECT_ARTIFACT_ID;
import static io.quarkus.generators.ProjectGenerator.PROJECT_GROUP_ID;
import static io.quarkus.generators.ProjectGenerator.PROJECT_VERSION;
@@ -18,6 +19,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.lang.model.SourceVersion;

/**
@@ -27,6 +30,8 @@
*/
public class CreateProject {

private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile("(?:1\\.)?(\\d+)(?:\\..*)?");

public static SourceType determineSourceType(Set<String> extensions) {
Optional<SourceType> sourceType = extensions.stream()
.map(SourceType::parse)
@@ -42,6 +47,8 @@ private static boolean isSpringStyle(Collection<String> extensions) {

private QuarkusCommandInvocation invocation;

private String javaTarget;

/**
* @deprecated since 1.3.0.CR1
* Please use {@link #CreateProject(ProjectWriter, QuarkusPlatformDescriptor)} instead.
@@ -76,6 +83,11 @@ public CreateProject sourceType(SourceType sourceType) {
return this;
}

public CreateProject javaTarget(String javaTarget) {
this.javaTarget = javaTarget;
return this;
}

public CreateProject className(String className) {
if (className == null) {
return this;
@@ -126,6 +138,7 @@ public boolean doCreateProject(final Map<String, Object> context) throws IOExcep
}
}
}

try {
return execute().isSuccess();
} catch (QuarkusCommandException e) {
@@ -134,6 +147,15 @@ public boolean doCreateProject(final Map<String, Object> context) throws IOExcep
}

public QuarkusCommandOutcome execute() throws QuarkusCommandException {
// Define the Java version to use determined from the one specified or the one creating the project
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment isn't really helpful, just saying :)

Matcher matcher = JAVA_VERSION_PATTERN
.matcher(this.javaTarget != null ? this.javaTarget : System.getProperty("java.version", ""));
if (matcher.matches() && Integer.parseInt(matcher.group(1)) < 11) {
invocation.setProperty(JAVA_TARGET, invocation.getBuildTool() == BuildTool.MAVEN ? "1.8" : "1_8");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not have one "java_target" and another "java_underscore_target" so the same property isn't to be treated differently ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the other option I pondered. I decided to go with this one.

} else {
invocation.setProperty(JAVA_TARGET, "11");
}

return new CreateProjectCommandHandler().execute(invocation);
}
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ public interface ProjectGenerator {
String CLASS_NAME = "class_name";
String IS_SPRING = "is_spring";
String RESOURCE_PATH = "path";
String JAVA_TARGET = "java_target";

String getName();