You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2017/02/20 22:48:30 UTC
svn commit: r1783807 - in
/felix/trunk/webconsole-plugins/servicediagnostics: core/
core/src/main/scala/servicediagnostics/
core/src/main/scala/servicediagnostics/impl/
core/src/main/scala/servicediagnostics/shell/
core/src/main/scala/servicediagnostic...
Author: pderop
Date: Mon Feb 20 22:48:30 2017
New Revision: 1783807
URL: http://svn.apache.org/viewvc?rev=1783807&view=rev
Log:
FELIX-5554: Remove usage of org.json from service diagnostics plugin
Modified:
felix/trunk/webconsole-plugins/servicediagnostics/core/pom.xml
felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/ServiceDiagnosticsPlugin.scala
felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/impl/ServiceDiagnosticsImpl.scala
felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/shell/CLI.scala
felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/webconsole/WebConsolePlugin.scala
felix/trunk/webconsole-plugins/servicediagnostics/parent/pom.xml
Modified: felix/trunk/webconsole-plugins/servicediagnostics/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/core/pom.xml?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/core/pom.xml (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/core/pom.xml Mon Feb 20 22:48:30 2017
@@ -50,12 +50,6 @@
<version>2.10.0</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <version>20090211</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
<build>
Modified: felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/ServiceDiagnosticsPlugin.scala
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/ServiceDiagnosticsPlugin.scala?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/ServiceDiagnosticsPlugin.scala (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/ServiceDiagnosticsPlugin.scala Mon Feb 20 22:48:30 2017
@@ -23,8 +23,6 @@ import collection.JavaConversions._
import scala.collection.mutable.{Map => mMap}
-import org.json.JSONObject
-
import Util._
/**
@@ -93,9 +91,26 @@ object Util
l.map(_.take(1)).mkString(".") + l.last.drop(1)
}
- /**
- * turn the ServiceDiagnostics output into a JSON representation.
- */
- def json(map:Map[String,Set[String]]) =
- new JSONObject(asJavaMap(mMap() ++ map.map(kv => (kv._1, asJavaList(kv._2.toList)))))
+}
+
+object JSON
+{
+ trait Json[T] {
+ def toJson(t:T):String
+ }
+ implicit object jsonStr extends Json[String] {
+ def toJson(s:String) = s""""$s""""
+ }
+ implicit object jsonInt extends Json[Int] {
+ def toJson(s:Int) = s"$s"
+ }
+ implicit def jsonSet[T:Json] = new Json[Set[T]] {
+ def toJson(l:Set[T]) = (l map (v => implicitly[Json[T]].toJson(v))).mkString("[",",","]")
+ }
+ implicit def jsonMap[T:Json] = new Json[Map[String,T]] {
+ def toJson(m:Map[String,T]) = (m map { case (k,v) =>
+ s""""$k":${implicitly[Json[T]].toJson(v)}""" }).mkString("{",",","}")
+ }
+
+ def json[T:Json](v:T) = implicitly[Json[T]].toJson(v)
}
Modified: felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/impl/ServiceDiagnosticsImpl.scala
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/impl/ServiceDiagnosticsImpl.scala?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/impl/ServiceDiagnosticsImpl.scala (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/impl/ServiceDiagnosticsImpl.scala Mon Feb 20 22:48:30 2017
@@ -28,6 +28,7 @@ import org.osgi.framework.Constants.OBJE
import org.apache.felix.servicediagnostics._
import org.apache.felix.servicediagnostics.Util._
+import org.apache.felix.servicediagnostics.JSON._
/**
* This is the ServiceDiagnostics implementation.
@@ -64,15 +65,6 @@ class ServiceDiagnosticsImpl(val bc:Bund
override def equals(o:Any) = o != null && o.getClass == getClass && o.asInstanceOf[Node].comp == comp
}
- //debug helper
- def json(l:Iterable[Node]) = l.toList.sortWith { (n1,n2) =>
- n1.name < n2.name
- }.foldLeft(new org.json.JSONArray()) { (j,n) =>
- j.put(new org.json.JSONObject(new java.util.HashMap[String,java.util.List[String]] {{
- put(n.name, new java.util.ArrayList[String] {{ addAll(n.edges.map(_.name)) }})
- }}))
- }.toString(2)
-
/**
* Implements ServiceDiagnostics.unresolved.
*
Modified: felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/shell/CLI.scala
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/shell/CLI.scala?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/shell/CLI.scala (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/shell/CLI.scala Mon Feb 20 22:48:30 2017
@@ -20,6 +20,7 @@ package org.apache.felix.servicediagnost
import org.apache.felix.servicediagnostics.ServiceDiagnostics
import org.apache.felix.servicediagnostics.Util._
+import org.apache.felix.servicediagnostics.JSON._
// old shell
import org.apache.felix.shell.Command
@@ -57,13 +58,13 @@ class CLI extends Command
// for old shell
override def execute(commandLine:String, out:PrintStream, err:PrintStream) = commandLine.split(" ").toList.tail match {
case "users"::Nil =>
- out.println(json(engine.usingBundles).toString(2))
+ out.println(json(engine.usingBundles))
case "providers"::Nil =>
- out.println(json(engine.serviceProviders).toString(2))
+ out.println(json(engine.serviceProviders))
case "b2b"::Nil =>
- out.println(json(engine.b2b).toString(2))
+ out.println(json(engine.b2b))
case "notavail"::Nil =>
- out.println(json(engine.notavail).toString(2))
+ out.println(json(engine.notavail))
case "loops"::tail => tail match {
case "-o"::Nil => showloops(out, true)
case _ => showloops(out, false)
@@ -73,7 +74,7 @@ class CLI extends Command
def showloops(out:PrintStream, o:Boolean) = {
val unresolved = engine.unresolved(o) // map(comp -> list(comp))
- out.println(json(unresolved).toString(2))
+ out.println(json(unresolved))
def follow(n:String, stack:Set[String] = Set()) :Set[String] =
if (stack contains n) stack
else unresolved.get(n) match {
Modified: felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/webconsole/WebConsolePlugin.scala
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/webconsole/WebConsolePlugin.scala?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/webconsole/WebConsolePlugin.scala (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/core/src/main/scala/servicediagnostics/webconsole/WebConsolePlugin.scala Mon Feb 20 22:48:30 2017
@@ -22,13 +22,11 @@ import java.io.PrintStream
import javax.servlet.http._
-import org.json.JSONObject
-import org.json.JSONArray
-
import org.apache.felix.webconsole.SimpleWebConsolePlugin
import org.apache.felix.servicediagnostics.ServiceDiagnostics
import org.apache.felix.servicediagnostics.Util._
+import org.apache.felix.servicediagnostics.JSON._
/**
* This is the Apache Felix WebConsolePlugin implementation.
@@ -57,11 +55,10 @@ class WebConsolePlugin extends SimpleWeb
case "/servicegraph/users" => resp.getWriter.println(json(engine.usingBundles))
case "/servicegraph/providers" => resp.getWriter.println(json(engine.serviceProviders))
case "/servicegraph/b2b" => resp.getWriter.println(json(engine.b2b))
- case "/servicegraph/notavail" => resp.getWriter.println(new JSONObject()
- .put("notavail", json(engine.notavail))
- .put("unresolved",
- json(engine.unresolved(
- Option(req.getParameter("optionals")).isDefined))))
+ case "/servicegraph/notavail" => resp.getWriter.println(json(Map(
+ "notavail" -> engine.notavail,
+ "unresolved" -> engine.unresolved(Option(req.getParameter("optionals")).isDefined)
+ )))
case x => super.doGet(req, resp)
}
}
Modified: felix/trunk/webconsole-plugins/servicediagnostics/parent/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/servicediagnostics/parent/pom.xml?rev=1783807&r1=1783806&r2=1783807&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/servicediagnostics/parent/pom.xml (original)
+++ felix/trunk/webconsole-plugins/servicediagnostics/parent/pom.xml Mon Feb 20 22:48:30 2017
@@ -91,7 +91,7 @@
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
- <version>3.1.2</version>
+ <version>3.2.2</version>
<executions>
<execution>
<goals>