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

Ensure that generated project GAV is always set #38849

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all 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
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
Loading