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

Pull and extract the content package set in distro.prop #286

Closed
wants to merge 4 commits into from

Conversation

nravilla
Copy link
Contributor

@nravilla nravilla commented Aug 22, 2024

Description of what I changed

Modified classes to download and extract and move content packages (just the backend content)

Issue I worked on

https://openmrs.atlassian.net/browse/O3-3640

Checklist: I completed these to help reviewers :)

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

  • Acceptance tests (setup and build-distro was tested and it works

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

  • All existing tests passed.

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

@suruchee suruchee requested review from rbuisson and ibacher August 22, 2024 03:47
Copy link
Member

@mherman22 mherman22 left a comment

Choose a reason for hiding this comment

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

Thanks @nravilla a few comments as we wait for @ibacher's review

System.out.println(artifactId);
System.out.println(getParam(key));
System.out.println(Artifact.GROUP_CONTENT);

Copy link
Member

Choose a reason for hiding this comment

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

i think we can remove these System.out.printlns during clean up after all the reviews

Copy link
Member

Choose a reason for hiding this comment

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

was this change intended?

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 @nravilla. Because of the number of formatting changes, this is a really hard PR to review. I've left a few pointers on things that stuck out to me, but I'll need more time to review the remaining files in any detail.

this.pluginManager = pluginManager;
}

public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact,
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
public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact,
public void downloadContent(File configurationDir, File contentDir, Artifact contentArtifact,

Comment on lines +429 to +440
File targetDirectory = new File(configDir, "temp_content");
targetDirectory.mkdir();

List<Artifact> contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory);
if (!contents.isEmpty()) {
wizard.showMessage("Downloading Contents...\n");
for (Artifact content : contents) {
wizard.showMessage("Downloading Content: " + content);
contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller);
}
}
FileUtils.deleteQuietly(targetDirectory);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be wrapped in something like:

Suggested change
File targetDirectory = new File(configDir, "temp_content");
targetDirectory.mkdir();
List<Artifact> contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory);
if (!contents.isEmpty()) {
wizard.showMessage("Downloading Contents...\n");
for (Artifact content : contents) {
wizard.showMessage("Downloading Content: " + content);
contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller);
}
}
FileUtils.deleteQuietly(targetDirectory);
File targetDirectory = new File(configDir, "temp_content");
targetDirectory.mkdir();
try {
List<Artifact> contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory);
if (!contents.isEmpty()) {
wizard.showMessage("Downloading Contents...\n");
for (Artifact content : contents) {
wizard.showMessage("Downloading Content: " + content);
contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller);
}
}
} finally {
FileUtils.deleteQuietly(targetDirectory);
}

Copy link
Member

Choose a reason for hiding this comment

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

Also, I always think that we should use Files.createTempDirectory() to create a temporary directory.


List<Artifact> contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory);
if (!contents.isEmpty()) {
wizard.showMessage("Downloading Contents...\n");
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
wizard.showMessage("Downloading Contents...\n");
wizard.showMessage("Downloading content packages...\n");

if (!contents.isEmpty()) {
wizard.showMessage("Downloading Contents...\n");
for (Artifact content : contents) {
wizard.showMessage("Downloading Content: " + content);
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
wizard.showMessage("Downloading Content: " + content);
wizard.showMessage("Downloading content package: " + content);


private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException {
if (distroProperties != null) {
File tempContentDir = new File(server.getServerDirectory(), "temp-content");
Copy link
Member

Choose a reason for hiding this comment

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

Same comments here as before

Comment on lines +52 to +54
if (backendConfigs == null || backendConfigs.listFiles().length == 0) {
throw new MojoExecutionException("No directories to process under content configuration directories");
}
Copy link
Member

Choose a reason for hiding this comment

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

There is no way that backendConfigs could be null here.

throw new MojoExecutionException("No directories to process under content configuration directories");
}

for (File backendConfig : backendConfigs.listFiles()) {
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
for (File backendConfig : backendConfigs.listFiles()) {
for (File configDir : backendConfigs.listFiles()) {

Comment on lines 62 to 71
if (!matchingConfigurationDir.exists() && !matchingConfigurationDir.isDirectory()) {
//this folder is from content zip
artifactDir = matchingConfigurationDir;
} else {
// Create a new folder with the artifactId under the matching output directory
artifactDir = new File(matchingConfigurationDir, artifactId);
if (!artifactDir.exists()) {
artifactDir.mkdirs();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Am I reading the logic here correctly? It says "if matchingConfigurationDir does not exist and it is not a directory, set artifactDir to matchingConfigurationDir, otherwise create a new subfolder"?

Assuming I'm reading that correctly:

  1. Under what circumstance can the if branch be true?
  2. We always want to ensure that we are writing to a subfolder of the configuration directory, right?

}

// Copy the content from inputDir to the newly created artifactDir
copyDirectory(backendConfig, artifactDir);
Copy link
Member

Choose a reason for hiding this comment

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

FileUtils.copyDirectory() can be used here.

executionEnvironment(mavenProject, mavenSession, pluginManager)
);
}

Copy link
Member

Choose a reason for hiding this comment

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

I don't love all the reformatting in this PR. It makes it very hard to review and know if anything has changed and if so, what.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't commit files you haven't touched other than reformatting. If there are any changes here, can you please use GitHub comments to indicate what those are?

@nravilla
Copy link
Contributor Author

@ibacher @mherman22 Unable to resolve the formatting issues, will close this and create a new branch

@nravilla nravilla closed this Aug 26, 2024
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.

3 participants