The gradle copy task is not honouring the caseSensitive property

Hello,

I’m having a problem with the Copy task-type in gradle, namely that it doesn’t copy all the files I want. I’m copying a tree full of *.ddl files, but some are called *.DDL, and those don’t get copied, even though I set caseSensitive = false in the copy task.

I created the following test build to show the problem:

task makefiles << {
  mkdir 'fromtest'
  file('fromtest/lower.foo').write('Test file lower case foo')
  file('fromtest/upper.FOO').write('Test file upper case FOO')
  file('fromtest/lower.foobar').write('Test file lower case bar')
}
  task copyfoo (type: Copy, dependsOn: makefiles) {
  into 'totest'
  from 'fromtest'
  include '*.foo'
  caseSensitive = false
}
  task show(dependsOn: copyfoo) << {
  fileTree('totest').each { println it.name }
}

The code above only copies lower.foo, whereas I would expect it to also copy upper.FOO What am I doing wrong ?

Hi, I have the same issue. Has anybody an idea? Is this a known bug?

I have created a workaround for this bug (I assume this is a bug!). Sorry if this looks a bit cluttered - I am a beginner in groovy :wink:

/**

  • Workaround for broken caseSensitive property of the copy task.

  • Checks whether the file starts with given extension prefix and if

  • the given path segment is part of the files path.

  • Both checks are case insensitive.

  • @param fileTreeElement The FileTreeElement instance to check.

  • @param extPrefix The prefix of the file extension.

  • @param pathSegment Optional part of the file path.

Backward slashes are converted to forward slashes!

  • @return boolean

*/ def checkExtension(fileTreeElement, extPrefix, pathSegment=’’) {

def path = fileTreeElement.getPath().toLowerCase().replace("\", “/”)

def lext = path.split(’[.]’)

def ll = lext.length

def ext = ‘’

if (ll > 1) {

ext = lext[ll - 1]

}

path.contains(pathSegment) && ext.startsWith(extPrefix) }

use this in the copy task as follows:

task copyExcel(type: Copy, dependsOn: copyXmlGen) {

from srcDir

into defaultDir + ‘/common/gtnexus’

includeEmptyDirs false

include({checkExtension(it, ‘xl’, ‘com/foo/bar’)}) }

Reproduced with Gradle 2.2 and raised GRADLE-3198. Thanks for the report.