Skip to content

Commit

Permalink
Support experimental option to compile to Scala 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Sep 19, 2012
1 parent 149241b commit 4883db2
Show file tree
Hide file tree
Showing 100 changed files with 1,795 additions and 1,430 deletions.
250 changes: 166 additions & 84 deletions framework/project/Build.scala

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions framework/src/console/src/main/scala/Console.scala
Expand Up @@ -20,13 +20,13 @@ object Console {
|| __/|_|\____|\__ (_) || __/|_|\____|\__ (_)
||_| |__/ ||_| |__/
| |
|""".stripMargin) + ("play! " + play.core.PlayVersion.current + ", http://www.playframework.org") |""".stripMargin) + ("play! " + play.core.PlayVersion.current + " (using Scala " + play.core.PlayVersion.scalaVersion + "), http://www.playframework.org")


// -- Commands // -- Commands


def replace(file: File, tokens: (String, String)*) { def replace(file: File, tokens: (String, String)*) {
if (file.exists) { if (file.exists) {
Path(file).write(tokens.foldLeft(Path(file).slurpString) { (state, token) => Path(file).write(tokens.foldLeft(Path(file).string) { (state, token) =>
state.replace("%" + token._1 + "%", token._2) state.replace("%" + token._1 + "%", token._2)
}) })
} }
Expand Down
@@ -0,0 +1,159 @@
package play.api;

import java.io.*;
import java.util.*;

import java.util.concurrent.atomic.AtomicLong;

/**
* Helper for `PlayException`.
*/
public class PlayException extends UsefulException {

private final AtomicLong generator = new AtomicLong(System.currentTimeMillis());

/**
* Generates a new unique exception ID.
*/
private String nextId() {
return java.lang.Long.toString(generator.incrementAndGet(), 26);
}

public PlayException(String title, String description, Throwable cause) {
super(title + "[" + description + "]",cause);
this.title = title;
this.description = description;
this.id = nextId();
this.cause = cause;
}

public PlayException(String title, String description) {
super(title + "[" + description + "]");
this.title = title;
this.description = description;
this.id = nextId();
this.cause = null;
}

/**
* Adds source attachment to a Play exception.
*/
public static abstract class ExceptionSource extends PlayException {

public ExceptionSource(String title, String description, Throwable cause) {
super(title, description,cause);
}

public ExceptionSource(String title, String description) {
super(title, description);
}

/**
* Error line number, if defined.
*/
public abstract Integer line();

/**
* Column position, if defined.
*/
public abstract Integer position();

/**
* Input stream used to read the source content.
*/
public abstract String input();

/**
* The source file name if defined.
*/
public abstract String sourceName();

/**
* Extracts interesting lines to be displayed to the user.
*
* @param border number of lines to use as a border
*/
public InterestingLines interestingLines(int border) {
try {
if(input() == null || line() == null) {
return null;
}
String[] lines = input().split("\n");
int firstLine = Math.max(0, line() - border);
int lastLine = Math.min(lines.length - 1, line() + border);
List<String> focusOn = new ArrayList<String>();
for(int i = firstLine; i <= lastLine; i++) {
focusOn.add(lines[i]);
}
return new InterestingLines(firstLine + 1, focusOn.toArray(new String[focusOn.size()]), line() - firstLine - 1);
} catch(Throwable e) {
e.printStackTrace();
return null;
}
}

public String toString() {
return super.toString() + " in " + sourceName() + ":" + line();
}
}

/**
* Adds any attachment to a Play exception.
*/
public static abstract class ExceptionAttachment extends PlayException {

public ExceptionAttachment(String title, String description, Throwable cause) {
super(title, description, cause);
}

public ExceptionAttachment(String title, String description) {
super(title, description);
}

/**
* Content title.
*/
public abstract String subTitle();

/**
* Content to be displayed.
*/
public abstract String content();

}

/**
* Adds a rich HTML description to a Play exception.
*/
public static abstract class RichDescription extends ExceptionAttachment {

public RichDescription(String title, String description, Throwable cause) {
super(title, description, cause);
}

public RichDescription(String title, String description) {
super(title, description);
}

/**
* The new description formatted as HTML.
*/
public abstract String htmlDescription();

}

public static class InterestingLines {

public final int firstLine;
public final int errorLine;
public final String[] focus;

public InterestingLines(int firstLine, String[] focus, int errorLine){
this.firstLine = firstLine;
this.errorLine = errorLine;
this.focus = focus;
}

}

}
@@ -0,0 +1,40 @@
package play.api;

/**
* A UsefulException is something useful to display in the User browser.
*/
public abstract class UsefulException extends RuntimeException {

/**
* Exception title.
*/
public String title;

/**
* Exception description.
*/
public String description;

/**
* Exception cause if defined.
*/
public Throwable cause;

/**
* Unique id for this exception.
*/
public String id;

public UsefulException(String message, Throwable cause) {
super(message, cause);
}

public UsefulException(String message) {
super(message);
}

public String toString() {
return "@" + id + ": " + title;
}

}
40 changes: 21 additions & 19 deletions framework/src/play/src/main/scala/play/api/Application.scala
Expand Up @@ -52,10 +52,11 @@ trait WithDefaultGlobal {
javaGlobal.map(new j.JavaGlobalSettingsAdapter(_)).getOrElse(scalaGlobal) javaGlobal.map(new j.JavaGlobalSettingsAdapter(_)).getOrElse(scalaGlobal)
} catch { } catch {
case e: PlayException => throw e case e: PlayException => throw e
case e => throw PlayException( case e => throw new PlayException(
"Cannot init the Global object", "Cannot init the Global object",
e.getMessage, e.getMessage,
Some(e)) e
)
} }
} }


