Skip to content
Browse files

Upgrade version and copyright.

  • Loading branch information...
1 parent 0a0a12f commit 2915e069ffc6ddb753f3a89f57d75fd09c918a31 @zhongl zhongl committed May 23, 2013
Showing with 253 additions and 243 deletions.
  1. +1 −1 acceptance-test/TraceTarget.java
  2. +2 −2 project/Build.scala
  3. +6 −18 src/main/java/com/github/zhongl/housemd/command/Env.java
  4. +2 −2 src/main/java/com/github/zhongl/housemd/command/Inspect.java
  5. +1 −1 src/main/java/com/github/zhongl/housemd/duck/Duck.java
  6. +9 −9 src/main/scala/com/github/zhongl/housemd/command/ClassMemberCompleter.scala
  7. +6 −5 src/main/scala/com/github/zhongl/housemd/command/Loaded.scala
  8. +5 −5 src/main/scala/com/github/zhongl/housemd/command/MethodFilter.scala
  9. +11 −10 src/main/scala/com/github/zhongl/housemd/command/Trace.scala
  10. +1 −1 src/main/scala/com/github/zhongl/housemd/command/TransformCommand.scala
  11. +4 −3 src/main/scala/com/github/zhongl/housemd/duck/Telephone.scala
  12. +18 −16 src/main/scala/com/github/zhongl/housemd/house/House.scala
  13. +2 −2 src/main/scala/com/github/zhongl/housemd/house/Mobilephone.scala
  14. +1 −1 src/main/scala/com/github/zhongl/housemd/instrument/Advice.java
  15. +1 −1 src/main/scala/com/github/zhongl/housemd/instrument/ClassDecorator.scala
  16. +1 −3 src/main/scala/com/github/zhongl/housemd/instrument/Context.scala
  17. +1 −1 src/main/scala/com/github/zhongl/housemd/instrument/Hook.scala
  18. +1 −1 src/main/scala/com/github/zhongl/housemd/instrument/Seconds.scala
  19. +33 −32 src/main/scala/com/github/zhongl/housemd/instrument/Transform.scala
  20. +2 −2 src/main/scala/com/github/zhongl/housemd/misc/ReflectionUtils.scala
  21. +7 −7 src/main/scala/com/github/zhongl/housemd/misc/Utils.scala
  22. +1 −1 src/test/scala/com/github/zhongl/housemd/command/AdviceReflection.scala
  23. +1 −1 src/test/scala/com/github/zhongl/housemd/command/ClassSimpleNameCompleterSpec.scala
  24. +7 −5 src/test/scala/com/github/zhongl/housemd/command/InspectSpec.scala
  25. +26 −22 src/test/scala/com/github/zhongl/housemd/command/LoadedSpec.scala
  26. +1 −1 src/test/scala/com/github/zhongl/housemd/command/MethodFilterCompleterSpec.scala
  27. +1 −1 src/test/scala/com/github/zhongl/housemd/command/MethodFilterSpec.scala
  28. +59 −54 src/test/scala/com/github/zhongl/housemd/command/TraceSpec.scala
  29. +35 −28 src/test/scala/com/github/zhongl/housemd/command/TransformCommandSpec.scala
  30. +2 −2 src/test/scala/com/github/zhongl/housemd/misc/ReflectionUtilsSpec.scala
  31. +2 −2 src/test/scala/com/github/zhongl/housemd/misc/UtilsSpec.scala
  32. +1 −1 src/test/scala/com/github/zhongl/test/A.scala
  33. +1 −1 src/test/scala/com/github/zhongl/test/F.scala
  34. +1 −1 src/test/scala/com/github/zhongl/test/I.scala
