Initial commit
This commit is contained in:
12
.gitattributes
vendored
Normal file
12
.gitattributes
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# https://help.github.com/articles/dealing-with-line-endings/
|
||||||
|
#
|
||||||
|
# Linux start script should use lf
|
||||||
|
/gradlew text eol=lf
|
||||||
|
|
||||||
|
# These are Windows script files and should use crlf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
|
||||||
|
# Binary files should be left untouched
|
||||||
|
*.jar binary
|
||||||
|
|
||||||
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Ignore Gradle project-specific cache directory
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# Ignore Gradle build output directory
|
||||||
|
build
|
||||||
|
app/bin
|
||||||
|
|
||||||
|
# Ignore Eclipse IDE files and directories
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
33
app/build.gradle
Normal file
33
app/build.gradle
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* This generated file contains a sample Java application project to get you started.
|
||||||
|
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.14/userguide/building_java_projects.html in the Gradle documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
|
id 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Use Maven Central for resolving dependencies.
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// This dependency is used by the application.
|
||||||
|
implementation libs.guava
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply a specific Java toolchain to ease working on different environments.
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
// Define the main class for the application.
|
||||||
|
mainClass = 'org.skinner.WebApp'
|
||||||
|
}
|
||||||
156
app/src/main/java/org/skinner/Database.java
Normal file
156
app/src/main/java/org/skinner/Database.java
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
private Database() {
|
||||||
|
try {
|
||||||
|
// TODO: Allow changing connection address
|
||||||
|
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/skinner", "skinner", "skinner");
|
||||||
|
|
||||||
|
InputStream is = WebApp.class.getResourceAsStream("/sql/init.sql");
|
||||||
|
executeScript(is);
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
errored = true;
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
errored = true;
|
||||||
|
exception = e;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ThreadLocal<Database> instances = ThreadLocal.withInitial(Database::new);
|
||||||
|
|
||||||
|
protected static Connection getConnection() throws SQLException {
|
||||||
|
Database instance = instances.get();
|
||||||
|
if (instance.errored)
|
||||||
|
throw instance.exception;
|
||||||
|
else
|
||||||
|
return instance.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeScript(InputStream is) throws SQLException, IOException {
|
||||||
|
// NOTE: This is a very simple implementation, should not be used outside this class.
|
||||||
|
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
|
||||||
|
String[] cmds = new String(is.readAllBytes()).split(";");
|
||||||
|
for (String cmd : cmds) {
|
||||||
|
if (!cmd.trim().isEmpty()) {
|
||||||
|
stmt.execute(cmd.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getSkinHashes() throws SQLException {
|
||||||
|
Statement stmt = getConnection().createStatement();
|
||||||
|
ResultSet resultSet = stmt.executeQuery("SELECT _hash FROM skin;");
|
||||||
|
|
||||||
|
List<String> hashes = new ArrayList<String>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
hashes.add(resultSet.getString("_hash"));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
return hashes.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashLabelPair[] getSkinHashesAndLabels() throws SQLException {
|
||||||
|
Statement stmt = getConnection().createStatement();
|
||||||
|
ResultSet resultSet = stmt.executeQuery("SELECT _hash, label FROM skin;");
|
||||||
|
|
||||||
|
List<HashLabelPair> pairs = new ArrayList<HashLabelPair>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
pairs.add(new HashLabelPair(
|
||||||
|
resultSet.getString("_hash"),
|
||||||
|
resultSet.getString("label")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
return pairs.toArray(new HashLabelPair[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Skin[] getSkins() throws SQLException {
|
||||||
|
Statement stmt = getConnection().createStatement();
|
||||||
|
ResultSet resultSet = stmt.executeQuery("SELECT * FROM skin;");
|
||||||
|
|
||||||
|
List<Skin> skins = new ArrayList<Skin>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
skins.add(new Skin(
|
||||||
|
resultSet.getInt("id"),
|
||||||
|
resultSet.getString("_hash"),
|
||||||
|
resultSet.getString("label"),
|
||||||
|
resultSet.getBoolean("slim"),
|
||||||
|
resultSet.getBytes("png"),
|
||||||
|
resultSet.getBytes("png_old")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
return skins.toArray(new Skin[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Skin getSkin(String hash) throws SQLException {
|
||||||
|
PreparedStatement stmt = getConnection().prepareStatement("SELECT * FROM skin WHERE _hash = ?;");
|
||||||
|
|
||||||
|
stmt.setString(1, hash);
|
||||||
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (!resultSet.next())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Skin skin = new Skin(
|
||||||
|
resultSet.getInt("id"),
|
||||||
|
resultSet.getString("_hash"),
|
||||||
|
resultSet.getString("label"),
|
||||||
|
resultSet.getBoolean("slim"),
|
||||||
|
resultSet.getBytes("png"),
|
||||||
|
resultSet.getBytes("png_old")
|
||||||
|
);
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addSkin(Skin skin) throws SQLException {
|
||||||
|
PreparedStatement stmt = getConnection().prepareStatement(
|
||||||
|
"INSERT INTO skin(_hash, label, slim, png, png_old) VALUES(?, ?, ?, ?, ?);"
|
||||||
|
);
|
||||||
|
|
||||||
|
stmt.setString ( 1, skin.getHash() );
|
||||||
|
stmt.setString ( 2, skin.getLabel() );
|
||||||
|
stmt.setBoolean ( 3, skin.getSlim() );
|
||||||
|
stmt.setBytes ( 4, skin.getPng() );
|
||||||
|
stmt.setBytes ( 5, skin.getPngOld() );
|
||||||
|
|
||||||
|
stmt.execute();
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Profile[] getProfiles() throws SQLException {
|
||||||
|
assert(false);
|
||||||
|
Statement stmt = getConnection().createStatement();
|
||||||
|
ResultSet resultSet = stmt.executeQuery("SELECT profile.* FROM profile AS profile JOIN skin AS skin ON profile.skin = skin.id;");
|
||||||
|
|
||||||
|
List<Profile> profiles = new ArrayList<Profile>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
return profiles.toArray(new Profile[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean errored = false;
|
||||||
|
private SQLException exception;
|
||||||
|
private Connection connection;
|
||||||
|
}
|
||||||
18
app/src/main/java/org/skinner/HashLabelPair.java
Normal file
18
app/src/main/java/org/skinner/HashLabelPair.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
public class HashLabelPair {
|
||||||
|
|
||||||
|
public HashLabelPair(String hash, String label) {
|
||||||
|
this.hash = hash;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
String hash;
|
||||||
|
String label;
|
||||||
|
|
||||||
|
}
|
||||||
102
app/src/main/java/org/skinner/MultipartForm.java
Normal file
102
app/src/main/java/org/skinner/MultipartForm.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
|
||||||
|
public class MultipartForm {
|
||||||
|
|
||||||
|
public MultipartForm(HttpExchange exchange) throws MultipartFormException, IOException {
|
||||||
|
parseFormBody(
|
||||||
|
exchange.getRequestBody().readAllBytes(),
|
||||||
|
exchange.getRequestHeaders().getFirst("Content-Type")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartForm(InputStream is, String contentType) throws MultipartFormException, IOException {
|
||||||
|
parseFormBody(is.readAllBytes(), contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartForm(byte[] body, String contentType) throws MultipartFormException, IOException {
|
||||||
|
parseFormBody(body, contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void parseFormBody(byte[] body, String contentType) throws MultipartFormException, IOException {
|
||||||
|
this.data = new HashMap<String, byte[]>();
|
||||||
|
|
||||||
|
String[] headerParts = contentType.split(";");
|
||||||
|
if (!headerParts[0].strip().equals("multipart/form-data"))
|
||||||
|
throw new MultipartFormException("Invalid Content-Type header, expected multipart/form-data");
|
||||||
|
if (headerParts.length == 1)
|
||||||
|
throw new MultipartFormException("Missing boundary field");
|
||||||
|
|
||||||
|
String boundary = null;
|
||||||
|
for (String headerPart : headerParts) {
|
||||||
|
String[] parts = headerPart.strip().split("=");
|
||||||
|
if (!parts[0].equals("boundary"))
|
||||||
|
continue;
|
||||||
|
boundary = parts[1].strip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boundary == null)
|
||||||
|
throw new MultipartFormException("Missing boundary field in Content-Type header");
|
||||||
|
|
||||||
|
String[] lines = new String(body, StandardCharsets.ISO_8859_1).split("\r\n");
|
||||||
|
String name = null;
|
||||||
|
String current = "";
|
||||||
|
boolean header = false;
|
||||||
|
for (String line : lines) {
|
||||||
|
if (line.equals("--"+boundary) || line.equals("--"+boundary+"--")) {
|
||||||
|
if (name != null) {
|
||||||
|
// We remove the last appended \r\n
|
||||||
|
data.put(name, current.substring(0, current.length()-2).getBytes(StandardCharsets.ISO_8859_1));
|
||||||
|
}
|
||||||
|
name = null;
|
||||||
|
current = "";
|
||||||
|
header = true;
|
||||||
|
|
||||||
|
if (line.equals("--"+boundary+"--")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header) {
|
||||||
|
if (line.equals("")) {
|
||||||
|
header = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] headerField = line.split(":", 2);
|
||||||
|
if (headerField[0].strip().equals("Content-Disposition")) {
|
||||||
|
for (String part : headerField[1].split(";")) {
|
||||||
|
if (!part.strip().startsWith("name=\""))
|
||||||
|
continue;
|
||||||
|
name = part.split("=", 2)[1].strip(); // Separate out the "name" value
|
||||||
|
name = name.substring(1, name.length()-1); // Remove quotes from around the value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
current += line + "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String name) {
|
||||||
|
return data.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] get(String name) {
|
||||||
|
return data.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String name) {
|
||||||
|
if (this.contains(name))
|
||||||
|
return new String(data.get(name));
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, byte[]> data;
|
||||||
|
|
||||||
|
}
|
||||||
27
app/src/main/java/org/skinner/MultipartFormException.java
Normal file
27
app/src/main/java/org/skinner/MultipartFormException.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
public class MultipartFormException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2845196104721963218L;
|
||||||
|
|
||||||
|
public MultipartFormException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartFormException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartFormException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartFormException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartFormException(String message, Throwable cause, boolean enableSuppression,
|
||||||
|
boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
app/src/main/java/org/skinner/Profile.java
Normal file
35
app/src/main/java/org/skinner/Profile.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import org.skinner.json.*;
|
||||||
|
|
||||||
|
public class Profile implements JSON {
|
||||||
|
public Profile(int id, String uuid, Skin skin) {
|
||||||
|
this.id = id;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Skin getSkin() {
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONValue toJSON() {
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("id", JSON.from(id));
|
||||||
|
object.put("uuid", JSON.from(uuid));
|
||||||
|
object.put("skin", skin.toJSON());
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String uuid;
|
||||||
|
private Skin skin;
|
||||||
|
}
|
||||||
24
app/src/main/java/org/skinner/Query.java
Normal file
24
app/src/main/java/org/skinner/Query.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Query extends HashMap<String, String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2095589600265440673L;
|
||||||
|
|
||||||
|
public Query(String query) {
|
||||||
|
// There's no data, empty map is OK :)
|
||||||
|
if (query == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String[] pairStrings = query.split("&");
|
||||||
|
for (String pairString : pairStrings) {
|
||||||
|
String[] pair = pairString.split("=", 2);
|
||||||
|
if (pair.length == 1)
|
||||||
|
this.put(pair[0], "");
|
||||||
|
else
|
||||||
|
this.put(pair[0], pair[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
app/src/main/java/org/skinner/ResourceServer.java
Normal file
66
app/src/main/java/org/skinner/ResourceServer.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
|
public class ResourceServer extends SafeHttpHandler {
|
||||||
|
|
||||||
|
public ResourceServer(String root, String fileRoot) {
|
||||||
|
super(root);
|
||||||
|
this.fileRoot = fileRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handle(HttpExchange exchange, URI uri) throws Exception {
|
||||||
|
String path = uri.getPath();
|
||||||
|
if (path.endsWith("/"))
|
||||||
|
path += "index.html";
|
||||||
|
String mime = mimeDB.get(path.substring(path.indexOf('.')+1));
|
||||||
|
InputStream resource = WebApp.class.getResourceAsStream(fileRoot + path);
|
||||||
|
if (resource == null) {
|
||||||
|
notFound(exchange, uri);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (path.endsWith(".gz")) {
|
||||||
|
resource = new GZIPInputStream(resource);
|
||||||
|
mime = mimeDB.get(
|
||||||
|
path
|
||||||
|
.substring(0, path.length()-3)
|
||||||
|
.substring(path.indexOf('.')+1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
byte[] data = resource.readAllBytes();
|
||||||
|
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", mime);
|
||||||
|
exchange.sendResponseHeaders(200, data.length);
|
||||||
|
exchange.getResponseBody().write(data);
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void notFound(HttpExchange exchange, URI uri) throws Exception {
|
||||||
|
String response = "Resource not found.";
|
||||||
|
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "text/plain");
|
||||||
|
exchange.sendResponseHeaders(404, response.length());
|
||||||
|
exchange.getResponseBody().write(response.getBytes());
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HashMap<String, String> mimeDB = new HashMap<String, String>() {
|
||||||
|
private static final long serialVersionUID = 2652944319747004387L;
|
||||||
|
{
|
||||||
|
put("txt", "text/plain");
|
||||||
|
put("html", "text/html");
|
||||||
|
put("css", "text/css");
|
||||||
|
|
||||||
|
put("png", "image/png");
|
||||||
|
|
||||||
|
put("js", "application/javascript");
|
||||||
|
}};
|
||||||
|
|
||||||
|
private String fileRoot;
|
||||||
|
|
||||||
|
}
|
||||||
134
app/src/main/java/org/skinner/RestAPI.java
Normal file
134
app/src/main/java/org/skinner/RestAPI.java
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.skinner.json.*;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
|
||||||
|
public class RestAPI extends SafeHttpHandler {
|
||||||
|
|
||||||
|
RestAPI(String root) {
|
||||||
|
super(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handle(HttpExchange exchange, URI uri) throws Exception {
|
||||||
|
String path = uri.getPath();
|
||||||
|
switch (exchange.getRequestMethod().toUpperCase())
|
||||||
|
{
|
||||||
|
case "GET":
|
||||||
|
switch (path)
|
||||||
|
{
|
||||||
|
case "/skins":
|
||||||
|
getSkins(exchange);
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Template-ish routes
|
||||||
|
default:
|
||||||
|
if (path.startsWith("/skin/")) {
|
||||||
|
getSkin(exchange, uri);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "POST":
|
||||||
|
switch (path)
|
||||||
|
{
|
||||||
|
case "/skin":
|
||||||
|
addSkin(exchange);
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Template-ish routes
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Headers headers = exchange.getResponseHeaders();
|
||||||
|
headers.add("Content-Type", "text/plain");
|
||||||
|
|
||||||
|
byte[] response = "Missing API endpoint".getBytes();
|
||||||
|
exchange.sendResponseHeaders(404, response.length);
|
||||||
|
exchange.getResponseBody().write(response);
|
||||||
|
exchange.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void getSkin(HttpExchange exchange, URI uri) throws Exception {
|
||||||
|
String[] pathParts = uri.getPath().split("/");
|
||||||
|
String hash = pathParts[pathParts.length-1].split("\\.")[0];
|
||||||
|
|
||||||
|
Skin skin = Database.getSkin(hash);
|
||||||
|
if (skin == null) {
|
||||||
|
notfound(exchange, "Skin not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Query query = new Query(uri.getQuery());
|
||||||
|
|
||||||
|
byte[] response = query.getOrDefault("legacy", "false").toLowerCase().equals("true") ?
|
||||||
|
skin.getPngOld() :
|
||||||
|
skin.getPng();
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "image/png");
|
||||||
|
exchange.sendResponseHeaders(200, response.length);
|
||||||
|
exchange.getResponseBody().write(response);
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void getSkins(HttpExchange exchange) throws Exception {
|
||||||
|
HashLabelPair[] pairs = Database.getSkinHashesAndLabels();
|
||||||
|
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
for (HashLabelPair pair : pairs) {
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("hash", JSON.from(pair.getHash()));
|
||||||
|
object.put("label", JSON.from(pair.getLabel()));
|
||||||
|
object.put("png", JSON.from(getRoot() + "skin/"+pair.getHash()+".png"));
|
||||||
|
object.put("png_old", JSON.from(getRoot() + "skin/"+pair.getHash()+".png?legacy=true"));
|
||||||
|
array.add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] response = array.toString().getBytes();
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||||
|
exchange.sendResponseHeaders(200, response.length);
|
||||||
|
exchange.getResponseBody().write(response);
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void getSkinsFull(HttpExchange exchange) throws Exception {
|
||||||
|
Skin[] skins = Database.getSkins();
|
||||||
|
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
for (Skin skin : skins) {
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("hash", JSON.from(skin.getHash()));
|
||||||
|
object.put("png", JSON.from(getRoot() + "skin/"+skin.getHash()+".png"));
|
||||||
|
object.put("png_old", JSON.from(getRoot() + "skin/"+skin.getHash()+".png?legacy=true"));
|
||||||
|
array.add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] response = array.toString().getBytes();
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||||
|
exchange.sendResponseHeaders(200, response.length);
|
||||||
|
exchange.getResponseBody().write(response);
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addSkin(HttpExchange exchange) throws Exception {
|
||||||
|
MultipartForm form = new MultipartForm(exchange);
|
||||||
|
|
||||||
|
if (!form.contains("skin")) {
|
||||||
|
fail(exchange, "Expected \"skin\" field not provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream is = new ByteArrayInputStream(form.get("skin"));
|
||||||
|
Skin skin = Skin.loadFromImage(is, form.getString("label"));
|
||||||
|
Database.addSkin(skin);
|
||||||
|
ok(exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
app/src/main/java/org/skinner/SafeHttpHandler.java
Normal file
66
app/src/main/java/org/skinner/SafeHttpHandler.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
|
||||||
|
public abstract class SafeHttpHandler implements HttpHandler {
|
||||||
|
public SafeHttpHandler(String root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(HttpExchange exchange) throws IOException {
|
||||||
|
try {
|
||||||
|
URI uri = new URI(
|
||||||
|
exchange
|
||||||
|
.getRequestURI()
|
||||||
|
.toString()
|
||||||
|
.replaceFirst("^"+root+"/*", "/")
|
||||||
|
);
|
||||||
|
handle(exchange, uri);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
// Maybe network error, don't print to console
|
||||||
|
fail(exchange, exception.toString());
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
fail(exchange, exception.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoot() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void text(HttpExchange exchange, int code, String message) throws IOException {
|
||||||
|
String response = message;
|
||||||
|
exchange.getResponseHeaders().add("Content-Type", "text/plain");
|
||||||
|
exchange.sendResponseHeaders(code, response.length());
|
||||||
|
exchange.getResponseBody().write(response.getBytes());
|
||||||
|
exchange.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fail(HttpExchange exchange, String message) throws IOException {
|
||||||
|
text(exchange, 500, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void notfound(HttpExchange exchange, String message) throws IOException {
|
||||||
|
text(exchange, 404, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void notfound(HttpExchange exchange) throws IOException {
|
||||||
|
notfound(exchange, "Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void ok(HttpExchange exchange, String message) throws IOException {
|
||||||
|
text(exchange, 200, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void ok(HttpExchange exchange) throws IOException {
|
||||||
|
ok(exchange, "Ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void handle(HttpExchange exchange, URI uri) throws Exception;
|
||||||
|
|
||||||
|
private String root;
|
||||||
|
}
|
||||||
171
app/src/main/java/org/skinner/Skin.java
Normal file
171
app/src/main/java/org/skinner/Skin.java
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.security.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Base64.Encoder;
|
||||||
|
|
||||||
|
import javax.imageio.*;
|
||||||
|
|
||||||
|
import org.skinner.json.*;
|
||||||
|
|
||||||
|
public class Skin implements JSON {
|
||||||
|
Skin(int id, String hash, String label, boolean slim, byte[] png, byte[] png_old) {
|
||||||
|
this.id = id;
|
||||||
|
this.hash = hash;
|
||||||
|
this.label = label;
|
||||||
|
this.slim = slim;
|
||||||
|
this.png = png;
|
||||||
|
this.png_old = png_old;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSlim() {
|
||||||
|
return slim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPng() {
|
||||||
|
return png;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPngOld() {
|
||||||
|
return png_old;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONValue toJSON() {
|
||||||
|
Encoder encoder = Base64.getEncoder();
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
object.put("id", JSON.from(id));
|
||||||
|
object.put("hash", JSON.from(hash));
|
||||||
|
object.put("label", JSON.from(label));
|
||||||
|
object.put("slim", JSON.from(slim));
|
||||||
|
object.put("png", JSON.from(encoder.encodeToString(png)));
|
||||||
|
object.put("png_old", JSON.from(encoder.encodeToString(png_old)));
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String hash;
|
||||||
|
private String label;
|
||||||
|
private boolean slim;
|
||||||
|
private byte[] png;
|
||||||
|
private byte[] png_old;
|
||||||
|
|
||||||
|
public static Skin loadFromImage(InputStream is, String label) throws SkinException, IOException, NoSuchAlgorithmException {
|
||||||
|
BufferedImage image = ImageIO.read(is);
|
||||||
|
int width = image.getWidth();
|
||||||
|
int height = image.getHeight();
|
||||||
|
|
||||||
|
if (width != 64)
|
||||||
|
throw new SkinException("Invalid skin width, must be 64");
|
||||||
|
|
||||||
|
if (height != 32 && height != 64)
|
||||||
|
throw new SkinException("Invalid skin height, must be 32 or 64");
|
||||||
|
|
||||||
|
byte[] imageData = new byte[width * height * 3];
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
int rgb = image.getRGB(x, y);
|
||||||
|
imageData[(y * width + x) * 3] = (byte) ((rgb >> 16) & 0xFF);
|
||||||
|
imageData[(y * width + x) * 3 + 1] = (byte) ((rgb >> 8) & 0xFF);
|
||||||
|
imageData[(y * width + x) * 3 + 2] = (byte) (rgb & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
byte[] hashBytes = digest.digest(imageData);
|
||||||
|
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
for (byte b : hashBytes) {
|
||||||
|
String hex = Integer.toHexString(0xff & b);
|
||||||
|
if (hex.length() == 1) {
|
||||||
|
hexString.append('0');
|
||||||
|
}
|
||||||
|
hexString.append(hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
String hash = hexString.toString();
|
||||||
|
boolean slim = false;
|
||||||
|
|
||||||
|
BufferedImage image_png;
|
||||||
|
BufferedImage image_png_old;
|
||||||
|
if (height == 64) { // We got 64x64 skin
|
||||||
|
image_png = image;
|
||||||
|
image_png_old = new BufferedImage(64, 32, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
int transparent = image.getRGB(63, 0);
|
||||||
|
slim = (
|
||||||
|
matchAreaRGB(image, transparent, 50, 16, 2, 4) ||
|
||||||
|
matchAreaRGB(image, transparent, 54, 20, 2, 12) ||
|
||||||
|
matchAreaRGB(image, transparent, 42, 48, 2, 4) ||
|
||||||
|
matchAreaRGB(image, transparent, 46, 52, 2, 12)
|
||||||
|
);
|
||||||
|
|
||||||
|
Graphics graphics = image_png_old.getGraphics();
|
||||||
|
graphics.drawImage(image_png, 0, 0, 64, 32, 0, 0, 64, 32, null);
|
||||||
|
|
||||||
|
if (slim) {
|
||||||
|
graphics.drawImage(image_png, 48, 16, 51, 20, 47, 16, 50, 20, null); // Move palm
|
||||||
|
graphics.drawImage(image_png, 51, 16, 52, 20, 49, 16, 50, 20, null); // Extend palm
|
||||||
|
graphics.drawImage(image_png, 47, 16, 48, 20, 46, 16, 47, 20, null); // Extend shoulder
|
||||||
|
|
||||||
|
graphics.drawImage(image_png, 48, 20, 55, 32, 47, 20, 54, 32, null); // Move right part
|
||||||
|
graphics.drawImage(image_png, 55, 20, 56, 32, 53, 20, 54, 32, null); // Extend right arm
|
||||||
|
graphics.drawImage(image_png, 47, 20, 48, 32, 46, 20, 47, 32, null); // Extend left arm
|
||||||
|
}
|
||||||
|
|
||||||
|
fillAreaRGB(image_png_old, transparent, 32, 0, 32, 16);
|
||||||
|
graphics.dispose();
|
||||||
|
} else { // We got 64x32 skin
|
||||||
|
image_png = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
image_png_old = image;
|
||||||
|
image_png_old.getGraphics().drawImage(image_png, 0, 0, 64, 32, 0, 0, 64, 32, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayOutputStream baos_png = new ByteArrayOutputStream();
|
||||||
|
ByteArrayOutputStream baos_png_old = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
ImageIO.write(image_png, "png", baos_png);
|
||||||
|
ImageIO.write(image_png_old, "png", baos_png_old);
|
||||||
|
|
||||||
|
baos_png.flush();
|
||||||
|
baos_png_old.flush();
|
||||||
|
|
||||||
|
byte[] png = baos_png.toByteArray();
|
||||||
|
byte[] png_old = baos_png_old.toByteArray();
|
||||||
|
|
||||||
|
return new Skin(-1, hash, label, slim, png, png_old);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean matchAreaRGB(BufferedImage image, int rgb, int x, int y, int w, int h) {
|
||||||
|
int endX = x + w;
|
||||||
|
int endY = y + h;
|
||||||
|
for (int i = y; i < endY; i++)
|
||||||
|
for (int j = x; j < endX; j++)
|
||||||
|
if (image.getRGB(j, i) != rgb)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fillAreaRGB(BufferedImage image, int rgb, int x, int y, int w, int h) {
|
||||||
|
int endX = x + w;
|
||||||
|
int endY = y + h;
|
||||||
|
for (int i = y; i < endY; i++)
|
||||||
|
for (int j = x; j < endX; j++)
|
||||||
|
image.setRGB(j, i, rgb);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/src/main/java/org/skinner/SkinException.java
Normal file
26
app/src/main/java/org/skinner/SkinException.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
public class SkinException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6173355382058208518L;
|
||||||
|
|
||||||
|
public SkinException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkinException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
app/src/main/java/org/skinner/WebApp.java
Normal file
25
app/src/main/java/org/skinner/WebApp.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package org.skinner;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.*;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
|
||||||
|
public class WebApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
// Create an HttpServer instance
|
||||||
|
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
|
||||||
|
|
||||||
|
// Create a context for a specific path and set the handler
|
||||||
|
server.createContext("/api/", new RestAPI("/api/"));
|
||||||
|
server.createContext("/", new ResourceServer("/", "/www"));
|
||||||
|
|
||||||
|
// Start the server
|
||||||
|
server.setExecutor(null); // Use the default executor
|
||||||
|
server.start();
|
||||||
|
|
||||||
|
System.out.println("Server is running on port 8000");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
app/src/main/java/org/skinner/json/JSON.java
Normal file
39
app/src/main/java/org/skinner/json/JSON.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public interface JSON {
|
||||||
|
JSONValue toJSON();
|
||||||
|
|
||||||
|
public static JSONBoolean from(boolean value) {
|
||||||
|
return new JSONBoolean(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONString from(String value) {
|
||||||
|
return new JSONString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONInt from(int value) {
|
||||||
|
return new JSONInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONFloat from(float value) {
|
||||||
|
return new JSONFloat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONArray from(JSONValue[] array) {
|
||||||
|
return JSON.from(Arrays.asList(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONArray from(Collection<JSONValue> list) {
|
||||||
|
return new JSONArray(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject from(Map<? extends String, ? extends JSONValue> map) {
|
||||||
|
return new JSONObject(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONValue from(JSON object) {
|
||||||
|
return object.toJSON();
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/src/main/java/org/skinner/json/JSONArray.java
Normal file
34
app/src/main/java/org/skinner/json/JSONArray.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class JSONArray extends ArrayList<JSONValue> implements JSONValue {
|
||||||
|
|
||||||
|
public JSONArray() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONArray(Collection<? extends JSONValue> c) {
|
||||||
|
super(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONArray(int initialCapacity) {
|
||||||
|
super(initialCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 4112322940331064783L;
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (this.size() == 0)
|
||||||
|
return "[]";
|
||||||
|
String string = "[";
|
||||||
|
for (JSONValue value : this)
|
||||||
|
string += value.toString() + ",";
|
||||||
|
return string.substring(0, string.length()-1) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
app/src/main/java/org/skinner/json/JSONBoolean.java
Normal file
27
app/src/main/java/org/skinner/json/JSONBoolean.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONBoolean implements JSONValue {
|
||||||
|
|
||||||
|
public JSONBoolean(boolean value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.BOOLEAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(boolean value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return value ? "true" : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean value;
|
||||||
|
|
||||||
|
}
|
||||||
26
app/src/main/java/org/skinner/json/JSONException.java
Normal file
26
app/src/main/java/org/skinner/json/JSONException.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7810908399955135495L;
|
||||||
|
|
||||||
|
public JSONException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
app/src/main/java/org/skinner/json/JSONFloat.java
Normal file
27
app/src/main/java/org/skinner/json/JSONFloat.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONFloat implements JSONValue {
|
||||||
|
|
||||||
|
public JSONFloat(float value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(float value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float value;
|
||||||
|
|
||||||
|
}
|
||||||
27
app/src/main/java/org/skinner/json/JSONInt.java
Normal file
27
app/src/main/java/org/skinner/json/JSONInt.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONInt implements JSONValue {
|
||||||
|
|
||||||
|
public JSONInt(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.INT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
}
|
||||||
16
app/src/main/java/org/skinner/json/JSONNull.java
Normal file
16
app/src/main/java/org/skinner/json/JSONNull.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONNull implements JSONValue {
|
||||||
|
|
||||||
|
public JSONNull() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
app/src/main/java/org/skinner/json/JSONObject.java
Normal file
38
app/src/main/java/org/skinner/json/JSONObject.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JSONObject extends HashMap<String, JSONValue> implements JSONValue {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1228642117432870512L;
|
||||||
|
|
||||||
|
public JSONObject() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject(int initialCapacity) {
|
||||||
|
super(initialCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject(Map<? extends String, ? extends JSONValue> m) {
|
||||||
|
super(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject(int initialCapacity, float loadFactor) {
|
||||||
|
super(initialCapacity, loadFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (this.size() == 0)
|
||||||
|
return "{}";
|
||||||
|
String string = "{";
|
||||||
|
for (Map.Entry<String, JSONValue> entry : this.entrySet())
|
||||||
|
string += "\"" + JSONString.project(entry.getKey()) + "\":" + entry.getValue().toString() + ",";
|
||||||
|
return string.substring(0, string.length()-1) + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
44
app/src/main/java/org/skinner/json/JSONString.java
Normal file
44
app/src/main/java/org/skinner/json/JSONString.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public class JSONString implements JSONValue {
|
||||||
|
|
||||||
|
public JSONString(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONType getType() {
|
||||||
|
return JSONType.STRING;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (value == null)
|
||||||
|
return new JSONNull().toString();
|
||||||
|
else
|
||||||
|
return "\"" + project(value) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
static public String project(String value) {
|
||||||
|
// NOTE: This function is not fully implemented, and supports features only
|
||||||
|
// required within current project scope.
|
||||||
|
return value
|
||||||
|
.replace("\\", "\\\\")
|
||||||
|
.replace("\t", "\\t")
|
||||||
|
.replace("\b", "\\b")
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r")
|
||||||
|
.replace("\f", "\\f")
|
||||||
|
.replace("\'", "\\'")
|
||||||
|
.replace("\"", "\\\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
}
|
||||||
11
app/src/main/java/org/skinner/json/JSONType.java
Normal file
11
app/src/main/java/org/skinner/json/JSONType.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public enum JSONType {
|
||||||
|
NULL,
|
||||||
|
BOOLEAN,
|
||||||
|
INT,
|
||||||
|
FLOAT,
|
||||||
|
STRING,
|
||||||
|
ARRAY,
|
||||||
|
OBJECT;
|
||||||
|
}
|
||||||
9
app/src/main/java/org/skinner/json/JSONValue.java
Normal file
9
app/src/main/java/org/skinner/json/JSONValue.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package org.skinner.json;
|
||||||
|
|
||||||
|
public interface JSONValue {
|
||||||
|
|
||||||
|
public JSONType getType();
|
||||||
|
|
||||||
|
public String toString();
|
||||||
|
|
||||||
|
}
|
||||||
28
app/src/main/resources/sql/init.sql
Normal file
28
app/src/main/resources/sql/init.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS skin(
|
||||||
|
id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
_hash VARCHAR(64) UNIQUE NOT NULL,
|
||||||
|
label TEXT,
|
||||||
|
slim BOOLEAN NOT NULL,
|
||||||
|
png BLOB NOT NULL,
|
||||||
|
png_old BLOB NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS profile(
|
||||||
|
id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
username TEXT NOT NULL,
|
||||||
|
uuid VARCHAR(36) UNIQUE NOT NULL,
|
||||||
|
skin INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (skin) REFERENCES skin(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS tag(
|
||||||
|
id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
label TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS skin_tag(
|
||||||
|
skin INTEGER NOT NULL,
|
||||||
|
tag INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (skin) REFERENCES skin(id),
|
||||||
|
FOREIGN KEY (tag) REFERENCES tag(id)
|
||||||
|
);
|
||||||
5
app/src/main/resources/www/api.js
Normal file
5
app/src/main/resources/www/api.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
api = {
|
||||||
|
getSkins: async function() {
|
||||||
|
return fetch("api/skins").then(res=>res.json());
|
||||||
|
},
|
||||||
|
};
|
||||||
25
app/src/main/resources/www/index.html
Normal file
25
app/src/main/resources/www/index.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="thirdparty/simple.css.gz">
|
||||||
|
<script src="api.js"></script>
|
||||||
|
<script src="thirdparty/skinview3d.js.gz"></script>
|
||||||
|
<script src="thirdparty/alpine.js.gz" defer></script>
|
||||||
|
<title>Skinner</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Skinner</h1>
|
||||||
|
<article>
|
||||||
|
<form method="POST" action="api/skin" enctype="multipart/form-data">
|
||||||
|
<input name="label" type="text" placeholder="Skin name">
|
||||||
|
<input name="skin" type="file" required>
|
||||||
|
<input type="submit" value="Add new skin">
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
<div x-data="{skins: api.getSkins()}">
|
||||||
|
<template x-for="skin in skins">
|
||||||
|
<p x-text="skin.label + ' <<>> ' + skin.hash"></p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
app/src/main/resources/www/thirdparty/alpine.js.gz
vendored
Normal file
BIN
app/src/main/resources/www/thirdparty/alpine.js.gz
vendored
Normal file
Binary file not shown.
BIN
app/src/main/resources/www/thirdparty/simple.css.gz
vendored
Normal file
BIN
app/src/main/resources/www/thirdparty/simple.css.gz
vendored
Normal file
Binary file not shown.
BIN
app/src/main/resources/www/thirdparty/skinview3d.js.gz
vendored
Normal file
BIN
app/src/main/resources/www/thirdparty/skinview3d.js.gz
vendored
Normal file
Binary file not shown.
5
gradle.properties
Normal file
5
gradle.properties
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# This file was generated by the Gradle 'init' task.
|
||||||
|
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||||
|
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
|
|
||||||
10
gradle/libs.versions.toml
Normal file
10
gradle/libs.versions.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# This file was generated by the Gradle 'init' task.
|
||||||
|
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
|
||||||
|
|
||||||
|
[versions]
|
||||||
|
guava = "33.4.5-jre"
|
||||||
|
junit-jupiter = "5.12.1"
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||||
|
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
251
gradlew
vendored
Normal file
251
gradlew
vendored
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
94
gradlew.bat
vendored
Normal file
94
gradlew.bat
vendored
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
14
settings.gradle
Normal file
14
settings.gradle
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* The settings file is used to specify which projects to include in your build.
|
||||||
|
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.14/userguide/multi_project_builds.html in the Gradle documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the foojay-resolver plugin to allow automatic download of JDKs
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.10.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'skinner'
|
||||||
|
include('app')
|
||||||
Reference in New Issue
Block a user