-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed & refactored loading pom.properties #727
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6538,6 +6538,44 @@ export const encodeForPurl = (s) => { | |
: s; | ||
}; | ||
|
||
/** | ||
* Method to get pom properties from maven directory | ||
* | ||
* @param {string} mavenDir Path to maven directory | ||
* | ||
* @return array with pom properties | ||
*/ | ||
export const getPomPropertiesFromMavenDir = function (mavenDir) { | ||
let pomProperties = {}; | ||
if (existsSync(mavenDir) && lstatSync(mavenDir).isDirectory()) { | ||
let mavenDirEntries = readdirSync(mavenDir, { withFileTypes: true }); | ||
mavenDirEntries.forEach((mavenDirEntry) => { | ||
if (mavenDirEntry.isDirectory()) { | ||
let groupDirEntries = readdirSync( | ||
join(mavenDirEntry.path, mavenDirEntry.name), | ||
{ withFileTypes: true } | ||
); | ||
groupDirEntries.forEach((groupDirEntry) => { | ||
if (groupDirEntry.isDirectory()) { | ||
let pomPropertiesFile = join( | ||
groupDirEntry.path, | ||
groupDirEntry.name, | ||
"pom.properties" | ||
); | ||
if (existsSync(pomPropertiesFile)) { | ||
const pomPropertiesString = readFileSync(pomPropertiesFile, { | ||
encoding: "utf-8" | ||
}); | ||
pomProperties = parsePomProperties(pomPropertiesString); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
return pomProperties; | ||
}; | ||
|
||
/** | ||
* Method to extract a war or ear file | ||
* | ||
|
@@ -6636,38 +6674,15 @@ export const extractJarArchive = function ( | |
if (jarResult.status !== 0) { | ||
console.error(jarResult.stdout, jarResult.stderr); | ||
} else { | ||
let group = "", | ||
name = "", | ||
version = "", | ||
confidence = 1, | ||
technique = "manifest-analysis"; | ||
// When maven descriptor is available take group, name and version from pom.properties | ||
// META-INF/maven/${groupId}/${artifactId}/pom.properties | ||
// see https://maven.apache.org/shared/maven-archiver/index.html | ||
if (existsSync(mavenDir)) { | ||
let groupDir = readdirSync(mavenDir); | ||
if (groupDir && groupDir.length) { | ||
let artifactDir = readdirSync(join(mavenDir, groupDir[0])); | ||
if (artifactDir && artifactDir.length) { | ||
let pomPropertiesFile = join( | ||
mavenDir, | ||
groupDir[0], | ||
artifactDir[0], | ||
"pom.properties" | ||
); | ||
if (existsSync(pomPropertiesFile)) { | ||
const pomProperties = parsePomProperties( | ||
readFileSync(pomPropertiesFile, { | ||
encoding: "utf-8" | ||
}) | ||
); | ||
group = pomProperties["groupId"]; | ||
name = pomProperties["artifactId"]; | ||
version = pomProperties["version"]; | ||
} | ||
} | ||
} | ||
} | ||
const pomProperties = getPomPropertiesFromMavenDir(mavenDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since pomProperties can be an empty object, do we need a condition to skip? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, it might be right below this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is an empty object (e.g. wsdl4j-1.6.3.jar) group, name and version will be undefined, but this case is handled later. |
||
let group = pomProperties["groupId"], | ||
name = pomProperties["artifactId"], | ||
version = pomProperties["version"], | ||
confidence = 1, | ||
technique = "manifest-analysis"; | ||
if ((!group || !name || !version) && existsSync(manifestFile)) { | ||
confidence = 0.8; | ||
const jarMetadata = parseJarManifest( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a break or return here since this is inside a loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately a return/break does not work with
forEach
. But usually the jar should anyway contain one directory on each level inside the META-INF/maven directory. And as I learned optionally theextension.xml
. Therefore I thought we can keep the implementation that way, because there will be no performance loss.