Merge lp:~nicolas-lunatech/play/contribution into lp:~play-developers/play/stable3-hacks

Proposed by Nicolas Leroux
Status: Merged
Merged at revision: not available
Proposed branch: lp:~nicolas-lunatech/play/contribution
Merge into: lp:~play-developers/play/stable3-hacks
Diff against target: 158 lines
3 files modified
framework/src/play/Play.java (+6/-3)
framework/src/play/mvc/Router.java (+18/-24)
framework/src/play/server/ServletWrapper.java (+4/-1)
To merge this branch: bzr merge lp:~nicolas-lunatech/play/contribution
Reviewer Review Type Date Requested Status
Guillaume Bort Approve
Review via email: mp+12534@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guillaume Bort (guillaume-bort) :
review: Approve
592. By guillaume <email address hidden>

play new,run

593. By guillaume <email address hidden>

Merge nicolas fix about servlet container

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'framework/src/play/Play.java'
2--- framework/src/play/Play.java 2009-09-06 18:05:44 +0000
3+++ framework/src/play/Play.java 2009-09-28 17:00:31 +0000
4@@ -135,6 +135,8 @@
5 // pv
6 static boolean firstStart = true;
7
8+ private final static String NO_PREFIX = "";
9+
10 /**
11 * Init the framework
12 * @param root The application path
13@@ -165,11 +167,12 @@
14 }
15 System.setProperty("play.path", Play.frameworkPath.getAbsolutePath());
16 System.setProperty("application.path", Play.applicationPath.getAbsolutePath());
17- Logger.info("");
18+
19 Logger.info("Starting %s", root.getAbsolutePath());
20
21 // Read the configuration file
22 readConfiguration();
23+
24 if (configuration.getProperty("play.tmp", "tmp").equals("none")) {
25 tmpDir = null;
26 Logger.debug("No tmp folder will be used (play.tmp is set to none)");
27@@ -348,7 +351,7 @@
28 Play.classloader.getAllClasses();
29
30 // Routes
31- Router.detectChanges();
32+ Router.detectChanges(NO_PREFIX);
33
34 // Plugins
35 for (PlayPlugin plugin : plugins) {
36@@ -429,7 +432,7 @@
37 }
38 try {
39 classloader.detectChanges();
40- Router.detectChanges();
41+ Router.detectChanges(NO_PREFIX);
42 if (conf.lastModified() > startedAt) {
43 start();
44 return;
45
46=== modified file 'framework/src/play/mvc/Router.java'
47--- framework/src/play/mvc/Router.java 2009-05-27 06:35:18 +0000
48+++ framework/src/play/mvc/Router.java 2009-09-28 17:00:31 +0000
49@@ -31,9 +31,9 @@
50 static Pattern methodOverride = new Pattern("^.*x-http-method-override=({method}GET|PUT|POST|DELETE).*$");
51 public static long lastLoading = -1;
52
53- public static void load() {
54+ public static void load(String prefix) {
55 routes.clear();
56- parse(Play.routes, "");
57+ parse(Play.routes, prefix);
58 lastLoading = System.currentTimeMillis();
59 // Plugins
60 for (PlayPlugin plugin : Play.plugins) {
61@@ -41,18 +41,20 @@
62 }
63 }
64
65- public static void addRoute(String method, String path, String action) {
66+ public static void addRoute(String method, String path, String action) {
67+ addRoute(method, path, action, null);
68+ }
69+
70+
71+ public static void addRoute(String method, String path, String action, String params) {
72 Route route = new Route();
73 route.method = method;
74 route.path = path;
75 route.path = route.path.replace("//", "/");
76 route.action = action;
77+ route.addParams(params);
78 route.compute();
79- if(routes.size() == 0) {
80- routes.add(route);
81- }else {
82- routes.add(0, route);
83- }
84+ routes.add(0, route);
85 }
86
87 /**
88@@ -90,35 +92,27 @@
89 Logger.error("Cannot include routes for module %s (not found)", moduleName);
90 }
91 } else {
92- Route route = new Route();
93- route.method = matcher.group("method");
94- if(matcher.group("path").equals("/") && !prefix.equals("")) {
95- route.path = prefix;
96- } else {
97- route.path = prefix + matcher.group("path");
98- }
99- route.path = route.path.replace("//", "/");
100- route.action = action;
101- route.addParams(matcher.group("params"));
102- route.compute();
103- routes.add(route);
104- }
105+ String method = matcher.group("method");
106+ String path = prefix + matcher.group("path");
107+ String params = matcher.group("params");
108+ addRoute(method, path, action, params);
109+ }
110 } else {
111 Logger.error("Invalid route definition : %s", line);
112 }
113 }
114 }
115
116- public static void detectChanges() {
117+ public static void detectChanges(String prefix) {
118 if (Play.mode == Mode.PROD && lastLoading > 0) {
119 return;
120 }
121 if (Play.routes.lastModified() > lastLoading) {
122- load();
123+ load(prefix);
124 } else {
125 for (VirtualFile file : Play.modulesRoutes.values()) {
126 if (file.lastModified() > lastLoading) {
127- load();
128+ load(prefix);
129 return;
130 }
131 }
132
133=== modified file 'framework/src/play/server/ServletWrapper.java'
134--- framework/src/play/server/ServletWrapper.java 2009-08-20 09:17:47 +0000
135+++ framework/src/play/server/ServletWrapper.java 2009-09-28 17:00:31 +0000
136@@ -50,6 +50,8 @@
137 String appDir = e.getServletContext().getRealPath("/WEB-INF/application");
138 File root = new File(appDir);
139 Play.init(root, System.getProperty("play.id", ""));
140+ // Reload the rules, but this time with the context. Not really efficient through...
141+ Router.load(e.getServletContext().getContextPath());
142 }
143
144 public void contextDestroyed(ServletContextEvent e) {
145@@ -98,11 +100,12 @@
146 }
147
148 public void serveStatic(HttpServletResponse servletResponse, HttpServletRequest servletRequest, RenderStatic renderStatic) throws IOException {
149+
150 VirtualFile file = Play.getVirtualFile(renderStatic.file);
151- servletResponse.setContentType(MimeTypes.getContentType(file.getName()));
152 if (file == null || file.isDirectory() || !file.exists()) {
153 //serve404(session, minaResponse, minaRequest, new NotFound("The file " + renderStatic.file + " does not exist"));
154 } else {
155+ servletResponse.setContentType(MimeTypes.getContentType(file.getName()));
156 boolean raw = false;
157 for (PlayPlugin plugin : Play.plugins) {
158 if (plugin.serveStatic(file, Request.current(), Response.current())) {

Subscribers

People subscribed via source and target branches