mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-24 12:16:28 +01:00
Add a staging tool to easily test modpacks in the launcher.
After building, copy the staging-tool/build/dist/stagingtool/ folder to your modpack's folder and use build_and_launch.bat to test the modpack.
This commit is contained in:
parent
adf90941e0
commit
d239b32fa3
@ -1,3 +1,3 @@
|
||||
rootProject.name = 'launcher-parent'
|
||||
|
||||
include 'launcher', 'launcher-fancy', 'launcher-builder', 'launcher-bootstrap'
|
||||
include 'launcher', 'launcher-fancy', 'launcher-builder', 'launcher-bootstrap', 'staging-tool'
|
||||
|
32
staging-tool/build.gradle
Normal file
32
staging-tool/build.gradle
Normal file
@ -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)
|
35
staging-tool/scripts/HOW_TO_USE.html
Normal file
35
staging-tool/scripts/HOW_TO_USE.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>How to Use</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 20px; }
|
||||
body { font-family: Calibri, Arial, sans-serif; font-size: 12pt; }
|
||||
#content { max-width: 600px; }
|
||||
code { background: #ccc; font-family: Consolas, monospace; font-size: 0.9em; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1>How to Use</h1>
|
||||
|
||||
<p>This tool lets you test the modpack locally.</p>
|
||||
|
||||
<p>It should be a <code>stagingtool</code> folder within the modpack folder.</p>
|
||||
|
||||
<h2>Usage</h2>
|
||||
|
||||
<p>Basically, whenever you want to test the modpack, use <code>build_and_launch.bat</code> to build the modpack output files, start a local web server, and open the launcher.</p>
|
||||
|
||||
<p>There are other files that you can run too:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>build.bat</code> just builds the modpack output files only</li>
|
||||
<li><code>http_server.bat</code> just runs the local web server only</li>
|
||||
<li><code>launch.bat</code> just runs the staging launcher only</li>
|
||||
<li><code>reset_build.bat</code> deletes all the generated modpack output files, but there is rarely a situation where you would need to do this</li>
|
||||
<li><code>reset_launcher.bat</code> deletes downloaded instances, so you can use the launcher as someone who hasn't yet downloaded the modpack yet</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
3
staging-tool/scripts/build.bat
Normal file
3
staging-tool/scripts/build.bat
Normal file
@ -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"
|
14
staging-tool/scripts/build_and_launch.bat
Normal file
14
staging-tool/scripts/build_and_launch.bat
Normal file
@ -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
|
2
staging-tool/scripts/http_server.bat
Normal file
2
staging-tool/scripts/http_server.bat
Normal file
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
java -cp staging-tool.jar com.skcraft.launcher.staging.StagingServer --www-dir www
|
5
staging-tool/scripts/launch.bat
Normal file
5
staging-tool/scripts/launch.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
|
||||
mkdir launcher
|
||||
cd launcher
|
||||
java -cp ..\staging-tool.jar com.skcraft.launcher.staging.StagingServer --www-dir ..\www --launch
|
3
staging-tool/scripts/reset_build.bat
Normal file
3
staging-tool/scripts/reset_build.bat
Normal file
@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
|
||||
del /f /s /q www
|
3
staging-tool/scripts/reset_launcher.bat
Normal file
3
staging-tool/scripts/reset_launcher.bat
Normal file
@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
|
||||
del /f /s /q launcher\instances
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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("<!DOCTYPE html>");
|
||||
writer.write("<html>");
|
||||
writer.write("<head>");
|
||||
writer.write("<title>Staging Tool</title>");
|
||||
writer.write("</head>");
|
||||
writer.write("<body>");
|
||||
writer.write("<p>Welcome to the staging tool!</p>");
|
||||
writer.write("</body>");
|
||||
writer.write("</html>");
|
||||
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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<ManifestInfo> 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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;
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#
|
||||
# SK's Minecraft Launcher
|
||||
# Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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
|
Loading…
Reference in New Issue
Block a user