Permalink
Browse files

update

  • Loading branch information...
1 parent 03d3fae commit c2a23c97c5e856f3c054cced3cb12e53c132cb67 @arden committed Dec 29, 2011
Showing with 81 additions and 17 deletions.
  1. +4 −8 Play-loader.iml
  2. +2 −2 README
  3. +1 −1 build.properties
  4. +2 −1 build.xml
  5. BIN commands.pyc
  6. BIN lib/play-loader.jar
  7. +72 −5 src/play/modules/loader/LoaderPlugin.java
View
@@ -1,19 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="Python" name="Python">
- <configuration sdkName="" />
- </facet>
- </component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
- <content url="file://$MODULE_DIR$">
+ <content url="file://$MODULE_DIR$/../..">
+ <sourceFolder url="file://$MODULE_DIR$/../../app" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
- <excludeFolder url="file://$MODULE_DIR$/.idea" />
+ <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Play-1.2" level="project" />
+ <orderEntry type="library" name="wengao" level="project" />
</component>
</module>
View
4 README
@@ -9,12 +9,12 @@
4)cd modules
5)git clone https://arden@github.com/arden/play-loader.git
6)修改conf/application.conf
- 增加:source.paths=src/main/java
+ 增加:javasource.path=src
7)启动项目 play run
二:修改视图模版路径
1)cd <your project>
2)cd app
3)mv views templates (假设把模版路径改为templates)
-4)修改conf/application.conf,增加template.paths=app/templates
+4)修改conf/application.conf,增加template.path=app/templates
5)启动项目,play run
View
@@ -1 +1 @@
-play.path=D:\play-1.2.1
+play.path=D:/java/play-1.2.4
View
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="play-loader" default="build" basedir=".">
- <property file="build.properties" />
+ <!--<property file="build.properties" />-->
+ <property name="play.path" value="D:/play-1.2.4"></property>
<target name="check" unless="play.path">
<fail message="Please specify Play framework path using -Dplay.path=/path/to/framework/home" />
</target>
View
Binary file not shown.
View
Binary file not shown.
@@ -5,27 +5,94 @@
import play.PlayPlugin;
import play.vfs.VirtualFile;
+import java.io.File;
+import java.lang.System;
+
/**
* 让Play加载自定义的java类文件
*
* @author arden
*/
public class LoaderPlugin extends PlayPlugin {
+ /**
+ * 加载项目依赖
+ */
public void onLoad() {
- String pattern = (String) Play.configuration.get("source.paths");
+ this.loadSources();
+ this.loadModules();
+ this.loadTemplates();
+ }
+
+ /**
+ * 加载项目模块
+ */
+ private void loadModules() {
VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
+ String pattern = (String) Play.configuration.get("app.modules");
if (pattern != null) {
- String[] paths = pattern.split(",");
+ File parentFile = appRoot.getRealFile().getParentFile();
+ String[] paths = pattern.split(",");
+ if (paths != null) {
+ for (int i = 0; i < paths.length; i++) {
+ try {
+ int index = paths[i].lastIndexOf("/");
+ String name = paths[i].substring(index + 1);
+ Play.addModule(name, new File(parentFile.getPath() + paths[i]));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 加载源代码
+ */
+ private void loadSources() {
+ VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
+ String pattern = (String) Play.configuration.get("source.paths");
+ String absolutePattern = (String) Play.configuration.get("source.absolute.paths");
+ String relativePattern = (String) Play.configuration.get("source.relative.paths");
+
+ //加载基于项目相对路径的源代码
+ if (relativePattern != null) {
+ File parentFile = appRoot.getRealFile().getParentFile();
+ String[] paths = relativePattern.split(",");
+ if (paths != null) {
+ for (int i = 0; i < paths.length; i++) {
+ Play.javaPath.add(VirtualFile.open(parentFile.getPath() + paths[i]));
+ }
+ }
+ }
+
+ //加载绝对路径的源代码
+ if (absolutePattern != null) {
+ String[] paths = absolutePattern.split(",");
+ if (paths != null) {
+ for (int i = 0; i < paths.length; i++) {
+ Play.javaPath.add(VirtualFile.open(new File(paths[i])));
+ }
+ }
+ }
+
+ //加载相对路径的源代码
+ if (pattern != null) {
+ String[] paths = pattern.split(",");
if (paths != null) {
for (int i = 0; i < paths.length; i++) {
Play.javaPath.add(appRoot.child(paths[i]));
}
}
- } else {
- Logger.info("Missing configuration 'source.paths', loader will be ignored!");
}
+ }
- pattern = (String) Play.configuration.get("template.paths");
+ /**
+ * 加载模版路径
+ */
+ public void loadTemplates() {
+ VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
+ String pattern = (String) Play.configuration.get("template.paths");
if (pattern != null) {
Play.templatesPath.add(appRoot.child(pattern));
}

0 comments on commit c2a23c9

Please sign in to comment.