Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hardcoded references to conf directory #1

Open
benmccann opened this issue Dec 2, 2014 · 4 comments
Open

Fix hardcoded references to conf directory #1

benmccann opened this issue Dec 2, 2014 · 4 comments

Comments

@benmccann
Copy link
Contributor

EbeanDynamicEvolutions has hardcoded references to the conf directory:

File evolutions = environment.getFile("conf/evolutions/" + key + "/1.sql");
Files.createDirectory(environment.getFile("conf/evolutions/" + key));
@felipebonezi
Copy link
Contributor

@benmccann @schmitch hey guys, I want to fix this problem but I'm not understanding how to get application conf folder and how to write some tests. Can you help me understand?

I was thinking to use Environment.rootPath() to get application root folder and then concat with /conf.
Do you think that is a good approach?

image

@benmccann
Copy link
Contributor Author

I haven't used Play in years. I'm afraid my memory from 2014 is rather fuzzy

@mkurz
Copy link
Member

mkurz commented May 13, 2021

@felipebonezi Look at this code from Play:

val evolution = {
  // First try a file on the filesystem
  val filename = Evolutions.fileName(db, paddedRevision)
  environment.getExistingFile(filename).map(_.toURI)
}.orElse {
  // If file was not found, try a resource on the classpath
  val resourceName = Evolutions.resourceName(db, paddedRevision)
  environment.resource(resourceName).map(url => url.toURI)
}

Evolutions.fileName(db, revision) also tries to access the evolutions file in the hardcoded conf folder.

  /**
   * Default evolutions directory location.
   */
  def directoryName(db: String): String = s"conf/evolutions/${db}"

  /**
   * Default evolution file location.
   */
  def fileName(db: String, revision: Int): String = s"${directoryName(db)}/${revision}.sql"

  def fileName(db: String, revision: String): String = s"${directoryName(db)}/${revision}.sql"

however if that files does not exist if falls back to Evolutions.resourceName(db, revision) which does not include the hardcoded conf/ prefix (also here the resource gets loaded via environment.resource(...) which loads the resource from the classpath).

I think that is the only way to solve this problem here. There is no helper method which gives you the conf folder. That's because in Play you can disable the PlayLayoutPlugin and then there is no conf folder anymore, but instead the maven style folder structure is used and src/main/resources is used instead.

@mkurz
Copy link
Member

mkurz commented May 13, 2021

Also, because (depending if PlayLayoutPlugin is enable dor not) the conf folder or src/main/resources gets added to the classpath, so that fallback should be able to read the file, no matter where it is located.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants