-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistribution.gradle
102 lines (85 loc) · 2.83 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.nio.file.Files
import java.nio.file.Paths
// changelog.gradle
apply from: 'https://git.io/JqJiC'
def getPathsRelativeToModule(moduleName, srcDirSet) {
def module = rootDir.toPath().resolve(moduleName)
def map = new HashMap<String, String>()
def srcDirs = srcDirSet.srcDirs.stream().withCloseable {
it.filter({ f -> f.exists() }).collect()
}
//@formatter:off
for (File srcDir : (srcDirs as List<File>)) {
Files.walk(srcDir.toPath()).withCloseable
{
def paths = it.filter({ Files.isRegularFile(it as java.nio.file.Path) }).collect()
for (java.nio.file.Path path : (paths as List<java.nio.file.Path>)) {
def srcDirPath = srcDir.toPath()
def relativePath = srcDirPath.relativize(path)
def srcDirName = module.relativize(srcDirPath)
map.put(relativePath.toString(), srcDirName.toString())
}
}
}//@formatter:on
return map
}
static def getRelativeCopyPath(fcd, relativePathMap) {
def path = relativePathMap.get(Paths.get(fcd.path).toString())
if (path != null) {
return fcd.relativePath.prepend(path)
}
else throw new Exception("Unable to relativize copy path: $fcd.path")
}
def mediaClassesDir = "$buildDir/classes/lua/media"
task mediaClasses(type: Copy, overwrite: true) {
into mediaClassesDir
from(sourceSets.media.java.srcDirs) {
def mSources = getPathsRelativeToModule('media', sourceSets.media.java)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mSources))
}
}
includeEmptyDirs = false
}
processMediaResources {
includeEmptyDirs = false
def mResources = getPathsRelativeToModule('media', sourceSets.media.resources)
eachFile {
def fcd = it as FileCopyDetails
fcd.setRelativePath(getRelativeCopyPath(fcd, mResources))
}
}
def stagePath = "$buildDir/tmp/distribution/stage"
task cleanModDistributionStage(type: Delete) {
description 'Clean distribution stage directory.'
group 'distribution'
it.onlyIf {
file(stagePath).exists()
}
delete(stagePath)
}
tasks.register('stageModDistribution', Copy.class) {
it.description 'Copy mod distribution files to stage directory.'
it.group 'distribution'
it.from mediaClassesDir, "$buildDir/resources/media"
it.into stagePath
it.dependsOn(cleanModDistributionStage)
it.mustRunAfter('processMediaResources', 'mediaClasses')
}
distributions {
mod.contents {
it.from stagePath
it.into 'media'
}
}
installModDist {
def parentDir = destinationDir.parentFile.toPath()
destinationDir = parentDir.resolve(rootProject.name).toFile()
}
['modDistTar', 'modDistZip'].forEach({
def task = tasks.named(it).get() as AbstractArchiveTask
task.archiveBaseName.set(rootProject.name)
task.mustRunAfter('stageModDistribution')
})
assembleModDist.dependsOn('processMediaResources', 'mediaClasses', 'stageModDistribution')