Skip to content

Commit d1f219e

Browse files
committed
Update gradle wrapper to 2.14 and reflectively call deprecated/removed setLogLevel for older versions.
1 parent 7fe75e3 commit d1f219e

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ dependencies {
9595
testCompile 'junit:junit:4.12'
9696
}
9797

98+
task wrapper(type: Wrapper) {
99+
gradleVersion = '2.14'
100+
}
101+
98102
sourceSets {
99103
main.compileClasspath += configurations.shade;
100104
main.runtimeClasspath += configurations.shade;
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/net/minecraftforge/gradle/tasks/CreateStartTask.java

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
import org.gradle.api.file.FileVisitDetails;
4040
import org.gradle.api.file.FileVisitor;
4141
import org.gradle.api.logging.LogLevel;
42+
import org.gradle.api.logging.LoggingManager;
4243
import org.gradle.api.tasks.Input;
4344
import org.gradle.api.tasks.OutputDirectory;
4445
import org.gradle.api.tasks.TaskAction;
46+
import org.gradle.util.GradleVersion;
4547

4648
import com.google.common.base.Charsets;
4749
import com.google.common.base.Joiner;
@@ -93,7 +95,7 @@ public void doStuff() throws IOException
9395
{
9496
out = out.replace(replacement.getKey(), (String) replacement.getValue());
9597
}
96-
98+
9799
// replace extra lines
98100
if (!extraLines.isEmpty())
99101
{
@@ -125,12 +127,7 @@ public void doStuff() throws IOException
125127
col = col.plus(config);
126128
}
127129

128-
AntBuilder ant = this.getAnt();
129-
// Remove errors on normal runs
130-
LogLevel startLevel = getProject().getGradle().getStartParameter().getLogLevel();
131-
if (startLevel.compareTo(LogLevel.LIFECYCLE) >= 0) {
132-
ant.setLifecycleLogLevel(AntMessagePriority.ERROR);
133-
}
130+
AntBuilder ant = this.setupAnt();
134131
// INVOKE!
135132
ant.invokeMethod("javac", ImmutableMap.builder()
136133
.put("srcDir", resourceDir.getCanonicalPath())
@@ -143,7 +140,7 @@ public void doStuff() throws IOException
143140
.put("target", "1.6")
144141
.put("debug", "true")
145142
.build());
146-
143+
147144
// copy the sources too, for debugging through GradleStart
148145
getProject().fileTree(resourceDir).visit(new FileVisitor() {
149146

@@ -158,18 +155,42 @@ public void visitFile(FileVisitDetails arg0)
158155
{
159156
arg0.copyTo(arg0.getRelativePath().getFile(compiled));
160157
}
161-
158+
162159
});
163160
}
164161

165162
}
166163

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

0 commit comments

Comments
 (0)