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

O3-3433: SDK Command: Add dependencies to distro.properties #283

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

wikumChamith
Copy link
Member

Description of what I changed

This adds a plugin that allows users to manipulate a distro.properties file by adding dependencies. This supports adding OMOD, SPA, OWA, and WAR dependencies.

Issue I worked on

see https://openmrs.atlassian.net/browse/O3-3433

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean install right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute the above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@wikumChamith wikumChamith requested a review from ibacher August 20, 2024 01:48
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Thanks @wikumChamith! Just a few things to adjust... Not sure how to handle the two PRs introducing similar functionality issue...

}
}

if(StringUtils.isBlank(type)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also prompt for this in the case that the type doesn't match one of the known types?

properties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper).getProperties();
}

switch (type) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
switch (type) {
switch (type.toUpperCase()) {

version = wizard.promptForMissingValueWithOptions("Enter the module version", null, null, versions,
"Please specify the SPA version", null);
}
properties.setProperty("spa.frontendModules.@openmrs/" + moduleName, version);
Copy link
Member

Choose a reason for hiding this comment

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

The @openmrs/ part is a part of the module name (and we need to allow for implementations that can't publish to our NPM org)

Suggested change
properties.setProperty("spa.frontendModules.@openmrs/" + moduleName, version);
properties.setProperty("spa.frontendModules." + moduleName, version);

* Type of the dependency to add
*/
@Parameter(property = "type")
private String type;
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to document the acceptable values here so user's don't have to guess.

Comment on lines 84 to 89
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use Jackson (already a dependency)?

import java.util.Map;
import java.util.stream.Collectors;

public class NPMHelper {
Copy link
Member

Choose a reason for hiding this comment

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

We've got this coming in as well. Which is, I think, a little more correct (i.e., it can support alternative registries, support for registries requiring authentication, etc.)

Copy link
Member Author

Choose a reason for hiding this comment

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

@ibacher should I wait for it to get merged?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think so.

@wikumChamith wikumChamith force-pushed the O3-3433 branch 3 times, most recently from 4cd9ace to 2adacd5 Compare August 23, 2024 10:21
@ibacher
Copy link
Member

ibacher commented Aug 28, 2024

Parallel to remove, should this be called add?

@wikumChamith wikumChamith force-pushed the O3-3433 branch 2 times, most recently from f0f827e to da3ef7f Compare August 29, 2024 06:38
@wikumChamith
Copy link
Member Author

@ibacher I updated the PR.

@wikumChamith wikumChamith requested a review from ibacher August 29, 2024 06:38
@ibacher
Copy link
Member

ibacher commented Sep 8, 2024

@wikumChamith Would you be able to fix the conflict please? I've also merged the other NPM version helper, so maybe we can switch to using that?

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Thanks @wikumChamith. Basically looks good. A couple of nits.

private final String SPA_OPTION = "SPA";
private final String OWA_OPTION = "OWA";
private final String WAR_OPTION = "WAR";
private final String CUSTOM_OPTION = "Custom";
Copy link
Member

Choose a reason for hiding this comment

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

What's the idea here?

Comment on lines 64 to 66


Copy link
Member

Choose a reason for hiding this comment

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

Could we remove the unnecessary blank lines?


private final String DEPENDENCY_TYPE_PROMPT = "Enter the type of dependency you need to add";

private final String OMOD_OPTION = "OMOD";
Copy link
Member

Choose a reason for hiding this comment

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

Better for these to be declared static


private static JsonNode getPackageMetadata(String versionRange, String packageName) throws IOException, InterruptedException {
if (packageName == null || packageName.isEmpty()) {

Copy link
Member

Choose a reason for hiding this comment

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

Do we need this line?

@wikumChamith
Copy link
Member Author

@ibacher I updated the PR.


Process process = processBuilder.start();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
Copy link
Member

Choose a reason for hiding this comment

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

Wrap this in a try-with-resources so the reader always gets closed.

Suggested change
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {

Also, instead of using the BufferedReader to read by line, please use the code from getPackageMetadata(); it's a little more efficient than a line reader for a case like this where we don't care about line-by-line format.

@wikumChamith wikumChamith force-pushed the O3-3433 branch 2 times, most recently from c6f0fca to aa24d7e Compare September 10, 2024 08:11
@ibacher ibacher merged commit b09b2ca into openmrs:master Sep 10, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants