summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi
diff options
context:
space:
mode:
Diffstat (limited to 'bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi')
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackageParser.scala89
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackages.scala27
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ImportPackages.scala51
3 files changed, 0 insertions, 167 deletions
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackageParser.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackageParser.scala
deleted file mode 100644
index 5cd93e84e87..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackageParser.scala
+++ /dev/null
@@ -1,89 +0,0 @@
-// 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
-
-import scala.util.parsing.combinator.JavaTokenParsers
-import ExportPackages.{Parameter, Export}
-import com.yahoo.container.plugin.util.Extractors.ListOf
-import scala.util.parsing.input.CharSequenceReader
-import scala.annotation.tailrec
-
-/**
- * @author tonytv
- */
-object ExportPackageParser extends JavaTokenParsers {
- val ListOfParameter = new ListOf(classOf[Parameter])
-
-
- def exportPackage = rep1sep(export, ",")
-
- //TODO: remove when fix is in current scala library
- //Fix for https://github.com/scala/scala-parser-combinators/pull/4
- def stringLiteral_fixed: Parser[String] = ("\""+"""([^"\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*+"""+"\"").r
-
- @SuppressWarnings(Array("unchecked"))
- def export : Parser[Export] = packageName ~ opt(";" ~> (parameters | export)) ^^ {
- case (packageName : String) ~ optional => {
- optional match {
- case None => Export(List(packageName.asInstanceOf[String]), List())
- case Some(e: Export) => e.copy(packageNames = packageName +: e.packageNames)
- case Some(ListOfParameter(parameters)) => Export(List(packageName), parameters)
- }
- }
- }
-
- def parameters = rep1sep(parameter, ";")
-
- def parameter = (directive | attribute) ^^ {
- case k ~ v => Parameter(k.toString, v.toString)
- }
-
- def directive = (extended_ <~ ":=") ~ argument
- def attribute = (extended_ <~ "=") ~ argument
-
- def packageName = rep1sep(ident_, ".") ^^ {
- x => x.mkString(".")
- }
-
- def extended = rep1("""\p{Alnum}""".r | "_" | "-" | ".") ^^ {
- _.mkString
- }
-
- def argument = (extended_ | stringLiteral_ | failure("argument expected")) ^^ {
- val quote = '"'.toString
- _.toString.stripPrefix(quote).stripSuffix(quote)
- }
-
- def parseAll(in: CharSequence): ParseResult[List[Export]] = {
- try {
- parseAll(exportPackage, in)
- } catch {
- case e: StackOverflowError =>
- throw new RuntimeException("Failed parsing Export-Package: '''\n" + in + "\n'''", e)
- }
- }
-
- //*** For debugging StackOverflow error **/
- def ident_ = printStackOverflow(ident)("ident")
- def stringLiteral_ = printStackOverflow(stringLiteral_fixed)("stringLiteral_fixed")
- def extended_ = printStackOverflow(extended)("extended")
-
- def printStackOverflow[T](p: => Parser[T])(name: String): Parser[T] = Parser{ in =>
- try {
- p(in)
- } catch {
- case e: StackOverflowError =>
- val input = in match {
- case reader: CharSequenceReader => readerToString(reader)
- case other => other.toString
- }
- println(s"***StackOverflow for $name with input '''$input'''")
- throw e
- }
- }
-
- @tailrec
- def readerToString(reader: CharSequenceReader, current: String = ""): String = {
- if (reader.atEnd) current
- else readerToString(reader.rest, current + reader.first)
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackages.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackages.scala
deleted file mode 100644
index 4a973c0b9b1..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ExportPackages.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ImportPackages.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ImportPackages.scala
deleted file mode 100644
index b6b47b954c0..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/osgi/ImportPackages.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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
-
-import ExportPackages.Export
-import util.control.Exception
-
-/**
- * @author tonytv
- */
-object ImportPackages {
- case class Import(packageName : String, version : Option[String]) {
- val majorMinorMicroVersion = Exception.handling(classOf[NumberFormatException]).
- by( e => throw new IllegalArgumentException(
- "Invalid version number '%s' for package '%s'.".format(version.get, packageName), e)) {
-
- version map { _.split('.') take 3 map {_.toInt} }
- }
-
- def majorVersion = majorMinorMicroVersion map { _.head }
-
- // TODO: Detecting guava packages should be based on Bundle-SymbolicName, not package name.
- def importVersionRange = {
- def upperLimit =
- if (isGuavaPackage) InfiniteVersion // guava increases major version for each release
- else majorVersion.get + 1
-
- version map (v => "[%s,%s)".format(majorMinorMicroVersion.get.mkString("."), upperLimit))
- }
-
- def isGuavaPackage = packageName.equals(GuavaBasePackage) || packageName.startsWith(GuavaBasePackage + ".")
-
- def asOsgiImport = packageName + (importVersionRange map {";version=\"" + _ + '"'} getOrElse(""))
- }
-
-
- val GuavaBasePackage = "com.google.common"
- val InfiniteVersion = 99999
-
- def calculateImports(referencedPackages : Set[String],
- implementedPackages : Set[String],
- exportedPackages : Map[String, Export]) : Map[String, Import] = {
- (for {
- undefinedPackage <- referencedPackages diff implementedPackages
- export <- exportedPackages.get(undefinedPackage)
- } yield undefinedPackage -> Import(undefinedPackage, version(export)))(
- collection.breakOut)
- }
-
- def version(export: Export): Option[String] =
- export.parameters.find(_.name == "version").map(_.value)
-}