Skip to content
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

Support project.* properties #18

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 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,17 @@ 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.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
Loading