Skip to content
Browse files

ルートパッケージの配置場所がファイルシステム上ではない場合(jarの中など)にアクションパッケージのFileオブジェクトの取得に失敗しNu…

…llPointerExceptionが発生する問題を修正。
  • Loading branch information...
1 parent 03f78b6 commit 4d70b258b87daf1e6daafdbe4751d125b5b9ac2c @growthfield growthfield committed Aug 24, 2012
Showing with 33 additions and 19 deletions.
  1. +33 −19 src/main/java/net/unit8/sastruts/routing/detector/ClassControllerDetector.java
View
52 src/main/java/net/unit8/sastruts/routing/detector/ClassControllerDetector.java
@@ -1,43 +1,57 @@
package net.unit8.sastruts.routing.detector;
-import java.io.File;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import net.unit8.sastruts.ControllerUtil;
import net.unit8.sastruts.routing.ControllerDetector;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
import org.seasar.framework.convention.NamingConvention;
-import org.seasar.framework.util.ResourceUtil;
+import org.seasar.framework.util.ClassTraversal.ClassHandler;
+import org.seasar.framework.util.ResourcesUtil;
+import org.seasar.framework.util.ResourcesUtil.Resources;
import org.seasar.framework.util.StringUtil;
+/**
+ * HotDeploy/WarmDeploy時用のControllerDetectorです。
+ *
+ * @author kawasima
+ * @author growthfield
+ *
+ */
public class ClassControllerDetector implements ControllerDetector {
- private static final String[] EXTENSIONS = {"class"};
+ /**
+ * @see ControllerDetector#detect()
+ */
public List<String> detect() {
- List<String> controllers = new ArrayList<String>();
-
+ final List<String> controllers = new ArrayList<String>();
S2Container container = SingletonS2ContainerFactory.getContainer();
NamingConvention namingConvention = (NamingConvention)container.getComponent(NamingConvention.class);
-
- String actionSuffix = namingConvention.getActionSuffix();
- String actionSubPackageName = namingConvention.fromSuffixToPackageName(actionSuffix);
+ final String actionSuffix = namingConvention.getActionSuffix();
+ final String actionSubPackageName = namingConvention.fromSuffixToPackageName(actionSuffix);
for (String rootPackageName : namingConvention.getRootPackageNames()) {
- String actionClasspath = StringUtil.replace(rootPackageName, ".", "/").concat("/").concat(actionSubPackageName);
- File dir = ResourceUtil.getResourceAsFile(actionClasspath);
- Iterator<File> actionIter = FileUtils.iterateFiles(dir, EXTENSIONS, true);
- while(actionIter.hasNext()) {
- String relativePath = StringUtils.substring(actionIter.next().getPath(), dir.getPath().length() + 1).replace(File.separatorChar, '/');
- String path = ControllerUtil.fromClassNameToPath(StringUtil.trimSuffix(relativePath, actionSuffix + ".class"));
- controllers.add(path);
+ final String actionPackageName = rootPackageName.concat(".").concat(actionSubPackageName);
+ ClassHandler handler = new ClassHandler() {
+ public void processClass(String packageName, String shortClassName) {
+ String pkgPath = StringUtils.removeStart(packageName, actionPackageName);
+ String uncapitalizedShortClassName = ControllerUtil.fromClassNameToPath(shortClassName);
+ String actionPath = StringUtil.trimSuffix(uncapitalizedShortClassName, actionSuffix);
+ StringBuilder sb = new StringBuilder();
+ if (!StringUtils.isEmpty(pkgPath)) {
+ sb.append(pkgPath.substring(1)).append("/");
+ }
+ sb.append(actionPath);
+ controllers.add(sb.toString());
+ }
+ };
+ Resources[] types = ResourcesUtil.getResourcesTypes(actionPackageName);
+ for (Resources r : types) {
+ r.forEach(handler);
}
}
-
return controllers;
}
-
}

0 comments on commit 4d70b25

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