1

After migrating to Play-2.1 I stuck into problem that routes compiler stopped working for my routes file. It's been completely fine with Play-2.0.4, but now I'm getting the build error and can't find any workaround for it.

In my project I'm using cake pattern, so controller actions are visible not through <package>.<controller class>.<action>, but through <package>.<component registry>.<controller instance>.<action>. New Play routes compiler is using all action path components except for the last two to form package name that will be used in managed sources (as far as I can get code in https://github.com/playframework/Play20/blob/2.1.0/framework/src/routes-compiler/src/main/scala/play/router/RoutesCompiler.scala). In my case it leads to situation when <package>.<component registry> is chosen as package name, which results in error during build:

[error] server/target/scala-2.10/src_managed/main/com/grumpycats/mmmtg/componentsRegistry/routes.java:5: componentsRegistry is already defined as object componentsRegistry
[error] package com.grumpycats.mmmtg.componentsRegistry;

I made the sample project to demonstrate this problem: https://github.com/rmihael/play-2.1-routes-problem

Is it possible to workaround this problem somehow without dropping cake pattern for controllers? It's the pity that I can't proceed with Play 2.1 due to this problem.

Michael Korbakov
  • 2,147
  • 1
  • 18
  • 20

2 Answers2

2

Because of reputation I can not create a comment.

The convention is that classes and objects start with upper case. This convention is applied to pattern matching as well. Looking at a string there seems to be no difference between a package object and normal object (appart from the case). I am not sure how Play 2.1 handles things, that's why this is not an answer but a comment.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • Thank you for suggestion! Unfortunately it doesn't help with current Play routes compiler code, because it has hardcoded "everything except last two" behavior. However I can make a patch for this compiler that will handle such situation. That will be nice little pull request :) – Michael Korbakov Feb 08 '13 at 09:44
0

You could try the new @ syntax in the router. That allows you to create an instance from the Global class. You would still specify <package>.<controller class>.<action>, but in the Global you get it from somewhere else (for example a component registry).

You can find a bit of extra information here under the 'Managed Controller classes instantiation': http://www.playframework.com/documentation/2.1.0/Highlights

This demo project shows it's usage: https://github.com/guillaumebort/play20-spring-demo

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
  • I managed to get it work through managed instantiation, however it not as good as it was with Play 2.0. Runtime instantiation makes system more fragile and requires additional testing. Code is pretty ugly as well, take a look there: http://stackoverflow.com/questions/14506891/play-2-1-getcontrollerinstance-usage/14793435#14793435 – Michael Korbakov Feb 10 '13 at 01:27