/
OSGiUtils.scala
32 lines (25 loc) · 1005 Bytes
/
OSGiUtils.scala
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
28
29
30
31
32
/*
* Copyright 2005-2010 LAMP/EPFL
*/
// $Id$
package scala.tools.eclipse.util
import java.io.IOException
import java.net.URL
import org.eclipse.core.runtime.FileLocator
import org.eclipse.core.runtime.IPath
import org.eclipse.core.runtime.Path
import org.osgi.framework.Bundle
object OSGiUtils {
private def urlToPath(url: URL): IPath = Path.fromOSString(FileLocator.toFileURL(url).getPath)
def pathInBundle(bundle: Bundle, path: String): Option[IPath] = {
val url = FileLocator.find(bundle, Path.fromPortableString(path), null)
Option(url) map urlToPath
}
def getBundlePath(bundle: Bundle): Option[IPath] = util.control.Exception.failing(classOf[IOException]) {
Option(FileLocator.getBundleFile(bundle)).map(f => Path.fromOSString(f.getAbsolutePath()))
}
def allPathsInBundle(bundle: Bundle, path: String, filePattern: String): Iterator[IPath] = {
import scala.collection.JavaConverters._
bundle.findEntries(path, filePattern, false).asScala map urlToPath
}
}