Spaces and drive letters in file not working on Mac


(Jason Zwolak) #1

Bare with me. I know Macs don’t have drive letters, but the path “c:/Program Files” is valid on a Mac.

The following Gradle code fails:

// This code fails.
x = file("c:/Program Files")
println x.getAbsolutePath();

With this error:

FAILURE: Build failed with an exception. > >* Where: >Build file ‘/Users/jzwolak/files/experimenting/gradle/spaces/build.gradle’ line: 2 > >* What went wrong: >A problem occurred evaluating root project ‘spaces’. >> java.net.URISyntaxException: Illegal character in path at index 10: c:/Program Files > >* Try: >Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. > >BUILD FAILED

For this Gradle version:

------------------------------------------------------------ Gradle 1.8 ------------------------------------------------------------

Build time:

2013-09-24 07:32:33 UTC Build number: none Revision:

7970ec3503b4f5767ee1c1c69f8b4186c4763e3d

Groovy:

1.8.6 Ant:

Apache Ant™ version 1.9.2 compiled on July 8 2013 Ivy:

2.2.0 JVM:

1.7.0_10 (Oracle Corporation 23.6-b04) OS:

Mac OS X 10.8.5 x86_64


(Peter Niederwieser) #2

Why do you think the path “c:/Program Files” is valid on a Mac?


(Jason Zwolak) #3

I can do this:

jzwolak@laptop:~/temp$ mkdir -p “c:/Program Files”

jzwolak@laptop:~/temp$ cd “c:/Program Files”

jzwolak@laptop:~/temp/c:/Program Files$


(Peter Niederwieser) #4

But that’s not the same thing. I recommend to only use that path on Windows.


(Jason Zwolak) #5

I defer to your judgement on whether this should be changed in Gradle, but it did get my attention and break my workflow when I was building a cross platform build system and coded a path for Windows and tested the system on my Mac.

Here’s another Gradle file that illustrates the point from a slightly different angle.

// This works
myPath = new File("k:/one two")
myPath.mkdirs()
  // This fails
myPath = file("m:/three four")
myPath.mkdirs()

(Peter Niederwieser) #6

The first probably “works” because it’s interpreted as a relative path, and isn’t canonicalized. But I doubt the result is very useful.