From 36c653274b9f51c2c01c589ed663f5b23c62bfa5 Mon Sep 17 00:00:00 2001 From: simpadjo Date: Mon, 26 Feb 2024 22:28:19 +0100 Subject: [PATCH] Support project.* properties Signed-off-by: Evgenii Kuznetcov Signed-off-by: simpadjo --- .../com/here/bom/internal/BomReader.scala | 15 +++++++++-- .../psv/with_project_version/build.sbt | 6 +++++ .../project/build.properties | 1 + .../with_project_version/project/plugins.sbt | 7 +++++ .../src/main/scala/Demo.scala | 26 +++++++++++++++++++ .../sbt-test/psv/with_project_version/test | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 plugin/src/sbt-test/psv/with_project_version/build.sbt create mode 100644 plugin/src/sbt-test/psv/with_project_version/project/build.properties create mode 100644 plugin/src/sbt-test/psv/with_project_version/project/plugins.sbt create mode 100644 plugin/src/sbt-test/psv/with_project_version/src/main/scala/Demo.scala create mode 100644 plugin/src/sbt-test/psv/with_project_version/test diff --git a/plugin/src/main/scala/com/here/bom/internal/BomReader.scala b/plugin/src/main/scala/com/here/bom/internal/BomReader.scala index 230cb01..68f7544 100644 --- a/plugin/src/main/scala/com/here/bom/internal/BomReader.scala +++ b/plugin/src/main/scala/com/here/bom/internal/BomReader.scala @@ -184,8 +184,7 @@ class BomReader(pomLocator: IvyPomLocator, logger: Logger, scalaBinaryVersion: S rest match { case Nil => acc case (m, reader) :: children => { - val updatedProps = new Props(cumulativeProps) - updatedProps.putAll(reader.getPomProperties.asInstanceOf[Props]) + val updatedProps = mergeProperties(reader, cumulativeProps) val res = (ResolvedBom(m, reader, updatedProps), prio) attachInheritedProps(children, res :: acc, updatedProps, prio - 1) } @@ -195,6 +194,18 @@ class BomReader(pomLocator: IvyPomLocator, logger: Logger, scalaBinaryVersion: S attachInheritedProps(chain, Nil, rootProps, rootPriority) } + private def mergeProperties(reader: PomReader, props: Props): Props = { + val into = new Props(props) + into.putAll(reader.getPomProperties.asInstanceOf[Props]) + into.put("project.version", reader.getVersion) + into.put("project.groupId", reader.getGroupId) + into.put("project.artifactId", reader.getArtifactId) + into.put("project.version", reader.getVersion) + into.put("project.packaging", reader.getPackaging) + into.put("project.description", reader.getDescription) + into + } + private def buildParentsChain( module: NormalizedArtifact ): List[(NormalizedArtifact, PomReader)] = { diff --git a/plugin/src/sbt-test/psv/with_project_version/build.sbt b/plugin/src/sbt-test/psv/with_project_version/build.sbt new file mode 100644 index 0000000..76ca9c1 --- /dev/null +++ b/plugin/src/sbt-test/psv/with_project_version/build.sbt @@ -0,0 +1,6 @@ +import com.here.bom.Bom + +lazy val slf4jDeps = Bom.read("org.slf4j" % "slf4j-bom" % "2.0.12")(bom => "org.slf4j" % "slf4j-log4j12" % bom) +lazy val root = (project in file(".")) + .settings(slf4jDeps) + .settings(libraryDependencies += slf4jDeps.key.value) diff --git a/plugin/src/sbt-test/psv/with_project_version/project/build.properties b/plugin/src/sbt-test/psv/with_project_version/project/build.properties new file mode 100644 index 0000000..04267b1 --- /dev/null +++ b/plugin/src/sbt-test/psv/with_project_version/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.9 diff --git a/plugin/src/sbt-test/psv/with_project_version/project/plugins.sbt b/plugin/src/sbt-test/psv/with_project_version/project/plugins.sbt new file mode 100644 index 0000000..9f738c3 --- /dev/null +++ b/plugin/src/sbt-test/psv/with_project_version/project/plugins.sbt @@ -0,0 +1,7 @@ +addSbtPlugin("com.here.platform.artifact" % "sbt-resolver" % "2.0.24") + +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.here.platform" % "sbt-bom" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} \ No newline at end of file diff --git a/plugin/src/sbt-test/psv/with_project_version/src/main/scala/Demo.scala b/plugin/src/sbt-test/psv/with_project_version/src/main/scala/Demo.scala new file mode 100644 index 0000000..71378df --- /dev/null +++ b/plugin/src/sbt-test/psv/with_project_version/src/main/scala/Demo.scala @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019-2024 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ +package com.here.bom + +import org.slf4j.LoggerFactory + +object Demo extends App { + val logger = LoggerFactory.getLogger("name") + logger.info("Hello World") +} \ No newline at end of file diff --git a/plugin/src/sbt-test/psv/with_project_version/test b/plugin/src/sbt-test/psv/with_project_version/test new file mode 100644 index 0000000..9e4c237 --- /dev/null +++ b/plugin/src/sbt-test/psv/with_project_version/test @@ -0,0 +1 @@ +> run \ No newline at end of file