Skip to content

Commit

Permalink
Download fabric and wilderforge dependencies from the internet, as th…
Browse files Browse the repository at this point in the history
…ey're no longer being shadowed.
  • Loading branch information
Gamebuster19901 committed Jan 1, 2022
1 parent 30ea955 commit a2fbca8
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 48 deletions.
51 changes: 51 additions & 0 deletions src/main/java/com/wildermods/workspace/LocalResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.wildermods.workspace;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class LocalResource implements Resource {

private final InputStream inputstream;
private final String resourceLocation;
private final String destPath;
private final boolean useBinDir;

public LocalResource(String path, boolean useBinDir) {
this(path, path, useBinDir);
}

public LocalResource(String resourceLocation, String destPath, boolean useBinDir) {
this.resourceLocation = resourceLocation;
this.destPath = destPath;
this.useBinDir = useBinDir;
InputStream stream = LocalResource.class.getResourceAsStream(resourceLocation);
if(stream == null) { //If we're being executed from a dir not a jar
stream = LocalResource.class.getResourceAsStream("/" + resourceLocation);
}
this.inputstream = stream;
if(inputstream == null) {
throw new MissingResourceException("Could not find resource " + resourceLocation, LocalResource.class.getName(), resourceLocation);
}
}

/*
* Note that a resource can only be written once.
*/
@SuppressWarnings("deprecation")
public void write(File destDir, boolean binEnabled) throws IOException {
File dest = new File(destDir.getAbsolutePath() + "/" + destPath);
if(!dest.exists()) {
System.out.println("writing " + dest);
FileUtils.writeByteArrayToFile(dest, IOUtils.toByteArray(inputstream), false);
}
else {
System.out.println("Resource already exists: " + dest);
}
}

}
37 changes: 29 additions & 8 deletions src/main/java/com/wildermods/workspace/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.lang3.StringUtils;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.wildermods.workspace.decompile.DecompileWriteRule;

import cuchaz.enigma.classprovider.ClassProvider;
Expand Down Expand Up @@ -45,6 +48,8 @@ public class Main {
public static final String README = ".*/Wildermyth/readme\\.txt";
public static final String PATCHLINE = ".*/Wildermyth/patchline\\.txt";

public static final JsonArray DEPENDENCIES;

static {
EXCLUSIONS.put("logs", ".*/Wildermyth/logs.*");
EXCLUSIONS.put("out", ".*/Wildermyth/out.*");
Expand All @@ -68,6 +73,12 @@ public Throwable write(File source, File dest) {
} return null;
}}
);

try {
DEPENDENCIES = JsonParser.parseString(new String(IOUtils.resourceToByteArray("/dependencies.json"))).getAsJsonObject().get("dependencies").getAsJsonArray();
} catch (Throwable t) {
throw new Error(t);
}
}

private static final HashSet<File> FILES = new HashSet<File>();
Expand Down Expand Up @@ -141,14 +152,24 @@ private static void setupWriteRulesAndResources(InstallationProperties propertie
WRITE_RULES.put("overwriteMods", new ShouldOverwriteWriteRule(properties.overwriteMods(), MODS));
}

for(JsonElement dependencyElement : DEPENDENCIES) {
RemoteResource resource;
try {
resource = new RemoteResource(dependencyElement.getAsJsonObject());
} catch (IOException e) {
throw new Error(e);
}
NEW_RESOURCES.put(resource.name, resource);
}

if(properties.createGradle()) {
NEW_RESOURCES.put(".gitignore", new Resource("gitignore", ".gitignore"));
NEW_RESOURCES.put(".gitattributes", new Resource("gitattributes", ".gitattributes"));
NEW_RESOURCES.put("build.gradle", new Resource("build.gradle"));
NEW_RESOURCES.put("gradlew", new Resource("gradlew"));
NEW_RESOURCES.put("gradlew.bat", new Resource("gradlew.bat"));
NEW_RESOURCES.put("gradleJar", new Resource("gradle/wrapper/gradle-wrapper", "gradle/wrapper/gradle-wrapper.jar"));
NEW_RESOURCES.put("gradleProperties", new Resource("gradle/wrapper/gradle-wrapper.properties"));
NEW_RESOURCES.put(".gitignore", new LocalResource("gitignore", ".gitignore", false));
NEW_RESOURCES.put(".gitattributes", new LocalResource("gitattributes", ".gitattributes", false));
NEW_RESOURCES.put("build.gradle", new LocalResource("build.gradle", false));
NEW_RESOURCES.put("gradlew", new LocalResource("gradlew", false));
NEW_RESOURCES.put("gradlew.bat", new LocalResource("gradlew.bat", false));
NEW_RESOURCES.put("gradleJar", new LocalResource("gradle/wrapper/gradle-wrapper", "gradle/wrapper/gradle-wrapper.jar", false));
NEW_RESOURCES.put("gradleProperties", new LocalResource("gradle/wrapper/gradle-wrapper.properties", false));
}

