forked from georchestra/geonetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-schema.sh
executable file
·102 lines (78 loc) · 2.34 KB
/
add-schema.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
function showUsage
{
echo -e "\nThis script is used to add a metadata schema in GeoNetwork for development"
echo
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
}
if [ "$1" = "-h" ]
then
showUsage
exit
fi
if [ $# -ne 3 ]
then
showUsage
exit
fi
schema=$1
gitRepository=$2
gitBranch=$3
# Note: In MacOS (darwin10.0) sed requires -i .bak as option to work properly
if [[ ${OSTYPE:0:6} == 'darwin' ]]; then
sedopt='-i .bak'
else
sedopt='-i'
fi
# Add submodule
if [ ! -d "schemas/${schema}" ]; then
echo "Adding schema from ${gitRepository}, branch ${gitBranch} to schemas/${schema}"
git submodule add -b ${gitBranch} ${gitRepository} schemas/${schema}
fi
# Add schema module in schemas/pom.xml
line=$(grep -n ${schema} schemas/pom.xml | cut -d: -f1)
if [ ! $line ]
then
line=$(grep -n 'iso19139</module>' schemas/pom.xml | cut -d: -f1)
echo "Adding schema ${schema} to schemas/pom.xml"
sed $sedopt "${line} a\\
<module>${schema}</module>
" schemas/pom.xml
fi
# Add schema dependency in web/pom.xml
line=$(grep -n "schema-${schema}" web/pom.xml | cut -d: -f1)
if [ ! $line ]
then
line=$(grep -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
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"
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
fi