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 ee38cfaa7..26547baf9 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 @@ -17,13 +17,13 @@ import org.openmrs.maven.plugins.git.GitHelper; import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.utility.ConfigurationInstaller; +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.utility.DockerHelper; import org.openmrs.maven.plugins.utility.Jira; import org.openmrs.maven.plugins.utility.MavenEnvironment; 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.SpaInstaller; import org.openmrs.maven.plugins.utility.StatsManager; @@ -112,6 +112,11 @@ public abstract class AbstractTask extends AbstractMojo { */ DistroHelper distroHelper; + /** + * handles content packages + */ + ContentHelper contentHelper; + /** * handles OWAs */ @@ -162,6 +167,7 @@ public AbstractTask(AbstractTask other) { this.moduleInstaller = other.moduleInstaller; this.versionsHelper = other.versionsHelper; this.distroHelper = other.distroHelper; + this.contentHelper = other.contentHelper; this.owaHelper = other.owaHelper; this.spaInstaller = other.spaInstaller; this.configurationInstaller = other.configurationInstaller; @@ -193,25 +199,28 @@ public void initTask() { gitHelper = new DefaultGitHelper(); } if (versionsHelper == null) { - versionsHelper = new VersionsHelper(artifactFactory, mavenProject, mavenSession, artifactMetadataSource); + versionsHelper = new VersionsHelper(mavenEnvironment); } if (moduleInstaller == null) { - moduleInstaller = new ModuleInstaller(mavenProject, mavenSession, pluginManager, versionsHelper); + moduleInstaller = new ModuleInstaller(mavenEnvironment); } if (distroHelper == null) { distroHelper = new DistroHelper(mavenEnvironment); } if (owaHelper == null) { - owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard); + owaHelper = new OwaHelper(mavenEnvironment); + } + if (contentHelper == null) { + contentHelper = new ContentHelper(mavenEnvironment); } if (spaInstaller == null) { - spaInstaller = new SpaInstaller(distroHelper, new NodeHelper(mavenProject, mavenSession, pluginManager)); + spaInstaller = new SpaInstaller(mavenEnvironment); } if (configurationInstaller == null) { - configurationInstaller = new ConfigurationInstaller(distroHelper); + configurationInstaller = new ConfigurationInstaller(mavenEnvironment); } if (dockerHelper == null) { - dockerHelper = new DockerHelper(mavenProject, mavenSession, pluginManager, wizard); + dockerHelper = new DockerHelper(mavenEnvironment); } if (StringUtils.isNotBlank(openMRSPath)) { Server.setServersPath(openMRSPath); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddFeature.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddFeature.java index f352ea131..feafe0344 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddFeature.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddFeature.java @@ -61,9 +61,9 @@ public void executeTask() throws MojoExecutionException { } private void addOwaSubmodule() throws MojoExecutionException { - new OwaHelper(mavenSession, mavenProject, pluginManager, wizard) - .setInstallationDir(new File(mavenProject.getBasedir(), "owa")) - .createOwaProject(); + OwaHelper owaHelper = new OwaHelper(getMavenEnvironment()); + owaHelper.setInstallationDir(new File(mavenProject.getBasedir(), "owa")); + owaHelper.createOwaProject(); //apply changes to config.xml and main pom.xml wizard.showMessage("Modifying pom.xml files..."); 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 6df9fbb00..bef9b2d35 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 @@ -16,7 +16,6 @@ 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.ContentHelper; import org.openmrs.maven.plugins.utility.DistributionBuilder; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.SDKConstants; @@ -300,7 +299,7 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION); configurationInstaller.installToDirectory(configDir, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(web, distroProperties, moduleInstaller, wizard); + contentHelper.downloadAndMoveContentBackendConfig(web, distroProperties); spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateProject.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateProject.java index 2d66ad3ca..bb86cc422 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateProject.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateProject.java @@ -207,7 +207,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { setProjectType(); if (TYPE_OWA.equals(type)) { - new OwaHelper(mavenSession, mavenProject, pluginManager, wizard).createOwaProject(); + new OwaHelper(getMavenEnvironment()).createOwaProject(); } else { createModule(); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Delete.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Delete.java index b72fb4161..593bd6bd1 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Delete.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Delete.java @@ -25,7 +25,7 @@ public void executeTask() throws MojoExecutionException { FileUtils.deleteDirectory(server.getServerDirectory()); if (StringUtils.isNotBlank(server.getContainerId())) { - new DockerHelper(mavenProject, mavenSession, pluginManager, wizard).runDbContainer( + new DockerHelper(getMavenEnvironment()).runDbContainer( server.getContainerId(), server.getMySqlPort(), server.getDbUser(), diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Reset.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Reset.java index afe761f1e..38c4023fb 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/Reset.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/Reset.java @@ -26,7 +26,7 @@ public class Reset extends AbstractServerTask { public void executeTask() throws MojoExecutionException { Server server = getServer(); if (StringUtils.isNotBlank(server.getContainerId())){ - new DockerHelper(mavenProject, mavenSession, pluginManager, wizard).runDbContainer( + new DockerHelper(getMavenEnvironment()).runDbContainer( server.getContainerId(), server.getMySqlPort(), server.getDbUser(), diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java index 46161585d..c2f2d0b76 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/ServerUpgrader.java @@ -10,7 +10,6 @@ import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.UpgradeDifferential; import org.openmrs.maven.plugins.model.Version; -import org.openmrs.maven.plugins.utility.ContentHelper; import org.openmrs.maven.plugins.utility.SDKConstants; import java.io.File; @@ -161,7 +160,7 @@ public void upgradeToDistro(Server server, Distribution distribution, boolean ig } if (contentChanges.hasChanges()) { - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, parentTask.moduleInstaller, parentTask.wizard); + parentTask.contentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties); // TODO: Where is the frontend config installation? for (Artifact artifact : contentChanges.getArtifactsToRemove()) { server.removePropertiesForArtifact(BaseSdkProperties.TYPE_CONTENT, artifact); 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 2dbcd22d9..7e6c22d3f 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 @@ -13,7 +13,6 @@ 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.DistributionBuilder; import org.openmrs.maven.plugins.utility.SDKConstants; @@ -285,7 +284,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE distroHelper.parseContentProperties(distroProperties); moduleInstaller.installModulesForDistro(server, distroProperties); - ContentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties, moduleInstaller, wizard); + contentHelper.downloadAndMoveContentBackendConfig(server.getServerDirectory(), distroProperties); if (spaInstaller != null) { spaInstaller.installFromDistroProperties(server.getServerDirectory(), distroProperties, ignorePeerDependencies, overrideReuseNodeCache); diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java index f8d2f8048..008895d57 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ConfigurationInstaller.java @@ -18,12 +18,11 @@ public class ConfigurationInstaller { private final Wizard wizard; - private final ModuleInstaller moduleInstaller; - public ConfigurationInstaller(DistroHelper distroHelper) { - this.wizard = distroHelper.wizard; - this.moduleInstaller = new ModuleInstaller(distroHelper.mavenProject, distroHelper.mavenSession, distroHelper.pluginManager, distroHelper.versionHelper); + public ConfigurationInstaller(MavenEnvironment mavenEnvironment) { + this.wizard = mavenEnvironment.getWizard(); + this.moduleInstaller = new ModuleInstaller(mavenEnvironment); } /** 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 5a1a8ec39..3f7792718 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 @@ -1,5 +1,10 @@ package org.openmrs.maven.plugins.utility; +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; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -8,11 +13,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.maven.plugin.MojoExecutionException; -import org.openmrs.maven.plugins.model.Artifact; -import org.openmrs.maven.plugins.model.DistroProperties; - /** * This class downloads and moves content backend config to respective configuration folders. */ @@ -21,7 +21,15 @@ public class ContentHelper { 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(); - private static File unpackArtifact(Artifact contentArtifact, ModuleInstaller moduleInstaller) throws MojoExecutionException { + private final ModuleInstaller moduleInstaller; + private final Wizard wizard; + + public ContentHelper(MavenEnvironment mavenEnvironment) { + this.moduleInstaller = new ModuleInstaller(mavenEnvironment); + this.wizard = mavenEnvironment.getWizard(); + } + + private File unpackArtifact(Artifact contentArtifact) throws MojoExecutionException { String artifactId = contentArtifact.getArtifactId(); // create a temporary artifact folder File sourceDir; @@ -37,8 +45,8 @@ private static File unpackArtifact(Artifact contentArtifact, ModuleInstaller mod return sourceDir; } - private static void moveBackendConfig(Artifact contentArtifact, File targetDir, ModuleInstaller moduleInstaller) throws MojoExecutionException { - File sourceDir = unpackArtifact(contentArtifact, moduleInstaller); + private void moveBackendConfig(Artifact contentArtifact, File targetDir) throws MojoExecutionException { + File sourceDir = unpackArtifact(contentArtifact); try { File backendConfigFiles = sourceDir.toPath().resolve(BACKEND_CONFIG_FOLDER).toFile(); Path targetPath = targetDir.toPath().toAbsolutePath(); @@ -62,8 +70,8 @@ private static void moveBackendConfig(Artifact contentArtifact, File targetDir, } } - public static List extractAndGetAllContentFrontendConfigs(Artifact contentArtifact, ModuleInstaller moduleInstaller) throws MojoExecutionException { - File sourceDir = unpackArtifact(contentArtifact, moduleInstaller); + public List extractAndGetAllContentFrontendConfigs(Artifact contentArtifact) throws MojoExecutionException { + File sourceDir = unpackArtifact(contentArtifact); List configFiles = new ArrayList<>(); File frontendConfigFiles = sourceDir.toPath().resolve(FRONTEND_CONFIG_FOLDER).toFile(); @@ -83,7 +91,7 @@ public static List extractAndGetAllContentFrontendConfigs(Artifact content } // This method now sets the static moduleInstaller - public static void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties, ModuleInstaller moduleInstaller, Wizard wizard) throws MojoExecutionException { + public void downloadAndMoveContentBackendConfig(File serverDirectory, DistroProperties distroProperties) throws MojoExecutionException { if (distroProperties != null) { File targetDir = new File(serverDirectory, SDKConstants.OPENMRS_SERVER_CONFIGURATION); List contents = distroProperties.getContentArtifacts(); @@ -91,19 +99,19 @@ public static void downloadAndMoveContentBackendConfig(File serverDirectory, Dis if (contents != null) { for (Artifact content : contents) { wizard.showMessage("Downloading Content: " + content + "\n"); - moveBackendConfig(content, targetDir, moduleInstaller); + moveBackendConfig(content, targetDir); } } } } - public static List collectFrontendConfigs(DistroProperties distroProperties, ModuleInstaller moduleInstaller) throws MojoExecutionException { + public List collectFrontendConfigs(DistroProperties distroProperties) throws MojoExecutionException { List allConfigFiles = new ArrayList<>(); if (distroProperties != null) { List contents = distroProperties.getContentArtifacts(); if (contents != null) { for (Artifact contentArtifact : contents) { - allConfigFiles.addAll(extractAndGetAllContentFrontendConfigs(contentArtifact, moduleInstaller)); + allConfigFiles.addAll(extractAndGetAllContentFrontendConfigs(contentArtifact)); } } } 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 0028e25c0..23c6f3cc9 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 @@ -2,10 +2,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -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; @@ -41,26 +38,10 @@ public class ModuleInstaller { private static final String GOAL_UNPACK = "unpack"; - final MavenProject mavenProject; + final MavenEnvironment mavenEnvironment; - 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 ModuleInstaller(DistroHelper distroHelper) { - this(distroHelper.mavenProject, distroHelper.mavenSession, distroHelper.pluginManager, distroHelper.versionHelper); + public ModuleInstaller(MavenEnvironment mavenEnvironment) { + this.mavenEnvironment = mavenEnvironment; } public void installDefaultModules(Server server) throws MojoExecutionException { @@ -178,7 +159,11 @@ private void prepareModules(Artifact[] artifacts, String outputDir, String goal, ), goal(goal), configuration(configuration.toArray(new Element[0])), - executionEnvironment(mavenProject, mavenSession, pluginManager) + executionEnvironment( + mavenEnvironment.getMavenProject(), + mavenEnvironment.getMavenSession(), + mavenEnvironment.getPluginManager() + ) ); } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/NodeHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/NodeHelper.java index bc5c5e34c..283f2fd3c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/NodeHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/NodeHelper.java @@ -2,7 +2,6 @@ import org.apache.commons.lang3.SystemUtils; 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.Server; @@ -31,12 +30,7 @@ public class NodeHelper { public static Path tempDir; - private final MavenSession mavenSession; - - private final MavenProject mavenProject; - - private final BuildPluginManager pluginManager; - + private final MavenEnvironment mavenEnvironment; private static final Logger logger = LoggerFactory.getLogger(NodeHelper.class); @@ -44,10 +38,8 @@ public class NodeHelper { private static final String _OPENMRS_SDK_NODE_CACHE = "_openmrs_sdk_node_cache"; - public NodeHelper(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager) { - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; + public NodeHelper(MavenEnvironment mavenEnvironment) { + this.mavenEnvironment = mavenEnvironment; } private static File getNodeCache() { @@ -89,6 +81,7 @@ public void runNpx(String arguments, String npmArguments) throws MojoExecutionEx // it's a little weird to use a custom NPM cache for this; however, it seems to be necessary to get things working on Bamboo // hack added in December 2021; it's use probably should be re-evaluated at some point // additional hack: we do not use --cache on macs due to https://github.com/npm/cli/issues/3256 + MavenProject mavenProject = mavenEnvironment.getMavenProject(); if (mavenProject != null && mavenProject.getBuild() != null && !SystemUtils.IS_OS_MAC_OSX) { npmExec = npmArguments + " --cache=" + tempDir.resolve("npm-cache").toAbsolutePath() + " exec -- " + arguments; @@ -110,6 +103,7 @@ private void runFrontendMavenPlugin(String goal, List conf throws MojoExecutionException { // the proxy already works for installing node and npm; however, it does not work when running npm or npx if (goal != null && !goal.equalsIgnoreCase("install-node-and-npm")) { + MavenSession mavenSession = mavenEnvironment.getMavenSession(); NodeProxyHelper.ProxyContext proxyContext = NodeProxyHelper.setupProxyContext(mavenSession); proxyContext.applyProxyContext(configuration); } @@ -122,7 +116,11 @@ private void runFrontendMavenPlugin(String goal, List conf ), goal(goal), configuration(configuration.toArray(new MojoExecutor.Element[0])), - executionEnvironment(mavenProject, mavenSession, pluginManager) + executionEnvironment( + mavenEnvironment.getMavenProject(), + mavenEnvironment.getMavenSession(), + mavenEnvironment.getPluginManager() + ) ); } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/OwaHelper.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/OwaHelper.java index b339700d1..df044ce0c 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/OwaHelper.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/OwaHelper.java @@ -7,12 +7,11 @@ import com.github.zafarkhaja.semver.Version; import com.github.zafarkhaja.semver.expr.Expression; import com.github.zafarkhaja.semver.expr.ExpressionParser; +import lombok.Setter; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.SystemUtils; -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; @@ -46,55 +45,25 @@ import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; import static org.twdata.maven.mojoexecutor.MojoExecutor.version; +@Setter public class OwaHelper { + private static final Logger logger = LoggerFactory.getLogger(OwaHelper.class); + public static final String PACKAGE_JSON_FILENAME = "package.json"; public static final String NODE_VERSION_KEY = "node"; public static final String NPM_VERSION_KEY = "npm"; - public static final String OWA_PACKAGE_EXTENSION = ".owa"; - private MavenSession session; - - private File installationDir; - - private MavenProject mavenProject; - - private BuildPluginManager pluginManager; - + private MavenEnvironment mavenEnvironment; private Wizard wizard; + private File installationDir; - private static final Logger logger = LoggerFactory.getLogger(OwaHelper.class); - - //enable chaining - public OwaHelper setInstallationDir(File installationDir) { - this.installationDir = installationDir; - return this; - } - - public OwaHelper(){} - - public OwaHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager, Wizard wizard) { - this.session = session; - this.mavenProject = mavenProject; - this.pluginManager = pluginManager; - this.wizard = wizard; - } - - public void setWizard(Wizard wizard) { - this.wizard = wizard; - } - - public void setMavenProject(MavenProject mavenProject) { - this.mavenProject = mavenProject; - } - - public void setPluginManager(BuildPluginManager pluginManager) { - this.pluginManager = pluginManager; - } + public OwaHelper() {} - public void setSession(MavenSession session) { - this.session = session; + public OwaHelper(MavenEnvironment mavenEnvironment) { + this.mavenEnvironment = mavenEnvironment; + this.wizard = mavenEnvironment.getWizard(); } public void downloadOwa(File owaDir, Artifact owa, ModuleInstaller moduleInstaller) throws MojoExecutionException { @@ -454,6 +423,7 @@ public SemVersion getProjectNodeFromPackageJson() throws MojoExecutionException public PackageJson getPackageJson(String jsonFilename) throws MojoExecutionException { Reader reader = null; File json; + MavenProject mavenProject = mavenEnvironment.getMavenProject(); if (mavenProject == null) { json = new File(jsonFilename); } else { @@ -500,7 +470,11 @@ public void runLocalNpmCommandWithArgs(List arguments, String installDir ), goal("npm"), configuration(configuration.toArray(new MojoExecutor.Element[0])), - executionEnvironment(mavenProject, session, pluginManager) + executionEnvironment( + mavenEnvironment.getMavenProject(), + mavenEnvironment.getMavenSession(), + mavenEnvironment.getPluginManager() + ) ); } @@ -525,7 +499,11 @@ public void runSystemNpmCommandWithArgs(List arguments) throws MojoExecu ), goal("exec"), configuration(configuration.toArray(new MojoExecutor.Element[0])), - executionEnvironment(mavenProject, session, pluginManager) + executionEnvironment( + mavenEnvironment.getMavenProject(), + mavenEnvironment.getMavenSession(), + mavenEnvironment.getPluginManager() + ) ); } @@ -637,7 +615,11 @@ public void runInstallLocalNodeAndNpm(String nodeVersion, String npmVersion, Str ), goal("install-node-and-npm"), configuration(configuration.toArray(new MojoExecutor.Element[0])), - executionEnvironment(mavenProject, session, pluginManager) + executionEnvironment( + mavenEnvironment.getMavenProject(), + mavenEnvironment.getMavenSession(), + mavenEnvironment.getPluginManager() + ) ); } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java index 1817caac6..07f6b02c8 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.io.MoreFiles; import com.google.common.io.RecursiveDeleteOption; +import lombok.Setter; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -25,6 +26,7 @@ import static org.openmrs.maven.plugins.utility.PropertiesUtils.getSdkProperties; +@Setter public class SpaInstaller { static final String BAD_SPA_PROPERTIES_MESSAGE = "Distro properties file contains invalid 'spa.' elements. " @@ -36,25 +38,20 @@ public class SpaInstaller { static final String NPM_VERSION = "10.8.2"; - private final NodeHelper nodeHelper; - - private final DistroHelper distroHelper; - - private final ModuleInstaller moduleInstaller; - - private final Wizard wizard; + private NodeHelper nodeHelper; + private ModuleInstaller moduleInstaller; + private ContentHelper contentHelper; + private Wizard wizard; private static final Logger logger = LoggerFactory.getLogger(SpaInstaller.class); - - public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper) { - this(distroHelper, nodeHelper, new ModuleInstaller(distroHelper), distroHelper.wizard); - } - public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper, ModuleInstaller moduleInstaller, Wizard wizard) { - this.distroHelper = distroHelper; - this.nodeHelper = nodeHelper; - this.moduleInstaller = moduleInstaller; - this.wizard = wizard; + public SpaInstaller() {} + + public SpaInstaller(MavenEnvironment mavenEnvironment) { + this.nodeHelper = new NodeHelper(mavenEnvironment); + this.moduleInstaller = new ModuleInstaller(mavenEnvironment); + this.contentHelper = new ContentHelper(mavenEnvironment); + this.wizard = mavenEnvironment.getWizard(); } /** @@ -149,7 +146,7 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro nodeHelper.runNpx(String.format("%s assemble --target %s --mode config --config %s", program, buildTargetDir, spaConfigFile), legacyPeerDeps); } else { - List configFiles = ContentHelper.collectFrontendConfigs(distroProperties, moduleInstaller); + List configFiles = contentHelper.collectFrontendConfigs(distroProperties); String assembleCommand = assembleWithFrontendConfig(program, buildTargetDir, configFiles, spaConfigFile); nodeHelper.runNpx(assembleCommand, legacyPeerDeps); } diff --git a/maven-plugin/src/test/java/org/openmrs/maven/plugins/BuildOwaTest.java b/maven-plugin/src/test/java/org/openmrs/maven/plugins/BuildOwaTest.java index 2f7639ee2..7c059a5b7 100644 --- a/maven-plugin/src/test/java/org/openmrs/maven/plugins/BuildOwaTest.java +++ b/maven-plugin/src/test/java/org/openmrs/maven/plugins/BuildOwaTest.java @@ -13,6 +13,7 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.maven.plugins.model.NodeDistro; +import org.openmrs.maven.plugins.utility.MavenEnvironment; import org.openmrs.maven.plugins.utility.OwaHelper; import org.openmrs.maven.plugins.utility.OwaHelper.SemVersion; import org.openmrs.maven.plugins.utility.SDKConstants; @@ -39,6 +40,9 @@ public class BuildOwaTest { @Spy private OwaHelper owaHelper; + @Mock + private MavenEnvironment mavenEnvironment; + @Mock private Wizard wizard; @@ -57,7 +61,8 @@ public void setUp() { build.wizard = wizard; build.owaHelper = owaHelper; - owaHelper.setWizard(wizard); + build.owaHelper.setWizard(wizard); + build.owaHelper.setMavenEnvironment(mavenEnvironment); } @Test diff --git a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java index 917092370..fff6a34d1 100644 --- a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java +++ b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java @@ -33,9 +33,6 @@ public class SpaInstallerTest { SpaInstaller spaInstaller; - @Mock - DistroHelper distroHelper; - @Mock ModuleInstaller moduleInstaller; @@ -51,7 +48,10 @@ public class SpaInstallerTest { public void setup() throws Exception { appDataDir = new File(ResourceExtractor.simpleExtractResources(getClass(), "/test-tmp"), "server1"); appDataDir.mkdirs(); - spaInstaller = new SpaInstaller(distroHelper, nodeHelper, moduleInstaller, wizard); + spaInstaller = new SpaInstaller(); + spaInstaller.setModuleInstaller(moduleInstaller); + spaInstaller.setNodeHelper(nodeHelper); + spaInstaller.setWizard(wizard); } @After diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/PackageJson.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/PackageJson.java index 0bff1fc37..fc54b73e5 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/PackageJson.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/PackageJson.java @@ -1,111 +1,21 @@ package org.openmrs.maven.plugins.model; +import lombok.Data; + import java.util.List; import java.util.Map; +@Data public class PackageJson { - private String name; private String version; private String description; - private Map repository; private Map dependencies; private Map devDependencies; private Map engines; private Map scripts; - private List keywords; - private String author; private String license; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map getRepository() { - return repository; - } - - public void setRepository(Map repository) { - this.repository = repository; - } - - public Map getDependencies() { - return dependencies; - } - - public void setDependencies(Map dependencies) { - this.dependencies = dependencies; - } - - public Map getDevDependencies() { - return devDependencies; - } - - public void setDevDependencies(Map devDependencies) { - this.devDependencies = devDependencies; - } - - public Map getEngines() { - return engines; - } - - public void setEngines(Map engines) { - this.engines = engines; - } - - public Map getScripts() { - return scripts; - } - - public void setScripts(Map scripts) { - this.scripts = scripts; - } - - public List getKeywords() { - return keywords; - } - - public void setKeywords(List keywords) { - this.keywords = keywords; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getLicense() { - return license; - } - - public void setLicense(String license) { - this.license = license; - } - -} +} \ No newline at end of file diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java index adc77a51a..fbd095003 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java @@ -51,11 +51,11 @@ public class DockerHelper { private final BuildPluginManager pluginManager; private final Wizard wizard; - public DockerHelper(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager, Wizard wizard){ - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; - this.wizard = wizard; + public DockerHelper(MavenEnvironment mavenEnvironment) { + this.mavenProject = mavenEnvironment.getMavenProject(); + this.mavenSession = mavenEnvironment.getMavenSession(); + this.pluginManager = mavenEnvironment.getPluginManager(); + this.wizard = mavenEnvironment.getWizard(); } private Properties getSdkProperties() throws MojoExecutionException { diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/MavenEnvironment.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/MavenEnvironment.java index 3e895c159..1c35d3f66 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/MavenEnvironment.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/MavenEnvironment.java @@ -13,6 +13,7 @@ */ @Data public class MavenEnvironment { + private MavenProject mavenProject; private MavenSession mavenSession; private Settings settings; @@ -26,6 +27,6 @@ public ArtifactHelper getArtifactHelper() { } public VersionsHelper getVersionsHelper() { - return new VersionsHelper(artifactFactory, mavenProject, mavenSession, artifactMetadataSource); + return new VersionsHelper(this); } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java index 340a57eb1..a1568c207 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/SDKConstants.java @@ -103,6 +103,7 @@ public class SDKConstants { public static final String REFAPP_DISTRO = "referenceapplication-distro"; + public static final String CONTENT_PROPERTIES_NAME = "content.properties"; public static final String DISTRO_PROPERTIES_NAME = "openmrs-distro.properties"; public static final String DISTRO_PROPERTIES_NAME_SHORT = "distro.properties"; diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/VersionsHelper.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/VersionsHelper.java index 7d5695e23..6a2d79425 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/VersionsHelper.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/VersionsHelper.java @@ -1,18 +1,13 @@ package org.openmrs.maven.plugins.utility; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ComparableVersion; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource; import org.openmrs.maven.plugins.model.Artifact; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Optional; /** * Created by user on 27.05.16. @@ -21,45 +16,22 @@ public class VersionsHelper { public static final String NO_VERSION_AVAILABLE_MSG = "No version is available in remote repositories!"; - /** - * The project currently being build. - */ - private final MavenProject mavenProject; - - /** - * The current Maven session. - - */ - private final MavenSession mavenSession; - - /** - * The artifact metadata source to use. - - */ - private final ArtifactMetadataSource artifactMetadataSource; + private final MavenEnvironment mavenEnvironment; - /** - * utility to create maven artifacts - */ - private final ArtifactFactory artifactFactory; - - public VersionsHelper(ArtifactFactory artifactFactory, MavenProject mavenProject, MavenSession mavenSession, ArtifactMetadataSource artifactMetadataSource) { - this.artifactFactory = artifactFactory; - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.artifactMetadataSource = artifactMetadataSource; + public VersionsHelper(MavenEnvironment mavenEnvironment) { + this.mavenEnvironment = mavenEnvironment; } - private List getVersions(Artifact artifact){ + private List getVersions(Artifact artifact) { try { - return artifactMetadataSource.retrieveAvailableVersions( - artifactFactory.createArtifact( + return mavenEnvironment.getArtifactMetadataSource().retrieveAvailableVersions( + mavenEnvironment.getArtifactFactory().createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "", ""), - mavenSession.getLocalRepository(), - mavenProject.getRemoteArtifactRepositories() + mavenEnvironment.getMavenSession().getLocalRepository(), + mavenEnvironment.getMavenProject().getRemoteArtifactRepositories() ); } catch (ArtifactMetadataRetrievalException e) { //TODO @@ -67,31 +39,15 @@ private List getVersions(Artifact artifact){ } } - public List getAllVersions(Artifact artifact, int maxSize) { - List versions = getVersions(artifact); - sortDescending(versions); - Optional firstNonSnapshotVersion = versions.stream() - .filter(version -> !version.toString().endsWith("-SNAPSHOT")) - .findFirst(); - - if (firstNonSnapshotVersion.isPresent()) { - ArtifactVersion firstNonSnapshot = firstNonSnapshotVersion.get(); - versions.removeIf(version -> version.toString().endsWith("-SNAPSHOT") - && new ComparableVersion(version.toString()).compareTo(new ComparableVersion(firstNonSnapshot.toString())) < 0); - } - - return versions.subList(0, Math.min(versions.size(), maxSize)); - } - - private void sortDescending(List versions){ - Collections.sort(versions, (v1, v2) -> new ComparableVersion(v2.toString()).compareTo(new ComparableVersion(v1.toString()))); + private void sortDescending(List versions) { + versions.sort((v1, v2) -> new ComparableVersion(v2.toString()).compareTo(new ComparableVersion(v1.toString()))); } /** * @param artifact the Maven artifact to get the latest released version of * @return latest released version. if none is available, return snapshot. If list is empty, returns error message */ - public String getLatestReleasedVersion(Artifact artifact){ + public String getLatestReleasedVersion(Artifact artifact) { return getLatestReleasedVersion(getVersions(artifact)); } diff --git a/sdk-commons/src/test/java/org/openmrs/maven/plugins/utility/VersionsHelperTest.java b/sdk-commons/src/test/java/org/openmrs/maven/plugins/utility/VersionsHelperTest.java index 67948fa39..e118a6441 100644 --- a/sdk-commons/src/test/java/org/openmrs/maven/plugins/utility/VersionsHelperTest.java +++ b/sdk-commons/src/test/java/org/openmrs/maven/plugins/utility/VersionsHelperTest.java @@ -19,7 +19,7 @@ public class VersionsHelperTest { @Before public void before() { - helper = new VersionsHelper(null, null, null, null); + helper = new VersionsHelper(null); } private List createTestVersions(String... versions) { diff --git a/tomcat7-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java b/tomcat7-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java index 87263df5a..d3efa6e41 100644 --- a/tomcat7-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java +++ b/tomcat7-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java @@ -1,12 +1,5 @@ package org.openmrs.maven.plugins; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.catalina.Context; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; @@ -16,6 +9,8 @@ import org.apache.catalina.startup.Tomcat; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; @@ -24,6 +19,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; @@ -31,58 +27,69 @@ import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; import org.openmrs.maven.plugins.utility.DockerHelper; +import org.openmrs.maven.plugins.utility.MavenEnvironment; import org.openmrs.maven.plugins.utility.OpenMRSSDKRedirectServlet; import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.Wizard; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + @Mojo(name = "run-tomcat", requiresProject = false) public class RunTomcat 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; - @Parameter(property = "serverId") - private String serverId; + @Parameter(defaultValue = "${settings}", readonly = true) + Settings settings; - @Parameter(property = "port") - private Integer port; + @Component + BuildPluginManager pluginManager; - @Parameter(property = "watchApi") - private Boolean watchApi; + @Component + ArtifactMetadataSource artifactMetadataSource; - /** - * The Maven BuildPluginManager component. - */ @Component - BuildPluginManager pluginManager; + ArtifactFactory artifactFactory; @Component private Wizard wizard; - public RunTomcat() { - } + @Parameter(property = "serverId") + private String serverId; + + @Parameter(property = "port") + private Integer port; - public RunTomcat(String serverId, Integer port, MavenSession mavenSession, MavenProject mavenProject, - BuildPluginManager pluginManager, Wizard wizard) { - this.serverId = serverId; - this.port = port; - this.wizard = wizard; - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; + @Parameter(property = "watchApi") + private Boolean watchApi; + + MavenEnvironment mavenEnvironment; + + public void initTask() { + if (mavenEnvironment == null) { + mavenEnvironment = new MavenEnvironment(); + mavenEnvironment.setMavenProject(mavenProject); + mavenEnvironment.setMavenSession(mavenSession); + mavenEnvironment.setSettings(settings); + mavenEnvironment.setArtifactMetadataSource(artifactMetadataSource); + mavenEnvironment.setArtifactFactory(artifactFactory); + mavenEnvironment.setPluginManager(pluginManager); + mavenEnvironment.setWizard(wizard); + } } @Override public void execute() throws MojoExecutionException { + initTask(); wizard.showMessage("\nUsing JAVA_HOME: " + System.getProperty("java.home")); wizard.showMessage("Using MAVEN_OPTS: " + System.getenv("MAVEN_OPTS")); @@ -130,11 +137,12 @@ public void execute() throws MojoExecutionException { } if (StringUtils.isNotBlank(server.getContainerId())) { - new DockerHelper(mavenProject, mavenSession, pluginManager, wizard).runDbContainer( + new DockerHelper(mavenEnvironment).runDbContainer( server.getContainerId(), server.getDbUri(), server.getDbUser(), - server.getDbPassword()); + server.getDbPassword() + ); } wizard.showMessage("Starting Tomcat...\n"); diff --git a/tomcat9-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java b/tomcat9-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java index 56cac9e4d..996d62087 100644 --- a/tomcat9-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java +++ b/tomcat9-maven-plugin/src/main/java/org/openmrs/maven/plugins/RunTomcat.java @@ -9,6 +9,8 @@ import org.apache.catalina.startup.Tomcat; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; @@ -17,6 +19,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.DuplicateRealmException; @@ -24,6 +27,7 @@ import org.openmrs.maven.plugins.model.Server; import org.openmrs.maven.plugins.model.Version; import org.openmrs.maven.plugins.utility.DockerHelper; +import org.openmrs.maven.plugins.utility.MavenEnvironment; import org.openmrs.maven.plugins.utility.OpenMRSSDKRedirectServlet; import org.openmrs.maven.plugins.utility.SDKConstants; import org.openmrs.maven.plugins.utility.Wizard; @@ -38,51 +42,54 @@ @Mojo(name = "run-tomcat", requiresProject = false) public class RunTomcat 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; - @Parameter(property = "serverId") - private String serverId; + @Parameter(defaultValue = "${settings}", readonly = true) + Settings settings; - @Parameter(property = "port") - private Integer port; + @Component + BuildPluginManager pluginManager; - @Parameter(property = "watchApi") - private Boolean watchApi; + @Component + ArtifactMetadataSource artifactMetadataSource; - /** - * The Maven BuildPluginManager component. - */ @Component - BuildPluginManager pluginManager; + ArtifactFactory artifactFactory; @Component private Wizard wizard; - public RunTomcat() { - } + @Parameter(property = "serverId") + private String serverId; + + @Parameter(property = "port") + private Integer port; - public RunTomcat(String serverId, Integer port, MavenSession mavenSession, MavenProject mavenProject, - BuildPluginManager pluginManager, Wizard wizard) { - this.serverId = serverId; - this.port = port; - this.wizard = wizard; - this.mavenProject = mavenProject; - this.mavenSession = mavenSession; - this.pluginManager = pluginManager; + @Parameter(property = "watchApi") + private Boolean watchApi; + + MavenEnvironment mavenEnvironment; + + public void initTask() { + if (mavenEnvironment == null) { + mavenEnvironment = new MavenEnvironment(); + mavenEnvironment.setMavenProject(mavenProject); + mavenEnvironment.setMavenSession(mavenSession); + mavenEnvironment.setSettings(settings); + mavenEnvironment.setArtifactMetadataSource(artifactMetadataSource); + mavenEnvironment.setArtifactFactory(artifactFactory); + mavenEnvironment.setPluginManager(pluginManager); + mavenEnvironment.setWizard(wizard); + } } @Override public void execute() throws MojoExecutionException { + initTask(); wizard.showMessage("\nUsing JAVA_HOME: " + System.getProperty("java.home")); wizard.showMessage("Using MAVEN_OPTS: " + System.getenv("MAVEN_OPTS")); @@ -143,11 +150,12 @@ public void execute() throws MojoExecutionException { } if (StringUtils.isNotBlank(server.getContainerId())) { - new DockerHelper(mavenProject, mavenSession, pluginManager, wizard).runDbContainer( + new DockerHelper(mavenEnvironment).runDbContainer( server.getContainerId(), server.getDbUri(), server.getDbUser(), - server.getDbPassword()); + server.getDbPassword() + ); } wizard.showMessage("Starting Tomcat...\n");