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

OZ-462: Ozone distro to repackage the O3 frontend #42

Merged
merged 6 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
62 changes: 60 additions & 2 deletions distro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Dependency versions -->
<referenceapplicationDistroVersion>3.0.0-beta.16</referenceapplicationDistroVersion>
<referenceapplicationDistroVersion>3.0.0-SNAPSHOT</referenceapplicationDistroVersion>
<odoo_initializerVersion>2.1.0</odoo_initializerVersion>
<commonreportsVersion>1.4.0-SNAPSHOT</commonreportsVersion>
<patientsummaryVersion>2.2.0</patientsummaryVersion>
Expand All @@ -52,6 +52,13 @@
<version>${referenceapplicationDistroVersion}</version>
</dependency>

<dependency>
<groupId>org.openmrs.distro</groupId>
<artifactId>referenceapplication-frontend</artifactId>
<type>zip</type>
<version>${referenceapplicationDistroVersion}</version>
</dependency>

<!-- Odoo addons-->
<dependency>
<groupId>net.mekomsolutions.odoo</groupId>
Expand Down Expand Up @@ -96,7 +103,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>Copy Odoo Initializer add-on</id>
Expand Down Expand Up @@ -183,6 +189,18 @@
</configuration>
</execution>

<execution>
<id>Unpack OpenMRS Ref App frontend configuration</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}/openmrs_frontend</outputDirectory>
<includeArtifactIds>referenceapplication-frontend</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>

Expand Down Expand Up @@ -310,6 +328,26 @@
</goals>
</execution>

<execution>
<id>Rename spa-assemble-config.json to reference-application-spa-assemble-config.json</id>
<phase>generate-resources</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/${project.artifactId}-${project.version}/configs/openmrs/frontend_assembly">
<fileset dir="${project.build.directory}/openmrs_frontend" />
<mapper from="spa-assemble-config.json" to="reference-application-spa-assemble-config.json" type="regexp" />
</copy>
<move todir="${project.build.directory}/openmrs_frontend">
<fileset dir="${project.build.directory}/openmrs_frontend" />
<mapper from="spa-assemble-config.json" to="reference-application-spa-assemble-config.json" type="regexp" />
</move>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>

<execution>
<id>Copy filtered OpenMRS configuration</id>
<phase>prepare-package</phase>
Expand All @@ -326,6 +364,7 @@
<goal>run</goal>
</goals>
</execution>

<execution>
<id>Copy filtered OpenMRS modules</id>
<phase>prepare-package</phase>
Expand Down Expand Up @@ -362,6 +401,25 @@
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<id>Build OpenMRS Frontend</id>
<goals>
<goal>execute</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<scripts>
<script>file://${project.basedir}/../scripts/openmrs/frontend_assembly/build-openmrs-frontend.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>

<!-- packaging the distro as a installable/deployable file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
26 changes: 26 additions & 0 deletions maven-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.groovy.version>4.0.18</maven.groovy.version>
</properties>

