summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackages.scala
blob: 4a973c0b9b1b2bf1da55e437601f0221094343b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.osgi

/**
 * @author  tonytv
 */
object ExportPackages {

  case class Export(packageNames: List[String], parameters: List[Parameter]) {
    def version: Option[String] = {
      (for (
        param <- parameters if param.name == "version"
      ) yield param.value).
        headOption
    }
  }

  case class Parameter(name: String, value: String)

  def exportsByPackageName(exports: Seq[Export]): Map[String, Export] = {
    (for {
      export <- exports.reverse  //ensure that earlier exports of a package overrides later exports.
      packageName <- export.packageNames
    } yield packageName -> export).
      toMap
  }
}