Skip to content

Commit

Permalink
Use unpack to support use of schema plugins as artifacts (geonetwork#…
Browse files Browse the repository at this point in the history
…4701)

* Add choice to unpack or copy schema plugins
* Consistently use 3.11.0-SNAPSHOT
* Assemble schema plugins as zip archives and unpack into web
* Update readme instructions and add-schema.sh
* Add notes on how web-app is built
* Include comments in all the filters for ease of comparison
* Remove build process research from README.md into a core-geonetwork proposal
* Remove submodule and Include iso19115-3 directly
* Update example snippet in add-schema.sh
* Add escapes so schema-plugins.dir is used in generated web/pom.xml unpack
  • Loading branch information
jodygarnett authored Aug 7, 2020
1 parent 9433407 commit 4acb4aa
Show file tree
Hide file tree
Showing 350 changed files with 180,232 additions and 155 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ schematrons/.build
docs/*/users/build
docs/schema-loc-*.rst
web/src/main/webapp/WEB-INF/server.prop
*.bak
*.iml
.*/
*/.*
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@
[submodule "docs/manuals"]
path = docs/manuals
url = https://github.com/geonetwork/doc.git
[submodule "schemas/iso19115-3.2018"]
path = schemas/iso19115-3.2018
url = https://github.com/metadata101/iso19115-3.2018
105 changes: 69 additions & 36 deletions add-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function showUsage
echo -e "Usage: ./`basename $0 $1` schema_name git_schema_repository git_schema_branch"
echo
echo -e "Example:"
echo -e "\t./`basename $0 $1` iso19115-3 https://github.com/metadata101/iso19115-3 3.4.x"
echo -e "\t./`basename $0 $1` iso19139.ca.HNAP https://github.com/metadata101/iso19139.ca.HNAP 3.11.x"
echo
}

Expand Down Expand Up @@ -45,62 +45,95 @@ fi
# Add schema module in schemas/pom.xml
line=$(grep -n ${schema} schemas/pom.xml | cut -d: -f1)

if [ ! $line ]
if [ ! -n "$line" ]
then
line=$(grep -n 'iso19139</module>' schemas/pom.xml | cut -d: -f1)
line=$(grep -n '</profiles>' schemas/pom.xml | cut -d: -f1)
insertLine=$(($line - 1))

echo "Adding schema ${schema} to schemas/pom.xml"

sed $sedopt -f /dev/stdin schemas/pom.xml << SED_SCRIPT
${line} a\\
\ <module>${schema}</module>
${insertLine} a\\
\ <profile>\\
\ <id>schema-${schema}</id>\\
\ <activation>\\
\ <file><exists>${schema}</exists></file>\\
\ </activation>\\
\ <modules>\\
\ <module>${schema}</module>\\
\ </modules>\\
\ </profile>
SED_SCRIPT
fi


# Add schema dependency in web/pom.xml
line=$(grep -n "schema-${schema}" web/pom.xml | cut -d: -f1)

if [ ! $line ]
if [ ! -n "$line" ]
then
line=$(grep -n 'schema-iso19139</artifactId>' web/pom.xml | cut -d: -f1)
insertLine=$(($line + 2))

projectGroupId='${project.groupId}'
gnSchemasVersion='${gn.schemas.version}'
gnSchemasVersion='${project.version}'
basedir='${basedir}'

echo "Adding schema ${schema} dependency to web/pom.xml"
echo "Adding schema ${schema} dependency to web/pom.xml for schemaCopy"

line=$(grep -n '<!-- add schema_plugins -->' web/pom.xml | cut -d: -f1 | tail -1)
insertLine=$(($line))
sed $sedopt -f /dev/stdin web/pom.xml << SED_SCRIPT
${insertLine} a\\
\ <dependency>\\
\ <groupId>${projectGroupId}</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>
\ <dependency>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>
SED_SCRIPT
fi


# Add schema resources in web/pom.xml
line=$(grep -n "schemas/${schema}/src/main/plugin</directory>" web/pom.xml | cut -d: -f1)

if [ ! $line ]
then
line=$(grep -n 'schemas/iso19139/src/main/plugin</directory>' web/pom.xml | cut -d: -f1)
finalLine=$(($line + 3))

projectBaseDir='${project.basedir}'
baseDir='${basedir}'

echo "Adding schema ${schema} resources to web/pom.xml"
echo "Adding schema ${schema} dependency to web/pom.xml for schemaUnpack"

