Skip to content

Commit

Permalink
Upgrade version and copyright.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongl committed May 23, 2013
1 parent 0a0a12f commit 2915e06
Show file tree
Hide file tree
Showing 34 changed files with 253 additions and 243 deletions.
2 changes: 1 addition & 1 deletion acceptance-test/TraceTarget.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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(
Expand Down
24 changes: 6 additions & 18 deletions src/main/java/com/github/zhongl/housemd/command/Env.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.*;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/zhongl/housemd/command/Inspect.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/zhongl/housemd/duck/Duck.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}
11 changes: 6 additions & 5 deletions src/main/scala/com/github/zhongl/housemd/command/Loaded.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -70,7 +70,7 @@ object MethodFilter {
}
}

implicit val string2MethodFilters = (_: String).split("\\s+") map {apply}
implicit val string2MethodFilters = (_: String).split("\\s+") map { apply }
}


21 changes: 11 additions & 10 deletions src/main/scala/com/github/zhongl/housemd/command/Trace.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 _ =>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/com/github/zhongl/housemd/duck/Telephone.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand All @@ -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)
Expand Down
34 changes: 18 additions & 16 deletions src/main/scala/com/github/zhongl/housemd/house/House.scala
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,8 +16,6 @@

package com.github.zhongl.housemd.instrument

import java.util


/**
* @author <a href="mailto:[email protected]">zhongl<a>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit 2915e06

Please sign in to comment.