diff --git a/build.gradle b/build.gradle
index 7891d5d..8271c6e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,95 +1,33 @@
-import java.time.ZonedDateTime
-import java.time.format.DateTimeFormatter
-
plugins {
- id "org.sonarqube" version "2.6.2"
- id "io.codearte.nexus-staging" version "0.11.0"
+ id "de.marcphilipp.nexus-publish" version "0.4.0"
+ id "io.codearte.nexus-staging" version "0.21.1"
}
-printf "Date: %s\nHost: %s\nOS: %s %s %s\nJava: %s %s %s %s\nGradle: %s Groovy: %s Java: %s\n" +
- "Build: group: ${project.group} name: ${project.name} version: ${project.version}\n",
- ZonedDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME),
- InetAddress.getLocalHost(),
- System.getProperty("os.name"),
- System.getProperty("os.arch"),
- System.getProperty("os.version"),
- System.getProperty("java.version"),
- System.getProperty("java.vm.version"),
- System.getProperty("java.vm.vendor"),
- System.getProperty("java.vm.name"),
- gradle.gradleVersion, GroovySystem.getVersion(), JavaVersion.current()
+wrapper {
+ gradleVersion = "${project.property('gradle.wrapper.version')}"
+ distributionType = Wrapper.DistributionType.ALL
+}
ext {
user = 'xbib'
- projectName = 'rpm'
- projectDescription = 'Java 8 RPM implementation with plugins for Ant, Maven, Gradle'
- scmUrl = 'https://github.com/xbib/rpm'
- scmConnection = 'scm:git:git://github.com/xbib/rpm.git'
- scmDeveloperConnection = 'scm:git:git://github.com/xbib/rpm.git'
+ name = 'rpm'
+ description = 'RPM implementation in Java with plugins for Ant, Maven, Gradle'
+ inceptionYear = '2016'
+ url = 'https://github.com/' + user + '/' + name
+ scmUrl = 'https://github.com/' + user + '/' + name
+ scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
+ scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git'
+ issueManagementSystem = 'Github'
+ issueManagementUrl = ext.scmUrl + '/issues'
+ licenseName = 'The Apache License, Version 2.0'
+ licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
subprojects {
-
- apply plugin: 'java'
- apply plugin: 'maven'
-
- repositories {
- mavenLocal()
- mavenCentral()
- }
-
- dependencies {
- testCompile "junit:junit:${project.property('junit.version')}"
- }
-
- compileJava {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
- }
- compileTestJava {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
- }
-
- [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
-
- tasks.withType(JavaCompile) {
- options.compilerArgs << "-Xlint:all" << "-profile" << "compact1"
- }
-
- test {
- testLogging {
- showStandardStreams = false
- exceptionFormat = 'full'
- }
- }
-
- clean {
- delete 'out'
- }
-
- sonarqube {
- properties {
- property "sonar.projectName", "xbib RPM"
- property "sonar.sourceEncoding", "UTF-8"
- property "sonar.tests", "src/test/java"
- property "sonar.scm.provider", "git"
- property "sonar.junit.reportsPath", "build/test-results/test/"
- }
- }
-
- task sourcesJar(type: Jar) {
- classifier 'sources'
- from sourceSets.main.allSource
- }
-
- task javadocJar(type: Jar) {
- classifier 'javadoc'
- }
-
- artifacts {
- archives sourcesJar, javadocJar
- }
-
- apply from: "${rootProject.projectDir}/gradle/publish.gradle"
+ apply plugin: 'java-library'
+ apply from: rootProject.file('gradle/ide/idea.gradle')
+ apply from: rootProject.file('gradle/compile/java.gradle')
+ apply from: rootProject.file('gradle/test/junit5.gradle')
+ apply from: rootProject.file('gradle/publishing/publication.gradle')
}
+apply from: rootProject.file('gradle/publishing/sonatype.gradle')
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
deleted file mode 100644
index 55e59d2..0000000
--- a/config/checkstyle/checkstyle.xml
+++ /dev/null
@@ -1,323 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/gradle-plugin-rpm/NOTICE.txt b/gradle-plugin-rpm/NOTICE.txt
deleted file mode 100644
index f188c12..0000000
--- a/gradle-plugin-rpm/NOTICE.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-This is a derived work of
-
-https://github.com/nebula-plugins/gradle-ospackage-plugin
-
-licensed under Apache Software License 2.0.
diff --git a/gradle-plugin-rpm/build.gradle b/gradle-plugin-rpm/build.gradle
index ab04047..84e910c 100644
--- a/gradle-plugin-rpm/build.gradle
+++ b/gradle-plugin-rpm/build.gradle
@@ -1,37 +1,41 @@
plugins {
id 'java-gradle-plugin'
- id 'com.gradle.plugin-publish' version '0.10.0'
+ id 'com.gradle.plugin-publish' version '0.11.0'
}
group = 'org.xbib.gradle.plugin'
apply plugin: 'groovy'
-apply plugin: 'maven'
-apply plugin: 'signing'
+apply plugin: 'java-gradle-plugin'
apply plugin: 'com.gradle.plugin-publish'
dependencies {
- compile gradleApi()
- compile project(':rpm-core')
- compileOnly "org.codehaus.groovy:groovy:${project.property('groovy.version')}"
- testCompile "junit:junit:${project.property('junit.version')}"
- testCompile("org.spockframework:spock-core:${project.property('spock-core.version')}") {
- exclude module: 'groovy'
- exclude module: 'junit'
- }
- testCompile "org.xbib:guice:${project.property('xbib-guice.version')}"
-
+ api gradleApi()
+ api project(':rpm-core')
+ testImplementation gradleTestKit()
}
compileGroovy {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
}
-test {
- testLogging {
- showStandardStreams = true
- exceptionFormat = 'full'
+compileTestGroovy {
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
+}
+
+validatePlugins {
+ // disable warning as failures because gradle plugin does not recognize @Delegate tag
+ failOnWarning = false
+}
+
+gradlePlugin {
+ plugins {
+ rpmPlugin {
+ id = 'org.xbib.gradle.plugin.rpm'
+ implementationClass = 'org.xbib.gradle.plugin.RpmPlugin'
+ }
}
}
@@ -43,8 +47,8 @@ if (project.hasProperty('gradle.publish.key')) {
rpmPlugin {
id = 'org.xbib.gradle.plugin.rpm'
version = project.version
- description = projectDescription
- displayName = projectDescription
+ description = rootProject.ext.description
+ displayName = rootProject.ext.description
tags = ['gradle', 'plugin', 'rpm']
}
}
diff --git a/gradle-plugin-rpm/config/checkstyle/checkstyle.xml b/gradle-plugin-rpm/config/checkstyle/checkstyle.xml
deleted file mode 100644
index 55e59d2..0000000
--- a/gradle-plugin-rpm/config/checkstyle/checkstyle.xml
+++ /dev/null
@@ -1,323 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/Rpm.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/Rpm.groovy
new file mode 100644
index 0000000..18274d4
--- /dev/null
+++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/Rpm.groovy
@@ -0,0 +1,51 @@
+package org.xbib.gradle.plugin
+
+import org.gradle.api.internal.file.copy.CopyAction
+import org.gradle.api.tasks.Nested
+import org.gradle.api.tasks.bundling.AbstractArchiveTask
+
+import java.util.concurrent.Callable
+
+class Rpm extends AbstractArchiveTask {
+
+ @Delegate
+ @Nested
+ RpmExtension rpmExtension
+
+ Rpm() {
+ rpmExtension = project.extensions.findByName('rpm') as RpmExtension
+ getArchiveExtension().set("rpm")
+ Callable archiveFileNameProvider = new Callable() {
+ @Override
+ String call() throws Exception {
+ constructArchiveFileName()
+ }
+ }
+ archiveFileName.set(project.provider(archiveFileNameProvider))
+ }
+
+ @Override
+ protected CopyAction createCopyAction() {
+ new RpmCopyAction(project, rpmExtension, this)
+ }
+
+ private String constructArchiveFileName() {
+ StringBuilder sb = new StringBuilder()
+ if (packageName) {
+ sb.append(packageName)
+ }
+ if (packageVersion) {
+ sb.append('-').append(packageVersion)
+ }
+ if (packageRelease) {
+ sb.append('-').append(packageRelease)
+ }
+ if (arch) {
+ sb.append('.').append(arch.name().toLowerCase(Locale.ROOT))
+ }
+ if (archiveExtension) {
+ sb.append('.').append(archiveExtension.get())
+ }
+ sb.toString()
+ }
+}
diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/RpmCopyAction.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/RpmCopyAction.groovy
new file mode 100644
index 0000000..d0d73d7
--- /dev/null
+++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/RpmCopyAction.groovy
@@ -0,0 +1,212 @@
+package org.xbib.gradle.plugin
+
+import org.gradle.api.Project
+import org.gradle.api.file.DuplicatesStrategy
+import org.gradle.api.file.FileCopyDetails
+import org.gradle.api.internal.file.CopyActionProcessingStreamAction
+import org.gradle.api.internal.file.copy.CopyAction
+import org.gradle.api.internal.file.copy.CopyActionProcessingStream
+import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
+import org.gradle.api.tasks.WorkResult
+import org.gradle.api.tasks.WorkResults
+import org.xbib.rpm.Dependency
+import org.xbib.rpm.Directory
+import org.xbib.rpm.Link
+import org.xbib.rpm.RpmBuilder
+import org.xbib.rpm.payload.Directive
+import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.StandardOpenOption
+
+class RpmCopyAction implements CopyAction {
+
+ Project project
+
+ Rpm task
+
+ RpmExtension ext
+
+ RpmBuilder builder
+
+ Path tempDir
+
+ RpmCopyAction(Project project, RpmExtension rpmExtension, Rpm task) {
+ this.project = project
+ this.task = task
+ this.ext = rpmExtension
+ }
+
+ @Override
+ WorkResult execute(CopyActionProcessingStream copyActionProcessingStream) {
+ if (ext.enabled) {
+ task.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
+ tempDir = task.getTemporaryDir().toPath()
+ this.builder = createRpm()
+ copyActionProcessingStream.process(new StreamAction())
+ addOther()
+ buildRpm()
+ }
+ WorkResults.didWork(true)
+ }
+
+ RpmBuilder createRpm() {
+ RpmBuilder builder = new RpmBuilder()
+ builder.setPackage ext.packageName, ext.packageVersion, ext.packageRelease, ext.epoch
+ builder.setType ext.packageType
+ builder.setPlatform ext.arch, ext.os
+ builder.setGroup ext.packageGroup
+ builder.setBuildHost ext.buildHost
+ builder.setSummary ext.summary
+ builder.setDescription ext.packageDescription
+ builder.setLicense ext.license
+ builder.setPackager ext.packager
+ builder.setDistribution ext.distribution
+ builder.setVendor ext.vendor
+ builder.setUrl ext.url
+ builder.setPrefixes task.prefixes
+ builder.setPrivateKeyId task.getSigningKeyId()
+ builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase()
+ builder.setPrivateKeyRing task.getSigningKeyRing()
+ builder.setPrivateKeyHashAlgo task.getSigningKeyHashAlgo()
+ builder.setSourceRpm(task.sourcePackage)
+ builder.setPreInstall task.preInstallFile?.text ?: task.preInstall
+ builder.setPostInstall task.postInstallFile?.text ?: task.postInstall
+ builder.setPreUninstall task.preUninstallFile?.text ?: task.preUninstall
+ builder.setPostUninstall task.postUninstallFile?.text ?: task.postUninstall
+ builder.setPreTrans task.preTransFile?.text ?: task.preTrans
+ builder.setPostTrans task.postTransFile?.text ?: task.postTrans
+ builder.setPreInstall prepareScripts(task, task.preInstallCommands)
+ builder.setPostInstall prepareScripts(task, task.postInstallCommands)
+ builder.setPreUninstall prepareScripts(task, task.preUninstallCommands)
+ builder.setPostUninstall prepareScripts(task, task.postUninstallCommands)
+ builder.setPreTrans prepareScripts(task, task.preTransCommands)
+ builder.setPostTrans prepareScripts(task, task.postTransCommands)
+ if (task.changeLogFile) {
+ builder.addChangelog task.changeLogFile?.toPath()
+ }
+ if (task.changeLog) {
+ builder.addChangelog(task.changeLog)
+ }
+ builder
+ }
+
+ void addOther() {
+ for (Link link : task.links) {
+ builder.addLink(link.path, link.target, link.permissions)
+ }
+ for (Dependency dep : task.dependencies) {
+ builder.addDependency(dep.packageName, dep.flags, dep.version)
+ }
+ for (Dependency obsolete: task.obsoletes) {
+ builder.addObsoletes(obsolete.packageName, obsolete.flags, obsolete.version)
+ }
+ for (Dependency conflict : task.conflicts) {
+ builder.addConflicts(conflict.packageName, conflict.flags, conflict.version)
+ }
+ for (Dependency provides : task.provides) {
+ builder.addProvides(provides.packageName, provides.flags, provides.version)
+ }
+ for (Directory directory : task.directories) {
+ String user = directory.user ? directory.user : task.user
+ String group = directory.group ? directory.group : task.group
+ builder.addDirectory(directory.path, directory.permissions, null, user, group, directory.addParents)
+ }
+ }
+
+ void buildRpm() {
+ Path path = task.archiveFile.get().asFile.toPath()
+ Files.createDirectories(path.parent)
+ Files.newByteChannel(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING).withCloseable { ch ->
+ builder.build(ch)
+ }
+ }
+
+ private class StreamAction implements CopyActionProcessingStreamAction {
+
+ @Override
+ void processFile(FileCopyDetailsInternal fileCopyDetailsInternal) {
+ boolean addParents = ext.addParentDirs != null ? ext.addParentDirs : task.addParentDirs
+ Path path = extractPath(tempDir, fileCopyDetailsInternal)
+ String p = "/${fileCopyDetailsInternal.path}"
+ if (Files.isSymbolicLink(path)) {
+ builder.addLink(p, Files.readSymbolicLink(path).toFile().path, -1)
+ } else if (!fileCopyDetailsInternal.isDirectory()) {
+ int mode = fileCopyDetailsInternal.mode
+ int dirmode = -1
+ EnumSet directive = makeDirective(ext.fileType)
+ String user = ext.user ?: task.user
+ String group = ext.group ?: task.group
+ builder.addFile(p, path, mode, dirmode, directive, user, group, addParents)
+ }
+ }
+ }
+
+ private static Path extractPath(Path tempDir, FileCopyDetails fileDetails) {
+ Path path
+ try {
+ path = fileDetails.file.toPath()
+ } catch (UnsupportedOperationException e) {
+ path = tempDir.resolve(fileDetails.path)
+ fileDetails.copyTo(path.toFile())
+ }
+ path
+ }
+
+ private static EnumSet makeDirective(List strings) {
+ EnumSet set = EnumSet.of(Directive.NONE)
+ for (String string : strings) {
+ set.add(Directive.valueOf(string.toUpperCase(Locale.ROOT)))
+ }
+ set
+ }
+
+ private static String prepareScripts(Rpm task, List