Skip to content

Commit ede6bd4

Browse files
authored
Integrate with common scripts for java toc (Azure#27441)
1 parent a541ccc commit ede6bd4

File tree

4 files changed

+167
-25
lines changed

4 files changed

+167
-25
lines changed

eng/pipelines/docindex.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
Paths:
6363
- package.json
6464
- metadata/
65+
- docs-ref-mapping/reference-unified.yml
6566
Repositories:
6667
- Name: azure-sdk/$(DocRepoName)
6768
WorkingDirectory: $(DailyDocRepoLocation)
@@ -86,6 +87,14 @@ jobs:
8687
filePath: eng/common/scripts/Update-DocsMsPackages.ps1
8788
arguments: -DocRepoLocation $(DailyDocRepoLocation)
8889
displayName: Update Docs Onboarding for Daily branch
90+
- task: Powershell@2
91+
inputs:
92+
pwsh: true
93+
filePath: eng/common/scripts/Update-DocsMsToc.ps1
94+
arguments: >-
95+
-DocRepoLocation $(DailyDocRepoLocation)
96+
-OutputLocation $(DailyDocRepoLocation)/docs-ref-mapping/reference-unified.yml
97+
displayName: Generate ToC for Daily branch
8998
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
9099
parameters:
91100
BaseRepoBranch: $(DailyDocsBranchName)

eng/scripts/Fetch-PackageList-Javadoc.ps1

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@ param (
2222
)
2323
. (Join-Path $PSScriptRoot ../common/scripts/common.ps1)
2424

25-
function Fetch-Namespaces-From-Javadoc ($jarFilePath, $tempLocation, $destination) {
26-
$tempLocation = (Join-Path ([System.IO.Path]::GetTempPath()) "jarFiles")
27-
if (Test-Path $tempLocation) {
28-
Remove-Item $tempLocation/* -Recurse -Force
29-
}
30-
else {
31-
New-Item -ItemType Directory -Path $tempLocation -Force
32-
}
33-
$originalLocation = Get-Location
34-
35-
try {
36-
Set-Location $tempLocation
37-
jar xf $jarFilePath
38-
if (Test-Path "./element-list") {
39-
# Rename and move to location
40-
Write-Host "Copying the element-list to $destination..."
41-
Copy-Item "./element-list" -Destination $destination
42-
}
43-
} finally {
44-
Set-Location $originalLocation
45-
}
46-
}
4725
Write-Host "The artifact name: $ArtifactName"
4826
$jarFile = Get-ChildItem $JavaDocJarLocation -Recurse -Include "$ArtifactName*-javadoc.jar"
4927
Write-Host "The jar file is $jarFile."
@@ -58,4 +36,4 @@ if ($originalVersion -and $originalVersion.IsPrerelease) {
5836
$packageNameLocation = "$DocRepoLocation/metadata/$metadataMoniker"
5937
New-Item -ItemType Directory -Path $packageNameLocation -Force
6038
Write-Host "The moniker $packageNameLocation"
61-
Fetch-Namespaces-From-Javadoc $jarFile.FullName $tempLocation "$packageNameLocation/$ArtifactName.txt"
39+
Fetch-Namespaces-From-Javadoc $jarFile.FullName "$packageNameLocation/$ArtifactName.txt"

eng/scripts/Language-Settings.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ $packagePattern = "*.pom"
55
$MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/main/_data/releases/latest/java-packages.csv"
66
$BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=java%2F&delimiter=%2F"
77
$CampaignTag = Resolve-Path (Join-Path -Path $PSScriptRoot -ChildPath "../repo-docs/ga_tag.html")
8+
$packageDownloadUrl = "https://repo1.maven.org/maven2"
9+
10+
. "$PSScriptRoot/docs/Docs-ToC.ps1"
811

912
function Get-java-PackageInfoFromRepo ($pkgPath, $serviceDirectory)
1013
{
@@ -243,7 +246,7 @@ function Update-java-CIConfig($pkgs, $ciRepo, $locationInDocRepo, $monikerId=$nu
243246
}
244247
else {
245248
$newItem = New-Object PSObject -Property @{
246-
packageDownloadUrl = "https://repo1.maven.org/maven2"
249+
packageDownloadUrl = $packageDownloadUrl
247250
packageGroupId = $releasingPkg.GroupId
248251
packageArtifactId = $releasingPkg.PackageId
249252
packageVersion = $releasingPkg.PackageVersion
@@ -536,7 +539,7 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata) {
536539
packageArtifactId = $packageName
537540
packageGroupId = $packageGroupId
538541
packageVersion = $packageVersion
539-
packageDownloadUrl = "https://repo1.maven.org/maven2"
542+
packageDownloadUrl = $packageDownloadUrl
540543
}
541544

542545
$outputPackages += $package

eng/scripts/docs/Docs-ToC.ps1

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
function Get-java-OnboardedDocsMsPackages($DocRepoLocation) {
2+
$packageOnboardingFiles = "$DocRepoLocation/package.json"
3+
4+
$onboardingSpec = ConvertFrom-Json (Get-Content $packageOnboardingFiles -Raw)
5+
$allPackages = @{}
6+
foreach ($spec in $onboardingSpec) {
7+
$spec.packages | ForEach-Object {$allPackages[$_.packageArtifactId] = $null}
8+
}
9+
return $allPackages
10+
}
11+
12+
function Get-java-DocsMsTocData($packageMetadata, $docRepoLocation) {
13+
# Fallback to get package-level readme name if metadata file info does not exist
14+
$packageLevelReadmeName = $packageMetadata.Package.Replace('azure-', '');
15+
16+
# If there is a metadata json for the package use the DocsMsReadmeName from
17+
# the metadata function
18+
if ($packageMetadata.PSObject.Members.Name -contains "FileMetadata") {
19+
$readmeMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageMetadata.FileMetadata
20+
$packageLevelReadmeName = $readmeMetadata.DocsMsReadMeName
21+
}
22+
23+
$packageTocHeader = $packageMetadata.Package
24+
if ($packageMetadata.DisplayName) {
25+
$packageTocHeader = $packageMetadata.DisplayName
26+
}
27+
28+
$children = @()
29+
# Children here combine namespaces in both preview and GA.
30+
if($package.VersionPreview) {
31+
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionPreview `
32+
-docRepoLocation $docRepoLocation -folderName "preview"
33+
}
34+
if($package.VersionGA) {
35+
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionGA `
36+
-docRepoLocation $docRepoLocation -folderName "latest"
37+
}
38+
if (!$children) {
39+
Write-Host "Did not find the package namespaces for $($packageMetadata.GroupId):$($packageMetadata.Package):$version"
40+
}
41+
$output = [PSCustomObject]@{
42+
PackageLevelReadmeHref = "~/docs-ref-services/{moniker}/$packageLevelReadmeName-readme.md"
43+
PackageTocHeader = $packageTocHeader
44+
TocChildren = $children
45+
}
46+
return $output
47+
}
48+
49+
function Get-java-DocsMsTocChildrenForManagementPackages($packageMetadata, $docRepoLocation) {
50+
$children = @()
51+
foreach ($package in $packageMetadata) {
52+
if($package.VersionPreview) {
53+
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionPreview `
54+
-docRepoLocation $docRepoLocation -folderName "preview"
55+
}
56+
if($package.VersionGA) {
57+
$children += Get-Toc-Children -package $package.Package -groupId $package.GroupId -version $package.VersionGA `
58+
-docRepoLocation $docRepoLocation -folderName "latest"
59+
}
60+
}
61+
# Children here combine namespaces in both preview and GA.
62+
return ($children | Sort-Object | Get-Unique)
63+
}
64+
65+
# This is a helper function which fetch the java package namespaces from javadoc jar.
66+
# Here are the major workflow:
67+
# 1. Read the ${package}.txt under /metadata folder
68+
# 2. If file not found, then download javadoc jar from maven repository.
69+
# 3. If there is 'element-list' in javadoc jar, then copy to destination ${package}.txt.
70+
# 4. If no 'element-list', then parse the 'overview-frame.html' for the namespaces and copy to destination.
71+
# 5. If no 'overview-frame.html', then read folder 'com/azure/...' for namespaces. E.g some mgmt packages use this structure.
72+
# 6. Otherwise, return empty children.
73+
function Get-Toc-Children($package, $groupId, $version, $docRepoLocation, $folderName) {
74+
# Looking for the txt
75+
$filePath = Join-Path "$docRepoLocation/metadata/$folderName" "$package.txt"
76+
if (!(Test-Path $filePath)) {
77+
# Download from maven
78+
# javadoc jar url. e.g.: https://repo1.maven.org/maven2/com/azure/azure-core/1.25.0/azure-core-1.25.0-javadoc.jar
79+
$artifact = "${groupId}:${package}:${version}:javadoc"
80+
# A temp folder
81+
$tempDirectory = Join-Path ([System.IO.Path]::GetTempPath()) "javadoc"
82+
if (!(Test-Path $tempDirectory)) {
83+
New-Item $tempDirectory -ItemType Directory | Out-Null
84+
}
85+
try {
86+
Write-Host "mvn dependency:copy -Dartifact=$artifact -DoutputDirectory=$tempDirectory"
87+
$javadocLocation = "$tempDirectory/$package-$version-javadoc.jar"
88+
& 'mvn' dependency:copy -Dartifact="$artifact" -DoutputDirectory="$tempDirectory" | Out-Null
89+
Write-Host "Download complete."
90+
}
91+
catch {
92+
Write-Error "Not able to download javadoc jar from $artifact."
93+
return @()
94+
}
95+
Fetch-Namespaces-From-Javadoc -jarFilePath $javadocLocation -destination $filePath
96+
}
97+
98+
if (!(Test-Path $filePath)) {
99+
# Log and warn
100+
Write-Host "Not able to find namespaces from javadoc jar $package-$version-javadoc.jar"
101+
}
102+
return (Get-Content $filePath | ForEach-Object {$_.Trim()})
103+
}
104+
105+
function Fetch-Namespaces-From-Javadoc ($jarFilePath, $destination) {
106+
$tempLocation = (Join-Path ([System.IO.Path]::GetTempPath()) "jarFiles")
107+
if (Test-Path $tempLocation) {
108+
Remove-Item $tempLocation/* -Recurse -Force
109+
}
110+
else {
111+
New-Item -ItemType Directory -Path $tempLocation -Force | Out-Null
112+
}
113+
114+
Add-Type -AssemblyName System.IO.Compression.FileSystem
115+
[System.IO.Compression.ZipFile]::ExtractToDirectory($jarFilePath, $tempLocation)
116+
if (Test-Path "$tempLocation/element-list") {
117+
# Rename and move to location
118+
Write-Host "Copying the element-list to $destination..."
119+
Copy-Item "$tempLocation/element-list" -Destination $destination
120+
}
121+
elseif (Test-Path "$tempLocation/overview-frame.html") {
122+
Parse-Overview-Frame -filePath "$tempLocation/overview-frame.html" -destination $destination
123+
}
124+
elseif (Test-Path "$tempLocation/com") {
125+
$originLocation = Get-Location
126+
try {
127+
Set-Location $tempLocation
128+
$allFolders = Get-ChildItem "$tempLocation/com" -Recurse -Directory |
129+
Where-Object {$_.GetFiles().Count -gt 0 -and $_.name -notmatch "class-use"}
130+
foreach ($path in $allFolders) {
131+
$path = (Resolve-Path $path -Relative) -replace "\./|\.\\"
132+
$path = $path -replace "\\|\/", "."
133+
Add-Content $destination -Value $path.Trim()
134+
}
135+
}
136+
finally {
137+
Set-Location $originLocation
138+
}
139+
}
140+
else {
141+
Write-Error "Can't find namespaces from javadoc jar jarFilePath."
142+
}
143+
}
144+
145+
function Parse-Overview-Frame ($filePath, $destination) {
146+
$htmlBody = Get-Content $filePath
147+
$packages = [RegEx]::Matches($htmlBody, "<li><a.*?>(?<package>.*?)<\/a><\/li>")
148+
149+
$namespaces = $packages | ForEach-Object { $_.Groups["package"].Value }
150+
Add-Content -Path $destination -Value $namespaces
151+
Get-Content $destination
152+
}

0 commit comments

Comments
 (0)