Skip to content

Commit 47f54e8

Browse files
authored
BOM, support ARM libraries (#45655)
* support other groupIds in patch release patch release * support BOM generation * adjustments * break * fix * add resourcemanger packages to patch release * BomGenerator, hack to only include premium packages * put the hack at the front to avoid inflating conflictlist * remove ARM libraries from patch release candidate * add artifact filter * nit, rename
1 parent 3e85df0 commit 47f54e8

File tree

12 files changed

+167
-63
lines changed

12 files changed

+167
-63
lines changed

eng/bomgenerator/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inputdir/*
2+
outputdir/*

eng/bomgenerator/generateAzureSDKBOM.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ $BomPomFilePath = Join-Path $RepoRoot "sdk" "boms" "azure-sdk-bom" $PomFileName
1414
$EngScriptDir = Join-Path $EngDir "scripts"
1515
$BomGeneratorPomFilePath = Join-Path ${PSScriptRoot} $PomFileName
1616
$NewBomFilePath = Join-Path $OutputDir $PomFileName
17+
$GroupIds = @("com.azure", "com.azure.resourcemanager")
18+
# This directory contains artifacts to include organized by {GroupId}.txt for each GroupId.
19+
# If this file is present for a given GroupId, only those artifacts in this file will be included.
20+
# Otherwise, no filter will be applied, meaning all artifacts under this GroupId will be included.
21+
$IncludesDirectoryPath = Join-Path ${PSScriptRoot} "includes"
1722

1823
. (Join-Path $EngScriptDir syncversionclient.ps1)
1924

@@ -36,8 +41,7 @@ function UpdateBomProjectElement($OldPomFilePath, $NewPomFilePath) {
3641
Write-Output "InputDir:$($InputDir)"
3742
Write-Output "OutputDir:$($OutputDir)"
3843
Write-Output "Updating version_client.txt file by looking at the packages released to maven."
39-
# TODO (alzimmer): Handle other group IDs for generating BOMs. https://github.com/Azure/azure-sdk-for-java/issues/44475
40-
SyncVersionClientFile -GroupId "com.azure"
44+
SyncVersionClientFile -GroupIds $GroupIds
4145
Write-Output "Updated version_client.txt file."
4246

4347
New-Item -Path $PSScriptRoot -Name "inputdir" -ItemType "directory" -Force
@@ -50,7 +54,12 @@ if (!(Test-Path -Path $DefaultPomFilePath)) {
5054
Copy-Item $BomPomFilePath -Destination $InputDir
5155
}
5256

53-
$cmdoutput = mvn clean install -f $BomGeneratorPomFilePath
57+
if (Test-Path -Path $IncludesDirectoryPath) {
58+
Copy-Item $IncludesDirectoryPath -Destination $InputDir -Recurse -Force
59+
}
60+
61+
$groupIdString = $GroupIds -join ","
62+
$cmdoutput = mvn clean install -f $BomGeneratorPomFilePath -DgroupIds="$groupIdString"
5463

5564
if (Test-Path -Path $BomPomFilePath && Test-Path -Path $NewBomFilePath) {
5665
Copy-Item $NewBomFilePath -Destination $BomPomFilePath -Force
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
azure-resourcemanager
2+
azure-resourcemanager-appplatform
3+
azure-resourcemanager-appservice
4+
azure-resourcemanager-authorization
5+
azure-resourcemanager-cdn
6+
azure-resourcemanager-compute
7+
azure-resourcemanager-containerinstance
8+
azure-resourcemanager-containerregistry
9+
azure-resourcemanager-containerservice
10+
azure-resourcemanager-cosmos
11+
azure-resourcemanager-dns
12+
azure-resourcemanager-eventhubs
13+
azure-resourcemanager-keyvault
14+
azure-resourcemanager-monitor
15+
azure-resourcemanager-msi
16+
azure-resourcemanager-network
17+
azure-resourcemanager-privatedns
18+
azure-resourcemanager-resources
19+
azure-resourcemanager-redis
20+
azure-resourcemanager-search
21+
azure-resourcemanager-servicebus
22+
azure-resourcemanager-sql
23+
azure-resourcemanager-storage
24+
azure-resourcemanager-trafficmanager

eng/bomgenerator/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>
1313
<maven.compiler.target>11</maven.compiler.target>
14+
<groupIds>com.azure,com.azure.resourcemanager</groupIds>
1415
</properties>
1516
<dependencyManagement>
1617
<dependencies>
@@ -72,6 +73,7 @@
7273
<argument>-inputdir=${project.basedir}/inputdir</argument>
7374
<argument>-outputdir=${project.basedir}/outputdir</argument>
7475
<argument>-mode=generate</argument>
76+
<argument>-groupids=${groupIds}</argument>
7577
</arguments>
7678
<cleanupDaemonThreads>false</cleanupDaemonThreads>
7779
</configuration>

eng/bomgenerator/src/main/java/com/azure/tools/bomgenerator/BomGenerator.java

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.azure.tools.bomgenerator.models.BomDependency;
77
import com.azure.tools.bomgenerator.models.BomDependencyManagement;
8+
import com.azure.tools.bomgenerator.models.BomDependencyNoVersion;
89
import com.fasterxml.jackson.annotation.JsonInclude;
910
import com.fasterxml.jackson.databind.SerializationFeature;
1011
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -38,9 +39,12 @@
3839
import java.util.ArrayList;
3940
import java.util.Collection;
4041
import java.util.HashMap;
42+
import java.util.HashSet;
4143
import java.util.List;
4244
import java.util.Map;
45+
import java.util.Set;
4346
import java.util.regex.Matcher;
47+
import java.util.regex.Pattern;
4448
import java.util.stream.Collectors;
4549

4650
import static com.azure.tools.bomgenerator.Utils.ANALYZE_MODE;
@@ -69,19 +73,31 @@ public class BomGenerator {
6973
private String mode;
7074
private String outputDirectory;
7175
private String inputDirectory;
76+
private final Pattern sdkDependencyPattern;
77+
private final Set<String> groupIds;
78+
private final DependencyFilter dependencyFilter;
7279

7380
private static Logger logger = LoggerFactory.getLogger(BomGenerator.class);
7481

75-
BomGenerator(String inputDirectory, String outputDirectory, String mode) throws FileNotFoundException {
82+
BomGenerator(String inputDirectory, String outputDirectory, String mode, List<String> groupIds) throws IOException {
7683
validateNotNullOrEmpty(inputDirectory, "inputDirectory");
7784
validateNotNullOrEmpty(outputDirectory, "outputDirectory");
7885

7986
this.inputDirectory = inputDirectory;
8087
this.outputDirectory = outputDirectory;
8188
this.mode = (mode == null ? GENERATE_MODE : mode);
89+
if (groupIds == null || groupIds.isEmpty()) {
90+
logger.warn("groupIds null, will use com.azure");
91+
this.groupIds = Set.of(BASE_AZURE_GROUPID);
92+
this.sdkDependencyPattern = SDK_DEPENDENCY_PATTERN;
93+
} else {
94+
this.groupIds = new HashSet<>(groupIds);
95+
this.sdkDependencyPattern = Pattern.compile(String.format("(%s):(.+);(.+);(.+)", String.join("|", this.groupIds)));
96+
}
8297

8398
parseInputs();
8499
validateInputs();
100+
this.dependencyFilter = new DependencyFilter(this.inputDirectory);
85101

86102
Path outputDirPath = Paths.get(outputDirectory);
87103
outputDirPath.toFile().mkdirs();
@@ -147,7 +163,7 @@ private boolean generate() {
147163
analyzer.reduce();
148164
Collection<BomDependency> outputDependencies = analyzer.getBomEligibleDependencies();
149165

150-
// 2. Create the new tree for the BOM.
166+
// 3. Create the new tree for the BOM.
151167
analyzer = new DependencyAnalyzer(outputDependencies, externalDependencies, this.reportFileName);
152168
boolean validationFailed = analyzer.validate();
153169
outputDependencies = analyzer.getBomEligibleDependencies();
@@ -169,7 +185,7 @@ private List<BomDependency> scanVersioningClientFileDependencies() {
169185
for (String line : Files.readAllLines(Paths.get(inputFileName))) {
170186
BomDependency dependency = scanDependency(line);
171187

172-
if(dependency != null) {
188+
if(dependencyFilter.apply(dependency)) {
173189
inputDependencies.add(dependency);
174190
}
175191
}
@@ -244,17 +260,18 @@ private List<BomDependency> scanOverriddenDependencies() {
244260
}
245261

246262
private BomDependency scanDependency(String line) {
247-
Matcher matcher = SDK_DEPENDENCY_PATTERN.matcher(line);
263+
Matcher matcher = sdkDependencyPattern.matcher(line);
248264
if (!matcher.matches()) {
249265
return null;
250266
}
251267

252-
if (matcher.groupCount() != 3) {
268+
if (matcher.groupCount() != 4) {
253269
return null;
254270
}
255271

256-
String artifactId = matcher.group(1);
257-
String version = matcher.group(2);
272+
String groupId = matcher.group(1);
273+
String artifactId = matcher.group(2);
274+
String version = matcher.group(3);
258275

259276
if(version.contains("-")) {
260277
// This is a non-GA library
@@ -264,11 +281,11 @@ private BomDependency scanDependency(String line) {
264281
if (EXCLUSION_LIST.contains(artifactId)
265282
|| artifactId.contains(AZURE_PERF_LIBRARY_IDENTIFIER)
266283
|| (artifactId.contains(AZURE_TEST_LIBRARY_IDENTIFIER))) {
267-
logger.trace("Skipping dependency {}:{}", BASE_AZURE_GROUPID, artifactId);
284+
logger.trace("Skipping dependency {}:{}", groupId, artifactId);
268285
return null;
269286
}
270287

271-
return new BomDependency(BASE_AZURE_GROUPID, artifactId, version);
288+
return new BomDependency(groupId, artifactId, version);
272289
}
273290

274291
private Model readModel() {
@@ -338,8 +355,44 @@ private void writeBom(Collection<BomDependency> bomDependencies) {
338355
dependencies.sort(new DependencyComparator());
339356

340357
// Remove external dependencies from the BOM.
341-
dependencies = dependencies.stream().filter(dependency -> BASE_AZURE_GROUPID.equals(dependency.getGroupId())).collect(Collectors.toList());
358+
dependencies = dependencies.stream().filter(dependency -> groupIds.contains(dependency.getGroupId())).collect(Collectors.toList());
342359
management.setDependencies(dependencies);
343360
writeModel(this.pomFileName, this.outputFileName, model);
344361
}
362+
363+
private static class DependencyFilter {
364+
private final Map<String, Set<BomDependencyNoVersion>> groupIdDependenciesMap = new HashMap<>();
365+
DependencyFilter(String inputDirectory) throws IOException {
366+
Path includesDirectory = Paths.get(inputDirectory, "includes");
367+
String fileSuffix = ".txt";
368+
Files.list(includesDirectory)
369+
.filter(file -> Files.isRegularFile(file) && file.getFileName().toString().endsWith(fileSuffix))
370+
.forEach(file -> {
371+
try {
372+
String fileName = file.getFileName().toString();
373+
String groupId = fileName.substring(0, fileName.length() - fileSuffix.length());
374+
Set<BomDependencyNoVersion> dependencies = groupIdDependenciesMap.computeIfAbsent(groupId, ignored -> new HashSet<>());
375+
for (String line : Files.readAllLines(file)) {
376+
if (line != null && !line.trim().isEmpty()) {
377+
dependencies.add(new BomDependencyNoVersion(groupId, line));
378+
}
379+
}
380+
} catch (IOException e) {
381+
throw new RuntimeException(e);
382+
}
383+
});
384+
}
385+
386+
boolean apply(BomDependency dependency) {
387+
if (dependency == null) {
388+
return false;
389+
}
390+
Set<BomDependencyNoVersion> allowedDependencies = this.groupIdDependenciesMap.get(dependency.getGroupId());
391+
// if allowed list is null, no filter will be applied
392+
if (allowedDependencies == null) {
393+
return true;
394+
}
395+
return allowedDependencies.contains(Utils.toBomDependencyNoVersion(dependency));
396+
}
397+
}
345398
}

eng/bomgenerator/src/main/java/com/azure/tools/bomgenerator/Main.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
package com.azure.tools.bomgenerator;
55

66
import java.io.FileNotFoundException;
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
711
import java.util.regex.Matcher;
812
import static com.azure.tools.bomgenerator.Utils.ANALYZE_MODE;
13+
import static com.azure.tools.bomgenerator.Utils.COMMANDLINE_GROUP_IDS;
914
import static com.azure.tools.bomgenerator.Utils.COMMANDLINE_INPUTDIRECTORY;
1015
import static com.azure.tools.bomgenerator.Utils.COMMANDLINE_OUTPUTDIRECTORY;
1116
import static com.azure.tools.bomgenerator.Utils.COMMANDLINE_MODE;
@@ -25,15 +30,16 @@ public static void main(String[] args) {
2530
}
2631

2732
System.out.println("Completed successfully.");
28-
} catch (FileNotFoundException e) {
33+
} catch (IOException e) {
2934
System.out.println("Error occurred.");
3035
e.printStackTrace();
3136
System.exit(1);
3237
}
3338
}
3439

35-
private static BomGenerator parseCommandLine(String[] args) throws FileNotFoundException {
40+
private static BomGenerator parseCommandLine(String[] args) throws IOException {
3641
String inputDir = null, outputDir = null, mode = null;
42+
List<String> groupIds = null;
3743
for (String arg : args) {
3844
Matcher matcher = COMMANDLINE_REGEX.matcher(arg);
3945
if (matcher.matches()) {
@@ -57,6 +63,10 @@ private static BomGenerator parseCommandLine(String[] args) throws FileNotFoundE
5763
validateValues(argName, argValue, GENERATE_MODE, ANALYZE_MODE);
5864
mode = argValue;
5965
break;
66+
67+
case COMMANDLINE_GROUP_IDS:
68+
groupIds = Arrays.asList(argValue.split(","));
69+
break;
6070
}
6171
}
6272

@@ -65,7 +75,7 @@ private static BomGenerator parseCommandLine(String[] args) throws FileNotFoundE
6575

6676
validateNotNullOrEmpty(inputDir, "inputDir");
6777
validateNotNullOrEmpty(outputDir, "outputDir");
68-
BomGenerator generator = new BomGenerator(inputDir, outputDir, mode);
78+
BomGenerator generator = new BomGenerator(inputDir, outputDir, mode, groupIds);
6979
return generator;
7080
}
7181
}

eng/bomgenerator/src/main/java/com/azure/tools/bomgenerator/Utils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ public class Utils {
4545
public static final String COMMANDLINE_INPUTDIRECTORY = "inputdir";
4646
public static final String COMMANDLINE_OUTPUTDIRECTORY = "outputdir";
4747
public static final String COMMANDLINE_MODE = "mode";
48+
public static final String COMMANDLINE_GROUP_IDS = "groupids";
4849
public static final String ANALYZE_MODE = "analyze";
4950
public static final String GENERATE_MODE = "generate";
5051
public static final Pattern COMMANDLINE_REGEX = Pattern.compile("-(.*)=(.*)");
5152
public static final List<String> EXCLUSION_LIST = Arrays.asList("azure-spring-data-cosmos", "azure-core-test", "azure-sdk-all", "azure-sdk-parent", "azure-client-sdk-parent");
52-
public static final Pattern SDK_DEPENDENCY_PATTERN = Pattern.compile("com.azure:(.+);(.+);(.+)");
53+
public static final Pattern SDK_DEPENDENCY_PATTERN = Pattern.compile("(com.azure):(.+);(.+);(.+)");
5354
// TODO (alzimmer): Handle creation of BOM for v2 libraries. https://github.com/Azure/azure-sdk-for-java/issues/44475
5455
public static final String BASE_AZURE_GROUPID = "com.azure";
5556
public static final String AZURE_TEST_LIBRARY_IDENTIFIER = "-test";

eng/scripts/Generate-Patches-For-Automatic-Releases.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ try {
5454

5555
# Reset each package to the latest stable release and update CHANGELOG, POM and README for patch release.
5656
foreach ($packageData in $packagesData) {
57-
. "${PSScriptRoot}/generatepatch.ps1" -ArtifactIds $packageData["name"] -ServiceDirectoryName $packageData["ServiceDirectory"] -BranchName $branchName
57+
. "${PSScriptRoot}/generatepatch.ps1" -ArtifactIds $packageData["name"] -ServiceDirectoryName $packageData["ServiceDirectory"] -BranchName $branchName -GroupId $packageData["groupId"]
5858
$libraryList += $packageData["groupId"] + ":" + $packageData["name"] + ","
5959
}
6060

eng/scripts/Update-Artifacts-List-For-Patch-Release.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ foreach ($line in Get-Content "${PSScriptRoot}/../pipelines/patch_release_client
8181
if (($line) -and !($line.StartsWith("#"))) {
8282
$libraryId = $line.split(" ")[0]
8383
$groupId, $artifactId = $libraryId.split(":")
84-
$ArtifactInfos[$artifactId] = GetVersionInfoForMavenArtifact -ArtifactId $artifactId
84+
$ArtifactInfos[$artifactId] = GetVersionInfoForMavenArtifact -ArtifactId $artifactId -GroupId $groupId
8585
}
8686
}
8787

eng/scripts/bomhelpers.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ class MavenArtifactInfo {
77
[String] $LatestGAOrPatchVersion
88
[String] $LatestReleasedVersion
99

10-
MavenArtifactInfo($ArtifactId, $LatestGAOrPatchVersion, $LatestReleasedVersion) {
10+
MavenArtifactInfo($ArtifactId, $LatestGAOrPatchVersion, $LatestReleasedVersion, $GroupId = "com.azure") {
1111
$this.ArtifactId = $ArtifactId
1212
$this.LatestGAOrPatchVersion = $LatestGAOrPatchVersion
1313
$this.LatestReleasedVersion = $LatestReleasedVersion
14-
$this.GroupId = 'com.azure'
14+
$this.GroupId = $GroupId
1515
}
1616
}
1717

@@ -42,23 +42,25 @@ function UpdateDependencyOfClientSDK() {
4242
}
4343

4444
# Get all azure com client artifacts from Maven.
45-
function GetAllAzComClientArtifactsFromMaven() {
46-
$webResponseObj = Invoke-WebRequest -Uri "https://repo1.maven.org/maven2/com/azure"
45+
function GetAllAzComClientArtifactsFromMaven($GroupId = "com.azure") {
46+
$groupPath = $GroupId -replace '\.', '/'
47+
$webResponseObj = Invoke-WebRequest -Uri "https://repo1.maven.org/maven2/$groupPath"
4748
$azureComArtifactIds = $webResponseObj.Links.HRef | Where-Object { ($_ -like 'azure-*') -and ($IgnoreList -notcontains $_) } | ForEach-Object { $_.substring(0, $_.length - 1) }
4849
return $azureComArtifactIds | Where-Object { ($_ -like "azure-*") -and !($_ -like "azure-spring") }
4950
}
5051

5152
# Get version info for an artifact.
52-
function GetVersionInfoForAnArtifactId([String]$ArtifactId) {
53-
$mavenMetadataUrl = "https://repo1.maven.org/maven2/com/azure/$($ArtifactId)/maven-metadata.xml"
53+
function GetVersionInfoForAnArtifactId([String]$GroupId = "com.azure", [String]$ArtifactId) {
54+
$groupPath = $GroupId -replace '\.', '/'
55+
$mavenMetadataUrl = "https://repo1.maven.org/maven2/$groupPath/$($ArtifactId)/maven-metadata.xml"
5456
$webResponseObj = Invoke-WebRequest -Uri $mavenMetadataUrl
5557
$versions = ([xml]$webResponseObj.Content).metadata.versioning.versions.version
5658
$semVersions = $versions | ForEach-Object { [AzureEngSemanticVersion]::ParseVersionString($_) }
5759
$sortedVersions = [AzureEngSemanticVersion]::SortVersions($semVersions)
5860
$latestReleasedVersion = $sortedVersions[0].RawVersion
5961
$latestPatchOrGAVersion = $sortedVersions | Where-Object { !($_.IsPrerelease) } | ForEach-Object { $_.RawVersion } | Select-Object -First 1
6062

61-
$mavenArtifactInfo = [MavenArtifactInfo]::new($ArtifactId, $latestPatchOrGAVersion, $latestReleasedVersion)
63+
$mavenArtifactInfo = [MavenArtifactInfo]::new($ArtifactId, $latestPatchOrGAVersion, $latestReleasedVersion, $GroupId)
6264

6365
return $mavenArtifactInfo
6466
}
@@ -279,7 +281,7 @@ function GeneratePatch($PatchInfo, [string]$BranchName, [string]$RemoteName, [st
279281

280282
if (!$releaseVersion) {
281283
Write-Output "Computing the latest release version for each of the relevant artifacts from Maven Central."
282-
$mavenArtifactInfo = [MavenArtifactInfo](GetVersionInfoForAnArtifactId -ArtifactId $artifactId)
284+
$mavenArtifactInfo = [MavenArtifactInfo](GetVersionInfoForAnArtifactId -GroupId $GroupId -ArtifactId $artifactId)
283285

284286
if ($null -eq $mavenArtifactInfo) {
285287
LogError "Could not find $artifactId on Maven Central."

0 commit comments

Comments
 (0)