Compare commits
10 commits
ee90a5e3d6
...
a3b9a1bccb
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a3b9a1bccb | ||
![]() |
05250f944c | ||
![]() |
b062b8e914 | ||
![]() |
40c7acb3cc | ||
![]() |
b57c10b6ca | ||
![]() |
e526b41b3f | ||
![]() |
5f374c92f4 | ||
![]() |
fb3141b516 | ||
![]() |
195c96eb54 | ||
![]() |
4e58a426c6 |
30 changed files with 1016 additions and 1 deletions
9
.gitattributes
vendored
Normal file
9
.gitattributes
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -20,4 +20,7 @@ gradle-app.setting
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
# JDT-specific (Eclipse Java Development Tools)
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
__MACOSX
|
__MACOSX
|
||||||
|
.DS_Store
|
||||||
|
.vscode
|
||||||
|
krusty.sqlite3
|
64
app/build.gradle.kts
Normal file
64
app/build.gradle.kts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* 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.4/userguide/building_java_projects.html in the Gradle documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
|
application
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Use Maven Central for resolving dependencies.
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
|
||||||
|
testImplementation("org.skyscreamer:jsonassert:1.5.0")
|
||||||
|
testImplementation("com.mashape.unirest:unirest-java:1.4.9")
|
||||||
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.10.2")
|
||||||
|
|
||||||
|
implementation("com.google.guava:guava:32.1.1-jre")
|
||||||
|
implementation("com.sparkjava:spark-core:2.9.4")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-core:2.17.0")
|
||||||
|
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.0")
|
||||||
|
|
||||||
|
implementation("org.slf4j:slf4j-simple:1.7.30")
|
||||||
|
implementation("mysql:mysql-connector-java:8.0.19")
|
||||||
|
implementation("org.xerial:sqlite-jdbc:3.30.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply a specific Java toolchain to ease working on different environments.
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
// Define the main class for the application.
|
||||||
|
mainClass.set("krusty.ServerMain")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named<Test>("test") {
|
||||||
|
// Use JUnit Platform for unit tests.
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.krusty"
|
||||||
|
version = "1.0"
|
||||||
|
description = "Krusty"
|
||||||
|
|
||||||
|
tasks.named<Jar>("jar") {
|
||||||
|
// Make the JAR executable.
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
"Main-Class" to "krusty.ServerMain",
|
||||||
|
"Implementation-Title" to "KrustyCookiesAPI",
|
||||||
|
"Implementation-Version" to version
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
60
app/src/main/java/krusty/Database.java
Normal file
60
app/src/main/java/krusty/Database.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package krusty;
|
||||||
|
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
private static final String jdbcString = "jdbc:sqlite:krusty.sqlite3";
|
||||||
|
|
||||||
|
public void connect() {
|
||||||
|
Connection conn = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(jdbcString);
|
||||||
|
System.out.println("Connection to SQLite has been established.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (conn != null) {
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement and change output in all methods below!
|
||||||
|
|
||||||
|
public String getCustomers(Request req, Response res) {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRawMaterials(Request req, Response res) {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCookies(Request req, Response res) {
|
||||||
|
return "{\"cookies\":[]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRecipes(Request req, Response res) {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPallets(Request req, Response res) {
|
||||||
|
return "{\"pallets\":[]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String reset(Request req, Response res) {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createPallet(Request req, Response res) {
|
||||||
|
return "{}";
|
||||||
|
}
|
||||||
|
}
|
78
app/src/main/java/krusty/Jsonizer.java
Normal file
78
app/src/main/java/krusty/Jsonizer.java
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
package krusty;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import java.io.IOError;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auxiliary class for automatically translating a ResultSet to JSON
|
||||||
|
*/
|
||||||
|
public class Jsonizer {
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
mapper.setDateFormat(df);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert any POJO or plain Java data to JSON supported by Jackson
|
||||||
|
*
|
||||||
|
* @param name name of returned data
|
||||||
|
* @return {name: jackson serialized json representation}
|
||||||
|
*/
|
||||||
|
public static String anythingToJson(Object data, String name) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> entries = new HashMap<>();
|
||||||
|
entries.put(name, data);
|
||||||
|
return mapper.writeValueAsString(entries);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new IOError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert JDBC Result to JSON
|
||||||
|
*
|
||||||
|
* @param rs open and unused ResultSet
|
||||||
|
* @param name name of the resultset
|
||||||
|
* @return JSON object with one entry: {name: result of ResultSet}
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public static String toJson(ResultSet rs, String name) throws SQLException {
|
||||||
|
try {
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
JsonGenerator writer = mapper.getFactory().createGenerator(sw);
|
||||||
|
|
||||||
|
writer.writeStartObject();
|
||||||
|
writer.writeFieldName(name);
|
||||||
|
writer.writeStartArray();
|
||||||
|
while (rs.next()) {
|
||||||
|
writer.writeStartObject();
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
writer.writeFieldName(meta.getColumnLabel(i));
|
||||||
|
writer.writeObject(rs.getObject(i));
|
||||||
|
}
|
||||||
|
writer.writeEndObject();
|
||||||
|
}
|
||||||
|
writer.writeEndArray();
|
||||||
|
writer.writeEndObject();
|
||||||
|
writer.flush();
|
||||||
|
return sw.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
83
app/src/main/java/krusty/ServerMain.java
Normal file
83
app/src/main/java/krusty/ServerMain.java
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
package krusty;
|
||||||
|
|
||||||
|
import java.io.IOError;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import static spark.Spark.*;
|
||||||
|
|
||||||
|
public class ServerMain {
|
||||||
|
public static int PORT = 8888;
|
||||||
|
public static String API_ENTRYPOINT = "/api/v1";
|
||||||
|
|
||||||
|
private Database db;
|
||||||
|
|
||||||
|
public void startServer() {
|
||||||
|
staticFiles.location("/public");
|
||||||
|
|
||||||
|
db = new Database();
|
||||||
|
db.connect();
|
||||||
|
|
||||||
|
port(PORT);
|
||||||
|
|
||||||
|
enableCORS();
|
||||||
|
|
||||||
|
initIndex();
|
||||||
|
initRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initIndex() {
|
||||||
|
try {
|
||||||
|
byte[] indexData = getClass().getResource("/public/index.html").openStream().readAllBytes();
|
||||||
|
final String index = new String(indexData, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
get("/", (req, res) -> index);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRoutes() {
|
||||||
|
get(API_ENTRYPOINT + "/customers", (req, res) -> db.getCustomers(req, res));
|
||||||
|
get(API_ENTRYPOINT + "/raw-materials", (req, res) -> db.getRawMaterials(req, res));
|
||||||
|
get(API_ENTRYPOINT + "/cookies", (req, res) -> db.getCookies(req, res));
|
||||||
|
get(API_ENTRYPOINT + "/recipes", (req, res) -> db.getRecipes(req, res));
|
||||||
|
get(API_ENTRYPOINT + "/pallets", (req, res) -> db.getPallets(req, res));
|
||||||
|
|
||||||
|
post(API_ENTRYPOINT + "/reset", (req, res) -> db.reset(req, res));
|
||||||
|
post(API_ENTRYPOINT + "/pallets", (req, res) -> db.createPallet(req, res));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopServer() {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup CORS, see:
|
||||||
|
* - https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||||
|
* - http://sparkjava.com/tutorials/cors
|
||||||
|
*/
|
||||||
|
private void enableCORS() {
|
||||||
|
options("/*", (request, response) -> {
|
||||||
|
String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers");
|
||||||
|
if (accessControlRequestHeaders != null) {
|
||||||
|
response.header("Access-Control-Allow-Headers", accessControlRequestHeaders);
|
||||||
|
}
|
||||||
|
String accessControlRequestMethod = request.headers("Access-Control-Request-Method");
|
||||||
|
if (accessControlRequestMethod != null) {
|
||||||
|
response.header("Access-Control-Allow-Methods", accessControlRequestMethod);
|
||||||
|
}
|
||||||
|
return "OK";
|
||||||
|
});
|
||||||
|
|
||||||
|
before((request, response) -> {
|
||||||
|
response.header("Access-Control-Allow-Origin", "*");
|
||||||
|
response.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
||||||
|
response.type("application/json");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
new ServerMain().startServer();
|
||||||
|
}
|
||||||
|
}
|
1
app/src/main/resources/public/index.html
Normal file
1
app/src/main/resources/public/index.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"><title>Krusty</title><link href="/static/css/main.59f83d58.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,l=r[0],i=r[1],a=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var i=t[l];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this.webpackJsonpfrontend=this.webpackJsonpfrontend||[],i=l.push.bind(l);l.push=r,l=l.slice();for(var a=0;a<l.length;a++)r(l[a]);var p=i;t()}([])</script><script src="/static/js/2.0a7bcc05.chunk.js"></script><script src="/static/js/main.4ee489f9.chunk.js"></script></body></html>
|
|
@ -0,0 +1,2 @@
|
||||||
|
div.App{width:800px;margin:0 auto}@media screen and (max-width:800px){div.App{width:100%}}body{margin:10px;padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:source-code-pro,Menlo,Monaco,Consolas,"Courier New",monospace}
|
||||||
|
/*# sourceMappingURL=main.59f83d58.chunk.css.map */
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"sources":["index.css"],"names":[],"mappings":"AAAA,QACC,WAAY,CACZ,aACD,CAEA,oCACE,QACE,UACF,CACF,CAEA,KACE,WAAY,CACZ,SAAU,CACV,mJAEY,CACZ,kCAAmC,CACnC,iCACF,CAEA,KACE,yEAEF","file":"main.59f83d58.chunk.css","sourcesContent":["div.App {\n\twidth: 800px;\n\tmargin: 0 auto;\n}\n\n@media screen and (max-width: 800px) {\n div.App {\n width: 100%;\n }\n}\n\nbody {\n margin: 10px;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n"]}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
object-assign
|
||||||
|
(c) Sindre Sorhus
|
||||||
|
@license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A better abstraction over CSS.
|
||||||
|
*
|
||||||
|
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
|
||||||
|
* @website https://github.com/cssinjs/jss
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v0.18.0
|
||||||
|
* scheduler.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v16.12.0
|
||||||
|
* react-dom.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v16.12.0
|
||||||
|
* react-is.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v16.12.0
|
||||||
|
* react.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,2 @@
|
||||||
|
!function(e){function r(r){for(var n,f,l=r[0],i=r[1],a=r[2],c=0,s=[];c<l.length;c++)f=l[c],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,l=1;l<t.length;l++){var i=t[l];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var l=this.webpackJsonpfrontend=this.webpackJsonpfrontend||[],i=l.push.bind(l);l.push=r,l=l.slice();for(var a=0;a<l.length;a++)r(l[a]);var p=i;t()}([]);
|
||||||
|
//# sourceMappingURL=runtime-main.1c2d59f4.js.map
|
File diff suppressed because one or more lines are too long
194
app/src/test/java/krusty/KrustyTests.java
Normal file
194
app/src/test/java/krusty/KrustyTests.java
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
package krusty;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
import org.skyscreamer.jsonassert.JSONAssert;
|
||||||
|
|
||||||
|
import com.mashape.unirest.http.HttpResponse;
|
||||||
|
import com.mashape.unirest.http.Unirest;
|
||||||
|
import com.mashape.unirest.http.exceptions.UnirestException;
|
||||||
|
|
||||||
|
@TestMethodOrder(org.junit.jupiter.api.MethodOrderer.DisplayName.class)
|
||||||
|
public class KrustyTests {
|
||||||
|
public static final String BASE_URL = "http://localhost:" + ServerMain.PORT + ServerMain.API_ENTRYPOINT + "/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Test cases
|
||||||
|
*
|
||||||
|
* Note that they are ordered in alphabetical order,
|
||||||
|
* this because one test case creates pallets that other use.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test01Customers() throws JSONException {
|
||||||
|
String expected = readFile("ExpectedCustomers.json");
|
||||||
|
String actual = getURL("customers");
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test02Cookies() throws JSONException {
|
||||||
|
String expected = readFile("ExpectedCookies.json");
|
||||||
|
String actual = getURL("cookies");
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test03RawMaterials() throws JSONException {
|
||||||
|
String expected = readFile("ExpectedRawMaterialsStart.json");
|
||||||
|
String actual = getURL("raw-materials");
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test04CreatePallets() throws JSONException {
|
||||||
|
createPallet("Nut ring");
|
||||||
|
createPallet("Nut ring");
|
||||||
|
createPallet("Tango");
|
||||||
|
createPallet("Amneris");
|
||||||
|
createPallet("Amneris");
|
||||||
|
createPallet("Amneris");
|
||||||
|
createPallet("Berliner");
|
||||||
|
|
||||||
|
String expected = readFile("ExpectedRawMaterialsAfterCreatingPallets.json");
|
||||||
|
String actual = getURL("raw-materials");
|
||||||
|
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test05Pallets() throws JSONException {
|
||||||
|
String expected = readFile("ExpectedPallets.json");
|
||||||
|
String actual = getURL("pallets");
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test06PalletsByCookie() throws JSONException, UnirestException {
|
||||||
|
String expected = readFile("ExpectedPalletsByCookie.json");
|
||||||
|
String actual = Unirest.get(BASE_URL + "pallets")
|
||||||
|
.queryString("cookie", "Nut ring")
|
||||||
|
.asString().getBody();
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test07PalletsByCookieAndDate() throws JSONException, UnirestException {
|
||||||
|
String expected = readFile("ExpectedPalletsByCookie.json");
|
||||||
|
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
String today = formatter.format(new Date());
|
||||||
|
|
||||||
|
String actual = Unirest.get(BASE_URL + "pallets")
|
||||||
|
.queryString("cookie", "Nut ring")
|
||||||
|
.queryString("from", today)
|
||||||
|
.asString().getBody();
|
||||||
|
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test08PalletsByCookieAndDate2() throws JSONException, UnirestException {
|
||||||
|
String expected = readFile("ExpectedPalletsEmpty.json");
|
||||||
|
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.add(Calendar.YEAR, 1);
|
||||||
|
String nextYear = formatter.format(calendar.getTime());
|
||||||
|
|
||||||
|
String actual = Unirest.get(BASE_URL + "pallets")
|
||||||
|
.queryString("cookie", "Nut ring")
|
||||||
|
.queryString("from", nextYear)
|
||||||
|
.asString().getBody();
|
||||||
|
|
||||||
|
JSONAssert.assertEquals(expected, actual, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Auxiliary methods
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected String readFile(String file) {
|
||||||
|
try {
|
||||||
|
String path = "src/test/resources/" + file;
|
||||||
|
return new String(Files.readAllBytes(Paths.get(path)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getURL(String url) {
|
||||||
|
try {
|
||||||
|
HttpResponse<String> res = Unirest.get(BASE_URL + url).asString();
|
||||||
|
return res.getBody();
|
||||||
|
} catch (UnirestException e) {
|
||||||
|
fail("Connection failed.\n" + e.getMessage());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String createPallet(String cookie) {
|
||||||
|
try {
|
||||||
|
HttpResponse<String> res = Unirest.post(BASE_URL + "pallets")
|
||||||
|
.queryString("cookie", cookie)
|
||||||
|
.asString();
|
||||||
|
return res.getBody();
|
||||||
|
} catch (UnirestException e) {
|
||||||
|
fail("Connection failed.\n" + e.getMessage());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Automatically start REST server if it is not running and reset database.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static ServerMain server;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void startServer() throws InterruptedException {
|
||||||
|
try {
|
||||||
|
// Check if rest server is running
|
||||||
|
Unirest.get(BASE_URL).asString();
|
||||||
|
} catch (UnirestException e) {
|
||||||
|
// Start REST server and sleep a bit before start running test cases
|
||||||
|
server = new ServerMain();
|
||||||
|
server.startServer();
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset database
|
||||||
|
try {
|
||||||
|
Unirest.post(BASE_URL + "reset").asString();
|
||||||
|
} catch (UnirestException e2) {
|
||||||
|
fail(e2.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void stopServer() {
|
||||||
|
if (server != null) {
|
||||||
|
server.stopServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
app/src/test/resources/ExpectedCookies.json
Normal file
10
app/src/test/resources/ExpectedCookies.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cookies": [
|
||||||
|
{"name": "Amneris"},
|
||||||
|
{"name": "Berliner"},
|
||||||
|
{"name": "Nut cookie"},
|
||||||
|
{"name": "Nut ring"},
|
||||||
|
{"name": "Tango"},
|
||||||
|
{"name": "Almond delight"}
|
||||||
|
]
|
||||||
|
}
|
12
app/src/test/resources/ExpectedCustomers.json
Normal file
12
app/src/test/resources/ExpectedCustomers.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"customers": [
|
||||||
|
{"name": "Bjudkakor AB", "address": "Ystad"},
|
||||||
|
{"name": "Finkakor AB", "address": "Helsingborg"},
|
||||||
|
{"name": "Gästkakor AB", "address": "Hässleholm"},
|
||||||
|
{"name": "Kaffebröd AB", "address": "Landskrona"},
|
||||||
|
{"name": "Kalaskakor AB", "address": "Trelleborg"},
|
||||||
|
{"name": "Partykakor AB", "address": "Kristianstad"},
|
||||||
|
{"name": "Skånekakor AB", "address": "Perstorp"},
|
||||||
|
{"name": "Småbröd AB", "address": "Malmö"}
|
||||||
|
]
|
||||||
|
}
|
11
app/src/test/resources/ExpectedPallets.json
Normal file
11
app/src/test/resources/ExpectedPallets.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"pallets": [
|
||||||
|
{"cookie": "Amneris", "blocked": "no"},
|
||||||
|
{"cookie": "Amneris", "blocked": "no"},
|
||||||
|
{"cookie": "Amneris", "blocked": "no"},
|
||||||
|
{"cookie": "Berliner", "blocked": "no"},
|
||||||
|
{"cookie": "Nut ring", "blocked": "no"},
|
||||||
|
{"cookie": "Nut ring", "blocked": "no"},
|
||||||
|
{"cookie": "Tango", "blocked": "no"}
|
||||||
|
]
|
||||||
|
}
|
6
app/src/test/resources/ExpectedPalletsByCookie.json
Normal file
6
app/src/test/resources/ExpectedPalletsByCookie.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"pallets": [
|
||||||
|
{"cookie": "Nut ring", "blocked": "no"},
|
||||||
|
{"cookie": "Nut ring", "blocked": "no"}
|
||||||
|
]
|
||||||
|
}
|
4
app/src/test/resources/ExpectedPalletsEmpty.json
Normal file
4
app/src/test/resources/ExpectedPalletsEmpty.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"pallets": [
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"raw-materials": [
|
||||||
|
{"name": "Bread crumbs", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Butter", "amount": 386600, "unit": "g"},
|
||||||
|
{"name": "Chocolate", "amount": 497300, "unit": "g"},
|
||||||
|
{"name": "Chopped almonds", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Cinnamon", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Egg whites", "amount": 500000, "unit": "ml"},
|
||||||
|
{"name": "Eggs", "amount": 456800, "unit": "g"},
|
||||||
|
{"name": "Fine-ground nuts", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Flour", "amount": 416300, "unit": "g"},
|
||||||
|
{"name": "Ground, roasted nuts", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Icing sugar", "amount": 474080, "unit": "g"},
|
||||||
|
{"name": "Marzipan", "amount": 378500, "unit": "g"},
|
||||||
|
{"name": "Potato starch", "amount": 495950, "unit": "g"},
|
||||||
|
{"name": "Roasted, chopped nuts", "amount": 475700, "unit": "g"},
|
||||||
|
{"name": "Sodium bicarbonate", "amount": 499784, "unit": "g"},
|
||||||
|
{"name": "Sugar", "amount": 486500, "unit": "g"},
|
||||||
|
{"name": "Vanilla", "amount": 499892, "unit": "g"},
|
||||||
|
{"name": "Vanilla sugar", "amount": 499730, "unit": "g"},
|
||||||
|
{"name": "Wheat flour", "amount": 495950, "unit": "g"}
|
||||||
|
]
|
||||||
|
}
|
23
app/src/test/resources/ExpectedRawMaterialsStart.json
Normal file
23
app/src/test/resources/ExpectedRawMaterialsStart.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"raw-materials": [
|
||||||
|
{"name": "Bread crumbs", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Butter", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Chocolate", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Chopped almonds", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Cinnamon", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Egg whites", "amount": 500000, "unit": "ml"},
|
||||||
|
{"name": "Eggs", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Fine-ground nuts", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Flour", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Ground, roasted nuts", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Icing sugar", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Marzipan", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Potato starch", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Roasted, chopped nuts", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Sodium bicarbonate", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Sugar", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Vanilla", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Vanilla sugar", "amount": 500000, "unit": "g"},
|
||||||
|
{"name": "Wheat flour", "amount": 500000, "unit": "g"}
|
||||||
|
]
|
||||||
|
}
|
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.4-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
249
gradlew
vendored
Executable file
249
gradlew
vendored
Executable file
|
@ -0,0 +1,249 @@
|
||||||
|
#!/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.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# 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/subprojects/plugins/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 "${APP_HOME:-./}" > /dev/null && pwd -P ) || 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=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# 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, 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" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# 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" "$@"
|
92
gradlew.bat
vendored
Normal file
92
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
@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
|
||||||
|
|
||||||
|
@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.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
: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
|
10
makefile
Normal file
10
makefile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
run:
|
||||||
|
./gradlew run
|
||||||
|
|
||||||
|
clean:
|
||||||
|
./gradlew clean
|
||||||
|
|
||||||
|
test:
|
||||||
|
./gradlew test
|
||||||
|
|
||||||
|
.PHONY: run clean test
|
14
settings.gradle.kts
Normal file
14
settings.gradle.kts
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.4/userguide/building_swift_projects.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.7.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = "CrustyCookiesAPI"
|
||||||
|
include("app")
|
Loading…
Reference in a new issue