Skip to content
New issue

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

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

Already on GitHub? # to your account

Folder Template does not work properly on Windows #598

Open
sebastianh001 opened this issue Aug 26, 2021 · 4 comments
Open

Folder Template does not work properly on Windows #598

sebastianh001 opened this issue Aug 26, 2021 · 4 comments

Comments

@sebastianh001
Copy link

steps

I setup my template as follows to support both java and scala templates. This can be decided by using the scala respectively java parameter (true/false)

src/main/$if(java.truthy)$java$endif$/$package$/Class.scala
src/main/$if(scala.truthy)$scala$endif$/$package$/Class.java

problem

If i run this template on Windows using sbt new file://{templatepath} (SBT 1.5.5)

if java = true and scala = false it will produce the following dirs:
src/main/java/{package}/Class.java
src/main/{package}/Class.scala
and if scala = true and java = false to:
src/main/scala/{package}/Class.scala
src/main/{package}/Class.java

Which is not as expected

expectation

this should be evaluated if java = true and scala = false to:
src/main/java/{package}/Class.java
and if scala = true and java = false to:
src/main/scala/{package}/Class.scala

This works properly on an Unix System (SBT 1.5.5) but does not work correctly on an Windows machine (SBT 1.5.5) (using the same template)

notes

@TonioGela
Copy link
Member

The template is indeed working as expected, since you are placing in the if just the java or scala token.
To get the behaviour you described you should place the whole remaining part of the path in the if condition like

src/main/$if(java.truthy)$java/$package$/Class.scala$endif$

//or

src/main/$if(scala.truthy)$scala/$package$/Class.scala$endif$

otherwise just the single path token will be elided (i.e. src/main/<I am empty so I will be elided>/{package}/Class.scala).

The only "side effect" in this solution is that in the java = false && scala = false case you won't get any .class produce (but after all that's what you required saying no java, no scala).

Does it answer to your question @sebastianh001?

@sebastianh001
Copy link
Author

sebastianh001 commented Aug 30, 2021

@TonioGela: Tryed the proposed Solution using Sbt 1.5.5 but get the following error using the windows environment.

The Soulution which i described worked well on unix but not on windows

