-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from PawelGutkowski/SDK-142
SDK-142 Add add-feature goal
- Loading branch information
Showing
13 changed files
with
477 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
20 changes: 20 additions & 0 deletions
20
archetype-submodule-owa/src/main/resources/META-INF/maven/archetype-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
21 changes: 21 additions & 0 deletions
21
archetype-submodule-owa/src/main/resources/archetype-resources/assembly.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
76 changes: 76 additions & 0 deletions
76
archetype-submodule-owa/src/main/resources/archetype-resources/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
90 changes: 90 additions & 0 deletions
90
maven-plugin/src/main/java/org/openmrs/maven/plugins/AddFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.