-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
There was a problem hiding this comment.
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"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct.
There was a problem hiding this comment.
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.