Skip to content

Commit

Permalink
Fixed NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
nravilla committed Sep 25, 2024
1 parent 7856415 commit 9b3a0b3
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.openmrs.maven.plugins.model.Artifact;
import org.openmrs.maven.plugins.model.DistroProperties;

/**
* This class is downloads and moves content backend config to respective configuration folders
* This class downloads and moves content backend config to respective configuration folders.
*/
public class ContentHelper {

Expand All @@ -31,38 +30,42 @@ private static File unpackArtifact(Artifact contentArtifact) throws MojoExecutio
} catch (IOException e) {
throw new MojoExecutionException("Exception while trying to create temporary directory", e);
}


// Ensure moduleInstaller is set before calling this
if (moduleInstaller == null) {
throw new MojoExecutionException("ModuleInstaller is not initialized.");
}
moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath());
return sourceDir;
}

private static void moveBackendConfig(Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException {
File sourceDir = unpackArtifact (contentArtifact);
private static void moveBackendConfig(Artifact contentArtifact, File targetDir) throws MojoExecutionException {
File sourceDir = unpackArtifact(contentArtifact);
try {
File backendConfigFiles = sourceDir.toPath().resolve(BACKEND_CONFIG_FOLDER).toFile();
Path targetPath = targetDir.toPath().toAbsolutePath();

if (backendConfigFiles.exists()) {
File[] configDirectories = backendConfigFiles.listFiles(File::isDirectory);
File[] configDirectories = backendConfigFiles.listFiles(File::isDirectory);
if (configDirectories != null) {
for (File config : configDirectories) {
Path destDir = targetPath.resolve(config.getName()).resolve(contentArtifact.getArtifactId());
Files.createDirectories(destDir);

//copy config files to the matching configuration folder
// Copy config files to the matching configuration folder
FileUtils.copyDirectory(config, destDir.toFile());
}
}
}
}
catch (IOException e) {
} catch (IOException e) {
throw new MojoExecutionException("Error copying backend configuration: " + e.getMessage(), e);
} finally {
FileUtils.deleteQuietly(sourceDir);
}
FileUtils.deleteQuietly(sourceDir);
}

public static List<File> extractAndGetAllContentFrontendConfigs(Artifact contentArtifact) throws MojoExecutionException {
File sourceDir = unpackArtifact (contentArtifact);
File sourceDir = unpackArtifact(contentArtifact);
List<File> configFiles = new ArrayList<>();
File frontendConfigFiles = sourceDir.toPath().resolve(FRONTEND_CONFIG_FOLDER).toFile();

Expand All @@ -76,29 +79,29 @@ public static List<File> extractAndGetAllContentFrontendConfigs(Artifact content
}
}
} else {
throw new MojoExecutionException("Error copying Frontend configuration");
throw new MojoExecutionException("Error: Frontend configuration folder not found.");
}
return configFiles;
}

// This method now sets the static moduleInstaller
public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInst, Wizard wizard) throws MojoExecutionException {
moduleInstaller = moduleInst;
moduleInstaller = moduleInst; // Set the static variable
if (distroProperties != null) {
File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION);
List<Artifact> contents = distroProperties.getContentArtifacts();

if (contents != null) {
for (Artifact content : contents) {
wizard.showMessage("Downloading Content: " + content + "\n");
moveBackendConfig(content, moduleInstaller, targetDir);
moveBackendConfig(content, targetDir);
}
}
}

}

public static List<File> collectFrontendConfigs(DistroProperties distroProperties) throws MojoExecutionException {
List<File> allConfigFiles = new ArrayList<File>();
List<File> allConfigFiles = new ArrayList<>();
if (distroProperties != null) {
List<Artifact> contents = distroProperties.getContentArtifacts();
if (contents != null) {
Expand All @@ -108,5 +111,10 @@ public static List<File> collectFrontendConfigs(DistroProperties distroPropertie
}
}
return allConfigFiles;
}

public static String assembleWithFrontendConfig(String program, File buildTargetDir, List<File> configFiles, File spaConfigFile) {
// TODO: Implement this method
return null;
}
}

0 comments on commit 9b3a0b3

Please sign in to comment.