Skip to content

Commit 8dd9745

Browse files
committed
fixed @killjoys broken stuff.. and reobf
1 parent 4e611fa commit 8dd9745

File tree

5 files changed

+99
-107
lines changed

5 files changed

+99
-107
lines changed

src/main/java/net/minecraftforge/gradle/user/IReobfuscator.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package net.minecraftforge.gradle.user;
2121

2222
import java.io.File;
23-
import java.util.Collection;
2423
import java.util.List;
2524

2625
import org.gradle.api.file.FileCollection;
@@ -31,7 +30,6 @@
3130
*/
3231
public interface IReobfuscator
3332
{
34-
3533
/**
3634
* Gets the mappings file used to reobfuscate. It should be either a
3735
* {@link File} or a String path for a DelayedFile.
@@ -66,36 +64,58 @@ public interface IReobfuscator
6664

6765
/**
6866
* Gets the extra srg lines and files. Modders should prefer to use
69-
* {@link #extra(Object...)} or {@code extra += []} instead of setting the
67+
* {@link #extraLines(Object...)} or {@code extra += []} instead of setting the
68+
* list manually.
69+
*
70+
* @return The extra srg lines
71+
*/
72+
List<Object> getExtraLines();
73+
74+
/**
75+
* Sets the extra lines. Modders should prefer to use
76+
* {@link #extraLines(Object...)} instead of setting the
7077
* list manually.
7178
*
72-
* @return The extra srg files or lines
79+
* @param extra The list of srg lines
7380
*/
74-
List<Object> getExtra();
81+
void setExtraLines(List<Object> extra);
7582

7683
/**
77-
* Sets the extra lines and files. Modders should prefer to use
78-
* {@link #extra(Object...)} or {@code extra += []} instead of setting the
84+
* Adds some additional srg lines for reobfuscating. These are resolved to strings.
85+
*
86+
* @param o The array to add
87+
*/
88+
void extraLines(Object... o);
89+
90+
/**
91+
* Adds a collection of additional srg lines for reobfuscating.
92+
*
93+
* @param o The collection to add
94+
*/
95+
void extraLines(Iterable<Object> o);
96+
97+
/**
98+
* Gets the extra srg files. Modders should prefer to use
99+
* {@link #extraFiles(Object...)} instead of setting the
79100
* list manually.
80101
*
81-
* @param extra The list of srgs
102+
* @return The extra srg files
82103
*/
83-
void setExtra(List<Object> extra);
104+
List<Object> getExtraFiles();
84105

85106
/**
86-
* Adds some additional srg files or lines for reobfuscating. Should be a
87-
* file or string path
107+
* Adds some additional srg files for reobfuscating. These are resolved to files with {@link org.gradle.api.Project#file(Object)}
88108
*
89109
* @param o The array to add
90110
*/
91-
void extra(Object... o);
111+
void extraFiles(Object... o);
92112

93113
/**
94-
* Adds a collection of additional srg files or lines for reobfuscating.
114+
* Adds a collection of additional srg files for reobfuscating.
95115
*
96116
* @param o The collection to add
97117
*/
98-
void extra(Collection<Object> o);
118+
void extraFiles(Iterable<Object> o);
99119

100120
/**
101121
* Sets the mappings to use Searge names. This is the default with the Forge

src/main/java/net/minecraftforge/gradle/user/ReobfTaskFactory.java

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
*/
2020
package net.minecraftforge.gradle.user;
2121

22-
import static net.minecraftforge.gradle.common.Constants.TASK_GENERATE_SRGS;
23-
2422
import java.io.File;
25-
import java.util.Collection;
2623
import java.util.List;
2724

2825
import org.gradle.api.Action;
@@ -32,7 +29,10 @@
3229
import org.gradle.api.file.FileCollection;
3330
import org.gradle.api.tasks.bundling.Jar;
3431

32+
import com.google.common.collect.Lists;
33+
3534
import groovy.lang.Closure;
35+
import net.minecraftforge.gradle.common.Constants;
3636
import net.minecraftforge.gradle.util.GradleConfigurationException;
3737

3838
public class ReobfTaskFactory implements NamedDomainObjectFactory<IReobfuscator>
@@ -51,7 +51,7 @@ public IReobfuscator create(final String jarName)
5151
String name = "reobf" + Character.toUpperCase(jarName.charAt(0)) + jarName.substring(1);
5252
final TaskSingleReobf task = plugin.maybeMakeTask(name, TaskSingleReobf.class);
5353

54-
task.dependsOn(TASK_GENERATE_SRGS, jarName);
54+
task.dependsOn(Constants.TASK_GENERATE_SRGS, jarName);
5555
task.mustRunAfter("test");
5656

5757
task.setJar(new Closure<File>(null) {
@@ -84,9 +84,9 @@ public void execute(Project arg0)
8484
class TaskWrapper implements IReobfuscator
8585
{
8686
private final String name;
87-
private final IReobfuscator reobf;
87+
private final TaskSingleReobf reobf;
8888

89-
public TaskWrapper(String name, IReobfuscator reobf)
89+
public TaskWrapper(String name, TaskSingleReobf reobf)
9090
{
9191
this.name = name;
9292
this.reobf = reobf;
@@ -103,7 +103,7 @@ public String getName()
103103
*
104104
* @return The task
105105
*/
106-
public IReobfuscator getTask()
106+
public TaskSingleReobf getTask()
107107
{
108108
return reobf;
109109
}
@@ -118,14 +118,14 @@ public boolean equals(Object obj)
118118
return false;
119119
}
120120

121-
public Object getMappings()
121+
public File getMappings()
122122
{
123-
return reobf.getMappings();
123+
return reobf.getPrimarySrg();
124124
}
125125

126126
public void setMappings(Object srg)
127127
{
128-
reobf.setMappings(srg);
128+
reobf.setPrimarySrg(srg);
129129
}
130130

131131
public void setClasspath(FileCollection classpath)
@@ -137,35 +137,74 @@ public FileCollection getClasspath()
137137
{
138138
return reobf.getClasspath();
139139
}
140+
141+
@Override
142+
public void setExtraLines(List<Object> extra)
143+
{
144+
reobf.getExtraSrgLines().clear();
145+
extraLines(extra);
146+
}
140147

141-
public List<Object> getExtra()
148+
@Override
149+
public List<Object> getExtraLines()
142150
{
143-
return reobf.getExtra();
151+
List<Object> list = Lists.newArrayList();
152+
list.addAll(reobf.getExtraSrgLines());
153+
return list;
154+
}
155+
156+
@Override
157+
public void extraLines(Iterable<Object> o)
158+
{
159+
for (Object obj : o)
160+
{
161+
reobf.addExtraSrgLine(Constants.resolveString(obj));
162+
}
144163
}
145164

146-
public void setExtra(List<Object> extra)
165+
@Override
166+
public void extraLines(Object... o)
147167
{
148-
reobf.setExtra(extra);
168+
for (Object obj : o)
169+
{
170+
reobf.addExtraSrgLine(Constants.resolveString(obj));
171+
}
149172
}
150173

151-
public void extra(Object... o)
174+
@Override
175+
public List<Object> getExtraFiles()
152176
{
153-
reobf.extra(o);
177+
List<Object> list = Lists.newArrayList();
178+
list.addAll(reobf.getSecondarySrgFiles().getFiles());
179+
return list;
154180
}
155181

156-
public void extra(Collection<Object> o)
182+
@Override
183+
public void extraFiles(Iterable<Object> o)
157184
{
158-
reobf.extra(o);
185+
for (Object obj : o)
186+
{
187+
reobf.addSecondarySrgFile(obj);
188+
}
159189
}
160190

191+
@Override
192+
public void extraFiles(Object... o)
193+
{
194+
for (Object obj : o)
195+
{
196+
reobf.addSecondarySrgFile(obj);
197+
}
198+
}
199+
161200
public void useSrgSrg()
162201
{
163-
reobf.useSrgSrg();
202+
reobf.setPrimarySrg(Constants.SRG_MCP_TO_SRG);
164203
}
165204

166205
public void useNotchSrg()
167206
{
168-
reobf.useNotchSrg();
207+
reobf.setPrimarySrg(Constants.SRG_MCP_TO_NOTCH);
169208
}
170209
}
171210
}

src/main/java/net/minecraftforge/gradle/user/TaskSingleReobf.java

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.google.common.io.Files;
4646

4747
import groovy.lang.Closure;
48-
import groovy.lang.GString;
4948
import net.md_5.specialsource.Jar;
5049
import net.md_5.specialsource.JarMapping;
5150
import net.md_5.specialsource.JarRemapper;
@@ -54,7 +53,6 @@
5453
import net.md_5.specialsource.provider.JointProvider;
5554
import net.minecraftforge.gradle.common.Constants;
5655
import net.minecraftforge.gradle.util.GradleConfigurationException;
57-
import net.minecraftforge.gradle.util.delayed.DelayedFile;
5856
import net.minecraftforge.gradle.util.mcp.ReobfExceptor;
5957

6058
/**
@@ -97,9 +95,8 @@
9795
*
9896
*/
9997
@ParallelizableTask
100-
public class TaskSingleReobf extends DefaultTask implements IReobfuscator
98+
public class TaskSingleReobf extends DefaultTask
10199
{
102-
103100
private Object jar;
104101
private FileCollection classpath;
105102

@@ -192,7 +189,7 @@ public void doTask() throws IOException
192189
// obfuscate
193190
File obfuscated = File.createTempFile("obfuscated", ".jar", getTemporaryDir());
194191
obfuscated.deleteOnExit();
195-
applySpecialSource(tempIn, obfuscated, srg, srgLines, getExtraSrgFiles());
192+
applySpecialSource(tempIn, obfuscated, srg, srgLines, getSecondarySrgFiles());
196193

197194
// post transform
198195
transformers = getPostTransformers();
@@ -308,71 +305,6 @@ public File getPrimarySrg()
308305
return getProject().file(primarySrg);
309306
}
310307

311-
@Override
312-
public void setMappings(Object srg)
313-
{
314-
setPrimarySrg(srg);
315-
}
316-
317-
@Override
318-
public Object getMappings()
319-
{
320-
return getPrimarySrg();
321-
}
322-
323-
public void useSrgSrg()
324-
{
325-
setMappings(Constants.SRG_MCP_TO_SRG);
326-
}
327-
328-
public void useNotchSrg()
329-
{
330-
setMappings(Constants.SRG_MCP_TO_NOTCH);
331-
}
332-
333-
@Override
334-
public void setExtra(List<Object> extra)
335-
{
336-
secondarySrgFiles.clear();
337-
extraSrgLines.clear();
338-
extra(extra);
339-
}
340-
341-
@Override
342-
public List<Object> getExtra()
343-
{
344-
List<Object> list = Lists.newArrayList();
345-
list.addAll(secondarySrgFiles);
346-
list.addAll(extraSrgLines);
347-
return list;
348-
}
349-
350-
@Override
351-
public void extra(Collection<Object> o)
352-
{
353-
for (Object obj : o)
354-
{
355-
if (obj instanceof String || obj instanceof GString)
356-
{
357-
addExtraSrgLine(obj.toString());
358-
}
359-
else if (obj instanceof File || obj instanceof DelayedFile)
360-
{
361-
addSecondarySrgFile(obj);
362-
}
363-
else
364-
{
365-
throw new IllegalArgumentException("Extra srgs must be a file or string. Found " + o.getClass());
366-
}
367-
}
368-
}
369-
370-
@Override
371-
public void extra(Object... o)
372-
{
373-
extra(Lists.newArrayList(o));
374-
}
375-
376308
public void setPrimarySrg(Object srg)
377309
{
378310
this.primarySrg = srg;
@@ -383,7 +315,7 @@ public void addSecondarySrgFile(Object thing)
383315
secondarySrgFiles.add(thing);
384316
}
385317

386-
public FileCollection getExtraSrgFiles()
318+
public FileCollection getSecondarySrgFiles()
387319
{
388320
List<File> files = new ArrayList<File>(secondarySrgFiles.size());
389321

src/main/java/net/minecraftforge/gradle/user/UserBasePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ protected void setupReobf(TaskSingleReobf reobf)
283283
reobf.setFieldCsv(delayedFile(CSV_FIELD));
284284
reobf.setMethodCsv(delayedFile(CSV_METHOD));
285285

286-
reobf.useNotchSrg();
286+
reobf.setPrimarySrg(delayedFile(SRG_MCP_TO_NOTCH));
287287
JavaPluginConvention java = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
288288
reobf.setClasspath(java.getSourceSets().getByName("main").getCompileClasspath());
289289
}

src/main/java/net/minecraftforge/gradle/user/patcherUser/forge/ForgePlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package net.minecraftforge.gradle.user.patcherUser.forge;
2121

2222
import static net.minecraftforge.gradle.common.Constants.REPLACE_MC_VERSION;
23+
import static net.minecraftforge.gradle.common.Constants.SRG_MCP_TO_SRG;
2324
import static net.minecraftforge.gradle.user.UserConstants.TASK_REOBF;
2425

2526
import java.io.File;
@@ -121,7 +122,7 @@ public void execute(Object arg0)
121122
protected void setupReobf(TaskSingleReobf reobf)
122123
{
123124
super.setupReobf(reobf);
124-
reobf.useSrgSrg();
125+
reobf.setPrimarySrg(delayedFile(SRG_MCP_TO_SRG));
125126
}
126127

127128
@Override

0 commit comments

Comments
 (0)