Skip to content

Commit

Permalink
Update based on feedback from Ian and Jose
Browse files Browse the repository at this point in the history
Signed-off-by: Jody Garnett <[email protected]>
  • Loading branch information
jodygarnett committed Jun 1, 2020
1 parent 4d589d2 commit 436259d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 43 deletions.
53 changes: 33 additions & 20 deletions add-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,34 @@ then

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

sed $sedopt "${line} a\\
<module>${schema}</module>
" schemas/pom.xml
sed $sedopt -f /dev/stdin schemas/pom.xml << SED_SCRIPT
${line} a\\
\ <module>${schema}</module>
SED_SCRIPT
fi


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

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

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

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

sed $sedopt "${insertLine} a\\
<dependency>\\
<groupId>${projectGroupId}</groupId>\\
<artifactId>schema-${schema}</artifactId>\\
<version>${gnSchemasVersion}</version>\\
</dependency>
" web/pom.xml
sed $sedopt -f /dev/stdin web/pom.xml << SED_SCRIPT
${insertLine} a\\
\ <dependency>\\
\ <groupId>${projectGroupId}</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>
SED_SCRIPT
fi


Expand All @@ -85,18 +87,29 @@ line=$(grep -n "schemas/${schema}/src/main/plugin</directory>" web/pom.xml | cut

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

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

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

sed $sedopt "${finalLine} a\\
<resource>\\
<directory>${projectBaseDir}/../schemas/${schema}/src/main/plugin</directory>\\
<targetPath>${baseDir}/src/main/webapp/WEB-INF/data/config/schema_plugins</targetPath>\\
</resource>
" web/pom.xml
sed $sedopt -f /dev/stdin web/pom.xml << SED_SCRIPT
${finalLine} a\\
\ <artifactItem>\\
\ <groupId>${projectGroupId}</groupId>\\
\ <artifactId>${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ <type>jar</type>\\
\ <overWrite>false</overWrite>\\
\ <outputDirectory>${basedir}/src/main/webapp/WEB-INF/data/config/schema_plugins</outputDirectory>\\
\ <includes>plugin/**</includes>\\
\ <fileMappers>\\
\ <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">\\
\ <pattern>^plugin/</pattern><replacement>./</replacement>\\
\ </fileMapper>\\
\ </fileMappers>\\
\ </artifactItem>\\
SED_SCRIPT
fi
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,5 @@
<jolokia.version>1.6.0</jolokia.version>
<httpcomponents.version>4.5.9</httpcomponents.version>
<gn.schemas.version>3.10-SNAPSHOT</gn.schemas.version>
<gn.schemas.version.range>[3.7,3.11]</gn.schemas.version.range>
</properties>
</project>
54 changes: 43 additions & 11 deletions schemas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

## Schema Plugin Definition

#. `src/main/plugin/<folder>` plugin contents:
1. `src/main/plugin/<folder>` contents:

* `schema-ident.xml` 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)
* `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)

#. `src/main/java` providing:
2. `src/main/java` providing:

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

#. Be sure your plugin includes `src/main/plugin`:
3. Schema plugin `pom.xml` must include `src/main/plugin` in resources section:

```xml
<resources>
Expand All @@ -28,24 +29,53 @@
</resources>
```

#. Use `mvn install` to install your schema plugin in your local repository.
4. If you need to depend on any modules please make use of:

* `gn.project.version` property for geonetwork modules:

```xml
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>common</artifactId>
<version>${gn.project.version}</version>
</dependency>
```

* `project.version` property for other schemas (or schema-core):

```
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19139</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
```

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

## Add a plugin to the build

While schema plugins can be built idependently, they can be conditionally included in 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 commiting.

* As a git submodule if you are making a fork
`
2. Use a profile (activated by your folder being present) to include your schema plugin to the list of modules in `pom.xml`.
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>iso19139.xyz</id>
<id>schema-iso19139.xyz</id>
<activation>
<file>
<exists>iso19139.xyz</exists>
Expand All @@ -57,4 +87,6 @@ While schema plugins can be built idependently, they can be conditionally includ
</profile>
</profiles>
```

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

26 changes: 18 additions & 8 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ If your plugin is not in the `schemas` folder:
mvn process-resources -Pschema-iso19139.xyz
```
5. Tip: If you commonly work with a set series of plugins you can manage via [settings.xml](https://maven.apache.org/settings.html).
5. Tip: If work with a set series of plugins you can manage via [settings.xml](https://maven.apache.org/settings.html).
## Including additional schema plugins
Expand All @@ -97,7 +97,7 @@ To include your schema plugin in `web/pom.xml`:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19115-3.2018</artifactId>
<version>${gn.schemas.version.range}</version>
<version>${gn.schemas.version}</version>
</dependency>
</dependencies>
<build>
Expand All @@ -116,7 +116,6 @@ To include your schema plugin in `web/pom.xml`:
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19115-3.2018</artifactId>
<version>${gn.schemas.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/data/config/schema_plugins</outputDirectory>
Expand All @@ -140,8 +139,8 @@ To include your schema plugin in `web/pom.xml`:
2. This profile example has several interesting features:

* Activates automatically if the `schemas/iso19115-3.2018` folder is present
* Disabled if `-DcopySchemas=true` property is set
* Adds a dependency using a version range so that the schema plugin jar is included
* Disabled if `-DschemasCopy=true` property is set
* Adds a dependency so that the schema plugin jar is included on the classpath
* Unpacks a `plugin` folder into the webapp `schema_plugins` folder

3. Over time we expect active metadata101 schema plugins be listed.
Expand All @@ -155,19 +154,21 @@ An alternative approach of copying folders is available using the `-DschemasCopy

To add your schema plugin to the `schemas-copy` profile:

1. Locate the `schemas-copys` profile in `pom.xml`:
1. Locate the `schemas-copy` profile in `web/pom.xml`:

2. Add your plugin as a dependency to the profile:

```xml
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19139.xyz</artifactId>
<version>${project.version}</version>
<version>${gn.schemas.version}</version>
</dependency>
```

3. By default each `src/main/plugin` folder in `schemas` is copied, if your plugin is in a different location:
3. By default each `src/main/plugin` folder in `schemas` is copied.

If your plugin is in not in the `schemas` folder:

```xml
<resource>
Expand All @@ -178,3 +179,12 @@ To add your schema plugin to the `schemas-copy` profile:
```

5. This approach modifies `web/pom.xml` so it can only be recommended in a fork or branch.

7. Implementation notes:

* The `<dependency>` added here makes use of a specific verion number.

* If your plugin is inheriting its version number from `schemas/pom.xml` you may use
the property `gn.schemas.version`.

6. The `add-schema.sh` script automates these changes.
4 changes: 1 addition & 3 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19115-3.2018</artifactId>
<version>${gn.schemas.version.range}</version>
<version>${gn.schemas.version}</version>
</dependency>
</dependencies>
<build>
Expand All @@ -868,12 +868,10 @@
<phase>process-resources</phase>
<goals><goal>unpack</goal></goals>
<configuration>
<encoding>UTF-8</encoding>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>schema-iso19115-3.2018</artifactId>
<version>${gn.schemas.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/data/config/schema_plugins</outputDirectory>
Expand Down

0 comments on commit 436259d

Please sign in to comment.