<build>
Expand Down Expand Up @@ -61,6 +62,31 @@
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>3.0.2</version>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${maven.groovy.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-ant</artifactId>
<version>${maven.groovy.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>${maven.groovy.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.openmrs.maven.plugins</groupId>
<artifactId>openmrs-packager-maven-plugin</artifactId>
Expand Down
80 changes: 80 additions & 0 deletions maven-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<type>zip</type>
<version>${ozone.version}</version>
</dependency>
<dependency>
<groupId>com.ozonehis</groupId>
<artifactId>ozone-scripts</artifactId>
<type>zip</type>
<version>${ozone.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -61,6 +67,18 @@
<includeArtifactIds>ozone</includeArtifactIds>
</configuration>
</execution>
<execution>
<id>Unpack Ozone Scripts</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}</outputDirectory>
<includeArtifactIds>ozone-scripts</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>

Expand Down Expand Up @@ -94,6 +112,49 @@
</configuration>
</execution>

<execution>
<!-- Copy reference-application-spa-assemble-config.json to frontend working directory -->
<id>Copy reference-application-spa-assemble-config.json to local working directory</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/openmrs_frontend</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.directory}/ozone/distro/configs/openmrs/frontend_assembly</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>

<execution>
<!-- Copy local spa-assemble-config.json if any -->
<id>Copy spa-assemble-config.json</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/openmrs_frontend
</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.basedir}/configs/openmrs/frontend_assembly</directory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this path correct?
I thought the frontend assembly config file was moved to scripts/.
Anyway, I don't see it in /configs/openmrs/frontend_assembly either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step copies the implementation-specific spa-assemble-config.json file, if any. I didn't change that location, but I can if it makes more sense in scripts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK we can leave it at this place.
But shouldn't this be distro/configs/openmrs/frontend_assembly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the implementation-specific projects, we usually don't have a distro sub-folder...

<includes>
<include>spa-assemble-config.json</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>

<execution>
<!-- Copy and substitute some helper files (for demo and Gitpod) -->
<id>Copy and substitute some helper files</id>
Expand Down Expand Up @@ -182,6 +243,25 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<id>Rebuild OpenMRS Frontend if necessary</id>
<goals>
<goal>execute</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<scripts>
<script>file://${project.build.directory}/openmrs/frontend_assembly/build-openmrs-frontend.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<modules>
<module>maven-commons</module>
<module>maven-parent</module>
<module>scripts</module>
<module>distro</module>
</modules>

Expand Down
16 changes: 16 additions & 0 deletions scripts/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
<id>zip-scripts-dir</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>.</outputDirectory>
<directory>${project.build.directory}/${project.artifactId}-${project.version}</directory>
</fileSet>
</fileSets>
</assembly>
47 changes: 47 additions & 0 deletions scripts/openmrs/frontend_assembly/build-openmrs-frontend.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.nio.file.Paths

log.info("Checking for frontend customizations in ${Paths.get("${project.build.directory}", "openmrs_frontend", "spa-assemble-config.json").toString()}")

def refAppConfigFile = Paths.get("${project.build.directory}", "openmrs_frontend", "reference-application-spa-assemble-config.json").toFile()
def slurper = new groovy.json.JsonSlurper()
def refAppConfig = slurper.parse(refAppConfigFile)
def openmrsVersion = refAppConfig["coreVersion"] ?: "next"

def assembleCommand = "npx --legacy-peer-deps openmrs@${openmrsVersion} assemble --manifest --mode config --target ${project.build.directory}/${project.artifactId}-${project.version}/binaries/openmrs/frontend --config ${refAppConfigFile.getAbsolutePath()}"
log.info("Project: ${project.groupId}:${project.artifactId}")
// by default, we build the frontend as part of Ozone and only rebuild if there are local customizations
def shouldBuildFrontend = "${project.groupId}" == "com.ozonehis" && "${project.artifactId}" == "ozone-distro"

if (!shouldBuildFrontend) {
frontendCustomizationsFile = Paths.get("${project.build.directory}", "openmrs_frontend", "spa-assemble-config.json").toFile()
if (frontendCustomizationsFile.exists()) {
log.info("Found frontend customizations. Rebuilding frontend...")

assembleCommand += "--config ${frontendCustomizationsFile.getAbsolutePath()}"
shouldBuildFrontend = true
}
}

if (shouldBuildFrontend) {
log.info("Running assemble command...")

def assembleProcess = assembleCommand.execute()
assembleProcess.consumeProcessOutput(System.out, System.err)
assembleProcess.waitFor()

if (assembleProcess.exitValue() != 0) {
throw new RuntimeException("'openmrs assemble' step failed. See previous messages for details.")
}

log.info("Running build command...")

def buildProcess = "npx --legacy-peer-deps openmrs@${openmrsVersion} build --config-url \$SPA_CONFIG_URLS --default-locale \$SPA_DEFAULT_LOCALE --target ${project.build.directory}/${project.artifactId}-${project.version}/binaries/openmrs/frontend".execute()
buildProcess.consumeProcessOutput(System.out, System.err)
buildProcess.waitFor()

if (buildProcess.exitValue() != 0) {
throw new RuntimeException("'openmrs build' step failed. See previous messages for details.")
}
} else {
log.info("No need to re-build the frontend detected")
}
Loading
Loading