diff --git a/settings.gradle b/settings.gradle index 8f515d2..fabc5b8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ rootProject.name = 'launcher-parent' -include 'launcher', 'launcher-fancy', 'launcher-builder', 'launcher-bootstrap' \ No newline at end of file +include 'launcher', 'launcher-fancy', 'launcher-builder', 'launcher-bootstrap', 'staging-tool' diff --git a/staging-tool/build.gradle b/staging-tool/build.gradle new file mode 100644 index 0000000..43934e0 --- /dev/null +++ b/staging-tool/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.github.johnrengelman.shadow' + +dependencies { + compile project(':launcher-builder') + compile 'org.eclipse.jetty:jetty-server:9.3.1.v20150714' +} + +shadowJar { + dependencies { + exclude(dependency('org.projectlombok:lombok')) + } +} + +task createDist(type: Copy) { + dependsOn jar, shadowJar + + def destDir = file("${buildDir}/dist/stagingtool") + destDir.parentFile.deleteDir() + destDir.mkdirs() + + destinationDir destDir + + from("${buildDir}/libs/${shadowJar.baseName}-${version}-all.jar") { + rename { f -> "staging-tool.jar" } + } + + from("${projectDir}/scripts") + +} + +build.dependsOn(shadowJar) +build.dependsOn(createDist) diff --git a/staging-tool/scripts/HOW_TO_USE.html b/staging-tool/scripts/HOW_TO_USE.html new file mode 100644 index 0000000..4b1bfe5 --- /dev/null +++ b/staging-tool/scripts/HOW_TO_USE.html @@ -0,0 +1,35 @@ + + + +How to Use + + + +
+

How to Use

+ +

This tool lets you test the modpack locally.

+ +

It should be a stagingtool folder within the modpack folder.

+ +

Usage

+ +

Basically, whenever you want to test the modpack, use build_and_launch.bat to build the modpack output files, start a local web server, and open the launcher.

+ +

There are other files that you can run too:

