From 8b8c07251049fdc6eb3e70d13d8fa26258f088ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0est=C3=A1k=20V=C3=ADt?= Date: Mon, 22 Oct 2018 12:49:17 +0200 Subject: [PATCH] Added support for scanning of non-JAR packages from Maven --- app/controllers/LibraryAdvisor.scala | 5 +++-- app/services/OdcService.scala | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/controllers/LibraryAdvisor.scala b/app/controllers/LibraryAdvisor.scala index 7d0a14c..8919c9e 100644 --- a/app/controllers/LibraryAdvisor.scala +++ b/app/controllers/LibraryAdvisor.scala @@ -54,7 +54,8 @@ class LibraryAdvisor @Inject() ( val groupId = (xml \ "groupId").text val artifactId = (xml \ "artifactId").text val version = (xml \ "version").text - Left(odcService.scanMaven(groupId, artifactId, version)) + val depType = (xml \ "type").text + Left(odcService.scanMaven(groupId, artifactId, version, depType)) case other => Right(s"Unknown root XML element: $other") } @@ -68,7 +69,7 @@ class LibraryAdvisor @Inject() ( // https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/0.9.10 url.getPath.split('/') match { case Array("", "artifact", groupId, artifactId, version) => - Left(odcService.scanMaven(groupId, artifactId, version)) + Left(odcService.scanMaven(groupId, artifactId, version, "")) case _ => Right("Unknown path for mvnrepository.com: Expected https://mvnrepository.com/artifact///") } diff --git a/app/services/OdcService.scala b/app/services/OdcService.scala index a7f47ad..c2e4622 100644 --- a/app/services/OdcService.scala +++ b/app/services/OdcService.scala @@ -103,12 +103,9 @@ class OdcService @Inject() (odcConfig: OdcConfig, odcDbConnectionConfig: OdcDbCo result.copy(limitations = result.limitations ++ additionalLimitations) } - def scanMaven(groupId: String, artifactId: String, version: String): Future[SingleLibraryScanResult] = scanInternal( - createOdcCommand = createMavenOdcCommand, - isMainLibraryOption = Some(_.identifiers.exists(id => id.identifierType == "maven" && id.name == s"$groupId:$artifactId:$version")), - logChecks = mavenLogChecks - ){ (odcInstallation, dir) => - val pomXml = + def scanMaven(groupId: String, artifactId: String, version: String, depType: String): Future[SingleLibraryScanResult] = { + val allowMultiple = depType != "" + def pomXml(odcInstallation: OdcInstallation) = 4.0.0 com.ysoft odc-adhoc-project @@ -147,12 +144,24 @@ class OdcService @Inject() (odcConfig: OdcConfig, odcDbConnectionConfig: OdcDbCo {groupId} {artifactId} {version} + {if (depType != "") {depType}} - Files.write(dir.resolve("pom.xml"), pomXml.toString.getBytes(UTF_8)) - PreparationResult(includesTransitive = true) - }.map(addMavenLibsLimitations) + scanInternal( + createOdcCommand = createMavenOdcCommand, + isMainLibraryOption = Some(isMainMavenLib(groupId, artifactId, version, allowMultiple)(_)), + logChecks = mavenLogChecks, + enableMultipleMainLibraries = allowMultiple + ) { (odcInstallation, dir) => + Files.write(dir.resolve("pom.xml"), pomXml(odcInstallation).toString.getBytes(UTF_8)) + PreparationResult(includesTransitive = true) + }.map(addMavenLibsLimitations) + } + + private def isMainMavenLib(groupId: String, artifactId: String, version: String, allowMultiple: Boolean)(dep: AbstractDependency): Boolean = { + allowMultiple || dep.identifiers.exists(id => id.identifierType == "maven" && id.name == s"$groupId:$artifactId:$version") + } private def nugetRestore(odcInstallation: OdcInstallation, dir: Path, packagesConfigFile: Path, packageName: String, version: String): Unit = { val packagesConfig =