[GRADLE-1611] Getting a path with backslashes where a path with slashes is expected in a ziptask with ziptree input Created: 14/Jun/11  Updated: 04/Jan/13  Resolved: 22/Jun/11

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-3
Fix Version/s: None

Type: Bug
Reporter: Ric Klaren Assignee: Unassigned
Resolution: Not A Bug Votes: 0


 Description   

We have a distribution task, that combines a number of zip files into one together with the artifacts generated by our build. During the unpack of the original zip files we relocate a few directories. We now run into the issue that on unix everything works but on windows we are not seeing a 'denormalized' paths as we would expect (e.g. we see a path with back slashes in stead of slashes).

The expectation from a path with slashes on windows stems from: http://gradle.org/current/docs/javadoc/org/gradle/api/file/FileTreeElement.html#getPath%28%29.

task dist(type: Zip, dependsOn: cleanDist) {
    description = "Build distribution ZIP"

    subprojects {
        dependsOn(it.jar)
    }

    def virgoFileTree = zipTree(configurations.server.getSingleFile())

    def virgoDocPath = 'docs/virgo-' + virgo_version
    virgoFileTree.matching({include "**/docs/**/*"}).each {
        newPath = it.path.substring(it.path.indexOf('/docs/') + 5, it.path.lastIndexOf('/'))
        from(it) { into (virgoDocPath + newPath) }
    }

    // more of the same.....
}

The 'include' in the matching part works, but the indexOf's fail, on windows, due to it.path using slashes on unix and backslashes on windows.



 Comments   
Comment by Adam Murdoch [ 21/Jun/11 ]

FileTree.each {} iterates over the files in the file tree as java.io.File objects. So, in your example above, it.path will contain native file name separators. Given that on windows this is a backslash, by calling into(virgoDocPath + newPath), you're asking Gradle to add the entry with backslashes in its name.

You might instead use CopySpec.eachFile, which allows you to work with the normalised path:

from(virgoFileTree) {
    include "**/docs/**/*"
    eachFile { FileCopyDetails file ->
       newPath = // do something with file.path
       file.path = // do something with newPath    
    }
}

See http://gradle.org/current/docs/javadoc/org/gradle/api/file/CopySpec.html#eachFile(groovy.lang.Closure)
and http://gradle.org/current/docs/javadoc/org/gradle/api/file/FileCopyDetails.html

Comment by Ric Klaren [ 27/Jun/11 ]

Thank you for the clarification, will update our build accordingly.

Cheers,

Ric

Generated at Wed Jun 30 11:59:57 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.