remove extension from rpm plugin

This commit is contained in:
Jörg Prante 2021-11-10 17:45:57 +01:00
parent ed0049ae68
commit d8f82a8978
12 changed files with 566 additions and 571 deletions

View file

@ -13,6 +13,7 @@ dependencies {
api "org.xbib:groovy-git:${project.property('groovy-git.version')}" api "org.xbib:groovy-git:${project.property('groovy-git.version')}"
testImplementation gradleTestKit() testImplementation gradleTestKit()
testImplementation "org.spockframework:spock-core:${project.property('spock.version')}" testImplementation "org.spockframework:spock-core:${project.property('spock.version')}"
testImplementation "junit:junit:${project.property('junit4.version')}"
} }
compileGroovy { compileGroovy {

View file

@ -10,11 +10,13 @@ import org.xbib.groovy.git.Git
import spock.lang.Specification import spock.lang.Specification
class GitPluginTest extends Specification { class GitPluginTest extends Specification {
@Rule TemporaryFolder tempDir = new TemporaryFolder() @Rule TemporaryFolder tempDir
File projectDir File projectDir
File buildFile File buildFile
def setup() { def setup() {
tempDir = new TemporaryFolder()
tempDir.create()
projectDir = tempDir.newFolder('project') projectDir = tempDir.newFolder('project')
buildFile = projectFile('build.gradle') buildFile = projectFile('build.gradle')
} }

View file

@ -1 +1 @@
version = 2.1.1 version = 3.0.0

View file

@ -1,20 +1,302 @@
package org.xbib.gradle.plugin package org.xbib.gradle.plugin
import org.gradle.api.internal.file.copy.CopyAction import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.tasks.Nested import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.bundling.AbstractArchiveTask import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.xbib.rpm.Dependency
import org.xbib.rpm.Directory
import org.xbib.rpm.Link
import org.xbib.rpm.lead.Architecture
import org.xbib.rpm.lead.Os
import org.xbib.rpm.lead.PackageType
import java.util.concurrent.Callable import java.util.concurrent.Callable
class Rpm extends AbstractArchiveTask { class Rpm extends AbstractArchiveTask {
@Delegate(methodAnnotations = true) @Input
@Nested String packageName
RpmExtension rpmExtension
@Input
String packageVersion
@Input
String packageRelease
@Optional
@Input
Integer epoch
@Optional
@Input
String signingKeyPassphrase
@Optional
@Input
String signingKeyRing
@Optional
@Input
String signingKeyId
@Optional
@Input
String signingKeyHashAlgo
@Optional
@Input
String user
@Optional
@Input
String group
@Optional
@Input
String buildHost
@Optional
@Input
String packageGroup
@Optional
@Input
String packageDescription
@Optional
@Input
String summary
@Optional
@Input
String license
@Optional
@Input
String packager
@Optional
@Input
String distribution
@Optional
@Input
String vendor
@Optional
@Input
String url
@Optional
@Input
String sourcePackage
@Optional
@Input
List<String> fileType
@Optional
@Input
Boolean addParentDirs
@Optional
@Input
Architecture arch
@Optional
@Input
Os os
@Optional
@Input
PackageType packageType
@Optional
@Input
List<String> prefixes
@Optional
@Input
Integer uid
@Optional
@Input
Integer gid
@Optional
@Input
String maintainer
@Optional
@Input
String uploaders
@Optional
@Input
String priority
@Optional
@Input
String preInstall
@Optional
@InputFile
File preInstallFile
@Optional
@Input
List<Object> preInstallCommands
@Optional
@Input
String postInstall
@Optional
@InputFile
File postInstallFile
@Optional
@Input
List<Object> postInstallCommands
@Optional
@Input
String preUninstall
@Optional
@InputFile
File preUninstallFile
@Optional
@Input
List<Object> preUninstallCommands
@Optional
@Input
String postUninstall
@Optional
@InputFile
File postUninstallFile
@Optional
@Input
List<Object> postUninstallCommands
@Optional
@Input
String preTrans
@Optional
@InputFile
File preTransFile
@Optional
@Input
List<Object> preTransCommands
@Optional
@Input
String postTrans
@Optional
@InputFile
File postTransFile
@Optional
@Input
List<Directory> directories
@Optional
@InputFile
File changeLogFile
@Optional
@Input
String changeLog
@Optional
@Input
List<Object> postTransCommands
@Optional
@Input
List<Object> commonCommands
@Optional
@Input
List<Link> links
@Optional
@Input
List<Dependency> dependencies
@Optional
@Input
List<Dependency> obsoletes
@Optional
@Input
List<Dependency> conflicts
@Optional
@Input
List<Dependency> recommends
@Optional
@Input
List<Dependency> suggests
@Optional
@Input
List<Dependency> enhances
@Optional
@Input
List<Dependency> preDepends
@Optional
@Input
List<Dependency> breaks
@Optional
@Input
List<Dependency> replaces
@Optional
@Input
List<Dependency> provides
Rpm() { Rpm() {
super() super()
rpmExtension = project.extensions.findByType(RpmExtension) as RpmExtension // sane defaults
os = Os.LINUX
arch = Architecture.AMD64
packageType = PackageType.BINARY
epoch = 0
packageDescription = ''
preInstallCommands = []
preUninstallCommands = []
preTransCommands = []
postInstallCommands = []
postUninstallCommands = []
postTransCommands = []
commonCommands = []
prefixes = []
directories = []
links = []
dependencies = []
obsoletes = []
conflicts = []
recommends = []
suggests = []
enhances = []
preDepends = []
breaks = []
replaces = []
provides = []
getArchiveExtension().set("rpm") getArchiveExtension().set("rpm")
Callable<String> archiveFileNameProvider = new Callable<String>() { Callable<String> archiveFileNameProvider = new Callable<String>() {
@Override @Override
@ -27,7 +309,7 @@ class Rpm extends AbstractArchiveTask {
@Override @Override
protected CopyAction createCopyAction() { protected CopyAction createCopyAction() {
new RpmCopyAction(project, rpmExtension, this) new RpmCopyAction(project, this)
} }
private String constructArchiveFileName() { private String constructArchiveFileName() {
@ -49,4 +331,161 @@ class Rpm extends AbstractArchiveTask {
} }
sb.toString() sb.toString()
} }
Directory directory(String path) {
Directory directory = new Directory(path: path)
directories << directory
directory
}
Link link(String path, String target) {
link(path, target, -1)
}
Link link(String path, String target, int permissions) {
Link link = new Link(path, target, permissions)
links.add(link)
link
}
Dependency requires(String packageName) {
requires(packageName, '')
}
Dependency requires(String packageName, String version){
requires(packageName, version, 0)
}
Dependency requires(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
dependencies.add(dep)
dep
}
Dependency obsoletes(String packageName) {
obsoletes(packageName, '')
}
Dependency obsoletes(String packageName, String version) {
obsoletes(packageName, version, 0)
}
Dependency obsoletes(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
obsoletes.add(dep)
dep
}
Dependency conflicts(String packageName) {
conflicts(packageName, '')
}
Dependency conflicts(String packageName, String version) {
conflicts(packageName, version, 0)
}
Dependency conflicts(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
conflicts.add(dep)
dep
}
Dependency recommends(String packageName) {
recommends(packageName, '')
}
Dependency recommends(String packageName, String version) {
recommends(packageName, version, 0)
}
Dependency recommends(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
recommends.add(dep)
dep
}
Dependency suggests(String packageName) {
suggests(packageName, '')
}
Dependency suggests(String packageName, String version) {
suggests(packageName, version, 0)
}
Dependency suggests(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
suggests.add(dep)
dep
}
Dependency enhances(String packageName) {
enhances(packageName, '')
}
Dependency enhances(String packageName, String version) {
enhances(packageName, version, 0)
}
Dependency enhances(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
enhances.add(dep)
dep
}
Dependency preDepends(String packageName) {
preDepends(packageName, '')
}
Dependency preDepends(String packageName, String version) {
preDepends(packageName, version, 0)
}
Dependency preDepends(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
preDepends.add(dep)
dep
}
Dependency breaks(String packageName) {
breaks(packageName, '')
}
Dependency breaks(String packageName, String version) {
breaks(packageName, version, 0)
}
Dependency breaks(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
breaks.add(dep)
dep
}
Dependency replaces(String packageName) {
replaces(packageName, '')
}
Dependency replaces(String packageName, String version) {
replaces(packageName, version, 0)
}
Dependency replaces(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
replaces.add(dep)
dep
}
Dependency provides(String packageName) {
provides(packageName, '')
}
Dependency provides(String packageName, String version) {
provides(packageName, version, 0)
}
Dependency provides(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
provides.add(dep)
dep
}
} }

View file

@ -24,24 +24,21 @@ class RpmCopyAction implements CopyAction {
Rpm task Rpm task
RpmExtension ext
RpmBuilder builder RpmBuilder builder
Path tempDir Path tempDir
RpmCopyAction(Project project, RpmExtension rpmExtension, Rpm task) { RpmCopyAction(Project project, Rpm task) {
this.project = project this.project = project
this.task = task this.task = task
this.ext = rpmExtension
} }
@Override @Override
WorkResult execute(CopyActionProcessingStream copyActionProcessingStream) { WorkResult execute(CopyActionProcessingStream copyActionProcessingStream) {
if (ext.enabled) { if (task.enabled) {
task.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) task.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
tempDir = task.getTemporaryDir().toPath() tempDir = task.getTemporaryDir().toPath()
this.builder = createRpm() builder = createRpm()
copyActionProcessingStream.process(new StreamAction()) copyActionProcessingStream.process(new StreamAction())
addOther() addOther()
buildRpm() buildRpm()
@ -51,18 +48,18 @@ class RpmCopyAction implements CopyAction {
RpmBuilder createRpm() { RpmBuilder createRpm() {
RpmBuilder builder = new RpmBuilder() RpmBuilder builder = new RpmBuilder()
builder.setPackage ext.packageName, ext.packageVersion, ext.packageRelease, ext.epoch builder.setPackage task.packageName, task.packageVersion, task.packageRelease, task.epoch
builder.setType ext.packageType builder.setType task.packageType
builder.setPlatform ext.arch, ext.os builder.setPlatform task.arch, task.os
builder.setGroup ext.packageGroup builder.setGroup task.packageGroup
builder.setBuildHost ext.buildHost builder.setBuildHost task.buildHost
builder.setSummary ext.summary builder.setSummary task.summary
builder.setDescription ext.packageDescription builder.setDescription task.packageDescription
builder.setLicense ext.license builder.setLicense task.license
builder.setPackager ext.packager builder.setPackager task.packager
builder.setDistribution ext.distribution builder.setDistribution task.distribution
builder.setVendor ext.vendor builder.setVendor task.vendor
builder.setUrl ext.url builder.setUrl task.url
builder.setPrefixes task.prefixes builder.setPrefixes task.prefixes
builder.setPrivateKeyId task.getSigningKeyId() builder.setPrivateKeyId task.getSigningKeyId()
builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase() builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase()
@ -126,7 +123,7 @@ class RpmCopyAction implements CopyAction {
@Override @Override
void processFile(FileCopyDetailsInternal fileCopyDetailsInternal) { void processFile(FileCopyDetailsInternal fileCopyDetailsInternal) {
boolean addParents = ext.addParentDirs != null ? ext.addParentDirs : task.addParentDirs boolean addParents = task.addParentDirs != null ? task.addParentDirs : task.addParentDirs
Path path = extractPath(tempDir, fileCopyDetailsInternal) Path path = extractPath(tempDir, fileCopyDetailsInternal)
String p = "/${fileCopyDetailsInternal.path}" String p = "/${fileCopyDetailsInternal.path}"
if (Files.isSymbolicLink(path)) { if (Files.isSymbolicLink(path)) {
@ -134,9 +131,9 @@ class RpmCopyAction implements CopyAction {
} else if (!fileCopyDetailsInternal.isDirectory()) { } else if (!fileCopyDetailsInternal.isDirectory()) {
int mode = fileCopyDetailsInternal.mode int mode = fileCopyDetailsInternal.mode
int dirmode = -1 int dirmode = -1
EnumSet<Directive> directive = makeDirective(ext.fileType) EnumSet<Directive> directive = makeDirective(task.fileType)
String user = ext.user ?: task.user String user = task.user ?: task.user
String group = ext.group ?: task.group String group = task.group ?: task.group
builder.addFile(p, path, mode, dirmode, directive, user, group, addParents) builder.addFile(p, path, mode, dirmode, directive, user, group, addParents)
} }
} }

View file

@ -1,430 +0,0 @@
package org.xbib.gradle.plugin
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.xbib.rpm.Dependency
import org.xbib.rpm.Directory
import org.xbib.rpm.Link
import org.xbib.rpm.lead.Architecture
import org.xbib.rpm.lead.Os
import org.xbib.rpm.lead.PackageType
class RpmExtension {
@Optional
@Input
Boolean enabled = true
@Optional
@Input
String packageName
@Optional
@Input
String packageVersion
@Optional
@Input
String packageRelease
@Optional
@Input
Integer epoch = 0
@Optional
@Input
String signingKeyPassphrase
@Optional
@Input
String signingKeyRing
@Optional
@Input
String signingKeyId
@Optional
@Input
String signingKeyHashAlgo
@Optional
@Input
String user
@Optional
@Input
String group
@Optional
@Input
String buildHost
@Optional
@Input
String packageGroup
@Optional
@Input
String packageDescription = ''
@Optional
@Input
String summary
@Optional
@Input
String license
@Optional
@Input
String packager
@Optional
@Input
String distribution
@Optional
@Input
String vendor
@Optional
@Input
String url
@Optional
@Input
String sourcePackage
@Optional
@Input
List<String> fileType
@Optional
@Input
Boolean addParentDirs = false
@Optional
@Input
Architecture arch = Architecture.X86_64
@Optional
@Input
Os os = Os.LINUX
@Optional
@Input
PackageType packageType = PackageType.BINARY
@Optional
@Input
List<String> prefixes = new ArrayList<String>()
@Optional
@Input
Integer uid
@Optional
@Input
Integer gid
@Optional
@Input
String maintainer
@Optional
@Input
String uploaders
@Optional
@Input
String priority
@Optional
@Input
String preInstall
@Optional
@InputFile
File preInstallFile
@Optional
@Input
List<Object> preInstallCommands = []
@Optional
@Input
String postInstall
@Optional
@InputFile
File postInstallFile
@Optional
@Input
List<Object> postInstallCommands = []
@Optional
@Input
String preUninstall
@Optional
@InputFile
File preUninstallFile
@Optional
@Input
List<Object> preUninstallCommands = []
@Optional
@Input
String postUninstall
@Optional
@InputFile
File postUninstallFile
@Optional
@Input
List<Object> postUninstallCommands = []
@Optional
@Input
String preTrans
@Optional
@InputFile
File preTransFile
@Optional
@Input
List<Object> preTransCommands = []
@Optional
@Input
String postTrans
@Optional
@InputFile
File postTransFile
@Optional
@Input
List<Directory> directories = []
@Optional
@InputFile
File changeLogFile
@Optional
@Input
String changeLog
@Optional
@Input
List<Object> postTransCommands = []
@Optional
@Input
List<Object> commonCommands = []
@Optional
@Input
List<Link> links = []
@Optional
@Input
List<Dependency> dependencies = []
@Optional
@Input
List<Dependency> obsoletes = []
@Optional
@Input
List<Dependency> conflicts = []
@Optional
@Input
List<Dependency> recommends = []
@Optional
@Input
List<Dependency> suggests = []
@Optional
@Input
List<Dependency> enhances = []
@Optional
@Input
List<Dependency> preDepends = []
@Optional
@Input
List<Dependency> breaks = []
@Optional
@Input
List<Dependency> replaces = []
@Optional
@Input
List<Dependency> provides = []
Directory directory(String path) {
Directory directory = new Directory(path: path)
directories << directory
directory
}
Link link(String path, String target) {
link(path, target, -1)
}
Link link(String path, String target, int permissions) {
Link link = new Link(path, target, permissions)
links.add(link)
link
}
Dependency requires(String packageName) {
requires(packageName, '')
}
Dependency requires(String packageName, String version){
requires(packageName, version, 0)
}
Dependency requires(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
dependencies.add(dep)
dep
}
Dependency obsoletes(String packageName) {
obsoletes(packageName, '')
}
Dependency obsoletes(String packageName, String version) {
obsoletes(packageName, version, 0)
}
Dependency obsoletes(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
obsoletes.add(dep)
dep
}
Dependency conflicts(String packageName) {
conflicts(packageName, '')
}
Dependency conflicts(String packageName, String version) {
conflicts(packageName, version, 0)
}
Dependency conflicts(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
conflicts.add(dep)
dep
}
Dependency recommends(String packageName) {
recommends(packageName, '')
}
Dependency recommends(String packageName, String version) {
recommends(packageName, version, 0)
}
Dependency recommends(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
recommends.add(dep)
dep
}
Dependency suggests(String packageName) {
suggests(packageName, '')
}
Dependency suggests(String packageName, String version) {
suggests(packageName, version, 0)
}
Dependency suggests(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
suggests.add(dep)
dep
}
Dependency enhances(String packageName) {
enhances(packageName, '')
}
Dependency enhances(String packageName, String version) {
enhances(packageName, version, 0)
}
Dependency enhances(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
enhances.add(dep)
dep
}
Dependency preDepends(String packageName) {
preDepends(packageName, '')
}
Dependency preDepends(String packageName, String version) {
preDepends(packageName, version, 0)
}
Dependency preDepends(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
preDepends.add(dep)
dep
}
Dependency breaks(String packageName) {
breaks(packageName, '')
}
Dependency breaks(String packageName, String version) {
breaks(packageName, version, 0)
}
Dependency breaks(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
breaks.add(dep)
dep
}
Dependency replaces(String packageName) {
replaces(packageName, '')
}
Dependency replaces(String packageName, String version) {
replaces(packageName, version, 0)
}
Dependency replaces(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
replaces.add(dep)
dep
}
Dependency provides(String packageName) {
provides(packageName, '')
}
Dependency provides(String packageName, String version) {
provides(packageName, version, 0)
}
Dependency provides(String packageName, String version, int flag) {
def dep = new Dependency(packageName, version, flag)
provides.add(dep)
dep
}
}

View file

@ -10,22 +10,11 @@ class RpmPlugin implements Plugin<Project> {
@Override @Override
void apply(Project project) { void apply(Project project) {
checkVersion()
project.plugins.apply(BasePlugin)
project.ext.Rpm = Rpm.class
project.with {
createExtension(project)
}
}
private static void checkVersion() {
String version = '6.4' String version = '6.4'
if (GradleVersion.current() < GradleVersion.version(version)) { if (GradleVersion.current() < GradleVersion.version(version)) {
throw new GradleException("need Gradle ${version} or higher") throw new GradleException("need Gradle ${version} or higher")
} }
} project.plugins.apply(BasePlugin)
project.ext.Rpm = Rpm.class
private static void createExtension(Project project) {
project.extensions.create('rpm', RpmExtension)
} }
} }

View file

@ -162,7 +162,7 @@ class RpmFullTest {
packageRelease = '1' packageRelease = '1'
with customCopySpec with customCopySpec
}) })
project.tasks.buildRpm.copy() project.tasks.buildRpm.copy() // run task
RpmReader rpmReader = new RpmReader() RpmReader rpmReader = new RpmReader()
RpmReaderResult result = rpmReader.read(project.tasks.buildRpm.outputs.files.first().toPath()) RpmReaderResult result = rpmReader.read(project.tasks.buildRpm.outputs.files.first().toPath())
assertThat(result.files*.name, is(['./lib/apple'])) assertThat(result.files*.name, is(['./lib/apple']))

View file

@ -35,10 +35,6 @@ plugins {
id 'org.xbib.gradle.plugin.rpm' id 'org.xbib.gradle.plugin.rpm'
} }
rpm {
enabled = true
}
task myRpm(type: Rpm) { task myRpm(type: Rpm) {
packageName = 'rpmIsUpToDate' packageName = 'rpmIsUpToDate'
arch = org.xbib.rpm.lead.Architecture.NOARCH arch = org.xbib.rpm.lead.Architecture.NOARCH

View file

@ -2,8 +2,9 @@ group = 'org.xbib.gradle.plugin'
name = 'gradle-plugins' name = 'gradle-plugins'
version = 0.0.1 version = 0.0.1
groovy.version = 2.5.12 groovy.version = 3.0.9
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 7.3
groovy-git.version = 2.0.1 groovy-git.version = 2.0.1
rpm.version = 2.1.0 rpm.version = 2.1.0
spock.version = 1.2-groovy-2.5 spock.version = 2.0-groovy-3.0
junit4.version = 4.13.2

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists