-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OZ-468: Add an Ozone archetype (#40)
- Loading branch information
Showing
28 changed files
with
1,845 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
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
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> |
103 changes: 103 additions & 0 deletions
103
maven-archetype/src/main/resources/META-INF/archetype-post-generate.groovy
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,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") | ||
|
57 changes: 57 additions & 0 deletions
57
maven-archetype/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,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
10
maven-archetype/src/main/resources/archetype-resources/.gitpod.yml
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,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
10
maven-archetype/src/main/resources/archetype-resources/README.md
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,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 | ||
|
||
### ${version} (in progress) |
Empty file.
Empty file.
Oops, something went wrong.