Skip to content

Commit eed8c6b

Browse files
authored
Merge pull request #511 from MinecraftModDevelopment/fg_2.1-gradle3fix
Fixes Gradle 3.0 through 4.4.1 with FG2.1
2 parents 160af89 + d319347 commit eed8c6b

22 files changed

+143
-122
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ dependencies {
9191
//Stuff used in the GradleStart classes
9292
compileOnly 'com.mojang:authlib:1.5.16'
9393
compileOnly "net.minecraft:launchwrapper:1.11"
94+
95+
testCompile 'junit:junit:4.12'
96+
}
97+
98+
task wrapper(type: Wrapper) {
99+
gradleVersion = '2.14'
94100
}
95101

96102
sourceSets {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Mar 28 14:11:55 CDT 2016
1+
#Sat Aug 20 15:56:50 PDT 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip

src/main/java/edu/sc/seis/launch4j/Launch4jPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private Task addCopyToLibTask()
137137
task.setGroup(LAUNCH4J_GROUP);
138138
// more stuff with the java plugin
139139
//task.with(configureDistSpec(project));
140-
task.into(new Closure<File>(null)
140+
task.into(new Closure<File>(Launch4jPlugin.class)
141141
{
142142
@Override
143143
public File call(Object... obj)
@@ -180,7 +180,7 @@ private Task addLaunch4jTask()
180180
@SuppressWarnings({ "serial", "unused" })
181181
private static CopySpec configureDistSpec(Project project)
182182
{
183-
CopySpec distSpec = project.copySpec(new Closure<Object>(null) {});
183+
CopySpec distSpec = project.copySpec(new Closure<Object>(Launch4jPlugin.class) {});
184184
Jar jar = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
185185

186186
distSpec.from(jar);

src/main/java/net/minecraftforge/gradle/common/BasePlugin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private void makeCommonTasks()
354354
{
355355
EtagDownloadTask getVersionJson = makeTask(TASK_DL_VERSION_JSON, EtagDownloadTask.class);
356356
{
357-
getVersionJson.setUrl(new Closure<String>(null, null) {
357+
getVersionJson.setUrl(new Closure<String>(BasePlugin.class) {
358358
@Override
359359
public String call()
360360
{
@@ -363,7 +363,7 @@ public String call()
363363
});
364364
getVersionJson.setFile(delayedFile(JSON_VERSION));
365365
getVersionJson.setDieWithError(false);
366-
getVersionJson.doLast(new Closure<Boolean>(project) // normalizes to linux endings
366+
getVersionJson.doLast(new Closure<Boolean>(BasePlugin.class) // normalizes to linux endings
367367
{
368368
@Override
369369
public Boolean call()
@@ -409,7 +409,7 @@ public Boolean call()
409409

410410
EtagDownloadTask getAssetsIndex = makeTask(TASK_DL_ASSET_INDEX, EtagDownloadTask.class);
411411
{
412-
getAssetsIndex.setUrl(new Closure<String>(null, null) {
412+
getAssetsIndex.setUrl(new Closure<String>(BasePlugin.class) {
413413
@Override
414414
public String call()
415415
{
@@ -431,7 +431,7 @@ public String call()
431431
Download dlClient = makeTask(TASK_DL_CLIENT, Download.class);
432432
{
433433
dlClient.setOutput(delayedFile(JAR_CLIENT_FRESH));
434-
dlClient.setUrl(new Closure<String>(null, null) {
434+
dlClient.setUrl(new Closure<String>(BasePlugin.class) {
435435
@Override
436436
public String call()
437437
{
@@ -445,7 +445,7 @@ public String call()
445445
Download dlServer = makeTask(TASK_DL_SERVER, Download.class);
446446
{
447447
dlServer.setOutput(delayedFile(JAR_SERVER_FRESH));
448-
dlServer.setUrl(new Closure<String>(null, null) {
448+
dlServer.setUrl(new Closure<String>(BasePlugin.class) {
449449
@Override
450450
public String call()
451451
{
@@ -805,7 +805,7 @@ public TokenReplacer load(String key)
805805
new CacheLoader<String, DelayedString>() {
806806
public DelayedString load(String key)
807807
{
808-
return new DelayedString(replacerCache.getUnchecked(key));
808+
return new DelayedString(CacheLoader.class, replacerCache.getUnchecked(key));
809809
}
810810
});
811811
private LoadingCache<String, DelayedFile> fileCache = CacheBuilder.newBuilder()
@@ -814,7 +814,7 @@ public DelayedString load(String key)
814814
new CacheLoader<String, DelayedFile>() {
815815
public DelayedFile load(String key)
816816
{
817-
return new DelayedFile(project, replacerCache.getUnchecked(key));
817+
return new DelayedFile(CacheLoader.class, project, replacerCache.getUnchecked(key));
818818
}
819819
});
820820

@@ -830,7 +830,7 @@ public DelayedFile delayedFile(String path)
830830

831831
public DelayedFileTree delayedTree(String path)
832832
{
833-
return new DelayedFileTree(project, replacerCache.getUnchecked(path));
833+
return new DelayedFileTree(BasePlugin.class, project, replacerCache.getUnchecked(path));
834834
}
835835

836836
protected File cacheFile(String path)

src/main/java/net/minecraftforge/gradle/common/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public String toString()
8787
public static final String GROUP_FG = "ForgeGradle";
8888

8989
@SuppressWarnings("serial")
90-
public static final Closure<Boolean> CALL_FALSE = new Closure<Boolean>(null) {
90+
public static final Closure<Boolean> CALL_FALSE = new Closure<Boolean>(Constants.class) {
9191
public Boolean call(Object o)
9292
{
9393
return false;

src/main/java/net/minecraftforge/gradle/patcher/PatcherExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void setWorkspaceDir(Object workspaceDir)
124124
@SuppressWarnings("serial")
125125
protected Closure<File> getDelayedWorkspaceDir()
126126
{
127-
return new Closure<File>(null) {
127+
return new Closure<File>(PatcherExtension.class) {
128128
public File call()
129129
{
130130
return getWorkspaceDir();
@@ -135,7 +135,7 @@ public File call()
135135
@SuppressWarnings("serial")
136136
protected Closure<File> getDelayedSubWorkspaceDir(final String path)
137137
{
138-
return new Closure<File>(null) {
138+
return new Closure<File>(PatcherExtension.class) {
139139
public File call()
140140
{
141141
return new File(getWorkspaceDir(), path);
@@ -146,7 +146,7 @@ public File call()
146146
@SuppressWarnings("serial")
147147
protected Closure<File> getDelayedVersionJson()
148148
{
149-
return new Closure<File>(null) {
149+
return new Closure<File>(PatcherExtension.class) {
150150
public File call()
151151
{
152152
return getVersionJson();

src/main/java/net/minecraftforge/gradle/patcher/PatcherPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ protected void makePackagingTasks()
238238
Zip installer = makeTask(TASK_BUILD_INSTALLER, Zip.class);
239239
{
240240
installer.from(outputJar);
241-
installer.from(delayedTree(JAR_INSTALLER), new CopyInto("", "!*.json", "!*.png"));
241+
installer.from(delayedTree(JAR_INSTALLER), new CopyInto(PatcherPlugin.class, "", "!*.json", "!*.png"));
242242
installer.from(delayedTree(JSON_INSTALLER));
243243
installer.setBaseName(project.getName());
244244
installer.setClassifier("installer");

src/main/java/net/minecraftforge/gradle/patcher/PatcherProject.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public void setApplyMcpPatches(boolean applyMcpPatches)
543543
@SuppressWarnings("serial")
544544
protected Closure<String> getDelayedMainClassClient()
545545
{
546-
return new Closure<String>(project, this) {
546+
return new Closure<String>(PatcherProject.class) {
547547
public String call()
548548
{
549549
return getMainClassClient();
@@ -554,7 +554,7 @@ public String call()
554554
@SuppressWarnings("serial")
555555
protected Closure<String> getDelayedTweakClassClient()
556556
{
557-
return new Closure<String>(project, this) {
557+
return new Closure<String>(PatcherProject.class) {
558558
public String call()
559559
{
560560
return getTweakClassClient();
@@ -565,7 +565,7 @@ public String call()
565565
@SuppressWarnings("serial")
566566
protected Closure<String> getDelayedRunArgsClient()
567567
{
568-
return new Closure<String>(project, this) {
568+
return new Closure<String>(PatcherProject.class) {
569569
public String call()
570570
{
571571
return getRunArgsClient();
@@ -576,7 +576,7 @@ public String call()
576576
@SuppressWarnings("serial")
577577
protected Closure<String> getDelayedMainClassServer()
578578
{
579-
return new Closure<String>(project, this) {
579+
return new Closure<String>(PatcherProject.class) {
580580
public String call()
581581
{
582582
return getMainClassServer();
@@ -587,7 +587,7 @@ public String call()
587587
@SuppressWarnings("serial")
588588
protected Closure<String> getDelayedTweakClassServer()
589589
{
590-
return new Closure<String>(project, this) {
590+
return new Closure<String>(PatcherProject.class) {
591591
public String call()
592592
{
593593
return getTweakClassServer();
@@ -598,7 +598,7 @@ public String call()
598598
@SuppressWarnings("serial")
599599
protected Closure<String> getDelayedRunArgsServer()
600600
{
601-
return new Closure<String>(project, this) {
601+
return new Closure<String>(PatcherProject.class) {
602602
public String call()
603603
{
604604
return getRunArgsServer();
@@ -609,7 +609,7 @@ public String call()
609609
@SuppressWarnings("serial")
610610
protected Closure<File> getDelayedSourcesDir()
611611
{
612-
return new Closure<File>(project, this) {
612+
return new Closure<File>(PatcherProject.class) {
613613
public File call()
614614
{
615615
return getSourcesDir();
@@ -620,7 +620,7 @@ public File call()
620620
@SuppressWarnings("serial")
621621
protected Closure<File> getDelayedResourcesDir()
622622
{
623-
return new Closure<File>(project, this) {
623+
return new Closure<File>(PatcherProject.class) {
624624
public File call()
625625
{
626626
return getResourcesDir();
@@ -631,7 +631,7 @@ public File call()
631631
@SuppressWarnings("serial")
632632
protected Closure<File> getDelayedTestSourcesDir()
633633
{
634-
return new Closure<File>(project, this) {
634+
return new Closure<File>(PatcherProject.class) {
635635
public File call()
636636
{
637637
return getTestSourcesDir();
@@ -642,7 +642,7 @@ public File call()
642642
@SuppressWarnings("serial")
643643
protected Closure<File> getDelayedTestResourcesDir()
644644
{
645-
return new Closure<File>(project, this) {
645+
return new Closure<File>(PatcherProject.class) {
646646
public File call()
647647
{
648648
return getTestResourcesDir();
@@ -653,7 +653,7 @@ public File call()
653653
@SuppressWarnings("serial")
654654
protected Closure<File> getDelayedPatchDir()
655655
{
656-
return new Closure<File>(project, this) {
656+
return new Closure<File>(PatcherProject.class) {
657657
public File call()
658658
{
659659
return getPatchDir();

src/main/java/net/minecraftforge/gradle/tasks/CreateStartTask.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@
3333
import net.minecraftforge.gradle.util.caching.Cached;
3434
import net.minecraftforge.gradle.util.caching.CachedTask;
3535

36+
import org.gradle.api.AntBuilder;
37+
import org.gradle.api.Task;
38+
import org.gradle.api.AntBuilder.AntMessagePriority;
3639
import org.gradle.api.file.FileCollection;
3740
import org.gradle.api.file.FileVisitDetails;
3841
import org.gradle.api.file.FileVisitor;
39-
import org.gradle.api.logging.LoggingManager;
4042
import org.gradle.api.logging.LogLevel;
43+
import org.gradle.api.logging.LoggingManager;
4144
import org.gradle.api.tasks.Input;
4245
import org.gradle.api.tasks.OutputDirectory;
4346
import org.gradle.api.tasks.TaskAction;
47+
import org.gradle.util.GradleVersion;
4448

4549
import com.google.common.base.Charsets;
4650
import com.google.common.base.Joiner;
@@ -92,7 +96,7 @@ public void doStuff() throws IOException
9296
{
9397
out = out.replace(replacement.getKey(), (String) replacement.getValue());
9498
}
95-
99+
96100
// replace extra lines
97101
if (!extraLines.isEmpty())
98102
{
@@ -124,14 +128,9 @@ public void doStuff() throws IOException
124128
col = col.plus(config);
125129
}
126130

127-
// Remove errors on normal runs
128-
LoggingManager log = getLogging();
129-
LogLevel startLevel = getProject().getGradle().getStartParameter().getLogLevel();
130-
if (startLevel.compareTo(LogLevel.LIFECYCLE) >= 0) {
131-
log.setLevel(LogLevel.ERROR);
132-
}
131+
AntBuilder ant = CreateStartTask.setupAnt(this);
133132
// INVOKE!
134-
this.getAnt().invokeMethod("javac", ImmutableMap.builder()
133+
ant.invokeMethod("javac", ImmutableMap.builder()
135134
.put("srcDir", resourceDir.getCanonicalPath())
136135
.put("destDir", compiled.getCanonicalPath())
137136
.put("failonerror", true)
@@ -142,7 +141,7 @@ public void doStuff() throws IOException
142141
.put("target", "1.6")
143142
.put("debug", "true")
144143
.build());
145-
144+
146145
// copy the sources too, for debugging through GradleStart
147146
getProject().fileTree(resourceDir).visit(new FileVisitor() {
148147

@@ -157,18 +156,42 @@ public void visitFile(FileVisitDetails arg0)
157156
{
158157
arg0.copyTo(arg0.getRelativePath().getFile(compiled));
159158
}
160-
159+
161160
});
162161
}
163162

164163
}
165164

165+
public static AntBuilder setupAnt(Task task)
166+
{
167+
AntBuilder ant = task.getAnt();
168+
LogLevel startLevel = task.getProject().getGradle().getStartParameter().getLogLevel();
169+
if (startLevel.compareTo(LogLevel.LIFECYCLE) >= 0)
170+
{
171+
GradleVersion v2_14 = GradleVersion.version("2.14");
172+
if (GradleVersion.current().compareTo(v2_14) >= 0)
173+
{
174+
ant.setLifecycleLogLevel(AntMessagePriority.ERROR);
175+
}
176+
else
177+
{
178+
try {
179+
LoggingManager.class.getMethod("setLevel", LogLevel.class).invoke(task.getLogging(), LogLevel.ERROR);
180+
} catch (Exception e) {
181+
//Couldn't find it? We are on some weird version oh well.
182+
task.getLogger().info("Could not set log level:", e);
183+
}
184+
}
185+
}
186+
return ant;
187+
}
188+
166189
@SuppressWarnings("rawtypes")
167190
private String resolveString(Object obj) throws IOException
168191
{
169192
if (obj == null)
170193
return null;
171-
194+
172195
if (obj instanceof Closure)
173196
return resolveString(((Closure) obj).call());
174197
else if (obj instanceof File)

src/main/java/net/minecraftforge/gradle/tasks/DeobfuscateJar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public void setOutJar(Object outJar)
439439
@SuppressWarnings("serial")
440440
public Closure<File> getDelayedOutput()
441441
{
442-
return new Closure<File>(getProject(), this) {
442+
return new Closure<File>(DeobfuscateJar.class) {
443443
public File call()
444444
{
445445
return getOutJar();

0 commit comments

Comments
 (0)