Skip to content

Commit

Permalink
Merge pull request #23 from merscwog/optionalParents
Browse files Browse the repository at this point in the history
Optionally add parent directories
  • Loading branch information
AlanKrueger committed Dec 13, 2012
2 parents eabe1b0 + 1918bf2 commit e1c1367
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {

dependencies {
compile gradleApi()
compile 'org.redline-rpm:redline:1.1.+'
compile 'org.redline-rpm:redline:1.1.10+'

groovy 'org.codehaus.groovy:groovy:1.8.+'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ class RpmCopySpecVisitor extends EmptyCopySpecVisitor {
void visitFile(FileVisitDetails fileDetails) {
logger.debug "adding file {}", fileDetails.relativePath.pathString
builder.addFile "/" + fileDetails.relativePath.pathString, fileDetails.file,
spec.fileMode == null ? -1 : spec.fileMode, spec.fileType, spec.user ?: task.user, spec.group ?: task.group
spec.fileMode == null ? -1 : spec.fileMode, -1, spec.fileType, spec.user ?: task.user, spec.group ?: task.group,
spec.addParentDirs
}

@Override
void visitDir(FileVisitDetails dirDetails) {
if (spec.createDirectoryEntry) {
logger.debug "adding directory {}", dirDetails.relativePath.pathString
builder.addDirectory "/" + dirDetails.relativePath.pathString, spec.dirMode == null ? -1 : spec.dirMode,
spec.fileType, spec.user ?: task.user, spec.group ?: task.group
spec.fileType, spec.user ?: task.user, spec.group ?: task.group, spec.addParentDirs
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RpmPlugin implements Plugin<Project> {
CopySpecImpl.metaClass.group = null
CopySpecImpl.metaClass.fileType = null
CopySpecImpl.metaClass.createDirectoryEntry = null
CopySpecImpl.metaClass.addParentDirs = true

Field.metaClass.hasModifier = { modifier ->
(modifiers & modifier) == modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class RpmPluginTest {
srcDir.mkdirs()
FileUtils.writeStringToFile(new File(srcDir, 'apple'), 'apple')

File noParentsDir = new File(buildDir, 'noParentsDir')
noParentsDir.mkdirs()
FileUtils.writeStringToFile(new File(noParentsDir, 'alone'), 'alone')

project.apply plugin: 'rpm'

project.task([type: Rpm], 'buildRpm', {
Expand Down Expand Up @@ -70,6 +74,11 @@ class RpmPluginTest {
fileType = CONFIG
}

from(noParentsDir) {
addParentDirs = false
into '/a/path/not/to/create'
}

link('/opt/bleah/banana', '/opt/bleah/apple')
})

Expand All @@ -80,8 +89,9 @@ class RpmPluginTest {
assertEquals('1', getHeaderEntryString(scan, RELEASE))
assertEquals('i386', getHeaderEntryString(scan, ARCH))
assertEquals('linux', getHeaderEntryString(scan, OS))
assertEquals(['./opt/bleah', './opt/bleah/apple', './opt/bleah/banana'], scan.files*.name)
assertEquals([DIR, FILE, SYMLINK], scan.files*.type)
assertEquals(['./a/path/not/to/create/alone', './opt/bleah',
'./opt/bleah/apple', './opt/bleah/banana'], scan.files*.name)
assertEquals([FILE, DIR, FILE, SYMLINK], scan.files*.type)
}

@Test
Expand Down

0 comments on commit e1c1367

Please sign in to comment.