From 6d08649da0bf5820117f8d416c2e4d63c161abde Mon Sep 17 00:00:00 2001
From: Calvin
Date: Fri, 4 May 2012 01:08:23 +0800
Subject: [PATCH] cleanup
---
examples/mini-service/pom.xml | 5 ---
examples/mini-web/pom.xml | 5 ---
examples/showcase/pom.xml | 5 ---
.../showcase/utilities/string/StringDemo.java | 41 +++++++++++++++---
.../webapp/WEB-INF/views/story/utilizes.jsp | 2 +-
.../WEB-INF/views/web/mashup-client.jsp | 2 +-
modules/core/pom.xml | 6 +--
.../modules/utils/PropertiesLoader.java | 24 +++++++----
modules/extension/pom.xml | 5 ---
.../memcached/SpyMemcachedClientTest.java | 4 +-
modules/parent/bin/eclipse.bat | 9 ----
modules/parent/{bin => }/install.bat | 2 -
modules/parent/pom.xml | 43 ++++++++-----------
modules/test/pom.xml | 5 ---
14 files changed, 73 insertions(+), 85 deletions(-)
delete mode 100644 modules/parent/bin/eclipse.bat
rename modules/parent/{bin => }/install.bat (89%)
diff --git a/examples/mini-service/pom.xml b/examples/mini-service/pom.xml
index fcd4dfd9..57ec6c65 100644
--- a/examples/mini-service/pom.xml
+++ b/examples/mini-service/pom.xml
@@ -181,11 +181,6 @@
junit
-
- org.hamcrest
- hamcrest-library
-
-
org.mockito
mockito-core
diff --git a/examples/mini-web/pom.xml b/examples/mini-web/pom.xml
index bf8221bc..8707b187 100644
--- a/examples/mini-web/pom.xml
+++ b/examples/mini-web/pom.xml
@@ -199,11 +199,6 @@
junit
-
- org.hamcrest
- hamcrest-library
-
-
org.mockito
mockito-core
diff --git a/examples/showcase/pom.xml b/examples/showcase/pom.xml
index f2d65a7c..964d7a6d 100644
--- a/examples/showcase/pom.xml
+++ b/examples/showcase/pom.xml
@@ -345,11 +345,6 @@
compile
-
- org.hamcrest
- hamcrest-library
-
-
org.mockito
mockito-core
diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/string/StringDemo.java b/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/string/StringDemo.java
index 3e74df54..146de77f 100644
--- a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/string/StringDemo.java
+++ b/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/string/StringDemo.java
@@ -13,15 +13,31 @@ import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+/**
+ * 演示Apache Commons Lang3的StringUtils 和 Guava的Joiner和Spliter。
+ *
+ * Apache的StringUtils已提供绝大多数常用的Null Safe的函数,
+ * Guava提供的是高级版的Joiner和Spliter,Case Format转换等高级函数.
+ *
+ * @author calvin
+ */
public class StringDemo {
+ /**
+ * Apache提供的最常用的Null Safe的函数。
+ * 另有一些与String一样,但Null Safe的函数如indexOf(),没有一一演示。
+ */
@Test
public void utilsByApache() {
- //非空,最常用函数
+ //判断非空,最常用函数
assertFalse(StringUtils.isNotBlank(null));
assertFalse(StringUtils.isNotBlank(""));
assertFalse(StringUtils.isNotBlank(" "));
+ //default值
+ assertEquals("defaultStr", StringUtils.defaultIfBlank(null, "defaultStr"));
+ assertEquals("defaultStr", StringUtils.defaultIfBlank("", "defaultStr"));
+
//截取字符串
String input = "hahakaka";
String result = StringUtils.substringAfter(input, "ha");
@@ -44,23 +60,31 @@ public class StringDemo {
result = StringUtils.leftPad("1", 3, '0');
assertEquals("001", result);
+ //超长部分变省略号
+ assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", 7));
+ assertEquals("abc...", StringUtils.abbreviate("abcdefg", 6));
+ assertEquals("ab...", StringUtils.abbreviate("abcdefg", 5));
+
//首字母大写
result = StringUtils.capitalize("abc");
assertEquals("Abc", result);
}
+ /**
+ * Guava的高级版Joiner,Splitter的函数与Joiner类似而相反,不再演示。
+ */
@Test
- public void joinByGuava() {
+ public void joinerByGuava() {
//忽略Null值。
String[] fantasyGenres = { "Space Opera", null, "Horror", "Magic realism", null, "Religion" };
String joined = Joiner.on(", ").skipNulls().join(fantasyGenres);
- System.out.println(joined);
+ assertEquals("Space Opera, Horror, Magic realism, Religion", joined);
//将Null值转换为特定字符串.
String[] fantasyGenres2 = { "Space Opera", null, "Horror", "Magic realism", null, "Religion" };
joined = Joiner.on(", ").useForNull("NULL!!!").join(fantasyGenres2);
- System.out.println(joined);
+ assertEquals("Space Opera, NULL!!!, Horror, Magic realism, NULL!!!, Religion", joined);
//join Map类型
Map map = Maps.newHashMap();
@@ -68,14 +92,17 @@ public class StringDemo {
map.put(2, "Horror");
map.put(3, "Magic realism");
joined = Joiner.on(",").withKeyValueSeparator(":").join(map);
- System.out.println(joined);
+ assertEquals("1:Space Opera,2:Horror,3:Magic realism", joined);
//append一个已存在的字符串
- StringBuilder sb = new StringBuilder("StringBulder Demo: ");
+ StringBuilder sb = new StringBuilder("Append StringBulder demo: ");
joined = Joiner.on(", ").skipNulls().appendTo(sb, fantasyGenres).toString();
- System.out.println(joined);
+ assertEquals("Append StringBulder demo: Space Opera, Horror, Magic realism, Religion", joined);
}
+ /**
+ * 好玩的CaseFormat转换,在spaceSize->space_size之间转换,比如数据库列名与Java属性。
+ */
@Test
public void caseFormatByGuava() {
String name = "SPACE_SIZE";
diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp
index 14ba227e..2e8eb353 100644
--- a/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp
+++ b/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp
@@ -38,7 +38,7 @@
日志演示
- Log4JManager: 通过JMX动态查询与改变Logger的日志等级与Appender, 详见JMX页面.
- - MockLog4jAppender: 在测试用例中验证日志的输出, 在Schedule测试用例使用MockAppender校验日志输出.
+ - Log4MockjAppender: 在测试用例中验证日志的输出, 在Schedule测试用例使用MockAppender校验日志输出.
其他常用工具
diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/web/mashup-client.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/web/mashup-client.jsp
index cdef6bfe..0ae14430 100644
--- a/examples/showcase/src/main/webapp/WEB-INF/views/web/mashup-client.jsp
+++ b/examples/showcase/src/main/webapp/WEB-INF/views/web/mashup-client.jsp
@@ -29,7 +29,7 @@
演示基于JQuery的JSONP实现,绕过浏览器对Ajax不能访问跨域名网站内容的限制实现Mashup.
请先将本页另存为本地html文件,打开本地文件访问本地应用服务器中的内容即为跨域访问的场景.
-
+
跨域页面内容:
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index 01bcbff6..b6eb55d1 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -122,11 +122,7 @@
junit
junit
-
- org.hamcrest
- hamcrest-library
-
-
+
org.mockito
mockito-core
diff --git a/modules/core/src/main/java/org/springside/modules/utils/PropertiesLoader.java b/modules/core/src/main/java/org/springside/modules/utils/PropertiesLoader.java
index 99ae71b3..34a1e05c 100644
--- a/modules/core/src/main/java/org/springside/modules/utils/PropertiesLoader.java
+++ b/modules/core/src/main/java/org/springside/modules/utils/PropertiesLoader.java
@@ -12,6 +12,7 @@ import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;
@@ -54,15 +55,11 @@ public class PropertiesLoader {
}
/**
- * 取出Property,但以System的Property优先.
+ * 取出Property,但以System的Property优先.如果都為Null則返回Default值.
*/
public String getProperty(String key, String defaultValue) {
String result = getProperty(key);
- if (result != null) {
- return result;
- } else {
- return defaultValue;
- }
+ return StringUtils.defaultString(result, defaultValue);
}
/**
@@ -76,7 +73,12 @@ public class PropertiesLoader {
* 取出Property,但以System的Property优先.
*/
public Integer getInteger(String key, Integer defaultValue) {
- return Integer.valueOf(getProperty(key, String.valueOf(defaultValue)));
+ String strResult = getProperty(key);
+ if (strResult != null) {
+ return Integer.valueOf(strResult);
+ } else {
+ return defaultValue;
+ }
}
/**
@@ -90,7 +92,13 @@ public class PropertiesLoader {
* 取出Property,但以System的Property优先.
*/
public Boolean getBoolean(String key, boolean defaultValue) {
- return Boolean.valueOf(getProperty(key, String.valueOf(defaultValue)));
+ String strResult = getProperty(key);
+ if (strResult != null) {
+ return Boolean.valueOf(strResult);
+ } else {
+ return defaultValue;
+ }
+
}
/**
diff --git a/modules/extension/pom.xml b/modules/extension/pom.xml
index f0841e13..fe00d920 100644
--- a/modules/extension/pom.xml
+++ b/modules/extension/pom.xml
@@ -75,11 +75,6 @@
junit
junit
-
-
- org.hamcrest
- hamcrest-library
-
org.mockito
diff --git a/modules/extension/src/test/java/org/springside/modules/memcached/SpyMemcachedClientTest.java b/modules/extension/src/test/java/org/springside/modules/memcached/SpyMemcachedClientTest.java
index da4f0498..19cbca04 100644
--- a/modules/extension/src/test/java/org/springside/modules/memcached/SpyMemcachedClientTest.java
+++ b/modules/extension/src/test/java/org/springside/modules/memcached/SpyMemcachedClientTest.java
@@ -22,12 +22,12 @@ public class SpyMemcachedClientTest extends SpringContextTestCase {
String value = "admin";
spyMemcachedClient.set(key, 60 * 60 * 1, value);
- Threads.sleep(1000);
+ Threads.sleep(2000);
String result = spyMemcachedClient.get(key);
assertEquals(value, result);
spyMemcachedClient.delete(key);
- Threads.sleep(1000);
+ Threads.sleep(2000);
result = spyMemcachedClient.get(key);
assertNull(result);
}
diff --git a/modules/parent/bin/eclipse.bat b/modules/parent/bin/eclipse.bat
deleted file mode 100644
index 57cd4e9f..00000000
--- a/modules/parent/bin/eclipse.bat
+++ /dev/null
@@ -1,9 +0,0 @@
-@echo off
-echo [INFO] Use maven eclipse plugin download jar and generate eclipse project files.
-echo [INFO] Please add "-Declipse.workspace=" at end of mvn command.
-
-cd %~dp0
-cd ..
-call mvn eclipse:clean eclipse:eclipse
-cd bin
-pause
\ No newline at end of file
diff --git a/modules/parent/bin/install.bat b/modules/parent/install.bat
similarity index 89%
rename from modules/parent/bin/install.bat
rename to modules/parent/install.bat
index f5aa3d83..d726fa0a 100644
--- a/modules/parent/bin/install.bat
+++ b/modules/parent/install.bat
@@ -2,7 +2,5 @@
echo [INFO] Install jar to local repository.
cd %~dp0
-cd ..
call mvn clean install -Dmaven.test.skip=true
-cd bin
pause
\ No newline at end of file
diff --git a/modules/parent/pom.xml b/modules/parent/pom.xml
index 9fe2ef8d..cca0e1e1 100644
--- a/modules/parent/pom.xml
+++ b/modules/parent/pom.xml
@@ -14,6 +14,7 @@
3.1.1.RELEASE
4.1.2
3.1.1
+ 1.0.3.RELEASE
2.6.0
1.12
1.2.0
@@ -22,9 +23,14 @@
2.5.2
4.2.0.Final
2.0.1
+ 11.0.2
+ 3.1
1.6.4
7.6.3.v20120416
1.3.166
+ 4.10
+ 1.9.0
+ 1.4.12
2.21.0
@@ -41,7 +47,7 @@
http://localhost:8081/nexus/content/groups/public
-->
-
+
@@ -575,7 +581,7 @@
org.apache.commons
commons-lang3
- 3.1
+ ${commons-lang3.version}
commons-io
@@ -608,7 +614,7 @@
com.google.guava
guava
- 11.0.2
+ ${guava.version}
@@ -680,39 +686,26 @@
junit
junit
- 4.10
- test
-
-
-
- org.hamcrest
- hamcrest-core
- 1.3.RC2
- test
-
-
- org.hamcrest
- hamcrest-library
- 1.3.RC2
+ ${junit.version}
test
org.mockito
mockito-core
- 1.9.0
+ ${mockito.version}
test
org.powermock
powermock-module-junit4
- 1.4.12
+ ${powermock.version}
test
org.powermock
powermock-api-mockito
- 1.4.12
+ ${powermock.version}
test
@@ -806,7 +799,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 2.3.2
+ 2.4
${jdk.version}
${jdk.version}
@@ -950,9 +943,9 @@
- org.codehaus.mojo
+ org.codehaus.sonar
sonar-maven-plugin
- 2.0
+ 3.0
diff --git a/modules/test/pom.xml b/modules/test/pom.xml
index 743f617e..9d4e18df 100644
--- a/modules/test/pom.xml
+++ b/modules/test/pom.xml
@@ -142,11 +142,6 @@
junit
-
- org.hamcrest
- hamcrest-library
-
-
org.powermock
powermock-module-junit4