if(properties.decompile()) {
Expand Down Expand Up @@ -263,7 +284,7 @@ else if(dest.exists()){
}
for(Resource r : NEW_RESOURCES.values()) {
try {
r.write(workspaceDir);
r.write(workspaceDir, properties.createGradle());
} catch (IOException e) {
throw new IOError(e);
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/wildermods/workspace/RemoteResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.wildermods.workspace;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class RemoteResource implements Resource {

public final String name;
private final URL url;
private final String destPath;
private final boolean useBinDir;

public RemoteResource(JsonElement resourceDefinition) throws IOException {
JsonObject resourceJson = resourceDefinition.getAsJsonObject();
JsonElement nameEle = resourceJson.get("name");
JsonElement urlEle = resourceJson.get("url");
JsonElement destEle = resourceJson.get("dest");
JsonElement binEle = resourceJson.get("bin");

this.name = nameEle.getAsString();
this.url = new URL(urlEle.getAsString());
this.destPath = destEle.getAsString();
this.useBinDir = destEle.getAsBoolean();
}

@Override
public void write(File destDir, boolean binEnabled) throws IOException {
File dest = new File(destDir, (binEnabled ? "/bin" : "") + destPath);
if(!dest.exists()) {
System.out.println("Downloading " + name + ":\nFrom: " + url + "\nInto: " + dest);
FileUtils.copyInputStreamToFile(url.openStream(), dest);
}
else {
System.out.println("Resource already exists: " + dest);
}
}

}
42 changes: 2 additions & 40 deletions src/main/java/com/wildermods/workspace/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,9 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
public interface Resource {

public class Resource {

private final InputStream inputstream;
private final String resourceLocation;
private final String destPath;

public Resource(String path) {
this(path, path);
}

public Resource(String resourceLocation, String destPath) {
this.resourceLocation = resourceLocation;
this.destPath = destPath;
InputStream stream = Resource.class.getResourceAsStream(resourceLocation);
if(stream == null) { //If we're being executed from a dir not a jar
stream = Resource.class.getResourceAsStream("/" + resourceLocation);
}
this.inputstream = stream;
if(inputstream == null) {
throw new MissingResourceException("Could not find resource " + resourceLocation, Resource.class.getName(), resourceLocation);
}
}
public void write(File destDir, boolean binEnabled) throws IOException;

/*
* Note that a resource can only be written once.
*/
@SuppressWarnings("deprecation")
public void write(File destDir) throws IOException {
File dest = new File(destDir.getAbsolutePath() + "/" + destPath);
if(!dest.exists()) {
System.out.println("writing " + dest);
FileUtils.writeByteArrayToFile(dest, IOUtils.toByteArray(inputstream), false);
}
else {
System.out.println("Resource already exists: " + dest);
}
}
}
82 changes: 82 additions & 0 deletions src/main/resources/dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"dependencies": [
{
"name": "Fabric Loader",
"url": "https://maven.fabricmc.net/net/fabricmc/fabric-loader/0.12.12/fabric-loader-0.12.12.jar",
"dest": "/fabric-loader-0.12.12.jar",
"bin":true
},
{
"name":"Wildermyth Game Provider",
"url": "https://dl.wildermods.com/?user=gamebuster19901&?project=wildermythgameprovider&?version=0.1.0.0&?artifact=provider-0.1.0.0-all.jar",
"dest": "/fabric/provider-0.1.0.0-all.jar",
"bin":true
},
{
"name":"Tiny Mappings Parser",
"url": "https://maven.fabricmc.net/net/fabricmc/tiny-mappings-parser/0.3.0%2Bbuild.17/tiny-mappings-parser-0.3.0%2Bbuild.17.jar",
"dest": "/fabric/tiny-mappings-parser-0.3.0+build.17.jar",
"bin":true
},
{
"name":"Tiny Remapper",
"url" : "https://maven.fabricmc.net/net/fabricmc/tiny-remapper/0.6.0/tiny-remapper-0.6.0.jar",
"dest": "/fabric/tiny-remapper-0.6.0.jar",
"bin":true
},
{
"name":"Access Widener",
"url" : "https://maven.fabricmc.net/net/fabricmc/access-widener/2.1.0/access-widener-2.1.0.jar",
"dest": "/fabric/access-widener-2.1.0.jar",
"bin":true
},
{
"name":"ASM",
"url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm/9.2/asm-9.2.jar",
"dest": "/fabric/asm-9.2.jar",
"bin":true
},
{
"name":"ASM Analysis",
"url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-analysis/9.2/asm-analysis-9.2.jar",
"dest": "/fabric/asm-analysis-9.2.jar",
"bin":true
},
{
"name":"ASM Commons",
"url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-commons/9.2/asm-commons-9.2.jar",
"dest": "/fabric/asm-commons-9.2.jar",
"bin":true
},
{
"name":"ASM Tree",
"url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/9.2/asm-tree-9.2.jar",
"dest": "/fabric/asm-tree-9.2.jar",
"bin":true
},
{
"name":"ASM Util",
"url": "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-util/9.2/asm-util-9.2.jar",
"dest": "/fabric/asm-util-9.2.jar",
"bin":true
},
{
"name":"Spongepowered Mixin",
"url":"https://repo.spongepowered.org/repository/maven-public/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar",
"dest": "/fabric/mixin-0.8.5.jar",
"bin":true
},
{
"name":"Guava",
"url": "https://repo.maven.apache.org/maven2/com/google/guava/guava/21.0/guava-21.0.jar",
"dest": "/fabric/guava-21.0.jar",
"bin":true
},
{
"name":"Gson",
"url": "https://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.8.7/gson-2.8.7.jar",
"dest": "/fabric/gson-2.8.7.jar",
"bin": true
}
]
}

0 comments on commit a2fbca8

Please sign in to comment.