-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
add-schema.sh
executable file
·162 lines (138 loc) · 4.62 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/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` iso19139.ca.HNAP https://github.com/metadata101/iso19139.ca.HNAP 3.11.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 [ ! -n "$line" ]
then
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
${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 [ ! -n "$line" ]
then
gnSchemasVersion='${project.version}'
basedir='${basedir}'
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>org.geonetwork-opensource.schemas</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ </dependency>
SED_SCRIPT
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
${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
# Add schema resources in service/pom.xml with test scope for unit tests
line=$(grep -n "<artifactId>schema-${schema}</artifactId>" services/pom.xml | cut -d: -f1)
if [ ! $line ]
then
line=$(grep -n '</dependencies>' services/pom.xml | cut -d: -f1)
finalLine=$(($line - 1))
projectGroupId='org.geonetwork-opensource.schemas'
gnSchemasVersion='${project.version}'
echo "Adding schema ${schema} resources to service/pom.xml"
sed $sedopt -f /dev/stdin services/pom.xml << SED_SCRIPT
${finalLine} a\\
\ <dependency>\\
\ <groupId>${projectGroupId}</groupId>\\
\ <artifactId>schema-${schema}</artifactId>\\
\ <version>${gnSchemasVersion}</version>\\
\ <scope>test</scope>\\
\ </dependency>
SED_SCRIPT
fi