Skip to content

Commit bebe52f

Browse files
authored
Removed the need for Maven parser for parsing BOM file (Azure#24726)
In order to support validation of single POM file we enabled support for parsing POM file which is not a BOM. Extending that support to now also include BOM file parsing and removing the special parsing of the BOM file via Maven plugin.
1 parent 8955e4b commit bebe52f

File tree

3 files changed

+12
-49
lines changed

3 files changed

+12
-49
lines changed

eng/bomgenerator/generateAzureSDKBOM.ps1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $pomFileName = "pom.xml"
66
$defaultVersionClientFilePath = Join-Path $inputDir $versionClientFileName
77
$defaultPomFilePath = Join-Path $inputDir $pomFileName
88
$versionClientFilePath = Join-Path $repoRoot "eng" "versioning" $versionClientFileName
9-
$bomPomFilePath = Join-Path $repoRoot "sdk" "containerregistry" "azure-containers-containerregistry" $pomFileName
9+
$bomPomFilePath = Join-Path $repoRoot "sdk" "boms" "azure-sdk-bom" $pomFileName
1010

1111
if(! (Test-Path $inputDir)) {
1212
New-Item -Path $PSScriptRoot -Name "inputDir" -ItemType "directory"
@@ -19,10 +19,6 @@ if(! (Test-Path $defaultVersionClientFilePath)) {
1919
if(! (Test-Path $defaultPomFilePath)) {
2020
Copy-Item $bomPomFilePath -Destination $inputDir
2121
}
22-
2322

24-
"mvn exec:java -Dexec.args='-inputDir=$inputDir -outputDir=$outputDir -mode=analyze'"
25-
if($LASTEXITCODE -ne 0) {
26-
LogError "Failed to generate the BOM."
27-
exit 1
28-
}
23+
$mvnResults = mvn install
24+
$mvnResults = "mvn exec:java -Dexec.args=`"-inputDir=$inputDir -outputDir=$outputDir -mode=analyze`""

eng/bomgenerator/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<arguments>
7777
<argument>-inputdir=${project.basedir}/inputdir</argument>
7878
<argument>-outputdir=${project.basedir}/outputdir</argument>
79+
<argument>-mode=analyze</argument>
7980
</arguments>
8081
<cleanupDaemonThreads>false</cleanupDaemonThreads>
8182
</configuration>

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

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ static List<BomDependency> parsePomFileContent(String fileName) {
184184

185185
static List<BomDependency> parsePomFileContent(Reader responseStream) {
186186
List<BomDependency> bomDependencies = new ArrayList<>();
187+
List<Dependency> dependencies;
187188

188189
ObjectMapper mapper = new XmlMapper();
189190
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
190191
try {
191192
Model value = mapper.readValue(responseStream, Model.class);
192-
List<Dependency> dependencies = value.getDependencies();
193+
if(value.getPackaging().equalsIgnoreCase("pom")) {
194+
// This is a bom file.
195+
dependencies = value.getDependencyManagement().getDependencies();
196+
}
197+
else {
198+
dependencies = value.getDependencies();
199+
}
193200

194201
if(dependencies == null) {
195202
return bomDependencies;
@@ -214,45 +221,4 @@ static List<BomDependency> parsePomFileContent(Reader responseStream) {
214221

215222
return bomDependencies.stream().distinct().collect(Collectors.toList());
216223
}
217-
218-
static List<BomDependency> parseBomFileContent(Reader responseStream) {
219-
MavenXpp3Reader reader = new MavenXpp3Reader();
220-
try {
221-
Model model = reader.read(responseStream);
222-
DependencyManagement management = model.getDependencyManagement();
223-
224-
return management.getDependencies().stream().map(dep -> {
225-
String version = getPropertyName(dep.getVersion());
226-
227-
while(model.getProperties().getProperty(version) != null) {
228-
version = getPropertyName(model.getProperties().getProperty(version));
229-
230-
if(version.equals(PROJECT_VERSION)) {
231-
version = model.getVersion();
232-
}
233-
}
234-
235-
if(version == null) {
236-
version = dep.getVersion();
237-
}
238-
239-
BomDependency bomDependency = new BomDependency(dep.getGroupId(), dep.getArtifactId(), version);
240-
return bomDependency;
241-
}).collect(Collectors.toList());
242-
} catch (IOException exception) {
243-
exception.printStackTrace();
244-
} catch (XmlPullParserException e) {
245-
e.printStackTrace();
246-
}
247-
248-
return null;
249-
}
250-
251-
private static String getPropertyName(String propertyValue) {
252-
if(propertyValue.startsWith("${")) {
253-
return propertyValue.substring(2, propertyValue.length() - 1);
254-
}
255-
256-
return propertyValue;
257-
}
258224
}

0 commit comments

Comments
 (0)