+ + +
+ + \ No newline at end of file diff --git a/staging-tool/scripts/build.bat b/staging-tool/scripts/build.bat new file mode 100644 index 0000000..2fbba1d --- /dev/null +++ b/staging-tool/scripts/build.bat @@ -0,0 +1,3 @@ +@echo off + +java -cp staging-tool.jar com.skcraft.launcher.builder.PackageBuilder --version "%DATE% %TIME%" --input ..\ --output www --manifest-dest "www/staging.json" \ No newline at end of file diff --git a/staging-tool/scripts/build_and_launch.bat b/staging-tool/scripts/build_and_launch.bat new file mode 100644 index 0000000..00cf748 --- /dev/null +++ b/staging-tool/scripts/build_and_launch.bat @@ -0,0 +1,14 @@ +@echo off + +call build.bat +if ERRORLEVEL 0 goto Launch + +:Launch +call launch.bat +goto End + +:Error +echo "ERROR -- Modpack building failed!" +pause + +:End \ No newline at end of file diff --git a/staging-tool/scripts/http_server.bat b/staging-tool/scripts/http_server.bat new file mode 100644 index 0000000..946b03e --- /dev/null +++ b/staging-tool/scripts/http_server.bat @@ -0,0 +1,2 @@ +@echo off +java -cp staging-tool.jar com.skcraft.launcher.staging.StagingServer --www-dir www \ No newline at end of file diff --git a/staging-tool/scripts/launch.bat b/staging-tool/scripts/launch.bat new file mode 100644 index 0000000..b180f7c --- /dev/null +++ b/staging-tool/scripts/launch.bat @@ -0,0 +1,5 @@ +@echo off + +mkdir launcher +cd launcher +java -cp ..\staging-tool.jar com.skcraft.launcher.staging.StagingServer --www-dir ..\www --launch \ No newline at end of file diff --git a/staging-tool/scripts/reset_build.bat b/staging-tool/scripts/reset_build.bat new file mode 100644 index 0000000..223e0de --- /dev/null +++ b/staging-tool/scripts/reset_build.bat @@ -0,0 +1,3 @@ +@echo off + +del /f /s /q www \ No newline at end of file diff --git a/staging-tool/scripts/reset_launcher.bat b/staging-tool/scripts/reset_launcher.bat new file mode 100644 index 0000000..b286db3 --- /dev/null +++ b/staging-tool/scripts/reset_launcher.bat @@ -0,0 +1,3 @@ +@echo off + +del /f /s /q launcher\instances \ No newline at end of file diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/LatestHandler.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/LatestHandler.java new file mode 100644 index 0000000..b0ff28a --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/LatestHandler.java @@ -0,0 +1,41 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.skcraft.launcher.selfupdate.LatestVersionInfo; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URL; + +public class LatestHandler extends AbstractHandler { + + private final ObjectMapper mapper; + + public LatestHandler(ObjectMapper mapper) { + this.mapper = mapper; + } + + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + response.setContentType("text/plain; charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + + LatestVersionInfo info = new LatestVersionInfo(); + info.setVersion("0.0.0"); + info.setUrl(new URL("http://localhost")); + mapper.writeValue(response.getWriter(), info); + + baseRequest.setHandled(true); + } + +} diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/LocalHttpServerBuilder.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/LocalHttpServerBuilder.java new file mode 100644 index 0000000..175740b --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/LocalHttpServerBuilder.java @@ -0,0 +1,77 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.server.handler.ContextHandlerCollection; +import org.eclipse.jetty.server.handler.ResourceHandler; +import org.eclipse.jetty.server.handler.gzip.GzipHandler; + +import java.io.File; + +public class LocalHttpServerBuilder { + + private File baseDir = new File("."); + private int port = 28888; + + public File getBaseDir() { + return baseDir; + } + + public LocalHttpServerBuilder setBaseDir(File baseDir) { + this.baseDir = baseDir; + return this; + } + + public int getPort() { + return port; + } + + public LocalHttpServerBuilder setPort(int port) { + this.port = port; + return this; + } + + public Server build() throws Exception { + Server server = new Server(port); + + ObjectMapper mapper = new ObjectMapper(); + + ResourceHandler resourceHandler = new ResourceHandler(); + resourceHandler.setDirectoriesListed(true); + resourceHandler.setResourceBase(baseDir.getAbsolutePath()); + + ContextHandler rootContext = new ContextHandler(); + rootContext.setContextPath("/"); + rootContext.setHandler(resourceHandler); + + ContextHandler packagesContext = new ContextHandler("/packages.json"); + packagesContext.setAllowNullPathInfo(true); + packagesContext.setHandler(new PackagesHandler(mapper, baseDir)); + + ContextHandler latestContext = new ContextHandler("/latest.json"); + latestContext.setAllowNullPathInfo(true); + latestContext.setHandler(new LatestHandler(mapper)); + + ContextHandler newsContext = new ContextHandler("/news.html"); + newsContext.setAllowNullPathInfo(true); + newsContext.setHandler(new NewsHandler()); + + ContextHandlerCollection contexts = new ContextHandlerCollection(); + contexts.setHandlers(new Handler[]{packagesContext, latestContext, newsContext, rootContext}); + + GzipHandler gzip = new GzipHandler(); + server.setHandler(gzip); + gzip.setHandler(contexts); + + return server; + } + +} diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/NewsHandler.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/NewsHandler.java new file mode 100644 index 0000000..08e9cac --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/NewsHandler.java @@ -0,0 +1,39 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +public class NewsHandler extends AbstractHandler { + + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + response.setContentType("text/html; charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + + PrintWriter writer = response.getWriter(); + writer.write(""); + writer.write(""); + writer.write(""); + writer.write("Staging Tool"); + writer.write(""); + writer.write(""); + writer.write("

Welcome to the staging tool!

"); + writer.write(""); + writer.write(""); + + baseRequest.setHandled(true); + } + +} diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/PackagesHandler.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/PackagesHandler.java new file mode 100644 index 0000000..9e63019 --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/PackagesHandler.java @@ -0,0 +1,66 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import com.beust.jcommander.internal.Lists; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.skcraft.launcher.model.modpack.Manifest; +import com.skcraft.launcher.model.modpack.ManifestInfo; +import com.skcraft.launcher.model.modpack.PackageList; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.List; + +public class PackagesHandler extends AbstractHandler { + + private final ObjectMapper mapper; + private final File baseDir; + + public PackagesHandler(ObjectMapper mapper, File baseDir) { + this.mapper = mapper; + this.baseDir = baseDir; + } + + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + response.setContentType("text/plain; charset=utf-8"); + response.setStatus(HttpServletResponse.SC_OK); + + List packages = Lists.newArrayList(); + PackageList packageList = new PackageList(); + packageList.setPackages(packages); + + File[] files = baseDir.listFiles(new PackageFileFilter()); + if (files != null) { + for (File file : files) { + Manifest manifest = mapper.readValue(file, Manifest.class); + ManifestInfo info = new ManifestInfo(); + info.setName(manifest.getName()); + info.setTitle(manifest.getTitle()); + info.setVersion(manifest.getVersion()); + info.setLocation(file.getName()); + packages.add(info); + } + } + + mapper.writeValue(response.getWriter(), packageList); + baseRequest.setHandled(true); + } + + private static class PackageFileFilter implements FileFilter { + @Override + public boolean accept(File pathname) { + return pathname.getName().toLowerCase().endsWith(".json"); + } + } +} diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingArguments.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingArguments.java new file mode 100644 index 0000000..9395d55 --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingArguments.java @@ -0,0 +1,29 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import com.beust.jcommander.Parameter; +import lombok.Data; + +import java.io.File; + +/** + * The command line arguments that the staging tool accepts. + */ +@Data +public class StagingArguments { + + @Parameter(names = "--www-dir") + private File wwwDir = new File("."); + + @Parameter(names = "--port") + private Integer port = 28888; + + @Parameter(names = "--launch") + private boolean launch = false; + +} diff --git a/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingServer.java b/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingServer.java new file mode 100644 index 0000000..34e561c --- /dev/null +++ b/staging-tool/src/main/java/com/skcraft/launcher/staging/StagingServer.java @@ -0,0 +1,36 @@ +/* + * SK's Minecraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.staging; + +import com.beust.jcommander.JCommander; +import com.skcraft.launcher.Launcher; +import org.eclipse.jetty.server.Server; + +import java.io.File; + +public class StagingServer { + + public static void main(String[] args) throws Exception { + StagingArguments options = new StagingArguments(); + new JCommander(options, args); + + File wwwDir = options.getWwwDir(); + wwwDir.mkdirs(); + + LocalHttpServerBuilder builder = new LocalHttpServerBuilder(); + builder.setBaseDir(wwwDir); + builder.setPort(options.getPort()); + + Server server = builder.build(); + server.start(); + + if (options.isLaunch()) { + Launcher.main(new String[0]); + } + } + +} diff --git a/staging-tool/src/main/resources/com/skcraft/launcher/launcher.properties b/staging-tool/src/main/resources/com/skcraft/launcher/launcher.properties new file mode 100644 index 0000000..10a62df --- /dev/null +++ b/staging-tool/src/main/resources/com/skcraft/launcher/launcher.properties @@ -0,0 +1,21 @@ +# +# SK's Minecraft Launcher +# Copyright (C) 2010-2014 Albert Pham and contributors +# Please see LICENSE.txt for license information. +# + +version=${project.version} +agentName=Minecraft +offlinePlayerName=Player + +versionManifestUrl=https://s3.amazonaws.com/Minecraft.Download/versions/%1$s/%1$s.json +librariesSource=https://libraries.minecraft.net/ +jarUrl=http://s3.amazonaws.com/Minecraft.Download/versions/%1$s/%1$s.jar +assetsIndexUrl=https://s3.amazonaws.com/Minecraft.Download/indexes/%s.json +assetsSource=http://resources.download.minecraft.net/ +yggdrasilAuthUrl=https://authserver.mojang.com/authenticate +resetPasswordUrl=https://minecraft.net/resetpassword + +newsUrl=http://localhost:28888/news.html +packageListUrl=http://localhost:28888/packages.json +selfUpdateUrl=http://localhost:28888/latest.json