-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathDocs-ToC.ps1
408 lines (386 loc) · 16.9 KB
/
Docs-ToC.ps1
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
function Get-java-OnboardedDocsMsPackages($DocRepoLocation) {
$packageOnboardingFiles = "$DocRepoLocation/package.json"
$onboardingSpec = ConvertFrom-Json (Get-Content $packageOnboardingFiles -Raw)
$allPackages = @{}
foreach ($spec in $onboardingSpec) {
$spec.packages | ForEach-Object {$allPackages["$($_.packageGroupId):$($_.packageArtifactId)"] = $null}
}
return $allPackages
}
function Get-java-OnboardedDocsMsPackagesForMoniker ($DocRepoLocation, $moniker) {
$packageOnboardingFiles = "$DocRepoLocation/package.json"
$onboardingSpec = ConvertFrom-Json (Get-Content $packageOnboardingFiles -Raw)
if ("preview" -eq $moniker) {
$onboardingSpec = $onboardingSpec | Where-Object { $_.output_path -eq "preview/docs-ref-autogen" }
} elseif("latest" -eq $moniker) {
$onboardingSpec = $onboardingSpec | Where-Object { $_.output_path -eq "docs-ref-autogen" }
} elseif ("legacy" -eq $moniker) {
$onboardingSpec = $onboardingSpec | Where-Object { $_.output_path -eq "legacy/docs-ref-autogen" }
}
$onboardedPackages = @{}
foreach ($spec in $onboardingSpec.packages) {
$packageName = $spec.packageArtifactId
$groupId = $spec.packageGroupId
$jsonFile = "$DocRepoLocation/metadata/$moniker/$packageName.json"
if (Test-Path $jsonFile) {
$onboardedPackages["$groupId`:$packageName"] = ConvertFrom-Json (Get-Content $jsonFile -Raw)
}
else{
$onboardedPackages["$groupId`:$packageName"] = $null
}
}
return $onboardedPackages
}
function GetPackageReadmeName ($packageMetadata) {
# Fallback to get package-level readme name if metadata file info does not exist
$packageLevelReadmeName = $packageMetadata.Package.Replace('azure-', '')
# If there is a metadata json for the package use the DocsMsReadmeName from
# the metadata function
if ($packageMetadata.PSObject.Members.Name -contains "FileMetadata") {
$readmeMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageMetadata.FileMetadata
$packageLevelReadmeName = $readmeMetadata.DocsMsReadMeName
}
return $packageLevelReadmeName
}
function Get-java-PackageLevelReadme($packageMetadata) {
return GetPackageReadmeName -packageMetadata $packageMetadata
}
# Defined in common.ps1
# $GetDocsMsTocDataFn = "Get-${Language}-DocsMsTocData"
function Get-java-DocsMsTocData($packageMetadata, $docRepoLocation) {
$packageLevelReadmeName = GetPackageReadmeName -packageMetadata $packageMetadata
$packageTocHeader = GetDocsTocDisplayName -pkg $packageMetadata
$children = @()
# Children here combine namespaces in both preview and GA.
if($packageMetadata.VersionPreview) {
$children += Get-Toc-Children -package $packageMetadata.Package -groupId $packageMetadata.GroupId -version $packageMetadata.VersionPreview `
-docRepoLocation $docRepoLocation -folderName "preview"
}
if($packageMetadata.VersionGA) {
$children += Get-Toc-Children -package $packageMetadata.Package -groupId $packageMetadata.GroupId -version $packageMetadata.VersionGA `
-docRepoLocation $docRepoLocation -folderName "latest"
}
if (!$children) {
if ($packageMetadata.VersionPreview) {
Write-Host "Did not find the package namespaces for $($packageMetadata.GroupId):$($packageMetadata.Package):$($packageMetadata.VersionPreview)"
}
if ($packageMetadata.VersionGA) {
Write-Host "Did not find the package namespaces for $($packageMetadata.GroupId):$($packageMetadata.Package):$($packageMetadata.VersionGA)"
}
}
$output = [PSCustomObject]@{
PackageLevelReadmeHref = "~/docs-ref-services/{moniker}/$packageLevelReadmeName-readme.md"
PackageTocHeader = $packageTocHeader
TocChildren = $children
}
return $output
}
function Get-java-DocsMsTocChildrenForManagementPackages($packageMetadata, $docRepoLocation) {
$children = @()
foreach ($package in $packageMetadata) {
if($package.VersionPreview) {
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionPreview `
-docRepoLocation $docRepoLocation -folderName "preview"
}
if($package.VersionGA) {
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionGA `
-docRepoLocation $docRepoLocation -folderName "latest"
}
}
# Children here combine namespaces in both preview and GA.
return ($children | Sort-Object | Get-Unique)
}
# This function is called within a loop. To prevent multiple reads of the same
# file data, this uses a script-scoped cache variable.
$script:PackageMetadataJsonLookup = $null
function GetPackageMetadataJsonLookup($docRepoLocation) {
if ($script:PackageMetadataJsonLookup) {
return $script:PackageMetadataJsonLookup
}
$script:PackageMetadataJsonLookup = @{}
$packageJsonFiles = Get-ChildItem $docRepoLocation/metadata/ -Filter *.json -Recurse
foreach ($packageJsonFile in $packageJsonFiles) {
$packageJson = Get-Content $packageJsonFile -Raw | ConvertFrom-Json -AsHashtable
if (!$script:PackageMetadataJsonLookup.ContainsKey($packageJson.Name)) {
$script:PackageMetadataJsonLookup[$packageJson.Name] = @($packageJson)
} else {
$script:PackageMetadataJsonLookup[$packageJson.Name] += $packageJson
}
}
return $script:PackageMetadataJsonLookup
}
# Grab the namespaces from the json file
function Get-Toc-Children($package, $docRepoLocation) {
$packageTable = GetPackageMetadataJsonLookup $docRepoLocation
$namespaces = @()
if ($packageTable.ContainsKey($package)) {
foreach ($entry in $packageTable[$package]) {
if ($entry.ContainsKey('Namespaces')) {
$namespaces += $entry['Namespaces']
}
}
}
# Sort the array and clean out any dupes (there shouldn't be any but better safe than sorry)
$namespaces = @($namespaces | Sort-Object -Unique)
# Ensure that this always returns an array, even if there's one item or 0 items
Write-Output -NoEnumerate $namespaces
}
# Given a library, groupId and version, return the list of namespaces
function Fetch-Namespaces-From-Javadoc($package, $groupId, $version, $javadocJarFile = $null) {
$namespaces = @()
# Create a temporary directory to drop the jar into
$tempDirectory = Join-Path ([System.IO.Path]::GetTempPath()) "${groupId}-${package}-${version}"
New-Item $tempDirectory -ItemType Directory | Out-Null
$artifact = "${groupId}:${package}:${version}:jar:javadoc"
try {
# If the $javadocJarFile is passed in, copy it to the $tempDirectory, otherwise download it
# from the dev feed or maven
if ($javadocJarFile) {
if (Test-Path $javadocJarFile -PathType Leaf) {
Copy-Item $javadocJarFile -Destination $tempDirectory
} else {
LogWarning "$javadocJarFile, does not exist."
}
} else {
# Download the Jar file
Write-Host "mvn dependency:copy -Dartifact=""$artifact"" -DoutputDirectory=""$tempDirectory"""
$mvnResults = mvn `
dependency:copy `
-Dartifact="$artifact" `
-DoutputDirectory="$tempDirectory"
if ($LASTEXITCODE -ne 0) {
LogWarning "Could not download javadoc artifact: $artifact"
$mvnResults | Write-Host
}
}
$javadocLocation = "$tempDirectory/$package-$version-javadoc.jar"
# If the Jar file doesn't exit the error has already been reported above and
# processing will return an empty namespaces list
if (Test-Path $javadocLocation -PathType Leaf) {
# Unpack the Jar file
$unpackDirectory = Join-Path $tempDirectory "unpackedJavadoc"
New-Item $unpackDirectory -ItemType Directory | Out-Null
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($javadocLocation, $unpackDirectory)
if (Test-Path "$unpackDirectory/element-list") {
# Grab the namespaces from the element-list.
Write-Host "Fetching Namespaces: processing element-list"
foreach($line in [System.IO.File]::ReadLines("$unpackDirectory/element-list")) {
if (-not [string]::IsNullOrWhiteSpace($line)) {
$namespaces += $line
}
}
}
elseif (Test-Path "$unpackDirectory/overview-frame.html") {
# Grab the namespaces from the overview-frame.html's package elements
Write-Host "Fetching Namespaces: processing overview-frame.html"
$htmlBody = Get-Content "$unpackDirectory/overview-frame.html"
$packages = [RegEx]::Matches($htmlBody, "<li><a.*?>(?<package>.*?)<\/a><\/li>")
$namespaces = $packages | ForEach-Object { $_.Groups["package"].Value }
}
elseif (Test-Path "$unpackDirectory/com") {
# If all else fails, scrape the namespaces from the directories
Write-Host "Fetching Namespaces: searching the /com directores"
$originLocation = Get-Location
try {
Set-Location $unpackDirectory
$allFolders = Get-ChildItem "$unpackDirectory/com" -Recurse -Directory |
Where-Object {$_.GetFiles().Count -gt 0 -and $_.name -notmatch "class-use"}
foreach ($path in $allFolders) {
$path = (Resolve-Path $path -Relative) -replace "\./|\.\\"
$path = $path -replace "\\|\/", "."
# add the namespace to the list
$namespaces += $path.Trim()
}
}
finally {
Set-Location $originLocation
}
}
else {
LogWarning "Unable to determine namespaces from $artifact. Please ensure that the a javadoc jar is being built for the artifact and that it's not empty (ex. START/END: Empty Java Doc & Sources isn't in the POM file)."
}
}
}
catch {
LogError "Exception while trying to retrieve namespaces from: $artifact"
LogError $_
LogError $_.ScriptStackTrace
}
finally {
# everything is contained within the temp directory, clean it up every time
if (Test-Path $tempDirectory) {
Remove-Item $tempDirectory -Recurse -Force
}
}
$namespaces = @($namespaces | Sort-Object -Unique)
# Make sure this always returns an array
Write-Output -NoEnumerate $namespaces
}
function Get-java-RepositoryLink ($packageInfo) {
$groupIdPath = $packageInfo.GroupId -replace "\.", "/"
return "$PackageRepositoryUri/$groupIdPath/$($packageInfo.Package)"
}
function Get-java-UpdatedDocsMsToc($toc) {
$services = $toc[0].items
# Add services exsting in old toc but missing in automation.
$otherService = $services[-1]
$sortableServices = $services | Where-Object { $_ –ne $otherService }
foreach ($service in $sortableServices) {
if ($service.name -eq "SQL") {
$items = $service.items
$service.items = @(
[PSCustomObject]@{
name = "Client"
landingPageType = "Service"
children = @("com.microsoft.azure.elasticdb*")
}
) + $items
}
if ($service.name -eq "Log Analytics") {
$items = $service.items
$service.items = @(
[PSCustomObject]@{
name = "Client"
landingPageType = "Service"
children = @("com.microsoft.azure.loganalytics*")
}
) + $items
}
if ($service.name -eq "Data Lake Analytics") {
$service.items += @(
[PSCustomObject]@{
name = "Resource Management"
landingPageType = "Service"
children = @("com.microsoft.azure.management.datalake.analytics*")
}
)
}
if ($service.name -eq "Data Lake Store") {
$service.items += @(
[PSCustomObject]@{
name = "Resource Management"
landingPageType = "Service"
children = @(
"com.microsoft.azure.management.datalakestore*",
"com.microsoft.azure.management.datalake.store*",
"com.microsoft.azure.management.datalake.store.models*"
)
}
)
}
if ($service.name -eq "Stream Analytics") {
$service.items += @(
[PSCustomObject]@{
name = "Resource Management"
landingPageType = "Service"
children = @("com.microsoft.azure.management.streamanalytics*")
}
)
}
}
$sortableServices += [PSCustomObject]@{
name = "Active Directory"
href = "~/docs-ref-services/{moniker}/activedirectory.md"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Resource Management"
href = "~/docs-ref-services/{moniker}/resourcemanager-msi-readme.md"
children = @("com.azure.resourcemanager.msi*")
},
[PSCustomObject]@{
name = "Client"
children = @(
"com.microsoft.aad.adal*",
"com.microsoft.aad.adal4j*",
"com.microsoft.identity.client*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Edge Gateway"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Resource Management"
children = @("com.microsoft.azure.management.edgegateway*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Resource Mover"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Resource Management"
children = @("com.microsoft.azure.management.resourcemover.v2021_01_01*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Bing AutoSuggest"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
href = "~/docs-ref-services/{moniker}/cognitiveservices/bing-autosuggest-readme.md"
children = @("com.microsoft.azure.cognitiveservices.search.autosuggest*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Content Moderator"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
children = @("com.microsoft.azure.cognitiveservices.vision.contentmoderator*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Custom Vision"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
children = @("com.microsoft.azure.cognitiveservices.vision.customvision*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Face API"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
children = @("com.microsoft.azure.cognitiveservices.vision.faceapi*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Language Understanding"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
children = @(
"com.microsoft.azure.cognitiveservices.language.luis*",
"com.microsoft.azure.cognitiveservices.language.luis.authoring*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Text Analytics"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Management"
children = @("com.microsoft.azure.cognitiveservices.language.text*")
})
}
$sortableServices += [PSCustomObject]@{
name = "Cognitive Services"
landingPageType = "Service"
items = @(
[PSCustomObject]@{
name = "Resource Management"
children = @("com.microsoft.azure.management.cognitiveservices*")
})
}
$toc[0].items = ($sortableServices | Sort-Object -Property name) + $otherService
return , $toc
}