summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util
diff options
context:
space:
mode:
Diffstat (limited to 'bundle-plugin/src/main/scala/com/yahoo/container/plugin/util')
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Extractors.scala17
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Files.scala23
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/IO.scala46
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Iteration.scala14
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala24
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Maps.scala19
-rw-r--r--bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Strings.scala14
7 files changed, 0 insertions, 157 deletions
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Extractors.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Extractors.scala
deleted file mode 100644
index 83f23f905fb..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Extractors.scala
+++ /dev/null
@@ -1,17 +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.util
-
-/**
-* @author tonytv
-*/
-object Extractors {
- class ListOf[C](val c : Class[C]) {
- def unapply[X](xs : X) : Option[List[C]] = {
- xs match {
- case x :: xr if c.isInstance(x) => unapply(xr) map ( c.cast(x) :: _)
- case Nil => Some(Nil)
- case _ => None
- }
- }
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Files.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Files.scala
deleted file mode 100644
index d32e57784da..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Files.scala
+++ /dev/null
@@ -1,23 +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.util
-
-import java.io.{FileOutputStream, File}
-import com.yahoo.container.plugin.util.IO._
-
-/**
- * @author tonytv
- */
-object Files {
- def allDescendantFiles(file: File): Stream[File] = {
- if (file.isFile)
- Stream(file)
- else if (file.isDirectory)
- file.listFiles().toStream.map(allDescendantFiles).flatten
- else
- Stream.empty
- }
-
- def withFileOutputStream[T](file: File)(f: FileOutputStream => T): T = {
- using(new FileOutputStream(file), readOnly = false)(f)
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/IO.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/IO.scala
deleted file mode 100644
index 90f3eb3e7fd..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/IO.scala
+++ /dev/null
@@ -1,46 +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.util
-
-import java.io.{Closeable, FileOutputStream, OutputStream, FileInputStream, File}
-import util.control.Exception
-import scala.Either
-
-/** Utility methods relating to IO
- * @author tonytv
- */
-object IO {
- def withFileInputStream[T](file : File)(f : FileInputStream => T) = {
- using(new FileInputStream(file), readOnly = true)(f)
- }
-
- /**
- * Creates a new file and all it's parent directories,
- * and provides a file output stream to the file.
- *
- * Exceptions from closing have priority over exceptions from f.
- */
- def withFileOutputStream[T](file: File)(f: OutputStream => T) {
- makeDirectoriesRecursive(file.getParentFile)
- using(new FileOutputStream(file), readOnly = false )(f)
- }
-
- def makeDirectoriesRecursive(file: File) {
- if (!file.mkdirs() && !file.isDirectory) {
- throw new RuntimeException("Could not create directory " + file.getPath)
- }
- }
-
- def using[RESOURCE <: Closeable, T](resource : RESOURCE, readOnly : Boolean)(f : RESOURCE => T) : T = {
- def catchPromiscuously = Exception.catchingPromiscuously(classOf[Throwable])
-
- val resultOrException = catchPromiscuously either f(resource)
- val closeException = Exception.allCatch either resource.close()
-
- prioritizeFirstException(
- resultOrException,
- if (readOnly) Right(()) else closeException) fold (throw _, identity)
- }
-
- private def prioritizeFirstException[T](first: Either[Throwable, T], second: Either[Throwable, Unit]) =
- first fold ( Left(_), value => second fold ( Left(_), _ => Right(value) ) )
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Iteration.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Iteration.scala
deleted file mode 100644
index fa50f5cdd17..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Iteration.scala
+++ /dev/null
@@ -1,14 +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.util
-
- /**
- * @author tonytv
- */
-object Iteration {
- def toStream[T](enumeration: java.util.Enumeration[T]): Stream[T] = {
- if (enumeration.hasMoreElements)
- Stream.cons(enumeration.nextElement(), toStream(enumeration))
- else
- Stream.Empty
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
deleted file mode 100644
index d7578f2b338..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/JarFiles.scala
+++ /dev/null
@@ -1,24 +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.util
-
-import java.util.jar.JarFile
-import java.util.zip.{ZipFile, ZipEntry}
-import IO.using
-import java.io.{Closeable, InputStream, File}
-
-/**
- * @author tonytv
- */
-object JarFiles {
- def withJarFile[T](file : File)(f : JarFile => T ) : T =
- using(new JarFile(file) with Closeable, readOnly = true)(f)
-
- def withInputStream[T](zipFile: ZipFile, zipEntry: ZipEntry)(f: InputStream => T): T =
- using(zipFile.getInputStream(zipEntry), readOnly = true)(f)
-
- def getManifest(jarFile : File) : Option[java.util.jar.Manifest] = {
- withJarFile(jarFile) { jar =>
- Option(jar.getManifest)
- }
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Maps.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Maps.scala
deleted file mode 100644
index cafc8431b0e..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Maps.scala
+++ /dev/null
@@ -1,19 +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.util
-
-import collection.mutable.MultiMap
-
-/**
- * @author tonytv
- */
-object Maps {
- def combine[K, V](map1 : Map[K, V], map2 : Map[K, V])(f : (V, V) => V) : Map[K, V] = {
- def logicError : V = throw new RuntimeException("Logic error.")
- def combineValues(key : K) = key -> f(map1.getOrElse(key, logicError), map2.getOrElse(key, logicError))
-
- val keysInBoth = map1.keySet intersect map2.keySet
- def notInBoth = !keysInBoth.contains(_ : K)
-
- map1.filterKeys(notInBoth) ++ map2.filterKeys(notInBoth) ++ keysInBoth.map(combineValues)
- }
-}
diff --git a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Strings.scala b/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Strings.scala
deleted file mode 100644
index 5f854fda944..00000000000
--- a/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Strings.scala
+++ /dev/null
@@ -1,14 +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.util
-
- /**
- * @author tonytv
- */
-object Strings {
- def emptyStringTo(replacement: String)(s: String) = {
- if (s.isEmpty) replacement
- else s
- }
-
- def noneIfEmpty(s: String) = Option(s).filterNot(_.isEmpty)
-}