line=$(grep -n '</profiles>' web/pom.xml | cut -d: -f1)
insertLine=$(($line - 1))
sed $sedopt -f /dev/stdin web/pom.xml << SED_SCRIPT
${finalLine} a\\
\ <resource>\\
\ <directory>${projectBaseDir}/../schemas/${schema}/src/main/plugin</directory>\\
\ <targetPath>${baseDir}/src/main/webapp/WEB-INF/data/config/schema_plugins</targetPath>\\
\ </resource>
${insertLine} a\\
\ <profile>\\
\ <id>schema-${schema}</id>\\
\ <activation>\\
\ <property><name>schemasCopy</name><value>!true</value></property>\\
\ <file><exists>../schemas/${schema}</exists></file>\\
\ </activation>\\
\ <dependencies>\\
\ <dependency>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>\\
\ </dependencies>\\
\ <build>\\
\ <plugins>\\
\ <plugin>\\
\ <groupId>org.apache.maven.plugins</groupId>\\
\ <artifactId>maven-dependency-plugin</artifactId>\\
\ <executions>\\
\ <execution>\\
\ <id>${schema}-resources</id>\\
\ <phase>process-resources</phase>\\
\ <goals><goal>unpack</goal></goals>\\
\ <configuration>\\
\ <artifactItems>\\
\ <artifactItem>\\
\ <groupId>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <type>zip</type>\\
\ <overWrite>false</overWrite>\\
\ <outputDirectory>\$\{schema-plugins.dir\}</outputDirectory>\\
\ </artifactItem>\\
\ </artifactItems>\\
\ </configuration>\\
\ </execution>\\
\ </executions>\\
\ </plugin>\\
\ </plugins>\\
\ </build>\\
\ </profile>
SED_SCRIPT
fi

Expand Down
11 changes: 9 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand All @@ -422,9 +426,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.geonetwork-opensource.schemas</groupId>
<artifactId>schema-iso19139</artifactId>
<version>${gn.schemas.version}</version>
<version>${project.version}</version>
</dependency>
<dependency> <!-- dummy API for ARC SDE stuff -->
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -562,6 +566,7 @@
</build>

<profiles>

<profile>
<id>run-static-analysis</id>
<activation>
Expand All @@ -578,7 +583,9 @@
</plugins>
</build>
</profile>

</profiles>

<properties>
<rootProjectDir>${basedir}/..</rootProjectDir>
</properties>
Expand Down
12 changes: 8 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
Expand Down Expand Up @@ -228,12 +233,12 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -299,7 +304,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF-8 -Xmx1G</argLine>
<argLine>-Dfile.encoding=UTF-8 -Xmx1G -Djava.awt.headless=true</argLine>
<!--<rerunFailingTestsCount>5</rerunFailingTestsCount>-->
<runOrder>alphabetical</runOrder>
<forkCount>${system.numCores}</forkCount>
Expand Down Expand Up @@ -1541,6 +1546,5 @@
<xbean.version>3.18</xbean.version>
<jolokia.version>1.6.0</jolokia.version>
<httpcomponents.version>4.5.9</httpcomponents.version>
<gn.schemas.version>3.7</gn.schemas.version>
</properties>
</project>
4 changes: 2 additions & 2 deletions schemas-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.geonetwork-opensource.schemas</groupId>
<artifactId>schema-iso19139</artifactId>
<version>${gn.schemas.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
123 changes: 115 additions & 8 deletions schemas/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,124 @@
# Maven module containing schema plugins

## Plugin structure
## Schema Plugin Definition

A schema plugin is composed off:
1. `src/main/plugin/<folder>` contents:

* `schema-ident.xml` required configuration file
* schema definition `xsd` files
* transformations `xsl` files

See [GeoNetwork Manual](https://geonetwork-opensource.org/manuals/trunk/en/customizing-application/implementing-a-schema-plugin.html)

* A configuration folder containing XML file for configuration,
the schema as XSDs and a set of transformation (See http://geonetwork-opensource.org/manuals/trunk/eng/developer/schemaPlugins/index.html).
2. `src/main/java` providing:

* Optional: SchemaPlugin bean
* Optional: ApplicationListener<ServerStartup> to auto install plugin

* (optional) A SchemaPlugin bean
3. Schema plugin `pom.xml` are asked to bundle their `src/main/plugin` into a `zip`:

```xml
<!-- package up plugin folder as a zip -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>plugin-assembly</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<inherited>false</inherited>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/assembly/schema-plugin.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
```

4. Using a `src/assembly/schema-plugin.xml` assembly:

```xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>plugin</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/plugin/</directory>
<outputDirectory></outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
```

4. If you need to depend on any geonetwork modules please make use of `project.version` property:

```xml
<dependency>
<groupId>org.geonetwork-opensource</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
```

## Add a plugin to the build
5. The use of `project.version` is also required for schemas modules:

To include a new schema plugin in a build, copy the schema folder
here and add it to the copy-schemas execution in web/pom.xml.
```xml
<dependencies>
<dependency>
<groupId>org.geonetwork-opensource.schemas</groupId>
<artifactId>schema-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.geonetwork-opensource.schemas</groupId>
<artifactId>schema-iso19139</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
```

5. Use `mvn install` to install your schema plugin in your local repository.

## Optional: Add a plugin to the build

While schema plugins can be built independently, they can be conditionally included in the build:

1. Add schema plugin:

* As a folder, using `.gitignore` to avoid accidentally committing:

```
iso19139.xyz
```

* As a git submodule if you are making a fork
`
2. Use a profile (activated by your schema plugin folder being present) to include your schema plugin to the list of modules in `pom.xml`.

```xml
<profiles>
<profile>
<id>schema-iso19139.xyz</id>
<activation>
<file>
<exists>iso19139.xyz</exists>
</file>
</activation>
<modules>
<module>iso19139.xyz</module>
</modules>
</profile>
</profiles>
```

3. The `add-schema.sh` script automates these changes.

Loading

0 comments on commit 4acb4aa

Please sign in to comment.