forked from CSUG/HouseMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed CSUG#60: Introduce command resources.
- Loading branch information
jushi
committed
Jul 2, 2012
1 parent
5671cd7
commit 1feea08
Showing
14 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ package com.github.zhongl.housemd.command | |
|
||
import java.lang.reflect.{Field, Method} | ||
import java.util.List | ||
import com.github.zhongl.housemd.misc.Reflections._ | ||
import com.github.zhongl.housemd.misc.ReflectionUtils._ | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">zhongl<a> | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/scala/com/github/zhongl/housemd/command/ClassSimpleName.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,27 +3,31 @@ package com.github.zhongl.housemd.command | |
import instrument.Instrumentation | ||
import com.github.zhongl.yascli.{Command, PrintOut} | ||
import collection.JavaConversions._ | ||
import org.reflections.Reflections | ||
import org.reflections.util.{ClasspathHelper, ConfigurationBuilder} | ||
import org.reflections.scanners.ResourcesScanner | ||
import com.google.common.base.Predicate | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">zhongl<a> | ||
*/ | ||
class Resources (inst: Instrumentation, out: PrintOut) | ||
extends Command("resources", "list source paths by resource name.", out) { | ||
|
||
private val resourceName = parameter[String]("name", "resource name.") | ||
private val regex = parameter[String]("regex", "resource name regex pattern.") | ||
|
||
private object Loader { | ||
def unapply(c: Class[_]) = if (c.getClassLoader == null) None else Some(c.getClassLoader) | ||
} | ||
|
||
def run() { | ||
val name = resourceName() | ||
val r = regex() | ||
val loaders = inst.getAllLoadedClasses collect {case Loader(cl) => cl } | ||
loaders foreach println | ||
println(name) | ||
val enumerations = loaders.distinct map {_.getResources(name)} | ||
val urls = for (e <- enumerations; url <- e) yield url | ||
val config = new ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(loaders: _*)).setScanners(new ResourcesScanner()) | ||
val reflections = new Reflections(config) | ||
|
||
urls.distinct foreach println | ||
val files = reflections.getResources(java.util.regex.Pattern.compile(r)) | ||
|
||
files foreach println | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import java.lang.reflect.{Method, Modifier} | |
* @author <a href="mailto:[email protected]">zhongl<a> | ||
*/ | ||
|
||
object Reflections { | ||
object ReflectionUtils { | ||
|
||
private val S = classOf[String] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,10 @@ import com.github.zhongl.housemd.instrument.Advice | |
/** | ||
* @author <a href="mailto:[email protected]">zhongl<a> | ||
*/ | ||
class ReflectionsSpec extends FunSpec with ShouldMatchers { | ||
describe("Reflection") { | ||
class ReflectionUtilsSpec extends FunSpec with ShouldMatchers { | ||
describe("ReflectionUtils") { | ||
it("should define Advice") { | ||
Reflections.loadOrDefine(classOf[Advice], new ClassLoader() { | ||
ReflectionUtils.loadOrDefine(classOf[Advice], new ClassLoader() { | ||
override def loadClass(name: String) = { | ||
if (name == classOf[Advice].getName) throw new ClassNotFoundException() | ||
else super.loadClass(name) | ||
|
@@ -36,17 +36,17 @@ class ReflectionsSpec extends FunSpec with ShouldMatchers { | |
|
||
it("shoulde get object native string"){ | ||
val o = new Object() | ||
Reflections.toNativeString(o) should be (o.toString) | ||
ReflectionUtils.toNativeString(o) should be (o.toString) | ||
} | ||
|
||
it("shoulde get or force to native string") { | ||
val o = new Object() | ||
Reflections.getOrForceToNativeString(o) should be (o.toString) | ||
ReflectionUtils.getOrForceToNativeString(o) should be (o.toString) | ||
} | ||
|
||
it("should force to native string") { | ||
val s = "hello" | ||
Reflections.getOrForceToNativeString(s) should be (Reflections.toNativeString(s)) | ||
ReflectionUtils.getOrForceToNativeString(s) should be (ReflectionUtils.toNativeString(s)) | ||
} | ||
} | ||
|
||
|
Empty file.