-
Notifications
You must be signed in to change notification settings - Fork 2
/
distribution.gradle
82 lines (68 loc) · 2.42 KB
/
distribution.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import org.gradle.util.GFileUtils
apply from: 'dist/distribution.gradle'
def stagePath = file("stage").toPath()
task cleanDistributionStage(type: Delete) {
description 'Clean distribution stage directory.'
group 'distribution'
it.onlyIf {
file(stagePath).exists()
}
delete(stagePath)
}
def docsList = ['README.md', 'LICENSE.txt', 'CHANGELOG.md']
tasks.register('stageDistribution', Copy.class) {
it.description 'Copy distribution files to stage directory.'
it.group 'distribution'
it.from projectDir
it.into stagePath
// files that need to be excluded
it.exclude '**/stage/', '/.gitignore', '.gitignored', 'distribution.sh', 'distribution.gradle',
'.idea/runConfigurations/distribution.xml', 'mod.info', '.idea/scopes/mod_*'
// dirs that are already excluded but we don't want to spend time on staging
it.exclude '/dist/**', '.gradle/**', 'buildSrc/.gradle/**', '/build/**',
'buildSrc/build/**', '/lib/**', '/media/**', '/logs/**'
// include project documentation
it.into('docs/zmod') {
it.from projectDir
it.include docsList + 'images/*'
}
// do additional copy actions we cannot do with this Copy task
it.doLast {
file('dist').listFiles().each {
/*
* copy additional distribution files manually because files
* excluded by task filters cannot be copied with Copy task
*/
if (it.directory) {
GFileUtils.copyDirectory(it, stagePath.resolve(it.getName()).toFile() as File)
}
else GFileUtils.copyFile(it, stagePath.resolve(it.getName()).toFile() as File)
}
// remove duplicate docs in root directory
docsList.forEach({
GFileUtils.deleteQuietly(stagePath.resolve(it).toFile())
})
}
it.dependsOn(cleanDistributionStage)
}
tasks.register('pruneDistributionStage', Delete.class) {
it.description 'Selectively delete files from distribution stage.'
it.group 'distribution'
// duplicate documentation directory
it.delete './stage/images'
def gitIgnored = file('.gitignored')
if (file(stagePath).exists() && gitIgnored.exists()) {
def ignoredFiles = GFileUtils.readFile(gitIgnored).split('\r|\n|\r\n')
ignoredFiles.each { s ->
File ignoredFile = file(s)
if (ignoredFile.toPath().toAbsolutePath().startsWith(stagePath.toAbsolutePath())) {
it.delete(ignoredFile)
logger.quiet("Deleting ignored file ${s}")
}
}
}
}
distributions.main.contents {
it.from stagePath
it.includeEmptyDirs false
}