java.io.IOException: Directory '\src\main\scala\{package}' could not be created
        at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:361)
        at org.apache.commons.io.FileUtils.writeStringToFile(FileUtils.java:2015)
        at org.apache.commons.io.FileUtils.writeStringToFile(FileUtils.java:1983)
        at giter8.G8$.write(g8.scala:195)
        at giter8.G8$.write(g8.scala:180)
        at giter8.G8$.$anonfun$writeTemplates$3(g8.scala:513)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at scala.util.control.Exception$Catch.$anonfun$opt$1(Exception.scala:246)
        at scala.util.control.Exception$Catch.apply(Exception.scala:228)
        at scala.util.control.Exception$Catch.opt(Exception.scala:246)
        at giter8.G8$.$anonfun$writeTemplates$2(g8.scala:513)
        at scala.collection.immutable.Stream.foreach(Stream.scala:533)
        at giter8.G8$.writeTemplates(g8.scala:499)
        at giter8.G8$.$anonfun$applyT$1(g8.scala:355)
        at scala.util.Either$RightProjection.flatMap(Either.scala:701)
        at giter8.G8$.applyT(g8.scala:338)
        at giter8.G8$.fromDirectory(g8.scala:77)
        at giter8.G8TemplateRenderer$.render(TemplateRenderer.scala:40)
        at giter8.AppProcessor.process(giter8.scala:58)
        at giter8.Runner.$anonfun$run$9(Runner.scala:51)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.$anonfun$run$5(Runner.scala:48)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.$anonfun$run$4(Runner.scala:47)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.run(Runner.scala:46)
        at giter8.Giter8.run(giter8.scala:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at giter8.LauncherProcessor.call(LauncherMain.scala:114)
        at giter8.LauncherProcessor.virtuallyRun(LauncherMain.scala:88)
        at giter8.LauncherProcessor.process(LauncherMain.scala:38)
        at giter8.Runner.$anonfun$run$9(Runner.scala:51)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.$anonfun$run$5(Runner.scala:48)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.$anonfun$run$4(Runner.scala:47)
        at scala.util.Either.flatMap(Either.scala:341)
        at giter8.Runner.run(Runner.scala:46)
        at giter8.Runner.run(Runner.scala:72)
        at sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:34)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sbt.TemplateCommandUtil$.call(TemplateCommandUtil.scala:113)
        at sbt.TemplateCommandUtil$.runTemplate(TemplateCommandUtil.scala:88)
        at sbt.TemplateCommandUtil$.$anonfun$run$1(TemplateCommandUtil.scala:64)
        at sbt.TemplateCommandUtil$.$anonfun$run$1$adapted(TemplateCommandUtil.scala:60)
        at scala.collection.LinearSeqOptimized.find(LinearSeqOptimized.scala:115)
        at scala.collection.LinearSeqOptimized.find$(LinearSeqOptimized.scala:112)
        at scala.collection.immutable.List.find(List.scala:91)
        at sbt.TemplateCommandUtil$.run(TemplateCommandUtil.scala:60)
        at sbt.TemplateCommandUtil$.runTemplate(TemplateCommandUtil.scala:47)
        at sbt.TemplateCommandUtil$.$anonfun$templateCommand$2(TemplateCommandUtil.scala:28)
        at sbt.Command$.$anonfun$applyEffect$4(Command.scala:150)
        at sbt.Command$.$anonfun$applyEffect$2(Command.scala:145)
        at sbt.Command$.process(Command.scala:189)
        at sbt.MainLoop$.$anonfun$processCommand$5(MainLoop.scala:245)
        at scala.Option.getOrElse(Option.scala:189)
        at sbt.MainLoop$.process$1(MainLoop.scala:245)
        at sbt.MainLoop$.processCommand(MainLoop.scala:276)
        at sbt.MainLoop$.$anonfun$next$5(MainLoop.scala:163)
        at sbt.State$StateOpsImpl$.runCmd$1(State.scala:289)
        at sbt.State$StateOpsImpl$.process$extension(State.scala:325)
        at sbt.MainLoop$.$anonfun$next$4(MainLoop.scala:163)
        at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
        at sbt.MainLoop$.next(MainLoop.scala:163)
        at sbt.MainLoop$.run(MainLoop.scala:144)
        at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:119)
        at sbt.io.Using.apply(Using.scala:27)
        at sbt.MainLoop$.runWithNewLog(MainLoop.scala:112)
        at sbt.MainLoop$.runAndClearLast(MainLoop.scala:66)
        at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:51)
        at sbt.MainLoop$.runLogged(MainLoop.scala:42)
        at sbt.StandardMain$.runManaged(Main.scala:218)
        at sbt.xMain$.$anonfun$run$9(Main.scala:113)
        at sbt.io.IO$.withTemporaryDirectory(IO.scala:490)
        at sbt.io.IO$.withTemporaryDirectory(IO.scala:500)
        at sbt.xMain$.run(Main.scala:101)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sbt.internal.XMainConfiguration.run(XMainConfiguration.java:56)
        at sbt.xMain.run(Main.scala:46)
        at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:111)
        at xsbt.boot.Launch$.withContextLoader(Launch.scala:130)
        at xsbt.boot.Launch$.run(Launch.scala:111)
        at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:37)
        at xsbt.boot.Launch$.launch(Launch.scala:119)
        at xsbt.boot.Launch$.apply(Launch.scala:20)
        at xsbt.boot.Boot$.runImpl(Boot.scala:56)
        at xsbt.boot.Boot$.main(Boot.scala:18)
        at xsbt.boot.Boot.main(Boot.scala)

@TonioGela
Copy link
Member

TonioGela commented Sep 2, 2021

Consider that you're literally trying to create a folder named "{package}" with curly braces and all.
Probably you meant to write "$package$", no @sebastianh001?

@sebastianh001
Copy link
Author

no the folder name is defined by the giter8 template variable package.

it should generate a folder structure like this:
com/myorg/myproject/...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

2 participants