Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 276f82a

Browse files
committed
[[ ExtensionLoading ]] Improve efficiency of initial manifest parsing
1 parent 72b67b7 commit 276f82a

1 file changed

Lines changed: 63 additions & 45 deletions

File tree

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -299,36 +299,53 @@ private command __extensionDownloadVerify pCacheIndex
299299
set the itemdel to "."
300300
if the last item of tExtensionPath is not "lce" then return __extensionError(pCacheIndex,"Could not install extension. The package extension '"&the last item of tExtensionPath&"' Is not valid. Must be 'lce'.")
301301

302+
# Get initial manifest data needed for loading
303+
local tManifestData, tManifestXMLTree
304+
put __extensionManifestData(pCacheIndex) into tManifestData
305+
put revXMLCreateTree(tManifestData,true,true,false) into tManifestXMLTree
306+
302307
# Check the manifest contains a name
303308
local tExtensionName
304-
put __extensionManifestValue(pCacheIndex, "name") into tExtensionName
305-
if tExtensionName is "error" then return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid name (com.livecode.extensions.<developer_ID>.<extension_name>)")
309+
put __extensionManifestValueFromTree(tManifestXMLTree, "name") into tExtensionName
310+
if the result is not empty then
311+
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid name (com.livecode.extensions.<developer_ID>.<extension_name>)")
312+
end if
306313
__extensionPropertySet pCacheIndex, "name", tExtensionName
307314

308315
# Check the manifest contains a version
309316
local tExtensionVersion
310-
put __extensionManifestValue(pCacheIndex, "version") into tExtensionVersion
311-
if tExtensionVersion is "error" then return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid version number (1.2.3 - major,minor,maintenance)")
317+
put __extensionManifestValueFromTree(tManifestXMLTree, "version") into tExtensionVersion
318+
if the result is not empty then
319+
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid version number (1.2.3 - major,minor,maintenance)")
320+
end if
312321
__extensionPropertySet pCacheIndex, "version", tExtensionVersion
313322

314323
# Check the manifest contains an author
315324
local tExtensionAuthor
316-
put __extensionManifestValue(pCacheIndex, "author") into tExtensionAuthor
317-
if tExtensionAuthor is "error" then return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain an author")
325+
put __extensionManifestValueFromTree(tManifestXMLTree, "author") into tExtensionAuthor
326+
if the result is not empty then
327+
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain an author")
328+
end if
318329
__extensionPropertySet pCacheIndex, "author", tExtensionAuthor
319330

320331
# Check the manifest contains an type
321332
local tExtensionType
322-
put __extensionManifestValue(pCacheIndex, "type") into tExtensionType
323-
if tExtensionType is "error" then return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a type")
333+
put __extensionManifestValueFromTree(tManifestXMLTree, "type") into tExtensionType
334+
if the result is not empty then
335+
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a type")
336+
end if
324337
__extensionPropertySet pCacheIndex, "type", tExtensionType
325338

326339
# Check the manifest contains an title
327340
local tExtensionTitle
328-
put __extensionManifestValue(pCacheIndex, "title") into tExtensionTitle
329-
if tExtensionTitle is "error" then return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a title")
341+
put __extensionManifestValueFromTree(tManifestXMLTree, "title") into tExtensionTitle
342+
if the result is not empty then
343+
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a title")
344+
end if
330345
__extensionPropertySet pCacheIndex, "title", tExtensionTitle
331346

347+
revXMLDeleteTree tManifestXMLTree
348+
332349
# Build the type ID from the name and version
333350
__extensionPropertySet pCacheIndex, "type_id", tExtensionName & "." & tExtensionVersion
334351
end __extensionDownloadVerify
@@ -1259,7 +1276,40 @@ function revIDEExtensionFetchDefaultScript pFolder, pCacheIndex, pValidate
12591276
return tScript
12601277
end revIDEExtensionFetchDefaultScript
12611278

1262-
function __extensionManifestValue pCacheIndex, pProperty
1279+
private function __extensionManifestValueFromTree pTreeID, pProperty
1280+
local tValue
1281+
switch pProperty
1282+
case "requires"
1283+
# Fetch extension dependencies
1284+
local tRequires, tCount
1285+
put 0 into tCount
1286+
put revXMLChildNames(pTreeID,"package",return,"requires",true) into tRequires
1287+
if tRequires begins with "xmlerr" then
1288+
put tRequires into tValue
1289+
break
1290+
end if
1291+
repeat for each line tDependency in tRequires
1292+
add 1 to tCount
1293+
local tName
1294+
put revXMLAttribute(pTreeID,"package" & "/" & tDependency,"name") into tName
1295+
if tName begins with "xmlerr" then
1296+
put tName into tValue
1297+
break
1298+
end if
1299+
put tName into tValue[tCount]
1300+
end repeat
1301+
default
1302+
put revXMLNodeContents(pTreeID,"/package/" & pProperty) into tValue
1303+
break
1304+
end switch
1305+
1306+
if tValue begins with "xmlerr" then
1307+
return tValue for error
1308+
end if
1309+
return tValue for value
1310+
end __extensionManifestValueFromTree
1311+
1312+
private function __extensionManifestData pCacheIndex
12631313
# Get the path to the package file
12641314
local tExtensionPackageFile
12651315
put __extensionPropertyGet(pCacheIndex, "download_package_path") into tExtensionPackageFile
@@ -1284,15 +1334,8 @@ function __extensionManifestValue pCacheIndex, pProperty
12841334
revZipExtractItemToVariable tExtensionPackageFile, (tZipRoot & "manifest.xml"), "tManifestData"
12851335

12861336
revZipCloseArchive tExtensionPackageFile
1287-
1288-
put revXMLCreateTree(tManifestData,true,true,false) into tManifestXMLTree
1289-
put revXMLNodeContents(tManifestXMLTree,"/package/" & pProperty) into tValue
1290-
if tValue begins with "xmlerr" then
1291-
return empty
1292-
else
1293-
return tValue
1294-
end if
1295-
end __extensionManifestValue
1337+
return tManifestData
1338+
end __extensionManifestData
12961339

12971340
function __extensionSampleStacks pID, pFolder
12981341
local tSampleFolder, tSamples, tSampleArray
@@ -1310,31 +1353,6 @@ function __extensionSampleStacks pID, pFolder
13101353
return tSampleArray
13111354
end __extensionSampleStacks
13121355

1313-
function __extensionManifestValueFromFile pCacheIndex, pProperty
1314-
# Get the path to the manifest file
1315-
local tExtensionInstallPath, tManifestFilepath
1316-
put __extensionPropertyGet(pCacheIndex, "install_path") into tExtensionInstallPath
1317-
put tExtensionInstallPath & slash & "manifest.xml" into tManifestFilepath
1318-
1319-
if not there is a file tManifestFilepath then
1320-
local tError
1321-
put "Could not get extension manifest information: " into tError
1322-
put "extension folder does not contain a manifest file" after tError
1323-
return __extensionError(pCacheIndex,tError)
1324-
end if
1325-
1326-
# Extract the package manfiest to a variable to read key data
1327-
local tManifestXMLTree, tValue
1328-
1329-
put revXMLCreateTreeFromFile(tManifestFilepath,true,true,false) into tManifestXMLTree
1330-
put revXMLNodeContents(tManifestXMLTree,"/package/" & pProperty) into tValue
1331-
if tValue begins with "xmlerr" then
1332-
return empty
1333-
else
1334-
return tValue
1335-
end if
1336-
end __extensionManifestValueFromFile
1337-
13381356
##############################
13391357
# CALLBACKS
13401358
##############################

0 commit comments

Comments
 (0)