Closed soid closed 10 years ago
I would like to have this working as well.!!!
I wrote this test, which throws the UnsupportedOperationException.
@Test
void filter_expression() {
Project project = ProjectBuilder.builder().build()
project.version = '1.0.0'
File appleFile = new File(project.buildDir, 'src/apple')
Files.createParentDirs(appleFile)
appleFile.text = 'apple'
project.apply plugin: 'rpm'
def rpmTask = project.task([type: Rpm], 'buildRpm', {
from(appleFile.getParentFile()) {
into '/usr/local/myproduct/bin'
filter({ line ->
return line //line.replaceAll('{{BASE}}', '/usr/local/myproduct')
})
}
})
rpmTask.execute()
}
I'll see that MappingCopySpecVisitor explicitly does not allow filter (https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/internal/file/copy/MappingCopySpecVisitor.java#L83). Now the question is how and why MappingCopySpecVisitor got involved.
Ah, when calling builder.addFile, we're passing in a java.io.File object. But Gradle is telling us that there is no file, since it does the filtering on the fly. We can open the "file" and get an InputStream but there is no concrete File object to point to. We'll have to write the contents of the filter to a tmp directory, since redline doesn't take InputStreams. What is annoying is that it's primarily used by CpioHeader to determine the modification time and the length. I think writing to a temp file is a the best solution, if filterChain.hasFilters(). It possible we can extend File URL, and then re-implement openConnection. We extend File, because FileInputStream requires a real file on the Filesystem.
Sounds like you have a good start on a fix and a pull request. =)
:-) I do, but I've got to finish my debian support first, since we need it internally here first. My codebase is also different enough right now that just fixing this one bug on master would be a little hard for me. But I can get back to this later.
I have a fix for #30, but it's at the end of a long pull request that I'm putting together. I just have the docs left to write.
I tried to use filter() expression do to some replacement in files that are going to rpm, but it didn't work. The code looked like that:
It threw an exception (caught using --stacktrace option):
It would be nice to support this standard in copy task function.