Skip to content

Patch for user input validation when using commands 'Java: New Project...' and 'Java: New File from Template...'. #405

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

Merged
merged 1 commit into from
Apr 24, 2025

Conversation

shivam71
Copy link
Member

  • Commands 'Java: New Project...' and 'Java: New File from Template...' take user input for
    • Project Directory/Folder where template file will be created.
    • Package Name
    • Java Object Name (Example : Enum,Class,Interface)
  • Using javax.lang.model packageSourceVersion.isName method checked for validity of the package name and object name.
  • Added check for write permission in the selected target folders.
  • In case of invalid user input sent appropriate error message to the user and prompted the user again for input.
  • NetBeans PR #7893

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 18, 2025
@naren2605
Copy link
Member

naren2605 commented Apr 23, 2025

@shivam71 can we also attach before-implementation and after-implementation ui screens image references with this pr description ? for future reference

sid-srini
sid-srini previously approved these changes Apr 23, 2025
Copy link
Member

@sid-srini sid-srini left a comment

Choose a reason for hiding this comment

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

For the time-being, while the upstream PR is still under review (mainly in the context of non-Java projects), these changes may still be considered for incorporation albeit as a draft patch (and with minor corrections included), since it has a positive impact on the user-experience. LGTM 👍

+ return CompletableFuture.completedFuture(name);
+ }
+ }
+ boolean isJavaTemplate = FileUtil.getMIMEType(template)!=null ? FileUtil.getMIMEType(template).equals("text/x-java"):false;
Copy link
Member

Choose a reason for hiding this comment

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

This maybe simplified to:

Suggested change
+ boolean isJavaTemplate = FileUtil.getMIMEType(template)!=null ? FileUtil.getMIMEType(template).equals("text/x-java"):false;
+ boolean isJavaTemplate = "text/x-java".equals(FileUtil.getMIMEType(template));

+ }
+ }
+ boolean isJavaTemplate = FileUtil.getMIMEType(template)!=null ? FileUtil.getMIMEType(template).equals("text/x-java"):false;
+ return isJavaTemplate ? client.showInputBox(new ShowInputBoxParams(Bundle.CTL_TemplateUI_SelectName(), desc.getProposedName())).thenCompose(new ValidateJavaObjectName()).thenApply(name -> builder.name(name)) : client.showInputBox(new ShowInputBoxParams(Bundle.CTL_TemplateUI_SelectName(), desc.getProposedName())).thenApply(name -> {return name != null ? builder.name(name) : null;});
Copy link
Member

Choose a reason for hiding this comment

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

It may be less error-prone to convert this ternary condition to 3 separate statements with one intermediate conditional statement. That would maintain the common code in a common flow.
i.e.

Function<String, CompletionStage<String>> userInput = client.showInputBox(...);
if (isJavaTemplate) userInput = userInput.thenCompose(...);
return userInput.thenApply(...);

"CTL_TemplateUI_SelectName=Name of the object?",
"# {0} - path",
- "ERR_InvalidPath={0} isn't valid folder",
+ "ERR_InvalidPath={0} isn't valid folder or is read only",
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a before valid in this and the following error strings. E.g.:

Suggested change
+ "ERR_InvalidPath={0} isn't valid folder or is read only",
+ "ERR_InvalidPath={0} isn't a valid folder or is read-only",

@shivam71
Copy link
Member Author

@shivam71 can we also attach before-implementation and after-implementation ui screens image references with this pr description ? for future reference

The ui steps are same I can add the screen shots of the error boxes that pop up in case of invalid input

Achal1607
Achal1607 previously approved these changes Apr 24, 2025
Copy link
Member

@Achal1607 Achal1607 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you

@shivam71 shivam71 dismissed stale reviews from Achal1607 and sid-srini via e70007b April 24, 2025 06:09
@shivam71 shivam71 force-pushed the user_input_validation_patch branch from b546422 to e70007b Compare April 24, 2025 06:09
@shivam71
Copy link
Member Author

Addressed the review comments

@shivam71 shivam71 requested review from Achal1607 and sid-srini April 24, 2025 06:14
…t...' and 'Java: New File from Template...'.
@shivam71 shivam71 force-pushed the user_input_validation_patch branch from e70007b to f19caf1 Compare April 24, 2025 10:49
Copy link
Member

@sid-srini sid-srini left a comment

Choose a reason for hiding this comment

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

Thanks @shivam71. LGTM 👍

Copy link
Member

@Achal1607 Achal1607 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you

@Achal1607 Achal1607 merged commit 1b1cd7a into oracle:main Apr 24, 2025
3 checks passed
@sid-srini sid-srini added this to the JVSC 24.1.0 milestone Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants