Skip to content

Commit

Permalink
Support project.* properties
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Kuznetcov <[email protected]>

Signed-off-by: simpadjo <[email protected]>
  • Loading branch information
simpadjo committed Feb 26, 2024
1 parent e139740 commit 36c6532
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugin/src/main/scala/com/here/bom/internal/BomReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)] = {
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/sbt-test/psv/with_project_version/build.sbt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.9
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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")
}
1 change: 1 addition & 0 deletions plugin/src/sbt-test/psv/with_project_version/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> run

0 comments on commit 36c6532

Please sign in to comment.