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

Adds an Ozone Implementation archetype #40

Merged
merged 15 commits into from
Feb 16, 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: mekomsolutions/shared-github-workflow/.github/workflows/maven-build-test.yml@main
with:
java-version: "8"
maven-phase: "install"
maven-args: "-P validator" # OMRS config validation
secrets:
NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ozone

> The entreprise-grade health information system that augments OpenMRS 3.
> The enterprise-grade health information system that augments OpenMRS 3

# Quick start

Expand Down
34 changes: 34 additions & 0 deletions maven-archetype/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ozonehis</groupId>
<artifactId>maven-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../maven-commons</relativePath>
</parent>

<artifactId>maven-archetype</artifactId>
<packaging>maven-archetype</packaging>

<name>Ozone Implementation Archetype</name>
<description>A Maven Archetype for Ozone implementation projects</description>

<url>https://www.ozone-his.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.1</version>
</extension>
</extensions>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.nio.file.Path
import java.nio.file.Paths
import java.util.logging.Logger
import java.util.zip.ZipInputStream

import groovy.util.XmlParser

// directory of the newly created project
projectDirectory = Paths.get(request.outputDirectory, request.artifactId);

// utility to run a shell command
def run(String command) {
def process = command.execute(null, projectDirectory.toFile());
process.consumeProcessOutput(System.out, System.err)
process.waitFor()
if (process.exitValue() != 0) {
throw new RuntimeException("'$command' exited with code ${process.exitValue()}")
}
}

// utility to unzip files
def unzip(InputStream stream, Path destination) {
def destinationRootFile = destination.toFile()
final zipInput = new ZipInputStream(stream)
zipInput.withStream {
def entry
while (entry = zipInput.nextEntry) {
if (!entry.isDirectory()) {
final file = destination.resolve(entry.name).toFile()
checkForZipSlip(destinationRootFile, file)
new FileOutputStream(file).withStream {
it << zipInput
}
} else {
final dir = destination.resolve(entry.name).toFile()
checkForZipSlip(destinationRootFile, dir)
dir.mkdirs()
}
}
}
}

private static void checkForZipSlip(File destination, File dir) {
if (!dir.canonicalPath.startsWith(destination.canonicalPath)) {
throw new IllegalArgumentException("Attempt to unzip ($dir.canonicalPath) outside of destination ($destination.canonicalPath) rejected")
}
}

// rename gitignore to .gitignore
projectDirectory.resolve("gitignore").toFile().renameTo(projectDirectory.resolve(".gitignore").toFile())

// Download the Maven wrapper without directly using Maven to do so
// Less flexible, but beginner friendly!
def mavenWrapperVersions = "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper-distribution/maven-metadata.xml".toURL().text
def mavenWrapperXml = new XmlParser().parseText(mavenWrapperVersions)
def mavenWrapperVersion = mavenWrapperXml.versioning.release.text()

unzip(
(InputStream) "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper-distribution/${mavenWrapperVersion}/maven-wrapper-distribution-${mavenWrapperVersion}-bin.zip".toURL().newInputStream(),
projectDirectory.resolve("scripts")
)

def wrapperDir = projectDirectory.resolve("scripts").resolve(".mvn").resolve("wrapper")
def wrapperDirFile = wrapperDir.toFile()
wrapperDirFile.mkdirs()

def wrapperJarUrl = "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/${mavenWrapperVersion}/maven-wrapper-${mavenWrapperVersion}.jar"
wrapperJarUrl.toURL().newInputStream().withStream { wrapperJar ->
new FileOutputStream(wrapperDir.resolve("maven-wrapper.jar").toFile()).withStream {
it << wrapperJar
}
}

Logger log = Logger.getAnonymousLogger()
// determine the Maven version
// We default to the most recent non-alpha, non-snapshot Maven version
def mavenDistributionVersions = "https://repo.maven.apache.org/maven2/org/apache/maven/maven/maven-metadata.xml".toURL().text
def mavenDistributionVersionsXml = new XmlParser().parseText(mavenDistributionVersions)
def mavenVersion = mavenDistributionVersionsXml.versioning.versions.version.findAll({ version ->
!version.text().contains("-")
}).last().text()
log.info("Using Maven: ${mavenVersion}")


new FileOutputStream(wrapperDir.resolve("maven-wrapper.properties").toFile()).withStream {
it << "distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${mavenVersion}/apache-maven-${mavenVersion}-bin.zip\n"
it << "wrapperUrl=${wrapperJarUrl}\n"
}

def isWindows = System.properties["os.name"].toLowerCase().contains("windows")
if (!isWindows) {
run("chmod +x ${projectDirectory.resolve("scripts").resolve("mvnw").toString()}")
run("chmod +x ${projectDirectory.resolve("scripts").resolve("mvnwDebug").toString()}")
}

// set the version of the parent to the version of the archetype
// NB at this point, we just use the Maven wrapper to do things
def mvnwCommand = isWindows ?
projectDirectory.resolve("scripts").resolve("mvnw.cmd").toString() :
projectDirectory.resolve("scripts").resolve("mvnw").toString()

run("${mvnwCommand} versions:update-parent -DskipResolution -DparentVersion=${request.archetypeVersion} -DgenerateBackupPoms=false")

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 https://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="Ozone Distribution Archetype">

<requiredProperties>
<requiredProperty key="distributionName" />
<requiredProperty key="version">
<!-- Work-around for https://issues.apache.org/jira/browse/ARCHETYPE-308
By using an expression, we should prompt for the value, with a default of 1.0.0-SNAPSHOT -->
<defaultValue>${package.getClass().forName("java.lang.String").getConstructor($package.getClass().forName("java.lang.String")).newInstance("1.0.0-SNAPSHOT")}</defaultValue>
</requiredProperty>
</requiredProperties>

<fileSets>
<fileSet>
<directory>config</directory>
<includes>
<include>**/*.*</include>
</includes>
</fileSet>
<fileSet>
<directory />
<includes>
<include>gitignore</include>
</includes>
</fileSet>
<fileSet filtered="true">
<directory />
<includes>
<include>.gitpod.yml</include>
<include>README.md</include>
<include>readme/**/*.md</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>
10 changes: 10 additions & 0 deletions maven-archetype/src/main/resources/archetype-resources/.gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tasks:
- name: Run Ozone ${distributionName}
before: sudo apt-get update && sudo apt-get install -y gettext-base && sudo rm -rf /var/lib/apt/lists/*
init: ./scripts/mvnw clean package
command: source target/go-to-scripts-dir.sh && ./start.sh
ports:
- name: OpenMRS
description: OpenMRS 3
port: 80
onOpen: open-browser
10 changes: 10 additions & 0 deletions maven-archetype/src/main/resources/archetype-resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ozone ${distributionName}

**Ozone ${distributionName}** is a distribution of [Ozone HIS](https://www.ozone-his.com).

## Implementer Guide
A technical guide to help implementers building and running the project can be found [here](readme/impl-guide.md).

## Release Notes
ibacher marked this conversation as resolved.
Show resolved Hide resolved

### ${version} (in progress)
Loading
Loading