View
2 acceptance-test/TraceTarget.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
4 project/Build.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ object Build extends sbt.Build {
import Dependencies._
import Unmanaged._
- val VERSION = "0.2.4"
+ val VERSION = "0.2.5"
val javaHome = sys.props("java.home").replace("/jre", "")
lazy val proguard = proguardSettings ++ Seq(
View
24 src/main/java/com/github/zhongl/housemd/command/Env.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,26 +16,14 @@
package com.github.zhongl.housemd.command;
-import static com.github.zhongl.yascli.JavaConvertions.defaultConverter;
-import static com.github.zhongl.yascli.JavaConvertions.get;
-import static com.github.zhongl.yascli.JavaConvertions.is;
-import static com.github.zhongl.yascli.JavaConvertions.list;
-import static com.github.zhongl.yascli.JavaConvertions.manifest;
-import static com.github.zhongl.yascli.JavaConvertions.none;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
+import com.github.zhongl.yascli.Command;
+import com.github.zhongl.yascli.PrintOut;
import jline.console.completer.Completer;
import scala.Function0;
-import com.github.zhongl.yascli.Command;
-import com.github.zhongl.yascli.PrintOut;
+import java.util.*;
+
+import static com.github.zhongl.yascli.JavaConvertions.*;
/**
View
4 src/main/java/com/github/zhongl/housemd/command/Inspect.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
import java.util.List;
import java.util.Set;
-import static com.github.zhongl.housemd.misc.ReflectionUtils.*;
+import static com.github.zhongl.housemd.misc.ReflectionUtils.simpleNameOf;
import static com.github.zhongl.yascli.JavaConvertions.manifest;
import static com.github.zhongl.yascli.JavaConvertions.none;
View
2 src/main/java/com/github/zhongl/housemd/duck/Duck.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
18 src/main/scala/com/github/zhongl/housemd/command/ClassMemberCompleter.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,15 +53,15 @@ trait MethodFilterCompleter extends ClassMemberCompleter {
}
override protected def completeAll(classSimpleName: String, cursor: Int, candidates: List[CharSequence]) =
- allDeclaredMethodsOf(classSimpleName) {a => a} match {
+ allDeclaredMethodsOf(classSimpleName) { a => a } match {
case Array() => -1
- case all => all.flatten.sorted foreach {candidates.add}; cursor
+ case all => all.flatten.sorted foreach { candidates.add }; cursor
}
override protected def complete(simpleName: String, prefix: String, cursor: Int, candidates: List[CharSequence]) =
- allDeclaredMethodsOf(simpleName) {_ collect {case m if m.startsWith(prefix) => m }} match {
+ allDeclaredMethodsOf(simpleName) { _ collect { case m if m.startsWith(prefix) => m } } match {
case Array() => -1
- case all => all.flatten.sorted foreach {candidates.add}; cursor - prefix.length
+ case all => all.flatten.sorted foreach { candidates.add }; cursor - prefix.length
}
}
@@ -74,14 +74,14 @@ trait FieldFilterCompleter extends ClassMemberCompleter {
}
override protected def completeAll(classSimpleName: String, cursor: Int, candidates: List[CharSequence]) =
- allDeclaredFieldsOf(classSimpleName) {_ map {_.getName}} match {
+ allDeclaredFieldsOf(classSimpleName) { _ map { _.getName } } match {
case Array() => -1
- case all => all.flatten.sorted foreach {candidates.add}; cursor
+ case all => all.flatten.sorted foreach { candidates.add }; cursor
}
override protected def complete(simpleName: String, prefix: String, cursor: Int, candidates: List[CharSequence]) =
- allDeclaredFieldsOf(simpleName) {_ collect {case f if f.getName.startsWith(prefix) => f.getName }} match {
+ allDeclaredFieldsOf(simpleName) { _ collect { case f if f.getName.startsWith(prefix) => f.getName } } match {
case Array() => -1
- case all => all.flatten.sorted foreach {candidates.add}; cursor - prefix.length
+ case all => all.flatten.sorted foreach { candidates.add }; cursor - prefix.length
}
}
View
11 src/main/scala/com/github/zhongl/housemd/command/Loaded.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,11 +34,12 @@ class Loaded(val inst: Instrumentation, out: PrintOut)
override def run() {
val k = classSimpleName()
- val matched = inst.getAllLoadedClasses filter {simpleNameOf(_) == k}
+ val matched = inst.getAllLoadedClasses filter { simpleNameOf(_) == k }
if (matched.isEmpty) println("No matched class")
- else matched foreach { c =>
- println(c.getName + " -> " + sourceOf(Manifest.classType(c)))
- if (hierarchyable()) layout(Option(c.getClassLoader))
+ else matched foreach {
+ c =>
+ println(c.getName + " -> " + sourceOf(Manifest.classType(c)))
+ if (hierarchyable()) layout(Option(c.getClassLoader))
}
}
View
10 src/main/scala/com/github/zhongl/housemd/command/MethodFilter.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,16 +36,16 @@ class MethodFilter(classSimpleName: String, methodName: String = "*") {
}
}
- private def lazyFilter(cond: => Boolean)(m: String) = if (cond) {methodName == "*" || methodName == m} else false
+ private def lazyFilter(cond: => Boolean)(m: String) = if (cond) {methodName == "*" || methodName == m } else false
private def lazyFilter(c: Class[_]): (String => Boolean) = lazyFilter(filterOnly(c))
private def filterOnly(className: String, superClassName: String, interfaceNames: Array[String]): Boolean = {
if (classSimpleName.endsWith("+")) {
val realname = classSimpleName.dropRight(1)
(simpleNameOf(className) == realname ||
- superClassName != null && simpleNameOf(superClassName) == realname) ||
- interfaceNames.find(simpleNameOf(_) == realname).isDefined
+ superClassName != null && simpleNameOf(superClassName) == realname) ||
+ interfaceNames.find(simpleNameOf(_) == realname).isDefined
} else {
simpleNameOf(className) == classSimpleName
}
@@ -70,7 +70,7 @@ object MethodFilter {
}
}
- implicit val string2MethodFilters = (_: String).split("\\s+") map {apply}
+ implicit val string2MethodFilters = (_: String).split("\\s+") map { apply }
}
View
21 src/main/scala/com/github/zhongl/housemd/command/Trace.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ class Trace(val inst: Instrumentation, out: PrintOut)
maxClassLoaderLength = math.max(maxClassLoaderLength, statistic.loader.length)
maxMethodSignLength = math.max(maxMethodSignLength, statistic.methodSign.length)
- statistics = statistics find {_.filter(context)} match {
+ statistics = statistics find { _.filter(context) } match {
case Some(s) => (statistics - s) + (s + statistic)
case None => statistics + statistic
}
@@ -125,11 +125,11 @@ class Trace(val inst: Instrumentation, out: PrintOut)
def +(s: Statistic) = new Statistic(context, totalTimes + s.totalTimes, totalElapseMills + s.totalElapseMills)
def filter(context: Context) = this.context.loader == context.loader &&
- this.context.className == context.className &&
- this.context.methodName == context.methodName &&
- this.context.arguments.size == context.arguments.size &&
- this.context.descriptor == context.descriptor &&
- (isInit(context.methodName) || this.context.thisObject == context.thisObject)
+ this.context.className == context.className &&
+ this.context.methodName == context.methodName &&
+ this.context.arguments.size == context.arguments.size &&
+ this.context.descriptor == context.descriptor &&
+ (isInit(context.methodName) || this.context.thisObject == context.thisObject)
def reps(maxMethodSignLength: Int, maxClassLoaderLength: Int) =
"%1$-" + maxMethodSignLength + "s %2$-" + maxClassLoaderLength + "s %3$#9s %4$#9sms %5$s" format(
@@ -164,9 +164,10 @@ class DetailWriter(writer: BufferedWriter) {
writer.newLine()
context.resultOrException match {
- case Some(x) if x.isInstanceOf[Throwable] => x.asInstanceOf[Throwable].getStackTrace.foreach { s =>
- writer.write("\tat " + s)
- writer.newLine()
+ case Some(x) if x.isInstanceOf[Throwable] => x.asInstanceOf[Throwable].getStackTrace.foreach {
+ s =>
+ writer.write("\tat " + s)
+ writer.newLine()
}
case _ =>
}
View
2 src/main/scala/com/github/zhongl/housemd/command/TransformCommand.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
7 src/main/scala/com/github/zhongl/housemd/duck/Telephone.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@ import jline.console.ConsoleReader
import com.github.zhongl.yascli.{Shell, PrintOut, Command}
import jline.TerminalFactory
import jline.console.history.FileHistory
-import management.ManagementFactory
import java.io.File
import com.github.zhongl.housemd.command.Last
@@ -44,7 +43,9 @@ class Telephone(inst: Instrumentation, port: Int, classes: Array[Class[Command]]
new Shell(name = "housemd", description = "a runtime diagnosis tool of jvm.", reader = reader) {
private val lastCommand = new Last(out)
- override protected def commands = Quit :: helpCommand :: lastCommand :: classes.map {toCommand(_, PrintOut(reader))}.toList
+ override protected def commands = Quit :: helpCommand :: lastCommand :: classes
+ .map { toCommand(_, PrintOut(reader)) }
+ .toList
override def error(a: Any) {
super.error(a)
View
34 src/main/scala/com/github/zhongl/housemd/house/House.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,14 +33,16 @@ import java.util.jar.{Attributes, JarInputStream}
*/
object House extends Command("housemd", "a runtime diagnosis tool of JVM.", PrintOut(System.out)) with Application {
- implicit private val string2Port = { value: String =>
- val p = value.toInt
- if (p > 1024 && p < 65536) p else throw new IllegalArgumentException(", it should be between 1025 and 65535")
+ implicit private val string2Port = {
+ value: String =>
+ val p = value.toInt
+ if (p > 1024 && p < 65536) p else throw new IllegalArgumentException(", it should be between 1025 and 65535")
}
- implicit private val string2File = { value: String =>
- val file = new File(value)
- if (file.exists() && file.isFile) file else throw new IllegalArgumentException(", it should be an existed file")
+ implicit private val string2File = {
+ value: String =>
+ val file = new File(value)
+ if (file.exists() && file.isFile) file else throw new IllegalArgumentException(", it should be an existed file")
}
private val port = option[Int]("-p" :: "--port" :: Nil, "set console local socket server port number.", 54321)
@@ -49,15 +51,15 @@ object House extends Command("housemd", "a runtime diagnosis tool of JVM.", Prin
private lazy val agentJarFile = sourceOf(Manifest.classType(getClass))
private lazy val agentOptions = agentJarFile ::
- classNameOf[Telephone] ::
- port() ::
- classNameOf[Trace] ::
- classNameOf[Loaded] ::
- classNameOf[Env] ::
- classNameOf[Inspect] ::
- classNameOf[Prop] ::
- classNameOf[Resources] ::
- Nil
+ classNameOf[Telephone] ::
+ port() ::
+ classNameOf[Trace] ::
+ classNameOf[Loaded] ::
+ classNameOf[Env] ::
+ classNameOf[Inspect] ::
+ classNameOf[Prop] ::
+ classNameOf[Resources] ::
+ Nil
private lazy val errorDetailFile = "/tmp/housemd.err." + pid()
private lazy val errorDetailWriter = new BufferedWriter(new FileWriter(errorDetailFile))
View
4 src/main/scala/com/github/zhongl/housemd/house/Mobilephone.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ class Mobilephone(port: Int, handle: PartialFunction[Signal, Any]) extends Actor
def act() {
val a = self
- val hook = sys.addShutdownHook {a !? PowerOff}
+ val hook = sys.addShutdownHook { a !? PowerOff }
var killer = Option.empty[OutputChannel[Any]]
def select() {
View
2 src/main/scala/com/github/zhongl/housemd/instrument/Advice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/main/scala/com/github/zhongl/housemd/instrument/ClassDecorator.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
4 src/main/scala/com/github/zhongl/housemd/instrument/Context.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package com.github.zhongl.housemd.instrument
-import java.util
-
/**
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
View
2 src/main/scala/com/github/zhongl/housemd/instrument/Hook.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/main/scala/com/github/zhongl/housemd/instrument/Seconds.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
65 src/main/scala/com/github/zhongl/housemd/instrument/Transform.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,12 +19,10 @@ package com.github.zhongl.housemd.instrument
import java.lang.instrument.{ClassFileTransformer, Instrumentation}
import java.security.ProtectionDomain
import java.util.concurrent.atomic.AtomicInteger
-import actors.Actor._
import com.github.zhongl.housemd.misc.ReflectionUtils._
import com.github.zhongl.yascli.Loggable
import java.lang.System.{currentTimeMillis => now}
-import actors.TIMEOUT
import java.util
import scala.actors.Actor._
import scala.actors._
@@ -40,22 +38,23 @@ class Transform extends ((Instrumentation, Filter, Seconds, Int, Loggable, Hook)
implicit val l = log
implicit val h = hook
- val candidates = inst.getAllLoadedClasses filter { c =>
+ val candidates = inst.getAllLoadedClasses filter {
+ c =>
- @inline
- def skipClass(description: String)(cause: Class[_] => Boolean) =
- if (cause(c)) {log.warn("Skip %1$s %2$s" format(c, description)); false} else true
+ @inline
+ def skipClass(description: String)(cause: Class[_] => Boolean) =
+ if (cause(c)) {log.warn("Skip %1$s %2$s" format(c, description)); false } else true
- @inline
- def isNotBelongsHouseMD = skipClass("belongs to HouseMD") {_.getName.startsWith("com.github.zhongl.housemd")}
+ @inline
+ def isNotBelongsHouseMD = skipClass("belongs to HouseMD") { _.getName.startsWith("com.github.zhongl.housemd") }
- @inline
- def isNotInterface = skipClass("") {_.isInterface}
+ @inline
+ def isNotInterface = skipClass("") { _.isInterface }
- @inline
- def isNotFromBootClassLoader = skipClass("loaded from bootclassloader") {isFromBootClassLoader}
+ @inline
+ def isNotFromBootClassLoader = skipClass("loaded from bootclassloader") { isFromBootClassLoader }
- filter(c) && isNotBelongsHouseMD && isNotInterface && isNotFromBootClassLoader
+ filter(c) && isNotBelongsHouseMD && isNotInterface && isNotFromBootClassLoader
}
if (candidates.isEmpty) {
@@ -113,29 +112,31 @@ class Transform extends ((Instrumentation, Filter, Seconds, Int, Loggable, Hook)
}
private def probe(classes: Array[Class[_]], advice: Advice)(implicit inst: Instrumentation, log: Loggable) {
- classes foreach { c =>
- try {
- loadOrDefineAdviceClassFrom(c.getClassLoader)
- .getMethod(Advice.SET_DELEGATE, classOf[Object])
- .invoke(null, advice)
- inst.retransformClasses(c)
- log.info("Probe " + c)
- } catch {
- case e => log.warn("Failed to probe " + c + " because of " + e)
- }
+ classes foreach {
+ c =>
+ try {
+ loadOrDefineAdviceClassFrom(c.getClassLoader)
+ .getMethod(Advice.SET_DELEGATE, classOf[Object])
+ .invoke(null, advice)
+ inst.retransformClasses(c)
+ log.info("Probe " + c)
+ } catch {
+ case e => log.warn("Failed to probe " + c + " because of " + e)
+ }
}
}
// FIXME : reduce duplication between probe and reset .
private def reset(classes: Array[Class[_]])(implicit inst: Instrumentation, log: Loggable) {
- classes foreach { c =>
- try {
- loadOrDefineAdviceClassFrom(c.getClassLoader).getMethod(Advice.SET_DEFAULT_DELEGATE).invoke(null)
- inst.retransformClasses(c)
- log.info("Reset " + c)
- } catch {
- case e => log.warn("Failed to reset " + c + " because of " + e)
- }
+ classes foreach {
+ c =>
+ try {
+ loadOrDefineAdviceClassFrom(c.getClassLoader).getMethod(Advice.SET_DEFAULT_DELEGATE).invoke(null)
+ inst.retransformClasses(c)
+ log.info("Reset " + c)
+ } catch {
+ case e => log.warn("Failed to reset " + c + " because of " + e)
+ }
}
}
View
4 src/main/scala/com/github/zhongl/housemd/misc/ReflectionUtils.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ object ReflectionUtils {
def getOrForceToNativeString(instance: AnyRef) =
if (instance.toString.startsWith(instance.getClass + "@")) instance.toString else toNativeString(instance)
- /**see https://github.com/zhongl/HouseMD/issues/17 */
+ /** see https://github.com/zhongl/HouseMD/issues/17 */
def loadOrDefine(clazz: Class[_], inClassLoader: ClassLoader) = {
val name = clazz.getName
try {
View
14 src/main/scala/com/github/zhongl/housemd/misc/Utils.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,9 +31,9 @@ object Utils {
private val noPath = "null"
private[misc] object File {
- def unapply(url:URL) = url.getFile match {
+ def unapply(url: URL) = url.getFile match {
case FileRE(_, source) => Some(source)
- case _ => None
+ case _ => None
}
}
@@ -47,16 +47,16 @@ object Utils {
bytes.toByteArray
}
- def locationOf[T:Manifest] = Option(manifest[T].erasure.getProtectionDomain.getCodeSource) match {
+ def locationOf[T: Manifest] = Option(manifest[T].erasure.getProtectionDomain.getCodeSource) match {
case Some(codeSource) => Option(codeSource.getLocation)
case None => Option(manifest[T].erasure.getResource(resourceNameOf[T]))
}
- def resourceNameOf[T:Manifest] = "/" + manifest[T].erasure.getName.replace('.', '/') + ".class"
+ def resourceNameOf[T: Manifest] = "/" + manifest[T].erasure.getName.replace('.', '/') + ".class"
- def sourceOf[T:Manifest] = locationOf[T] match {
+ def sourceOf[T: Manifest] = locationOf[T] match {
case Some(File(path)) => path
- case None => noPath
+ case None => noPath
}
def classNameOf[T: Manifest] = manifest[T].erasure.getName
View
2 src/test/scala/com/github/zhongl/housemd/command/AdviceReflection.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/test/scala/com/github/zhongl/housemd/command/ClassSimpleNameCompleterSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
12 src/test/scala/com/github/zhongl/housemd/command/InspectSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,11 +56,13 @@ class InspectSpec extends FunSpec with ShouldMatchers with AdviceReflection {
host.receiveWithin(10) {
case TIMEOUT =>
invoke(classOf[A].getName, "m", "()V", g, Array.empty[AnyRef], null)
- case "exit" => cond = false
+ case "exit" => cond = false
}
}
- out.toString.split("\n").filter(l => !l.isEmpty && !l.startsWith("INFO")) should contain("G.i 5 " + g + " " + g.getClass.getClassLoader)
+ out.toString.split("\n").filter(l => !l.isEmpty && !l.startsWith("INFO")) should contain("G.i 5 " + g + " " + g
+ .getClass
+ .getClassLoader)
}
}
@@ -71,7 +73,7 @@ class InspectSpec extends FunSpec with ShouldMatchers with AdviceReflection {
doReturn(Array(classOf[G])).when(inst).getAllLoadedClasses
val candidates = new util.ArrayList[CharSequence]()
- inspect.complete("G.", 2, candidates) should be (2)
+ inspect.complete("G.", 2, candidates) should be(2)
candidates should contain("i".asInstanceOf[CharSequence])
}
@@ -83,7 +85,7 @@ class InspectSpec extends FunSpec with ShouldMatchers with AdviceReflection {
doReturn(Array(classOf[Duck])).when(inst).getAllLoadedClasses
val candidates = new util.ArrayList[CharSequence]()
- inspect.complete("Duc", 3, candidates) should be (0)
+ inspect.complete("Duc", 3, candidates) should be(0)
candidates should contain("Duck".asInstanceOf[CharSequence])
}
View
48 src/test/scala/com/github/zhongl/housemd/command/LoadedSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,41 +30,45 @@ import annotation.tailrec
class LoadedSpec extends FunSpec with ShouldMatchers {
describe("Loaded") {
it("should display the source jar of String") {
- parseAndRun("String") {_ should startWith("java.lang.String -> ")}
+ parseAndRun("String") { _ should startWith("java.lang.String -> ") }
}
it("should display the classloader hierarchies") {
- parseAndRun("-h Loaded") { out =>
- val lines = out.split("\n")
- lines.head should startWith("com.github.zhongl.housemd.command.Loaded -> ")
-
- @tailrec
- def eq(list: List[String], classLoader: ClassLoader) {
- list match {
- case head :: tail => head should endWith(classLoader.toString); eq(tail, classLoader.getParent)
- case Nil => // end
+ parseAndRun("-h Loaded") {
+ out =>
+ val lines = out.split("\n")
+ lines.head should startWith("com.github.zhongl.housemd.command.Loaded -> ")
+
+ @tailrec
+ def eq(list: List[String], classLoader: ClassLoader) {
+ list match {
+ case head :: tail => head should endWith(classLoader.toString); eq(tail, classLoader.getParent)
+ case Nil => // end
+ }
}
- }
- eq(lines.tail.toList, classOf[Loaded].getClassLoader)
+ eq(lines.tail.toList, classOf[Loaded].getClassLoader)
}
}
it("should complete class simple name") {
- complete("Lo") { (cursor, candidates) =>
- cursor should be(0)
- candidates should contain("Loaded".asInstanceOf[CharSequence])
+ complete("Lo") {
+ (cursor, candidates) =>
+ cursor should be(0)
+ candidates should contain("Loaded".asInstanceOf[CharSequence])
}
- complete("-h Lo") { (cursor, candidates) =>
- cursor should be(3)
- candidates should contain("Loaded".asInstanceOf[CharSequence])
+ complete("-h Lo") {
+ (cursor, candidates) =>
+ cursor should be(3)
+ candidates should contain("Loaded".asInstanceOf[CharSequence])
}
}
it("should complete all class simple name") {
- complete("") { (cursor, candidates) =>
- cursor should be(0)
- candidates should not be ('empty)
+ complete("") {
+ (cursor, candidates) =>
+ cursor should be(0)
+ candidates should not be ('empty)
}
}
View
2 src/test/scala/com/github/zhongl/housemd/command/MethodFilterCompleterSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/test/scala/com/github/zhongl/housemd/command/MethodFilterSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
113 src/test/scala/com/github/zhongl/housemd/command/TraceSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ class TraceSpec extends FunSpec with ShouldMatchers with AdviceReflection {
trace.stackFile.delete()
val host = self
- actor {trace.run(); host ! "exit"}
+ actor { trace.run(); host ! "exit" }
var cond = true
while (cond) {
@@ -64,76 +64,81 @@ class TraceSpec extends FunSpec with ShouldMatchers with AdviceReflection {
describe("Trace") {
it("should display statistics") {
- parseAndRun("-t 3 A.m") { (out, detail, stack) =>
- val methodFullName = """[\.\w\(\),\$ <>]+"""
- val objectToString = """[\.\w,@\$ \[\]]+"""
- val number = """\d+\s+"""
- val elapse = """<?\d+ms"""
- out.split("\n").filter(s => !s.startsWith("INFO") && !s.isEmpty).tail foreach {
- _ should fullyMatch regex (methodFullName + objectToString + number + elapse + objectToString)
- }
+ parseAndRun("-t 3 A.m") {
+ (out, detail, stack) =>
+ val methodFullName = """[\.\w\(\),\$ <>]+"""
+ val objectToString = """[\.\w,@\$ \[\]]+"""
+ val number = """\d+\s+"""
+ val elapse = """<?\d+ms"""
+ out.split("\n").filter(s => !s.startsWith("INFO") && !s.isEmpty).tail foreach {
+ _ should fullyMatch regex (methodFullName + objectToString + number + elapse + objectToString)
+ }
}
}
it("should output invocation details") {
- parseAndRun("-d -t 1 -l 1 A") { (out, detail, stack) =>
- out.split("\n") should contain("INFO : You can get invocation detail from " + detail)
-
- val date = """\d{4}-\d{2}-\d{2}"""
- val time = """\d{2}:\d{2}:\d{2}"""
- val elapse = """\d+ms"""
- val thread = """\[[^\]]+\]"""
- val thisObject = """com\.github\.zhongl\.test\.A@[\da-f]+"""
- val name = """com\.github\.zhongl\.test\.A\.(m|<init>)"""
- val arguments = """\[\]"""
- val result = "void"
- Source.fromFile(detail).getLines() foreach {
- _ should fullyMatch regex ((date :: time :: elapse :: thread :: thisObject :: name :: arguments :: result :: Nil)
- .mkString(" "))
- }
+ parseAndRun("-d -t 1 -l 1 A") {
+ (out, detail, stack) =>
+ out.split("\n") should contain("INFO : You can get invocation detail from " + detail)
+
+ val date = """\d{4}-\d{2}-\d{2}"""
+ val time = """\d{2}:\d{2}:\d{2}"""
+ val elapse = """\d+ms"""
+ val thread = """\[[^\]]+\]"""
+ val thisObject = """com\.github\.zhongl\.test\.A@[\da-f]+"""
+ val name = """com\.github\.zhongl\.test\.A\.(m|<init>)"""
+ val arguments = """\[\]"""
+ val result = "void"
+ Source.fromFile(detail).getLines() foreach {
+ _ should fullyMatch regex ((date :: time :: elapse :: thread :: thisObject :: name :: arguments :: result :: Nil)
+ .mkString(" "))
+ }
}
}
it("should output invocation details with exception stack trace") {
- parseAndRun("-d -t 1 -l 1 A", new Exception) { (out, detail, stack) =>
- val date = """\d{4}-\d{2}-\d{2}"""
- val time = """\d{2}:\d{2}:\d{2}"""
- val elapse = """\d+ms"""
- val thread = """\[[^\]]+\]"""
- val thisObject = """com\.github\.zhongl\.test\.A@[\da-f]+"""
- val name = """com\.github\.zhongl\.test\.A\.(m|<init>)"""
- val arguments = """\[\]"""
- val result = "java\\.lang\\.Exception"
- val log = (date :: time :: elapse :: thread :: thisObject :: name :: arguments :: result :: Nil).mkString(" ")
- Source.fromFile(detail).getLines() foreach {
- _ should {
- fullyMatch regex log or fullyMatch regex ("\\tat .+")
+ parseAndRun("-d -t 1 -l 1 A", new Exception) {
+ (out, detail, stack) =>
+ val date = """\d{4}-\d{2}-\d{2}"""
+ val time = """\d{2}:\d{2}:\d{2}"""
+ val elapse = """\d+ms"""
+ val thread = """\[[^\]]+\]"""
+ val thisObject = """com\.github\.zhongl\.test\.A@[\da-f]+"""
+ val name = """com\.github\.zhongl\.test\.A\.(m|<init>)"""
+ val arguments = """\[\]"""
+ val result = "java\\.lang\\.Exception"
+ val log = (date :: time :: elapse :: thread :: thisObject :: name :: arguments :: result :: Nil).mkString(" ")
+ Source.fromFile(detail).getLines() foreach {
+ _ should {
+ fullyMatch regex log or fullyMatch regex ("\\tat .+")
+ }
}
- }
}
}
it("should output invocation stack") {
- parseAndRun("-s -l 1 A") { (out, detail, stack) =>
- out.split("\n") should contain("INFO : You can get invocation stack from " + stack)
-
- val lines = Source.fromFile(stack).getLines().toList.dropRight(1)
- val head = """com\.github\.zhongl\.test\.A\.m\(\)V call by thread \[[\w-]+\]""".r
- val st = """\t\S+\(\S+:\d+\)""".r
- lines.tail foreach {
- _ match {
- case head() =>
- case st() =>
- case "" =>
- case _ => fail()
+ parseAndRun("-s -l 1 A") {
+ (out, detail, stack) =>
+ out.split("\n") should contain("INFO : You can get invocation stack from " + stack)
+
+ val lines = Source.fromFile(stack).getLines().toList.dropRight(1)
+ val head = """com\.github\.zhongl\.test\.A\.m\(\)V call by thread \[[\w-]+\]""".r
+ val st = """\t\S+\(\S+:\d+\)""".r
+ lines.tail foreach {
+ _ match {
+ case head() =>
+ case st() =>
+ case "" =>
+ case _ => fail()
+ }
}
- }
}
}
it("should only include package com.github") {
- parseAndRun("-p com\\.github String") { (out, detail, stack) =>
- out should not be ("No matched class")
+ parseAndRun("-p com\\.github String") {
+ (out, detail, stack) =>
+ out should not be ("No matched class")
}
}
View
63 src/test/scala/com/github/zhongl/housemd/command/TransformCommandSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ class TransformCommandSpec extends FunSpec with ShouldMatchers with AdviceReflec
concrete.parse(arguments.split("\\s+"))
val host = self
- actor {concrete.run(); host ! "exit"}
+ actor { concrete.run(); host ! "exit" }
var cond = true
while (cond) {
@@ -83,56 +83,63 @@ class TransformCommandSpec extends FunSpec with ShouldMatchers with AdviceReflec
describe("TransformCommand") {
it("should probe final class") {
- parseAndRun("-l 1 F.m") { out =>
- out.split("\n").filter(!_.startsWith("INFO")) foreach {
- _ should fullyMatch regex ("F.+")
- }
+ parseAndRun("-l 1 F.m") {
+ out =>
+ out.split("\n").filter(!_.startsWith("INFO")) foreach {
+ _ should fullyMatch regex ("F.+")
+ }
}
}
it("should reset by overlimit") {
- parseAndRun("-l 1 -t 3 A") { out =>
- out.split("\n").dropRight(1).last should be("INFO : Ended by overlimit")
+ parseAndRun("-l 1 -t 3 A") {
+ out =>
+ out.split("\n").dropRight(1).last should be("INFO : Ended by overlimit")
}
}
it("should reset by timeout") {
- parseAndRun("-l 100000 -t 1 A") { out =>
- out.split("\n").dropRight(1).last should be("INFO : Ended by timeout")
+ parseAndRun("-l 100000 -t 1 A") {
+ out =>
+ out.split("\n").dropRight(1).last should be("INFO : Ended by timeout")
}
}
it("should not probe class loaded by boot classloader") {
- parseAndRun("String") { out =>
- out.split("\n").head should be("WARN : Skip " + classOf[String] + " loaded from bootclassloader")
+ parseAndRun("String") {
+ out =>
+ out.split("\n").head should be("WARN : Skip " + classOf[String] + " loaded from bootclassloader")
}
}
it("should not probe interface") {
- parseAndRun("I") { out =>
- out.split("\n") should {
- contain("WARN : Skip " + classOf[I])
- contain("No matched class")
- }
+ parseAndRun("I") {
+ out =>
+ out.split("\n") should {
+ contain("WARN : Skip " + classOf[I])
+ contain("No matched class")
+ }
}
}
it("should not probe classes belongs to HouseMD") {
- parseAndRun("Duck") { out =>
- out.split("\n") should {
- contain("WARN : Skip " + classOf[Duck] + " belongs to HouseMD.")
- contain("No matched class")
- }
+ parseAndRun("Duck") {
+ out =>
+ out.split("\n") should {
+ contain("WARN : Skip " + classOf[Duck] + " belongs to HouseMD.")
+ contain("No matched class")
+ }
}
}
it("should probe F by I+") {
- parseAndRun("-l 1 I+") { out =>
- val withoutInfo = out.split("\n").filter(!_.startsWith("INFO"))
- withoutInfo.head should be("WARN : Skip " + classOf[I] + " ")
- withoutInfo.tail foreach {
- _ should fullyMatch regex ("F.+")
- }
+ parseAndRun("-l 1 I+") {
+ out =>
+ val withoutInfo = out.split("\n").filter(!_.startsWith("INFO"))
+ withoutInfo.head should be("WARN : Skip " + classOf[I] + " ")
+ withoutInfo.tail foreach {
+ _ should fullyMatch regex ("F.+")
+ }
}
}
View
4 src/test/scala/com/github/zhongl/housemd/misc/ReflectionUtilsSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class ReflectionUtilsSpec extends FunSpec with ShouldMatchers {
}
it("should include <init> if it is a class") {
- ReflectionUtils.constructorAndMethodNamesOf(classOf[A]) should contain ("<init>")
+ ReflectionUtils.constructorAndMethodNamesOf(classOf[A]) should contain("<init>")
}
it("should not include <init> if it is a interface") {
View
4 src/test/scala/com/github/zhongl/housemd/misc/UtilsSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import Utils._
* @author <a href="mailto:zhong.lunfu@gmail.com">zhongl<a>
*/
-class UtilsSpec extends FunSpec with ShouldMatchers{
+class UtilsSpec extends FunSpec with ShouldMatchers {
describe("Untils") {
it("should convert input stream to bytes") {
View
2 src/test/scala/com/github/zhongl/test/A.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/test/scala/com/github/zhongl/test/F.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
View
2 src/test/scala/com/github/zhongl/test/I.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 zhongl
+ * Copyright 2013 zhongl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

0 comments on commit 2915e06

Please sign in to comment.
Something went wrong with that request. Please try again.