forked from MinecraftForge/ForgeGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskMergeFiles.java
More file actions
145 lines (119 loc) · 3.63 KB
/
TaskMergeFiles.java
File metadata and controls
145 lines (119 loc) · 3.63 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins.
* Copyright (C) 2013-2019 Minecraft Forge
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.minecraftforge.gradle.patcher;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import net.minecraftforge.gradle.common.Constants;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.io.Files;
class TaskMergeFiles extends DefaultTask
{
@InputFiles
private final List<Object> inSrgs = Lists.newArrayListWithExpectedSize(3);
@OutputFile
private Object outSrg;
@InputFiles
private final List<Object> inExcs = Lists.newArrayListWithExpectedSize(3);
@OutputFile
private Object outExc;
@InputFiles
private final List<Object> inAts = Lists.newArrayListWithExpectedSize(3);
@OutputFile
private Object outAt;
//@formatter:off
public TaskMergeFiles() {}
//@formatter:on
@TaskAction
public void mergeFiles() throws IOException
{
mergeFiles(getInSrgs(), ".srg", getOutSrg());
mergeFiles(getInExcs(), ".exc", getOutExc());
mergeFiles(getInAts(), "_at.cfg", getOutAt());
}
private void mergeFiles(FileCollection in, String ending, File out) throws IOException
{
Set<String> lines = Sets.newLinkedHashSet();
for (File f : in.getFiles())
{
if (f.isDirectory() || !f.exists() || !f.getName().endsWith(ending))
continue;
lines.addAll(Files.readLines(f, Constants.CHARSET));
}
out.getParentFile().mkdirs();
Files.write(Joiner.on('\n').join(lines), out, Constants.CHARSET);
}
public File getOutSrg()
{
return getProject().file(outSrg);
}
public void setOutSrg(Object outSrg)
{
this.outSrg = outSrg;
}
public File getOutExc()
{
return getProject().file(outExc);
}
public void setOutExc(Object outExc)
{
this.outExc = outExc;
}
public File getOutAt()
{
return getProject().file(outAt);
}
public void setOutAt(Object outAt)
{
this.outAt = outAt;
}
public FileCollection getInSrgs()
{
return getProject().files(inSrgs);
}
public void addSrg(Object srg)
{
inSrgs.add(srg);
}
public FileCollection getInExcs()
{
return getProject().files(inExcs);
}
public void addExc(Object exc)
{
inExcs.add(exc);
}
public FileCollection getInAts()
{
return getProject().files(inAts);
}
public void addAt(Object at)
{
inAts.add(at);
}
}