Skip to content

Commit

Permalink
Merge pull request #38849 from geoand/#38837
Browse files Browse the repository at this point in the history
Ensure that generated project GAV is always set
  • Loading branch information
geoand authored Feb 19, 2024
2 parents 5f0dbbc + 8178c7f commit a786faf
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 a786faf

Please sign in to comment.