Skip to content

Commit

Permalink
Merge pull request #53 from fff/master
Browse files Browse the repository at this point in the history
enable relocatable rpm
  • Loading branch information
AlanKrueger committed Nov 3, 2013
2 parents 3c77a2b + f5ebe38 commit e123391
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ modifyPom {
artifactId 'oss-parent'
version '7'
}

scm {
url 'scm:git://github.com/TrigonicSolutions/gradle-rpm-plugin.git'
connection 'scm:git://github.com/TrigonicSolutions/gradle-rpm-plugin.git'
}

licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}

developers {
developer {
id 'akrueger'
Expand Down
9 changes: 5 additions & 4 deletions src/main/groovy/com/trigonic/gradle/plugins/rpm/Rpm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Rpm extends AbstractArchiveTask {
String url = ''
String sourcePackage
String provides
String prefixes
File installUtils
File preInstall
File postInstall
Expand Down Expand Up @@ -123,11 +124,11 @@ class Rpm extends AbstractArchiveTask {
String getArchiveName() {
String.format("%s-%s-%s.%s.%s", packageName, version, release, arch.name().toLowerCase(), extension)
}

Link link(String path, String target) {
link(path, target, -1)
}

Link link(String path, String target, int permissions) {
Link link = new Link()
link.path = path
Expand All @@ -136,7 +137,7 @@ class Rpm extends AbstractArchiveTask {
links.add(link)
link
}

Dependency requires(String packageName, String version, int flag) {
Dependency dep = new Dependency()
dep.packageName = packageName
Expand All @@ -145,7 +146,7 @@ class Rpm extends AbstractArchiveTask {
dependencies.add(dep)
dep
}

Dependency requires(String packageName) {
requires(packageName, '', 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ class RpmCopySpecVisitor extends EmptyCopySpecVisitor {
builder.setVendor task.vendor
builder.setUrl task.url
builder.setProvides task.provides ?: task.packageName
builder.setPrefixes task.prefixes

String sourcePackage = task.sourcePackage
if (!sourcePackage) {
// need a source package because createrepo will assume your package is a source package without it
sourcePackage = builder.defaultSourcePackage
}
builder.addHeaderEntry HeaderTag.SOURCERPM, sourcePackage

builder.setPreInstallScript(scriptWithUtils(task.installUtils, task.preInstall))
builder.setPostInstallScript(scriptWithUtils(task.installUtils, task.postInstall))
builder.setPreUninstallScript(scriptWithUtils(task.installUtils, task.preUninstall))
Expand Down Expand Up @@ -98,12 +99,12 @@ class RpmCopySpecVisitor extends EmptyCopySpecVisitor {
logger.debug "adding link {} -> {}", link.path, link.target
builder.addLink link.path, link.target, link.permissions
}

for (Dependency dep : task.dependencies) {
logger.debug "adding dependency on {} {}", dep.packageName, dep.version
builder.addDependency dep.packageName, dep.version, dep.flag
}

String rpmFile = builder.build(destinationDir)
didWork = true
logger.info 'Created rpm {}', rpmFile
Expand All @@ -113,20 +114,20 @@ class RpmCopySpecVisitor extends EmptyCopySpecVisitor {
boolean getDidWork() {
didWork
}

String standardScriptDefines() {
includeStandardDefines ?
includeStandardDefines ?
String.format(" RPM_ARCH=%s \n RPM_OS=%s \n RPM_PACKAGE_NAME=%s \n RPM_PACKAGE_VERSION=%s \n RPM_PACKAGE_RELEASE=%s \n\n",
task?.arch?.toString().toLowerCase(), task?.os?.toString()?.toLowerCase(), task?.packageName, task?.version, task?.release) : null
task?.arch?.toString().toLowerCase(), task?.os?.toString()?.toLowerCase(), task?.packageName, task?.version, task?.release) : null
}

Object scriptWithUtils(File utils, File script) {
concat(standardScriptDefines(), utils, script)
}

String concat(Object... scripts) {
String shebang
StringBuilder result = new StringBuilder();
StringBuilder result = new StringBuilder();
scripts.each { script ->
script?.eachLine { line ->
if (line.matches('^#!.*$')) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/groovy/com/trigonic/gradle/plugins/rpm/Scanner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.freecompany.redline.payload.CpioHeader
import org.junit.Assert

/**
* Based on {@link org.freecompany.redline.Scanner}, but modified to return scanned nformation for
* Based on {@link org.freecompany.redline.Scanner}, but modified to return scanned information for
* programmatic verification.
*/
class Scanner {
Expand All @@ -32,15 +32,15 @@ class Scanner {
fileInputStream.close()
}
}

static Map scan(InputStream inputStream) {
ReadableChannelWrapper wrapper = new ReadableChannelWrapper(Channels.newChannel(inputStream))
Format format = scanHeader(wrapper)

InputStream uncompressed = new GZIPInputStream(inputStream)
wrapper = new ReadableChannelWrapper(Channels.newChannel(uncompressed))
CpioHeader header = null

def files = []
int total = 0
while (header == null || !header.isLast()) {
Expand All @@ -53,7 +53,7 @@ class Scanner {
assertEquals(skip, uncompressed.skip(skip))
total += header.getFileSize()
}

return [format: format, files: files]
}

Expand Down
27 changes: 27 additions & 0 deletions test-rpm/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
group = 'com.trigonic'
version = '1.5-SNAPSHOT'

apply plugin: 'rpm'


buildscript {
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
classpath 'com.trigonic:gradle-rpm-plugin:1.5-SNAPSHOT'
}
}


task rpm(type: Rpm) {
prefixes = '/tmp/original'
os = LINUX
release = 1.0
from('src') {
into '/tmp/original'
}
}

1 change: 1 addition & 0 deletions test-rpm/src/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test me

0 comments on commit e123391

Please sign in to comment.