Skip to content

Commit

Permalink
Merge branch 'master' of github.com:playframework/play
Browse files Browse the repository at this point in the history
  • Loading branch information
pepite committed Oct 17, 2010
2 parents db48942 + 12565ae commit 525d790
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 39 deletions.
Binary file added framework/lib/xstream-1.3.jar
Binary file not shown.
12 changes: 8 additions & 4 deletions framework/pym/play/commands/check.py
Expand Up @@ -72,7 +72,9 @@ def url(self):
def __eq__(self, other):
return self.strversion == other.strversion
def __lt__(self, other):
for i in range(self.versions):
if self == other:
return False
for i in range(len(self.versions)):
if self.versions[i] < other.versions[i]:
return True # ex: 1.1 vs 1.2
if self.versions[i] > other.versions[i]:
Expand All @@ -82,11 +84,13 @@ def __lt__(self, other):
if len(self.versions) > len(other.versions):
return False
# From here, numeric part is the same - now having a rest means older version
if len(other.numpart) > 0:
if len(other.numpart) > 0 and len(self.numpart) == 0:
return False
if len(self.numpart) > 0:
if len(self.numpart) > 0 and len(other.numpart) == 0:
return True
return False # self == other (thus strict comparison is false)
# Both have a rest, use a string comparison
# alpha1 < beta1 < rc1 < rc2...
return self.rest < other.rest
def __le__(self, other):
return self == other or self < other
def __gt__(self, other):
Expand Down
55 changes: 35 additions & 20 deletions framework/pym/play/commands/eclipse.py
Expand Up @@ -15,16 +15,22 @@ def execute(**kargs):
args = kargs.get("args")
play_env = kargs.get("env")

is_application = os.path.exists(os.path.join(app.path, 'conf', 'application.conf'))
app.check()
app.check_jpda()
if is_application:
app.check_jpda()
modules = app.modules()
classpath = app.getClasspath()

# determine the name of the project
# if this is an application, the name of the project is in the application.conf file
# if this is a module, we infer the name from the path
application_name = app.readConf('application.name')
if application_name:
application_name = application_name.replace("/", " ")
else:
application_name = os.path.dirname(app.path)
application_name = os.path.basename(app.path)

dotProject = os.path.join(app.path, '.project')
dotClasspath = os.path.join(app.path, '.classpath')
dotSettings = os.path.join(app.path, '.settings')
Expand All @@ -41,7 +47,8 @@ def execute(**kargs):

shutil.copyfile(os.path.join(play_env["basedir"], 'resources/eclipse/.project'), dotProject)
shutil.copyfile(os.path.join(play_env["basedir"], 'resources/eclipse/.classpath'), dotClasspath)
shutil.copytree(os.path.join(play_env["basedir"], 'resources/eclipse'), eclipse)
if is_application:
shutil.copytree(os.path.join(play_env["basedir"], 'resources/eclipse'), eclipse)
shutil.copytree(os.path.join(play_env["basedir"], 'resources/eclipse/.settings'), dotSettings)
replaceAll(dotProject, r'%PROJECT_NAME%', application_name)

Expand All @@ -65,9 +72,16 @@ def execute(**kargs):
cpXML += '<classpathentry kind="lib" path="%s" sourcepath="%s"/>\n\t' % (os.path.normpath(el), cpJarToSource[el])
else:
cpXML += '<classpathentry kind="lib" path="%s"/>\n\t' % os.path.normpath(el)

if not is_application:
cpXML += '<classpathentry kind="src" path="src"/>'
replaceAll(dotClasspath, r'%PROJECTCLASSPATH%', cpXML)

# generate source path for test folder if one exists
cpTEST = ""
if os.path.exists(os.path.join(app.path, 'test')):
cpTEST += '<classpathentry kind="src" path="test"/>'
replaceAll(dotClasspath, r'%TESTCLASSPATH%', cpTEST)

if len(modules):
lXML = ""
cXML = ""
Expand All @@ -84,22 +98,23 @@ def execute(**kargs):
replaceAll(dotProject, r'%LINKS%', '')
replaceAll(dotClasspath, r'%MODULES%', '')

replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%JPDA_PORT%', str(app.jpda_port))

replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%JPDA_PORT%', str(app.jpda_port))

replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%JPDA_PORT%', str(app.jpda_port))

os.rename(os.path.join(app.path, 'eclipse/connect.launch'), os.path.join(app.path, 'eclipse/Connect JPDA to %s.launch' % application_name))
os.rename(os.path.join(app.path, 'eclipse/test.launch'), os.path.join(app.path, 'eclipse/Test %s.launch' % application_name))
os.rename(os.path.join(app.path, 'eclipse/debug.launch'), os.path.join(app.path, 'eclipse/%s.launch' % application_name))
if is_application:
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/debug.launch'), r'%JPDA_PORT%', str(app.jpda_port))

replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_BASE%', play_env["basedir"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%PLAY_ID%', play_env["id"])
replaceAll(os.path.join(app.path, 'eclipse/test.launch'), r'%JPDA_PORT%', str(app.jpda_port))

replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%PROJECT_NAME%', application_name)
replaceAll(os.path.join(app.path, 'eclipse/connect.launch'), r'%JPDA_PORT%', str(app.jpda_port))

os.rename(os.path.join(app.path, 'eclipse/connect.launch'), os.path.join(app.path, 'eclipse/Connect JPDA to %s.launch' % application_name))
os.rename(os.path.join(app.path, 'eclipse/test.launch'), os.path.join(app.path, 'eclipse/Test %s.launch' % application_name))
os.rename(os.path.join(app.path, 'eclipse/debug.launch'), os.path.join(app.path, 'eclipse/%s.launch' % application_name))

# Module-specific modifications
for module in modules:
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/CorePlugin.java
Expand Up @@ -279,7 +279,7 @@ static ThreadGroup getRootThread() {

@Override
public void enhance(ApplicationClass applicationClass) throws Exception {
Class[] enhancers = new Class[]{
Class<?>[] enhancers = new Class[]{
SigEnhancer.class,
ControllersEnhancer.class,
MailerEnhancer.class,
Expand Down
1 change: 1 addition & 0 deletions framework/src/play/data/binding/Binder.java
Expand Up @@ -349,6 +349,7 @@ public static Object directBind(String value, Class<?> clazz) throws Exception {
return directBind(null, null, value, clazz);
}

@SuppressWarnings("unchecked")
public static Object directBind(String name, Annotation[] annotations, String value, Class<?> clazz) throws Exception {
Logger.trace("directBind: value [" + value + "] annotation [" + Utils.join(annotations, " ") + "] Class [" + clazz + "]");

Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/db/Model.java
Expand Up @@ -36,7 +36,7 @@ public static interface Choices {
public static interface Factory {

public String keyName();
public Class keyType();
public Class<?> keyType();
public Object keyValue(Model m);
public Model findById(Object id);
public List<Model> fetch(int offset, int length, String orderBy, String orderDirection, List<String> properties, String keywords, String where);
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/db/jpa/Blob.java
Expand Up @@ -59,7 +59,7 @@ public boolean exists() {
return UUID != null && getFile().exists();
}

File getFile() {
public File getFile() {
if(file == null) {
file = new File(getStore(), UUID);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/db/jpa/JPAPlugin.java
Expand Up @@ -479,7 +479,7 @@ public String keyName() {
return keyField().getName();
}

public Class keyType() {
public Class<?> keyType() {
return keyField().getType();
}

Expand Down
3 changes: 2 additions & 1 deletion framework/src/play/db/jpa/JPQL.java
Expand Up @@ -157,12 +157,13 @@ public String createCountQuery(String entityName, String entityClass, String que
return "select count(e) from " + entityName + " e where " + query;
}

@SuppressWarnings("unchecked")
public Query bindParameters(Query q, Object... params) {
if (params == null) {
return q;
}
if (params.length == 1 && params[0] instanceof Map) {
return bindParameters(q, (Map<String,Object>) params[0]);
return bindParameters(q, (Map<String, Object>) params[0]);
}
for (int i = 0; i < params.length; i++) {
q.setParameter(i + 1, params[i]);
Expand Down
29 changes: 29 additions & 0 deletions framework/src/play/libs/IO.java
Expand Up @@ -12,6 +12,7 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -98,6 +99,34 @@ public static String readContentAsString(File file, String encoding) {
}
}

@SuppressWarnings("unchecked")
public static List<String> readLines(InputStream is) {
List<String> lines = null;
try {
lines = IOUtils.readLines(is);
} catch (IOException ex) {
throw new UnexpectedException(ex);
}
return lines;
}

@SuppressWarnings("unchecked")
public static List<String> readLines(File file, String encoding) {
List<String> lines = null;
try {
InputStream is = new FileInputStream(file);
lines = IOUtils.readLines(is, encoding);
is.close();
} catch (IOException ex) {
throw new UnexpectedException(ex);
}
return lines;
}

public static List<String> readLines(File file) {
return readLines(file, "utf-8");
}

/**
* Read binary content of a file (warning does not use on large file !)
* @param file The file te read
Expand Down
39 changes: 36 additions & 3 deletions framework/src/play/mvc/Controller.java
@@ -1,6 +1,5 @@
package play.mvc;

import com.google.gson.JsonSerializer;
import java.io.File;
import java.io.InputStream;
import java.lang.annotation.Annotation;
Expand All @@ -11,7 +10,9 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

import org.w3c.dom.Document;

import play.Invoker.Suspend;
import play.Logger;
import play.Play;
Expand All @@ -25,7 +26,6 @@
import play.exceptions.PlayException;
import play.exceptions.TemplateNotFoundException;
import play.exceptions.UnexpectedException;
import play.utils.Java;
import play.libs.Time;
import play.mvc.Http.Request;
import play.mvc.Router.ActionDefinition;
Expand All @@ -39,17 +39,21 @@
import play.mvc.results.RedirectToStatic;
import play.mvc.results.RenderBinary;
import play.mvc.results.RenderHtml;
import play.mvc.results.RenderJson;
import play.mvc.results.RenderTemplate;
import play.mvc.results.RenderText;
import play.mvc.results.RenderJson;
import play.mvc.results.RenderXml;
import play.mvc.results.Result;
import play.mvc.results.Unauthorized;
import play.templates.Template;
import play.templates.TemplateLoader;
import play.utils.Default;
import play.utils.Java;
import play.vfs.VirtualFile;

import com.google.gson.JsonSerializer;
import com.thoughtworks.xstream.XStream;

/**
* Application controller support: The controller receives input and initiates a response by making calls on model objects.
*
Expand Down Expand Up @@ -180,6 +184,24 @@ protected static void renderXml(Document xml) {
throw new RenderXml(xml);
}

/**
* Return a 200 OK text/xml response. Use renderXml(Object, XStream) to customize the result.
* @param o the object to serialize
*/
protected static void renderXml(Object o) {
throw new RenderXml(o);
}

/**
* Return a 200 OK text/xml response
* @param o the object to serialize
* @param xstream the XStream object to use for serialization. See XStream's documentation
* for details about customizing the output.
*/
protected static void renderXml(Object o, XStream xstream) {
throw new RenderXml(o, xstream);
}

/**
* Return a 200 OK application/binary response
* @param is The stream to copy
Expand Down Expand Up @@ -352,6 +374,17 @@ protected static void notFoundIfNull(Object o) {
}
}

/**
* Send a 404 Not Found response if object is null
* @param o The object to check
* @param what The Not Found resource name
*/
protected static void notFoundIfNull(Object o, String what) {
if (o == null) {
notFound(what);
}
}

/**
* Send a 404 Not Found reponse
*/
Expand Down
17 changes: 14 additions & 3 deletions framework/src/play/mvc/results/RenderXml.java
@@ -1,26 +1,37 @@
package play.mvc.results;

import org.w3c.dom.Document;

import play.exceptions.UnexpectedException;
import play.libs.XML;
import play.mvc.Http.Request;
import play.mvc.Http.Response;

import com.thoughtworks.xstream.XStream;

/**
* 200 OK with a text/xml
*/
public class RenderXml extends Result {

String xml;

public RenderXml(CharSequence xml) {
this.xml = xml.toString();
}

public RenderXml(Document document) {
this.xml = XML.serialize(document);
}

public RenderXml(Object o, XStream xstream) {
this.xml = xstream.toXML(o);
}

public RenderXml(Object o) {
this(o, new XStream());
}

public void apply(Request request, Response response) {
try {
setContentTypeIfNotSet(response, "text/xml");
Expand Down
2 changes: 0 additions & 2 deletions framework/src/play/server/PlayHandler.java
Expand Up @@ -33,12 +33,10 @@

import java.io.*;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.*;
import javax.mail.internet.InternetAddress;

import play.data.validation.Validation;

Expand Down
1 change: 1 addition & 0 deletions framework/src/play/test/Fixtures.java
Expand Up @@ -247,6 +247,7 @@ static void serialize(Map<?, ?> values, String prefix, Map<String, String[]> ser
}
}

@SuppressWarnings("unchecked")
static void resolveDependencies(Class<Model> type, Map<String, String[]> serialized, Map<String, Object> idCache) {
Set<Field> fields = new HashSet<Field>();
Class<?> clazz = type;
Expand Down
2 changes: 1 addition & 1 deletion play.bat
@@ -1,2 +1,2 @@
@echo off
"%~dp0python\python.exe" "%~dp0play" %1 %2 %3 %4 %5 %6 %7 %8 %9
"%~dp0python\python.exe" "%~dp0play" %*
2 changes: 1 addition & 1 deletion resources/eclipse/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="views/**" kind="src" path="app"/>
<classpathentry kind="src" path="test"/>
%TESTCLASSPATH%
%MODULES%
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
%PROJECTCLASSPATH%
Expand Down
9 changes: 9 additions & 0 deletions samples-and-tests/just-test-cases/test/catch.test.html
@@ -0,0 +1,9 @@
#{selenium 'Test the @Catch'}

open('@{UsingBefore.fight("bob")}')
assertTextPresent('Oops, got java.lang.ArithmeticException')

open('@{UsingBefore.fight()}')
assertTextPresent('Hey!, got java.lang.NullPointerException')

#{/selenium}

0 comments on commit 525d790

Please sign in to comment.