Expand All @@ -76,6 +77,7 @@ trait WithDefaultConfiguration {
} }


def configuration: Configuration = fullConfiguration def configuration: Configuration = fullConfiguration

} }


trait WithDefaultPlugins { trait WithDefaultPlugins {
Expand All @@ -92,7 +94,7 @@ trait WithDefaultPlugins {
val pluginFiles = self.classloader.getResources("play.plugins").asScala.toList ++ self.classloader.getResources("conf/play.plugins").asScala.toList val pluginFiles = self.classloader.getResources("play.plugins").asScala.toList ++ self.classloader.getResources("conf/play.plugins").asScala.toList


pluginFiles.distinct.map { plugins => pluginFiles.distinct.map { plugins =>
(plugins.asInput.slurpString.split("\n").map(_.trim)).filterNot(_.isEmpty).map { (plugins.asInput.string.split("\n").map(_.trim)).filterNot(_.isEmpty).map {
case PluginDeclaration(priority, className) => (priority.toInt, className) case PluginDeclaration(priority, className) => (priority.toInt, className)
} }
}.flatten.sortBy(_._1).map(_._2) }.flatten.sortBy(_._1).map(_._2)
Expand Down Expand Up @@ -133,21 +135,21 @@ trait WithDefaultPlugins {
if (plugin.enabled) Some(plugin) else { Logger("play").warn("Plugin [" + className + "] is disabled"); None } if (plugin.enabled) Some(plugin) else { Logger("play").warn("Plugin [" + className + "] is disabled"); None }
} catch { } catch {
case e: PlayException => throw e case e: PlayException => throw e
case e => throw PlayException( case e => throw new PlayException(
"Cannot load plugin", "Cannot load plugin",
"Plugin [" + className + "] cannot been instantiated.", "Plugin [" + className + "] cannot been instantiated.",
Some(e)) e)
} }
} }
case e: InvocationTargetException => throw PlayException( case e: InvocationTargetException => throw new PlayException(
"Cannot load plugin", "Cannot load plugin",
"An exception occurred during Plugin [" + className + "] initialization", "An exception occurred during Plugin [" + className + "] initialization",
Some(e.getTargetException)) e.getTargetException)
case e: PlayException => throw e case e: PlayException => throw e
case e => throw PlayException( case e => throw new PlayException(
"Cannot load plugin", "Cannot load plugin",
"Plugin [" + className + "] cannot been instantiated.", "Plugin [" + className + "] cannot been instantiated.",
Some(e)) e)
} }
}.flatten }.flatten


