giter8 icon indicating copy to clipboard operation
giter8 copied to clipboard

g8Test failed when using Formatting template fields for filename

Open melito00 opened this issue 7 years ago • 4 comments

Envilonment

  • Windows 7
  • sbt version: 1.1.0

Repoducing procedures is as follows:

  • sbt new foundweekends/giter8.g8
  • use all default value
  • cd my-template-project
  • sbt g8Test (Works fine)
  • change src/main/scala/stub.scala to src/main/scala/$name$.scala
  • Then, execute again "sbt 8Test", but it failed with following messaages.
> sbt g8Test
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems, Inc"
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from C:\work\prog\tmp\my-template-project\project
[info] Loading settings from build.sbt ...
[info] Set current project to My Template Project (in build file:/C:/work/prog/tmp/my-template-project/)
[error] org.stringtemplate.v4.compiler.STException: relative: src\main\scala\$name$.scala, toPath: C:\work\prog\tmp\my-template-project\target\sbt-test\My Template Project\scripted, 1:20: doesn't look like an expression
[error]         at giter8.G8$.expandPath(g8.scala:201)
[error]         at giter8.G8$.$anonfun$apply$2(g8.scala:98)
[error]         at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:241)
[error]         at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59)
[error]         at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52)
[error]         at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
[error]         at scala.collection.TraversableLike.flatMap(TraversableLike.scala:241)
[error]         at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:238)
[error]         at scala.collection.AbstractTraversable.flatMap(Traversable.scala:104)
[error]         at giter8.G8$.apply(g8.scala:96)
[error]         at giter8.Giter8Plugin$.$anonfun$giter8TestSettings$6(Giter8Plugin.scala:105)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[error]         at java.util.concurrent.FutureTask.run(Unknown Source)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error]         at java.lang.Thread.run(Unknown Source)
[error] (Test / g8) org.stringtemplate.v4.compiler.STException: relative: src\main\scala\$name$.scala, toPath: C:\work\prog\tmp\my-template-project\target\sbt-test\My Template Project\scripted, 1:20: doesn't look like an expression
[error] Total time: 1 s, completed 31-Jan-2018 17:53:42

However, it works fine to use this template as follows

sbt new file://./my-template-project/

melito00 avatar Feb 01 '18 16:02 melito00

Same issue with version "0.13.0-M1" and sbt version: 1.3.8.

org.stringtemplate.v4.compiler.STException: relative: **\$classname$.scala, toPath: **\sbt-test\**\scripted, An unexpected
error occurred while processing the template. Check that all literal '$' are properly escaped with '\$'

tonykoval avatar May 28 '20 08:05 tonykoval

It's not happening to me, the second time I prompt sbt g8Test the tests are not failing @melito00 @tonykoval can you confirm if is still happening? Env:

MacOsX 10.15.7
sbt 1.5.2 
java AdoptOpenJDK Java 1.8.0_292

TonioGela avatar May 29 '21 10:05 TonioGela

I still have same issue with following environment.

name [My Template Project]:
giter8_version [0.13.1]:
sbt_version [1.5.5]:
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)

melito00 avatar Oct 04 '21 21:10 melito00

Hi,

I think I've hit this same issue, and after way too much tinkering I could not find for sure what the issue is, but I have a few ideas.

In my case the full error log is

sbt:scala.g8> g8Test
[error] stack trace is suppressed; run last Test / g8 for the full output
[error] (Test / g8) org.stringtemplate.v4.compiler.STException: relative: src\main\scala\$package$\core\Stub.scala, toPath: C:\Users\Chewie\Code\Projects\scala.g8\target\sbt-test\scala.g8\scripted, An unexpected error occurred while processing the template. Check that all literal '$' are properly escaped with '\$'
[error] Total time: 0 s, completed 6 Oct 2021, 00:43:48
sbt:scala.g8> last Test / g8
[error] org.stringtemplate.v4.compiler.STException: relative: src\main\scala\$package$\core\Stub.scala, toPath: C:\Users\Chewie\Code\Projects\scala.g8\target\sbt-test\scala.g8\scripted, An unexpected error occurred while processing the template. Check that all literal '$' are properly escaped with '\$'
[error]         at giter8.G8$.expandPath(g8.scala:229)
[error]         at giter8.G8$.$anonfun$apply$2(g8.scala:99)
[error]         at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
[error]         at scala.collection.Iterator.foreach(Iterator.scala:943)
[error]         at scala.collection.Iterator.foreach$(Iterator.scala:943)
[error]         at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
[error]         at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error]         at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error]         at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error]         at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
[error]         at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
[error]         at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
[error]         at giter8.G8$.apply(g8.scala:97)
[error]         at giter8.Giter8Plugin$.$anonfun$giter8TestSettings$6(Giter8Plugin.scala:121)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]         at java.base/java.lang.Thread.run(Thread.java:829)
[error] (Test / g8) org.stringtemplate.v4.compiler.STException: relative: src\main\scala\$package$\core\Stub.scala, toPath: C:\Users\Chewie\Code\Projects\scala.g8\target\sbt-test\scala.g8\scripted, An unexpected error occurred while processing the template. Check that all literal '$' are properly escaped with '\$'

First, it seems the issue is specific to Windows as, like the OP, I'm on Windows.

Second, it seems the issue occurs when running g8Test, but now when using the template via sbt new. At least that's what I'm seeing here.

I stumbled upon #334 which mentions that g8Test does not go through the same code path as running sbt new, one calling G8.apply and the other calling G8.applyT

Indeed it would seem that G8.expandPath is called with somewhat different arguments depending on the caller being apply or applyT (via G8.writeTemplates). In the second case, the argument goes through G8.relativize, which by calling .toURI, will replace \ with / in the relative path (this is where Windows is relevant).

Now I would have expected the call to expandPath from applyT (which goes through relativize) to be the one to fail, given that expandPath was apparently recently fixed to handle Windows file separators, but it seems to be the opposite and at this point I'm utterly confused. Nevertheless, maybe this info can help someone better equipped than me to look at this in more detail?

Thanks in advance

chwthewke avatar Oct 05 '21 22:10 chwthewke