Skip to content

Commit

Permalink
Merge pull request #117 from PawelGutkowski/SDK-142
Browse files Browse the repository at this point in the history
SDK-142 Add add-feature goal
  • Loading branch information
AdamGrzybkowski authored Nov 29, 2016
2 parents 408eeb1 + 18e67fc commit 8e45bea
Show file tree
Hide file tree
Showing 13 changed files with 477 additions and 3 deletions.
38 changes: 38 additions & 0 deletions archetype-submodule-owa/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>openmrs-sdk</artifactId>
<groupId>org.openmrs.maven</groupId>
<version>3.4.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.openmrs.maven.archetypes</groupId>
<artifactId>openmrs-sdk-archetype-submodule-owa</artifactId>
<version>3.4.8-SNAPSHOT</version>
<packaging>maven-archetype</packaging>

<name>OpenMRS OWA Submodule Maven Archetype</name>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.2</version>
</extension>
</extensions>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="openmrs-sdk-archetype-submodule-owa"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<requiredProperties>
<requiredProperty key="moduleArtifactId"></requiredProperty>
</requiredProperties>

<fileSets>
<fileSet filtered="true" encoding="UTF-8">
<directory></directory>
<includes>
<include>assembly.xml</include>
</includes>
</fileSet>
</fileSets>

</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>dist</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>dist</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>**/*</include>
<include>*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>${moduleArtifactId}-owa</artifactId>
<groupId>${groupId}</groupId>
<version>${version}</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.0</version>
<executions>

<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>validate</phase>
<configuration>
<nodeVersion>v5.3.0</nodeVersion>
<npmVersion>3.9.6</npmVersion>
</configuration>
</execution>

<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>

<execution>
<id>npm build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build:prod</arguments>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>zip-owa</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.openmrs.maven.plugins;

import edu.emory.mathcs.backport.java.util.Arrays;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.openmrs.maven.plugins.utility.OwaHelper;
import org.openmrs.maven.plugins.utility.Project;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.openmrs.maven.plugins.utility.XmlHelper;

import java.io.File;
import java.util.List;
import java.util.Properties;

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;

/**
* @goal add-feature
* @requiresProject false
*/
public class AddFeature extends AbstractTask {

public static final String OPEN_WEB_APP = "Open Web App";
public static final String[] OPTIONS = {OPEN_WEB_APP};

/**
* feature user wants to add
*
* @parameter expression="${feature}"
*/
private String feature;

@Override
public void executeTask() throws MojoExecutionException, MojoFailureException {
if (Project.hasProject(new File(System.getProperty("user.dir")))) {
feature = wizard.promptForMissingValueWithOptions("What feature would you like to add?", feature, "feature", Arrays.asList(OPTIONS), null, null);
if(feature.equals(OPEN_WEB_APP) || feature.equals("owa")){
addOwaSubmodule();
} else {
throw new IllegalArgumentException("Adding feature "+feature+" is not available. Available features: "+OPTIONS);
}
} else {
throw new IllegalArgumentException("No project found in this directory. Please enter project's main directory and run this command again");
}
}

private void addOwaSubmodule() throws MojoExecutionException {
//apply changes to config.xml and main pom.xml
wizard.showMessage("Modifying pom.xml files...");
new XmlHelper().modifyXml(new File(mavenProject.getBasedir(), "omod"+File.separator+"pom.xml"), "archetype-submodule-owa/omod.pom.xml");
new XmlHelper().modifyXml(new File(mavenProject.getBasedir(), "omod"+File.separator+"src"+File.separator+"main"+File.separator+"resources"+File.separator+"config.xml"), "archetype-submodule-owa/config.xml");

//run archetype to create skeleton configuration for maven owa submodule
Properties properties = new Properties();
properties.setProperty("artifactId", "owa");
properties.setProperty("moduleArtifactId", mavenProject.getArtifactId());
properties.setProperty("groupId", mavenProject.getGroupId());
properties.setProperty("package", "owa");
properties.setProperty("version", mavenProject.getVersion());
mavenSession.getExecutionProperties().putAll(properties);

wizard.showMessage("Creating OWA submodule...");
executeMojo(
plugin(
groupId(SDKConstants.PLUGIN_ARCHETYPE_GROUP_ID),
artifactId(SDKConstants.PLUGIN_ARCHETYPE_ARTIFACT_ID),
version(SDKConstants.PLUGIN_ARCHETYPE_VERSION)
),
goal("generate"), configuration(
element("interactiveMode", "false"),
element("archetypeArtifactId", "openmrs-sdk-archetype-submodule-owa"),
element("archetypeGroupId", "org.openmrs.maven.archetypes"),
element("archetypeVersion", SDKConstants.getSDKInfo().getVersion())
),
executionEnvironment(mavenProject, mavenSession, pluginManager));

new OwaHelper(mavenSession, mavenProject, pluginManager, wizard)
.setInstallationDir(new File(mavenProject.getBasedir(),"owa"))
.createOwaProject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.openmrs.maven.plugins.utility.Wizard;
import org.twdata.maven.mojoexecutor.MojoExecutor;

import java.io.File;
Expand All @@ -31,12 +30,20 @@ public class OwaHelper {

private MavenSession session;

private File installationDir;

private MavenProject mavenProject;

private BuildPluginManager pluginManager;

private final Wizard wizard;

//enable chaining
public OwaHelper setInstallationDir(File installationDir) {
this.installationDir = installationDir;
return this;
}

public OwaHelper(MavenSession session, MavenProject mavenProject, BuildPluginManager pluginManager, Wizard wizard) {
this.session = session;
this.mavenProject = mavenProject;
Expand All @@ -45,7 +52,7 @@ public OwaHelper(MavenSession session, MavenProject mavenProject, BuildPluginMan
}

public void createOwaProject() throws MojoExecutionException {
File owaDir = prepareOwaDir();
File owaDir = installationDir != null ? installationDir : prepareOwaDir();

wizard.showMessage("Creating OWA project in " + owaDir.getAbsolutePath() + "...\n");

Expand All @@ -66,7 +73,7 @@ private File prepareOwaDir() {
File owaDir = new File(System.getProperty("user.dir"));
boolean pathCorrect = false;
do {
String owaDirValue = wizard.promptForValueIfMissingWithDefault("Please specify a directory for OWA project (a relative or absolute path)", null, null, null);
String owaDirValue = wizard.promptForValueIfMissingWithDefault("Please specify a directory for OWA project (a relative or absolute path)", owaDir.getName(), null, null);
File owaDirPath = new File(owaDirValue);
if (owaDirPath.isAbsolute()) {
owaDir = owaDirPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class SDKConstants {
public static final String PLUGIN_DEPENDENCIES_GROUP_ID = "org.apache.maven.plugins";
public static final String PLUGIN_DEPENDENCIES_ARTIFACT_ID = "maven-dependency-plugin";
public static final String PLUGIN_DEPENDENCIES_VERSION = "2.8";
// archetype plugin
public static final String PLUGIN_ARCHETYPE_GROUP_ID = "org.apache.maven.plugins";
public static final String PLUGIN_ARCHETYPE_ARTIFACT_ID = "maven-archetype-plugin";
public static final String PLUGIN_ARCHETYPE_VERSION = "2.4";
//docker plugin
public static final String PLUGIN_DOCKER_ARTIFACT_ID = "openmrs-sdk-docker-maven-plugin";
// release plugin
Expand Down
Loading

0 comments on commit 8e45bea

Please sign in to comment.