1- import java.nio.file.Files
2- import java.nio.file.Paths
3-
4- // changelog.gradle
5- apply from : ' https://git.io/JqJiC'
6-
7- def getPathsRelativeToModule (moduleName , srcDirSet ) {
8-
9- def module = rootDir. toPath(). resolve(moduleName)
10- def map = new HashMap<String , String > ()
11-
12- def srcDirs = srcDirSet. srcDirs. stream(). withCloseable {
13- it. filter({ f -> f. exists() }). collect()
14- }
15- for (File srcDir : (srcDirs as List<File > ))
16- {
17- Files . walk(srcDir. toPath()). withCloseable
18- {
19- def paths = it. filter({ Files . isRegularFile(it as java.nio.file.Path ) }). collect()
20- for (java.nio.file.Path path : (paths as List<java.nio.file.Path > ))
21- {
22- def srcDirPath = srcDir. toPath()
23- def relativePath = srcDirPath. relativize(path)
24- def srcDirName = module. relativize(srcDirPath)
25- map. put(relativePath. toString(), srcDirName. toString())
26- }
27- }
28- }
29- return map
30- }
31-
32- static def getRelativeCopyPath (fcd , relativePathMap ) {
33-
34- def path = relativePathMap. get(Paths . get(fcd. path). toString())
35- if (path != null ) {
36- return fcd. relativePath. prepend(path)
37- }
38- else throw new Exception (" Unable to relativize copy path: $fcd . path " )
39- }
40-
41- def mediaClassesDir = " $buildDir /classes/lua/media"
42- task mediaClasses (type : Copy , overwrite : true ) {
43-
44- into mediaClassesDir
45- from(sourceSets. media. java. srcDirs) {
46- def mSources = getPathsRelativeToModule(' media' , sourceSets. media. java)
47- eachFile {
48- def fcd = it as FileCopyDetails
49- fcd. setRelativePath(getRelativeCopyPath(fcd, mSources))
50- }
51- }
52- includeEmptyDirs = false
53- }
54-
55- processMediaResources {
56-
57- includeEmptyDirs = false
58- def mResources = getPathsRelativeToModule(' media' , sourceSets. media. resources)
59- eachFile {
60- def fcd = it as FileCopyDetails
61- fcd. setRelativePath(getRelativeCopyPath(fcd, mResources))
62- }
63- }
64-
65- def stagePath = " $buildDir /tmp/distribution/stage"
66- task cleanModDistributionStage (type : Delete ) {
67-
68- description ' Clean distribution stage directory.'
69- group ' distribution'
70-
71- it. onlyIf {
72- file(stagePath). exists()
73- }
74- delete(stagePath)
75- }
76- tasks. register(' stageModDistribution' , Copy . class) {
77-
78- it. description ' Copy mod distribution files to stage directory.'
79- it. group ' distribution'
80-
81- it. from mediaClassesDir, " $buildDir /resources/media"
82- it. into stagePath
83-
84- it. dependsOn(cleanModDistributionStage)
85- it. mustRunAfter(' processMediaResources' , ' mediaClasses' )
86- }
87-
88- distributions {
89- mod. contents {
90- it. from stagePath
91- it. into ' media'
92- }
93- }
94- installModDist {
95- def parentDir = destinationDir. parentFile. toPath()
96- destinationDir = parentDir. resolve(rootProject. name). toFile()
97- }
98- [ ' modDistTar' , ' modDistZip' ]. forEach({
99- def task = tasks. named(it). get() as AbstractArchiveTask
100- task. archiveBaseName. set(rootProject. name)
101- task. mustRunAfter(' stageModDistribution' )
102- })
1+ import java.nio.file.Files
2+ import java.nio.file.Paths
3+
4+ // changelog.gradle
5+ apply from : ' https://git.io/JqJiC'
6+
7+ def getPathsRelativeToModule (moduleName , srcDirSet ) {
8+
9+ def module = rootDir. toPath(). resolve(moduleName)
10+ def map = new HashMap<String , String > ()
11+
12+ def srcDirs = srcDirSet. srcDirs. stream(). withCloseable {
13+ it. filter({ f -> f. exists() }). collect()
14+ }
15+ // @formatter:off
16+ for (File srcDir : (srcDirs as List<File > )) {
17+ Files . walk(srcDir. toPath()). withCloseable
18+ {
19+ def paths = it. filter({ Files . isRegularFile(it as java.nio.file.Path ) }). collect()
20+ for (java.nio.file.Path path : (paths as List<java.nio.file.Path > )) {
21+ def srcDirPath = srcDir. toPath()
22+ def relativePath = srcDirPath. relativize(path)
23+ def srcDirName = module. relativize(srcDirPath)
24+ map. put(relativePath. toString(), srcDirName. toString())
25+ }
26+ }
27+ }// @formatter:on
28+ return map
29+ }
30+
31+ static def getRelativeCopyPath (fcd , relativePathMap ) {
32+
33+ def path = relativePathMap. get(Paths . get(fcd. path). toString())
34+ if (path != null ) {
35+ return fcd. relativePath. prepend(path)
36+ }
37+ else throw new Exception (" Unable to relativize copy path: $fcd . path " )
38+ }
39+
40+ def mediaClassesDir = " $buildDir /classes/lua/media"
41+ task mediaClasses (type : Copy , overwrite : true ) {
42+
43+ into mediaClassesDir
44+ from(sourceSets. media. java. srcDirs) {
45+ def mSources = getPathsRelativeToModule(' media' , sourceSets. media. java)
46+ eachFile {
47+ def fcd = it as FileCopyDetails
48+ fcd. setRelativePath(getRelativeCopyPath(fcd, mSources))
49+ }
50+ }
51+ includeEmptyDirs = false
52+ }
53+
54+ processMediaResources {
55+
56+ includeEmptyDirs = false
57+ def mResources = getPathsRelativeToModule(' media' , sourceSets. media. resources)
58+ eachFile {
59+ def fcd = it as FileCopyDetails
60+ fcd. setRelativePath(getRelativeCopyPath(fcd, mResources))
61+ }
62+ }
63+
64+ def stagePath = " $buildDir /tmp/distribution/stage"
65+ task cleanModDistributionStage (type : Delete ) {
66+
67+ description ' Clean distribution stage directory.'
68+ group ' distribution'
69+
70+ it. onlyIf {
71+ file(stagePath). exists()
72+ }
73+ delete(stagePath)
74+ }
75+ tasks. register(' stageModDistribution' , Copy . class) {
76+
77+ it. description ' Copy mod distribution files to stage directory.'
78+ it. group ' distribution'
79+
80+ it. from mediaClassesDir, " $buildDir /resources/media"
81+ it. into stagePath
82+
83+ it. dependsOn(cleanModDistributionStage)
84+ it. mustRunAfter(' processMediaResources' , ' mediaClasses' )
85+ }
86+
87+ distributions {
88+ mod. contents {
89+ it. from stagePath
90+ it. into ' media'
91+ }
92+ }
93+ installModDist {
94+ def parentDir = destinationDir. parentFile. toPath()
95+ destinationDir = parentDir. resolve(rootProject. name). toFile()
96+ }
97+ [' modDistTar' , ' modDistZip' ]. forEach({
98+ def task = tasks. named(it). get() as AbstractArchiveTask
99+ task. archiveBaseName. set(rootProject. name)
100+ task. mustRunAfter(' stageModDistribution' )
101+ })
103102assembleModDist. dependsOn(' processMediaResources' , ' mediaClasses' , ' stageModDistribution' )
0 commit comments