1+ package mekanism
2+
3+ import org.gradle.api.file.DirectoryProperty
4+ import org.gradle.api.file.FileCollection
5+ import org.gradle.api.file.ProjectLayout
6+ import org.gradle.api.file.RegularFileProperty
7+ import org.gradle.api.tasks.InputFile
8+ import org.gradle.api.tasks.InputFiles
9+ import org.gradle.api.tasks.Internal
10+ import org.gradle.api.tasks.TaskAction
11+ import org.gradle.api.tasks.util.PatternFilterable
12+ import org.gradle.jvm.tasks.Jar
13+
14+ import javax.inject.Inject
15+
16+ abstract class AllJar extends Jar {
17+
18+ // TODO: Should this be declared as some sort of input?
19+ @Internal
20+ final DirectoryProperty generatedDir
21+
22+ @InputFile
23+ final RegularFileProperty pathsToExclude
24+ @InputFiles
25+ abstract FileCollection apiOutput
26+ @InputFiles
27+ abstract FileCollection mainOutput
28+ @InputFiles
29+ FileCollection secondaryModuleOutputs
30+
31+ @Inject
32+ AllJar (ProjectLayout projectLayout ) {
33+ generatedDir = objectFactory. directoryProperty(). convention(projectLayout. buildDirectory. dir(' generated' ))
34+ pathsToExclude = objectFactory. fileProperty()
35+ secondaryModuleOutputs = objectFactory. fileCollection()
36+ }
37+
38+ @Override
39+ @TaskAction
40+ protected void copy () {
41+ // copy all the files except for ones we are going to include from the merged intersection
42+ from(apiOutput)
43+
44+ // Note: We have to use from(FileCollection) as we want to ensure the pathsToExclude gets lazily evaluated, trying to lazily configure it
45+ // via a closure causes an additional spec to be added to this task at execution time, which causes it to error out. The easiest way for
46+ // us to do it, is to turn collections into file trees, and then use a matching block on them as that allows it to lazily evaluate the
47+ // filter as the collection is defined to stay up to date if the backing collection changes
48+ from(filterFiles(mainOutput, ' crafttweaker_parameter_names.json' ))
49+ from(filterFiles(secondaryModuleOutputs, ' logo.png' , ' pack.mcmeta' ))
50+
51+ // And finally copy over the generated files
52+ from(generatedDir. asFileTree. matching({ PatternFilterable pf ->
53+ pf. include(pathsToExclude. get(). asFile. text. split(' \n ' ))
54+ }))
55+
56+ super . copy()
57+ }
58+
59+ private FileCollection filterFiles (FileCollection collection , String ... extraExclusions ) {
60+ return collection. asFileTree. matching({ PatternFilterable pf ->
61+ pf. exclude(pathsToExclude. get(). asFile. text. split(' \n ' ))
62+ pf. exclude(extraExclusions)
63+ })
64+ }
65+ }
0 commit comments