Skip to content

Commit

Permalink
Ensure that generated project GAV is always set
Browse files Browse the repository at this point in the history
Fixes: quarkusio#38837
(cherry picked from commit 8178c7f)
  • Loading branch information
geoand authored and gsmet committed Feb 19, 2024
1 parent 09d7118 commit f1cb0ef
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ public void execute() throws MojoExecutionException {
}

askTheUserForMissingValues();
if (projectArtifactId != DEFAULT_ARTIFACT_ID && !OK_ID.matcher(projectArtifactId).matches()) {
if (!DEFAULT_ARTIFACT_ID.equals(projectArtifactId) && !OK_ID.matcher(projectArtifactId).matches()) {
throw new MojoExecutionException(String.format(BAD_IDENTIFIER, "artifactId", projectArtifactId));
}
if (projectGroupId != DEFAULT_GROUP_ID && !OK_ID.matcher(projectGroupId).matches()) {
if (!DEFAULT_GROUP_ID.equals(projectGroupId) && !OK_ID.matcher(projectGroupId).matches()) {
throw new MojoExecutionException(String.format(BAD_IDENTIFIER, "groupId", projectGroupId));
}

Expand Down Expand Up @@ -389,16 +389,7 @@ private void askTheUserForMissingValues() throws MojoExecutionException {
// If the user has disabled the interactive mode or if the user has specified the artifactId, disable the
// user interactions.
if (!session.getRequest().isInteractiveMode() || shouldUseDefaults()) {
if (isBlank(projectArtifactId)) {
// we need to set it for the project directory
projectArtifactId = DEFAULT_ARTIFACT_ID;
}
if (isBlank(projectGroupId)) {
projectGroupId = DEFAULT_GROUP_ID;
}
if (isBlank(projectVersion)) {
projectVersion = DEFAULT_VERSION;
}
setProperDefaults();
return;
}

Expand Down Expand Up @@ -427,12 +418,27 @@ private void askTheUserForMissingValues() throws MojoExecutionException {
input -> noCode = input.startsWith("n"));

prompter.collectInput();
} else {
setProperDefaults();
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to get user input", e);
}
}

private void setProperDefaults() {
if (isBlank(projectArtifactId)) {
// we need to set it for the project directory
projectArtifactId = DEFAULT_ARTIFACT_ID;
}
if (isBlank(projectGroupId)) {
projectGroupId = DEFAULT_GROUP_ID;
}
if (isBlank(projectVersion)) {
projectVersion = DEFAULT_VERSION;
}
}

private boolean shouldUseDefaults() {
// Must be called before user input
return projectArtifactId != null;
Expand Down

0 comments on commit f1cb0ef

Please sign in to comment.