Expand Down Expand Up @@ -262,19 +264,19 @@ trait Application {
*/ */
private[play] def handleError(request: RequestHeader, e: Throwable): Result = try { private[play] def handleError(request: RequestHeader, e: Throwable): Result = try {
e match { e match {
case e: PlayException.UsefulException => throw e case e: UsefulException => throw e
case e: Throwable => { case e: Throwable => {


val source = sources.flatMap(_.sourceFor(e)) val source = sources.flatMap(_.sourceFor(e))


throw new PlayException( throw new PlayException.ExceptionSource(
"Execution exception", "Execution exception",
"[%s: %s]".format(e.getClass.getSimpleName, e.getMessage), "[%s: %s]".format(e.getClass.getSimpleName, e.getMessage),
Some(e)) with PlayException.ExceptionSource { e) {
def line = source.map(_._2) def line = source.flatMap(_._2).map(_.asInstanceOf[java.lang.Integer]).orNull
def position = None def position = null
def input = source.map(_._1).map(scalax.file.Path(_)) def input = source.map(_._1).map(scalax.file.Path(_).string).orNull
def sourceName = source.map(_._1.getAbsolutePath) def sourceName = source.map(_._1.getAbsolutePath).orNull
} }
} }
} }
Expand All @@ -288,8 +290,8 @@ trait Application {
case p: PlayException => "@" + p.id + " - " case p: PlayException => "@" + p.id + " - "
case _ => "" case _ => ""
}, request.method, request.uri), }, request.method, request.uri),
e) e

)
global.onError(request, e) global.onError(request, e)
} catch { } catch {
case e => DefaultGlobal.onError(request, e) case e => DefaultGlobal.onError(request, e)
Expand Down Expand Up @@ -413,4 +415,4 @@ class DefaultApplication(
override val classloader: ClassLoader, override val classloader: ClassLoader,
override val sources: Option[SourceMapper], override val sources: Option[SourceMapper],
override val mode: Mode.Mode override val mode: Mode.Mode
) extends Application with WithDefaultConfiguration with WithDefaultGlobal with WithDefaultPlugins ) extends Application with WithDefaultConfiguration with WithDefaultGlobal with WithDefaultPlugins
10 changes: 5 additions & 5 deletions framework/src/play/src/main/scala/play/api/Configuration.scala
Expand Up @@ -68,11 +68,11 @@ object Configuration {


private def configError(origin: ConfigOrigin, message: String, e: Option[Throwable] = None): PlayException = { private def configError(origin: ConfigOrigin, message: String, e: Option[Throwable] = None): PlayException = {
import scalax.io.JavaConverters._ import scalax.io.JavaConverters._
new PlayException("Configuration error", message, e) with PlayException.ExceptionSource { new PlayException.ExceptionSource("Configuration error", message, e.orNull) {
def line = Option(origin.lineNumber) def line = Option(origin.lineNumber:java.lang.Integer).orNull
def position = None def position = null
def input = Option(origin.url).map(_.asInput) def input = Option(origin.url).map(_.asInput.string).orNull
def sourceName = Option(origin.filename) def sourceName = Option(origin.filename).orNull
override def toString = "Configuration error: " + getMessage override def toString = "Configuration error: " + getMessage
} }
} }
Expand Down

4 comments on commit 4883db2

@leon
Copy link
Contributor

@leon leon commented on 4883db2 Sep 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i try compiling with ./build -Dexperimental=true publish-local i'm getting 26 errors?

some of them are
object Future is not a member of package akka.dispatch
object Await is not a member of package akka.dispatch
object duration is not a member of package akka.util
object config is not a member of package akka

What should I do to get it working?

@guillaumebort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't compile with Scala 2.10 yet. This work is the preliminary project structure refactoring needed to move the runtime API to Scala 2.10 while keeping the sbt related stuff to Scala 2.9.2 (to be able to release with the current stable sbt 0.12)

@sadache
Copy link
Contributor

@sadache sadache commented on 4883db2 Sep 20, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leon
Copy link
Contributor

@leon leon commented on 4883db2 Sep 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait :)

Please sign in to comment.