Skip to content

Commit 6f66543

Browse files
LexManostterrag1098
authored andcommitted
Strip out usage of raw 'json' file from Forge's server.
This should of been removed years ago, but nobody ever did it. Forge version must be specified in full string format.
1 parent eed8c6b commit 6f66543

File tree

9 files changed

+67
-525
lines changed

9 files changed

+67
-525
lines changed

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

Lines changed: 57 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
import net.minecraftforge.gradle.user.UserBaseExtension;
3232
import net.minecraftforge.gradle.user.UserBasePlugin;
3333
import net.minecraftforge.gradle.util.GradleConfigurationException;
34-
import net.minecraftforge.gradle.util.json.forgeversion.ForgeBuild;
35-
import net.minecraftforge.gradle.util.json.forgeversion.ForgeVersion;
3634

3735
public class ForgeExtension extends UserBaseExtension
3836
{
39-
protected ForgeVersion forgeJson;
4037
private String forgeVersion;
4138
private String coreMod = null;
4239

@@ -92,7 +89,7 @@ public void setVersion(String inVersion)
9289

9390
// ----------------------------------------
9491
// Code to check the forge version and stuff
95-
// ----------------------------------------
92+
// ----------------------------------------
9693

9794
private static final String JUST_MC = "(\\d+\\.\\d+(?:\\.\\d+)?[_pre\\d]*)";
9895
private static final String JUST_API = "((?:\\d+\\.){3}(\\d+))((?:-[\\w\\.]+)?)";
@@ -103,183 +100,63 @@ public void setVersion(String inVersion)
103100
private void checkAndSetVersion(String str)
104101
{
105102
str = str.trim();
106-
107-
// build number
108-
if (isAllNums(str))
109-
{
110-
boolean worked = getFromBuildNumber(str);
111-
if (worked)
112-
return;
113-
}
114-
115-
// promotions
116-
if (this.forgeJson != null && this.forgeJson.promos != null && this.forgeJson.promos.containsKey(str))
117-
{
118-
boolean worked = getFromBuildNumber(this.forgeJson.promos.get(str));
119-
LOGGER.lifecycle("Selected version " + this.forgeVersion);
120-
if (worked)
121-
return;
122-
}
123-
124-
// matches just an API version
125-
Matcher matcher = API.matcher(str);
126-
if (matcher.matches())
127-
{
128-
String branch = Strings.emptyToNull(matcher.group(3));
129-
String forgeVersion = matcher.group(1);
130-
131-
try
132-
{
133-
ForgeBuild build = this.forgeJson.number.get(Integer.valueOf(matcher.group(2)));
134-
135-
if (build == null)
136-
{
137-
throw new GradleConfigurationException("No such version exists!");
138-
}
139-
140-
boolean branchMatches = false;
141-
if (branch == null)
142-
branchMatches = Strings.isNullOrEmpty(build.branch);
143-
else
144-
branchMatches = branch.substring(1).equals(build.branch);
145-
146-
String outBranch = build.branch;
147-
if (outBranch == null)
148-
outBranch = "";
149-
else
150-
outBranch = "-" + build.branch;
151-
152-
if (!build.version.equals(forgeVersion) || !branchMatches)
153-
{
154-
throw new GradleConfigurationException(str + " is an invalid version! did you mean '" + build.version + outBranch + "' ?");
155-
}
156-
157-
version = build.mcversion.replace("_", "-");
158-
this.forgeVersion = build.version;
159-
if (!Strings.isNullOrEmpty(build.branch) && !"null".equals(build.branch))
160-
this.forgeVersion += outBranch;
161-
162-
}
163-
catch (GradleConfigurationException e)
164-
{
165-
throw e;
166-
}
167-
catch (Exception e)// everythng but the gradle exception
168-
{
169-
System.out.println("Error occurred parsing version!");
170-
171-
version = "1.8";// just gonna guess.. since we dont know..
172-
this.forgeVersion = forgeVersion;
173-
if (!Strings.isNullOrEmpty(branch) && !"null".equals(branch))
174-
this.forgeVersion += branch;
175-
}
176-
177-
return;
178-
}
179-
180-
// matches standard form.
181-
matcher = STANDARD.matcher(str);
182-
if (matcher.matches())
183-
{
184-
String branch = matcher.group(4);
185-
String mcversion = matcher.group(1);
186-
187-
String forgeVersion = matcher.group(2);
188-
String buildNumber = matcher.group(3);
189-
190-
try
191-
{
192-
if ("0".equals(buildNumber))
193-
{
194-
LOGGER.lifecycle("Assuming custom forge version!");
195-
version = mcversion;
196-
this.forgeVersion = forgeVersion + branch;
197-
return;
198-
}
199-
200-
ForgeBuild build = this.forgeJson.number.get(Integer.parseInt(buildNumber));
201-
202-
if (build == null)
203-
{
204-
throw new GradleConfigurationException("No such version exists!");
205-
}
206-
207-
boolean branchMatches = false;
208-
if (Strings.isNullOrEmpty(branch))
209-
branchMatches = Strings.isNullOrEmpty(build.branch);
210-
else
211-
branchMatches = branch.substring(1).equals(build.branch);
212-
213-
boolean mcMatches = build.mcversion.equals(mcversion);
214-
215-
String outBranch = build.branch;
216-
if (outBranch == null)
217-
outBranch = "";
218-
else
219-
outBranch = "-" + build.branch;
220-
221-
if (!build.version.equals(forgeVersion) || !branchMatches || !mcMatches)
222-
{
223-
throw new GradleConfigurationException(str + " is an invalid version! did you mean '" + build.mcversion + "-" + build.version + outBranch + "' ?");
224-
}
225-
226-
version = build.mcversion.replace("_", "-");
227-
this.forgeVersion = build.version;
228-
if (!Strings.isNullOrEmpty(build.branch) && !"null".equals(build.branch))
229-
this.forgeVersion += outBranch;
230-
}
231-
catch (GradleConfigurationException e)
232-
{
233-
throw e;
234-
}
235-
catch (Exception e)// everythng but the gradle exception
236-
{
237-
System.out.println("Error occurred parsing version!");
238-
239-
version = mcversion;
240-
this.forgeVersion = forgeVersion;
241-
if (!Strings.isNullOrEmpty(branch) && !"null".equals(branch))
242-
this.forgeVersion += branch;
243-
}
244-
245-
return;
246-
}
247-
248-
throw new GradleConfigurationException("Invalid version notation, or version doesnt exist! The following are valid notations. Buildnumber, version, version-branch, mcversion-version-branch, and pomotion");
103+
int idx = str.indexOf('-');
104+
if (idx == -1)
105+
throw new IllegalArgumentException("You must specify the full forge version, including MC version in your build.gradle. Example: 1.12.2-14.23.5.2811");
106+
this.version = str.substring(0, idx); //MC Version
107+
this.forgeVersion = str.substring(idx + 1);
108+
109+
/*
110+
* Old FG used to use a horribly outdated MASSIVE json file for trying to be 'smart' when processing the version information.
111+
* It tried to allow for many 'shortcuts' when specifying the Forge version.
112+
* All of this are horribly and stupid, and should of never existed in the first place.
113+
* So I'm gutting them.
114+
*
115+
* But will document them here to the best of my understanding, so that if people need them we can re-implement them in less horribly hacky ways.
116+
*
117+
* JUST the build number:
118+
* Prior to 1.13, Forge used a unique build number to identify all versions. So in theory you could pick an exact build with just the build number.
119+
* Example:
120+
* Input: 2815
121+
* Output: 1.12.2-14.23.5.2815
122+
* Solution:
123+
* Download maven-metadata.xml, loop through all versions doing:
124+
* key = ver.split('-')[0].rsplit('.', 1)[1]
125+
* if (!map.containsKey(key)) //This is important because metadata is ordered oldest to newest, and new versions could duplicate the build number
126+
* map.put(key, ver)
127+
*
128+
*
129+
* Promotion Name:
130+
* We publish 'promoted' builds of Forge. Typically 'latest' and 'recommended'. Simple enough way to make a auto updating version.
131+
* Example:
132+
* Input: 1.8-recommended
133+
* Output: 1.8-11.14.4.1563
134+
* Solution:
135+
* Again, Abrar downloaded a 2MB MASSIVE json file, when a slim json would do.
136+
* https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json
137+
*
138+
*
139+
* API-Wildcards:
140+
* Abrar tried to emulate dynamic versions which would be introduced into gradle far afterwords.
141+
* Example:
142+
* Input: 14.23.5.1
143+
* Output: 1.12.2-14.23.5.2811
144+
* Solution:
145+
* Again, can be solved using maven-metadata.xml, use Apache's ArtifactVersion library to parse out a easy comparable version for everything in the metadata, and the version the user input.
146+
* Set MinVersion = ArtifactVersion(input)
147+
* prefix = input.substring(0, input.lastIndexOf('.'))
148+
* MaxVersion = ArtifactVersion(prefix.rsplit('.', 1)[0] + '.' + (int(prefix.rsplit('.', 1)[1]) + 1))
149+
*
150+
* Then find the max version that fits: MinVersion <= Version < MaxVersion
151+
*
152+
* Full Version:
153+
* Example:
154+
* Input: 1.12.2-14.23.5.2811
155+
* Output: 1.12.2-14.23.5.2811
156+
*
157+
* This was just used to verify the version existed. This can be done via maven-metadata.xml
158+
*/
249159
}
250-
251-
private boolean isAllNums(String in)
252-
{
253-
for (char c : in.toCharArray())
254-
{
255-
if (!Character.isDigit(c))
256-
return false;
257-
}
258-
259-
return true;
260-
}
261-
262-
private boolean getFromBuildNumber(String str)
263-
{
264-
return getFromBuildNumber(Integer.valueOf(str));
265-
}
266-
267-
private boolean getFromBuildNumber(Integer num)
268-
{
269-
ForgeBuild build = this.forgeJson.number.get(num);
270-
if (build != null)
271-
{
272-
version = build.mcversion.replace("_", "-");
273-
this.forgeVersion = build.version;
274-
if (!Strings.isNullOrEmpty(build.branch) && !"null".equals(build.branch))
275-
this.forgeVersion += "-" + build.branch;
276-
277-
return true;
278-
}
279-
else
280-
return false;
281-
}
282-
283160
/**
284161
* Get the coremod class for the mod
285162
*

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

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import org.gradle.api.tasks.bundling.Jar;
3232

3333
import com.google.common.base.Strings;
34-
import com.google.gson.JsonSyntaxException;
35-
3634
import net.minecraftforge.gradle.common.Constants;
3735
import net.minecraftforge.gradle.tasks.CreateStartTask;
3836
import net.minecraftforge.gradle.user.ReobfMappingType;
@@ -41,28 +39,23 @@
4139
import net.minecraftforge.gradle.user.UserConstants;
4240
import net.minecraftforge.gradle.user.patcherUser.PatcherUserBasePlugin;
4341
import net.minecraftforge.gradle.util.GradleConfigurationException;
44-
import net.minecraftforge.gradle.util.json.JsonFactory;
4542
import net.minecraftforge.gradle.util.json.fgversion.FGVersion;
4643
import net.minecraftforge.gradle.util.json.fgversion.FGVersionWrapper;
47-
import net.minecraftforge.gradle.util.json.forgeversion.ForgeVersion;
4844

4945
public class ForgePlugin extends PatcherUserBasePlugin<ForgeExtension>
5046
{
5147
@SuppressWarnings({ "unchecked", "rawtypes" })
5248
@Override
5349
protected void applyUserPlugin()
5450
{
55-
// set the version info into the extension object
56-
setForgeVersionJson();
57-
5851
super.applyUserPlugin();
5952

6053
// setup reobf
6154
{
6255
TaskSingleReobf reobf = (TaskSingleReobf) project.getTasks().getByName(TASK_REOBF);
6356
reobf.addPreTransformer(new McVersionTransformer(delayedString(REPLACE_MC_VERSION)));
6457
}
65-
58+
6659
// add coremod loading hack to gradle start
6760
{
6861
CreateStartTask makeStart = ((CreateStartTask)project.getTasks().getByName(UserConstants.TASK_MAKE_START));
@@ -72,7 +65,7 @@ protected void applyUserPlugin()
7265
}
7366
makeStart.addExtraLine("net.minecraftforge.gradle.GradleForgeHacks.searchCoremods(this);");
7467
}
75-
68+
7669
// configure eclipse task to do extra stuff.
7770
project.getTasks().getByName("eclipse").doLast(new Action() {
7871

@@ -139,51 +132,31 @@ protected void afterEvaluate()
139132
// add manifest things
140133
{
141134
Jar jarTask = (Jar) project.getTasks().getByName("jar");
142-
135+
143136
if (!Strings.isNullOrEmpty(ext.getCoreMod()))
144137
{
145138
jarTask.getManifest().getAttributes().put("FMLCorePlugin", ext.getCoreMod());
146139
}
147140
}
148141
}
149142

150-
private void setForgeVersionJson()
151-
{
152-
File jsonCache = cacheFile("ForgeVersion.json");
153-
File etagFile = new File(jsonCache.getAbsolutePath() + ".etag");
154-
String url = Constants.URL_FORGE_MAVEN + "/net/minecraftforge/forge/json";
155-
156-
try
157-
{
158-
getExtension().forgeJson = JsonFactory.GSON.fromJson(getWithEtag(url, jsonCache, etagFile), ForgeVersion.class);
159-
}
160-
catch(NullPointerException e)
161-
{
162-
getExtension().forgeJson = null;
163-
}
164-
catch(JsonSyntaxException e)
165-
{
166-
getExtension().forgeJson = null;
167-
}
168-
}
169-
170143
@Override
171144
protected void onVersionCheck(FGVersion version, FGVersionWrapper wrapper)
172145
{
173146
String forgeVersion = getExtension().getForgeVersion();
174-
147+
175148
// isolate build number
176149
int index = forgeVersion.indexOf('-');
177150
if (index >= 0)
178151
forgeVersion = forgeVersion.substring(0, index);
179152
index = forgeVersion.lastIndexOf('.');
180153
forgeVersion.substring(index + 1);
181-
154+
182155
int buildNum = Integer.parseInt(forgeVersion);
183-
156+
184157
int minBuild = version.ext.get("forgeMinBuild").getAsInt();
185158
int maxBuild = version.ext.get("forgeMaxBuild").getAsInt();
186-
159+
187160
if (buildNum < minBuild)
188161
throw new GradleConfigurationException("This version of ForgeGradle ("+getExtension().forgeGradleVersion+") does not support forge builds less than #"+minBuild);
189162
else if (buildNum > maxBuild)
@@ -255,7 +228,7 @@ protected List<String> getServerRunArgs(ForgeExtension ext)
255228
{
256229
return ext.getResolvedServerRunArgs();
257230
}
258-
231+
259232
@Override
260233
protected List<String> getClientJvmArgs(ForgeExtension ext)
261234
{

src/main/java/net/minecraftforge/gradle/util/json/JsonFactory.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import net.minecraftforge.gradle.util.json.LiteLoaderJson.VersionObject;
4040
import net.minecraftforge.gradle.util.json.fgversion.FGVersionDeserializer;
4141
import net.minecraftforge.gradle.util.json.fgversion.FGVersionWrapper;
42-
import net.minecraftforge.gradle.util.json.forgeversion.ForgeArtifact;
43-
import net.minecraftforge.gradle.util.json.forgeversion.ForgeArtifactAdapter;
4442
import net.minecraftforge.gradle.util.json.version.AssetIndex;
4543
import net.minecraftforge.gradle.util.json.version.ManifestVersion;
4644
import net.minecraftforge.gradle.util.json.version.Version;
@@ -56,7 +54,6 @@ public class JsonFactory
5654
builder.registerTypeAdapter(Date.class, new DateAdapter());
5755
builder.registerTypeAdapter(File.class, new FileAdapter());
5856
builder.registerTypeAdapter(VersionObject.class, new LiteLoaderJson.VersionAdapter());
59-
builder.registerTypeAdapter(ForgeArtifact.class, new ForgeArtifactAdapter());
6057
builder.registerTypeAdapter(FGVersionWrapper.class, new FGVersionDeserializer());
6158
builder.registerTypeAdapter(FGVersionWrapper.class, new FGVersionDeserializer());
6259
builder.registerTypeAdapter(new TypeToken<Map<String, ManifestVersion>>() {}.getType(), new MojangManifestAdapter());

0 commit comments

Comments
 (0)