From 384e7b3bbfbb94dd22cb6ef3eb38bb4b948ce0e8 Mon Sep 17 00:00:00 2001 From: Ravilla Date: Wed, 21 Aug 2024 23:18:57 -0400 Subject: [PATCH 01/31] Pull and extract the content package set in distro.prop --- .../openmrs/maven/plugins/AbstractTask.java | 98 +-- .../openmrs/maven/plugins/BuildDistro.java | 342 ++++----- .../java/org/openmrs/maven/plugins/Setup.java | 368 +++++----- .../maven/plugins/utility/ContentHelper.java | 99 +++ .../plugins/utility/ModuleInstaller.java | 209 +++--- .../openmrs/maven/plugins/model/Artifact.java | 1 + .../plugins/model/BaseSdkProperties.java | 649 ++++++++++-------- .../maven/plugins/model/DistroProperties.java | 566 +++++++-------- 8 files changed, 1277 insertions(+), 1055 deletions(-) create mode 100644 maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 61a397758..14d87f4a9 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -1,5 +1,7 @@ package org.openmrs.maven.plugins; +import java.util.ArrayDeque; + import org.apache.commons.lang.StringUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; @@ -12,11 +14,12 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; +import org.openmrs.maven.plugins.git.DefaultGitHelper; +import org.openmrs.maven.plugins.git.GitHelper; import org.openmrs.maven.plugins.model.Server; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DefaultJira; import org.openmrs.maven.plugins.utility.DistroHelper; -import org.openmrs.maven.plugins.git.DefaultGitHelper; -import org.openmrs.maven.plugins.git.GitHelper; import org.openmrs.maven.plugins.utility.DockerHelper; import org.openmrs.maven.plugins.utility.Jira; import org.openmrs.maven.plugins.utility.ModuleInstaller; @@ -27,116 +30,119 @@ import org.openmrs.maven.plugins.utility.VersionsHelper; import org.openmrs.maven.plugins.utility.Wizard; -import java.util.ArrayDeque; - /** * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ OwaHelper owaHelper; - + + /** + * handles Contents + */ + ContentHelper contentHelper; + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - + public AbstractTask(AbstractTask other) { this.mavenProject = other.mavenProject; this.mavenSession = other.mavenSession; @@ -148,6 +154,7 @@ public AbstractTask(AbstractTask other) { this.versionsHelper = other.versionsHelper; this.distroHelper = other.distroHelper; this.owaHelper = other.owaHelper; + this.contentHelper = other.contentHelper; this.spaInstaller = other.spaInstaller; this.gitHelper = other.gitHelper; this.dockerHelper = other.dockerHelper; @@ -158,7 +165,7 @@ public AbstractTask(AbstractTask other) { this.stats = other.stats; initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -178,6 +185,9 @@ public void initTask() { if (owaHelper == null) { owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); + } if (spaInstaller == null) { spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); } @@ -187,19 +197,19 @@ public void initTask() { if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index e609621b3..74b7885e8 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -1,138 +1,137 @@ package org.openmrs.maven.plugins; -import net.lingala.zip4j.core.ZipFile; -import net.lingala.zip4j.exception.ZipException; -import net.lingala.zip4j.model.ZipParameters; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.eclipse.jgit.api.errors.GitAPIException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.eclipse.jgit.api.CloneCommand; -import org.eclipse.jgit.api.Git; import org.openmrs.maven.plugins.model.Artifact; import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; import org.openmrs.maven.plugins.utility.DistroHelper; -import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.utility.SDKConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import net.lingala.zip4j.core.ZipFile; +import net.lingala.zip4j.exception.ZipException; +import net.lingala.zip4j.model.ZipParameters; /** * Create docker configuration for distributions. */ @Mojo(name = "build-distro", requiresProject = false) public class BuildDistro extends AbstractTask { - + private static final String DEFAULT_SQL_DUMP = Server.CLASSPATH_SCRIPT_PREFIX + "openmrs-platform.sql"; - + private static final String OPENMRS_WAR = "openmrs.war"; - + private static final String OPENMRS_DISTRO_PROPERTIES = "openmrs-distro.properties"; - + private static final String DOCKER_COMPOSE_PATH = "build-distro/docker-compose.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_PATH = "build-distro/docker-compose.override.yml"; - + private static final String DOCKER_COMPOSE_PROD_PATH = "build-distro/docker-compose.prod.yml"; - + private static final String README_PATH = "build-distro/README.md"; - + private static final String DISTRIBUTION_VERSION_PROMPT = "You can build the following versions of distribution"; - + private static final String DUMP_PREFIX = "CREATE DATABASE IF NOT EXISTS `openmrs`;\n\n USE `openmrs`;\n\n"; - + private static final String DB_DUMP_PATH = "dbdump" + File.separator + "dump.sql"; - + private static final String WAR_FILE_MODULES_DIRECTORY_NAME = "bundledModules"; - + private static final String WEB = "web"; - + private static final String DOCKER_COMPOSE_YML = "docker-compose.yml"; - + private static final String DOCKER_COMPOSE_PROD_YML = "docker-compose.prod.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_YML = "docker-compose.override.yml"; - + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final Logger log = LoggerFactory.getLogger(BuildDistro.class); - + /** * Path to the openmrs-distro.properties file. */ @Parameter(property = "distro") private String distro; - + /** * Directory for generated files. (default to 'docker') */ @Parameter(property = "dir") private String dir; - + /** * SQL script for database configuration. */ @Parameter(property = "dbSql") private String dbSql; - + /** * Causes npm to completely ignore peerDependencies */ @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + /** - * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after the setup + * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after + * the setup */ @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + /** - * Instead of creating a `modules` folder in the distro directory, will put modules inside - * the war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` + * Instead of creating a `modules` folder in the distro directory, will put modules inside the + * war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` */ @Parameter(defaultValue = "false", property = "bundled") private boolean bundled; - + /** * Flag to indicate whether to delete the target directory or not. */ @Parameter(defaultValue = "false", property = "reset") private boolean reset; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Override public void executeTask() throws MojoExecutionException, MojoFailureException { File buildDirectory = getBuildDirectory(); - + File userDir = new File(System.getProperty("user.dir")); - + Artifact distroArtifact = null; DistroProperties distroProperties = null; - + if (distro == null) { File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME); if (distroFile.exists()) { @@ -142,15 +141,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } else if (Project.hasProject(userDir)) { Project config = Project.loadProject(userDir); - distroArtifact = DistroHelper - .parseDistroArtifact(config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), - versionsHelper); - + distroArtifact = DistroHelper.parseDistroArtifact( + config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), versionsHelper); + wizard.showMessage("Building distribution from the source at " + userDir + "...\n"); new Build(this).buildProject(config); - distroFile = distroHelper - .extractFileFromDistro(buildDirectory, distroArtifact, DistroProperties.DISTRO_FILE_NAME); - + distroFile = distroHelper.extractFileFromDistro(buildDirectory, distroArtifact, + DistroProperties.DISTRO_FILE_NAME); + if (distroFile.exists()) { distroProperties = new DistroProperties(distroFile); } else { @@ -162,14 +160,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroArtifact = distroProperties.getParentArtifact(); distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } - + if (distroProperties == null) { Server server = new Server.ServerBuilder().build(); - + List options = new ArrayList<>(); options.add(O2_DISTRIBUTION); options.add(O3_DISTRIBUTION); - + String choice = wizard.promptForMissingValueWithOptions("You can setup following servers", null, null, options); switch (choice) { case O2_DISTRIBUTION: @@ -178,57 +176,62 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = new DistroProperties(server.getVersion()); } else { distroProperties = distroHelper.downloadDistroProperties(buildDirectory, server); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), - "jar"); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), + server.getDistroGroupId(), "jar"); } break; case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); server.setServerDirectory(buildDirectory); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties( + distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); } - + } - + if (distroProperties == null) { throw new MojoExecutionException("The distro you specified, '" + distro + "' could not be retrieved"); } - + String distroName = buildDistro(buildDirectory, distroArtifact, distroProperties); - + wizard.showMessage( - "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " - + buildDirectory.getAbsolutePath() + "\n"); + "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " + + buildDirectory.getAbsolutePath() + "\n"); } - - private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException { - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, appShellVersion); + + private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, + DistroProperties distroProperties) throws MojoExecutionException { + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) + && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, + appShellVersion); } return distroProperties; } - + private File getBuildDirectory() throws MojoExecutionException { final File targetDir; if (StringUtils.isBlank(dir)) { String directory = wizard.promptForValueIfMissingWithDefault( - "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); + "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); targetDir = new File(directory); } else { targetDir = new File(dir); } - + if (targetDir.exists()) { if (targetDir.isDirectory()) { if (!reset) { if (isDockerComposeCreated(targetDir)) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' contains docker config. Only modules and openmrs.war will be overriden"); + + "' contains docker config. Only modules and openmrs.war will be overriden"); deleteDistroFiles(new File(targetDir, WEB)); } else if (targetDir.list().length != 0) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' is not empty. All its content will be lost."); + + "' is not empty. All its content will be lost."); boolean chooseDifferent = wizard.promptYesNo("Would you like to choose a different directory?"); if (chooseDifferent) { return getBuildDirectory(); @@ -246,12 +249,12 @@ private File getBuildDirectory() throws MojoExecutionException { } else { targetDir.mkdirs(); } - + dir = targetDir.getAbsolutePath(); - + return targetDir; } - + private void deleteDistroFiles(File targetDir) { try { FileUtils.deleteDirectory(new File(targetDir, "modules")); @@ -262,47 +265,52 @@ private void deleteDistroFiles(File targetDir) { log.error(e.getMessage(), e); } } - + private void deleteDirectory(File targetDir) throws MojoExecutionException { try { FileUtils.cleanDirectory(targetDir); } catch (IOException e) { - throw new MojoExecutionException("Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); + throw new MojoExecutionException( + "Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); } } - + private String buildDistro(File targetDirectory, Artifact distroArtifact, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { InputStream dbDumpStream; wizard.showMessage("Downloading modules...\n"); - + String distroName = adjustImageName(distroProperties.getName()); File web = new File(targetDirectory, WEB); web.mkdirs(); - - moduleInstaller - .installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), web.getAbsolutePath()); + + moduleInstaller.installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), + web.getAbsolutePath()); renameWebApp(web); - + if (bundled) { try { ZipFile warfile = new ZipFile(new File(web, OPENMRS_WAR)); File tempDir = new File(web, "WEB-INF"); tempDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); - + new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); + File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + + //TODO: does this flow need this? + //downloadContents(targetDirectory, distroProperties); + + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, + overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); - if(frontendDir.exists()) { + if (frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); } - + warfile.addFolder(tempDir, new ZipParameters()); try { FileUtils.deleteDirectory(tempDir); @@ -318,23 +326,24 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File modulesDir = new File(web, "modules"); modulesDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - modulesDir.getAbsolutePath()); - + modulesDir.getAbsolutePath()); + File frontendDir = new File(web, "frontend"); frontendDir.mkdir(); - + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); - + + downloadContents(configDir, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - - + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); + } - + wizard.showMessage("Creating Docker Compose configuration...\n"); String distroVersion = adjustImageName(distroProperties.getVersion()); writeDockerCompose(targetDirectory, distroVersion); @@ -345,38 +354,40 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro copyBuildDistroResource(".env", new File(targetDirectory, ".env")); copyDockerfile(web, distroProperties); distroProperties.saveTo(web); - + dbDumpStream = getSqlDumpStream(StringUtils.isNotBlank(dbSql) ? dbSql : distroProperties.getSqlScriptPath(), - targetDirectory, distroArtifact); + targetDirectory, distroArtifact); if (dbDumpStream != null) { copyDbDump(targetDirectory, dbDumpStream); } //clean up extracted sql file cleanupSqlFiles(targetDirectory); - + return distroName; } - - private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException { + + private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) + throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - - + downloadConfigs(distroProperties, configDir); - - File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); - + + File refappConfigFile = new File(configDir, + distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) + && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -387,11 +398,12 @@ private void setConfigFolder(File configDir, DistroProperties distroProperties, FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } catch (ZipException | IOException e) { + } + catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { List configs = distroProperties.getConfigArtifacts(); wizard.showMessage("Downloading Configs...\n"); @@ -399,9 +411,9 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -411,14 +423,30 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + + private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { + + File targetDirectory = new File(configDir, "temp_content"); + targetDirectory.mkdir(); + + List 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); + } + private boolean isDockerComposeCreated(File targetDir) { File dockerComposeOverride = new File(targetDir, DOCKER_COMPOSE_OVERRIDE_YML); File dockerCompose = new File(targetDir, DOCKER_COMPOSE_YML); File dockerComposeProd = new File(targetDir, DOCKER_COMPOSE_PROD_YML); return dockerCompose.exists() && dockerComposeOverride.exists() && dockerComposeProd.exists(); } - + private void copyDockerfile(File targetDirectory, DistroProperties distroProperties) throws MojoExecutionException { Version platformVersion = new Version(distroProperties.getPlatformVersion(distroHelper, targetDirectory)); int majorVersion = platformVersion.getMajorVersion(); @@ -435,8 +463,7 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } else { copyBuildDistroResource("Dockerfile-tomcat8", new File(targetDirectory, "Dockerfile")); } - } - else { + } else { if (bundled) { copyBuildDistroResource("Dockerfile-jre8-bundled", new File(targetDirectory, "Dockerfile")); } else { @@ -445,18 +472,18 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } } } - + private boolean isPlatform2point5AndAbove(Version platformVersion) { return platformVersion.getMajorVersion() > 2 - || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); + || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); } - + /** * name of sql dump file is unknown, so wipe all files with 'sql' extension */ private void cleanupSqlFiles(File targetDirectory) { File[] sqlFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".sql"); @@ -466,18 +493,19 @@ public boolean accept(File dir, String name) { FileUtils.deleteQuietly(sql); } } - + private void writeDockerCompose(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PATH, DOCKER_COMPOSE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_OVERRIDE_PATH, DOCKER_COMPOSE_OVERRIDE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PROD_PATH, DOCKER_COMPOSE_PROD_YML); } - + private void writeReadme(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, README_PATH, "README.md"); } - - private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) throws MojoExecutionException { + + private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) + throws MojoExecutionException { URL composeUrl = getClass().getClassLoader().getResource(path); if (composeUrl == null) { throw new MojoExecutionException("Failed to find file '" + path + "' in classpath"); @@ -494,11 +522,11 @@ private void writeTemplatedFile(File targetDirectory, String version, String pat } } } - + private String adjustImageName(String part) { return part.replaceAll("\\s+", "").toLowerCase(); } - + private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExecutionException { File dbDump = new File(targetDirectory, DB_DUMP_PATH); try { @@ -508,16 +536,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe catch (IOException e) { throw new MojoExecutionException("Failed to create SQL dump file " + e.getMessage(), e); } - - try (FileWriter writer = new FileWriter(dbDump); - BufferedInputStream bis = new BufferedInputStream(stream)) { + + try (FileWriter writer = new FileWriter(dbDump); BufferedInputStream bis = new BufferedInputStream(stream)) { writer.write(DUMP_PREFIX); - + int c; while ((c = bis.read()) != -1) { writer.write(c); } - + writer.write("\n" + SDKConstants.RESET_SEARCH_INDEX_SQL + "\n"); writer.flush(); } @@ -528,15 +555,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe IOUtils.closeQuietly(stream); } } - + private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) - throws MojoExecutionException { + throws MojoExecutionException { InputStream stream = null; - + if (sqlScriptPath == null) { return null; } - + try { if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); @@ -545,8 +572,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, stream = resourceUrl.openStream(); } else { if (distroArtifact != null && distroArtifact.isValid()) { - File extractedSqlFile = distroHelper - .extractFileFromDistro(targetDirectory, distroArtifact, sqlScript); + File extractedSqlFile = distroHelper.extractFileFromDistro(targetDirectory, distroArtifact, + sqlScript); stream = new FileInputStream(extractedSqlFile); } } @@ -555,7 +582,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, if (scriptFile.exists()) { stream = new FileInputStream(scriptFile); } else { - throw new MojoExecutionException("Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); + throw new MojoExecutionException( + "Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); } } } @@ -564,7 +592,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, } return stream; } - + private void copyBuildDistroResource(String resource, File target) throws MojoExecutionException { URL resourceUrl = getClass().getClassLoader().getResource("build-distro/web/" + resource); if (resourceUrl != null && !target.exists()) { @@ -572,28 +600,28 @@ private void copyBuildDistroResource(String resource, File target) throws MojoEx FileUtils.copyURLToFile(resourceUrl, target); } catch (IOException e) { - throw new MojoExecutionException( - "Failed to copy file from classpath: " + resourceUrl + " to " + target.getAbsolutePath() + e.getMessage(), e); + throw new MojoExecutionException("Failed to copy file from classpath: " + resourceUrl + " to " + + target.getAbsolutePath() + e.getMessage(), e); } } } - + private void renameWebApp(File targetDirectory) throws MojoExecutionException { File[] warFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".war"); } }); - + if (warFiles != null) { for (File file : warFiles) { wizard.showMessage("file:" + file.getAbsolutePath()); } - + wizard.showMessage("target:" + targetDirectory); - + if (warFiles.length == 1) { boolean renameSuccess = warFiles[0].renameTo(new File(targetDirectory, OPENMRS_WAR)); if (!renameSuccess) { diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 00b23e95a..6b7e68ec4 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -20,8 +20,6 @@ import java.util.List; import java.util.Objects; -import net.lingala.zip4j.core.ZipFile; -import net.lingala.zip4j.exception.ZipException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.lang.StringUtils; @@ -39,141 +37,144 @@ import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.ServerHelper; +import net.lingala.zip4j.core.ZipFile; +import net.lingala.zip4j.exception.ZipException; /** - * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters. + * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a + * distribution. It prompts for any missing, but required parameters. */ @Mojo(name = "setup", requiresProject = false) public class Setup extends AbstractServerTask { - + public static final String SETTING_UP_A_NEW_SERVER = "Setting up a new server..."; - + public static final String SETUP_SERVERS_PROMPT = "You can setup the following servers"; - - public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = - "If you want to enable remote debugging by default when running the server, " - + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; - + + public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = "If you want to enable remote debugging by default when running the server, " + + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String PLATFORM = "Platform"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final String CLASSPATH_SCRIPT_PREFIX = "classpath://"; - + private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - + private static final int DEFAULT_PORT = 8080; - + /** * DB Driver type */ @Parameter(property = "dbDriver") private String dbDriver; - + /** * DB Uri */ @Parameter(property = "dbUri") private String dbUri; - + /** * DB User */ @Parameter(property = "dbUser") private String dbUser; - + /** * DB Pass */ @Parameter(property = "dbPassword") private String dbPassword; - + /** * DB dump script to import */ @Parameter(property = "dbSql") private String dbSql; - + /** * Docker host address */ @Parameter(property = "dockerHost") private String dockerHost; - + /** * DB reset if exists */ @Parameter(property = "dbReset") private Boolean dbReset; - + /** * Path to JDK Version */ @Parameter(property = "javaHome") private String javaHome; - + /** * Path to installation.properties */ @Parameter(property = "file") private String file; - + /** * Option to include demo data */ @Parameter(defaultValue = "false", property = "addDemoData") private boolean addDemoData; - + /** - * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, if it is 'org.openmrs.distro'. + * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, + * if it is 'org.openmrs.distro'. */ @Parameter(property = "distro") private String distro; - + /** * OpenMRS Platform version to setup e.g. '1.11.5'. */ @Parameter(property = "platform") private String platform; - + @Parameter(property = "debug") private String debug; - + @Parameter(defaultValue = "false", property = "run") private boolean run; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + private ServerHelper serverHelper; - + public Setup() { super(); } - + public Setup(AbstractServerTask other) { super(other); } - + public Setup(AbstractTask other) { super(other); } - + /** - * Gets the distro properties. The distro properties can come from a file specified by path - * or in the current directory or from a maven artifact. - * If no distro properties file can be found, `null` is returned. In this case, the distro - * file will be created after the database is initialized. Setup should proceed to install - * modules based on the OpenMRS WAR file for the given platform version. - * As of this writing, this function can return null only in platform mode. + * Gets the distro properties. The distro properties can come from a file specified by path or + * in the current directory or from a maven artifact. If no distro properties file can be found, + * `null` is returned. In this case, the distro file will be created after the database is + * initialized. Setup should proceed to install modules based on the OpenMRS WAR file for the + * given platform version. As of this writing, this function can return null only in platform + * mode. * * @param server An initialized Server instance * @return distro properties instantiated by DistroHelper @@ -188,12 +189,12 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu if (distroProperties != null) { options.add(distroProperties.getName() + " " + distroProperties.getVersion() + " from current directory"); } - + options.add(O3_DISTRIBUTION); options.add(O2_DISTRIBUTION); options.add(PLATFORM); String choice = wizard.promptForMissingValueWithOptions(SETUP_SERVERS_PROMPT, null, null, options); - + switch (choice) { case PLATFORM: platformMode = true; @@ -210,18 +211,22 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties(distroHelper.getArtifactProperties(artifact, server, appShellVersion)); + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties( + distroHelper.getArtifactProperties(artifact, server, appShellVersion)); platformMode = false; break; - - default: // distro properties from current directory + + default: // distro properties from current directory Artifact distroArtifact = distroProperties.getParentArtifact(); - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion); + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) + && StringUtils.isNotBlank(distroArtifact.getGroupId()) + && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, + appShellVersion); } else { server.setPlatformVersion( - distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); + distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); server.setVersion(distroProperties.getVersion()); } platformMode = false; @@ -229,7 +234,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } else if (platform != null) { server.setPlatformVersion(platform); platformMode = true; - } else { // getting distro properties from file + } else { // getting distro properties from file distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); if (distroProperties == null) { throw new MojoExecutionException("Distro " + distro + "could not be retrieved"); @@ -238,15 +243,14 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu server.setVersion(distroProperties.getVersion()); platformMode = false; } - + if (platformMode) { Artifact platformArtifact = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, - SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); + SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); String version = wizard.promptForPlatformVersionIfMissing(server.getPlatformVersion(), - versionsHelper.getSuggestedVersions(platformArtifact, 6)); - platformArtifact = DistroHelper - .parseDistroArtifact(Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, - versionsHelper); + versionsHelper.getSuggestedVersions(platformArtifact, 6)); + platformArtifact = DistroHelper.parseDistroArtifact( + Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, versionsHelper); server.setPlatformVersion(platformArtifact.getVersion()); try { distroProperties = distroHelper.downloadDistroProperties(server.getServerDirectory(), platformArtifact); @@ -256,16 +260,15 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu distroProperties = null; } } - + return distroProperties; } - + /** - * Sets up a server based on an initialized Server instance and the provided - * distroProperties. Installs modules and other artifacts. Sets up the database. - * Writes openmrs-server.properties. + * Sets up a server based on an initialized Server instance and the provided distroProperties. + * Installs modules and other artifacts. Sets up the database. Writes openmrs-server.properties. * - * @param server An initialized server instance + * @param server An initialized server instance * @param distroProperties Allowed to be null, only if this is a platform install * @throws MojoExecutionException */ @@ -278,37 +281,39 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); + installContents(server, distroProperties); if (spaInstaller != null) { - spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, + ignorePeerDependencies, overrideReuseNodeCache); } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); } - + serverHelper = new ServerHelper(wizard); - + setServerPort(server); setDebugPort(server); - + setupDatabase(server, distroProperties); - + // If there's no distro at this point, we create a minimal one here, // *after* having initialized server.isH2Supported in `setupDatabase` above. if (distroProperties == null) { distroProperties = distroHelper.createDistroForPlatform(server); } distroProperties.saveTo(server.getServerDirectory()); - + setJdk(server); - + server.setValuesFromDistroPropertiesModules( - distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), - distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); + distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), + distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); server.setUnspecifiedToDefault(); server.save(); } - + private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); @@ -319,10 +324,10 @@ private void setJdk(Server server) throws MojoExecutionException { } else { wizard.showMessage("Note: JDK 1.8 or above is needed for platform version " + platformVersion + "."); } - + wizard.promptForJavaHomeIfMissing(server); } - + private void installOWAs(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { File owasDir = new File(server.getServerDirectory(), "owa"); @@ -330,9 +335,18 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } } - + + private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + if (distroProperties != null) { + File tempContentDir = new File(server.getServerDirectory(), "temp-content"); + tempContentDir.mkdir(); + downloadContents(server, distroProperties, tempContentDir); + FileUtils.deleteQuietly(tempContentDir); + } + } + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -342,35 +356,51 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + + private void downloadContents(Server server, DistroProperties distroProperties, File tempContentDir) + throws MojoExecutionException { + List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); + //Configuration dir gets created before this method is called + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); + + if (!contents.isEmpty()) { + wizard.showMessage("Downloading Contents...\n"); + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(configDir, tempContentDir, content, moduleInstaller); + } + } + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * - * @param server The server for which to set the configuration folder. + * @param server The server for which to set the configuration folder. * @param distroProperties The distro properties containing the configuration information. */ private void setConfigFolder(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - + downloadConfigs(distroProperties, configDir); - + File refappConfigFile = new File(configDir, server.getDistroArtifactId() + "-" + server.getVersion() + ".zip"); - + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) && "referenceapplication-distro".equals(server.getDistroArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) + && "referenceapplication-distro".equals(server.getDistroArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -381,16 +411,19 @@ private void setConfigFolder(Server server, DistroProperties distroProperties) t FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } catch (ZipException | IOException e) { + } + catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + /** - * Downloads the configuration artifact specified in the distro properties and saves them in the provided config directory. + * Downloads the configuration artifact specified in the distro properties and saves them in the + * provided config directory. * - * @param distroProperties The distro properties containing the configuration artifacts to download. - * @param configDir The directory where the configuration files will be saved. + * @param distroProperties The distro properties containing the configuration artifacts to + * download. + * @param configDir The directory where the configuration files will be saved. * @throws MojoExecutionException If an error occurs while downloading the configuration files. */ private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { @@ -400,7 +433,7 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void wipeDatabase(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { @@ -415,14 +448,11 @@ private void wipeDatabase(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to drop " + server.getDbName() + " database"); } } - + private void setServerPort(Server server) throws MojoExecutionException { String message = "What port would you like your server to use?"; - String port = wizard.promptForValueIfMissingWithDefault( - message, - server.getParam("tomcat.port"), - "port number", - String.valueOf(Setup.DEFAULT_PORT)); + String port = wizard.promptForValueIfMissingWithDefault(message, server.getParam("tomcat.port"), "port number", + String.valueOf(Setup.DEFAULT_PORT)); if (!StringUtils.isNumeric(port) || !this.serverHelper.isPort(Integer.parseInt(port))) { wizard.showMessage("Port must be numeric and less or equal 65535."); this.setServerPort(server); @@ -430,15 +460,12 @@ private void setServerPort(Server server) throws MojoExecutionException { } server.setPort(port); } - + private void setDebugPort(Server server) throws MojoExecutionException { if (StringUtils.isBlank(debug) || wizard.checkYes(debug)) { while (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug) && !StringUtils.isNumeric(debug)) { - debug = wizard.promptForValueIfMissingWithDefault( - ENABLE_DEBUGGING_DEFAULT_MESSAGE, - server.getDebugPort(), - "port number", - NO_DEBUGGING_DEFAULT_ANSWER); + debug = wizard.promptForValueIfMissingWithDefault(ENABLE_DEBUGGING_DEFAULT_MESSAGE, server.getDebugPort(), + "port number", NO_DEBUGGING_DEFAULT_ANSWER); if (!StringUtils.isNumeric(debug) && !NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { wizard.showMessage("\nPort number must be numeric."); } else if (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { @@ -447,9 +474,9 @@ private void setDebugPort(Server server) throws MojoExecutionException { } } } - + private void setServerVersionsFromDistroProperties(Server server, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { if (server.getPlatformVersion() == null) { server.setPlatformVersion(distroProperties.getPlatformVersion(distroHelper, server.getServerDirectory())); } @@ -457,54 +484,55 @@ private void setServerVersionsFromDistroProperties(Server server, DistroProperti server.setVersion(distroProperties.getVersion()); } } - + private void setupDatabase(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (server.getDbDriver() == null) { boolean isH2Supported = true; if (distroProperties != null) { isH2Supported = distroProperties.isH2Supported(); } - + wizard.promptForDb(server, dockerHelper, isH2Supported, dbDriver, dockerHost); } - + if (server.getDbDriver() != null) { setupDatabaseForServer(server); } } - + private void setupDatabaseForServer(Server server) throws MojoExecutionException { if (server.getDbName() == null) { server.setDbName(determineDbName(server.getDbUri(), server.getServerId())); } - + if (server.isMySqlDb() || server.isPostgreSqlDb()) { String uri = getUriWithoutDb(server); - try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), + server.getDbName())) { connector.checkAndCreate(server); wizard.showMessage("Connected to the database."); } catch (SQLException e) { throw new MojoExecutionException("Failed to connect to the specified database " + server.getDbUri(), e); } - + if (hasDbTables(server)) { if (dbReset == null) { dbReset = !wizard.promptYesNo( - "Would you like to setup the server using existing data (if not, all data will be lost)?"); + "Would you like to setup the server using existing data (if not, all data will be lost)?"); } - + if (dbReset) { wipeDatabase(server); } else { server.setParam("create_tables", "false"); } } - + if (dbReset == null) { dbReset = true; } - + if (!"null".equals(dbSql) && dbReset) { if (dbSql != null) { importDb(server, dbSql); @@ -512,7 +540,7 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else if (!server.isMySqlDb() && !server.isPostgreSqlDb()) { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage("The specified database " + server.getDbName() - + " does not exist and it will be created when OpenMRS starts."); + + " does not exist and it will be created when OpenMRS starts."); } } else if (!dbReset) { resetSearchIndex(server); @@ -520,29 +548,30 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage( - "The specified database " + server.getDbName() + " does not exist and it will be created for you."); + "The specified database " + server.getDbName() + " does not exist and it will be created for you."); } } - + private boolean hasDbTables(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { DatabaseMetaData md = connector.getConnection().getMetaData(); - + try (ResultSet rs = md.getTables(server.getDbName(), null, null, new String[] { "TABLE" })) { return rs.next(); } } catch (SQLException e) { - throw new MojoExecutionException("Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); + throw new MojoExecutionException( + "Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); } } - + private void resetSearchIndex(Server server) throws MojoExecutionException { String uri = server.getDbUri(); - + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName()); - PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { + PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { ps.execute(); wizard.showMessage("The search index has been reset."); } @@ -550,20 +579,20 @@ private void resetSearchIndex(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to reset search index " + e.getMessage(), e); } } - + private void importDb(Server server, String sqlScriptPath) throws MojoExecutionException { wizard.showMessage("Importing an initial database from " + sqlScriptPath + "..."); String uri = server.getDbUri().replace("@DBNAME@", server.getDbName()); - + InputStream sqlStream; if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); sqlStream = (Setup.class.getClassLoader().getResourceAsStream(sqlScript)); if (sqlStream == null) { Artifact distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); - File extractedSqlFile = distroHelper - .extractFileFromDistro(server.getServerDirectory(), distroArtifact, sqlScript); + server.getDistroGroupId(), "jar"); + File extractedSqlFile = distroHelper.extractFileFromDistro(server.getServerDirectory(), distroArtifact, + sqlScript); extractedSqlFile.deleteOnExit(); try { sqlStream = new FileInputStream(extractedSqlFile); @@ -578,19 +607,20 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE sqlStream = new FileInputStream(scriptFile); } catch (FileNotFoundException e) { - throw new MojoExecutionException("SQL import script could not be found at \"" + - scriptFile.getAbsolutePath() + "\" " + e.getMessage() , e); + throw new MojoExecutionException( + "SQL import script could not be found at \"" + scriptFile.getAbsolutePath() + "\" " + e.getMessage(), + e); } } - + try (InputStreamReader sqlReader = new InputStreamReader(sqlStream); - Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { + Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { ScriptRunner scriptRunner = new ScriptRunner(connection); //we don't want to display ~5000 lines of queries to user if there is no error scriptRunner.setLogWriter(new PrintWriter(new NullOutputStream())); scriptRunner.setStopOnError(true); scriptRunner.runScript(sqlReader); - + wizard.showMessage("Database imported successfully."); server.setParam("create_tables", "false"); } @@ -599,10 +629,10 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE throw new MojoExecutionException("Failed to import database", e); } } - + public String determineDbName(String uri, String serverId) throws MojoExecutionException { String dbName = String.format(SDKConstants.DB_NAME_TEMPLATE, serverId); - + if (!uri.contains("@DBNAME@")) { //determine db name from uri try { @@ -612,67 +642,59 @@ public String determineDbName(String uri, String serverId) throws MojoExecutionE } else { parsedUri = new URI(uri); } - + dbName = parsedUri.getPath(); - + if (dbName == null || dbName.isEmpty() || dbName.equals("/")) { throw new MojoExecutionException("No database name is given in the URI: " + dbName); } - + dbName = dbName.substring(1); - + if (!dbName.substring(1).matches("^[A-Za-z0-9_\\-]+$")) { throw new MojoExecutionException( - "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " - + - dbName); + "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " + + dbName); } } catch (URISyntaxException e) { throw new MojoExecutionException("Could not parse uri: " + uri, e); } } - + return dbName; } - + + @Override public void executeTask() throws MojoExecutionException, MojoFailureException { wizard.showMessage(SETTING_UP_A_NEW_SERVER); - + Server.ServerBuilder serverBuilder; if (file != null) { serverBuilder = new Server.ServerBuilder(Server.loadServer(Paths.get(file))); } else { serverBuilder = new Server.ServerBuilder(); } - - Server server = serverBuilder - .setServerId(serverId) - .setDbDriver(dbDriver) - .setDbUri(dbUri) - .setDbUser(dbUser) - .setDbPassword(dbPassword) - .setInteractiveMode(testMode) - .setJavaHome(javaHome) - .setDebugPort(debug) - .build(); - + + Server server = serverBuilder.setServerId(serverId).setDbDriver(dbDriver).setDbUri(dbUri).setDbUser(dbUser) + .setDbPassword(dbPassword).setInteractiveMode(testMode).setJavaHome(javaHome).setDebugPort(debug).build(); + wizard.promptForNewServerIfMissing(server); - + File serverDir = Server.getServersPath().resolve(server.getServerId()).toFile(); if (serverDir.isDirectory()) { throw new MojoExecutionException( - "Cannot create server: directory with name " + serverDir.getName() + " already exists"); + "Cannot create server: directory with name " + serverDir.getName() + " already exists"); + } else if (serverDir.getAbsolutePath().contains(" ")) { + throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + + " contains a space. Please make sure your server path does not include any spaces."); } - else if (serverDir.getAbsolutePath().contains(" ")) { - throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + - " contains a space. Please make sure your server path does not include any spaces."); - } - + server.setServerDirectory(serverDir); serverDir.mkdir(); - + try { + DistroProperties distroProperties = resolveDistroProperties(server); setup(server, distroProperties); } @@ -680,14 +702,14 @@ else if (serverDir.getAbsolutePath().contains(" ")) { FileUtils.deleteQuietly(server.getServerDirectory()); throw new MojoExecutionException("Failed to setup server", e); } - + getLog().info("Server configured successfully, path: " + serverDir); - + if (run) { new Run(this, server.getServerId()).execute(); } } - + private String getUriWithoutDb(Server server) { String uri = server.getDbUri(); uri = uri.substring(0, uri.lastIndexOf("/") + 1); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java new file mode 100644 index 000000000..3b3098730 --- /dev/null +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -0,0 +1,99 @@ +package org.openmrs.maven.plugins.utility; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.openmrs.maven.plugins.model.Artifact; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ContentHelper { + + private final MavenSession session; + + private final BuildPluginManager pluginManager; + + private final MavenProject mavenProject; + + private static final Logger logger = LoggerFactory.getLogger(ContentHelper.class); + + public ContentHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager) { + this.session = session; + this.mavenProject = mavenProject; + this.pluginManager = pluginManager; + } + + public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact, + ModuleInstaller moduleInstaller) throws MojoExecutionException { + + String artifactId = contentArtifact.getArtifactId(); + File contentDir = new File(tempContentDir, artifactId); + + moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); + moveBackendConfig(contentDir, configurationDir, artifactId); + } + + private void moveBackendConfig(File inputDir, File configurationDir, String artifactId) throws MojoExecutionException { + + // Check if inputDir and outputDir are valid directories + if (!inputDir.isDirectory() || !configurationDir.isDirectory()) { + throw new MojoExecutionException("Both inputDir and outputDir must be valid directories."); + } + + // List all directories in the inputDir + File backendConfigs = new File(inputDir, "configs" + File.separator + "backend_config"); + + if (backendConfigs == null || backendConfigs.listFiles().length == 0) { + throw new MojoExecutionException("No directories to process under content configuration directories"); + } + + for (File backendConfig : backendConfigs.listFiles()) { + // Find a corresponding directory in the outputDir with the same name as inputSubDir + File matchingConfigurationDir = new File(configurationDir, backendConfig.getName()); + + File artifactDir = null; + + 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 the content from inputDir to the newly created artifactDir + copyDirectory(backendConfig, artifactDir); + + } + } + + private void copyDirectory(File sourceDir, File destDir) throws MojoExecutionException { + try { + if (!destDir.exists()) { + destDir.mkdirs(); + } + + for (File file : sourceDir.listFiles()) { + File destFile = new File(destDir, file.getName()); + if (file.isDirectory()) { + copyDirectory(file, destFile); + } else { + Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } + } + catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + } + +} diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index c72e9527c..9c8d0c0a8 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -1,19 +1,5 @@ package org.openmrs.maven.plugins.utility; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.BuildPluginManager; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.openmrs.maven.plugins.model.Artifact; -import org.openmrs.maven.plugins.model.DistroProperties; -import org.openmrs.maven.plugins.model.Server; -import org.twdata.maven.mojoexecutor.MojoExecutor; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import static org.twdata.maven.mojoexecutor.MojoExecutor.Element; import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; import static org.twdata.maven.mojoexecutor.MojoExecutor.element; @@ -24,98 +10,113 @@ import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; import static org.twdata.maven.mojoexecutor.MojoExecutor.version; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Server; +import org.twdata.maven.mojoexecutor.MojoExecutor; +import org.twdata.maven.mojoexecutor.MojoExecutor.Element; + /** * Handles installing modules on server */ public class ModuleInstaller { - - private static final String GOAL_UNPACK = "unpack"; - - final MavenProject mavenProject; - - final MavenSession mavenSession; - - final BuildPluginManager pluginManager; - - final VersionsHelper versionsHelper; - - public ModuleInstaller(MavenProject mavenProject, - MavenSession mavenSession, - BuildPluginManager pluginManager, - VersionsHelper versionsHelper) { - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; - this.versionsHelper = versionsHelper; - } - - public void installDefaultModules(Server server) throws MojoExecutionException { - boolean isPlatform = server.getVersion() == null; // this might be always true, in which case `getCoreModules` can be simplified - List coreModules = SDKConstants.getCoreModules(server.getPlatformVersion(), isPlatform); - if (coreModules == null) { - throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getPlatformVersion())); - } - installModules(coreModules, server.getServerDirectory().getPath()); - } - - public void installModulesForDistro(Server server, DistroProperties properties, DistroHelper distroHelper) throws MojoExecutionException { - List coreModules; - // install other modules - coreModules = properties.getWarArtifacts(distroHelper, server.getServerDirectory()); - if (coreModules == null) { - throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getVersion())); - } - installModules(coreModules, server.getServerDirectory().getPath()); - File modules = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_MODULES); - modules.mkdirs(); - List artifacts = properties.getModuleArtifacts(distroHelper, server.getServerDirectory()); - // install modules for each version - installModules(artifacts, modules.getPath()); - } - - public void installModules(List artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts.toArray(new Artifact[0]), outputDir, goal); - } - - public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts, outputDir, goal); - } - - public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(new Artifact[] { artifact }, outputDir, goal); - } - - /** - * Handle list of modules - * @param artifacts - * @param outputDir - * @param goal - * @throws MojoExecutionException - */ - private void prepareModules(Artifact[] artifacts, String outputDir, String goal) throws MojoExecutionException { - MojoExecutor.Element[] artifactItems = new MojoExecutor.Element[artifacts.length]; - for (int index = 0; index < artifacts.length; index++) { - artifactItems[index] = artifacts[index].toElement(outputDir); - } - - List configuration = new ArrayList<>(); - configuration.add(element("artifactItems", artifactItems)); - if (goal.equals(GOAL_UNPACK)) { - configuration.add(element("overWriteSnapshots", "true")); - configuration.add(element("overWriteReleases", "true")); - } - executeMojo( - plugin( - groupId(SDKConstants.DEPENDENCY_PLUGIN_GROUP_ID), - artifactId(SDKConstants.DEPENDENCY_PLUGIN_ARTIFACT_ID), - version(SDKConstants.DEPENDENCY_PLUGIN_VERSION) - ), - goal(goal), - configuration(configuration.toArray(new Element[0])), - executionEnvironment(mavenProject, mavenSession, pluginManager) - ); - } + + private static final String GOAL_UNPACK = "unpack"; + + final MavenProject mavenProject; + + final MavenSession mavenSession; + + final BuildPluginManager pluginManager; + + final VersionsHelper versionsHelper; + + public ModuleInstaller(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager, + VersionsHelper versionsHelper) { + this.mavenProject = mavenProject; + this.mavenSession = mavenSession; + this.pluginManager = pluginManager; + this.versionsHelper = versionsHelper; + } + + public void installDefaultModules(Server server) throws MojoExecutionException { + boolean isPlatform = server.getVersion() == null; // this might be always true, in which case `getCoreModules` can be simplified + List coreModules = SDKConstants.getCoreModules(server.getPlatformVersion(), isPlatform); + if (coreModules == null) { + throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getPlatformVersion())); + } + installModules(coreModules, server.getServerDirectory().getPath()); + } + + public void installModulesForDistro(Server server, DistroProperties properties, DistroHelper distroHelper) + throws MojoExecutionException { + List coreModules; + // install other modules + coreModules = properties.getWarArtifacts(distroHelper, server.getServerDirectory()); + if (coreModules == null) { + throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getVersion())); + } + installModules(coreModules, server.getServerDirectory().getPath()); + File modules = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_MODULES); + modules.mkdirs(); + List artifacts = properties.getModuleArtifacts(distroHelper, server.getServerDirectory()); + // install modules for each version + installModules(artifacts, modules.getPath()); + } + + public void installModules(List artifacts, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(artifacts.toArray(new Artifact[0]), outputDir, goal); + } + + public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(artifacts, outputDir, goal); + } + + public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(new Artifact[] { artifact }, outputDir, goal); + } + + public void installUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { + final String goal = GOAL_UNPACK; + prepareModules(new Artifact[] { artifact }, outputDir, goal); + } + + /** + * Handle list of modules + * + * @param artifacts + * @param outputDir + * @param goal + * @throws MojoExecutionException + */ + private void prepareModules(Artifact[] artifacts, String outputDir, String goal) throws MojoExecutionException { + MojoExecutor.Element[] artifactItems = new MojoExecutor.Element[artifacts.length]; + for (int index = 0; index < artifacts.length; index++) { + artifactItems[index] = artifacts[index].toElement(outputDir); + } + + List configuration = new ArrayList<>(); + configuration.add(element("artifactItems", artifactItems)); + if (goal.equals(GOAL_UNPACK)) { + configuration.add(element("overWriteSnapshots", "true")); + configuration.add(element("overWriteReleases", "true")); + } + executeMojo( + plugin(groupId(SDKConstants.DEPENDENCY_PLUGIN_GROUP_ID), artifactId(SDKConstants.DEPENDENCY_PLUGIN_ARTIFACT_ID), + version(SDKConstants.DEPENDENCY_PLUGIN_VERSION)), + goal(goal), configuration(configuration.toArray(new Element[0])), + executionEnvironment(mavenProject, mavenSession, pluginManager)); + } + } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java index 175e9d28c..2cebb1cdb 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java @@ -27,6 +27,7 @@ public class Artifact { public static final String GROUP_OPENMRS = "org.openmrs"; public static final String GROUP_H2 = "com.h2database"; public static final String GROUP_DISTRO = "org.openmrs.distro"; + public static final String GROUP_CONTENT = "org.openmrs.content"; public static final String TYPE_OMOD = "omod"; public static final String TYPE_WAR = "war"; public static final String TYPE_JAR = "jar"; diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index a843e1337..66f636288 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -1,7 +1,5 @@ package org.openmrs.maven.plugins.model; -import org.apache.commons.lang.StringUtils; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -9,325 +7,366 @@ import java.util.Properties; import java.util.Set; +import org.apache.commons.lang.StringUtils; + /** * */ public abstract class BaseSdkProperties { - - public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; - public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; - protected static final String ARTIFACT_ID = "artifactId"; - protected static final String TYPE = "type"; - protected static final String GROUP_ID = "groupId"; - protected static final String TYPE_OMOD = "omod"; - protected static final String TYPE_WAR = "war"; - protected static final String TYPE_JAR = "jar"; - protected static final String NAME = "name"; - protected static final String VERSION = "version"; - protected static final String TYPE_DISTRO = "distro"; - protected static final String TYPE_OWA = "owa"; - protected static final String TYPE_SPA = "spa"; - protected static final String TYPE_CONFIG = "config"; - protected static final String TYPE_ZIP = "zip"; - - protected Properties properties; - - public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { - Properties properties = new Properties(); - for (Artifact artifact : warArtifacts) { - - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_WAR)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - - if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); - } - - for (Artifact artifact : moduleArtifacts) { - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_JAR)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); - } - return properties; - } - - public String getPlatformVersion(){ - return getParam("war.openmrs"); - } - - public void setPlatformVersion(String version){ - properties.setProperty("war.openmrs", version); - } - - public String getVersion(){ - return getParam("version"); - } - - public void setVersion(String version){ - properties.setProperty("version", version); - } - - public String getName(){ - return getParam("name"); - } - - public void setName(String name){ - properties.setProperty("name", name); - } - - public List getModuleArtifacts(){ - List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if(artifactType.equals(TYPE_OMOD)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); - } - } - return artifactList; - } - - public List getOwaArtifacts() { - List artifacts = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - if (key.startsWith(TYPE_OWA + ".")) { - String artifactId = key.substring(TYPE_OWA.length() + 1); - artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_OWA, Artifact.TYPE_ZIP)); - } - } - return artifacts; - } - - public Map getSpaProperties() { - Map spaProperties = new HashMap<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - if (key.startsWith(TYPE_SPA + ".")) { - spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); - } - } - return spaProperties; - } - - public List getWarArtifacts(){ - List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if(artifactType.equals(TYPE_WAR)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); - } - } - return artifactList; - } - + + public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; + + public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; + + protected static final String ARTIFACT_ID = "artifactId"; + + protected static final String TYPE = "type"; + + protected static final String GROUP_ID = "groupId"; + + protected static final String TYPE_OMOD = "omod"; + + protected static final String TYPE_WAR = "war"; + + protected static final String TYPE_JAR = "jar"; + + protected static final String NAME = "name"; + + protected static final String VERSION = "version"; + + protected static final String TYPE_DISTRO = "distro"; + + protected static final String TYPE_OWA = "owa"; + + protected static final String TYPE_SPA = "spa"; + + protected static final String TYPE_CONFIG = "config"; + + protected static final String TYPE_CONTENT = "content"; + + protected static final String TYPE_ZIP = "zip"; + + protected Properties properties; + + public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { + Properties properties = new Properties(); + for (Artifact artifact : warArtifacts) { + + stripArtifactId(artifact); + + if (!artifact.getType().equals(TYPE_WAR)) { + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + } + + if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + } + + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); + } + + for (Artifact artifact : moduleArtifacts) { + stripArtifactId(artifact); + + if (!artifact.getType().equals(TYPE_JAR)) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + } + if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + } + + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); + } + return properties; + } + + public String getPlatformVersion() { + return getParam("war.openmrs"); + } + + public void setPlatformVersion(String version) { + properties.setProperty("war.openmrs", version); + } + + public String getVersion() { + return getParam("version"); + } + + public void setVersion(String version) { + properties.setProperty("version", version); + } + + public String getName() { + return getParam("name"); + } + + public void setName(String name) { + properties.setProperty("name", name); + } + + public List getModuleArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_OMOD)) { + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), + checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); + } + } + return artifactList; + } + + public List getOwaArtifacts() { + List artifacts = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_OWA + ".")) { + String artifactId = key.substring(TYPE_OWA.length() + 1); + artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_OWA, Artifact.TYPE_ZIP)); + } + } + return artifacts; + } + + public Map getSpaProperties() { + Map spaProperties = new HashMap<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_SPA + ".")) { + spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); + } + } + return spaProperties; + } + + public List getWarArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_WAR)) { + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), + checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); + } + } + return artifactList; + } + public List getConfigArtifacts() { List artifactList = new ArrayList<>(); for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); if (artifactType.equals(TYPE_CONFIG)) { - artifactList.add( - new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), - checkIfOverwritten(key, TYPE))); + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), + checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); } } return artifactList; } - + + public List getContentArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONTENT)) { + String artifactId = key.substring(TYPE_CONTENT.length() + 1); + System.out.println("n\n"); + System.out.println(artifactId); + System.out.println(getParam(key)); + System.out.println(Artifact.GROUP_CONTENT); + + artifactList.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); + } + } + return artifactList; + } + protected Set getAllKeys() { return properties.keySet(); } - - protected String getArtifactType(String key){ - String[] wordsArray = key.split("\\."); - if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){ - if(key.contains(".")){ - return key.substring(0, key.indexOf(".")); - }else { - return ""; - } - }else { - return ""; - } - } - - protected String checkIfOverwritten(String key, String param) { - String newKey = key + "." + param; - if (getParam(newKey) != null) { - String setting = getParam(newKey); - if (setting.equals("referenceapplication")) { - setting = setting.concat("-"); - setting = setting.concat("package"); - } - - return setting; - } else { - switch (param) { - case ARTIFACT_ID: - return extractArtifactId(key); - case GROUP_ID: - switch (getArtifactType(key)) { - case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId - return Artifact.GROUP_WEB; - case TYPE_OMOD: - return Artifact.GROUP_MODULE; - case TYPE_DISTRO: - case TYPE_CONFIG: - return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); - default: - return ""; - } - - case TYPE: - switch (getArtifactType(key)) { - case TYPE_OMOD: - case TYPE_DISTRO: - return TYPE_JAR; - case TYPE_WAR: - return TYPE_WAR; - case TYPE_CONFIG: + + protected String getArtifactType(String key) { + String[] wordsArray = key.split("\\."); + if (!(wordsArray[wordsArray.length - 1].equals(TYPE) || wordsArray[wordsArray.length - 1].equals(ARTIFACT_ID) + || wordsArray[wordsArray.length - 1].equals(GROUP_ID))) { + if (key.contains(".")) { + return key.substring(0, key.indexOf(".")); + } else { + return ""; + } + } else { + return ""; + } + } + + protected String checkIfOverwritten(String key, String param) { + String newKey = key + "." + param; + if (getParam(newKey) != null) { + String setting = getParam(newKey); + if (setting.equals("referenceapplication")) { + setting = setting.concat("-"); + setting = setting.concat("package"); + } + + return setting; + } else { + switch (param) { + case ARTIFACT_ID: + return extractArtifactId(key); + case GROUP_ID: + switch (getArtifactType(key)) { + case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId + return Artifact.GROUP_WEB; + case TYPE_OMOD: + return Artifact.GROUP_MODULE; + case TYPE_DISTRO: + case TYPE_CONFIG: + return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); + default: + return ""; + } + + case TYPE: + switch (getArtifactType(key)) { + case TYPE_OMOD: + case TYPE_DISTRO: + return TYPE_JAR; + case TYPE_WAR: + return TYPE_WAR; + case TYPE_CONFIG: return TYPE_ZIP; - default: - return ""; - } - default: - return ""; - } - } - } - - protected String extractArtifactId(String key){ - String type = getArtifactType(key); - StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); - if(type.equals(TYPE_OMOD)) { - stringBuilder.append("-"); - stringBuilder.append(type); - } else if(type.equals(TYPE_WAR)){ - stringBuilder.append("-"); - stringBuilder.append("webapp"); - } // referenceapplication exclusive parser - else if (key.equals("distro.referenceapplication")) { - stringBuilder.append("-"); - stringBuilder.append("package"); - } - - return stringBuilder.toString(); - } - - /** - * get param from properties - * @param key - * @return - */ - public String getParam(String key) {return properties.getProperty(key); } - - public Artifact getModuleArtifact(String artifactId){ - String key = TYPE_OMOD + "." + artifactId; - if(StringUtils.isNotBlank(getParam(key))){ - return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)); - } - return null; - } - - public void setModuleProperties(Artifact newModule) { - newModule = stripArtifactId(newModule); - if(!newModule.getGroupId().equals(Artifact.GROUP_MODULE)){ - setCustomModuleGroupId(newModule); - } - if(!newModule.getType().equals(TYPE_JAR)){ - setCustomModuleType(newModule); - } - setModule(newModule); - - } - - public void removeModuleProperties(Artifact artifact) { - artifact = stripArtifactId(artifact); - if (getModuleArtifact(artifact.getArtifactId()) != null) { - Properties newProperties = new Properties(); - newProperties.putAll(properties); - for(Object keyObject: properties.keySet()){ - String key = keyObject.toString(); - if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId())){ - newProperties.remove(key); - } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE)){ - newProperties.remove(key); - } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID)){ - newProperties.remove(key); - } - } - properties = newProperties; - } - } - - /** - * Removes `-omod` or `-webapp` suffix from artifact ID. - * - * @param artifact - * @return The same artifact, mutated - */ - private Artifact stripArtifactId(Artifact artifact) { - String artifactId = artifact.getArtifactId(); - if (artifactId.endsWith("-omod") || artifactId.endsWith("-webapp")) { - artifact.setArtifactId(artifactId.substring(0, artifactId.lastIndexOf("-"))); - } - return artifact; - } - - private void setModule(Artifact artifact) { - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId(), artifact.getVersion()); - } - - private void setCustomModuleType(Artifact artifact){ - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType()); - } - - private void setCustomModuleGroupId(Artifact artifact){ - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId()); - } - - public void synchronize(BaseSdkProperties other){ - for(Object key: getAllKeys()){ - if (isBaseSdkProperty(key.toString())) { - other.properties.put(key, properties.get(key)); - } - } - for(Object key: new ArrayList<>(other.getAllKeys())){ - if(isBaseSdkProperty(key.toString())){ - if(StringUtils.isBlank(getParam(key.toString()))){ - other.properties.remove(key); - } - } - } - } - - private boolean isBaseSdkProperty(String key) { - return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); - } - - - public void setArtifacts(List warArtifacts, List moduleArtifacts){ - for (Artifact moduleArtifact : moduleArtifacts) { - this.setModuleProperties(moduleArtifact); - } - for (Artifact warArtifact : warArtifacts) { - this.setPlatformVersion(warArtifact.getVersion()); - } - } - + default: + return ""; + } + default: + return ""; + } + } + } + + protected String extractArtifactId(String key) { + String type = getArtifactType(key); + StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); + if (type.equals(TYPE_OMOD)) { + stringBuilder.append("-"); + stringBuilder.append(type); + } else if (type.equals(TYPE_WAR)) { + stringBuilder.append("-"); + stringBuilder.append("webapp"); + } // referenceapplication exclusive parser + else if (key.equals("distro.referenceapplication")) { + stringBuilder.append("-"); + stringBuilder.append("package"); + } + + return stringBuilder.toString(); + } + + /** + * get param from properties + * + * @param key + * @return + */ + public String getParam(String key) { + return properties.getProperty(key); + } + + public Artifact getModuleArtifact(String artifactId) { + String key = TYPE_OMOD + "." + artifactId; + if (StringUtils.isNotBlank(getParam(key))) { + return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), + checkIfOverwritten(key, TYPE)); + } + return null; + } + + public void setModuleProperties(Artifact newModule) { + newModule = stripArtifactId(newModule); + if (!newModule.getGroupId().equals(Artifact.GROUP_MODULE)) { + setCustomModuleGroupId(newModule); + } + if (!newModule.getType().equals(TYPE_JAR)) { + setCustomModuleType(newModule); + } + setModule(newModule); + + } + + public void removeModuleProperties(Artifact artifact) { + artifact = stripArtifactId(artifact); + if (getModuleArtifact(artifact.getArtifactId()) != null) { + Properties newProperties = new Properties(); + newProperties.putAll(properties); + for (Object keyObject : properties.keySet()) { + String key = keyObject.toString(); + if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId())) { + newProperties.remove(key); + } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE)) { + newProperties.remove(key); + } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID)) { + newProperties.remove(key); + } + } + properties = newProperties; + } + } + + /** + * Removes `-omod` or `-webapp` suffix from artifact ID. + * + * @param artifact + * @return The same artifact, mutated + */ + private Artifact stripArtifactId(Artifact artifact) { + String artifactId = artifact.getArtifactId(); + if (artifactId.endsWith("-omod") || artifactId.endsWith("-webapp")) { + artifact.setArtifactId(artifactId.substring(0, artifactId.lastIndexOf("-"))); + } + return artifact; + } + + private void setModule(Artifact artifact) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); + } + + private void setCustomModuleType(Artifact artifact) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + } + + private void setCustomModuleGroupId(Artifact artifact) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + } + + public void synchronize(BaseSdkProperties other) { + for (Object key : getAllKeys()) { + if (isBaseSdkProperty(key.toString())) { + other.properties.put(key, properties.get(key)); + } + } + for (Object key : new ArrayList<>(other.getAllKeys())) { + if (isBaseSdkProperty(key.toString())) { + if (StringUtils.isBlank(getParam(key.toString()))) { + other.properties.remove(key); + } + } + } + } + + private boolean isBaseSdkProperty(String key) { + return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); + } + + public void setArtifacts(List warArtifacts, List moduleArtifacts) { + for (Artifact moduleArtifact : moduleArtifacts) { + this.setModuleProperties(moduleArtifact); + } + for (Artifact warArtifact : warArtifacts) { + this.setPlatformVersion(warArtifact.getVersion()); + } + } + } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index 09f1e1e53..f15ff43bd 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -3,13 +3,6 @@ import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile; import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.openmrs.maven.plugins.utility.DistroHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -21,274 +14,303 @@ import java.util.Properties; import java.util.Set; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.plugin.MojoExecutionException; +import org.openmrs.maven.plugins.utility.DistroHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * */ public class DistroProperties extends BaseSdkProperties { - - public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt"; - private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties"; - public static final String DISTRO_FILE_NAME = "openmrs-distro.properties"; - private static final String DB_SQL = "db.sql"; - public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default"; - public static final String PROPERTY_KEY = "property.%s"; - + + public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt"; + + private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties"; + + public static final String DISTRO_FILE_NAME = "openmrs-distro.properties"; + + private static final String DB_SQL = "db.sql"; + + public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default"; + + public static final String PROPERTY_KEY = "property.%s"; + private static final Logger log = LoggerFactory.getLogger(DistroProperties.class); - - public DistroProperties(String version){ - properties = new Properties(); - try { - loadPropertiesFromResource(createFileName(version), properties); - } catch (MojoExecutionException e) { - log.error(e.getMessage(), e); - } - } - - public DistroProperties(String name, String platformVersion){ - properties = new Properties(); - setName(name); - setVersion("1.0"); // it's unclear what this means or why it is necessary, but it is tested for - setPlatformVersion(platformVersion); - } - - public DistroProperties(Properties properties){ - this.properties = properties; - } - - public DistroProperties(File file) throws MojoExecutionException{ - this.properties = new Properties(); - loadPropertiesFromFile(file, this.properties); - } - - private String createFileName(String version){ - return String.format(DEAFAULT_FILE_NAME, version); - } - - public boolean isH2Supported(){ - return Boolean.parseBoolean(getParam("db.h2.supported")); - } - - public void setH2Support(boolean supported) { - properties.setProperty("db.h2.supported", String.valueOf(supported)); - } - - public String getSqlScriptPath() { - return getParam(DB_SQL); - } - - public String getPropertyPrompt(String propertyName){ - return getParam(String.format(PROPERTY_PROMPT_KEY, propertyName)); - } - - public String getPropertyDefault(String propertyName){ - return getParam(String.format(PROPERTY_DEFAULT_VALUE_KEY, propertyName)); - } - - public String getPropertyValue(String propertyName){ - return getParam(String.format(PROPERTY_KEY, propertyName)); - } - - public Set getPropertiesNames(){ - Set propertiesNames = new HashSet<>(); - for(Object key: getAllKeys()){ - if(key.toString().startsWith("property.")){ - propertiesNames.add(extractPropertyName(key.toString())); - } - } - return propertiesNames; - } - - private String extractPropertyName(String key) { - int beginIndex = key.indexOf("."); - if(key.endsWith(".default")){ - return key.substring(beginIndex+1, key.length()-8); - } else if(key.endsWith(".prompt")){ - return key.substring(beginIndex+1, key.length()-7); - } else { - return key.substring(beginIndex+1); - } - } - - public Artifact getDistroArtifact() { - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if(artifactType.equals(TYPE_DISTRO)) { - return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "jar"); - } - } - return null; - } - - public Artifact getParentArtifact() { - String parentArtifactId = getParam("parent.artifactId"); - String parentGroupId = getParam("parent.groupId"); - String parentVersion = getParam("parent.version"); - - int missingCount = 0; - if (StringUtils.isBlank(parentArtifactId)) { - log.warn("parent.artifactId missing"); - missingCount++; - } - if (StringUtils.isBlank(parentGroupId)) { - log.warn("parent.groupId is missing"); - missingCount++; - } - if (StringUtils.isBlank(parentVersion)) { - log.warn("parent.version is missing"); - missingCount++; - } - - // We are only going to throw an error if only one or two parameters are missing - if (missingCount > 0 && missingCount < 3) { - throw new IllegalArgumentException("Missing arguments for the parent"); - } - - return new Artifact(parentArtifactId, parentVersion, parentGroupId, "zip"); - } - - public List getModuleArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getModuleArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getModuleArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public List getOwaArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getOwaArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getOwaArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public Map getSpaProperties(DistroHelper distroHelper, File directory) throws MojoExecutionException { - Map spaProperties = getSpaProperties(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - spaProperties.putAll(distroProperties.getSpaProperties(distroHelper, directory)); - } - return spaProperties; - } - - public List getWarArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException{ - List childArtifacts = getWarArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getWarArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException{ - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - return distroProperties.getPlatformVersion(distroHelper, directory); - } - return getPlatformVersion(); - } - - private List mergeArtifactLists(List childArtifacts, List parentArtifacts) { - List artifactList = new ArrayList<>(childArtifacts); - for (Artifact parentArtifact : parentArtifacts) { - boolean found = false; - for (Artifact childArtifact : childArtifacts) { - boolean isGroupIdMatch = childArtifact.getGroupId().equals(parentArtifact.getGroupId()); - boolean isArtifactIdMatch = childArtifact.getArtifactId().equals(parentArtifact.getArtifactId()); - boolean isTypeMatch = childArtifact.getType().equals(parentArtifact.getType()); - if (isGroupIdMatch && isArtifactIdMatch && isTypeMatch) { - found = true; - break; - } - } - if (!found) { - artifactList.add(parentArtifact); - } - } - return artifactList; - } - - public void saveTo(File path) throws MojoExecutionException { - FileOutputStream out = null; - try { - out = new FileOutputStream(new File(path, DISTRO_FILE_NAME)); - SortedProperties sortedProperties = new SortedProperties(); - sortedProperties.putAll(properties); - sortedProperties.store(out, null); - } - catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); - } - finally { - IOUtils.closeQuietly(out); - } - } - - public void resolvePlaceholders(Properties projectProperties) throws MojoExecutionException { - for(Map.Entry property: properties.entrySet()){ - if(hasPlaceholder(property.getValue())){ - try{ - Object placeholderValue = projectProperties.get(getPlaceholderKey((String)property.getValue())); - if(placeholderValue == null){ - throw new MojoExecutionException( - "Failed to resolve property placeholders in distro file, no property for key \"" + - property.getKey() + "\""); - } else { - property.setValue(putInPlaceholder((String)property.getValue(), (String)placeholderValue)); - } - } catch (ClassCastException e){ - throw new MojoExecutionException("Property with key \"" + property.getKey() + "\" and value \"" + - property.getValue() + "\" is not placeholder."); - } - } - } - } - - public Set getAllKeys() { - return properties.keySet(); - } - - public List getExclusions() { - String exclusions = getParam("exclusions"); - if(exclusions == null) { - return new ArrayList<>(); - } - return Arrays.asList(exclusions.split(",")); - } - - private String getPlaceholderKey(String string){ - int startIndex = string.indexOf("${")+2; - int endIndex = string.indexOf("}", startIndex); - return string.substring(startIndex, endIndex); - } - - private String putInPlaceholder(String value, String placeholderValue) { - return value.replace("${"+getPlaceholderKey(value)+"}", placeholderValue); - } - - private boolean hasPlaceholder(Object object){ - String asString; - try{ - asString = (String) object; - } catch(ClassCastException e){ - return false; - } - int index = asString.indexOf("{"); - return index != -1 && asString.substring(index).contains("}"); - } + + public DistroProperties(String version) { + properties = new Properties(); + try { + loadPropertiesFromResource(createFileName(version), properties); + } + catch (MojoExecutionException e) { + log.error(e.getMessage(), e); + } + } + + public DistroProperties(String name, String platformVersion) { + properties = new Properties(); + setName(name); + setVersion("1.0"); // it's unclear what this means or why it is necessary, but it is tested for + setPlatformVersion(platformVersion); + } + + public DistroProperties(Properties properties) { + this.properties = properties; + } + + public DistroProperties(File file) throws MojoExecutionException { + this.properties = new Properties(); + loadPropertiesFromFile(file, this.properties); + } + + private String createFileName(String version) { + return String.format(DEAFAULT_FILE_NAME, version); + } + + public boolean isH2Supported() { + return Boolean.parseBoolean(getParam("db.h2.supported")); + } + + public void setH2Support(boolean supported) { + properties.setProperty("db.h2.supported", String.valueOf(supported)); + } + + public String getSqlScriptPath() { + return getParam(DB_SQL); + } + + public String getPropertyPrompt(String propertyName) { + return getParam(String.format(PROPERTY_PROMPT_KEY, propertyName)); + } + + public String getPropertyDefault(String propertyName) { + return getParam(String.format(PROPERTY_DEFAULT_VALUE_KEY, propertyName)); + } + + public String getPropertyValue(String propertyName) { + return getParam(String.format(PROPERTY_KEY, propertyName)); + } + + public Set getPropertiesNames() { + Set propertiesNames = new HashSet<>(); + for (Object key : getAllKeys()) { + if (key.toString().startsWith("property.")) { + propertiesNames.add(extractPropertyName(key.toString())); + } + } + return propertiesNames; + } + + private String extractPropertyName(String key) { + int beginIndex = key.indexOf("."); + if (key.endsWith(".default")) { + return key.substring(beginIndex + 1, key.length() - 8); + } else if (key.endsWith(".prompt")) { + return key.substring(beginIndex + 1, key.length() - 7); + } else { + return key.substring(beginIndex + 1); + } + } + + public Artifact getDistroArtifact() { + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_DISTRO)) { + return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), + checkIfOverwritten(key, TYPE), "jar"); + } + } + return null; + } + + public Artifact getParentArtifact() { + String parentArtifactId = getParam("parent.artifactId"); + String parentGroupId = getParam("parent.groupId"); + String parentVersion = getParam("parent.version"); + + int missingCount = 0; + if (StringUtils.isBlank(parentArtifactId)) { + log.warn("parent.artifactId missing"); + missingCount++; + } + if (StringUtils.isBlank(parentGroupId)) { + log.warn("parent.groupId is missing"); + missingCount++; + } + if (StringUtils.isBlank(parentVersion)) { + log.warn("parent.version is missing"); + missingCount++; + } + + // We are only going to throw an error if only one or two parameters are missing + if (missingCount > 0 && missingCount < 3) { + throw new IllegalArgumentException("Missing arguments for the parent"); + } + + return new Artifact(parentArtifactId, parentVersion, parentGroupId, "zip"); + } + + public List getModuleArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getModuleArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getModuleArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public List getOwaArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getOwaArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getOwaArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public List getContentArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getContentArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getContentArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public Map getSpaProperties(DistroHelper distroHelper, File directory) throws MojoExecutionException { + Map spaProperties = getSpaProperties(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + spaProperties.putAll(distroProperties.getSpaProperties(distroHelper, directory)); + } + return spaProperties; + } + + public List getWarArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getWarArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getWarArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException { + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + return distroProperties.getPlatformVersion(distroHelper, directory); + } + return getPlatformVersion(); + } + + private List mergeArtifactLists(List childArtifacts, List parentArtifacts) { + List artifactList = new ArrayList<>(childArtifacts); + for (Artifact parentArtifact : parentArtifacts) { + boolean found = false; + for (Artifact childArtifact : childArtifacts) { + boolean isGroupIdMatch = childArtifact.getGroupId().equals(parentArtifact.getGroupId()); + boolean isArtifactIdMatch = childArtifact.getArtifactId().equals(parentArtifact.getArtifactId()); + boolean isTypeMatch = childArtifact.getType().equals(parentArtifact.getType()); + if (isGroupIdMatch && isArtifactIdMatch && isTypeMatch) { + found = true; + break; + } + } + if (!found) { + artifactList.add(parentArtifact); + } + } + return artifactList; + } + + public void saveTo(File path) throws MojoExecutionException { + FileOutputStream out = null; + try { + out = new FileOutputStream(new File(path, DISTRO_FILE_NAME)); + SortedProperties sortedProperties = new SortedProperties(); + sortedProperties.putAll(properties); + sortedProperties.store(out, null); + } + catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + finally { + IOUtils.closeQuietly(out); + } + } + + public void resolvePlaceholders(Properties projectProperties) throws MojoExecutionException { + for (Map.Entry property : properties.entrySet()) { + if (hasPlaceholder(property.getValue())) { + try { + Object placeholderValue = projectProperties.get(getPlaceholderKey((String) property.getValue())); + if (placeholderValue == null) { + throw new MojoExecutionException( + "Failed to resolve property placeholders in distro file, no property for key \"" + + property.getKey() + "\""); + } else { + property.setValue(putInPlaceholder((String) property.getValue(), (String) placeholderValue)); + } + } + catch (ClassCastException e) { + throw new MojoExecutionException("Property with key \"" + property.getKey() + "\" and value \"" + + property.getValue() + "\" is not placeholder."); + } + } + } + } + + @Override + public Set getAllKeys() { + return properties.keySet(); + } + + public List getExclusions() { + String exclusions = getParam("exclusions"); + if (exclusions == null) { + return new ArrayList<>(); + } + return Arrays.asList(exclusions.split(",")); + } + + private String getPlaceholderKey(String string) { + int startIndex = string.indexOf("${") + 2; + int endIndex = string.indexOf("}", startIndex); + return string.substring(startIndex, endIndex); + } + + private String putInPlaceholder(String value, String placeholderValue) { + return value.replace("${" + getPlaceholderKey(value) + "}", placeholderValue); + } + + private boolean hasPlaceholder(Object object) { + String asString; + try { + asString = (String) object; + } + catch (ClassCastException e) { + return false; + } + int index = asString.indexOf("{"); + return index != -1 && asString.substring(index).contains("}"); + } } From 54761882828c2fbdfdb203a4de4b980569a19ba2 Mon Sep 17 00:00:00 2001 From: Ravilla Date: Mon, 26 Aug 2024 13:51:21 -0400 Subject: [PATCH 02/31] Revert "Pull and extract the content package set in distro.prop" This reverts commit 384e7b3bbfbb94dd22cb6ef3eb38bb4b948ce0e8. --- .../openmrs/maven/plugins/AbstractTask.java | 98 ++- .../openmrs/maven/plugins/BuildDistro.java | 342 +++++---- .../java/org/openmrs/maven/plugins/Setup.java | 368 +++++----- .../maven/plugins/utility/ContentHelper.java | 99 --- .../plugins/utility/ModuleInstaller.java | 209 +++--- .../openmrs/maven/plugins/model/Artifact.java | 1 - .../plugins/model/BaseSdkProperties.java | 649 ++++++++---------- .../maven/plugins/model/DistroProperties.java | 566 ++++++++------- 8 files changed, 1055 insertions(+), 1277 deletions(-) delete mode 100644 maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 14d87f4a9..61a397758 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -1,7 +1,5 @@ package org.openmrs.maven.plugins; -import java.util.ArrayDeque; - import org.apache.commons.lang.StringUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; @@ -14,12 +12,11 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; -import org.openmrs.maven.plugins.git.DefaultGitHelper; -import org.openmrs.maven.plugins.git.GitHelper; import org.openmrs.maven.plugins.model.Server; -import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DefaultJira; import org.openmrs.maven.plugins.utility.DistroHelper; +import org.openmrs.maven.plugins.git.DefaultGitHelper; +import org.openmrs.maven.plugins.git.GitHelper; import org.openmrs.maven.plugins.utility.DockerHelper; import org.openmrs.maven.plugins.utility.Jira; import org.openmrs.maven.plugins.utility.ModuleInstaller; @@ -30,119 +27,116 @@ import org.openmrs.maven.plugins.utility.VersionsHelper; import org.openmrs.maven.plugins.utility.Wizard; +import java.util.ArrayDeque; + /** * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ OwaHelper owaHelper; - - /** - * handles Contents - */ - ContentHelper contentHelper; - + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - + public AbstractTask(AbstractTask other) { this.mavenProject = other.mavenProject; this.mavenSession = other.mavenSession; @@ -154,7 +148,6 @@ public AbstractTask(AbstractTask other) { this.versionsHelper = other.versionsHelper; this.distroHelper = other.distroHelper; this.owaHelper = other.owaHelper; - this.contentHelper = other.contentHelper; this.spaInstaller = other.spaInstaller; this.gitHelper = other.gitHelper; this.dockerHelper = other.dockerHelper; @@ -165,7 +158,7 @@ public AbstractTask(AbstractTask other) { this.stats = other.stats; initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -185,9 +178,6 @@ public void initTask() { if (owaHelper == null) { owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); } - if (contentHelper == null) { - contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); - } if (spaInstaller == null) { spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); } @@ -197,19 +187,19 @@ public void initTask() { if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index 74b7885e8..e609621b3 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -1,137 +1,138 @@ package org.openmrs.maven.plugins; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - +import net.lingala.zip4j.core.ZipFile; +import net.lingala.zip4j.exception.ZipException; +import net.lingala.zip4j.model.ZipParameters; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.Git; import org.openmrs.maven.plugins.model.Artifact; import org.openmrs.maven.plugins.model.DistroProperties; -import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; import org.openmrs.maven.plugins.utility.DistroHelper; +import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.utility.SDKConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.lingala.zip4j.core.ZipFile; -import net.lingala.zip4j.exception.ZipException; -import net.lingala.zip4j.model.ZipParameters; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; /** * Create docker configuration for distributions. */ @Mojo(name = "build-distro", requiresProject = false) public class BuildDistro extends AbstractTask { - + private static final String DEFAULT_SQL_DUMP = Server.CLASSPATH_SCRIPT_PREFIX + "openmrs-platform.sql"; - + private static final String OPENMRS_WAR = "openmrs.war"; - + private static final String OPENMRS_DISTRO_PROPERTIES = "openmrs-distro.properties"; - + private static final String DOCKER_COMPOSE_PATH = "build-distro/docker-compose.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_PATH = "build-distro/docker-compose.override.yml"; - + private static final String DOCKER_COMPOSE_PROD_PATH = "build-distro/docker-compose.prod.yml"; - + private static final String README_PATH = "build-distro/README.md"; - + private static final String DISTRIBUTION_VERSION_PROMPT = "You can build the following versions of distribution"; - + private static final String DUMP_PREFIX = "CREATE DATABASE IF NOT EXISTS `openmrs`;\n\n USE `openmrs`;\n\n"; - + private static final String DB_DUMP_PATH = "dbdump" + File.separator + "dump.sql"; - + private static final String WAR_FILE_MODULES_DIRECTORY_NAME = "bundledModules"; - + private static final String WEB = "web"; - + private static final String DOCKER_COMPOSE_YML = "docker-compose.yml"; - + private static final String DOCKER_COMPOSE_PROD_YML = "docker-compose.prod.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_YML = "docker-compose.override.yml"; - + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final Logger log = LoggerFactory.getLogger(BuildDistro.class); - + /** * Path to the openmrs-distro.properties file. */ @Parameter(property = "distro") private String distro; - + /** * Directory for generated files. (default to 'docker') */ @Parameter(property = "dir") private String dir; - + /** * SQL script for database configuration. */ @Parameter(property = "dbSql") private String dbSql; - + /** * Causes npm to completely ignore peerDependencies */ @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + /** - * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after - * the setup + * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after the setup */ @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + /** - * Instead of creating a `modules` folder in the distro directory, will put modules inside the - * war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` + * Instead of creating a `modules` folder in the distro directory, will put modules inside + * the war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` */ @Parameter(defaultValue = "false", property = "bundled") private boolean bundled; - + /** * Flag to indicate whether to delete the target directory or not. */ @Parameter(defaultValue = "false", property = "reset") private boolean reset; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Override public void executeTask() throws MojoExecutionException, MojoFailureException { File buildDirectory = getBuildDirectory(); - + File userDir = new File(System.getProperty("user.dir")); - + Artifact distroArtifact = null; DistroProperties distroProperties = null; - + if (distro == null) { File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME); if (distroFile.exists()) { @@ -141,14 +142,15 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } else if (Project.hasProject(userDir)) { Project config = Project.loadProject(userDir); - distroArtifact = DistroHelper.parseDistroArtifact( - config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), versionsHelper); - + distroArtifact = DistroHelper + .parseDistroArtifact(config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), + versionsHelper); + wizard.showMessage("Building distribution from the source at " + userDir + "...\n"); new Build(this).buildProject(config); - distroFile = distroHelper.extractFileFromDistro(buildDirectory, distroArtifact, - DistroProperties.DISTRO_FILE_NAME); - + distroFile = distroHelper + .extractFileFromDistro(buildDirectory, distroArtifact, DistroProperties.DISTRO_FILE_NAME); + if (distroFile.exists()) { distroProperties = new DistroProperties(distroFile); } else { @@ -160,14 +162,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroArtifact = distroProperties.getParentArtifact(); distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } - + if (distroProperties == null) { Server server = new Server.ServerBuilder().build(); - + List options = new ArrayList<>(); options.add(O2_DISTRIBUTION); options.add(O3_DISTRIBUTION); - + String choice = wizard.promptForMissingValueWithOptions("You can setup following servers", null, null, options); switch (choice) { case O2_DISTRIBUTION: @@ -176,62 +178,57 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = new DistroProperties(server.getVersion()); } else { distroProperties = distroHelper.downloadDistroProperties(buildDirectory, server); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), + "jar"); } break; case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); server.setServerDirectory(buildDirectory); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties( - distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); } - + } - + if (distroProperties == null) { throw new MojoExecutionException("The distro you specified, '" + distro + "' could not be retrieved"); } - + String distroName = buildDistro(buildDirectory, distroArtifact, distroProperties); - + wizard.showMessage( - "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " - + buildDirectory.getAbsolutePath() + "\n"); + "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " + + buildDirectory.getAbsolutePath() + "\n"); } - - private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, - DistroProperties distroProperties) throws MojoExecutionException { - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) - && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, - appShellVersion); + + private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException { + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, appShellVersion); } return distroProperties; } - + private File getBuildDirectory() throws MojoExecutionException { final File targetDir; if (StringUtils.isBlank(dir)) { String directory = wizard.promptForValueIfMissingWithDefault( - "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); + "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); targetDir = new File(directory); } else { targetDir = new File(dir); } - + if (targetDir.exists()) { if (targetDir.isDirectory()) { if (!reset) { if (isDockerComposeCreated(targetDir)) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' contains docker config. Only modules and openmrs.war will be overriden"); + + "' contains docker config. Only modules and openmrs.war will be overriden"); deleteDistroFiles(new File(targetDir, WEB)); } else if (targetDir.list().length != 0) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' is not empty. All its content will be lost."); + + "' is not empty. All its content will be lost."); boolean chooseDifferent = wizard.promptYesNo("Would you like to choose a different directory?"); if (chooseDifferent) { return getBuildDirectory(); @@ -249,12 +246,12 @@ private File getBuildDirectory() throws MojoExecutionException { } else { targetDir.mkdirs(); } - + dir = targetDir.getAbsolutePath(); - + return targetDir; } - + private void deleteDistroFiles(File targetDir) { try { FileUtils.deleteDirectory(new File(targetDir, "modules")); @@ -265,52 +262,47 @@ private void deleteDistroFiles(File targetDir) { log.error(e.getMessage(), e); } } - + private void deleteDirectory(File targetDir) throws MojoExecutionException { try { FileUtils.cleanDirectory(targetDir); } catch (IOException e) { - throw new MojoExecutionException( - "Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); + throw new MojoExecutionException("Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); } } - + private String buildDistro(File targetDirectory, Artifact distroArtifact, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { InputStream dbDumpStream; wizard.showMessage("Downloading modules...\n"); - + String distroName = adjustImageName(distroProperties.getName()); File web = new File(targetDirectory, WEB); web.mkdirs(); - - moduleInstaller.installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), - web.getAbsolutePath()); + + moduleInstaller + .installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), web.getAbsolutePath()); renameWebApp(web); - + if (bundled) { try { ZipFile warfile = new ZipFile(new File(web, OPENMRS_WAR)); File tempDir = new File(web, "WEB-INF"); tempDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); - + new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); + File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - - //TODO: does this flow need this? - //downloadContents(targetDirectory, distroProperties); - - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, - overrideReuseNodeCache); + + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); - if (frontendDir.exists()) { + if(frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); } - + warfile.addFolder(tempDir, new ZipParameters()); try { FileUtils.deleteDirectory(tempDir); @@ -326,24 +318,23 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File modulesDir = new File(web, "modules"); modulesDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - modulesDir.getAbsolutePath()); - + modulesDir.getAbsolutePath()); + File frontendDir = new File(web, "frontend"); frontendDir.mkdir(); - + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); - - downloadContents(configDir, distroProperties); + spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - + + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - } - + wizard.showMessage("Creating Docker Compose configuration...\n"); String distroVersion = adjustImageName(distroProperties.getVersion()); writeDockerCompose(targetDirectory, distroVersion); @@ -354,40 +345,38 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro copyBuildDistroResource(".env", new File(targetDirectory, ".env")); copyDockerfile(web, distroProperties); distroProperties.saveTo(web); - + dbDumpStream = getSqlDumpStream(StringUtils.isNotBlank(dbSql) ? dbSql : distroProperties.getSqlScriptPath(), - targetDirectory, distroArtifact); + targetDirectory, distroArtifact); if (dbDumpStream != null) { copyDbDump(targetDirectory, dbDumpStream); } //clean up extracted sql file cleanupSqlFiles(targetDirectory); - + return distroName; } - - private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) - throws MojoExecutionException { + + private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + + downloadConfigs(distroProperties, configDir); - - File refappConfigFile = new File(configDir, - distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); - + + File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) - && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -398,12 +387,11 @@ private void setConfigFolder(File configDir, DistroProperties distroProperties, FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } - catch (ZipException | IOException e) { + } catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { List configs = distroProperties.getConfigArtifacts(); wizard.showMessage("Downloading Configs...\n"); @@ -411,9 +399,9 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -423,30 +411,14 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - - private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { - - File targetDirectory = new File(configDir, "temp_content"); - targetDirectory.mkdir(); - - List 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); - } - + private boolean isDockerComposeCreated(File targetDir) { File dockerComposeOverride = new File(targetDir, DOCKER_COMPOSE_OVERRIDE_YML); File dockerCompose = new File(targetDir, DOCKER_COMPOSE_YML); File dockerComposeProd = new File(targetDir, DOCKER_COMPOSE_PROD_YML); return dockerCompose.exists() && dockerComposeOverride.exists() && dockerComposeProd.exists(); } - + private void copyDockerfile(File targetDirectory, DistroProperties distroProperties) throws MojoExecutionException { Version platformVersion = new Version(distroProperties.getPlatformVersion(distroHelper, targetDirectory)); int majorVersion = platformVersion.getMajorVersion(); @@ -463,7 +435,8 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } else { copyBuildDistroResource("Dockerfile-tomcat8", new File(targetDirectory, "Dockerfile")); } - } else { + } + else { if (bundled) { copyBuildDistroResource("Dockerfile-jre8-bundled", new File(targetDirectory, "Dockerfile")); } else { @@ -472,18 +445,18 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } } } - + private boolean isPlatform2point5AndAbove(Version platformVersion) { return platformVersion.getMajorVersion() > 2 - || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); + || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); } - + /** * name of sql dump file is unknown, so wipe all files with 'sql' extension */ private void cleanupSqlFiles(File targetDirectory) { File[] sqlFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".sql"); @@ -493,19 +466,18 @@ public boolean accept(File dir, String name) { FileUtils.deleteQuietly(sql); } } - + private void writeDockerCompose(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PATH, DOCKER_COMPOSE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_OVERRIDE_PATH, DOCKER_COMPOSE_OVERRIDE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PROD_PATH, DOCKER_COMPOSE_PROD_YML); } - + private void writeReadme(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, README_PATH, "README.md"); } - - private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) - throws MojoExecutionException { + + private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) throws MojoExecutionException { URL composeUrl = getClass().getClassLoader().getResource(path); if (composeUrl == null) { throw new MojoExecutionException("Failed to find file '" + path + "' in classpath"); @@ -522,11 +494,11 @@ private void writeTemplatedFile(File targetDirectory, String version, String pat } } } - + private String adjustImageName(String part) { return part.replaceAll("\\s+", "").toLowerCase(); } - + private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExecutionException { File dbDump = new File(targetDirectory, DB_DUMP_PATH); try { @@ -536,15 +508,16 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe catch (IOException e) { throw new MojoExecutionException("Failed to create SQL dump file " + e.getMessage(), e); } - - try (FileWriter writer = new FileWriter(dbDump); BufferedInputStream bis = new BufferedInputStream(stream)) { + + try (FileWriter writer = new FileWriter(dbDump); + BufferedInputStream bis = new BufferedInputStream(stream)) { writer.write(DUMP_PREFIX); - + int c; while ((c = bis.read()) != -1) { writer.write(c); } - + writer.write("\n" + SDKConstants.RESET_SEARCH_INDEX_SQL + "\n"); writer.flush(); } @@ -555,15 +528,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe IOUtils.closeQuietly(stream); } } - + private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) - throws MojoExecutionException { + throws MojoExecutionException { InputStream stream = null; - + if (sqlScriptPath == null) { return null; } - + try { if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); @@ -572,8 +545,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, stream = resourceUrl.openStream(); } else { if (distroArtifact != null && distroArtifact.isValid()) { - File extractedSqlFile = distroHelper.extractFileFromDistro(targetDirectory, distroArtifact, - sqlScript); + File extractedSqlFile = distroHelper + .extractFileFromDistro(targetDirectory, distroArtifact, sqlScript); stream = new FileInputStream(extractedSqlFile); } } @@ -582,8 +555,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, if (scriptFile.exists()) { stream = new FileInputStream(scriptFile); } else { - throw new MojoExecutionException( - "Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); + throw new MojoExecutionException("Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); } } } @@ -592,7 +564,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, } return stream; } - + private void copyBuildDistroResource(String resource, File target) throws MojoExecutionException { URL resourceUrl = getClass().getClassLoader().getResource("build-distro/web/" + resource); if (resourceUrl != null && !target.exists()) { @@ -600,28 +572,28 @@ private void copyBuildDistroResource(String resource, File target) throws MojoEx FileUtils.copyURLToFile(resourceUrl, target); } catch (IOException e) { - throw new MojoExecutionException("Failed to copy file from classpath: " + resourceUrl + " to " - + target.getAbsolutePath() + e.getMessage(), e); + throw new MojoExecutionException( + "Failed to copy file from classpath: " + resourceUrl + " to " + target.getAbsolutePath() + e.getMessage(), e); } } } - + private void renameWebApp(File targetDirectory) throws MojoExecutionException { File[] warFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".war"); } }); - + if (warFiles != null) { for (File file : warFiles) { wizard.showMessage("file:" + file.getAbsolutePath()); } - + wizard.showMessage("target:" + targetDirectory); - + if (warFiles.length == 1) { boolean renameSuccess = warFiles[0].renameTo(new File(targetDirectory, OPENMRS_WAR)); if (!renameSuccess) { diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 6b7e68ec4..00b23e95a 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -20,6 +20,8 @@ import java.util.List; import java.util.Objects; +import net.lingala.zip4j.core.ZipFile; +import net.lingala.zip4j.exception.ZipException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.NullOutputStream; import org.apache.commons.lang.StringUtils; @@ -37,144 +39,141 @@ import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.ServerHelper; -import net.lingala.zip4j.core.ZipFile; -import net.lingala.zip4j.exception.ZipException; /** - * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a - * distribution. It prompts for any missing, but required parameters. + * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters. */ @Mojo(name = "setup", requiresProject = false) public class Setup extends AbstractServerTask { - + public static final String SETTING_UP_A_NEW_SERVER = "Setting up a new server..."; - + public static final String SETUP_SERVERS_PROMPT = "You can setup the following servers"; - - public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = "If you want to enable remote debugging by default when running the server, " - + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; - + + public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = + "If you want to enable remote debugging by default when running the server, " + + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String PLATFORM = "Platform"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final String CLASSPATH_SCRIPT_PREFIX = "classpath://"; - + private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - + private static final int DEFAULT_PORT = 8080; - + /** * DB Driver type */ @Parameter(property = "dbDriver") private String dbDriver; - + /** * DB Uri */ @Parameter(property = "dbUri") private String dbUri; - + /** * DB User */ @Parameter(property = "dbUser") private String dbUser; - + /** * DB Pass */ @Parameter(property = "dbPassword") private String dbPassword; - + /** * DB dump script to import */ @Parameter(property = "dbSql") private String dbSql; - + /** * Docker host address */ @Parameter(property = "dockerHost") private String dockerHost; - + /** * DB reset if exists */ @Parameter(property = "dbReset") private Boolean dbReset; - + /** * Path to JDK Version */ @Parameter(property = "javaHome") private String javaHome; - + /** * Path to installation.properties */ @Parameter(property = "file") private String file; - + /** * Option to include demo data */ @Parameter(defaultValue = "false", property = "addDemoData") private boolean addDemoData; - + /** - * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, - * if it is 'org.openmrs.distro'. + * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, if it is 'org.openmrs.distro'. */ @Parameter(property = "distro") private String distro; - + /** * OpenMRS Platform version to setup e.g. '1.11.5'. */ @Parameter(property = "platform") private String platform; - + @Parameter(property = "debug") private String debug; - + @Parameter(defaultValue = "false", property = "run") private boolean run; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + private ServerHelper serverHelper; - + public Setup() { super(); } - + public Setup(AbstractServerTask other) { super(other); } - + public Setup(AbstractTask other) { super(other); } - + /** - * Gets the distro properties. The distro properties can come from a file specified by path or - * in the current directory or from a maven artifact. If no distro properties file can be found, - * `null` is returned. In this case, the distro file will be created after the database is - * initialized. Setup should proceed to install modules based on the OpenMRS WAR file for the - * given platform version. As of this writing, this function can return null only in platform - * mode. + * Gets the distro properties. The distro properties can come from a file specified by path + * or in the current directory or from a maven artifact. + * If no distro properties file can be found, `null` is returned. In this case, the distro + * file will be created after the database is initialized. Setup should proceed to install + * modules based on the OpenMRS WAR file for the given platform version. + * As of this writing, this function can return null only in platform mode. * * @param server An initialized Server instance * @return distro properties instantiated by DistroHelper @@ -189,12 +188,12 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu if (distroProperties != null) { options.add(distroProperties.getName() + " " + distroProperties.getVersion() + " from current directory"); } - + options.add(O3_DISTRIBUTION); options.add(O2_DISTRIBUTION); options.add(PLATFORM); String choice = wizard.promptForMissingValueWithOptions(SETUP_SERVERS_PROMPT, null, null, options); - + switch (choice) { case PLATFORM: platformMode = true; @@ -211,22 +210,18 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties( - distroHelper.getArtifactProperties(artifact, server, appShellVersion)); + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties(distroHelper.getArtifactProperties(artifact, server, appShellVersion)); platformMode = false; break; - - default: // distro properties from current directory + + default: // distro properties from current directory Artifact distroArtifact = distroProperties.getParentArtifact(); - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) - && StringUtils.isNotBlank(distroArtifact.getGroupId()) - && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, - appShellVersion); + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion); } else { server.setPlatformVersion( - distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); + distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); server.setVersion(distroProperties.getVersion()); } platformMode = false; @@ -234,7 +229,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } else if (platform != null) { server.setPlatformVersion(platform); platformMode = true; - } else { // getting distro properties from file + } else { // getting distro properties from file distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); if (distroProperties == null) { throw new MojoExecutionException("Distro " + distro + "could not be retrieved"); @@ -243,14 +238,15 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu server.setVersion(distroProperties.getVersion()); platformMode = false; } - + if (platformMode) { Artifact platformArtifact = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, - SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); + SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); String version = wizard.promptForPlatformVersionIfMissing(server.getPlatformVersion(), - versionsHelper.getSuggestedVersions(platformArtifact, 6)); - platformArtifact = DistroHelper.parseDistroArtifact( - Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, versionsHelper); + versionsHelper.getSuggestedVersions(platformArtifact, 6)); + platformArtifact = DistroHelper + .parseDistroArtifact(Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, + versionsHelper); server.setPlatformVersion(platformArtifact.getVersion()); try { distroProperties = distroHelper.downloadDistroProperties(server.getServerDirectory(), platformArtifact); @@ -260,15 +256,16 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu distroProperties = null; } } - + return distroProperties; } - + /** - * Sets up a server based on an initialized Server instance and the provided distroProperties. - * Installs modules and other artifacts. Sets up the database. Writes openmrs-server.properties. + * Sets up a server based on an initialized Server instance and the provided + * distroProperties. Installs modules and other artifacts. Sets up the database. + * Writes openmrs-server.properties. * - * @param server An initialized server instance + * @param server An initialized server instance * @param distroProperties Allowed to be null, only if this is a platform install * @throws MojoExecutionException */ @@ -281,39 +278,37 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - installContents(server, distroProperties); if (spaInstaller != null) { - spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, - ignorePeerDependencies, overrideReuseNodeCache); + spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); } - + serverHelper = new ServerHelper(wizard); - + setServerPort(server); setDebugPort(server); - + setupDatabase(server, distroProperties); - + // If there's no distro at this point, we create a minimal one here, // *after* having initialized server.isH2Supported in `setupDatabase` above. if (distroProperties == null) { distroProperties = distroHelper.createDistroForPlatform(server); } distroProperties.saveTo(server.getServerDirectory()); - + setJdk(server); - + server.setValuesFromDistroPropertiesModules( - distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), - distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); + distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), + distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); server.setUnspecifiedToDefault(); server.save(); } - + private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); @@ -324,10 +319,10 @@ private void setJdk(Server server) throws MojoExecutionException { } else { wizard.showMessage("Note: JDK 1.8 or above is needed for platform version " + platformVersion + "."); } - + wizard.promptForJavaHomeIfMissing(server); } - + private void installOWAs(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { File owasDir = new File(server.getServerDirectory(), "owa"); @@ -335,18 +330,9 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } } - - private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { - if (distroProperties != null) { - File tempContentDir = new File(server.getServerDirectory(), "temp-content"); - tempContentDir.mkdir(); - downloadContents(server, distroProperties, tempContentDir); - FileUtils.deleteQuietly(tempContentDir); - } - } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -356,51 +342,35 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - - private void downloadContents(Server server, DistroProperties distroProperties, File tempContentDir) - throws MojoExecutionException { - List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); - //Configuration dir gets created before this method is called - File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); - - if (!contents.isEmpty()) { - wizard.showMessage("Downloading Contents...\n"); - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(configDir, tempContentDir, content, moduleInstaller); - } - } - } - + /** * Sets the configuration folder for the specified server using the provided distro properties. * - * @param server The server for which to set the configuration folder. + * @param server The server for which to set the configuration folder. * @param distroProperties The distro properties containing the configuration information. */ private void setConfigFolder(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - + downloadConfigs(distroProperties, configDir); - + File refappConfigFile = new File(configDir, server.getDistroArtifactId() + "-" + server.getVersion() + ".zip"); - + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) - && "referenceapplication-distro".equals(server.getDistroArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) && "referenceapplication-distro".equals(server.getDistroArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -411,19 +381,16 @@ private void setConfigFolder(Server server, DistroProperties distroProperties) t FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } - catch (ZipException | IOException e) { + } catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + /** - * Downloads the configuration artifact specified in the distro properties and saves them in the - * provided config directory. + * Downloads the configuration artifact specified in the distro properties and saves them in the provided config directory. * - * @param distroProperties The distro properties containing the configuration artifacts to - * download. - * @param configDir The directory where the configuration files will be saved. + * @param distroProperties The distro properties containing the configuration artifacts to download. + * @param configDir The directory where the configuration files will be saved. * @throws MojoExecutionException If an error occurs while downloading the configuration files. */ private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { @@ -433,7 +400,7 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void wipeDatabase(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { @@ -448,11 +415,14 @@ private void wipeDatabase(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to drop " + server.getDbName() + " database"); } } - + private void setServerPort(Server server) throws MojoExecutionException { String message = "What port would you like your server to use?"; - String port = wizard.promptForValueIfMissingWithDefault(message, server.getParam("tomcat.port"), "port number", - String.valueOf(Setup.DEFAULT_PORT)); + String port = wizard.promptForValueIfMissingWithDefault( + message, + server.getParam("tomcat.port"), + "port number", + String.valueOf(Setup.DEFAULT_PORT)); if (!StringUtils.isNumeric(port) || !this.serverHelper.isPort(Integer.parseInt(port))) { wizard.showMessage("Port must be numeric and less or equal 65535."); this.setServerPort(server); @@ -460,12 +430,15 @@ private void setServerPort(Server server) throws MojoExecutionException { } server.setPort(port); } - + private void setDebugPort(Server server) throws MojoExecutionException { if (StringUtils.isBlank(debug) || wizard.checkYes(debug)) { while (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug) && !StringUtils.isNumeric(debug)) { - debug = wizard.promptForValueIfMissingWithDefault(ENABLE_DEBUGGING_DEFAULT_MESSAGE, server.getDebugPort(), - "port number", NO_DEBUGGING_DEFAULT_ANSWER); + debug = wizard.promptForValueIfMissingWithDefault( + ENABLE_DEBUGGING_DEFAULT_MESSAGE, + server.getDebugPort(), + "port number", + NO_DEBUGGING_DEFAULT_ANSWER); if (!StringUtils.isNumeric(debug) && !NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { wizard.showMessage("\nPort number must be numeric."); } else if (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { @@ -474,9 +447,9 @@ private void setDebugPort(Server server) throws MojoExecutionException { } } } - + private void setServerVersionsFromDistroProperties(Server server, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { if (server.getPlatformVersion() == null) { server.setPlatformVersion(distroProperties.getPlatformVersion(distroHelper, server.getServerDirectory())); } @@ -484,55 +457,54 @@ private void setServerVersionsFromDistroProperties(Server server, DistroProperti server.setVersion(distroProperties.getVersion()); } } - + private void setupDatabase(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (server.getDbDriver() == null) { boolean isH2Supported = true; if (distroProperties != null) { isH2Supported = distroProperties.isH2Supported(); } - + wizard.promptForDb(server, dockerHelper, isH2Supported, dbDriver, dockerHost); } - + if (server.getDbDriver() != null) { setupDatabaseForServer(server); } } - + private void setupDatabaseForServer(Server server) throws MojoExecutionException { if (server.getDbName() == null) { server.setDbName(determineDbName(server.getDbUri(), server.getServerId())); } - + if (server.isMySqlDb() || server.isPostgreSqlDb()) { String uri = getUriWithoutDb(server); - try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), - server.getDbName())) { + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { connector.checkAndCreate(server); wizard.showMessage("Connected to the database."); } catch (SQLException e) { throw new MojoExecutionException("Failed to connect to the specified database " + server.getDbUri(), e); } - + if (hasDbTables(server)) { if (dbReset == null) { dbReset = !wizard.promptYesNo( - "Would you like to setup the server using existing data (if not, all data will be lost)?"); + "Would you like to setup the server using existing data (if not, all data will be lost)?"); } - + if (dbReset) { wipeDatabase(server); } else { server.setParam("create_tables", "false"); } } - + if (dbReset == null) { dbReset = true; } - + if (!"null".equals(dbSql) && dbReset) { if (dbSql != null) { importDb(server, dbSql); @@ -540,7 +512,7 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else if (!server.isMySqlDb() && !server.isPostgreSqlDb()) { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage("The specified database " + server.getDbName() - + " does not exist and it will be created when OpenMRS starts."); + + " does not exist and it will be created when OpenMRS starts."); } } else if (!dbReset) { resetSearchIndex(server); @@ -548,30 +520,29 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage( - "The specified database " + server.getDbName() + " does not exist and it will be created for you."); + "The specified database " + server.getDbName() + " does not exist and it will be created for you."); } } - + private boolean hasDbTables(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { DatabaseMetaData md = connector.getConnection().getMetaData(); - + try (ResultSet rs = md.getTables(server.getDbName(), null, null, new String[] { "TABLE" })) { return rs.next(); } } catch (SQLException e) { - throw new MojoExecutionException( - "Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); + throw new MojoExecutionException("Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); } } - + private void resetSearchIndex(Server server) throws MojoExecutionException { String uri = server.getDbUri(); - + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName()); - PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { + PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { ps.execute(); wizard.showMessage("The search index has been reset."); } @@ -579,20 +550,20 @@ private void resetSearchIndex(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to reset search index " + e.getMessage(), e); } } - + private void importDb(Server server, String sqlScriptPath) throws MojoExecutionException { wizard.showMessage("Importing an initial database from " + sqlScriptPath + "..."); String uri = server.getDbUri().replace("@DBNAME@", server.getDbName()); - + InputStream sqlStream; if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); sqlStream = (Setup.class.getClassLoader().getResourceAsStream(sqlScript)); if (sqlStream == null) { Artifact distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); - File extractedSqlFile = distroHelper.extractFileFromDistro(server.getServerDirectory(), distroArtifact, - sqlScript); + server.getDistroGroupId(), "jar"); + File extractedSqlFile = distroHelper + .extractFileFromDistro(server.getServerDirectory(), distroArtifact, sqlScript); extractedSqlFile.deleteOnExit(); try { sqlStream = new FileInputStream(extractedSqlFile); @@ -607,20 +578,19 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE sqlStream = new FileInputStream(scriptFile); } catch (FileNotFoundException e) { - throw new MojoExecutionException( - "SQL import script could not be found at \"" + scriptFile.getAbsolutePath() + "\" " + e.getMessage(), - e); + throw new MojoExecutionException("SQL import script could not be found at \"" + + scriptFile.getAbsolutePath() + "\" " + e.getMessage() , e); } } - + try (InputStreamReader sqlReader = new InputStreamReader(sqlStream); - Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { + Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { ScriptRunner scriptRunner = new ScriptRunner(connection); //we don't want to display ~5000 lines of queries to user if there is no error scriptRunner.setLogWriter(new PrintWriter(new NullOutputStream())); scriptRunner.setStopOnError(true); scriptRunner.runScript(sqlReader); - + wizard.showMessage("Database imported successfully."); server.setParam("create_tables", "false"); } @@ -629,10 +599,10 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE throw new MojoExecutionException("Failed to import database", e); } } - + public String determineDbName(String uri, String serverId) throws MojoExecutionException { String dbName = String.format(SDKConstants.DB_NAME_TEMPLATE, serverId); - + if (!uri.contains("@DBNAME@")) { //determine db name from uri try { @@ -642,59 +612,67 @@ public String determineDbName(String uri, String serverId) throws MojoExecutionE } else { parsedUri = new URI(uri); } - + dbName = parsedUri.getPath(); - + if (dbName == null || dbName.isEmpty() || dbName.equals("/")) { throw new MojoExecutionException("No database name is given in the URI: " + dbName); } - + dbName = dbName.substring(1); - + if (!dbName.substring(1).matches("^[A-Za-z0-9_\\-]+$")) { throw new MojoExecutionException( - "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " - + dbName); + "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " + + + dbName); } } catch (URISyntaxException e) { throw new MojoExecutionException("Could not parse uri: " + uri, e); } } - + return dbName; } - - @Override + public void executeTask() throws MojoExecutionException, MojoFailureException { wizard.showMessage(SETTING_UP_A_NEW_SERVER); - + Server.ServerBuilder serverBuilder; if (file != null) { serverBuilder = new Server.ServerBuilder(Server.loadServer(Paths.get(file))); } else { serverBuilder = new Server.ServerBuilder(); } - - Server server = serverBuilder.setServerId(serverId).setDbDriver(dbDriver).setDbUri(dbUri).setDbUser(dbUser) - .setDbPassword(dbPassword).setInteractiveMode(testMode).setJavaHome(javaHome).setDebugPort(debug).build(); - + + Server server = serverBuilder + .setServerId(serverId) + .setDbDriver(dbDriver) + .setDbUri(dbUri) + .setDbUser(dbUser) + .setDbPassword(dbPassword) + .setInteractiveMode(testMode) + .setJavaHome(javaHome) + .setDebugPort(debug) + .build(); + wizard.promptForNewServerIfMissing(server); - + File serverDir = Server.getServersPath().resolve(server.getServerId()).toFile(); if (serverDir.isDirectory()) { throw new MojoExecutionException( - "Cannot create server: directory with name " + serverDir.getName() + " already exists"); - } else if (serverDir.getAbsolutePath().contains(" ")) { - throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() - + " contains a space. Please make sure your server path does not include any spaces."); + "Cannot create server: directory with name " + serverDir.getName() + " already exists"); } - + else if (serverDir.getAbsolutePath().contains(" ")) { + throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + + " contains a space. Please make sure your server path does not include any spaces."); + } + server.setServerDirectory(serverDir); serverDir.mkdir(); - + try { - DistroProperties distroProperties = resolveDistroProperties(server); setup(server, distroProperties); } @@ -702,14 +680,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { FileUtils.deleteQuietly(server.getServerDirectory()); throw new MojoExecutionException("Failed to setup server", e); } - + getLog().info("Server configured successfully, path: " + serverDir); - + if (run) { new Run(this, server.getServerId()).execute(); } } - + private String getUriWithoutDb(Server server) { String uri = server.getDbUri(); uri = uri.substring(0, uri.lastIndexOf("/") + 1); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java deleted file mode 100644 index 3b3098730..000000000 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.openmrs.maven.plugins.utility; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.BuildPluginManager; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.openmrs.maven.plugins.model.Artifact; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ContentHelper { - - private final MavenSession session; - - private final BuildPluginManager pluginManager; - - private final MavenProject mavenProject; - - private static final Logger logger = LoggerFactory.getLogger(ContentHelper.class); - - public ContentHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager) { - this.session = session; - this.mavenProject = mavenProject; - this.pluginManager = pluginManager; - } - - public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact, - ModuleInstaller moduleInstaller) throws MojoExecutionException { - - String artifactId = contentArtifact.getArtifactId(); - File contentDir = new File(tempContentDir, artifactId); - - moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); - moveBackendConfig(contentDir, configurationDir, artifactId); - } - - private void moveBackendConfig(File inputDir, File configurationDir, String artifactId) throws MojoExecutionException { - - // Check if inputDir and outputDir are valid directories - if (!inputDir.isDirectory() || !configurationDir.isDirectory()) { - throw new MojoExecutionException("Both inputDir and outputDir must be valid directories."); - } - - // List all directories in the inputDir - File backendConfigs = new File(inputDir, "configs" + File.separator + "backend_config"); - - if (backendConfigs == null || backendConfigs.listFiles().length == 0) { - throw new MojoExecutionException("No directories to process under content configuration directories"); - } - - for (File backendConfig : backendConfigs.listFiles()) { - // Find a corresponding directory in the outputDir with the same name as inputSubDir - File matchingConfigurationDir = new File(configurationDir, backendConfig.getName()); - - File artifactDir = null; - - 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 the content from inputDir to the newly created artifactDir - copyDirectory(backendConfig, artifactDir); - - } - } - - private void copyDirectory(File sourceDir, File destDir) throws MojoExecutionException { - try { - if (!destDir.exists()) { - destDir.mkdirs(); - } - - for (File file : sourceDir.listFiles()) { - File destFile = new File(destDir, file.getName()); - if (file.isDirectory()) { - copyDirectory(file, destFile); - } else { - Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - } - } - catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); - } - } - -} diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index 9c8d0c0a8..c72e9527c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -1,5 +1,19 @@ package org.openmrs.maven.plugins.utility; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.DistroProperties; +import org.openmrs.maven.plugins.model.Server; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import static org.twdata.maven.mojoexecutor.MojoExecutor.Element; import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; import static org.twdata.maven.mojoexecutor.MojoExecutor.element; @@ -10,113 +24,98 @@ import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; import static org.twdata.maven.mojoexecutor.MojoExecutor.version; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.BuildPluginManager; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; -import org.openmrs.maven.plugins.model.Artifact; -import org.openmrs.maven.plugins.model.DistroProperties; -import org.openmrs.maven.plugins.model.Server; -import org.twdata.maven.mojoexecutor.MojoExecutor; -import org.twdata.maven.mojoexecutor.MojoExecutor.Element; - /** * Handles installing modules on server */ public class ModuleInstaller { - - private static final String GOAL_UNPACK = "unpack"; - - final MavenProject mavenProject; - - final MavenSession mavenSession; - - final BuildPluginManager pluginManager; - - final VersionsHelper versionsHelper; - - public ModuleInstaller(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager, - VersionsHelper versionsHelper) { - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; - this.versionsHelper = versionsHelper; - } - - public void installDefaultModules(Server server) throws MojoExecutionException { - boolean isPlatform = server.getVersion() == null; // this might be always true, in which case `getCoreModules` can be simplified - List coreModules = SDKConstants.getCoreModules(server.getPlatformVersion(), isPlatform); - if (coreModules == null) { - throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getPlatformVersion())); - } - installModules(coreModules, server.getServerDirectory().getPath()); - } - - public void installModulesForDistro(Server server, DistroProperties properties, DistroHelper distroHelper) - throws MojoExecutionException { - List coreModules; - // install other modules - coreModules = properties.getWarArtifacts(distroHelper, server.getServerDirectory()); - if (coreModules == null) { - throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getVersion())); - } - installModules(coreModules, server.getServerDirectory().getPath()); - File modules = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_MODULES); - modules.mkdirs(); - List artifacts = properties.getModuleArtifacts(distroHelper, server.getServerDirectory()); - // install modules for each version - installModules(artifacts, modules.getPath()); - } - - public void installModules(List artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts.toArray(new Artifact[0]), outputDir, goal); - } - - public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts, outputDir, goal); - } - - public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(new Artifact[] { artifact }, outputDir, goal); - } - - public void installUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { - final String goal = GOAL_UNPACK; - prepareModules(new Artifact[] { artifact }, outputDir, goal); - } - - /** - * Handle list of modules - * - * @param artifacts - * @param outputDir - * @param goal - * @throws MojoExecutionException - */ - private void prepareModules(Artifact[] artifacts, String outputDir, String goal) throws MojoExecutionException { - MojoExecutor.Element[] artifactItems = new MojoExecutor.Element[artifacts.length]; - for (int index = 0; index < artifacts.length; index++) { - artifactItems[index] = artifacts[index].toElement(outputDir); - } - - List configuration = new ArrayList<>(); - configuration.add(element("artifactItems", artifactItems)); - if (goal.equals(GOAL_UNPACK)) { - configuration.add(element("overWriteSnapshots", "true")); - configuration.add(element("overWriteReleases", "true")); - } - executeMojo( - plugin(groupId(SDKConstants.DEPENDENCY_PLUGIN_GROUP_ID), artifactId(SDKConstants.DEPENDENCY_PLUGIN_ARTIFACT_ID), - version(SDKConstants.DEPENDENCY_PLUGIN_VERSION)), - goal(goal), configuration(configuration.toArray(new Element[0])), - executionEnvironment(mavenProject, mavenSession, pluginManager)); - } - + + private static final String GOAL_UNPACK = "unpack"; + + final MavenProject mavenProject; + + final MavenSession mavenSession; + + final BuildPluginManager pluginManager; + + final VersionsHelper versionsHelper; + + public ModuleInstaller(MavenProject mavenProject, + MavenSession mavenSession, + BuildPluginManager pluginManager, + VersionsHelper versionsHelper) { + this.mavenProject = mavenProject; + this.mavenSession = mavenSession; + this.pluginManager = pluginManager; + this.versionsHelper = versionsHelper; + } + + public void installDefaultModules(Server server) throws MojoExecutionException { + boolean isPlatform = server.getVersion() == null; // this might be always true, in which case `getCoreModules` can be simplified + List coreModules = SDKConstants.getCoreModules(server.getPlatformVersion(), isPlatform); + if (coreModules == null) { + throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getPlatformVersion())); + } + installModules(coreModules, server.getServerDirectory().getPath()); + } + + public void installModulesForDistro(Server server, DistroProperties properties, DistroHelper distroHelper) throws MojoExecutionException { + List coreModules; + // install other modules + coreModules = properties.getWarArtifacts(distroHelper, server.getServerDirectory()); + if (coreModules == null) { + throw new MojoExecutionException(String.format("Invalid version: '%s'", server.getVersion())); + } + installModules(coreModules, server.getServerDirectory().getPath()); + File modules = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_MODULES); + modules.mkdirs(); + List artifacts = properties.getModuleArtifacts(distroHelper, server.getServerDirectory()); + // install modules for each version + installModules(artifacts, modules.getPath()); + } + + public void installModules(List artifacts, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(artifacts.toArray(new Artifact[0]), outputDir, goal); + } + + public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(artifacts, outputDir, goal); + } + + public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { + final String goal = "copy"; + prepareModules(new Artifact[] { artifact }, outputDir, goal); + } + + /** + * Handle list of modules + * @param artifacts + * @param outputDir + * @param goal + * @throws MojoExecutionException + */ + private void prepareModules(Artifact[] artifacts, String outputDir, String goal) throws MojoExecutionException { + MojoExecutor.Element[] artifactItems = new MojoExecutor.Element[artifacts.length]; + for (int index = 0; index < artifacts.length; index++) { + artifactItems[index] = artifacts[index].toElement(outputDir); + } + + List configuration = new ArrayList<>(); + configuration.add(element("artifactItems", artifactItems)); + if (goal.equals(GOAL_UNPACK)) { + configuration.add(element("overWriteSnapshots", "true")); + configuration.add(element("overWriteReleases", "true")); + } + executeMojo( + plugin( + groupId(SDKConstants.DEPENDENCY_PLUGIN_GROUP_ID), + artifactId(SDKConstants.DEPENDENCY_PLUGIN_ARTIFACT_ID), + version(SDKConstants.DEPENDENCY_PLUGIN_VERSION) + ), + goal(goal), + configuration(configuration.toArray(new Element[0])), + executionEnvironment(mavenProject, mavenSession, pluginManager) + ); + } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java index 2cebb1cdb..175e9d28c 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java @@ -27,7 +27,6 @@ public class Artifact { public static final String GROUP_OPENMRS = "org.openmrs"; public static final String GROUP_H2 = "com.h2database"; public static final String GROUP_DISTRO = "org.openmrs.distro"; - public static final String GROUP_CONTENT = "org.openmrs.content"; public static final String TYPE_OMOD = "omod"; public static final String TYPE_WAR = "war"; public static final String TYPE_JAR = "jar"; diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 66f636288..a843e1337 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -1,5 +1,7 @@ package org.openmrs.maven.plugins.model; +import org.apache.commons.lang.StringUtils; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -7,366 +9,325 @@ import java.util.Properties; import java.util.Set; -import org.apache.commons.lang.StringUtils; - /** * */ public abstract class BaseSdkProperties { - - public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; - - public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; - - protected static final String ARTIFACT_ID = "artifactId"; - - protected static final String TYPE = "type"; - - protected static final String GROUP_ID = "groupId"; - - protected static final String TYPE_OMOD = "omod"; - - protected static final String TYPE_WAR = "war"; - - protected static final String TYPE_JAR = "jar"; - - protected static final String NAME = "name"; - - protected static final String VERSION = "version"; - - protected static final String TYPE_DISTRO = "distro"; - - protected static final String TYPE_OWA = "owa"; - - protected static final String TYPE_SPA = "spa"; - - protected static final String TYPE_CONFIG = "config"; - - protected static final String TYPE_CONTENT = "content"; - - protected static final String TYPE_ZIP = "zip"; - - protected Properties properties; - - public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { - Properties properties = new Properties(); - for (Artifact artifact : warArtifacts) { - - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_WAR)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - - if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); - } - - for (Artifact artifact : moduleArtifacts) { - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_JAR)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); - } - return properties; - } - - public String getPlatformVersion() { - return getParam("war.openmrs"); - } - - public void setPlatformVersion(String version) { - properties.setProperty("war.openmrs", version); - } - - public String getVersion() { - return getParam("version"); - } - - public void setVersion(String version) { - properties.setProperty("version", version); - } - - public String getName() { - return getParam("name"); - } - - public void setName(String name) { - properties.setProperty("name", name); - } - - public List getModuleArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_OMOD)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), - checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); - } - } - return artifactList; - } - - public List getOwaArtifacts() { - List artifacts = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - if (key.startsWith(TYPE_OWA + ".")) { - String artifactId = key.substring(TYPE_OWA.length() + 1); - artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_OWA, Artifact.TYPE_ZIP)); - } - } - return artifacts; - } - - public Map getSpaProperties() { - Map spaProperties = new HashMap<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - if (key.startsWith(TYPE_SPA + ".")) { - spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); - } - } - return spaProperties; - } - - public List getWarArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_WAR)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), - checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); - } - } - return artifactList; - } - + + public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; + public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; + protected static final String ARTIFACT_ID = "artifactId"; + protected static final String TYPE = "type"; + protected static final String GROUP_ID = "groupId"; + protected static final String TYPE_OMOD = "omod"; + protected static final String TYPE_WAR = "war"; + protected static final String TYPE_JAR = "jar"; + protected static final String NAME = "name"; + protected static final String VERSION = "version"; + protected static final String TYPE_DISTRO = "distro"; + protected static final String TYPE_OWA = "owa"; + protected static final String TYPE_SPA = "spa"; + protected static final String TYPE_CONFIG = "config"; + protected static final String TYPE_ZIP = "zip"; + + protected Properties properties; + + public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { + Properties properties = new Properties(); + for (Artifact artifact : warArtifacts) { + + stripArtifactId(artifact); + + if (!artifact.getType().equals(TYPE_WAR)) { + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + } + + if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + } + + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); + } + + for (Artifact artifact : moduleArtifacts) { + stripArtifactId(artifact); + + if (!artifact.getType().equals(TYPE_JAR)) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + } + if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + } + + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); + } + return properties; + } + + public String getPlatformVersion(){ + return getParam("war.openmrs"); + } + + public void setPlatformVersion(String version){ + properties.setProperty("war.openmrs", version); + } + + public String getVersion(){ + return getParam("version"); + } + + public void setVersion(String version){ + properties.setProperty("version", version); + } + + public String getName(){ + return getParam("name"); + } + + public void setName(String name){ + properties.setProperty("name", name); + } + + public List getModuleArtifacts(){ + List artifactList = new ArrayList<>(); + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if(artifactType.equals(TYPE_OMOD)) { + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); + } + } + return artifactList; + } + + public List getOwaArtifacts() { + List artifacts = new ArrayList<>(); + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_OWA + ".")) { + String artifactId = key.substring(TYPE_OWA.length() + 1); + artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_OWA, Artifact.TYPE_ZIP)); + } + } + return artifacts; + } + + public Map getSpaProperties() { + Map spaProperties = new HashMap<>(); + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_SPA + ".")) { + spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); + } + } + return spaProperties; + } + + public List getWarArtifacts(){ + List artifactList = new ArrayList<>(); + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if(artifactType.equals(TYPE_WAR)) { + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); + } + } + return artifactList; + } + public List getConfigArtifacts() { List artifactList = new ArrayList<>(); for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); if (artifactType.equals(TYPE_CONFIG)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), - checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); - } - } - return artifactList; - } - - public List getContentArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_CONTENT)) { - String artifactId = key.substring(TYPE_CONTENT.length() + 1); - System.out.println("n\n"); - System.out.println(artifactId); - System.out.println(getParam(key)); - System.out.println(Artifact.GROUP_CONTENT); - - artifactList.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); + artifactList.add( + new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), + checkIfOverwritten(key, TYPE))); } } return artifactList; } - + protected Set getAllKeys() { return properties.keySet(); } - - protected String getArtifactType(String key) { - String[] wordsArray = key.split("\\."); - if (!(wordsArray[wordsArray.length - 1].equals(TYPE) || wordsArray[wordsArray.length - 1].equals(ARTIFACT_ID) - || wordsArray[wordsArray.length - 1].equals(GROUP_ID))) { - if (key.contains(".")) { - return key.substring(0, key.indexOf(".")); - } else { - return ""; - } - } else { - return ""; - } - } - - protected String checkIfOverwritten(String key, String param) { - String newKey = key + "." + param; - if (getParam(newKey) != null) { - String setting = getParam(newKey); - if (setting.equals("referenceapplication")) { - setting = setting.concat("-"); - setting = setting.concat("package"); - } - - return setting; - } else { - switch (param) { - case ARTIFACT_ID: - return extractArtifactId(key); - case GROUP_ID: - switch (getArtifactType(key)) { - case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId - return Artifact.GROUP_WEB; - case TYPE_OMOD: - return Artifact.GROUP_MODULE; - case TYPE_DISTRO: - case TYPE_CONFIG: - return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); - default: - return ""; - } - - case TYPE: - switch (getArtifactType(key)) { - case TYPE_OMOD: - case TYPE_DISTRO: - return TYPE_JAR; - case TYPE_WAR: - return TYPE_WAR; - case TYPE_CONFIG: + + protected String getArtifactType(String key){ + String[] wordsArray = key.split("\\."); + if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){ + if(key.contains(".")){ + return key.substring(0, key.indexOf(".")); + }else { + return ""; + } + }else { + return ""; + } + } + + protected String checkIfOverwritten(String key, String param) { + String newKey = key + "." + param; + if (getParam(newKey) != null) { + String setting = getParam(newKey); + if (setting.equals("referenceapplication")) { + setting = setting.concat("-"); + setting = setting.concat("package"); + } + + return setting; + } else { + switch (param) { + case ARTIFACT_ID: + return extractArtifactId(key); + case GROUP_ID: + switch (getArtifactType(key)) { + case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId + return Artifact.GROUP_WEB; + case TYPE_OMOD: + return Artifact.GROUP_MODULE; + case TYPE_DISTRO: + case TYPE_CONFIG: + return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); + default: + return ""; + } + + case TYPE: + switch (getArtifactType(key)) { + case TYPE_OMOD: + case TYPE_DISTRO: + return TYPE_JAR; + case TYPE_WAR: + return TYPE_WAR; + case TYPE_CONFIG: return TYPE_ZIP; - default: - return ""; - } - default: - return ""; - } - } - } - - protected String extractArtifactId(String key) { - String type = getArtifactType(key); - StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); - if (type.equals(TYPE_OMOD)) { - stringBuilder.append("-"); - stringBuilder.append(type); - } else if (type.equals(TYPE_WAR)) { - stringBuilder.append("-"); - stringBuilder.append("webapp"); - } // referenceapplication exclusive parser - else if (key.equals("distro.referenceapplication")) { - stringBuilder.append("-"); - stringBuilder.append("package"); - } - - return stringBuilder.toString(); - } - - /** - * get param from properties - * - * @param key - * @return - */ - public String getParam(String key) { - return properties.getProperty(key); - } - - public Artifact getModuleArtifact(String artifactId) { - String key = TYPE_OMOD + "." + artifactId; - if (StringUtils.isNotBlank(getParam(key))) { - return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), - checkIfOverwritten(key, TYPE)); - } - return null; - } - - public void setModuleProperties(Artifact newModule) { - newModule = stripArtifactId(newModule); - if (!newModule.getGroupId().equals(Artifact.GROUP_MODULE)) { - setCustomModuleGroupId(newModule); - } - if (!newModule.getType().equals(TYPE_JAR)) { - setCustomModuleType(newModule); - } - setModule(newModule); - - } - - public void removeModuleProperties(Artifact artifact) { - artifact = stripArtifactId(artifact); - if (getModuleArtifact(artifact.getArtifactId()) != null) { - Properties newProperties = new Properties(); - newProperties.putAll(properties); - for (Object keyObject : properties.keySet()) { - String key = keyObject.toString(); - if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId())) { - newProperties.remove(key); - } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE)) { - newProperties.remove(key); - } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID)) { - newProperties.remove(key); - } - } - properties = newProperties; - } - } - - /** - * Removes `-omod` or `-webapp` suffix from artifact ID. - * - * @param artifact - * @return The same artifact, mutated - */ - private Artifact stripArtifactId(Artifact artifact) { - String artifactId = artifact.getArtifactId(); - if (artifactId.endsWith("-omod") || artifactId.endsWith("-webapp")) { - artifact.setArtifactId(artifactId.substring(0, artifactId.lastIndexOf("-"))); - } - return artifact; - } - - private void setModule(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); - } - - private void setCustomModuleType(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - - private void setCustomModuleGroupId(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - public void synchronize(BaseSdkProperties other) { - for (Object key : getAllKeys()) { - if (isBaseSdkProperty(key.toString())) { - other.properties.put(key, properties.get(key)); - } - } - for (Object key : new ArrayList<>(other.getAllKeys())) { - if (isBaseSdkProperty(key.toString())) { - if (StringUtils.isBlank(getParam(key.toString()))) { - other.properties.remove(key); - } - } - } - } - - private boolean isBaseSdkProperty(String key) { - return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); - } - - public void setArtifacts(List warArtifacts, List moduleArtifacts) { - for (Artifact moduleArtifact : moduleArtifacts) { - this.setModuleProperties(moduleArtifact); - } - for (Artifact warArtifact : warArtifacts) { - this.setPlatformVersion(warArtifact.getVersion()); - } - } - + default: + return ""; + } + default: + return ""; + } + } + } + + protected String extractArtifactId(String key){ + String type = getArtifactType(key); + StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); + if(type.equals(TYPE_OMOD)) { + stringBuilder.append("-"); + stringBuilder.append(type); + } else if(type.equals(TYPE_WAR)){ + stringBuilder.append("-"); + stringBuilder.append("webapp"); + } // referenceapplication exclusive parser + else if (key.equals("distro.referenceapplication")) { + stringBuilder.append("-"); + stringBuilder.append("package"); + } + + return stringBuilder.toString(); + } + + /** + * get param from properties + * @param key + * @return + */ + public String getParam(String key) {return properties.getProperty(key); } + + public Artifact getModuleArtifact(String artifactId){ + String key = TYPE_OMOD + "." + artifactId; + if(StringUtils.isNotBlank(getParam(key))){ + return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)); + } + return null; + } + + public void setModuleProperties(Artifact newModule) { + newModule = stripArtifactId(newModule); + if(!newModule.getGroupId().equals(Artifact.GROUP_MODULE)){ + setCustomModuleGroupId(newModule); + } + if(!newModule.getType().equals(TYPE_JAR)){ + setCustomModuleType(newModule); + } + setModule(newModule); + + } + + public void removeModuleProperties(Artifact artifact) { + artifact = stripArtifactId(artifact); + if (getModuleArtifact(artifact.getArtifactId()) != null) { + Properties newProperties = new Properties(); + newProperties.putAll(properties); + for(Object keyObject: properties.keySet()){ + String key = keyObject.toString(); + if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId())){ + newProperties.remove(key); + } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE)){ + newProperties.remove(key); + } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID)){ + newProperties.remove(key); + } + } + properties = newProperties; + } + } + + /** + * Removes `-omod` or `-webapp` suffix from artifact ID. + * + * @param artifact + * @return The same artifact, mutated + */ + private Artifact stripArtifactId(Artifact artifact) { + String artifactId = artifact.getArtifactId(); + if (artifactId.endsWith("-omod") || artifactId.endsWith("-webapp")) { + artifact.setArtifactId(artifactId.substring(0, artifactId.lastIndexOf("-"))); + } + return artifact; + } + + private void setModule(Artifact artifact) { + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId(), artifact.getVersion()); + } + + private void setCustomModuleType(Artifact artifact){ + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType()); + } + + private void setCustomModuleGroupId(Artifact artifact){ + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId()); + } + + public void synchronize(BaseSdkProperties other){ + for(Object key: getAllKeys()){ + if (isBaseSdkProperty(key.toString())) { + other.properties.put(key, properties.get(key)); + } + } + for(Object key: new ArrayList<>(other.getAllKeys())){ + if(isBaseSdkProperty(key.toString())){ + if(StringUtils.isBlank(getParam(key.toString()))){ + other.properties.remove(key); + } + } + } + } + + private boolean isBaseSdkProperty(String key) { + return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); + } + + + public void setArtifacts(List warArtifacts, List moduleArtifacts){ + for (Artifact moduleArtifact : moduleArtifacts) { + this.setModuleProperties(moduleArtifact); + } + for (Artifact warArtifact : warArtifacts) { + this.setPlatformVersion(warArtifact.getVersion()); + } + } + } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index f15ff43bd..09f1e1e53 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -3,6 +3,13 @@ import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile; import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.plugin.MojoExecutionException; +import org.openmrs.maven.plugins.utility.DistroHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -14,303 +21,274 @@ import java.util.Properties; import java.util.Set; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.openmrs.maven.plugins.utility.DistroHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * */ public class DistroProperties extends BaseSdkProperties { - - public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt"; - - private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties"; - - public static final String DISTRO_FILE_NAME = "openmrs-distro.properties"; - - private static final String DB_SQL = "db.sql"; - - public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default"; - - public static final String PROPERTY_KEY = "property.%s"; - + + public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt"; + private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties"; + public static final String DISTRO_FILE_NAME = "openmrs-distro.properties"; + private static final String DB_SQL = "db.sql"; + public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default"; + public static final String PROPERTY_KEY = "property.%s"; + private static final Logger log = LoggerFactory.getLogger(DistroProperties.class); - - public DistroProperties(String version) { - properties = new Properties(); - try { - loadPropertiesFromResource(createFileName(version), properties); - } - catch (MojoExecutionException e) { - log.error(e.getMessage(), e); - } - } - - public DistroProperties(String name, String platformVersion) { - properties = new Properties(); - setName(name); - setVersion("1.0"); // it's unclear what this means or why it is necessary, but it is tested for - setPlatformVersion(platformVersion); - } - - public DistroProperties(Properties properties) { - this.properties = properties; - } - - public DistroProperties(File file) throws MojoExecutionException { - this.properties = new Properties(); - loadPropertiesFromFile(file, this.properties); - } - - private String createFileName(String version) { - return String.format(DEAFAULT_FILE_NAME, version); - } - - public boolean isH2Supported() { - return Boolean.parseBoolean(getParam("db.h2.supported")); - } - - public void setH2Support(boolean supported) { - properties.setProperty("db.h2.supported", String.valueOf(supported)); - } - - public String getSqlScriptPath() { - return getParam(DB_SQL); - } - - public String getPropertyPrompt(String propertyName) { - return getParam(String.format(PROPERTY_PROMPT_KEY, propertyName)); - } - - public String getPropertyDefault(String propertyName) { - return getParam(String.format(PROPERTY_DEFAULT_VALUE_KEY, propertyName)); - } - - public String getPropertyValue(String propertyName) { - return getParam(String.format(PROPERTY_KEY, propertyName)); - } - - public Set getPropertiesNames() { - Set propertiesNames = new HashSet<>(); - for (Object key : getAllKeys()) { - if (key.toString().startsWith("property.")) { - propertiesNames.add(extractPropertyName(key.toString())); - } - } - return propertiesNames; - } - - private String extractPropertyName(String key) { - int beginIndex = key.indexOf("."); - if (key.endsWith(".default")) { - return key.substring(beginIndex + 1, key.length() - 8); - } else if (key.endsWith(".prompt")) { - return key.substring(beginIndex + 1, key.length() - 7); - } else { - return key.substring(beginIndex + 1); - } - } - - public Artifact getDistroArtifact() { - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_DISTRO)) { - return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), - checkIfOverwritten(key, TYPE), "jar"); - } - } - return null; - } - - public Artifact getParentArtifact() { - String parentArtifactId = getParam("parent.artifactId"); - String parentGroupId = getParam("parent.groupId"); - String parentVersion = getParam("parent.version"); - - int missingCount = 0; - if (StringUtils.isBlank(parentArtifactId)) { - log.warn("parent.artifactId missing"); - missingCount++; - } - if (StringUtils.isBlank(parentGroupId)) { - log.warn("parent.groupId is missing"); - missingCount++; - } - if (StringUtils.isBlank(parentVersion)) { - log.warn("parent.version is missing"); - missingCount++; - } - - // We are only going to throw an error if only one or two parameters are missing - if (missingCount > 0 && missingCount < 3) { - throw new IllegalArgumentException("Missing arguments for the parent"); - } - - return new Artifact(parentArtifactId, parentVersion, parentGroupId, "zip"); - } - - public List getModuleArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getModuleArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getModuleArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public List getOwaArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getOwaArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getOwaArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public List getContentArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getContentArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getContentArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public Map getSpaProperties(DistroHelper distroHelper, File directory) throws MojoExecutionException { - Map spaProperties = getSpaProperties(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - spaProperties.putAll(distroProperties.getSpaProperties(distroHelper, directory)); - } - return spaProperties; - } - - public List getWarArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getWarArtifacts(); - List parentArtifacts = new ArrayList<>(); - - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getWarArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } - - public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException { - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - return distroProperties.getPlatformVersion(distroHelper, directory); - } - return getPlatformVersion(); - } - - private List mergeArtifactLists(List childArtifacts, List parentArtifacts) { - List artifactList = new ArrayList<>(childArtifacts); - for (Artifact parentArtifact : parentArtifacts) { - boolean found = false; - for (Artifact childArtifact : childArtifacts) { - boolean isGroupIdMatch = childArtifact.getGroupId().equals(parentArtifact.getGroupId()); - boolean isArtifactIdMatch = childArtifact.getArtifactId().equals(parentArtifact.getArtifactId()); - boolean isTypeMatch = childArtifact.getType().equals(parentArtifact.getType()); - if (isGroupIdMatch && isArtifactIdMatch && isTypeMatch) { - found = true; - break; - } - } - if (!found) { - artifactList.add(parentArtifact); - } - } - return artifactList; - } - - public void saveTo(File path) throws MojoExecutionException { - FileOutputStream out = null; - try { - out = new FileOutputStream(new File(path, DISTRO_FILE_NAME)); - SortedProperties sortedProperties = new SortedProperties(); - sortedProperties.putAll(properties); - sortedProperties.store(out, null); - } - catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); - } - finally { - IOUtils.closeQuietly(out); - } - } - - public void resolvePlaceholders(Properties projectProperties) throws MojoExecutionException { - for (Map.Entry property : properties.entrySet()) { - if (hasPlaceholder(property.getValue())) { - try { - Object placeholderValue = projectProperties.get(getPlaceholderKey((String) property.getValue())); - if (placeholderValue == null) { - throw new MojoExecutionException( - "Failed to resolve property placeholders in distro file, no property for key \"" - + property.getKey() + "\""); - } else { - property.setValue(putInPlaceholder((String) property.getValue(), (String) placeholderValue)); - } - } - catch (ClassCastException e) { - throw new MojoExecutionException("Property with key \"" + property.getKey() + "\" and value \"" - + property.getValue() + "\" is not placeholder."); - } - } - } - } - - @Override - public Set getAllKeys() { - return properties.keySet(); - } - - public List getExclusions() { - String exclusions = getParam("exclusions"); - if (exclusions == null) { - return new ArrayList<>(); - } - return Arrays.asList(exclusions.split(",")); - } - - private String getPlaceholderKey(String string) { - int startIndex = string.indexOf("${") + 2; - int endIndex = string.indexOf("}", startIndex); - return string.substring(startIndex, endIndex); - } - - private String putInPlaceholder(String value, String placeholderValue) { - return value.replace("${" + getPlaceholderKey(value) + "}", placeholderValue); - } - - private boolean hasPlaceholder(Object object) { - String asString; - try { - asString = (String) object; - } - catch (ClassCastException e) { - return false; - } - int index = asString.indexOf("{"); - return index != -1 && asString.substring(index).contains("}"); - } + + public DistroProperties(String version){ + properties = new Properties(); + try { + loadPropertiesFromResource(createFileName(version), properties); + } catch (MojoExecutionException e) { + log.error(e.getMessage(), e); + } + } + + public DistroProperties(String name, String platformVersion){ + properties = new Properties(); + setName(name); + setVersion("1.0"); // it's unclear what this means or why it is necessary, but it is tested for + setPlatformVersion(platformVersion); + } + + public DistroProperties(Properties properties){ + this.properties = properties; + } + + public DistroProperties(File file) throws MojoExecutionException{ + this.properties = new Properties(); + loadPropertiesFromFile(file, this.properties); + } + + private String createFileName(String version){ + return String.format(DEAFAULT_FILE_NAME, version); + } + + public boolean isH2Supported(){ + return Boolean.parseBoolean(getParam("db.h2.supported")); + } + + public void setH2Support(boolean supported) { + properties.setProperty("db.h2.supported", String.valueOf(supported)); + } + + public String getSqlScriptPath() { + return getParam(DB_SQL); + } + + public String getPropertyPrompt(String propertyName){ + return getParam(String.format(PROPERTY_PROMPT_KEY, propertyName)); + } + + public String getPropertyDefault(String propertyName){ + return getParam(String.format(PROPERTY_DEFAULT_VALUE_KEY, propertyName)); + } + + public String getPropertyValue(String propertyName){ + return getParam(String.format(PROPERTY_KEY, propertyName)); + } + + public Set getPropertiesNames(){ + Set propertiesNames = new HashSet<>(); + for(Object key: getAllKeys()){ + if(key.toString().startsWith("property.")){ + propertiesNames.add(extractPropertyName(key.toString())); + } + } + return propertiesNames; + } + + private String extractPropertyName(String key) { + int beginIndex = key.indexOf("."); + if(key.endsWith(".default")){ + return key.substring(beginIndex+1, key.length()-8); + } else if(key.endsWith(".prompt")){ + return key.substring(beginIndex+1, key.length()-7); + } else { + return key.substring(beginIndex+1); + } + } + + public Artifact getDistroArtifact() { + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if(artifactType.equals(TYPE_DISTRO)) { + return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "jar"); + } + } + return null; + } + + public Artifact getParentArtifact() { + String parentArtifactId = getParam("parent.artifactId"); + String parentGroupId = getParam("parent.groupId"); + String parentVersion = getParam("parent.version"); + + int missingCount = 0; + if (StringUtils.isBlank(parentArtifactId)) { + log.warn("parent.artifactId missing"); + missingCount++; + } + if (StringUtils.isBlank(parentGroupId)) { + log.warn("parent.groupId is missing"); + missingCount++; + } + if (StringUtils.isBlank(parentVersion)) { + log.warn("parent.version is missing"); + missingCount++; + } + + // We are only going to throw an error if only one or two parameters are missing + if (missingCount > 0 && missingCount < 3) { + throw new IllegalArgumentException("Missing arguments for the parent"); + } + + return new Artifact(parentArtifactId, parentVersion, parentGroupId, "zip"); + } + + public List getModuleArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getModuleArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getModuleArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public List getOwaArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getOwaArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getOwaArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public Map getSpaProperties(DistroHelper distroHelper, File directory) throws MojoExecutionException { + Map spaProperties = getSpaProperties(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + spaProperties.putAll(distroProperties.getSpaProperties(distroHelper, directory)); + } + return spaProperties; + } + + public List getWarArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException{ + List childArtifacts = getWarArtifacts(); + List parentArtifacts = new ArrayList<>(); + + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getWarArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } + + public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException{ + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + return distroProperties.getPlatformVersion(distroHelper, directory); + } + return getPlatformVersion(); + } + + private List mergeArtifactLists(List childArtifacts, List parentArtifacts) { + List artifactList = new ArrayList<>(childArtifacts); + for (Artifact parentArtifact : parentArtifacts) { + boolean found = false; + for (Artifact childArtifact : childArtifacts) { + boolean isGroupIdMatch = childArtifact.getGroupId().equals(parentArtifact.getGroupId()); + boolean isArtifactIdMatch = childArtifact.getArtifactId().equals(parentArtifact.getArtifactId()); + boolean isTypeMatch = childArtifact.getType().equals(parentArtifact.getType()); + if (isGroupIdMatch && isArtifactIdMatch && isTypeMatch) { + found = true; + break; + } + } + if (!found) { + artifactList.add(parentArtifact); + } + } + return artifactList; + } + + public void saveTo(File path) throws MojoExecutionException { + FileOutputStream out = null; + try { + out = new FileOutputStream(new File(path, DISTRO_FILE_NAME)); + SortedProperties sortedProperties = new SortedProperties(); + sortedProperties.putAll(properties); + sortedProperties.store(out, null); + } + catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + finally { + IOUtils.closeQuietly(out); + } + } + + public void resolvePlaceholders(Properties projectProperties) throws MojoExecutionException { + for(Map.Entry property: properties.entrySet()){ + if(hasPlaceholder(property.getValue())){ + try{ + Object placeholderValue = projectProperties.get(getPlaceholderKey((String)property.getValue())); + if(placeholderValue == null){ + throw new MojoExecutionException( + "Failed to resolve property placeholders in distro file, no property for key \"" + + property.getKey() + "\""); + } else { + property.setValue(putInPlaceholder((String)property.getValue(), (String)placeholderValue)); + } + } catch (ClassCastException e){ + throw new MojoExecutionException("Property with key \"" + property.getKey() + "\" and value \"" + + property.getValue() + "\" is not placeholder."); + } + } + } + } + + public Set getAllKeys() { + return properties.keySet(); + } + + public List getExclusions() { + String exclusions = getParam("exclusions"); + if(exclusions == null) { + return new ArrayList<>(); + } + return Arrays.asList(exclusions.split(",")); + } + + private String getPlaceholderKey(String string){ + int startIndex = string.indexOf("${")+2; + int endIndex = string.indexOf("}", startIndex); + return string.substring(startIndex, endIndex); + } + + private String putInPlaceholder(String value, String placeholderValue) { + return value.replace("${"+getPlaceholderKey(value)+"}", placeholderValue); + } + + private boolean hasPlaceholder(Object object){ + String asString; + try{ + asString = (String) object; + } catch(ClassCastException e){ + return false; + } + int index = asString.indexOf("{"); + return index != -1 && asString.substring(index).contains("}"); + } } From 024cffc5727d71a56c49670c981f3794f4151cbb Mon Sep 17 00:00:00 2001 From: nravilla Date: Mon, 26 Aug 2024 22:41:21 -0400 Subject: [PATCH 03/31] To handle content packages --- .../openmrs/maven/plugins/AbstractTask.java | 62 +++-- .../openmrs/maven/plugins/BuildDistro.java | 26 +- .../java/org/openmrs/maven/plugins/Setup.java | 24 ++ .../maven/plugins/utility/ContentHelper.java | 88 +++++++ .../plugins/utility/ModuleInstaller.java | 5 + .../openmrs/maven/plugins/model/Artifact.java | 1 + .../plugins/model/BaseSdkProperties.java | 244 +++++++++--------- .../maven/plugins/model/DistroProperties.java | 14 +- 8 files changed, 316 insertions(+), 148 deletions(-) create mode 100644 maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 61a397758..daf3c3395 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -22,6 +22,7 @@ import org.openmrs.maven.plugins.utility.ModuleInstaller; import org.openmrs.maven.plugins.utility.NodeHelper; import org.openmrs.maven.plugins.utility.OwaHelper; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.SpaInstaller; import org.openmrs.maven.plugins.utility.StatsManager; import org.openmrs.maven.plugins.utility.VersionsHelper; @@ -113,6 +114,11 @@ public abstract class AbstractTask extends AbstractMojo { * handles OWAs */ OwaHelper owaHelper; + + /** + * handles Contents + */ + ContentHelper contentHelper; /** * installs SPAs @@ -137,26 +143,27 @@ public abstract class AbstractTask extends AbstractMojo { public AbstractTask() { } - public AbstractTask(AbstractTask other) { - this.mavenProject = other.mavenProject; - this.mavenSession = other.mavenSession; - this.wizard = other.wizard; - this.pluginManager = other.pluginManager; - this.artifactFactory = other.artifactFactory; - this.artifactMetadataSource = other.artifactMetadataSource; - this.moduleInstaller = other.moduleInstaller; - this.versionsHelper = other.versionsHelper; - this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; - this.spaInstaller = other.spaInstaller; - this.gitHelper = other.gitHelper; - this.dockerHelper = other.dockerHelper; - this.settings = other.settings; - this.batchAnswers = other.batchAnswers; - this.testMode = other.testMode; - this.openMRSPath = other.openMRSPath; - this.stats = other.stats; - initTask(); + public AbstractTask(AbstractTask other) { + this.mavenProject = other.mavenProject; + this.mavenSession = other.mavenSession; + this.wizard = other.wizard; + this.pluginManager = other.pluginManager; + this.artifactFactory = other.artifactFactory; + this.artifactMetadataSource = other.artifactMetadataSource; + this.moduleInstaller = other.moduleInstaller; + this.versionsHelper = other.versionsHelper; + this.distroHelper = other.distroHelper; + this.owaHelper = other.owaHelper; + this.contentHelper = other.contentHelper; + this.spaInstaller = other.spaInstaller; + this.gitHelper = other.gitHelper; + this.dockerHelper = other.dockerHelper; + this.settings = other.settings; + this.batchAnswers = other.batchAnswers; + this.testMode = other.testMode; + this.openMRSPath = other.openMRSPath; + this.stats = other.stats; + initTask(); } public void initTask() { @@ -175,12 +182,15 @@ public void initTask() { if (distroHelper == null) { distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard, versionsHelper); } - if (owaHelper == null) { - owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } - if (spaInstaller == null) { - spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); - } + if (owaHelper == null) { + owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); + } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); + } + if (spaInstaller == null) { + spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); + } if (dockerHelper == null) { dockerHelper = new DockerHelper(mavenProject, mavenSession, pluginManager, wizard); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index e609621b3..abe72daf7 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -296,7 +296,9 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - + + //TODO: does this flow need this? + //downloadContents(targetDirectory, distroProperties); spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); if(frontendDir.exists()) { @@ -323,10 +325,10 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File frontendDir = new File(web, "frontend"); frontendDir.mkdir(); - File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); - configDir.mkdir(); - setConfigFolder(configDir, distroProperties, distroArtifact); - + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); + configDir.mkdir(); + setConfigFolder(configDir, distroProperties, distroArtifact); + downloadContents(configDir, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); @@ -604,4 +606,18 @@ public boolean accept(File dir, String name) { } } } + + private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { + File targetDirectory = new File(configDir, "temp_content"); + targetDirectory.mkdir(); + + List contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory); + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller); + } + } + FileUtils.deleteQuietly(targetDirectory); + } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 00b23e95a..2593a7635 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -278,6 +278,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); + installContents(server, distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } @@ -693,4 +694,27 @@ private String getUriWithoutDb(Server server) { uri = uri.substring(0, uri.lastIndexOf("/") + 1); return uri; } + + private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + if (distroProperties != null) { + File tempContentDir = new File(server.getServerDirectory(), "temp-content"); + tempContentDir.mkdir(); + downloadContents(server, distroProperties, tempContentDir); + FileUtils.deleteQuietly(tempContentDir); + } + } + + private void downloadContents(Server server, DistroProperties distroProperties, File tempContentDir) + throws MojoExecutionException { + List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); + //Configuration dir gets created before this method is called + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); + + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(configDir, tempContentDir, content, moduleInstaller); + } + } + } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java new file mode 100644 index 000000000..fd1a1f78b --- /dev/null +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -0,0 +1,88 @@ +package org.openmrs.maven.plugins.utility; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.openmrs.maven.plugins.model.Artifact; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ContentHelper { + + private final MavenSession session; + private final BuildPluginManager pluginManager; + private final MavenProject mavenProject; + private static final Logger logger = LoggerFactory.getLogger(ContentHelper.class); + + public ContentHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager) { + this.session = session; + this.mavenProject = mavenProject; + this.pluginManager = pluginManager; + } + + public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact, + ModuleInstaller moduleInstaller) throws MojoExecutionException { + + String artifactId = contentArtifact.getArtifactId(); + File contentDir = new File(tempContentDir, artifactId); + + moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); + moveBackendConfig(contentDir, configurationDir, artifactId); + } + + private void moveBackendConfig(File inputDir, File configurationDir, String artifactId) throws MojoExecutionException { + + if (!inputDir.isDirectory() || !configurationDir.isDirectory()) { + throw new MojoExecutionException("Both inputDir and configurationDir must be valid directories."); + } + + File backendConfigs = new File(inputDir, "configs" + File.separator + "backend_config"); + + if (backendConfigs.listFiles() == null || backendConfigs.listFiles().length == 0) { + throw new MojoExecutionException("No directories to process under content configuration directories"); + } + + for (File backendConfig : backendConfigs.listFiles()) { + // Find a corresponding directory in the configurationDir with the same name as backendConfig + File matchingConfigurationDir = new File(configurationDir, backendConfig.getName()); + + File artifactDir; + 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(); + } + } + copyDirectory(backendConfig, artifactDir); + } + } + + private void copyDirectory(File sourceDir, File destDir) throws MojoExecutionException { + try { + if (!destDir.exists()) { + destDir.mkdirs(); + } + + for (File file : sourceDir.listFiles()) { + File destFile = new File(destDir, file.getName()); + if (file.isDirectory()) { + copyDirectory(file, destFile); + } else { + Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + } +} diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index c72e9527c..e7cc8549c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -87,6 +87,11 @@ public void installModule(Artifact artifact, String outputDir) throws MojoExecut final String goal = "copy"; prepareModules(new Artifact[] { artifact }, outputDir, goal); } + + public void installUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { + final String goal = GOAL_UNPACK; + prepareModules(new Artifact[] { artifact }, outputDir, goal); + } /** * Handle list of modules diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java index 175e9d28c..5253065fb 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java @@ -25,6 +25,7 @@ public class Artifact { public static final String GROUP_OWA = "org.openmrs.owa"; public static final String GROUP_WEB = "org.openmrs.web"; public static final String GROUP_OPENMRS = "org.openmrs"; + public static final String GROUP_CONTENT = "org.openmrs.content"; public static final String GROUP_H2 = "com.h2database"; public static final String GROUP_DISTRO = "org.openmrs.distro"; public static final String TYPE_OMOD = "omod"; diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index a843e1337..fe1b400e7 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -13,7 +13,7 @@ * */ public abstract class BaseSdkProperties { - + public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; protected static final String ARTIFACT_ID = "artifactId"; @@ -28,81 +28,82 @@ public abstract class BaseSdkProperties { protected static final String TYPE_OWA = "owa"; protected static final String TYPE_SPA = "spa"; protected static final String TYPE_CONFIG = "config"; + protected static final String TYPE_CONTENT = "content"; protected static final String TYPE_ZIP = "zip"; - + protected Properties properties; - + public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { Properties properties = new Properties(); for (Artifact artifact : warArtifacts) { - + stripArtifactId(artifact); - + if (!artifact.getType().equals(TYPE_WAR)) { properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); } - + if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); } - + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); } - + for (Artifact artifact : moduleArtifacts) { stripArtifactId(artifact); - + if (!artifact.getType().equals(TYPE_JAR)) { properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); } if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); } - + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); } return properties; } - - public String getPlatformVersion(){ + + public String getPlatformVersion() { return getParam("war.openmrs"); } - - public void setPlatformVersion(String version){ + + public void setPlatformVersion(String version) { properties.setProperty("war.openmrs", version); } - - public String getVersion(){ + + public String getVersion() { return getParam("version"); } - - public void setVersion(String version){ + + public void setVersion(String version) { properties.setProperty("version", version); } - - public String getName(){ + + public String getName() { return getParam("name"); } - - public void setName(String name){ + + public void setName(String name) { properties.setProperty("name", name); } - - public List getModuleArtifacts(){ + + public List getModuleArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { + for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); - if(artifactType.equals(TYPE_OMOD)) { + if (artifactType.equals(TYPE_OMOD)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); } } - return artifactList; + return artifactList; } - + public List getOwaArtifacts() { List artifacts = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { + for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); if (key.startsWith(TYPE_OWA + ".")) { String artifactId = key.substring(TYPE_OWA.length() + 1); @@ -111,10 +112,10 @@ public List getOwaArtifacts() { } return artifacts; } - + public Map getSpaProperties() { Map spaProperties = new HashMap<>(); - for (Object keyObject: getAllKeys()) { + for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); if (key.startsWith(TYPE_SPA + ".")) { spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); @@ -122,50 +123,61 @@ public Map getSpaProperties() { } return spaProperties; } - - public List getWarArtifacts(){ + + public List getWarArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { + for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); - if(artifactType.equals(TYPE_WAR)) { + if (artifactType.equals(TYPE_WAR)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); } } - return artifactList; + return artifactList; } - - public List getConfigArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_CONFIG)) { - artifactList.add( - new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), - checkIfOverwritten(key, TYPE))); - } - } - return artifactList; - } - - protected Set getAllKeys() { - return properties.keySet(); - } - - protected String getArtifactType(String key){ + + public List getConfigArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONFIG)) { + artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); + } + } + return artifactList; + } + + public List getContentArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONTENT)) { + String artifactId = key.substring(TYPE_CONTENT.length() + 1); + artifactList.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); + } + } + return artifactList; + } + + protected Set getAllKeys() { + return properties.keySet(); + } + + protected String getArtifactType(String key) { String[] wordsArray = key.split("\\."); - if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){ - if(key.contains(".")){ + if (!(wordsArray[wordsArray.length - 1].equals(TYPE) || wordsArray[wordsArray.length - 1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length - 1].equals(GROUP_ID))) { + if (key.contains(".")) { return key.substring(0, key.indexOf(".")); - }else { + } else { return ""; } - }else { + } else { return ""; } } - + protected String checkIfOverwritten(String key, String param) { String newKey = key + "." + param; if (getParam(newKey) != null) { @@ -174,50 +186,50 @@ protected String checkIfOverwritten(String key, String param) { setting = setting.concat("-"); setting = setting.concat("package"); } - + return setting; } else { - switch (param) { - case ARTIFACT_ID: - return extractArtifactId(key); - case GROUP_ID: + switch (param) { + case ARTIFACT_ID: + return extractArtifactId(key); + case GROUP_ID: switch (getArtifactType(key)) { - case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId + case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId return Artifact.GROUP_WEB; case TYPE_OMOD: return Artifact.GROUP_MODULE; case TYPE_DISTRO: - case TYPE_CONFIG: + case TYPE_CONFIG: return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); default: return ""; } - - case TYPE: + + case TYPE: switch (getArtifactType(key)) { case TYPE_OMOD: case TYPE_DISTRO: return TYPE_JAR; case TYPE_WAR: return TYPE_WAR; - case TYPE_CONFIG: - return TYPE_ZIP; + case TYPE_CONFIG: + return TYPE_ZIP; default: return ""; } - default: - return ""; - } + default: + return ""; + } } } - - protected String extractArtifactId(String key){ + + protected String extractArtifactId(String key) { String type = getArtifactType(key); StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); - if(type.equals(TYPE_OMOD)) { + if (type.equals(TYPE_OMOD)) { stringBuilder.append("-"); stringBuilder.append(type); - } else if(type.equals(TYPE_WAR)){ + } else if (type.equals(TYPE_WAR)) { stringBuilder.append("-"); stringBuilder.append("webapp"); } // referenceapplication exclusive parser @@ -225,56 +237,56 @@ else if (key.equals("distro.referenceapplication")) { stringBuilder.append("-"); stringBuilder.append("package"); } - - return stringBuilder.toString(); + + return stringBuilder.toString(); } - + /** * get param from properties * @param key * @return */ - public String getParam(String key) {return properties.getProperty(key); } - - public Artifact getModuleArtifact(String artifactId){ + public String getParam(String key) {return properties.getProperty(key);} + + public Artifact getModuleArtifact(String artifactId) { String key = TYPE_OMOD + "." + artifactId; - if(StringUtils.isNotBlank(getParam(key))){ + if (StringUtils.isNotBlank(getParam(key))) { return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)); } return null; } - + public void setModuleProperties(Artifact newModule) { newModule = stripArtifactId(newModule); - if(!newModule.getGroupId().equals(Artifact.GROUP_MODULE)){ + if (!newModule.getGroupId().equals(Artifact.GROUP_MODULE)) { setCustomModuleGroupId(newModule); } - if(!newModule.getType().equals(TYPE_JAR)){ + if (!newModule.getType().equals(TYPE_JAR)) { setCustomModuleType(newModule); } setModule(newModule); - + } - + public void removeModuleProperties(Artifact artifact) { artifact = stripArtifactId(artifact); if (getModuleArtifact(artifact.getArtifactId()) != null) { Properties newProperties = new Properties(); newProperties.putAll(properties); - for(Object keyObject: properties.keySet()){ + for (Object keyObject : properties.keySet()) { String key = keyObject.toString(); - if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId())){ + if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId())) { newProperties.remove(key); - } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE)){ + } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE)) { newProperties.remove(key); - } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID)){ + } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID)) { newProperties.remove(key); } } properties = newProperties; } } - + /** * Removes `-omod` or `-webapp` suffix from artifact ID. * @@ -288,40 +300,40 @@ private Artifact stripArtifactId(Artifact artifact) { } return artifact; } - + private void setModule(Artifact artifact) { - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId(), artifact.getVersion()); + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); } - - private void setCustomModuleType(Artifact artifact){ - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType()); + + private void setCustomModuleType(Artifact artifact) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); } - - private void setCustomModuleGroupId(Artifact artifact){ - properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId()); + + private void setCustomModuleGroupId(Artifact artifact) { + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); } - - public void synchronize(BaseSdkProperties other){ - for(Object key: getAllKeys()){ + + public void synchronize(BaseSdkProperties other) { + for (Object key : getAllKeys()) { if (isBaseSdkProperty(key.toString())) { other.properties.put(key, properties.get(key)); } } - for(Object key: new ArrayList<>(other.getAllKeys())){ - if(isBaseSdkProperty(key.toString())){ - if(StringUtils.isBlank(getParam(key.toString()))){ + for (Object key : new ArrayList<>(other.getAllKeys())) { + if (isBaseSdkProperty(key.toString())) { + if (StringUtils.isBlank(getParam(key.toString()))) { other.properties.remove(key); } } } } - + private boolean isBaseSdkProperty(String key) { - return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); + return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); } - - - public void setArtifacts(List warArtifacts, List moduleArtifacts){ + + + public void setArtifacts(List warArtifacts, List moduleArtifacts) { for (Artifact moduleArtifact : moduleArtifacts) { this.setModuleProperties(moduleArtifact); } @@ -329,5 +341,5 @@ public void setArtifacts(List warArtifacts, List moduleArtif this.setPlatformVersion(warArtifact.getVersion()); } } - + } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index 09f1e1e53..70e290271 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -193,6 +193,17 @@ public List getWarArtifacts(DistroHelper distroHelper, File directory) } return mergeArtifactLists(childArtifacts, parentArtifacts); } + + public List getContentArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { + List childArtifacts = getContentArtifacts(); + List parentArtifacts = new ArrayList<>(); + Artifact artifact = getDistroArtifact(); + if (artifact != null) { + DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); + parentArtifacts.addAll(distroProperties.getContentArtifacts(distroHelper, directory)); + } + return mergeArtifactLists(childArtifacts, parentArtifacts); + } public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException{ Artifact artifact = getDistroArtifact(); @@ -259,7 +270,8 @@ public void resolvePlaceholders(Properties projectProperties) throws MojoExecuti } } - public Set getAllKeys() { + @Override + public Set getAllKeys() { return properties.keySet(); } From 605240440f5212d03b873f9aee72fe9dbf9b4ced Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 07:33:54 -0400 Subject: [PATCH 04/31] Formatting fix --- .../openmrs/maven/plugins/AbstractTask.java | 148 +++---- sdk-commons/.classpath | 32 ++ sdk-commons/.project | 23 + .../org.eclipse.core.resources.prefs | 5 + .../.settings/org.eclipse.jdt.core.prefs | 403 ++++++++++++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 2 + .../.settings/org.eclipse.m2e.core.prefs | 4 + 7 files changed, 543 insertions(+), 74 deletions(-) create mode 100644 sdk-commons/.classpath create mode 100644 sdk-commons/.project create mode 100644 sdk-commons/.settings/org.eclipse.core.resources.prefs create mode 100644 sdk-commons/.settings/org.eclipse.jdt.core.prefs create mode 100644 sdk-commons/.settings/org.eclipse.jdt.ui.prefs create mode 100644 sdk-commons/.settings/org.eclipse.m2e.core.prefs diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index daf3c3395..57229bed7 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -34,138 +34,138 @@ * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ OwaHelper owaHelper; - /** - * handles Contents - */ - ContentHelper contentHelper; - + /** + * handles Contents + */ + ContentHelper contentHelper; + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - - public AbstractTask(AbstractTask other) { - this.mavenProject = other.mavenProject; - this.mavenSession = other.mavenSession; - this.wizard = other.wizard; - this.pluginManager = other.pluginManager; - this.artifactFactory = other.artifactFactory; - this.artifactMetadataSource = other.artifactMetadataSource; - this.moduleInstaller = other.moduleInstaller; - this.versionsHelper = other.versionsHelper; - this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; - this.contentHelper = other.contentHelper; - this.spaInstaller = other.spaInstaller; - this.gitHelper = other.gitHelper; - this.dockerHelper = other.dockerHelper; - this.settings = other.settings; - this.batchAnswers = other.batchAnswers; - this.testMode = other.testMode; - this.openMRSPath = other.openMRSPath; - this.stats = other.stats; - initTask(); + + public AbstractTask(AbstractTask other) { + this.mavenProject = other.mavenProject; + this.mavenSession = other.mavenSession; + this.wizard = other.wizard; + this.pluginManager = other.pluginManager; + this.artifactFactory = other.artifactFactory; + this.artifactMetadataSource = other.artifactMetadataSource; + this.moduleInstaller = other.moduleInstaller; + this.versionsHelper = other.versionsHelper; + this.distroHelper = other.distroHelper; + this.owaHelper = other.owaHelper; + this.contentHelper = other.contentHelper; + this.spaInstaller = other.spaInstaller; + this.gitHelper = other.gitHelper; + this.dockerHelper = other.dockerHelper; + this.settings = other.settings; + this.batchAnswers = other.batchAnswers; + this.testMode = other.testMode; + this.openMRSPath = other.openMRSPath; + this.stats = other.stats; + initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -182,34 +182,34 @@ public void initTask() { if (distroHelper == null) { distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard, versionsHelper); } - if (owaHelper == null) { - owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } - if (contentHelper == null) { - contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); - } - if (spaInstaller == null) { - spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); - } + if (owaHelper == null) { + owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); + } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); + } + if (spaInstaller == null) { + spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); + } if (dockerHelper == null) { dockerHelper = new DockerHelper(mavenProject, mavenSession, pluginManager, wizard); } if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } diff --git a/sdk-commons/.classpath b/sdk-commons/.classpath new file mode 100644 index 000000000..a5d95095c --- /dev/null +++ b/sdk-commons/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk-commons/.project b/sdk-commons/.project new file mode 100644 index 000000000..cbb5e32cf --- /dev/null +++ b/sdk-commons/.project @@ -0,0 +1,23 @@ + + + sdk-commons + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/sdk-commons/.settings/org.eclipse.core.resources.prefs b/sdk-commons/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..839d647ee --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/sdk-commons/.settings/org.eclipse.jdt.core.prefs b/sdk-commons/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..5d8d13b29 --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,403 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false +org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 +org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false +org.eclipse.jdt.core.formatter.align_with_spaces=false +org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=0 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=48 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=20 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=19 +org.eclipse.jdt.core.formatter.alignment_for_assertion_message=0 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=0 +org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=20 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_record_components=20 +org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0 +org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=48 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=0 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0 +org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0 +org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false +org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=true +org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=false +org.eclipse.jdt.core.formatter.comment.format_source_code=false +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.indent_tag_description=false +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert +org.eclipse.jdt.core.formatter.comment.line_length=100 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert +org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false +org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_if_empty +org.eclipse.jdt.core.formatter.lineSplit=125 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=space +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.text_block_indentation=0 +org.eclipse.jdt.core.formatter.use_on_off_tags=true +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true +org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true +org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true +org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false +org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true +org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true +org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true +org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true +org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true +org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true +org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true +org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/sdk-commons/.settings/org.eclipse.jdt.ui.prefs b/sdk-commons/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 000000000..f7eb4c48f --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +formatter_settings_version=22 diff --git a/sdk-commons/.settings/org.eclipse.m2e.core.prefs b/sdk-commons/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 000000000..f897a7f1c --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 From 05e7edf981940ddf637e42fa29f38901f089f896 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 07:35:18 -0400 Subject: [PATCH 05/31] Revert "Formatting fix" This reverts commit 605240440f5212d03b873f9aee72fe9dbf9b4ced. --- .../openmrs/maven/plugins/AbstractTask.java | 148 +++---- sdk-commons/.classpath | 32 -- sdk-commons/.project | 23 - .../org.eclipse.core.resources.prefs | 5 - .../.settings/org.eclipse.jdt.core.prefs | 403 ------------------ .../.settings/org.eclipse.jdt.ui.prefs | 2 - .../.settings/org.eclipse.m2e.core.prefs | 4 - 7 files changed, 74 insertions(+), 543 deletions(-) delete mode 100644 sdk-commons/.classpath delete mode 100644 sdk-commons/.project delete mode 100644 sdk-commons/.settings/org.eclipse.core.resources.prefs delete mode 100644 sdk-commons/.settings/org.eclipse.jdt.core.prefs delete mode 100644 sdk-commons/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 sdk-commons/.settings/org.eclipse.m2e.core.prefs diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 57229bed7..daf3c3395 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -34,138 +34,138 @@ * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ OwaHelper owaHelper; - /** - * handles Contents - */ - ContentHelper contentHelper; - + /** + * handles Contents + */ + ContentHelper contentHelper; + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - - public AbstractTask(AbstractTask other) { - this.mavenProject = other.mavenProject; - this.mavenSession = other.mavenSession; - this.wizard = other.wizard; - this.pluginManager = other.pluginManager; - this.artifactFactory = other.artifactFactory; - this.artifactMetadataSource = other.artifactMetadataSource; - this.moduleInstaller = other.moduleInstaller; - this.versionsHelper = other.versionsHelper; - this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; - this.contentHelper = other.contentHelper; - this.spaInstaller = other.spaInstaller; - this.gitHelper = other.gitHelper; - this.dockerHelper = other.dockerHelper; - this.settings = other.settings; - this.batchAnswers = other.batchAnswers; - this.testMode = other.testMode; - this.openMRSPath = other.openMRSPath; - this.stats = other.stats; - initTask(); + + public AbstractTask(AbstractTask other) { + this.mavenProject = other.mavenProject; + this.mavenSession = other.mavenSession; + this.wizard = other.wizard; + this.pluginManager = other.pluginManager; + this.artifactFactory = other.artifactFactory; + this.artifactMetadataSource = other.artifactMetadataSource; + this.moduleInstaller = other.moduleInstaller; + this.versionsHelper = other.versionsHelper; + this.distroHelper = other.distroHelper; + this.owaHelper = other.owaHelper; + this.contentHelper = other.contentHelper; + this.spaInstaller = other.spaInstaller; + this.gitHelper = other.gitHelper; + this.dockerHelper = other.dockerHelper; + this.settings = other.settings; + this.batchAnswers = other.batchAnswers; + this.testMode = other.testMode; + this.openMRSPath = other.openMRSPath; + this.stats = other.stats; + initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -182,34 +182,34 @@ public void initTask() { if (distroHelper == null) { distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard, versionsHelper); } - if (owaHelper == null) { - owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } - if (contentHelper == null) { - contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); - } - if (spaInstaller == null) { - spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); - } + if (owaHelper == null) { + owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); + } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); + } + if (spaInstaller == null) { + spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); + } if (dockerHelper == null) { dockerHelper = new DockerHelper(mavenProject, mavenSession, pluginManager, wizard); } if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } diff --git a/sdk-commons/.classpath b/sdk-commons/.classpath deleted file mode 100644 index a5d95095c..000000000 --- a/sdk-commons/.classpath +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk-commons/.project b/sdk-commons/.project deleted file mode 100644 index cbb5e32cf..000000000 --- a/sdk-commons/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - sdk-commons - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/sdk-commons/.settings/org.eclipse.core.resources.prefs b/sdk-commons/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 839d647ee..000000000 --- a/sdk-commons/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/main/resources=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/sdk-commons/.settings/org.eclipse.jdt.core.prefs b/sdk-commons/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 5d8d13b29..000000000 --- a/sdk-commons/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,403 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 -org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false -org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 -org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false -org.eclipse.jdt.core.formatter.align_with_spaces=false -org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=0 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0 -org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=48 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=20 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=19 -org.eclipse.jdt.core.formatter.alignment_for_assertion_message=0 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=0 -org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 -org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 -org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16 -org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=20 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_record_components=20 -org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 -org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0 -org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=0 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=48 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=0 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=0 -org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=0 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0 -org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0 -org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0 -org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=1 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false -org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=true -org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=false -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=false -org.eclipse.jdt.core.formatter.comment.format_source_code=false -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.indent_tag_description=false -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert -org.eclipse.jdt.core.formatter.comment.line_length=100 -org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true -org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true -org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off -org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true -org.eclipse.jdt.core.formatter.indentation.size=4 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert -org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert -org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert -org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert -org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.join_lines_in_comments=true -org.eclipse.jdt.core.formatter.join_wrapped_lines=true -org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never -org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never -org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false -org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false -org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false -org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false -org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never -org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_if_empty -org.eclipse.jdt.core.formatter.lineSplit=125 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0 -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0 -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0 -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines -org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=space -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.text_block_indentation=0 -org.eclipse.jdt.core.formatter.use_on_off_tags=true -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=true -org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true -org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true -org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false -org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true -org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true -org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true -org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true -org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true -org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true -org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true -org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true -org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false -org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true -org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter diff --git a/sdk-commons/.settings/org.eclipse.jdt.ui.prefs b/sdk-commons/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index f7eb4c48f..000000000 --- a/sdk-commons/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -formatter_settings_version=22 diff --git a/sdk-commons/.settings/org.eclipse.m2e.core.prefs b/sdk-commons/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1c..000000000 --- a/sdk-commons/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 From e46fcac2659051e07c77304bc0dc1ec5da0ea599 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 07:37:34 -0400 Subject: [PATCH 06/31] Formatting fix --- .../openmrs/maven/plugins/AbstractTask.java | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index daf3c3395..57229bed7 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -34,138 +34,138 @@ * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ OwaHelper owaHelper; - /** - * handles Contents - */ - ContentHelper contentHelper; - + /** + * handles Contents + */ + ContentHelper contentHelper; + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - - public AbstractTask(AbstractTask other) { - this.mavenProject = other.mavenProject; - this.mavenSession = other.mavenSession; - this.wizard = other.wizard; - this.pluginManager = other.pluginManager; - this.artifactFactory = other.artifactFactory; - this.artifactMetadataSource = other.artifactMetadataSource; - this.moduleInstaller = other.moduleInstaller; - this.versionsHelper = other.versionsHelper; - this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; - this.contentHelper = other.contentHelper; - this.spaInstaller = other.spaInstaller; - this.gitHelper = other.gitHelper; - this.dockerHelper = other.dockerHelper; - this.settings = other.settings; - this.batchAnswers = other.batchAnswers; - this.testMode = other.testMode; - this.openMRSPath = other.openMRSPath; - this.stats = other.stats; - initTask(); + + public AbstractTask(AbstractTask other) { + this.mavenProject = other.mavenProject; + this.mavenSession = other.mavenSession; + this.wizard = other.wizard; + this.pluginManager = other.pluginManager; + this.artifactFactory = other.artifactFactory; + this.artifactMetadataSource = other.artifactMetadataSource; + this.moduleInstaller = other.moduleInstaller; + this.versionsHelper = other.versionsHelper; + this.distroHelper = other.distroHelper; + this.owaHelper = other.owaHelper; + this.contentHelper = other.contentHelper; + this.spaInstaller = other.spaInstaller; + this.gitHelper = other.gitHelper; + this.dockerHelper = other.dockerHelper; + this.settings = other.settings; + this.batchAnswers = other.batchAnswers; + this.testMode = other.testMode; + this.openMRSPath = other.openMRSPath; + this.stats = other.stats; + initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -182,34 +182,34 @@ public void initTask() { if (distroHelper == null) { distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard, versionsHelper); } - if (owaHelper == null) { - owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } - if (contentHelper == null) { - contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); - } - if (spaInstaller == null) { - spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); - } + if (owaHelper == null) { + owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); + } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); + } + if (spaInstaller == null) { + spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); + } if (dockerHelper == null) { dockerHelper = new DockerHelper(mavenProject, mavenSession, pluginManager, wizard); } if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } From c2edc3603215467724a853ee972516d4fc7a67c4 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 07:40:57 -0400 Subject: [PATCH 07/31] Formatting fix --- .../openmrs/maven/plugins/BuildDistro.java | 319 +++++++++--------- 1 file changed, 164 insertions(+), 155 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index abe72daf7..91720620a 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -41,98 +41,99 @@ */ @Mojo(name = "build-distro", requiresProject = false) public class BuildDistro extends AbstractTask { - + private static final String DEFAULT_SQL_DUMP = Server.CLASSPATH_SCRIPT_PREFIX + "openmrs-platform.sql"; - + private static final String OPENMRS_WAR = "openmrs.war"; - + private static final String OPENMRS_DISTRO_PROPERTIES = "openmrs-distro.properties"; - + private static final String DOCKER_COMPOSE_PATH = "build-distro/docker-compose.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_PATH = "build-distro/docker-compose.override.yml"; - + private static final String DOCKER_COMPOSE_PROD_PATH = "build-distro/docker-compose.prod.yml"; - + private static final String README_PATH = "build-distro/README.md"; - + private static final String DISTRIBUTION_VERSION_PROMPT = "You can build the following versions of distribution"; - + private static final String DUMP_PREFIX = "CREATE DATABASE IF NOT EXISTS `openmrs`;\n\n USE `openmrs`;\n\n"; - + private static final String DB_DUMP_PATH = "dbdump" + File.separator + "dump.sql"; - + private static final String WAR_FILE_MODULES_DIRECTORY_NAME = "bundledModules"; - + private static final String WEB = "web"; - + private static final String DOCKER_COMPOSE_YML = "docker-compose.yml"; - + private static final String DOCKER_COMPOSE_PROD_YML = "docker-compose.prod.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_YML = "docker-compose.override.yml"; - + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final Logger log = LoggerFactory.getLogger(BuildDistro.class); - + /** * Path to the openmrs-distro.properties file. */ @Parameter(property = "distro") private String distro; - + /** * Directory for generated files. (default to 'docker') */ @Parameter(property = "dir") private String dir; - + /** * SQL script for database configuration. */ @Parameter(property = "dbSql") private String dbSql; - + /** * Causes npm to completely ignore peerDependencies */ @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + /** - * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after the setup + * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after + * the setup */ @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + /** - * Instead of creating a `modules` folder in the distro directory, will put modules inside - * the war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` + * Instead of creating a `modules` folder in the distro directory, will put modules inside the + * war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` */ @Parameter(defaultValue = "false", property = "bundled") private boolean bundled; - + /** * Flag to indicate whether to delete the target directory or not. */ @Parameter(defaultValue = "false", property = "reset") private boolean reset; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Override public void executeTask() throws MojoExecutionException, MojoFailureException { File buildDirectory = getBuildDirectory(); - + File userDir = new File(System.getProperty("user.dir")); - + Artifact distroArtifact = null; DistroProperties distroProperties = null; - + if (distro == null) { File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME); if (distroFile.exists()) { @@ -142,15 +143,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } else if (Project.hasProject(userDir)) { Project config = Project.loadProject(userDir); - distroArtifact = DistroHelper - .parseDistroArtifact(config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), - versionsHelper); - + distroArtifact = DistroHelper.parseDistroArtifact( + config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), versionsHelper); + wizard.showMessage("Building distribution from the source at " + userDir + "...\n"); new Build(this).buildProject(config); - distroFile = distroHelper - .extractFileFromDistro(buildDirectory, distroArtifact, DistroProperties.DISTRO_FILE_NAME); - + distroFile = distroHelper.extractFileFromDistro(buildDirectory, distroArtifact, + DistroProperties.DISTRO_FILE_NAME); + if (distroFile.exists()) { distroProperties = new DistroProperties(distroFile); } else { @@ -162,14 +162,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroArtifact = distroProperties.getParentArtifact(); distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } - + if (distroProperties == null) { Server server = new Server.ServerBuilder().build(); - + List options = new ArrayList<>(); options.add(O2_DISTRIBUTION); options.add(O3_DISTRIBUTION); - + String choice = wizard.promptForMissingValueWithOptions("You can setup following servers", null, null, options); switch (choice) { case O2_DISTRIBUTION: @@ -178,57 +178,62 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = new DistroProperties(server.getVersion()); } else { distroProperties = distroHelper.downloadDistroProperties(buildDirectory, server); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), - "jar"); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), + server.getDistroGroupId(), "jar"); } break; case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); server.setServerDirectory(buildDirectory); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties( + distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); } - + } - + if (distroProperties == null) { throw new MojoExecutionException("The distro you specified, '" + distro + "' could not be retrieved"); } - + String distroName = buildDistro(buildDirectory, distroArtifact, distroProperties); - + wizard.showMessage( - "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " - + buildDirectory.getAbsolutePath() + "\n"); + "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " + + buildDirectory.getAbsolutePath() + "\n"); } - - private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException { - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, appShellVersion); + + private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, + DistroProperties distroProperties) throws MojoExecutionException { + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) + && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, + appShellVersion); } return distroProperties; } - + private File getBuildDirectory() throws MojoExecutionException { final File targetDir; if (StringUtils.isBlank(dir)) { String directory = wizard.promptForValueIfMissingWithDefault( - "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); + "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); targetDir = new File(directory); } else { targetDir = new File(dir); } - + if (targetDir.exists()) { if (targetDir.isDirectory()) { if (!reset) { if (isDockerComposeCreated(targetDir)) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' contains docker config. Only modules and openmrs.war will be overriden"); + + "' contains docker config. Only modules and openmrs.war will be overriden"); deleteDistroFiles(new File(targetDir, WEB)); } else if (targetDir.list().length != 0) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' is not empty. All its content will be lost."); + + "' is not empty. All its content will be lost."); boolean chooseDifferent = wizard.promptYesNo("Would you like to choose a different directory?"); if (chooseDifferent) { return getBuildDirectory(); @@ -246,12 +251,12 @@ private File getBuildDirectory() throws MojoExecutionException { } else { targetDir.mkdirs(); } - + dir = targetDir.getAbsolutePath(); - + return targetDir; } - + private void deleteDistroFiles(File targetDir) { try { FileUtils.deleteDirectory(new File(targetDir, "modules")); @@ -262,49 +267,51 @@ private void deleteDistroFiles(File targetDir) { log.error(e.getMessage(), e); } } - + private void deleteDirectory(File targetDir) throws MojoExecutionException { try { FileUtils.cleanDirectory(targetDir); } catch (IOException e) { - throw new MojoExecutionException("Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); + throw new MojoExecutionException( + "Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); } } - + private String buildDistro(File targetDirectory, Artifact distroArtifact, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { InputStream dbDumpStream; wizard.showMessage("Downloading modules...\n"); - + String distroName = adjustImageName(distroProperties.getName()); File web = new File(targetDirectory, WEB); web.mkdirs(); - - moduleInstaller - .installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), web.getAbsolutePath()); + + moduleInstaller.installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), + web.getAbsolutePath()); renameWebApp(web); - + if (bundled) { try { ZipFile warfile = new ZipFile(new File(web, OPENMRS_WAR)); File tempDir = new File(web, "WEB-INF"); tempDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); - + new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); + File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - //TODO: does this flow need this? - //downloadContents(targetDirectory, distroProperties); - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + //TODO: does this flow need this? + //downloadContents(targetDirectory, distroProperties); + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, + overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); - if(frontendDir.exists()) { + if (frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); } - + warfile.addFolder(tempDir, new ZipParameters()); try { FileUtils.deleteDirectory(tempDir); @@ -320,23 +327,22 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File modulesDir = new File(web, "modules"); modulesDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - modulesDir.getAbsolutePath()); - + modulesDir.getAbsolutePath()); + File frontendDir = new File(web, "frontend"); frontendDir.mkdir(); - - File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); - configDir.mkdir(); - setConfigFolder(configDir, distroProperties, distroArtifact); - downloadContents(configDir, distroProperties); + + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); + configDir.mkdir(); + setConfigFolder(configDir, distroProperties, distroArtifact); + downloadContents(configDir, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - - + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); } - + wizard.showMessage("Creating Docker Compose configuration...\n"); String distroVersion = adjustImageName(distroProperties.getVersion()); writeDockerCompose(targetDirectory, distroVersion); @@ -347,38 +353,40 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro copyBuildDistroResource(".env", new File(targetDirectory, ".env")); copyDockerfile(web, distroProperties); distroProperties.saveTo(web); - + dbDumpStream = getSqlDumpStream(StringUtils.isNotBlank(dbSql) ? dbSql : distroProperties.getSqlScriptPath(), - targetDirectory, distroArtifact); + targetDirectory, distroArtifact); if (dbDumpStream != null) { copyDbDump(targetDirectory, dbDumpStream); } //clean up extracted sql file cleanupSqlFiles(targetDirectory); - + return distroName; } - - private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException { + + private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) + throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - - + downloadConfigs(distroProperties, configDir); - - File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); - + + File refappConfigFile = new File(configDir, + distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) + && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -389,11 +397,12 @@ private void setConfigFolder(File configDir, DistroProperties distroProperties, FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } catch (ZipException | IOException e) { + } + catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { List configs = distroProperties.getConfigArtifacts(); wizard.showMessage("Downloading Configs...\n"); @@ -401,9 +410,9 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -413,14 +422,14 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + private boolean isDockerComposeCreated(File targetDir) { File dockerComposeOverride = new File(targetDir, DOCKER_COMPOSE_OVERRIDE_YML); File dockerCompose = new File(targetDir, DOCKER_COMPOSE_YML); File dockerComposeProd = new File(targetDir, DOCKER_COMPOSE_PROD_YML); return dockerCompose.exists() && dockerComposeOverride.exists() && dockerComposeProd.exists(); } - + private void copyDockerfile(File targetDirectory, DistroProperties distroProperties) throws MojoExecutionException { Version platformVersion = new Version(distroProperties.getPlatformVersion(distroHelper, targetDirectory)); int majorVersion = platformVersion.getMajorVersion(); @@ -437,8 +446,7 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } else { copyBuildDistroResource("Dockerfile-tomcat8", new File(targetDirectory, "Dockerfile")); } - } - else { + } else { if (bundled) { copyBuildDistroResource("Dockerfile-jre8-bundled", new File(targetDirectory, "Dockerfile")); } else { @@ -447,18 +455,18 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } } } - + private boolean isPlatform2point5AndAbove(Version platformVersion) { return platformVersion.getMajorVersion() > 2 - || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); + || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); } - + /** * name of sql dump file is unknown, so wipe all files with 'sql' extension */ private void cleanupSqlFiles(File targetDirectory) { File[] sqlFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".sql"); @@ -468,18 +476,19 @@ public boolean accept(File dir, String name) { FileUtils.deleteQuietly(sql); } } - + private void writeDockerCompose(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PATH, DOCKER_COMPOSE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_OVERRIDE_PATH, DOCKER_COMPOSE_OVERRIDE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PROD_PATH, DOCKER_COMPOSE_PROD_YML); } - + private void writeReadme(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, README_PATH, "README.md"); } - - private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) throws MojoExecutionException { + + private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) + throws MojoExecutionException { URL composeUrl = getClass().getClassLoader().getResource(path); if (composeUrl == null) { throw new MojoExecutionException("Failed to find file '" + path + "' in classpath"); @@ -496,11 +505,11 @@ private void writeTemplatedFile(File targetDirectory, String version, String pat } } } - + private String adjustImageName(String part) { return part.replaceAll("\\s+", "").toLowerCase(); } - + private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExecutionException { File dbDump = new File(targetDirectory, DB_DUMP_PATH); try { @@ -510,16 +519,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe catch (IOException e) { throw new MojoExecutionException("Failed to create SQL dump file " + e.getMessage(), e); } - - try (FileWriter writer = new FileWriter(dbDump); - BufferedInputStream bis = new BufferedInputStream(stream)) { + + try (FileWriter writer = new FileWriter(dbDump); BufferedInputStream bis = new BufferedInputStream(stream)) { writer.write(DUMP_PREFIX); - + int c; while ((c = bis.read()) != -1) { writer.write(c); } - + writer.write("\n" + SDKConstants.RESET_SEARCH_INDEX_SQL + "\n"); writer.flush(); } @@ -530,15 +538,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe IOUtils.closeQuietly(stream); } } - + private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) - throws MojoExecutionException { + throws MojoExecutionException { InputStream stream = null; - + if (sqlScriptPath == null) { return null; } - + try { if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); @@ -547,8 +555,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, stream = resourceUrl.openStream(); } else { if (distroArtifact != null && distroArtifact.isValid()) { - File extractedSqlFile = distroHelper - .extractFileFromDistro(targetDirectory, distroArtifact, sqlScript); + File extractedSqlFile = distroHelper.extractFileFromDistro(targetDirectory, distroArtifact, + sqlScript); stream = new FileInputStream(extractedSqlFile); } } @@ -557,7 +565,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, if (scriptFile.exists()) { stream = new FileInputStream(scriptFile); } else { - throw new MojoExecutionException("Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); + throw new MojoExecutionException( + "Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); } } } @@ -566,7 +575,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, } return stream; } - + private void copyBuildDistroResource(String resource, File target) throws MojoExecutionException { URL resourceUrl = getClass().getClassLoader().getResource("build-distro/web/" + resource); if (resourceUrl != null && !target.exists()) { @@ -574,28 +583,28 @@ private void copyBuildDistroResource(String resource, File target) throws MojoEx FileUtils.copyURLToFile(resourceUrl, target); } catch (IOException e) { - throw new MojoExecutionException( - "Failed to copy file from classpath: " + resourceUrl + " to " + target.getAbsolutePath() + e.getMessage(), e); + throw new MojoExecutionException("Failed to copy file from classpath: " + resourceUrl + " to " + + target.getAbsolutePath() + e.getMessage(), e); } } } - + private void renameWebApp(File targetDirectory) throws MojoExecutionException { File[] warFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".war"); } }); - + if (warFiles != null) { for (File file : warFiles) { wizard.showMessage("file:" + file.getAbsolutePath()); } - + wizard.showMessage("target:" + targetDirectory); - + if (warFiles.length == 1) { boolean renameSuccess = warFiles[0].renameTo(new File(targetDirectory, OPENMRS_WAR)); if (!renameSuccess) { @@ -607,17 +616,17 @@ public boolean accept(File dir, String name) { } } - private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { - File targetDirectory = new File(configDir, "temp_content"); - targetDirectory.mkdir(); - - List contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory); - if (!contents.isEmpty()) { - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller); - } - } - FileUtils.deleteQuietly(targetDirectory); - } + private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { + File targetDirectory = new File(configDir, "temp_content"); + targetDirectory.mkdir(); + + List contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory); + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller); + } + } + FileUtils.deleteQuietly(targetDirectory); + } } From 6d894530e0342f499d607981290156a506682b57 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 11:41:06 -0400 Subject: [PATCH 08/31] Formatting fix --- .../openmrs/maven/plugins/AbstractTask.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 57229bed7..e077dd4cd 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -13,6 +13,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.openmrs.maven.plugins.model.Server; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DefaultJira; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.git.DefaultGitHelper; @@ -22,7 +23,6 @@ import org.openmrs.maven.plugins.utility.ModuleInstaller; import org.openmrs.maven.plugins.utility.NodeHelper; import org.openmrs.maven.plugins.utility.OwaHelper; -import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.SpaInstaller; import org.openmrs.maven.plugins.utility.StatsManager; import org.openmrs.maven.plugins.utility.VersionsHelper; @@ -34,82 +34,82 @@ * Base class for all OpenMRS SDK Maven Mojos */ public abstract class AbstractTask extends AbstractMojo { - + /** * The project currently being build */ @Parameter(defaultValue = "${project}", readonly = true) MavenProject mavenProject; - + /** * The current Maven session. */ @Parameter(defaultValue = "${session}", readonly = true, required = true) MavenSession mavenSession; - + /** * The Maven Settings */ @Parameter(defaultValue = "${settings}", readonly = true) Settings settings; - + /** * test mode, if true disables interactive mode and uses batchAnswers, even if there is none */ @Parameter(defaultValue = "false", property = "testMode") boolean testMode; - + /** * path to openmrs directory */ @Parameter(property = "openMRSPath") String openMRSPath; - + /*** * answers to use if not running in interactive mode */ @Parameter(property = "batchAnswers") ArrayDeque batchAnswers; - + /** * stats */ @Parameter(defaultValue = "false", property = "stats") boolean stats; - - /** - * The artifact metadata source to use. - */ - @Component - ArtifactMetadataSource artifactMetadataSource; - - @Component - ArtifactFactory artifactFactory; - - /** - * The Maven BuildPluginManager component. - */ - @Component - BuildPluginManager pluginManager; - - @Component - Wizard wizard; - + + /** + * The artifact metadata source to use. + */ + @Component + ArtifactMetadataSource artifactMetadataSource; + + @Component + ArtifactFactory artifactFactory; + + /** + * The Maven BuildPluginManager component. + */ + @Component + BuildPluginManager pluginManager; + + @Component + Wizard wizard; + /** * wizard for resolving artifact available versions */ VersionsHelper versionsHelper; - + /** * handles installing modules on server */ ModuleInstaller moduleInstaller; - + /** * handles distro-properties */ DistroHelper distroHelper; - + /** * handles OWAs */ @@ -119,30 +119,30 @@ public abstract class AbstractTask extends AbstractMojo { * handles Contents */ ContentHelper contentHelper; - + /** * installs SPAs */ SpaInstaller spaInstaller; - + /** * handles github and provides basic git utilities */ GitHelper gitHelper; - + /** * handles jira */ Jira jira; - + /** * handles docker */ DockerHelper dockerHelper; - + public AbstractTask() { } - + public AbstractTask(AbstractTask other) { this.mavenProject = other.mavenProject; this.mavenSession = other.mavenSession; @@ -165,7 +165,7 @@ public AbstractTask(AbstractTask other) { this.stats = other.stats; initTask(); } - + public void initTask() { if (jira == null) { jira = new DefaultJira(); @@ -197,19 +197,19 @@ public void initTask() { if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); } - + if ((batchAnswers != null && !batchAnswers.isEmpty()) || testMode) { wizard.setAnswers(batchAnswers); wizard.setInteractiveMode(false); } } - + @Override public void execute() throws MojoExecutionException, MojoFailureException { initTask(); new StatsManager(wizard, mavenSession, stats).incrementGoalStats(); executeTask(); } - - abstract public void executeTask() throws MojoExecutionException, MojoFailureException; + + abstract public void executeTask() throws MojoExecutionException, MojoFailureException; } From 44d620ca5538d67ec568b59eace2064fea9f4557 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 11:54:44 -0400 Subject: [PATCH 09/31] Formatting fix --- .../src/main/java/org/openmrs/maven/plugins/BuildDistro.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index 91720620a..a98977a0e 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -619,7 +619,7 @@ public boolean accept(File dir, String name) { private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { File targetDirectory = new File(configDir, "temp_content"); targetDirectory.mkdir(); - + List contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory); if (!contents.isEmpty()) { for (Artifact content : contents) { @@ -628,5 +628,6 @@ private void downloadContents(File configDir, DistroProperties distroProperties) } } FileUtils.deleteQuietly(targetDirectory); - } + } } + From 3e699cedc5c33271331628342edf4f0f8fd109f9 Mon Sep 17 00:00:00 2001 From: nravilla Date: Tue, 27 Aug 2024 12:04:53 -0400 Subject: [PATCH 10/31] Formatting fix --- .../plugins/model/BaseSdkProperties.java | 256 +++++++++--------- 1 file changed, 129 insertions(+), 127 deletions(-) diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index fe1b400e7..7c229126f 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -13,7 +13,7 @@ * */ public abstract class BaseSdkProperties { - + public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId"; protected static final String ARTIFACT_ID = "artifactId"; @@ -30,80 +30,80 @@ public abstract class BaseSdkProperties { protected static final String TYPE_CONFIG = "config"; protected static final String TYPE_CONTENT = "content"; protected static final String TYPE_ZIP = "zip"; - + protected Properties properties; - + public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { Properties properties = new Properties(); for (Artifact artifact : warArtifacts) { - + stripArtifactId(artifact); - + if (!artifact.getType().equals(TYPE_WAR)) { properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); } - + if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); } - + properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); } - + for (Artifact artifact : moduleArtifacts) { stripArtifactId(artifact); - + if (!artifact.getType().equals(TYPE_JAR)) { properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); } if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); } - + properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); } return properties; } - - public String getPlatformVersion() { + + public String getPlatformVersion(){ return getParam("war.openmrs"); } - - public void setPlatformVersion(String version) { + + public void setPlatformVersion(String version){ properties.setProperty("war.openmrs", version); } - - public String getVersion() { + + public String getVersion(){ return getParam("version"); } - - public void setVersion(String version) { + + public void setVersion(String version){ properties.setProperty("version", version); } - - public String getName() { + + public String getName(){ return getParam("name"); } - - public void setName(String name) { + + public void setName(String name){ properties.setProperty("name", name); } - - public List getModuleArtifacts() { + + public List getModuleArtifacts(){ List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { + for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_OMOD)) { + if(artifactType.equals(TYPE_OMOD)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); } } - return artifactList; + return artifactList; } - + public List getOwaArtifacts() { List artifacts = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { + for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); if (key.startsWith(TYPE_OWA + ".")) { String artifactId = key.substring(TYPE_OWA.length() + 1); @@ -112,10 +112,10 @@ public List getOwaArtifacts() { } return artifacts; } - + public Map getSpaProperties() { Map spaProperties = new HashMap<>(); - for (Object keyObject : getAllKeys()) { + for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); if (key.startsWith(TYPE_SPA + ".")) { spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); @@ -123,61 +123,63 @@ public Map getSpaProperties() { } return spaProperties; } - - public List getWarArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_WAR)) { - artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); - } - } - return artifactList; - } - - public List getConfigArtifacts() { + + public List getWarArtifacts(){ List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { + for (Object keyObject: getAllKeys()) { String key = keyObject.toString(); String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_CONFIG)) { + if(artifactType.equals(TYPE_WAR)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); } } - return artifactList; + return artifactList; } - - public List getContentArtifacts() { - List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); - String artifactType = getArtifactType(key); - if (artifactType.equals(TYPE_CONTENT)) { - String artifactId = key.substring(TYPE_CONTENT.length() + 1); - artifactList.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); - } - } - return artifactList; - } - - protected Set getAllKeys() { - return properties.keySet(); - } - - protected String getArtifactType(String key) { + + public List getConfigArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONFIG)) { + artifactList.add( + new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), + checkIfOverwritten(key, TYPE))); + } + } + return artifactList; + } + + public List getContentArtifacts() { + List artifactList = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONTENT)) { + String artifactId = key.substring(TYPE_CONTENT.length() + 1); + artifactList.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); + } + } + return artifactList; + } + + protected Set getAllKeys() { + return properties.keySet(); + } + + protected String getArtifactType(String key){ String[] wordsArray = key.split("\\."); - if (!(wordsArray[wordsArray.length - 1].equals(TYPE) || wordsArray[wordsArray.length - 1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length - 1].equals(GROUP_ID))) { - if (key.contains(".")) { + if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){ + if(key.contains(".")){ return key.substring(0, key.indexOf(".")); - } else { + }else { return ""; } - } else { + }else { return ""; } } - + protected String checkIfOverwritten(String key, String param) { String newKey = key + "." + param; if (getParam(newKey) != null) { @@ -186,50 +188,50 @@ protected String checkIfOverwritten(String key, String param) { setting = setting.concat("-"); setting = setting.concat("package"); } - + return setting; } else { - switch (param) { - case ARTIFACT_ID: - return extractArtifactId(key); - case GROUP_ID: + switch (param) { + case ARTIFACT_ID: + return extractArtifactId(key); + case GROUP_ID: switch (getArtifactType(key)) { - case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId + case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId return Artifact.GROUP_WEB; case TYPE_OMOD: return Artifact.GROUP_MODULE; case TYPE_DISTRO: - case TYPE_CONFIG: + case TYPE_CONFIG: return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO); default: return ""; } - - case TYPE: + + case TYPE: switch (getArtifactType(key)) { case TYPE_OMOD: case TYPE_DISTRO: return TYPE_JAR; case TYPE_WAR: return TYPE_WAR; - case TYPE_CONFIG: - return TYPE_ZIP; + case TYPE_CONFIG: + return TYPE_ZIP; default: return ""; } - default: - return ""; - } + default: + return ""; + } } } - - protected String extractArtifactId(String key) { + + protected String extractArtifactId(String key){ String type = getArtifactType(key); StringBuilder stringBuilder = new StringBuilder(key.substring(key.indexOf(".") + 1)); - if (type.equals(TYPE_OMOD)) { + if(type.equals(TYPE_OMOD)) { stringBuilder.append("-"); stringBuilder.append(type); - } else if (type.equals(TYPE_WAR)) { + } else if(type.equals(TYPE_WAR)){ stringBuilder.append("-"); stringBuilder.append("webapp"); } // referenceapplication exclusive parser @@ -237,56 +239,56 @@ else if (key.equals("distro.referenceapplication")) { stringBuilder.append("-"); stringBuilder.append("package"); } - - return stringBuilder.toString(); + + return stringBuilder.toString(); } - + /** * get param from properties * @param key * @return */ - public String getParam(String key) {return properties.getProperty(key);} - - public Artifact getModuleArtifact(String artifactId) { + public String getParam(String key) {return properties.getProperty(key); } + + public Artifact getModuleArtifact(String artifactId){ String key = TYPE_OMOD + "." + artifactId; - if (StringUtils.isNotBlank(getParam(key))) { + if(StringUtils.isNotBlank(getParam(key))){ return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)); } return null; } - + public void setModuleProperties(Artifact newModule) { newModule = stripArtifactId(newModule); - if (!newModule.getGroupId().equals(Artifact.GROUP_MODULE)) { + if(!newModule.getGroupId().equals(Artifact.GROUP_MODULE)){ setCustomModuleGroupId(newModule); } - if (!newModule.getType().equals(TYPE_JAR)) { + if(!newModule.getType().equals(TYPE_JAR)){ setCustomModuleType(newModule); } setModule(newModule); - + } - + public void removeModuleProperties(Artifact artifact) { artifact = stripArtifactId(artifact); if (getModuleArtifact(artifact.getArtifactId()) != null) { Properties newProperties = new Properties(); newProperties.putAll(properties); - for (Object keyObject : properties.keySet()) { + for(Object keyObject: properties.keySet()){ String key = keyObject.toString(); - if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId())) { + if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId())){ newProperties.remove(key); - } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE)) { + } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE)){ newProperties.remove(key); - } else if (key.equals(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID)) { + } else if(key.equals(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID)){ newProperties.remove(key); } } properties = newProperties; } } - + /** * Removes `-omod` or `-webapp` suffix from artifact ID. * @@ -300,40 +302,40 @@ private Artifact stripArtifactId(Artifact artifact) { } return artifact; } - + private void setModule(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId(), artifact.getVersion()); } - - private void setCustomModuleType(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); + + private void setCustomModuleType(Artifact artifact){ + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType()); } - - private void setCustomModuleGroupId(Artifact artifact) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); + + private void setCustomModuleGroupId(Artifact artifact){ + properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId()); } - - public void synchronize(BaseSdkProperties other) { - for (Object key : getAllKeys()) { + + public void synchronize(BaseSdkProperties other){ + for(Object key: getAllKeys()){ if (isBaseSdkProperty(key.toString())) { other.properties.put(key, properties.get(key)); } } - for (Object key : new ArrayList<>(other.getAllKeys())) { - if (isBaseSdkProperty(key.toString())) { - if (StringUtils.isBlank(getParam(key.toString()))) { + for(Object key: new ArrayList<>(other.getAllKeys())){ + if(isBaseSdkProperty(key.toString())){ + if(StringUtils.isBlank(getParam(key.toString()))){ other.properties.remove(key); } } } } - + private boolean isBaseSdkProperty(String key) { - return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); + return (key.startsWith(TYPE_OMOD) || key.startsWith(TYPE_WAR) || key.equals(NAME) || key.equals(VERSION)); } - - - public void setArtifacts(List warArtifacts, List moduleArtifacts) { + + + public void setArtifacts(List warArtifacts, List moduleArtifacts){ for (Artifact moduleArtifact : moduleArtifacts) { this.setModuleProperties(moduleArtifact); } @@ -341,5 +343,5 @@ public void setArtifacts(List warArtifacts, List moduleArtif this.setPlatformVersion(warArtifact.getVersion()); } } - + } From fbc954ec6aa637613a7cb148c6cf27490a75e711 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 16:57:22 -0400 Subject: [PATCH 11/31] Removed unused variables --- .../openmrs/maven/plugins/AbstractTask.java | 13 +- .../openmrs/maven/plugins/BuildDistro.java | 22 +- .../java/org/openmrs/maven/plugins/Setup.java | 378 +++++++++--------- .../maven/plugins/utility/ContentHelper.java | 144 ++++--- 4 files changed, 266 insertions(+), 291 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index e077dd4cd..8a75669a8 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -115,11 +115,6 @@ public abstract class AbstractTask extends AbstractMojo { */ OwaHelper owaHelper; - /** - * handles Contents - */ - ContentHelper contentHelper; - /** * installs SPAs */ @@ -153,8 +148,7 @@ public AbstractTask(AbstractTask other) { this.moduleInstaller = other.moduleInstaller; this.versionsHelper = other.versionsHelper; this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; - this.contentHelper = other.contentHelper; + this.owaHelper = other.owaHelper; this.spaInstaller = other.spaInstaller; this.gitHelper = other.gitHelper; this.dockerHelper = other.dockerHelper; @@ -184,10 +178,7 @@ public void initTask() { } if (owaHelper == null) { owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } - if (contentHelper == null) { - contentHelper = new ContentHelper(mavenSession, mavenProject, pluginManager); - } + } if (spaInstaller == null) { spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index a98977a0e..b615d58c3 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -17,6 +17,7 @@ import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.model.Project; import org.openmrs.maven.plugins.utility.SDKConstants; @@ -303,8 +304,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - //TODO: does this flow need this? - //downloadContents(targetDirectory, distroProperties); + downloadContents(targetDirectory, distroProperties); spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); @@ -335,7 +335,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); - downloadContents(configDir, distroProperties); + downloadContents(web, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File owasDir = new File(web, "owa"); @@ -616,18 +616,20 @@ public boolean accept(File dir, String name) { } } - private void downloadContents(File configDir, DistroProperties distroProperties) throws MojoExecutionException { - File targetDirectory = new File(configDir, "temp_content"); - targetDirectory.mkdir(); - - List contents = distroProperties.getContentArtifacts(distroHelper, targetDirectory); + private void downloadContents(File web, DistroProperties distroProperties) throws MojoExecutionException { + + ContentHelper contentHelper = new ContentHelper(web); + File tempContentDirectory = new File(web, "temp_content"); + web.mkdir(); + + List contents = distroProperties.getContentArtifacts(distroHelper, web); if (!contents.isEmpty()) { for (Artifact content : contents) { wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(configDir, targetDirectory, content, moduleInstaller); + contentHelper.downloadContent(content, moduleInstaller, tempContentDirectory); } } - FileUtils.deleteQuietly(targetDirectory); + FileUtils.deleteQuietly(web); } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 2593a7635..58997a678 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -34,146 +34,147 @@ import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DBConnector; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.ServerHelper; - /** - * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters. + * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a + * distribution. It prompts for any missing, but required parameters. */ @Mojo(name = "setup", requiresProject = false) public class Setup extends AbstractServerTask { - + public static final String SETTING_UP_A_NEW_SERVER = "Setting up a new server..."; - + public static final String SETUP_SERVERS_PROMPT = "You can setup the following servers"; - - public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = - "If you want to enable remote debugging by default when running the server, " - + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; - + + public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = "If you want to enable remote debugging by default when running the server, " + + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String PLATFORM = "Platform"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final String CLASSPATH_SCRIPT_PREFIX = "classpath://"; - + private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - + private static final int DEFAULT_PORT = 8080; - + /** * DB Driver type */ @Parameter(property = "dbDriver") private String dbDriver; - + /** * DB Uri */ @Parameter(property = "dbUri") private String dbUri; - + /** * DB User */ @Parameter(property = "dbUser") private String dbUser; - + /** * DB Pass */ @Parameter(property = "dbPassword") private String dbPassword; - + /** * DB dump script to import */ @Parameter(property = "dbSql") private String dbSql; - + /** * Docker host address */ @Parameter(property = "dockerHost") private String dockerHost; - + /** * DB reset if exists */ @Parameter(property = "dbReset") private Boolean dbReset; - + /** * Path to JDK Version */ @Parameter(property = "javaHome") private String javaHome; - + /** * Path to installation.properties */ @Parameter(property = "file") private String file; - + /** * Option to include demo data */ @Parameter(defaultValue = "false", property = "addDemoData") private boolean addDemoData; - + /** - * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, if it is 'org.openmrs.distro'. + * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, + * if it is 'org.openmrs.distro'. */ @Parameter(property = "distro") private String distro; - + /** * OpenMRS Platform version to setup e.g. '1.11.5'. */ @Parameter(property = "platform") private String platform; - + @Parameter(property = "debug") private String debug; - + @Parameter(defaultValue = "false", property = "run") private boolean run; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + private ServerHelper serverHelper; - + public Setup() { super(); } - + public Setup(AbstractServerTask other) { super(other); } - + public Setup(AbstractTask other) { super(other); } - + /** - * Gets the distro properties. The distro properties can come from a file specified by path - * or in the current directory or from a maven artifact. - * If no distro properties file can be found, `null` is returned. In this case, the distro - * file will be created after the database is initialized. Setup should proceed to install - * modules based on the OpenMRS WAR file for the given platform version. - * As of this writing, this function can return null only in platform mode. + * Gets the distro properties. The distro properties can come from a file specified by path or + * in the current directory or from a maven artifact. If no distro properties file can be found, + * `null` is returned. In this case, the distro file will be created after the database is + * initialized. Setup should proceed to install modules based on the OpenMRS WAR file for the + * given platform version. As of this writing, this function can return null only in platform + * mode. * * @param server An initialized Server instance * @return distro properties instantiated by DistroHelper @@ -188,12 +189,12 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu if (distroProperties != null) { options.add(distroProperties.getName() + " " + distroProperties.getVersion() + " from current directory"); } - + options.add(O3_DISTRIBUTION); options.add(O2_DISTRIBUTION); options.add(PLATFORM); String choice = wizard.promptForMissingValueWithOptions(SETUP_SERVERS_PROMPT, null, null, options); - + switch (choice) { case PLATFORM: platformMode = true; @@ -210,18 +211,22 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties(distroHelper.getArtifactProperties(artifact, server, appShellVersion)); + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties( + distroHelper.getArtifactProperties(artifact, server, appShellVersion)); platformMode = false; break; - - default: // distro properties from current directory + + default: // distro properties from current directory Artifact distroArtifact = distroProperties.getParentArtifact(); - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion); + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) + && StringUtils.isNotBlank(distroArtifact.getGroupId()) + && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, + appShellVersion); } else { server.setPlatformVersion( - distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); + distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); server.setVersion(distroProperties.getVersion()); } platformMode = false; @@ -229,7 +234,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } else if (platform != null) { server.setPlatformVersion(platform); platformMode = true; - } else { // getting distro properties from file + } else { // getting distro properties from file distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); if (distroProperties == null) { throw new MojoExecutionException("Distro " + distro + "could not be retrieved"); @@ -238,15 +243,14 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu server.setVersion(distroProperties.getVersion()); platformMode = false; } - + if (platformMode) { Artifact platformArtifact = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, - SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); + SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); String version = wizard.promptForPlatformVersionIfMissing(server.getPlatformVersion(), - versionsHelper.getSuggestedVersions(platformArtifact, 6)); - platformArtifact = DistroHelper - .parseDistroArtifact(Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, - versionsHelper); + versionsHelper.getSuggestedVersions(platformArtifact, 6)); + platformArtifact = DistroHelper.parseDistroArtifact( + Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, versionsHelper); server.setPlatformVersion(platformArtifact.getVersion()); try { distroProperties = distroHelper.downloadDistroProperties(server.getServerDirectory(), platformArtifact); @@ -256,16 +260,15 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu distroProperties = null; } } - + return distroProperties; } - + /** - * Sets up a server based on an initialized Server instance and the provided - * distroProperties. Installs modules and other artifacts. Sets up the database. - * Writes openmrs-server.properties. + * Sets up a server based on an initialized Server instance and the provided distroProperties. + * Installs modules and other artifacts. Sets up the database. Writes openmrs-server.properties. * - * @param server An initialized server instance + * @param server An initialized server instance * @param distroProperties Allowed to be null, only if this is a platform install * @throws MojoExecutionException */ @@ -280,36 +283,37 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setConfigFolder(server, distroProperties); installContents(server, distroProperties); if (spaInstaller != null) { - spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, + ignorePeerDependencies, overrideReuseNodeCache); } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); } - + serverHelper = new ServerHelper(wizard); - + setServerPort(server); setDebugPort(server); - + setupDatabase(server, distroProperties); - + // If there's no distro at this point, we create a minimal one here, // *after* having initialized server.isH2Supported in `setupDatabase` above. if (distroProperties == null) { distroProperties = distroHelper.createDistroForPlatform(server); } distroProperties.saveTo(server.getServerDirectory()); - + setJdk(server); - + server.setValuesFromDistroPropertiesModules( - distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), - distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); + distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), + distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); server.setUnspecifiedToDefault(); server.save(); } - + private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); @@ -320,10 +324,10 @@ private void setJdk(Server server) throws MojoExecutionException { } else { wizard.showMessage("Note: JDK 1.8 or above is needed for platform version " + platformVersion + "."); } - + wizard.promptForJavaHomeIfMissing(server); } - + private void installOWAs(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { File owasDir = new File(server.getServerDirectory(), "owa"); @@ -331,9 +335,9 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -343,35 +347,36 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + /** * Sets the configuration folder for the specified server using the provided distro properties. * - * @param server The server for which to set the configuration folder. + * @param server The server for which to set the configuration folder. * @param distroProperties The distro properties containing the configuration information. */ private void setConfigFolder(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - + downloadConfigs(distroProperties, configDir); - + File refappConfigFile = new File(configDir, server.getDistroArtifactId() + "-" + server.getVersion() + ".zip"); - + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) && "referenceapplication-distro".equals(server.getDistroArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) + && "referenceapplication-distro".equals(server.getDistroArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -382,16 +387,19 @@ private void setConfigFolder(Server server, DistroProperties distroProperties) t FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } catch (ZipException | IOException e) { + } + catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + /** - * Downloads the configuration artifact specified in the distro properties and saves them in the provided config directory. + * Downloads the configuration artifact specified in the distro properties and saves them in the + * provided config directory. * - * @param distroProperties The distro properties containing the configuration artifacts to download. - * @param configDir The directory where the configuration files will be saved. + * @param distroProperties The distro properties containing the configuration artifacts to + * download. + * @param configDir The directory where the configuration files will be saved. * @throws MojoExecutionException If an error occurs while downloading the configuration files. */ private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { @@ -401,7 +409,7 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void wipeDatabase(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { @@ -416,14 +424,11 @@ private void wipeDatabase(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to drop " + server.getDbName() + " database"); } } - + private void setServerPort(Server server) throws MojoExecutionException { String message = "What port would you like your server to use?"; - String port = wizard.promptForValueIfMissingWithDefault( - message, - server.getParam("tomcat.port"), - "port number", - String.valueOf(Setup.DEFAULT_PORT)); + String port = wizard.promptForValueIfMissingWithDefault(message, server.getParam("tomcat.port"), "port number", + String.valueOf(Setup.DEFAULT_PORT)); if (!StringUtils.isNumeric(port) || !this.serverHelper.isPort(Integer.parseInt(port))) { wizard.showMessage("Port must be numeric and less or equal 65535."); this.setServerPort(server); @@ -431,15 +436,12 @@ private void setServerPort(Server server) throws MojoExecutionException { } server.setPort(port); } - + private void setDebugPort(Server server) throws MojoExecutionException { if (StringUtils.isBlank(debug) || wizard.checkYes(debug)) { while (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug) && !StringUtils.isNumeric(debug)) { - debug = wizard.promptForValueIfMissingWithDefault( - ENABLE_DEBUGGING_DEFAULT_MESSAGE, - server.getDebugPort(), - "port number", - NO_DEBUGGING_DEFAULT_ANSWER); + debug = wizard.promptForValueIfMissingWithDefault(ENABLE_DEBUGGING_DEFAULT_MESSAGE, server.getDebugPort(), + "port number", NO_DEBUGGING_DEFAULT_ANSWER); if (!StringUtils.isNumeric(debug) && !NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { wizard.showMessage("\nPort number must be numeric."); } else if (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { @@ -448,9 +450,9 @@ private void setDebugPort(Server server) throws MojoExecutionException { } } } - + private void setServerVersionsFromDistroProperties(Server server, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { if (server.getPlatformVersion() == null) { server.setPlatformVersion(distroProperties.getPlatformVersion(distroHelper, server.getServerDirectory())); } @@ -458,54 +460,55 @@ private void setServerVersionsFromDistroProperties(Server server, DistroProperti server.setVersion(distroProperties.getVersion()); } } - + private void setupDatabase(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (server.getDbDriver() == null) { boolean isH2Supported = true; if (distroProperties != null) { isH2Supported = distroProperties.isH2Supported(); } - + wizard.promptForDb(server, dockerHelper, isH2Supported, dbDriver, dockerHost); } - + if (server.getDbDriver() != null) { setupDatabaseForServer(server); } } - + private void setupDatabaseForServer(Server server) throws MojoExecutionException { if (server.getDbName() == null) { server.setDbName(determineDbName(server.getDbUri(), server.getServerId())); } - + if (server.isMySqlDb() || server.isPostgreSqlDb()) { String uri = getUriWithoutDb(server); - try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), + server.getDbName())) { connector.checkAndCreate(server); wizard.showMessage("Connected to the database."); } catch (SQLException e) { throw new MojoExecutionException("Failed to connect to the specified database " + server.getDbUri(), e); } - + if (hasDbTables(server)) { if (dbReset == null) { dbReset = !wizard.promptYesNo( - "Would you like to setup the server using existing data (if not, all data will be lost)?"); + "Would you like to setup the server using existing data (if not, all data will be lost)?"); } - + if (dbReset) { wipeDatabase(server); } else { server.setParam("create_tables", "false"); } } - + if (dbReset == null) { dbReset = true; } - + if (!"null".equals(dbSql) && dbReset) { if (dbSql != null) { importDb(server, dbSql); @@ -513,7 +516,7 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else if (!server.isMySqlDb() && !server.isPostgreSqlDb()) { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage("The specified database " + server.getDbName() - + " does not exist and it will be created when OpenMRS starts."); + + " does not exist and it will be created when OpenMRS starts."); } } else if (!dbReset) { resetSearchIndex(server); @@ -521,29 +524,30 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage( - "The specified database " + server.getDbName() + " does not exist and it will be created for you."); + "The specified database " + server.getDbName() + " does not exist and it will be created for you."); } } - + private boolean hasDbTables(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { DatabaseMetaData md = connector.getConnection().getMetaData(); - + try (ResultSet rs = md.getTables(server.getDbName(), null, null, new String[] { "TABLE" })) { return rs.next(); } } catch (SQLException e) { - throw new MojoExecutionException("Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); + throw new MojoExecutionException( + "Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); } } - + private void resetSearchIndex(Server server) throws MojoExecutionException { String uri = server.getDbUri(); - + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName()); - PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { + PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { ps.execute(); wizard.showMessage("The search index has been reset."); } @@ -551,20 +555,20 @@ private void resetSearchIndex(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to reset search index " + e.getMessage(), e); } } - + private void importDb(Server server, String sqlScriptPath) throws MojoExecutionException { wizard.showMessage("Importing an initial database from " + sqlScriptPath + "..."); String uri = server.getDbUri().replace("@DBNAME@", server.getDbName()); - + InputStream sqlStream; if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); sqlStream = (Setup.class.getClassLoader().getResourceAsStream(sqlScript)); if (sqlStream == null) { Artifact distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); - File extractedSqlFile = distroHelper - .extractFileFromDistro(server.getServerDirectory(), distroArtifact, sqlScript); + server.getDistroGroupId(), "jar"); + File extractedSqlFile = distroHelper.extractFileFromDistro(server.getServerDirectory(), distroArtifact, + sqlScript); extractedSqlFile.deleteOnExit(); try { sqlStream = new FileInputStream(extractedSqlFile); @@ -579,19 +583,20 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE sqlStream = new FileInputStream(scriptFile); } catch (FileNotFoundException e) { - throw new MojoExecutionException("SQL import script could not be found at \"" + - scriptFile.getAbsolutePath() + "\" " + e.getMessage() , e); + throw new MojoExecutionException( + "SQL import script could not be found at \"" + scriptFile.getAbsolutePath() + "\" " + e.getMessage(), + e); } } - + try (InputStreamReader sqlReader = new InputStreamReader(sqlStream); - Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { + Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { ScriptRunner scriptRunner = new ScriptRunner(connection); //we don't want to display ~5000 lines of queries to user if there is no error scriptRunner.setLogWriter(new PrintWriter(new NullOutputStream())); scriptRunner.setStopOnError(true); scriptRunner.runScript(sqlReader); - + wizard.showMessage("Database imported successfully."); server.setParam("create_tables", "false"); } @@ -600,10 +605,10 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE throw new MojoExecutionException("Failed to import database", e); } } - + public String determineDbName(String uri, String serverId) throws MojoExecutionException { String dbName = String.format(SDKConstants.DB_NAME_TEMPLATE, serverId); - + if (!uri.contains("@DBNAME@")) { //determine db name from uri try { @@ -613,66 +618,56 @@ public String determineDbName(String uri, String serverId) throws MojoExecutionE } else { parsedUri = new URI(uri); } - + dbName = parsedUri.getPath(); - + if (dbName == null || dbName.isEmpty() || dbName.equals("/")) { throw new MojoExecutionException("No database name is given in the URI: " + dbName); } - + dbName = dbName.substring(1); - + if (!dbName.substring(1).matches("^[A-Za-z0-9_\\-]+$")) { throw new MojoExecutionException( - "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " - + - dbName); + "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " + + dbName); } } catch (URISyntaxException e) { throw new MojoExecutionException("Could not parse uri: " + uri, e); } } - + return dbName; } - + public void executeTask() throws MojoExecutionException, MojoFailureException { wizard.showMessage(SETTING_UP_A_NEW_SERVER); - + Server.ServerBuilder serverBuilder; if (file != null) { serverBuilder = new Server.ServerBuilder(Server.loadServer(Paths.get(file))); } else { serverBuilder = new Server.ServerBuilder(); } - - Server server = serverBuilder - .setServerId(serverId) - .setDbDriver(dbDriver) - .setDbUri(dbUri) - .setDbUser(dbUser) - .setDbPassword(dbPassword) - .setInteractiveMode(testMode) - .setJavaHome(javaHome) - .setDebugPort(debug) - .build(); - + + Server server = serverBuilder.setServerId(serverId).setDbDriver(dbDriver).setDbUri(dbUri).setDbUser(dbUser) + .setDbPassword(dbPassword).setInteractiveMode(testMode).setJavaHome(javaHome).setDebugPort(debug).build(); + wizard.promptForNewServerIfMissing(server); - + File serverDir = Server.getServersPath().resolve(server.getServerId()).toFile(); if (serverDir.isDirectory()) { throw new MojoExecutionException( - "Cannot create server: directory with name " + serverDir.getName() + " already exists"); - } - else if (serverDir.getAbsolutePath().contains(" ")) { - throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + - " contains a space. Please make sure your server path does not include any spaces."); + "Cannot create server: directory with name " + serverDir.getName() + " already exists"); + } else if (serverDir.getAbsolutePath().contains(" ")) { + throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + + " contains a space. Please make sure your server path does not include any spaces."); } - + server.setServerDirectory(serverDir); serverDir.mkdir(); - + try { DistroProperties distroProperties = resolveDistroProperties(server); setup(server, distroProperties); @@ -681,40 +676,35 @@ else if (serverDir.getAbsolutePath().contains(" ")) { FileUtils.deleteQuietly(server.getServerDirectory()); throw new MojoExecutionException("Failed to setup server", e); } - + getLog().info("Server configured successfully, path: " + serverDir); - + if (run) { new Run(this, server.getServerId()).execute(); } } - + private String getUriWithoutDb(Server server) { String uri = server.getDbUri(); uri = uri.substring(0, uri.lastIndexOf("/") + 1); return uri; } - private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { - if (distroProperties != null) { - File tempContentDir = new File(server.getServerDirectory(), "temp-content"); - tempContentDir.mkdir(); - downloadContents(server, distroProperties, tempContentDir); - FileUtils.deleteQuietly(tempContentDir); - } - } - - private void downloadContents(Server server, DistroProperties distroProperties, File tempContentDir) - throws MojoExecutionException { - List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); - //Configuration dir gets created before this method is called - File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); - - if (!contents.isEmpty()) { - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(configDir, tempContentDir, content, moduleInstaller); - } - } - } + private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + if (distroProperties != null) { + ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); + File tempContentDir = new File(server.getServerDirectory(), "temp-content"); + tempContentDir.mkdir(); + List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); + + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(content, moduleInstaller, tempContentDir); + } + } + FileUtils.deleteQuietly(tempContentDir); + } + } + } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index fd1a1f78b..5618e20ac 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -5,84 +5,76 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; import org.openmrs.maven.plugins.model.Artifact; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +/** + * This class is responsible for + */ public class ContentHelper { - - private final MavenSession session; - private final BuildPluginManager pluginManager; - private final MavenProject mavenProject; - private static final Logger logger = LoggerFactory.getLogger(ContentHelper.class); - - public ContentHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager) { - this.session = session; - this.mavenProject = mavenProject; - this.pluginManager = pluginManager; - } - - public void downloadContent(File configurationDir, File tempContentDir, Artifact contentArtifact, - ModuleInstaller moduleInstaller) throws MojoExecutionException { - - String artifactId = contentArtifact.getArtifactId(); - File contentDir = new File(tempContentDir, artifactId); - - moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); - moveBackendConfig(contentDir, configurationDir, artifactId); - } - - private void moveBackendConfig(File inputDir, File configurationDir, String artifactId) throws MojoExecutionException { - - if (!inputDir.isDirectory() || !configurationDir.isDirectory()) { - throw new MojoExecutionException("Both inputDir and configurationDir must be valid directories."); - } - - File backendConfigs = new File(inputDir, "configs" + File.separator + "backend_config"); - - if (backendConfigs.listFiles() == null || backendConfigs.listFiles().length == 0) { - throw new MojoExecutionException("No directories to process under content configuration directories"); - } - - for (File backendConfig : backendConfigs.listFiles()) { - // Find a corresponding directory in the configurationDir with the same name as backendConfig - File matchingConfigurationDir = new File(configurationDir, backendConfig.getName()); - - File artifactDir; - 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(); - } - } - copyDirectory(backendConfig, artifactDir); - } - } - - private void copyDirectory(File sourceDir, File destDir) throws MojoExecutionException { - try { - if (!destDir.exists()) { - destDir.mkdirs(); - } - - for (File file : sourceDir.listFiles()) { - File destFile = new File(destDir, file.getName()); - if (file.isDirectory()) { - copyDirectory(file, destFile); - } else { - Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - } - } catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); - } - } + + File serverDirectory; + + public ContentHelper(File serverDirectory) { + this.serverDirectory = serverDirectory; + } + + public void downloadContent(Artifact contentArtifact, ModuleInstaller moduleInstaller, File tempContentDir) throws MojoExecutionException { + + String artifactId = contentArtifact.getArtifactId(); + //create a artifact folder under temp_content + File contentDir = new File(tempContentDir, artifactId); + contentDir.mkdirs(); + + moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); + moveBackendConfig(artifactId, contentDir); + + } + + private void moveBackendConfig(String artifactId, File contentDir) throws MojoExecutionException { + + File configurationDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); + + if (!contentDir.isDirectory() || !configurationDir.isDirectory()) { + throw new MojoExecutionException("Both inputDir and configurationDir must be valid directories."); + } + + File backendConfigFiles = new File(contentDir, "configs" + File.separator + "backend_config"); + + for (File config : backendConfigFiles.listFiles()) { + // Find a corresponding directory in the configurationDir with the same name as backendConfig + File matchingConfigurationDir = new File(configurationDir, config.getName()); + File destDir = null; + if (!matchingConfigurationDir.exists() || !matchingConfigurationDir.isDirectory()) { + // Folder doesn't exist under configuration, we will be creating a new configuration here + matchingConfigurationDir.mkdirs(); + destDir = matchingConfigurationDir; + } + // Create a new artifact folder under the matching configuration folder + destDir = new File(matchingConfigurationDir, artifactId); + + //copy config files to the matching configuration folder + copyDirectory(config, destDir); + } + } + + private void copyDirectory(File config, File destDir) throws MojoExecutionException { + try { + if (!destDir.exists()) { + destDir.mkdirs(); + } + for (File file : config.listFiles()) { + File destFile = new File(destDir, file.getName()); + if (file.isDirectory()) { + copyDirectory(file, destFile); + } else { + Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } + } + catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + } + } From 12fb282a7a9cbcdba5fa86af050aa76b6dffe8aa Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 17:03:12 -0400 Subject: [PATCH 12/31] Formatting fix --- .../src/main/java/org/openmrs/maven/plugins/AbstractTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 8a75669a8..285d61756 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -178,7 +178,7 @@ public void initTask() { } if (owaHelper == null) { owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); - } + } if (spaInstaller == null) { spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); } From 46ac43c97bf19b87b292dd7d5c09557b53fec37f Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 17:07:32 -0400 Subject: [PATCH 13/31] Formatting fix --- .../src/main/java/org/openmrs/maven/plugins/AbstractTask.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 285d61756..2e5f96180 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -13,7 +13,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.openmrs.maven.plugins.model.Server; -import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DefaultJira; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.git.DefaultGitHelper; @@ -148,7 +147,7 @@ public AbstractTask(AbstractTask other) { this.moduleInstaller = other.moduleInstaller; this.versionsHelper = other.versionsHelper; this.distroHelper = other.distroHelper; - this.owaHelper = other.owaHelper; + this.owaHelper = other.owaHelper; this.spaInstaller = other.spaInstaller; this.gitHelper = other.gitHelper; this.dockerHelper = other.dockerHelper; From cd35a016b996221e09adccf1f922fae071aeaf24 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 17:10:30 -0400 Subject: [PATCH 14/31] Formatting fix --- .../src/main/java/org/openmrs/maven/plugins/AbstractTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java index 2e5f96180..61a397758 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AbstractTask.java @@ -113,7 +113,7 @@ public abstract class AbstractTask extends AbstractMojo { * handles OWAs */ OwaHelper owaHelper; - + /** * installs SPAs */ From b32c4d6b64122be01320d93840e3dc780a2884db Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 20:22:53 -0400 Subject: [PATCH 15/31] Formatting fix --- .../main/java/org/openmrs/maven/plugins/BuildDistro.java | 9 +++++---- .../src/main/java/org/openmrs/maven/plugins/Setup.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index b615d58c3..d8c64cc7a 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -303,8 +303,8 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); + downloadContents(web, distroProperties); - downloadContents(targetDirectory, distroProperties); spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); @@ -336,6 +336,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); downloadContents(web, distroProperties); + spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File owasDir = new File(web, "owa"); @@ -618,7 +619,8 @@ public boolean accept(File dir, String name) { private void downloadContents(File web, DistroProperties distroProperties) throws MojoExecutionException { - ContentHelper contentHelper = new ContentHelper(web); + ContentHelper contentHelper = new ContentHelper(web); + File tempContentDirectory = new File(web, "temp_content"); web.mkdir(); @@ -630,6 +632,5 @@ private void downloadContents(File web, DistroProperties distroProperties) throw } } FileUtils.deleteQuietly(web); - } + } } - diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 58997a678..5c715c552 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -281,7 +281,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - installContents(server, distroProperties); + downloadContents(server, distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); @@ -690,7 +690,7 @@ private String getUriWithoutDb(Server server) { return uri; } - private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + private void downloadContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); File tempContentDir = new File(server.getServerDirectory(), "temp-content"); From 6a68fe2e9ab063221be84d9865989cd771e2a025 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 21:31:38 -0400 Subject: [PATCH 16/31] Formatting fix --- .../src/main/java/org/openmrs/maven/plugins/Setup.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 5c715c552..ddad8d40d 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -281,7 +281,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - downloadContents(server, distroProperties); + installContents(server, distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); @@ -690,7 +690,7 @@ private String getUriWithoutDb(Server server) { return uri; } - private void downloadContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); File tempContentDir = new File(server.getServerDirectory(), "temp-content"); @@ -706,5 +706,5 @@ private void downloadContents(Server server, DistroProperties distroProperties) FileUtils.deleteQuietly(tempContentDir); } } - + } From 1e50aed0666f153ff5d5a128ac5c880cd19d1c99 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 21:40:25 -0400 Subject: [PATCH 17/31] Formatting fix --- .../java/org/openmrs/maven/plugins/Setup.java | 358 +++++++++--------- 1 file changed, 172 insertions(+), 186 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index ddad8d40d..00b23e95a 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -34,147 +34,146 @@ import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; -import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DBConnector; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.ServerHelper; + /** - * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a - * distribution. It prompts for any missing, but required parameters. + * Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters. */ @Mojo(name = "setup", requiresProject = false) public class Setup extends AbstractServerTask { - + public static final String SETTING_UP_A_NEW_SERVER = "Setting up a new server..."; - + public static final String SETUP_SERVERS_PROMPT = "You can setup the following servers"; - - public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = "If you want to enable remote debugging by default when running the server, " - + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; - + + public static final String ENABLE_DEBUGGING_DEFAULT_MESSAGE = + "If you want to enable remote debugging by default when running the server, " + + "\nspecify the %s here (e.g. 1044). Leave blank to disable debugging. \n(Do not do this on a production server)"; + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String PLATFORM = "Platform"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final String CLASSPATH_SCRIPT_PREFIX = "classpath://"; - + private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - + private static final int DEFAULT_PORT = 8080; - + /** * DB Driver type */ @Parameter(property = "dbDriver") private String dbDriver; - + /** * DB Uri */ @Parameter(property = "dbUri") private String dbUri; - + /** * DB User */ @Parameter(property = "dbUser") private String dbUser; - + /** * DB Pass */ @Parameter(property = "dbPassword") private String dbPassword; - + /** * DB dump script to import */ @Parameter(property = "dbSql") private String dbSql; - + /** * Docker host address */ @Parameter(property = "dockerHost") private String dockerHost; - + /** * DB reset if exists */ @Parameter(property = "dbReset") private Boolean dbReset; - + /** * Path to JDK Version */ @Parameter(property = "javaHome") private String javaHome; - + /** * Path to installation.properties */ @Parameter(property = "file") private String file; - + /** * Option to include demo data */ @Parameter(defaultValue = "false", property = "addDemoData") private boolean addDemoData; - + /** - * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, - * if it is 'org.openmrs.distro'. + * OpenMRS Distribution to setup in a format 'groupId:artifactId:version'. You can skip groupId, if it is 'org.openmrs.distro'. */ @Parameter(property = "distro") private String distro; - + /** * OpenMRS Platform version to setup e.g. '1.11.5'. */ @Parameter(property = "platform") private String platform; - + @Parameter(property = "debug") private String debug; - + @Parameter(defaultValue = "false", property = "run") private boolean run; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + private ServerHelper serverHelper; - + public Setup() { super(); } - + public Setup(AbstractServerTask other) { super(other); } - + public Setup(AbstractTask other) { super(other); } - + /** - * Gets the distro properties. The distro properties can come from a file specified by path or - * in the current directory or from a maven artifact. If no distro properties file can be found, - * `null` is returned. In this case, the distro file will be created after the database is - * initialized. Setup should proceed to install modules based on the OpenMRS WAR file for the - * given platform version. As of this writing, this function can return null only in platform - * mode. + * Gets the distro properties. The distro properties can come from a file specified by path + * or in the current directory or from a maven artifact. + * If no distro properties file can be found, `null` is returned. In this case, the distro + * file will be created after the database is initialized. Setup should proceed to install + * modules based on the OpenMRS WAR file for the given platform version. + * As of this writing, this function can return null only in platform mode. * * @param server An initialized Server instance * @return distro properties instantiated by DistroHelper @@ -189,12 +188,12 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu if (distroProperties != null) { options.add(distroProperties.getName() + " " + distroProperties.getVersion() + " from current directory"); } - + options.add(O3_DISTRIBUTION); options.add(O2_DISTRIBUTION); options.add(PLATFORM); String choice = wizard.promptForMissingValueWithOptions(SETUP_SERVERS_PROMPT, null, null, options); - + switch (choice) { case PLATFORM: platformMode = true; @@ -211,22 +210,18 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties( - distroHelper.getArtifactProperties(artifact, server, appShellVersion)); + server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties(distroHelper.getArtifactProperties(artifact, server, appShellVersion)); platformMode = false; break; - - default: // distro properties from current directory + + default: // distro properties from current directory Artifact distroArtifact = distroProperties.getParentArtifact(); - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) - && StringUtils.isNotBlank(distroArtifact.getGroupId()) - && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, - appShellVersion); + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion); } else { server.setPlatformVersion( - distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); + distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory())); server.setVersion(distroProperties.getVersion()); } platformMode = false; @@ -234,7 +229,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu } else if (platform != null) { server.setPlatformVersion(platform); platformMode = true; - } else { // getting distro properties from file + } else { // getting distro properties from file distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); if (distroProperties == null) { throw new MojoExecutionException("Distro " + distro + "could not be retrieved"); @@ -243,14 +238,15 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu server.setVersion(distroProperties.getVersion()); platformMode = false; } - + if (platformMode) { Artifact platformArtifact = new Artifact(SDKConstants.PLATFORM_ARTIFACT_ID, - SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); + SDKConstants.SETUP_DEFAULT_PLATFORM_VERSION, Artifact.GROUP_DISTRO); String version = wizard.promptForPlatformVersionIfMissing(server.getPlatformVersion(), - versionsHelper.getSuggestedVersions(platformArtifact, 6)); - platformArtifact = DistroHelper.parseDistroArtifact( - Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, versionsHelper); + versionsHelper.getSuggestedVersions(platformArtifact, 6)); + platformArtifact = DistroHelper + .parseDistroArtifact(Artifact.GROUP_DISTRO + ":" + SDKConstants.PLATFORM_ARTIFACT_ID + ":" + version, + versionsHelper); server.setPlatformVersion(platformArtifact.getVersion()); try { distroProperties = distroHelper.downloadDistroProperties(server.getServerDirectory(), platformArtifact); @@ -260,15 +256,16 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu distroProperties = null; } } - + return distroProperties; } - + /** - * Sets up a server based on an initialized Server instance and the provided distroProperties. - * Installs modules and other artifacts. Sets up the database. Writes openmrs-server.properties. + * Sets up a server based on an initialized Server instance and the provided + * distroProperties. Installs modules and other artifacts. Sets up the database. + * Writes openmrs-server.properties. * - * @param server An initialized server instance + * @param server An initialized server instance * @param distroProperties Allowed to be null, only if this is a platform install * @throws MojoExecutionException */ @@ -281,39 +278,37 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - installContents(server, distroProperties); if (spaInstaller != null) { - spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, - ignorePeerDependencies, overrideReuseNodeCache); + spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); } - + serverHelper = new ServerHelper(wizard); - + setServerPort(server); setDebugPort(server); - + setupDatabase(server, distroProperties); - + // If there's no distro at this point, we create a minimal one here, // *after* having initialized server.isH2Supported in `setupDatabase` above. if (distroProperties == null) { distroProperties = distroHelper.createDistroForPlatform(server); } distroProperties.saveTo(server.getServerDirectory()); - + setJdk(server); - + server.setValuesFromDistroPropertiesModules( - distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), - distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); + distroProperties.getWarArtifacts(distroHelper, server.getServerDirectory()), + distroProperties.getModuleArtifacts(distroHelper, server.getServerDirectory()), distroProperties); server.setUnspecifiedToDefault(); server.save(); } - + private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); @@ -324,10 +319,10 @@ private void setJdk(Server server) throws MojoExecutionException { } else { wizard.showMessage("Note: JDK 1.8 or above is needed for platform version " + platformVersion + "."); } - + wizard.promptForJavaHomeIfMissing(server); } - + private void installOWAs(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { File owasDir = new File(server.getServerDirectory(), "owa"); @@ -335,9 +330,9 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -347,36 +342,35 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + /** * Sets the configuration folder for the specified server using the provided distro properties. * - * @param server The server for which to set the configuration folder. + * @param server The server for which to set the configuration folder. * @param distroProperties The distro properties containing the configuration information. */ private void setConfigFolder(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + File configDir = new File(server.getServerDirectory(), SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - + downloadConfigs(distroProperties, configDir); - + File refappConfigFile = new File(configDir, server.getDistroArtifactId() + "-" + server.getVersion() + ".zip"); - + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) - && "referenceapplication-distro".equals(server.getDistroArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(server.getDistroGroupId()) && "referenceapplication-distro".equals(server.getDistroArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -387,19 +381,16 @@ private void setConfigFolder(Server server, DistroProperties distroProperties) t FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } - catch (ZipException | IOException e) { + } catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + /** - * Downloads the configuration artifact specified in the distro properties and saves them in the - * provided config directory. + * Downloads the configuration artifact specified in the distro properties and saves them in the provided config directory. * - * @param distroProperties The distro properties containing the configuration artifacts to - * download. - * @param configDir The directory where the configuration files will be saved. + * @param distroProperties The distro properties containing the configuration artifacts to download. + * @param configDir The directory where the configuration files will be saved. * @throws MojoExecutionException If an error occurs while downloading the configuration files. */ private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { @@ -409,7 +400,7 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void wipeDatabase(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { @@ -424,11 +415,14 @@ private void wipeDatabase(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to drop " + server.getDbName() + " database"); } } - + private void setServerPort(Server server) throws MojoExecutionException { String message = "What port would you like your server to use?"; - String port = wizard.promptForValueIfMissingWithDefault(message, server.getParam("tomcat.port"), "port number", - String.valueOf(Setup.DEFAULT_PORT)); + String port = wizard.promptForValueIfMissingWithDefault( + message, + server.getParam("tomcat.port"), + "port number", + String.valueOf(Setup.DEFAULT_PORT)); if (!StringUtils.isNumeric(port) || !this.serverHelper.isPort(Integer.parseInt(port))) { wizard.showMessage("Port must be numeric and less or equal 65535."); this.setServerPort(server); @@ -436,12 +430,15 @@ private void setServerPort(Server server) throws MojoExecutionException { } server.setPort(port); } - + private void setDebugPort(Server server) throws MojoExecutionException { if (StringUtils.isBlank(debug) || wizard.checkYes(debug)) { while (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug) && !StringUtils.isNumeric(debug)) { - debug = wizard.promptForValueIfMissingWithDefault(ENABLE_DEBUGGING_DEFAULT_MESSAGE, server.getDebugPort(), - "port number", NO_DEBUGGING_DEFAULT_ANSWER); + debug = wizard.promptForValueIfMissingWithDefault( + ENABLE_DEBUGGING_DEFAULT_MESSAGE, + server.getDebugPort(), + "port number", + NO_DEBUGGING_DEFAULT_ANSWER); if (!StringUtils.isNumeric(debug) && !NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { wizard.showMessage("\nPort number must be numeric."); } else if (!NO_DEBUGGING_DEFAULT_ANSWER.equals(debug)) { @@ -450,9 +447,9 @@ private void setDebugPort(Server server) throws MojoExecutionException { } } } - + private void setServerVersionsFromDistroProperties(Server server, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { if (server.getPlatformVersion() == null) { server.setPlatformVersion(distroProperties.getPlatformVersion(distroHelper, server.getServerDirectory())); } @@ -460,55 +457,54 @@ private void setServerVersionsFromDistroProperties(Server server, DistroProperti server.setVersion(distroProperties.getVersion()); } } - + private void setupDatabase(Server server, DistroProperties distroProperties) throws MojoExecutionException { if (server.getDbDriver() == null) { boolean isH2Supported = true; if (distroProperties != null) { isH2Supported = distroProperties.isH2Supported(); } - + wizard.promptForDb(server, dockerHelper, isH2Supported, dbDriver, dockerHost); } - + if (server.getDbDriver() != null) { setupDatabaseForServer(server); } } - + private void setupDatabaseForServer(Server server) throws MojoExecutionException { if (server.getDbName() == null) { server.setDbName(determineDbName(server.getDbUri(), server.getServerId())); } - + if (server.isMySqlDb() || server.isPostgreSqlDb()) { String uri = getUriWithoutDb(server); - try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), - server.getDbName())) { + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { connector.checkAndCreate(server); wizard.showMessage("Connected to the database."); } catch (SQLException e) { throw new MojoExecutionException("Failed to connect to the specified database " + server.getDbUri(), e); } - + if (hasDbTables(server)) { if (dbReset == null) { dbReset = !wizard.promptYesNo( - "Would you like to setup the server using existing data (if not, all data will be lost)?"); + "Would you like to setup the server using existing data (if not, all data will be lost)?"); } - + if (dbReset) { wipeDatabase(server); } else { server.setParam("create_tables", "false"); } } - + if (dbReset == null) { dbReset = true; } - + if (!"null".equals(dbSql) && dbReset) { if (dbSql != null) { importDb(server, dbSql); @@ -516,7 +512,7 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else if (!server.isMySqlDb() && !server.isPostgreSqlDb()) { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage("The specified database " + server.getDbName() - + " does not exist and it will be created when OpenMRS starts."); + + " does not exist and it will be created when OpenMRS starts."); } } else if (!dbReset) { resetSearchIndex(server); @@ -524,30 +520,29 @@ private void setupDatabaseForServer(Server server) throws MojoExecutionException } else { moduleInstaller.installModule(SDKConstants.H2_ARTIFACT, server.getServerDirectory().getPath()); wizard.showMessage( - "The specified database " + server.getDbName() + " does not exist and it will be created for you."); + "The specified database " + server.getDbName() + " does not exist and it will be created for you."); } } - + private boolean hasDbTables(Server server) throws MojoExecutionException { String uri = getUriWithoutDb(server); try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName())) { DatabaseMetaData md = connector.getConnection().getMetaData(); - + try (ResultSet rs = md.getTables(server.getDbName(), null, null, new String[] { "TABLE" })) { return rs.next(); } } catch (SQLException e) { - throw new MojoExecutionException( - "Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); + throw new MojoExecutionException("Failed to fetch table list from \"" + server.getDbName() + "\" database. " + e.getMessage(), e); } } - + private void resetSearchIndex(Server server) throws MojoExecutionException { String uri = server.getDbUri(); - + try (DBConnector connector = new DBConnector(uri, server.getDbUser(), server.getDbPassword(), server.getDbName()); - PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { + PreparedStatement ps = connector.getConnection().prepareStatement(SDKConstants.RESET_SEARCH_INDEX_SQL)) { ps.execute(); wizard.showMessage("The search index has been reset."); } @@ -555,20 +550,20 @@ private void resetSearchIndex(Server server) throws MojoExecutionException { throw new MojoExecutionException("Failed to reset search index " + e.getMessage(), e); } } - + private void importDb(Server server, String sqlScriptPath) throws MojoExecutionException { wizard.showMessage("Importing an initial database from " + sqlScriptPath + "..."); String uri = server.getDbUri().replace("@DBNAME@", server.getDbName()); - + InputStream sqlStream; if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); sqlStream = (Setup.class.getClassLoader().getResourceAsStream(sqlScript)); if (sqlStream == null) { Artifact distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); - File extractedSqlFile = distroHelper.extractFileFromDistro(server.getServerDirectory(), distroArtifact, - sqlScript); + server.getDistroGroupId(), "jar"); + File extractedSqlFile = distroHelper + .extractFileFromDistro(server.getServerDirectory(), distroArtifact, sqlScript); extractedSqlFile.deleteOnExit(); try { sqlStream = new FileInputStream(extractedSqlFile); @@ -583,20 +578,19 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE sqlStream = new FileInputStream(scriptFile); } catch (FileNotFoundException e) { - throw new MojoExecutionException( - "SQL import script could not be found at \"" + scriptFile.getAbsolutePath() + "\" " + e.getMessage(), - e); + throw new MojoExecutionException("SQL import script could not be found at \"" + + scriptFile.getAbsolutePath() + "\" " + e.getMessage() , e); } } - + try (InputStreamReader sqlReader = new InputStreamReader(sqlStream); - Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { + Connection connection = DriverManager.getConnection(uri, server.getDbUser(), server.getDbPassword())) { ScriptRunner scriptRunner = new ScriptRunner(connection); //we don't want to display ~5000 lines of queries to user if there is no error scriptRunner.setLogWriter(new PrintWriter(new NullOutputStream())); scriptRunner.setStopOnError(true); scriptRunner.runScript(sqlReader); - + wizard.showMessage("Database imported successfully."); server.setParam("create_tables", "false"); } @@ -605,10 +599,10 @@ private void importDb(Server server, String sqlScriptPath) throws MojoExecutionE throw new MojoExecutionException("Failed to import database", e); } } - + public String determineDbName(String uri, String serverId) throws MojoExecutionException { String dbName = String.format(SDKConstants.DB_NAME_TEMPLATE, serverId); - + if (!uri.contains("@DBNAME@")) { //determine db name from uri try { @@ -618,56 +612,66 @@ public String determineDbName(String uri, String serverId) throws MojoExecutionE } else { parsedUri = new URI(uri); } - + dbName = parsedUri.getPath(); - + if (dbName == null || dbName.isEmpty() || dbName.equals("/")) { throw new MojoExecutionException("No database name is given in the URI: " + dbName); } - + dbName = dbName.substring(1); - + if (!dbName.substring(1).matches("^[A-Za-z0-9_\\-]+$")) { throw new MojoExecutionException( - "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " - + dbName); + "The database name is not in the correct format (it should only have alphanumeric, dash and underscore signs): " + + + dbName); } } catch (URISyntaxException e) { throw new MojoExecutionException("Could not parse uri: " + uri, e); } } - + return dbName; } - + public void executeTask() throws MojoExecutionException, MojoFailureException { wizard.showMessage(SETTING_UP_A_NEW_SERVER); - + Server.ServerBuilder serverBuilder; if (file != null) { serverBuilder = new Server.ServerBuilder(Server.loadServer(Paths.get(file))); } else { serverBuilder = new Server.ServerBuilder(); } - - Server server = serverBuilder.setServerId(serverId).setDbDriver(dbDriver).setDbUri(dbUri).setDbUser(dbUser) - .setDbPassword(dbPassword).setInteractiveMode(testMode).setJavaHome(javaHome).setDebugPort(debug).build(); - + + Server server = serverBuilder + .setServerId(serverId) + .setDbDriver(dbDriver) + .setDbUri(dbUri) + .setDbUser(dbUser) + .setDbPassword(dbPassword) + .setInteractiveMode(testMode) + .setJavaHome(javaHome) + .setDebugPort(debug) + .build(); + wizard.promptForNewServerIfMissing(server); - + File serverDir = Server.getServersPath().resolve(server.getServerId()).toFile(); if (serverDir.isDirectory()) { throw new MojoExecutionException( - "Cannot create server: directory with name " + serverDir.getName() + " already exists"); - } else if (serverDir.getAbsolutePath().contains(" ")) { - throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() - + " contains a space. Please make sure your server path does not include any spaces."); + "Cannot create server: directory with name " + serverDir.getName() + " already exists"); } - + else if (serverDir.getAbsolutePath().contains(" ")) { + throw new MojoExecutionException("Cannot create server: The server path " + serverDir.getAbsolutePath() + + " contains a space. Please make sure your server path does not include any spaces."); + } + server.setServerDirectory(serverDir); serverDir.mkdir(); - + try { DistroProperties distroProperties = resolveDistroProperties(server); setup(server, distroProperties); @@ -676,35 +680,17 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { FileUtils.deleteQuietly(server.getServerDirectory()); throw new MojoExecutionException("Failed to setup server", e); } - + getLog().info("Server configured successfully, path: " + serverDir); - + if (run) { new Run(this, server.getServerId()).execute(); } } - + private String getUriWithoutDb(Server server) { String uri = server.getDbUri(); uri = uri.substring(0, uri.lastIndexOf("/") + 1); return uri; } - - private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { - if (distroProperties != null) { - ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); - File tempContentDir = new File(server.getServerDirectory(), "temp-content"); - tempContentDir.mkdir(); - List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); - - if (!contents.isEmpty()) { - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(content, moduleInstaller, tempContentDir); - } - } - FileUtils.deleteQuietly(tempContentDir); - } - } - } From a86913c1a06c632e8757c0b19f5181e6651f1c70 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 21:45:48 -0400 Subject: [PATCH 18/31] Formatting fix --- .../java/org/openmrs/maven/plugins/Setup.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 00b23e95a..b714db935 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -35,6 +35,7 @@ import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; import org.openmrs.maven.plugins.utility.DBConnector; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.ServerHelper; @@ -278,6 +279,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); + installContents(server, distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } @@ -693,4 +695,22 @@ private String getUriWithoutDb(Server server) { uri = uri.substring(0, uri.lastIndexOf("/") + 1); return uri; } + + private void installContents(Server server, DistroProperties distroProperties) throws MojoExecutionException { + if (distroProperties != null) { + ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); + File tempContentDir = new File(server.getServerDirectory(), "temp-content"); + tempContentDir.mkdir(); + List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); + + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content); + contentHelper.downloadContent(content, moduleInstaller, tempContentDir); + } + } + FileUtils.deleteQuietly(tempContentDir); + } + } + } From 392fc717cb0de6b46728f5dca51f5f17f1ba61bd Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 29 Aug 2024 21:54:04 -0400 Subject: [PATCH 19/31] Formatting fix --- .../openmrs/maven/plugins/BuildDistro.java | 291 +++++++++--------- 1 file changed, 139 insertions(+), 152 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index d8c64cc7a..889744ea4 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -42,99 +42,98 @@ */ @Mojo(name = "build-distro", requiresProject = false) public class BuildDistro extends AbstractTask { - + private static final String DEFAULT_SQL_DUMP = Server.CLASSPATH_SCRIPT_PREFIX + "openmrs-platform.sql"; - + private static final String OPENMRS_WAR = "openmrs.war"; - + private static final String OPENMRS_DISTRO_PROPERTIES = "openmrs-distro.properties"; - + private static final String DOCKER_COMPOSE_PATH = "build-distro/docker-compose.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_PATH = "build-distro/docker-compose.override.yml"; - + private static final String DOCKER_COMPOSE_PROD_PATH = "build-distro/docker-compose.prod.yml"; - + private static final String README_PATH = "build-distro/README.md"; - + private static final String DISTRIBUTION_VERSION_PROMPT = "You can build the following versions of distribution"; - + private static final String DUMP_PREFIX = "CREATE DATABASE IF NOT EXISTS `openmrs`;\n\n USE `openmrs`;\n\n"; - + private static final String DB_DUMP_PATH = "dbdump" + File.separator + "dump.sql"; - + private static final String WAR_FILE_MODULES_DIRECTORY_NAME = "bundledModules"; - + private static final String WEB = "web"; - + private static final String DOCKER_COMPOSE_YML = "docker-compose.yml"; - + private static final String DOCKER_COMPOSE_PROD_YML = "docker-compose.prod.yml"; - + private static final String DOCKER_COMPOSE_OVERRIDE_YML = "docker-compose.override.yml"; - + private static final String O2_DISTRIBUTION = "2.x Distribution"; - + private static final String O3_DISTRIBUTION = "O3 Distribution"; - + private static final Logger log = LoggerFactory.getLogger(BuildDistro.class); - + /** * Path to the openmrs-distro.properties file. */ @Parameter(property = "distro") private String distro; - + /** * Directory for generated files. (default to 'docker') */ @Parameter(property = "dir") private String dir; - + /** * SQL script for database configuration. */ @Parameter(property = "dbSql") private String dbSql; - + /** * Causes npm to completely ignore peerDependencies */ @Parameter(property = "ignorePeerDependencies", defaultValue = "true") private boolean ignorePeerDependencies; - + /** - * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after - * the setup + * Override the reuseNodeCache property that controls whether the SDK reuse the NPM cache after the setup */ @Parameter(property = "reuseNodeCache") public Boolean overrideReuseNodeCache; - + /** - * Instead of creating a `modules` folder in the distro directory, will put modules inside the - * war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` + * Instead of creating a `modules` folder in the distro directory, will put modules inside + * the war file in `/webapp/src/main/webapp/WEB-INF/bundledModules` */ @Parameter(defaultValue = "false", property = "bundled") private boolean bundled; - + /** * Flag to indicate whether to delete the target directory or not. */ @Parameter(defaultValue = "false", property = "reset") private boolean reset; - + @Parameter(property = "appShellVersion") private String appShellVersion; - + @Override public void executeTask() throws MojoExecutionException, MojoFailureException { File buildDirectory = getBuildDirectory(); - + File userDir = new File(System.getProperty("user.dir")); - + Artifact distroArtifact = null; DistroProperties distroProperties = null; - + if (distro == null) { File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME); if (distroFile.exists()) { @@ -144,14 +143,15 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } else if (Project.hasProject(userDir)) { Project config = Project.loadProject(userDir); - distroArtifact = DistroHelper.parseDistroArtifact( - config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), versionsHelper); - + distroArtifact = DistroHelper + .parseDistroArtifact(config.getGroupId() + ":" + config.getArtifactId() + ":" + config.getVersion(), + versionsHelper); + wizard.showMessage("Building distribution from the source at " + userDir + "...\n"); new Build(this).buildProject(config); - distroFile = distroHelper.extractFileFromDistro(buildDirectory, distroArtifact, - DistroProperties.DISTRO_FILE_NAME); - + distroFile = distroHelper + .extractFileFromDistro(buildDirectory, distroArtifact, DistroProperties.DISTRO_FILE_NAME); + if (distroFile.exists()) { distroProperties = new DistroProperties(distroFile); } else { @@ -163,14 +163,14 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroArtifact = distroProperties.getParentArtifact(); distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties); } - + if (distroProperties == null) { Server server = new Server.ServerBuilder().build(); - + List options = new ArrayList<>(); options.add(O2_DISTRIBUTION); options.add(O3_DISTRIBUTION); - + String choice = wizard.promptForMissingValueWithOptions("You can setup following servers", null, null, options); switch (choice) { case O2_DISTRIBUTION: @@ -179,62 +179,57 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { distroProperties = new DistroProperties(server.getVersion()); } else { distroProperties = distroHelper.downloadDistroProperties(buildDirectory, server); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "jar"); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), + "jar"); } break; case O3_DISTRIBUTION: wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper); server.setServerDirectory(buildDirectory); - distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), - server.getDistroGroupId(), "zip"); - distroProperties = new DistroProperties( - distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); + distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip"); + distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion)); } - + } - + if (distroProperties == null) { throw new MojoExecutionException("The distro you specified, '" + distro + "' could not be retrieved"); } - + String distroName = buildDistro(buildDirectory, distroArtifact, distroProperties); - + wizard.showMessage( - "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " - + buildDirectory.getAbsolutePath() + "\n"); + "The '" + distroName + "' distribution created! To start up the server run 'docker-compose up' from " + + buildDirectory.getAbsolutePath() + "\n"); } - - private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, - DistroProperties distroProperties) throws MojoExecutionException { - if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) - && StringUtils.isNotBlank(distroArtifact.getVersion())) { - distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, - appShellVersion); + + private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException { + if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { + distroProperties = distroHelper.resolveParentArtifact(distroArtifact, buildDirectory, distroProperties, appShellVersion); } return distroProperties; } - + private File getBuildDirectory() throws MojoExecutionException { final File targetDir; if (StringUtils.isBlank(dir)) { String directory = wizard.promptForValueIfMissingWithDefault( - "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); + "Specify build directory for generated files (-Ddir, default: 'docker')", dir, "dir", "docker"); targetDir = new File(directory); } else { targetDir = new File(dir); } - + if (targetDir.exists()) { if (targetDir.isDirectory()) { if (!reset) { if (isDockerComposeCreated(targetDir)) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' contains docker config. Only modules and openmrs.war will be overriden"); + + "' contains docker config. Only modules and openmrs.war will be overriden"); deleteDistroFiles(new File(targetDir, WEB)); } else if (targetDir.list().length != 0) { wizard.showMessage("The directory at '" + targetDir.getAbsolutePath() - + "' is not empty. All its content will be lost."); + + "' is not empty. All its content will be lost."); boolean chooseDifferent = wizard.promptYesNo("Would you like to choose a different directory?"); if (chooseDifferent) { return getBuildDirectory(); @@ -252,12 +247,12 @@ private File getBuildDirectory() throws MojoExecutionException { } else { targetDir.mkdirs(); } - + dir = targetDir.getAbsolutePath(); - + return targetDir; } - + private void deleteDistroFiles(File targetDir) { try { FileUtils.deleteDirectory(new File(targetDir, "modules")); @@ -268,50 +263,47 @@ private void deleteDistroFiles(File targetDir) { log.error(e.getMessage(), e); } } - + private void deleteDirectory(File targetDir) throws MojoExecutionException { try { FileUtils.cleanDirectory(targetDir); } catch (IOException e) { - throw new MojoExecutionException( - "Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); + throw new MojoExecutionException("Could not clean up directory \"" + targetDir.getAbsolutePath() + "\" " + e.getMessage(), e); } } - + private String buildDistro(File targetDirectory, Artifact distroArtifact, DistroProperties distroProperties) - throws MojoExecutionException { + throws MojoExecutionException { InputStream dbDumpStream; wizard.showMessage("Downloading modules...\n"); - + String distroName = adjustImageName(distroProperties.getName()); File web = new File(targetDirectory, WEB); web.mkdirs(); - - moduleInstaller.installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), - web.getAbsolutePath()); + + moduleInstaller + .installModules(distroProperties.getWarArtifacts(distroHelper, targetDirectory), web.getAbsolutePath()); renameWebApp(web); - + if (bundled) { try { ZipFile warfile = new ZipFile(new File(web, OPENMRS_WAR)); File tempDir = new File(web, "WEB-INF"); tempDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); - + new File(tempDir, WAR_FILE_MODULES_DIRECTORY_NAME).getAbsolutePath()); + File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); downloadContents(web, distroProperties); - - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, - overrideReuseNodeCache); + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); - if (frontendDir.exists()) { + if(frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); } - + warfile.addFolder(tempDir, new ZipParameters()); try { FileUtils.deleteDirectory(tempDir); @@ -327,23 +319,22 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File modulesDir = new File(web, "modules"); modulesDir.mkdir(); moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory), - modulesDir.getAbsolutePath()); - + modulesDir.getAbsolutePath()); + File frontendDir = new File(web, "frontend"); frontendDir.mkdir(); - + File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); downloadContents(web, distroProperties); - spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); } - + wizard.showMessage("Creating Docker Compose configuration...\n"); String distroVersion = adjustImageName(distroProperties.getVersion()); writeDockerCompose(targetDirectory, distroVersion); @@ -354,40 +345,37 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro copyBuildDistroResource(".env", new File(targetDirectory, ".env")); copyDockerfile(web, distroProperties); distroProperties.saveTo(web); - + dbDumpStream = getSqlDumpStream(StringUtils.isNotBlank(dbSql) ? dbSql : distroProperties.getSqlScriptPath(), - targetDirectory, distroArtifact); + targetDirectory, distroArtifact); if (dbDumpStream != null) { copyDbDump(targetDirectory, dbDumpStream); } //clean up extracted sql file cleanupSqlFiles(targetDirectory); - + return distroName; } - - private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) - throws MojoExecutionException { + + private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException { if (distroProperties.getConfigArtifacts().isEmpty()) { return; } - + downloadConfigs(distroProperties, configDir); - - File refappConfigFile = new File(configDir, - distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); - + + File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip"); + // Handle O2 configuration - if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) - && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { + if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) { refappConfigFile = new File(configDir, "referenceapplication-distro.owa"); } - + if (!refappConfigFile.exists()) { wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath()); return; } - + try { ZipFile zipFile = new ZipFile(refappConfigFile); zipFile.extractAll(configDir.getPath()); @@ -398,12 +386,11 @@ private void setConfigFolder(File configDir, DistroProperties distroProperties, FileUtils.deleteQuietly(file); } FileUtils.deleteQuietly(refappConfigFile); - } - catch (ZipException | IOException e) { + } catch (ZipException | IOException e) { throw new RuntimeException(e); } } - + private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException { List configs = distroProperties.getConfigArtifacts(); wizard.showMessage("Downloading Configs...\n"); @@ -411,9 +398,9 @@ private void downloadConfigs(DistroProperties distroProperties, File configDir) moduleInstaller.installModules(configs, configDir.getAbsolutePath()); } } - + private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) - throws MojoExecutionException { + throws MojoExecutionException { List owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory); if (!owas.isEmpty()) { wizard.showMessage("Downloading OWAs...\n"); @@ -423,14 +410,14 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + private boolean isDockerComposeCreated(File targetDir) { File dockerComposeOverride = new File(targetDir, DOCKER_COMPOSE_OVERRIDE_YML); File dockerCompose = new File(targetDir, DOCKER_COMPOSE_YML); File dockerComposeProd = new File(targetDir, DOCKER_COMPOSE_PROD_YML); return dockerCompose.exists() && dockerComposeOverride.exists() && dockerComposeProd.exists(); } - + private void copyDockerfile(File targetDirectory, DistroProperties distroProperties) throws MojoExecutionException { Version platformVersion = new Version(distroProperties.getPlatformVersion(distroHelper, targetDirectory)); int majorVersion = platformVersion.getMajorVersion(); @@ -447,7 +434,8 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } else { copyBuildDistroResource("Dockerfile-tomcat8", new File(targetDirectory, "Dockerfile")); } - } else { + } + else { if (bundled) { copyBuildDistroResource("Dockerfile-jre8-bundled", new File(targetDirectory, "Dockerfile")); } else { @@ -456,18 +444,18 @@ private void copyDockerfile(File targetDirectory, DistroProperties distroPropert } } } - + private boolean isPlatform2point5AndAbove(Version platformVersion) { return platformVersion.getMajorVersion() > 2 - || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); + || (platformVersion.getMajorVersion() == 2 && platformVersion.getMinorVersion() >= 5); } - + /** * name of sql dump file is unknown, so wipe all files with 'sql' extension */ private void cleanupSqlFiles(File targetDirectory) { File[] sqlFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".sql"); @@ -477,19 +465,18 @@ public boolean accept(File dir, String name) { FileUtils.deleteQuietly(sql); } } - + private void writeDockerCompose(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PATH, DOCKER_COMPOSE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_OVERRIDE_PATH, DOCKER_COMPOSE_OVERRIDE_YML); writeTemplatedFile(targetDirectory, version, DOCKER_COMPOSE_PROD_PATH, DOCKER_COMPOSE_PROD_YML); } - + private void writeReadme(File targetDirectory, String version) throws MojoExecutionException { writeTemplatedFile(targetDirectory, version, README_PATH, "README.md"); } - - private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) - throws MojoExecutionException { + + private void writeTemplatedFile(File targetDirectory, String version, String path, String filename) throws MojoExecutionException { URL composeUrl = getClass().getClassLoader().getResource(path); if (composeUrl == null) { throw new MojoExecutionException("Failed to find file '" + path + "' in classpath"); @@ -506,11 +493,11 @@ private void writeTemplatedFile(File targetDirectory, String version, String pat } } } - + private String adjustImageName(String part) { return part.replaceAll("\\s+", "").toLowerCase(); } - + private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExecutionException { File dbDump = new File(targetDirectory, DB_DUMP_PATH); try { @@ -520,15 +507,16 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe catch (IOException e) { throw new MojoExecutionException("Failed to create SQL dump file " + e.getMessage(), e); } - - try (FileWriter writer = new FileWriter(dbDump); BufferedInputStream bis = new BufferedInputStream(stream)) { + + try (FileWriter writer = new FileWriter(dbDump); + BufferedInputStream bis = new BufferedInputStream(stream)) { writer.write(DUMP_PREFIX); - + int c; while ((c = bis.read()) != -1) { writer.write(c); } - + writer.write("\n" + SDKConstants.RESET_SEARCH_INDEX_SQL + "\n"); writer.flush(); } @@ -539,15 +527,15 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe IOUtils.closeQuietly(stream); } } - + private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, Artifact distroArtifact) - throws MojoExecutionException { + throws MojoExecutionException { InputStream stream = null; - + if (sqlScriptPath == null) { return null; } - + try { if (sqlScriptPath.startsWith(Server.CLASSPATH_SCRIPT_PREFIX)) { String sqlScript = sqlScriptPath.replace(Server.CLASSPATH_SCRIPT_PREFIX, ""); @@ -556,8 +544,8 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, stream = resourceUrl.openStream(); } else { if (distroArtifact != null && distroArtifact.isValid()) { - File extractedSqlFile = distroHelper.extractFileFromDistro(targetDirectory, distroArtifact, - sqlScript); + File extractedSqlFile = distroHelper + .extractFileFromDistro(targetDirectory, distroArtifact, sqlScript); stream = new FileInputStream(extractedSqlFile); } } @@ -566,8 +554,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, if (scriptFile.exists()) { stream = new FileInputStream(scriptFile); } else { - throw new MojoExecutionException( - "Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); + throw new MojoExecutionException("Specified script \"" + scriptFile.getAbsolutePath() + "\" does not exist."); } } } @@ -576,7 +563,7 @@ private InputStream getSqlDumpStream(String sqlScriptPath, File targetDirectory, } return stream; } - + private void copyBuildDistroResource(String resource, File target) throws MojoExecutionException { URL resourceUrl = getClass().getClassLoader().getResource("build-distro/web/" + resource); if (resourceUrl != null && !target.exists()) { @@ -584,28 +571,28 @@ private void copyBuildDistroResource(String resource, File target) throws MojoEx FileUtils.copyURLToFile(resourceUrl, target); } catch (IOException e) { - throw new MojoExecutionException("Failed to copy file from classpath: " + resourceUrl + " to " - + target.getAbsolutePath() + e.getMessage(), e); + throw new MojoExecutionException( + "Failed to copy file from classpath: " + resourceUrl + " to " + target.getAbsolutePath() + e.getMessage(), e); } } } - + private void renameWebApp(File targetDirectory) throws MojoExecutionException { File[] warFiles = targetDirectory.listFiles(new FilenameFilter() { - + @Override public boolean accept(File dir, String name) { return name.endsWith(".war"); } }); - + if (warFiles != null) { for (File file : warFiles) { wizard.showMessage("file:" + file.getAbsolutePath()); } - + wizard.showMessage("target:" + targetDirectory); - + if (warFiles.length == 1) { boolean renameSuccess = warFiles[0].renameTo(new File(targetDirectory, OPENMRS_WAR)); if (!renameSuccess) { @@ -616,13 +603,12 @@ public boolean accept(File dir, String name) { } } } - + private void downloadContents(File web, DistroProperties distroProperties) throws MojoExecutionException { - ContentHelper contentHelper = new ContentHelper(web); - + ContentHelper contentHelper = new ContentHelper(web); File tempContentDirectory = new File(web, "temp_content"); - web.mkdir(); + tempContentDirectory.mkdir(); List contents = distroProperties.getContentArtifacts(distroHelper, web); if (!contents.isEmpty()) { @@ -631,6 +617,7 @@ private void downloadContents(File web, DistroProperties distroProperties) throw contentHelper.downloadContent(content, moduleInstaller, tempContentDirectory); } } - FileUtils.deleteQuietly(web); + FileUtils.deleteQuietly(tempContentDirectory); } + } From 776b404fc581327723a0f4d801937a25ea03cd94 Mon Sep 17 00:00:00 2001 From: nravilla Date: Mon, 9 Sep 2024 09:38:01 -0400 Subject: [PATCH 20/31] Added getContentArtifacts --- .../maven/plugins/model/BaseSdkProperties.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index e6ed4ee9c..510f39f3e 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -150,6 +150,18 @@ public List getConfigArtifacts() { return artifactList; } + public List getContentArtifacts() { + List artifacts = new ArrayList<>(); + for (Object keyObject: getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_CONTENT + ".")) { + String artifactId = key.substring(TYPE_CONTENT.length() + 1); + artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); + } + } + return artifacts; + } + protected Set getAllKeys() { return properties.keySet(); } From 89120ef0de29ad02cd9a3c97522cf69341c7061d Mon Sep 17 00:00:00 2001 From: nravilla Date: Mon, 9 Sep 2024 10:27:20 -0400 Subject: [PATCH 21/31] Changed Content to ContentConfiguration --- .../openmrs/maven/plugins/BuildDistro.java | 8 +++---- .../java/org/openmrs/maven/plugins/Setup.java | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index b9c50c925..a8be8884f 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -294,9 +294,9 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); - downloadOWAs(targetDirectory, distroProperties, owasDir); - downloadContents(web, distroProperties); + downloadOWAs(targetDirectory, distroProperties, owasDir); spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + installContentConfiguration(web, distroProperties); File frontendDir = new File(tempDir, "frontend"); if(frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); @@ -325,7 +325,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); - downloadContents(web, distroProperties); + installContentConfiguration(web, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File owasDir = new File(web, "owa"); @@ -622,7 +622,7 @@ public boolean accept(File dir, String name) { } } - private void downloadContents(File web, DistroProperties distroProperties) throws MojoExecutionException { + private void installContentConfiguration(File web, DistroProperties distroProperties) throws MojoExecutionException { ContentHelper contentHelper = new ContentHelper(web); File tempContentDirectory = new File(web, "temp_content"); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 3df0cc825..205080d9d 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -14,6 +14,7 @@ import org.openmrs.maven.plugins.model.DistroProperties; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; +import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.DBConnector; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.SDKConstants; @@ -279,6 +280,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); + installContentConfiguration(server, distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } @@ -330,7 +332,7 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw owasDir.mkdir(); downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } - } + } private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) throws MojoExecutionException { @@ -343,7 +345,24 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } } - + + private void installContentConfiguration(Server server, DistroProperties distroProperties) throws MojoExecutionException { + if (distroProperties != null) { + File tempContentDir = new File(server.getServerDirectory(), "temp-content"); + tempContentDir.mkdir(); + List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); + ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); + + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content + "\n"); + contentHelper.downloadContent(content, moduleInstaller, tempContentDir); + } + } + FileUtils.deleteQuietly(tempContentDir); + } + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * From 37c0442070033eeacde8f64c6e4fe48d6c3eeecc Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 19 Sep 2024 02:55:59 -0400 Subject: [PATCH 22/31] Removed serverDirectory as an instance variable from ContentHelper --- .../openmrs/maven/plugins/BuildDistro.java | 22 ++-- .../java/org/openmrs/maven/plugins/Setup.java | 26 +++-- .../maven/plugins/utility/ContentHelper.java | 109 ++++++++++-------- .../maven/plugins/model/DistroProperties.java | 14 +-- 4 files changed, 88 insertions(+), 83 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index a8be8884f..c19525196 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -294,9 +294,9 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); - downloadOWAs(targetDirectory, distroProperties, owasDir); - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - installContentConfiguration(web, distroProperties); + downloadOWAs(targetDirectory, distroProperties, owasDir); + //downloadAndMoveContentBackendConfig(targetDirectory, distroProperties); + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); if(frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); @@ -304,6 +304,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro warfile.addFolder(tempDir, new ZipParameters()); try { + //ContentHelper.deleteTempContentFolder(targetDirectory); FileUtils.deleteDirectory(tempDir); } catch (IOException e) { @@ -325,12 +326,13 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); - installContentConfiguration(web, distroProperties); + downloadAndMoveContentBackendConfig(web, distroProperties, configDir); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); + //ContentHelper.deleteTempContentFolder(targetDirectory); } @@ -622,20 +624,16 @@ public boolean accept(File dir, String name) { } } - private void installContentConfiguration(File web, DistroProperties distroProperties) throws MojoExecutionException { + private void downloadAndMoveContentBackendConfig(File web, DistroProperties distroProperties, File targetDir) throws MojoExecutionException { - ContentHelper contentHelper = new ContentHelper(web); - File tempContentDirectory = new File(web, "temp_content"); - tempContentDirectory.mkdir(); - - List contents = distroProperties.getContentArtifacts(distroHelper, web); + List contents = distroProperties.getContentArtifacts(); if (!contents.isEmpty()) { for (Artifact content : contents) { wizard.showMessage("Downloading Content: " + content); - contentHelper.downloadContent(content, moduleInstaller, tempContentDirectory); + ContentHelper.downloadContent(web, content, moduleInstaller, targetDir); } } - FileUtils.deleteQuietly(tempContentDirectory); + } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 205080d9d..09dc88c06 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,7 +65,8 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; + private static final int DEFAULT_PORT = 8080; + /** * DB Driver type @@ -280,10 +281,11 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - installContentConfiguration(server, distroProperties); + downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } + ContentHelper.deleteTempContentFolder(server.getServerDirectory()); installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -312,6 +314,11 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE server.save(); } + private void cleanupContentTempFolder() { + + + } + private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); @@ -346,20 +353,17 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie } } - private void installContentConfiguration(Server server, DistroProperties distroProperties) throws MojoExecutionException { + private void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { - File tempContentDir = new File(server.getServerDirectory(), "temp-content"); - tempContentDir.mkdir(); - List contents = distroProperties.getContentArtifacts(distroHelper, tempContentDir); - ContentHelper contentHelper = new ContentHelper(server.getServerDirectory()); - + File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); + List contents = distroProperties.getContentArtifacts(); + if (!contents.isEmpty()) { for (Artifact content : contents) { wizard.showMessage("Downloading Content: " + content + "\n"); - contentHelper.downloadContent(content, moduleInstaller, tempContentDir); + ContentHelper.downloadContent(serverDirectory, content, moduleInstaller, targetDir); } - } - FileUtils.deleteQuietly(tempContentDir); + } } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index 5618e20ac..efd8da58c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -4,76 +4,91 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Collection; +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 responsible for + * This class is downloads and moves content backend config to respective configuration folders */ public class ContentHelper { - File serverDirectory; + public static final String TEMP_CONTENT_FOLDER = "temp-content"; + public static final String FRONTEND_CONFIG_FOLDER = File.separator + "configs" + File.separator + "frontend_config"; + public static final String BACKEND_CONFIG_FOLDER = "configs" + File.separator + "backend_config"; - public ContentHelper(File serverDirectory) { - this.serverDirectory = serverDirectory; - } - - public void downloadContent(Artifact contentArtifact, ModuleInstaller moduleInstaller, File tempContentDir) throws MojoExecutionException { + public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { String artifactId = contentArtifact.getArtifactId(); //create a artifact folder under temp_content - File contentDir = new File(tempContentDir, artifactId); - contentDir.mkdirs(); - - moduleInstaller.installUnpackModule(contentArtifact, contentDir.getAbsolutePath()); - moveBackendConfig(artifactId, contentDir); + File sourceDir = new File(serverDirectory, TEMP_CONTENT_FOLDER + File.separator + artifactId); + sourceDir.mkdirs(); + moduleInstaller.installUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); + moveBackendConfig(artifactId, sourceDir, targetDir); } - private void moveBackendConfig(String artifactId, File contentDir) throws MojoExecutionException { - - File configurationDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); - - if (!contentDir.isDirectory() || !configurationDir.isDirectory()) { - throw new MojoExecutionException("Both inputDir and configurationDir must be valid directories."); - } - - File backendConfigFiles = new File(contentDir, "configs" + File.separator + "backend_config"); - - for (File config : backendConfigFiles.listFiles()) { - // Find a corresponding directory in the configurationDir with the same name as backendConfig - File matchingConfigurationDir = new File(configurationDir, config.getName()); - File destDir = null; - if (!matchingConfigurationDir.exists() || !matchingConfigurationDir.isDirectory()) { - // Folder doesn't exist under configuration, we will be creating a new configuration here - matchingConfigurationDir.mkdirs(); - destDir = matchingConfigurationDir; - } - // Create a new artifact folder under the matching configuration folder - destDir = new File(matchingConfigurationDir, artifactId); + private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { + try { + File backendConfigFiles = new File(sourceDir, BACKEND_CONFIG_FOLDER); - //copy config files to the matching configuration folder - copyDirectory(config, destDir); + for (File config : backendConfigFiles.listFiles()) { + // Find a corresponding directory in the configurationDir with the same name as backendConfig + File matchingConfigurationDir = new File(targetDir, config.getName()); + File destDir = null; + if (!matchingConfigurationDir.exists() || !matchingConfigurationDir.isDirectory()) { + // Folder doesn't exist so create it + matchingConfigurationDir.mkdirs(); + destDir = matchingConfigurationDir; + } + // Create a new artifact folder under the matching configuration folder + destDir = new File(matchingConfigurationDir, artifactId); + + //copy config files to the matching configuration folder + FileUtils.copyDirectory(config, destDir); + } } + catch (IOException e) { + throw new MojoExecutionException("Error copying backend configuration: " + e.getMessage(), e); + } + } + + public static List getContentFrontendConfigFiles(DistroProperties distroProperties, File serverDirectory) { + List contentConfigFiles = new ArrayList(); + + List artifacts = distroProperties.getContentArtifacts(); + if (artifacts != null) { + for (Artifact artifact : artifacts) { + String artifactId = artifact.getArtifactId(); + File artifactFrontendDir = new File(serverDirectory, + TEMP_CONTENT_FOLDER + File.separator + artifactId + FRONTEND_CONFIG_FOLDER); + + // Add all files from the artifact directory + if (artifactFrontendDir.exists() && artifactFrontendDir.isDirectory()) { + //just include json files and set recursive to true + Collection files = FileUtils.listFiles(artifactFrontendDir, null, true); + contentConfigFiles.addAll(files); + } + } + } + return contentConfigFiles; } - private void copyDirectory(File config, File destDir) throws MojoExecutionException { + public static void deleteTempContentFolder(File serverDirectory) throws MojoExecutionException { try { - if (!destDir.exists()) { - destDir.mkdirs(); - } - for (File file : config.listFiles()) { - File destFile = new File(destDir, file.getName()); - if (file.isDirectory()) { - copyDirectory(file, destFile); - } else { - Files.copy(file.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } + File tempContentDir = new File(serverDirectory, TEMP_CONTENT_FOLDER); + + if (tempContentDir.exists()) { + FileUtils.deleteDirectory(tempContentDir); } } catch (IOException e) { - throw new MojoExecutionException(e.getMessage()); + throw new MojoExecutionException("Error deleting temp content directory: " + e.getMessage(), e); } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index 03dbc807a..4c887d343 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -193,17 +193,6 @@ public List getWarArtifacts(DistroHelper distroHelper, File directory) } return mergeArtifactLists(childArtifacts, parentArtifacts); } - - public List getContentArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException { - List childArtifacts = getContentArtifacts(); - List parentArtifacts = new ArrayList<>(); - Artifact artifact = getDistroArtifact(); - if (artifact != null) { - DistroProperties distroProperties = distroHelper.downloadDistroProperties(directory, artifact); - parentArtifacts.addAll(distroProperties.getContentArtifacts(distroHelper, directory)); - } - return mergeArtifactLists(childArtifacts, parentArtifacts); - } public String getPlatformVersion(DistroHelper distroHelper, File directory) throws MojoExecutionException{ Artifact artifact = getDistroArtifact(); @@ -270,8 +259,7 @@ public void resolvePlaceholders(Properties projectProperties) throws MojoExecuti } } - @Override - public Set getAllKeys() { + public Set getAllKeys() { return properties.keySet(); } From 6b5041a9df101de0d4c1613c9dc76e09a3a15eb5 Mon Sep 17 00:00:00 2001 From: nravilla Date: Thu, 19 Sep 2024 07:59:48 -0400 Subject: [PATCH 23/31] removed empty method - cleanupContentTempFolder() --- .../src/main/java/org/openmrs/maven/plugins/Setup.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 09dc88c06..ad54cfecc 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -314,11 +314,6 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE server.save(); } - private void cleanupContentTempFolder() { - - - } - private void setJdk(Server server) throws MojoExecutionException { String platformVersion = server.getPlatformVersion(); Version version = new Version(platformVersion); From 78a39b77c24e8c1d4dfbbd963bd5fc7694b22c3c Mon Sep 17 00:00:00 2001 From: nravilla Date: Sun, 22 Sep 2024 22:46:06 -0400 Subject: [PATCH 24/31] Changes based on PR code review --- .../openmrs/maven/plugins/BuildDistro.java | 20 ++------ .../java/org/openmrs/maven/plugins/Setup.java | 23 ++------- .../maven/plugins/utility/ContentHelper.java | 47 ++++++++++--------- .../plugins/utility/ModuleInstaller.java | 2 +- .../plugins/model/BaseSdkProperties.java | 24 ++++++---- 5 files changed, 48 insertions(+), 68 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index c19525196..bed57cd6a 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -325,14 +325,13 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - setConfigFolder(configDir, distroProperties, distroArtifact); - downloadAndMoveContentBackendConfig(web, distroProperties, configDir); + setConfigFolder(configDir, distroProperties, distroArtifact); + ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); - //ContentHelper.deleteTempContentFolder(targetDirectory); } @@ -622,18 +621,5 @@ public boolean accept(File dir, String name) { throw new MojoExecutionException("Distro should contain only single war file"); } } - } - - private void downloadAndMoveContentBackendConfig(File web, DistroProperties distroProperties, File targetDir) throws MojoExecutionException { - - List contents = distroProperties.getContentArtifacts(); - if (!contents.isEmpty()) { - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content); - ContentHelper.downloadContent(web, content, moduleInstaller, targetDir); - } - } - - } - + } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index ad54cfecc..77714e3d5 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -281,11 +281,10 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - } - ContentHelper.deleteTempContentFolder(server.getServerDirectory()); + } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -334,7 +333,7 @@ private void installOWAs(Server server, DistroProperties distroProperties) throw owasDir.mkdir(); downloadOWAs(server.getServerDirectory(), distroProperties, owasDir); } - } + } private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir) throws MojoExecutionException { @@ -346,21 +345,7 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - - private void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties) throws MojoExecutionException { - if (distroProperties != null) { - File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); - List contents = distroProperties.getContentArtifacts(); - - if (!contents.isEmpty()) { - for (Artifact content : contents) { - wizard.showMessage("Downloading Content: " + content + "\n"); - ContentHelper.downloadContent(serverDirectory, content, moduleInstaller, targetDir); - } - } - } - } + } /** * Sets the configuration folder for the specified server using the provided distro properties. diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index efd8da58c..f2073169d 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; @@ -22,15 +23,19 @@ public class ContentHelper { public static final String FRONTEND_CONFIG_FOLDER = File.separator + "configs" + File.separator + "frontend_config"; public static final String BACKEND_CONFIG_FOLDER = "configs" + File.separator + "backend_config"; - public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { - - String artifactId = contentArtifact.getArtifactId(); - //create a artifact folder under temp_content - File sourceDir = new File(serverDirectory, TEMP_CONTENT_FOLDER + File.separator + artifactId); - sourceDir.mkdirs(); - - moduleInstaller.installUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); - moveBackendConfig(artifactId, sourceDir, targetDir); + public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, + File targetDir) throws MojoExecutionException { + try { + String artifactId = contentArtifact.getArtifactId(); + //create a artifact folder under temp_content + File sourceDir = Files.createTempDirectory(TEMP_CONTENT_FOLDER + artifactId).toFile(); + + moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); + moveBackendConfig(artifactId, sourceDir, targetDir); + } + catch (Exception e) { + throw new MojoExecutionException("Error creating temp_content: " + e.getMessage(), e); + } } private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { @@ -79,17 +84,17 @@ public static List getContentFrontendConfigFiles(DistroProperties distroPr return contentConfigFiles; } - public static void deleteTempContentFolder(File serverDirectory) throws MojoExecutionException { - try { - File tempContentDir = new File(serverDirectory, TEMP_CONTENT_FOLDER); - - if (tempContentDir.exists()) { - FileUtils.deleteDirectory(tempContentDir); - } - } - catch (IOException e) { - throw new MojoExecutionException("Error deleting temp content directory: " + e.getMessage(), e); + public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInstaller, Wizard wizard) throws MojoExecutionException { + if (distroProperties != null) { + File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); + List contents = distroProperties.getContentArtifacts(); + + if (!contents.isEmpty()) { + for (Artifact content : contents) { + wizard.showMessage("Downloading Content: " + content + "\n"); + ContentHelper.downloadContent(serverDirectory, content, moduleInstaller, targetDir); + } + } } - } - + } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index e7cc8549c..856e01741 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -88,7 +88,7 @@ public void installModule(Artifact artifact, String outputDir) throws MojoExecut prepareModules(new Artifact[] { artifact }, outputDir, goal); } - public void installUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { + public void installAndUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { final String goal = GOAL_UNPACK; prepareModules(new Artifact[] { artifact }, outputDir, goal); } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 510f39f3e..4f1952b57 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -2,6 +2,10 @@ import org.apache.commons.lang.StringUtils; +import static org.openmrs.maven.plugins.model.BaseSdkProperties.ARTIFACT_ID; +import static org.openmrs.maven.plugins.model.BaseSdkProperties.GROUP_ID; +import static org.openmrs.maven.plugins.model.BaseSdkProperties.TYPE; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -151,16 +155,16 @@ public List getConfigArtifacts() { } public List getContentArtifacts() { - List artifacts = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); - if (key.startsWith(TYPE_CONTENT + ".")) { - String artifactId = key.substring(TYPE_CONTENT.length() + 1); - artifacts.add(new Artifact(artifactId, getParam(key), Artifact.GROUP_CONTENT, Artifact.TYPE_ZIP)); - } - } - return artifacts; - } + List artifacts = new ArrayList<>(); + for (Object keyObject : getAllKeys()) { + String key = keyObject.toString(); + if (key.startsWith(TYPE_CONTENT + ".")) { + artifacts.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), + checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); + } + } + return artifacts; + } protected Set getAllKeys() { return properties.keySet(); From 7db72c42b7501a493491b235a1fa1dada575fa9f Mon Sep 17 00:00:00 2001 From: nravilla Date: Sun, 22 Sep 2024 22:53:58 -0400 Subject: [PATCH 25/31] Changes based on PR code review-formatting fix --- .../java/org/openmrs/maven/plugins/Setup.java | 11 +++-- sdk-commons/.classpath | 40 +++++++++++++++++++ sdk-commons/.project | 23 +++++++++++ .../org.eclipse.core.resources.prefs | 5 +++ .../.settings/org.eclipse.jdt.core.prefs | 8 ++++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ .../plugins/model/BaseSdkProperties.java | 4 -- 7 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 sdk-commons/.classpath create mode 100644 sdk-commons/.project create mode 100644 sdk-commons/.settings/org.eclipse.core.resources.prefs create mode 100644 sdk-commons/.settings/org.eclipse.jdt.core.prefs create mode 100644 sdk-commons/.settings/org.eclipse.m2e.core.prefs diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 77714e3d5..2db239b35 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,8 +65,7 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; - + private static final int DEFAULT_PORT = 8080; /** * DB Driver type @@ -281,10 +280,10 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - } + } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -345,8 +344,8 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * diff --git a/sdk-commons/.classpath b/sdk-commons/.classpath new file mode 100644 index 000000000..f7e4a1dd5 --- /dev/null +++ b/sdk-commons/.classpath @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk-commons/.project b/sdk-commons/.project new file mode 100644 index 000000000..cbb5e32cf --- /dev/null +++ b/sdk-commons/.project @@ -0,0 +1,23 @@ + + + sdk-commons + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/sdk-commons/.settings/org.eclipse.core.resources.prefs b/sdk-commons/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..839d647ee --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding/=UTF-8 diff --git a/sdk-commons/.settings/org.eclipse.jdt.core.prefs b/sdk-commons/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..2f5cc74c3 --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/sdk-commons/.settings/org.eclipse.m2e.core.prefs b/sdk-commons/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 000000000..f897a7f1c --- /dev/null +++ b/sdk-commons/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 4f1952b57..8e0b154a2 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -2,10 +2,6 @@ import org.apache.commons.lang.StringUtils; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.ARTIFACT_ID; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.GROUP_ID; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.TYPE; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; From 57484dba19f88e05da3eef3f19cd3f6463e8bb31 Mon Sep 17 00:00:00 2001 From: nravilla Date: Sun, 22 Sep 2024 23:10:25 -0400 Subject: [PATCH 26/31] formatting fix --- .../main/java/org/openmrs/maven/plugins/Setup.java | 11 +++++------ .../maven/plugins/model/BaseSdkProperties.java | 4 ---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 77714e3d5..2db239b35 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,8 +65,7 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; - + private static final int DEFAULT_PORT = 8080; /** * DB Driver type @@ -281,10 +280,10 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - } + } installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -345,8 +344,8 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 4f1952b57..8e0b154a2 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -2,10 +2,6 @@ import org.apache.commons.lang.StringUtils; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.ARTIFACT_ID; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.GROUP_ID; -import static org.openmrs.maven.plugins.model.BaseSdkProperties.TYPE; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; From 8ddadf534654c1d96919054a06914f84090aaf2c Mon Sep 17 00:00:00 2001 From: nravilla Date: Sun, 22 Sep 2024 23:35:52 -0400 Subject: [PATCH 27/31] Removed accidently added eclipse files --- sdk-commons/.classpath | 40 ------------------- sdk-commons/.project | 23 ----------- .../org.eclipse.core.resources.prefs | 5 --- .../.settings/org.eclipse.jdt.core.prefs | 8 ---- .../.settings/org.eclipse.m2e.core.prefs | 4 -- 5 files changed, 80 deletions(-) delete mode 100644 sdk-commons/.classpath delete mode 100644 sdk-commons/.project delete mode 100644 sdk-commons/.settings/org.eclipse.core.resources.prefs delete mode 100644 sdk-commons/.settings/org.eclipse.jdt.core.prefs delete mode 100644 sdk-commons/.settings/org.eclipse.m2e.core.prefs diff --git a/sdk-commons/.classpath b/sdk-commons/.classpath deleted file mode 100644 index f7e4a1dd5..000000000 --- a/sdk-commons/.classpath +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sdk-commons/.project b/sdk-commons/.project deleted file mode 100644 index cbb5e32cf..000000000 --- a/sdk-commons/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - sdk-commons - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/sdk-commons/.settings/org.eclipse.core.resources.prefs b/sdk-commons/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 839d647ee..000000000 --- a/sdk-commons/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/main/resources=UTF-8 -encoding//src/test/java=UTF-8 -encoding/=UTF-8 diff --git a/sdk-commons/.settings/org.eclipse.jdt.core.prefs b/sdk-commons/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 2f5cc74c3..000000000 --- a/sdk-commons/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/sdk-commons/.settings/org.eclipse.m2e.core.prefs b/sdk-commons/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1c..000000000 --- a/sdk-commons/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 From c5e8d41c9b247a3fd209a6ddb045f89fcb580ffc Mon Sep 17 00:00:00 2001 From: nravilla Date: Sun, 22 Sep 2024 23:39:29 -0400 Subject: [PATCH 28/31] Changes based on PR code review --- .../java/org/openmrs/maven/plugins/BuildDistro.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index bed57cd6a..49c3ef023 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -294,9 +294,8 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File owasDir = new File(tempDir, "bundledOwas"); owasDir.mkdir(); - downloadOWAs(targetDirectory, distroProperties, owasDir); - //downloadAndMoveContentBackendConfig(targetDirectory, distroProperties); - spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); + downloadOWAs(targetDirectory, distroProperties, owasDir); + spaInstaller.installFromDistroProperties(tempDir, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); File frontendDir = new File(tempDir, "frontend"); if(frontendDir.exists()) { frontendDir.renameTo(new File(tempDir, "bundledFrontend")); @@ -304,7 +303,6 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro warfile.addFolder(tempDir, new ZipParameters()); try { - //ContentHelper.deleteTempContentFolder(targetDirectory); FileUtils.deleteDirectory(tempDir); } catch (IOException e) { @@ -325,7 +323,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); - setConfigFolder(configDir, distroProperties, distroArtifact); + setConfigFolder(configDir, distroProperties, distroArtifact); ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); @@ -621,5 +619,6 @@ public boolean accept(File dir, String name) { throw new MojoExecutionException("Distro should contain only single war file"); } } - } + } + } From 2e8af3f5f41a72961d08ad9f3ec7f0fc2c9e0f73 Mon Sep 17 00:00:00 2001 From: nravilla Date: Mon, 23 Sep 2024 10:16:40 -0400 Subject: [PATCH 29/31] Reverted changes regarding OS temp directory --- .../openmrs/maven/plugins/BuildDistro.java | 3 +- .../java/org/openmrs/maven/plugins/Setup.java | 10 +++--- .../maven/plugins/utility/ContentHelper.java | 36 +++++++++++-------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index 49c3ef023..e40e44c4d 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -326,7 +326,8 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro setConfigFolder(configDir, distroProperties, distroArtifact); ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - + ContentHelper.deleteTempContentFolder(web); + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 2db239b35..07951f8ea 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,7 +65,8 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; + private static final int DEFAULT_PORT = 8080; + /** * DB Driver type @@ -280,10 +281,11 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); setConfigFolder(server, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } + ContentHelper.deleteTempContentFolder(server.getServerDirectory()); installOWAs(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); @@ -344,8 +346,8 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index f2073169d..f06027939 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; @@ -23,19 +22,15 @@ public class ContentHelper { public static final String FRONTEND_CONFIG_FOLDER = File.separator + "configs" + File.separator + "frontend_config"; public static final String BACKEND_CONFIG_FOLDER = "configs" + File.separator + "backend_config"; - public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, - File targetDir) throws MojoExecutionException { - try { - String artifactId = contentArtifact.getArtifactId(); - //create a artifact folder under temp_content - File sourceDir = Files.createTempDirectory(TEMP_CONTENT_FOLDER + artifactId).toFile(); - - moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); - moveBackendConfig(artifactId, sourceDir, targetDir); - } - catch (Exception e) { - throw new MojoExecutionException("Error creating temp_content: " + e.getMessage(), e); - } + public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { + + String artifactId = contentArtifact.getArtifactId(); + //create a artifact folder under temp_content + File sourceDir = new File(serverDirectory, TEMP_CONTENT_FOLDER + File.separator + artifactId); + sourceDir.mkdirs(); + + moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); + moveBackendConfig(artifactId, sourceDir, targetDir); } private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { @@ -84,6 +79,19 @@ public static List getContentFrontendConfigFiles(DistroProperties distroPr return contentConfigFiles; } + public static void deleteTempContentFolder(File serverDirectory) throws MojoExecutionException { + File tempContentDir = new File(serverDirectory, TEMP_CONTENT_FOLDER); + try { + if (tempContentDir.exists()) { + FileUtils.deleteDirectory(tempContentDir); + } + } + catch (IOException e) { + throw new MojoExecutionException("Failed to delete temporary content folder at: " + + tempContentDir.getAbsolutePath() + " due to: " + e.getMessage(), e); + } + } + public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInstaller, Wizard wizard) throws MojoExecutionException { if (distroProperties != null) { File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); From 9e9e4d235ce313e4f16b09adae1764ef7c24a412 Mon Sep 17 00:00:00 2001 From: nravilla Date: Mon, 23 Sep 2024 10:23:50 -0400 Subject: [PATCH 30/31] Formatting fix --- .../main/java/org/openmrs/maven/plugins/BuildDistro.java | 3 +-- .../src/main/java/org/openmrs/maven/plugins/Setup.java | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index e40e44c4d..c10fbb1d9 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -327,7 +327,7 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); ContentHelper.deleteTempContentFolder(web); - + File owasDir = new File(web, "owa"); owasDir.mkdir(); downloadOWAs(targetDirectory, distroProperties, owasDir); @@ -621,5 +621,4 @@ public boolean accept(File dir, String name) { } } } - } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index 07951f8ea..e1f460704 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -65,8 +65,7 @@ public class Setup extends AbstractServerTask { private static final String NO_DEBUGGING_DEFAULT_ANSWER = "no debugging"; - private static final int DEFAULT_PORT = 8080; - + private static final int DEFAULT_PORT = 8080; /** * DB Driver type @@ -346,8 +345,8 @@ private void downloadOWAs(File targetDirectory, DistroProperties distroPropertie owaHelper.downloadOwa(owasDir, owa, moduleInstaller); } } - } - + } + /** * Sets the configuration folder for the specified server using the provided distro properties. * From 1fefe4411559fb183a7c3cb87ceda5f9185cbbc4 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 24 Sep 2024 14:50:56 -0400 Subject: [PATCH 31/31] Code review and some improvements --- .../openmrs/maven/plugins/BuildDistro.java | 5 +- .../java/org/openmrs/maven/plugins/Setup.java | 7 +- .../maven/plugins/utility/ContentHelper.java | 95 ++++++------------- .../plugins/utility/ModuleInstaller.java | 42 +++++--- .../plugins/model/BaseSdkProperties.java | 15 ++- 5 files changed, 80 insertions(+), 84 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java index c10fbb1d9..91ef6bdef 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java @@ -324,9 +324,10 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configDir.mkdir(); setConfigFolder(configDir, distroProperties, distroArtifact); + ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); + spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); - ContentHelper.deleteTempContentFolder(web); File owasDir = new File(web, "owa"); owasDir.mkdir(); @@ -513,7 +514,7 @@ private void writeTemplatedFile(File targetDirectory, String version, String pat } private String adjustImageName(String part) { - return part.replaceAll("\\s+", "").toLowerCase(); + return part != null ? part.replaceAll("\\s+", "").toLowerCase() : ""; } private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExecutionException { diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java index e1f460704..b71f17fa2 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java @@ -279,13 +279,16 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE setServerVersionsFromDistroProperties(server, distroProperties); distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper); - setConfigFolder(server, distroProperties); + ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); } - ContentHelper.deleteTempContentFolder(server.getServerDirectory()); + installOWAs(server, distroProperties); + + setConfigFolder(server, distroProperties); } else { moduleInstaller.installDefaultModules(server); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java index f06027939..06168e42c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ContentHelper.java @@ -3,9 +3,8 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.Collection; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; import org.apache.commons.io.FileUtils; @@ -18,78 +17,46 @@ */ public class ContentHelper { - public static final String TEMP_CONTENT_FOLDER = "temp-content"; - public static final String FRONTEND_CONFIG_FOLDER = File.separator + "configs" + File.separator + "frontend_config"; - public static final String BACKEND_CONFIG_FOLDER = "configs" + File.separator + "backend_config"; + public static final String FRONTEND_CONFIG_FOLDER = Paths.get("configs", "frontend_config").toString(); + public static final String BACKEND_CONFIG_FOLDER = Paths.get("configs", "backend_config").toString(); - public static void downloadContent(File serverDirectory, Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { - + public static void downloadContent(Artifact contentArtifact, ModuleInstaller moduleInstaller, File targetDir) throws MojoExecutionException { String artifactId = contentArtifact.getArtifactId(); - //create a artifact folder under temp_content - File sourceDir = new File(serverDirectory, TEMP_CONTENT_FOLDER + File.separator + artifactId); - sourceDir.mkdirs(); - - moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); + // create a temporary artifact folder + File sourceDir; + try { + sourceDir = Files.createTempDirectory("openmrs-sdk-" + artifactId + "-").toFile(); + } catch (IOException e) { + throw new MojoExecutionException("Exception while trying to create temporary directory", e); + } + + moduleInstaller.installAndUnpackModule(contentArtifact, sourceDir.getAbsolutePath()); moveBackendConfig(artifactId, sourceDir, targetDir); + + FileUtils.deleteQuietly(sourceDir); } private static void moveBackendConfig(String artifactId, File sourceDir, File targetDir) throws MojoExecutionException { try { - File backendConfigFiles = new File(sourceDir, BACKEND_CONFIG_FOLDER); - - for (File config : backendConfigFiles.listFiles()) { - // Find a corresponding directory in the configurationDir with the same name as backendConfig - File matchingConfigurationDir = new File(targetDir, config.getName()); - File destDir = null; - if (!matchingConfigurationDir.exists() || !matchingConfigurationDir.isDirectory()) { - // Folder doesn't exist so create it - matchingConfigurationDir.mkdirs(); - destDir = matchingConfigurationDir; + File backendConfigFiles = sourceDir.toPath().resolve(BACKEND_CONFIG_FOLDER).toFile(); + Path targetPath = targetDir.toPath().toAbsolutePath(); + + if (backendConfigFiles.exists()) { + File[] configDirectories = backendConfigFiles.listFiles(File::isDirectory); + if (configDirectories != null) { + for (File config : configDirectories) { + Path destDir = targetPath.resolve(config.getName()).resolve(artifactId); + Files.createDirectories(destDir); + + //copy config files to the matching configuration folder + FileUtils.copyDirectory(config, destDir.toFile()); + } } - // Create a new artifact folder under the matching configuration folder - destDir = new File(matchingConfigurationDir, artifactId); - - //copy config files to the matching configuration folder - FileUtils.copyDirectory(config, destDir); } } catch (IOException e) { throw new MojoExecutionException("Error copying backend configuration: " + e.getMessage(), e); } - } - - public static List getContentFrontendConfigFiles(DistroProperties distroProperties, File serverDirectory) { - List contentConfigFiles = new ArrayList(); - - List artifacts = distroProperties.getContentArtifacts(); - if (artifacts != null) { - for (Artifact artifact : artifacts) { - String artifactId = artifact.getArtifactId(); - File artifactFrontendDir = new File(serverDirectory, - TEMP_CONTENT_FOLDER + File.separator + artifactId + FRONTEND_CONFIG_FOLDER); - - // Add all files from the artifact directory - if (artifactFrontendDir.exists() && artifactFrontendDir.isDirectory()) { - //just include json files and set recursive to true - Collection files = FileUtils.listFiles(artifactFrontendDir, null, true); - contentConfigFiles.addAll(files); - } - } - } - return contentConfigFiles; - } - - public static void deleteTempContentFolder(File serverDirectory) throws MojoExecutionException { - File tempContentDir = new File(serverDirectory, TEMP_CONTENT_FOLDER); - try { - if (tempContentDir.exists()) { - FileUtils.deleteDirectory(tempContentDir); - } - } - catch (IOException e) { - throw new MojoExecutionException("Failed to delete temporary content folder at: " - + tempContentDir.getAbsolutePath() + " due to: " + e.getMessage(), e); - } } public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInstaller, Wizard wizard) throws MojoExecutionException { @@ -97,10 +64,10 @@ public static void downloadAndMoveContentBackendConfig(File serverDirectory, Dis File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); List contents = distroProperties.getContentArtifacts(); - if (!contents.isEmpty()) { + if (contents != null) { for (Artifact content : contents) { wizard.showMessage("Downloading Content: " + content + "\n"); - ContentHelper.downloadContent(serverDirectory, content, moduleInstaller, targetDir); + ContentHelper.downloadContent(content, moduleInstaller, targetDir); } } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index 856e01741..07b337890 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -1,5 +1,6 @@ package org.openmrs.maven.plugins.utility; +import org.apache.commons.io.FileUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; @@ -10,7 +11,11 @@ import org.twdata.maven.mojoexecutor.MojoExecutor; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.twdata.maven.mojoexecutor.MojoExecutor.Element; @@ -29,6 +34,8 @@ */ public class ModuleInstaller { + private static final String GOAL_COPY = "copy"; + private static final String GOAL_UNPACK = "unpack"; final MavenProject mavenProject; @@ -74,23 +81,31 @@ public void installModulesForDistro(Server server, DistroProperties properties, } public void installModules(List artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts.toArray(new Artifact[0]), outputDir, goal); + prepareModules(artifacts.toArray(new Artifact[0]), outputDir, GOAL_COPY); } public void installModules(Artifact[] artifacts, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(artifacts, outputDir, goal); + prepareModules(artifacts, outputDir, GOAL_COPY); } public void installModule(Artifact artifact, String outputDir) throws MojoExecutionException { - final String goal = "copy"; - prepareModules(new Artifact[] { artifact }, outputDir, goal); + prepareModules(new Artifact[] { artifact }, outputDir, GOAL_COPY); } - + public void installAndUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { - final String goal = GOAL_UNPACK; - prepareModules(new Artifact[] { artifact }, outputDir, goal); + Path markersDirectory; + try { + markersDirectory = Files.createTempDirectory("openmrs-sdk-markers"); + } catch (IOException e) { + throw new MojoExecutionException("Error creating markers directory", e); + } + + prepareModules(new Artifact[] { artifact }, outputDir, GOAL_UNPACK, + element("overWriteSnapshots", "true"), + element("overWriteReleases", "true"), + element("markersDirectory", markersDirectory.toAbsolutePath().toString())); + + FileUtils.deleteQuietly(markersDirectory.toFile()); } /** @@ -100,7 +115,7 @@ public void installAndUnpackModule(Artifact artifact, String outputDir) throws M * @param goal * @throws MojoExecutionException */ - private void prepareModules(Artifact[] artifacts, String outputDir, String goal) throws MojoExecutionException { + private void prepareModules(Artifact[] artifacts, String outputDir, String goal, MojoExecutor.Element... additionalConfiguration) throws MojoExecutionException { MojoExecutor.Element[] artifactItems = new MojoExecutor.Element[artifacts.length]; for (int index = 0; index < artifacts.length; index++) { artifactItems[index] = artifacts[index].toElement(outputDir); @@ -108,10 +123,9 @@ private void prepareModules(Artifact[] artifacts, String outputDir, String goal) List configuration = new ArrayList<>(); configuration.add(element("artifactItems", artifactItems)); - if (goal.equals(GOAL_UNPACK)) { - configuration.add(element("overWriteSnapshots", "true")); - configuration.add(element("overWriteReleases", "true")); - } + + configuration.addAll(Arrays.asList(additionalConfiguration)); + executeMojo( plugin( groupId(SDKConstants.DEPENDENCY_PLUGIN_GROUP_ID), diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index 8e0b154a2..a75cce6d9 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -82,7 +82,7 @@ public void setVersion(String version){ } public String getName(){ - return getParam("name"); + return getParam("name", "openmrs"); } public void setName(String name){ @@ -249,7 +249,18 @@ else if (key.equals("distro.referenceapplication")) { * @param key * @return */ - public String getParam(String key) {return properties.getProperty(key); } + public String getParam(String key) { + return properties.getProperty(key); + } + + /** + * get param from properties + * @param key + * @return + */ + public String getParam(String key, String defaultValue) { + return properties.getProperty(key, defaultValue); + } public Artifact getModuleArtifact(String artifactId){ String key = TYPE_OMOD + "." + artifactId;