Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-298: SDK Setup should support non-interactive usage for all options #251

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

/**
* Enhance an existing module by adding a feature
*/
@Mojo(name = "add-feature", requiresProject = false)
public class AddFeature extends AbstractTask {

Expand Down
12 changes: 12 additions & 0 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@
import java.util.Properties;
import java.util.Set;

/**
* Build server's watched projects, OWA projects or node projects.
*/
@Mojo(name = "build", requiresProject = false)
public class Build extends AbstractServerTask {

/**
* Flag to indicate whether to build OWA projects.
*/
@Parameter(property = "buildOwa", defaultValue = "true")
private boolean buildOwa;

/**
* Version of npm to use for building node projects.
*/
@Parameter(property = "npmVersion")
protected String npmVersion;

/**
* Version of Node.js to use for building node projects.
*/
@Parameter(property = "nodeVersion")
protected String nodeVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import java.util.ArrayList;
import java.util.List;

/**
* Create docker configuration for distributions.
*/
@Mojo(name = "build-distro", requiresProject = false)
public class BuildDistro extends AbstractTask {

Expand Down Expand Up @@ -74,18 +77,33 @@ public class BuildDistro extends AbstractTask {

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
*/
@Parameter(property = "reuseNodeCache")
public Boolean overrideReuseNodeCache;

Expand All @@ -96,6 +114,9 @@ public class BuildDistro extends AbstractTask {
@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;

Expand Down
15 changes: 15 additions & 0 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Clone.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,37 @@

import static org.twdata.maven.mojoexecutor.MojoExecutor.*;

/**
* Clone any OpenMRS module repository
*/
@Mojo(name = "clone", requiresProject = false)
public class Clone extends AbstractTask {

public static final String GITHUB_COM = "github.com";

public static final String GITHUB_BASE_URL = "https://github.com/";

/**
* groupId of the module you want to clone.
*/
@Parameter(property = "groupId")
private String groupId;

/**
* artifactId of module You want to clone.
*/
@Parameter(property = "artifactId")
private String artifactId;

/**
* Github username
*/
@Parameter(property = "githubUsername")
private String username;

/**
* GitHub password or personal access token.
*/
@Parameter(property = "githubPassword", alias = "personalAccessToken")
private String personalAccessToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public class CreateProject extends AbstractTask {
@Parameter(defaultValue = "org.openmrs.maven.archetypes:", property = "filter")
private String filter;

/**
* The output directory.
*/
@Parameter(defaultValue = "${project.basedir}", property = "outputDirectory")
private File outputDirectory;

Expand Down
19 changes: 19 additions & 0 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Deploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,40 @@ public class Deploy extends AbstractServerTask {

private static final String DEPLOY_PLATFORM_OPTION = "Platform";

/**
* Artifact id of an artifact, which you want to deploy.
*/
@Parameter(property = "artifactId")
private String artifactId;

/**
* Group id of an artifact, which you want to deploy
*/
@Parameter(property = "groupId")
private String groupId;

/**
* Version of an artifact, which you want to deploy.
*/
@Parameter(property = "version")
private String version;

/**
* OpenMRS Distribution to set up in the format 'groupId:artifactId:version'.
* You can skip groupId, if it is 'org.openmrs.distro'. You can also give Path to distro.properties file
*/
@Parameter(property = "distro")
private String distro;

/**
* OpenMRS platform version.
*/
@Parameter(property = "platform")
private String platform;

/**
* Owa property in the format 'owa-name:version'
*/
@Parameter(property = "owa")
private String owa;

Expand Down
18 changes: 18 additions & 0 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Fetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

/**
* Fetch any OpenMRS module or OWA.
*/
@Mojo(name = "fetch", requiresProject = false)
public class Fetch extends AbstractTask {

Expand All @@ -35,18 +38,33 @@ public class Fetch extends AbstractTask {

private static final String DEFAULT_GROUP_ID = "org.openmrs.module";

/**
* artifactId of the module you want to fetch.
*/
@Parameter(property = "artifactId")
private String artifactId;

/**
* groupId of the module you want to fetch.
*/
@Parameter(property = "groupId")
private String groupId;

/**
* version of the module you want to fetch.
*/
@Parameter(property = "version")
private String version;

/**
* OWA you want to fetch.
*/
@Parameter(property = "owa")
private String owa;

/**
* The Directory the file should be fetched into. (Default to the current directory)"
*/
@Parameter(property = "dir")
private String dir;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.List;
import java.util.Properties;

/**
* Generates an openmrs-distro.properties file for a specific version of OpenMRS Distro
*/
@Mojo(name = "generate-distro", requiresProject = false)
public class GenerateDistro extends AbstractTask {

Expand All @@ -33,6 +36,9 @@ public class GenerateDistro extends AbstractTask {

private static final Logger logger = LoggerFactory.getLogger(GenerateDistro.class);

/**
* Specify the location where the file should be saved. (Default to current location)
*/
@Parameter(property = "output")
private String outputLocation;

Expand Down
80 changes: 19 additions & 61 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Help.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,32 @@
package org.openmrs.maven.plugins;

import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.ho.yaml.YamlDecoder;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.twdata.maven.mojoexecutor.MojoExecutor;

import java.io.EOFException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

@Mojo(name = "help", requiresProject = false)
public class Help extends AbstractTask {

private static final String HELP_FILE = "help.yaml";
private static final String DESC_MESSAGE = "Description: ";
private static final String INFO = "OpenMRS SDK %s";
private static final String WIKI = "https://wiki.openmrs.org/display/docs/OpenMRS+SDK";

public void executeTask() throws MojoExecutionException {
InputStream stream = getClass().getClassLoader().getResourceAsStream(HELP_FILE);
YamlDecoder dec = new YamlDecoder(stream);
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(4);
formatter.setDescPadding(8);
try {
@SuppressWarnings("unchecked")
Map<String, Object> keys = (Map<String, Object>) dec.readObject();
@SuppressWarnings("unchecked")
List<Map<String, Object>> l = (List<Map<String, Object>>) keys.get("help");
String printVersion = String.format(INFO, keys.get("version"));
String printWikiLink = "For more info, see SDK documentation: " + WIKI;
PrintWriter writer = new PrintWriter(System.out);
writer.println();
writer.println();
writer.println(printVersion);
writer.println();
writer.println(printWikiLink);
writer.println();
writer.println();
writer.flush();
if (l == null) {
throw new MojoExecutionException("Error during reading help data");
}
for (Map<String, Object> o: l) {
Options options = new Options();
@SuppressWarnings("unchecked")
List<Map<String, Object>> params = (List<Map<String, Object>>) o.get("options");
String header = (o.get("desc") != null) ? o.get("desc").toString() : "None";
header = DESC_MESSAGE.concat(header);
if (params != null) {
for (Map<String, Object> x: params) {
String name = x.get("name").toString();
String desc = x.get("desc").toString();
if ((name == null) || (desc == null)) throw new MojoExecutionException("Error in help file structure");
options.addOption(new Option(name, desc));
}
}
formatter.printHelp(o.get("name").toString(), header, options, "");
writer.println();
writer.flush();
}
writer.flush();
} catch (EOFException e) {
throw new MojoExecutionException(e.getMessage());
} finally {
dec.close();
}
List<MojoExecutor.Element> configuration = new ArrayList<>(3);
configuration.add(element("groupId", "org.openmrs.maven.plugins"));
configuration.add(element("artifactId", "openmrs-sdk-maven-plugin"));
configuration.add(element("version", mavenProject.getVersion()));
configuration.add(element("detail", "true"));
executeMojo(plugin(groupId(SDKConstants.HELP_PLUGIN_GROUP_ID), artifactId(SDKConstants.HELP_PLUGIN_ARTIFACT_ID), version(SDKConstants.HELP_PLUGIN_VERSION)), goal("describe"), configuration(configuration.toArray(new MojoExecutor.Element[0])), executionEnvironment(mavenProject, mavenSession, pluginManager));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import java.util.Set;

/**
* Display server details including the list of watched modules.
*/
@Mojo(name = "info", requiresProject = false)
public class Info extends AbstractServerTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.util.List;
import java.util.Set;

/**
* Pull changes from upstream for all watched projects or for any project if executed in its directory.
*/
@Mojo(name = "pull", requiresProject = false)
public class Pull extends AbstractServerTask {

Expand Down Expand Up @@ -64,6 +67,9 @@ public class Pull extends AbstractServerTask {

private static final String TEMP_BRANCH = "tempBranch";

/**
* Branch that is needed be pulled. (Default to 'master')
*/
@Parameter(property = "branch")
private String branch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import java.util.ArrayList;
import java.util.List;

/**
* Create or update pull request to any OpenMRS repository.
*/
@Mojo(name = "pr", requiresProject = false)
public class PullRequest extends AbstractTask {

/**
* Interactive mode flag, set for 'false' allows automatic testing in batch mode,
* as it makes all 'yes/no' prompts return 'yes'
/**
* The branch to create the pull request.
*/
@Parameter(defaultValue = "master", property = "branch")
String branch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.IOException;
import java.sql.SQLException;

/**
* Reset the server and its database to the initial state.
*/
@Mojo(name = "reset", requiresProject = false)
public class Reset extends AbstractServerTask {

Expand Down
Loading
Loading