Yield Packagedata objects from parsing a Maven pom file at `location` or using the provided `text` (one or the other but not both).
(
datasource_id,
package_type,
primary_language,
location=None,
text=None,
base_url='https://repo1.maven.org/maven2',
package_only=False,
)
| 1216 | |
| 1217 | |
| 1218 | def _parse( |
| 1219 | datasource_id, |
| 1220 | package_type, |
| 1221 | primary_language, |
| 1222 | location=None, |
| 1223 | text=None, |
| 1224 | base_url='https://repo1.maven.org/maven2', |
| 1225 | package_only=False, |
| 1226 | ): |
| 1227 | """ |
| 1228 | Yield Packagedata objects from parsing a Maven pom file at `location` or |
| 1229 | using the provided `text` (one or the other but not both). |
| 1230 | """ |
| 1231 | pom = get_maven_pom(location=location, text=text) |
| 1232 | |
| 1233 | if not pom: |
| 1234 | return |
| 1235 | |
| 1236 | if TRACE: |
| 1237 | ptd = pformat(pom.to_dict()) |
| 1238 | logger.debug(f'PomXmlHandler.parse: pom:.to_dict()\n{ptd}') |
| 1239 | |
| 1240 | version = pom.version |
| 1241 | # pymaven whart |
| 1242 | if version == 'latest.release': |
| 1243 | version = None |
| 1244 | |
| 1245 | qualifiers = {} |
| 1246 | classifier = pom.classifier |
| 1247 | if classifier: |
| 1248 | qualifiers['classifier'] = classifier |
| 1249 | |
| 1250 | packaging = pom.packaging |
| 1251 | if packaging: |
| 1252 | extension = get_extension(packaging) |
| 1253 | if extension and extension not in ('jar', 'pom'): |
| 1254 | # we use type as in the PURL spec: this is a problematic field with |
| 1255 | # complex defeinition in Maven |
| 1256 | qualifiers['type'] = extension |
| 1257 | |
| 1258 | extracted_license_statement = clean_licenses(pom.licenses) or None |
| 1259 | |
| 1260 | group_id = pom.group_id |
| 1261 | artifact_id = pom.artifact_id |
| 1262 | |
| 1263 | # craft a source package purl for the main binary |
| 1264 | source_packages = [] |
| 1265 | is_main_binary_jar = not classifier and all([group_id, artifact_id, version]) |
| 1266 | if is_main_binary_jar: |
| 1267 | spurl = PackageURL( |
| 1268 | type=package_type, |
| 1269 | namespace=group_id, |
| 1270 | name=artifact_id, |
| 1271 | version=version, |
| 1272 | # we hardcode the source qualifier for now... |
| 1273 | qualifiers=dict(classifier='sources')) |
| 1274 | source_packages = [spurl.to_string()] |
| 1275 |
no test coverage detected