2121
2222import static net .minecraftforge .gradle .common .Constants .TASK_GENERATE_SRGS ;
2323
24+ import java .io .File ;
2425import java .util .Collection ;
2526import java .util .List ;
2627
28+ import org .gradle .api .Action ;
2729import org .gradle .api .NamedDomainObjectFactory ;
30+ import org .gradle .api .Project ;
2831import org .gradle .api .Task ;
2932import org .gradle .api .file .FileCollection ;
3033import org .gradle .api .tasks .bundling .Jar ;
3134
35+ import groovy .lang .Closure ;
3236import net .minecraftforge .gradle .util .GradleConfigurationException ;
3337
3438public class ReobfTaskFactory implements NamedDomainObjectFactory <IReobfuscator >
@@ -40,27 +44,39 @@ public ReobfTaskFactory(UserBasePlugin<?> plugin)
4044 this .plugin = plugin ;
4145 }
4246
47+ @ SuppressWarnings ("serial" )
4348 @ Override
44- public IReobfuscator create (String jarName )
49+ public IReobfuscator create (final String jarName )
4550 {
46- Task jar = plugin .project .getTasks ().getByName (jarName );
47-
48- if (!(jar instanceof Jar ))
49- {
50- throw new GradleConfigurationException (jarName + " is not a jar task. Can only reobf jars!" );
51- }
5251 String name = "reobf" + Character .toUpperCase (jarName .charAt (0 )) + jarName .substring (1 );
53- TaskSingleReobf task = plugin .maybeMakeTask (name , TaskSingleReobf .class );
54-
55- task .setJar (((Jar ) jar ).getArchivePath ());
52+ final TaskSingleReobf task = plugin .maybeMakeTask (name , TaskSingleReobf .class );
5653
57- task .dependsOn (TASK_GENERATE_SRGS , jar );
54+ task .dependsOn (TASK_GENERATE_SRGS , jarName );
5855 task .mustRunAfter ("test" );
56+
57+ task .setJar (new Closure <File >(null ) {
58+ public File call ()
59+ {
60+ return ((Jar ) plugin .project .getTasks ().getByName (jarName )).getArchivePath ();
61+ }
62+ });
5963
60- plugin .project .getTasks ().getByName ("build" ).dependsOn (task );
6164 plugin .project .getTasks ().getByName ("assemble" ).dependsOn (task );
6265
6366 plugin .setupReobf (task );
67+
68+ // do after-Evaluate resolution, for the same of good error reporting
69+ plugin .project .afterEvaluate (new Action <Project >() {
70+ @ Override
71+ public void execute (Project arg0 )
72+ {
73+ Task jar = plugin .project .getTasks ().getByName (jarName );
74+ if (!(jar instanceof Jar ))
75+ {
76+ throw new GradleConfigurationException (jarName + " is not a jar task. Can only reobf jars!" );
77+ }
78+ }
79+ });
6480
6581 return new TaskWrapper (jarName , task );
6682 }
0 commit comments