-
Notifications
You must be signed in to change notification settings - Fork 11
/
MxInstall.mql
260 lines (227 loc) · 11.7 KB
/
MxInstall.mql
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
##############################################################################
#
# This file is part of MxUpdate <http://www.mxupdate.org>.
#
# MxUpdate is a deployment tool for a PLM platform to handle
# administration objects as single update files (configuration item).
#
# Copyright (C) 2008-2016 The MxUpdate Team - All Rights Reserved
#
# You may use, distribute and modify MxUpdate under the terms of the
# MxUpdate license. You should have received a copy of the MxUpdate
# license with this file. If not, please write to <[email protected]>,
# or visit <www.mxupdate.org>.
#
##############################################################################
tcl;
eval {
set VERSION "0-90-0"
set ENV_NAME_MXUPDATE_PATH "MXUPDATE_PATH"
set ENV_NAME_MAPPING_EXTENSION "MXUPDATE_MAPPING_FILE"
set ENV_NAME_DEVELOPMENT "MXUPDATE_DEVELOPMENT"
# get the installation directory
# is the installation directory defined as local MX environment variable?
if {[mql exists env "${ENV_NAME_MXUPDATE_PATH}"] > 0} {
set sRoot [mql get env "${ENV_NAME_MXUPDATE_PATH}"]
# maybe as global environment variable?
} elseif {[mql exists env global "${ENV_NAME_MXUPDATE_PATH}"] > 0} {
set sRoot [mql get env global "${ENV_NAME_MXUPDATE_PATH}"]
# or as shell enviroment variable?
} elseif {[info exists env(${ENV_NAME_MXUPDATE_PATH})] > 0} {
set sRoot $env(${ENV_NAME_MXUPDATE_PATH})
# otherwise error!!!!
} else {
error "\nRequired enviroment variable '${ENV_NAME_MXUPDATE_PATH}' is not defined!"
}
# get mapping file extension (if defined)
# is the mapping file extension defined as local MX environment variable?
if {[mql exists env "${ENV_NAME_MAPPING_EXTENSION}"] > 0} {
set sMappingFileExtension [mql get env "${ENV_NAME_MAPPING_EXTENSION}"]
# maybe as global environment variable?
} elseif {[mql exists env global "${ENV_NAME_MAPPING_EXTENSION}"] > 0} {
set sMappingFileExtension [mql get env global "${ENV_NAME_MAPPING_EXTENSION}"]
# or as shell enviroment variable?
} elseif {[info exists env(${ENV_NAME_MAPPING_EXTENSION})] > 0} {
set sMappingFileExtension $env(${ENV_NAME_MAPPING_EXTENSION})
} else {
set sMappingFileExtension ""
}
# check if development mode is used
# is the development mode is defined as local MX environment variable?
if {[mql exists env "${ENV_NAME_DEVELOPMENT}"] > 0} {
set bDevelopmentMode [mql get env "${ENV_NAME_DEVELOPMENT}"]
# maybe as global environment variable?
} elseif {[mql exists env global "${ENV_NAME_DEVELOPMENT}"] > 0} {
set bDevelopmentMode [mql get env global "${ENV_NAME_DEVELOPMENT}"]
# or as shell enviroment variable?
} elseif {[info exists env(${ENV_NAME_DEVELOPMENT})] > 0} {
set bDevelopmentMode $env(${ENV_NAME_DEVELOPMENT})
} else {
set bDevelopmentMode "false"
}
# define paths
set sRootJPOs [file join "${sRoot}" "src" "main" "java"]
set sMappingFileOriginal [file join "${sRoot}" "src" "main" "resources" "org" "mxupdate" "mapping.properties"]
set sLicenseFile [file join "${sRoot}" "LICENSE.md"]
############################################################################
# Read the mapping configuration between MX names and internal used names
############################################################################
proc pReadMapping {} {
global asMapping
global sMappingFileExtension
global sMappingFileOriginal
# read original mapping file
set pFile [open [file join "${sMappingFileOriginal}"] r]
set lsMapping [split [read $pFile] "\n"]
close $pFile
# read extension file (if defined)
if {"${sMappingFileExtension}" != ""} {
set pFile [open [file join "${sMappingFileExtension}"] r]
set lsMapping [concat $lsMapping [split [read $pFile] "\n"]]
close $pFile
}
# prepare mapping
foreach sOneLine ${lsMapping} {
set sOneLine [string trim "${sOneLine}"]
# check for none empty line and none comment line
if {([string length "${sOneLine}"] > 0) && ([string index "${sOneLine}" 0] != "#")} {
# equal index position
set iIdx [string first "=" "${sOneLine}"]
if {${iIdx} > 0} {
# extract key and value
set sKey [string trim [string range "${sOneLine}" 0 [expr ${iIdx} - 1]]]
set sVal [string trim [string range "${sOneLine}" [expr ${iIdx} + 1] end]]
set asMapping(${sKey}) "${sVal}"
}
}
}
}
##############################################################################
# The procedure installs given property within the given root path.
##############################################################################
proc pInstallProperties {_sVersion _sProgName} {
global asMapping
global sMappingFileExtension
global sMappingFileOriginal
global sLicenseFile
# if a file extension exists, both file dates must be checked!
set sFileDate [clock format [file mtime "${sMappingFileOriginal}"] -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]
if {"${sMappingFileExtension}" != ""} {
set sFileDate "${sFileDate}, [clock format [file mtime "${sMappingFileExtension}"] -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]"
}
set sFileDate "${sFileDate}, [clock format [file mtime "${sLicenseFile}"] -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]"
if {[mql list prog "${_sProgName}"] == ""} {
set sDate ""
mql add prog "${_sProgName}"
} else {
set sDate [mql print prog "${_sProgName}" select property\[$asMapping(PropertyDef.FileDate.PropertyName)\].value dump]
}
if {"${sDate}" != "${sFileDate}"} {
puts "update property '${_sProgName}'"
# read original properties
set pFile [open [file join "${sMappingFileOriginal}"] r]
set sCode [read $pFile]
close $pFile
# read extension file
if {"${sMappingFileExtension}" != ""} {
set pFile [open [file join "${sMappingFileExtension}"] r]
set sCode "${sCode}\n[read $pFile]"
close $pFile
}
# append license
# (hint: umlaute, sz and backslashes must be converted!)
set pFile [open "${sLicenseFile}" r]
fconfigure $pFile -encoding utf-8
set sLicense [string trim [read $pFile]]
close $pFile
regsub -all {\\} "${sLicense}" "\\\\\\\\" sLicense
regsub -all {\n\ } "${sLicense}" "\n\\u0020" sLicense
regsub -all {\u00A7} "${sLicense}" {\u00A7} sLicense
regsub -all {\u00C4} "${sLicense}" {\u00C4} sLicense
regsub -all {\u00D6} "${sLicense}" {\u00D6} sLicense
regsub -all {\u00DC} "${sLicense}" {\u00DC} sLicense
regsub -all {\u1E9E} "${sLicense}" {\u1E9E} sLicense
regsub -all {\u00E4} "${sLicense}" {\u00E4} sLicense
regsub -all {\u00F6} "${sLicense}" {\u00F6} sLicense
regsub -all {\u00FC} "${sLicense}" {\u00FC} sLicense
regsub -all {\u00DF} "${sLicense}" {\u00DF} sLicense
regsub -all {\n} "${sLicense}" "\\n\\\n " sLicense
set sCode "${sCode}\n\nParameterDef.ActionLicenseText.Default = ${sLicense}\n"
# update property program (with escape on because of special characters)
mql set escape on
mql mod prog ${_sProgName} \
code "${sCode}" \
add property $asMapping(PropertyDef.FileDate.PropertyName) value "${sFileDate}"
mql set escape off
}
}
##############################################################################
# The procedure installs given JPO within the given root path.
##############################################################################
proc pInstallJPO {_sVersion _sJPOName} {
global asMapping
global sRootJPOs
regsub -all {\.} "${_sJPOName}" {/} sFileName
set sFileName [file join "${sRootJPOs}" "${sFileName}_mxJPO.java"]
if {[mql list prog "${_sJPOName}"] == ""} {
set sJPODate ""
} else {
set sJPODate [mql print prog "${_sJPOName}" select property\[$asMapping(PropertyDef.FileDate.PropertyName)\].value dump]
}
# daylight saving problem... test +/- 1 hour
set iLastMod [file mtime "${sFileName}"]
set sFileDate [clock format ${iLastMod} -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]
set sFileDateP1 [clock format [expr ${iLastMod} + 3600] -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]
set sFileDateM1 [clock format [expr ${iLastMod} - 3600] -gmt true -format $asMapping(ParameterDef.InstallFileDateFormatTCL.Default)]
if {("${sJPODate}" != "${sFileDate}") && ("${sJPODate}" != "${sFileDateP1}") && ("${sJPODate}" != "${sFileDateM1}")} {
puts "update jpo '${_sJPOName}'"
mql insert prog "${sFileName}"
mql mod prog ${_sJPOName} \
add property "compiled" value "false" \
add property $asMapping(PropertyDef.FileDate.PropertyName) value "${sFileDate}"
}
}
############################################################################
# The procedure compiles all MxUpdate JPOs if required by testing property
# "compiled" on the MxUpdate JPOs (which all must be true, otherwise a
# compile with force update must be done).
# The compile with force update is only done if not in development mode!
############################################################################
proc pCompileJPO {} {
global bDevelopmentMode
set llsProgs [split [mql list prog org.mxupdate.*,MxUpdate select name property\[compiled\].value dump "\t"] "\n"]
set bCompile "false"
foreach lsOneProg ${llsProgs} {
set lsOneProg [split ${lsOneProg} "\t"]
if {([llength ${lsOneProg}] == 1) || ([lindex ${lsOneProg} 1] != "true")} {
set bCompile "true"
break
}
}
if {${bCompile} == "true"} {
puts "some JPOs are changed, complete recompile needed"
mql verbose on
if {${bDevelopmentMode} == "true"} {
puts "development mode! only simple compile is done!"
mql compile prog org.mxupdate.*,MxUpdate
} else {
mql compile prog org.mxupdate.*,MxUpdate force update
}
mql verbose off
foreach lsOneProg ${llsProgs} {
set lsOneProg [split ${lsOneProg} "\t"]
mql mod prog [lindex ${lsOneProg} 0] add property "compiled" value "true"
}
}
}
mql verbose off
mql set escape off
pReadMapping
pInstallProperties "${VERSION}" "org.mxupdate.mapping.properties"
pInstallJPO "${VERSION}" "org.mxupdate.install.Insert"
pInstallJPO "${VERSION}" "org.mxupdate.util.JPOHandler"
pInstallJPO "${VERSION}" "org.mxupdate.util.MqlBuilderUtil"
mql exec prog "org.mxupdate.install.Insert" "${sRootJPOs}" "${VERSION}" "$asMapping(ParameterDef.InstallFileDateFormatJava.Default)"
pCompileJPO
mql exec prog "org.mxupdate.install.InstallDataModel" "${VERSION}"
}