From 9ca95838eb6c766f728952b309eb33b27a5e53fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 20 May 2014 22:16:11 +0200 Subject: [PATCH] makefile in root; cli args; --help, --silent, --warnings --- build/Makefile => Makefile | 30 +++++++----- README.md | 7 ++- src/mightypork/gamecore/core/BaseApp.java | 6 ++- src/mightypork/rogue/Launcher.java | 56 ++++++++++++++++++----- 4 files changed, 71 insertions(+), 28 deletions(-) rename build/Makefile => Makefile (55%) diff --git a/build/Makefile b/Makefile similarity index 55% rename from build/Makefile rename to Makefile index 300d96a..1162cd7 100644 --- a/build/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ -STUB = ./stub.jar +STUB = ./build/stub.jar -IN_DIR = ./in +IN_DIR = ./build/in IN = $(IN_DIR)/build.jar -OUT_DIR = ./out +OUT_DIR = ./build/out OUT = $(OUT_DIR)/release.jar -TMP_DIR = ./tmp +TMP_DIR = ./build/tmp -all: $(OUT) +all: build + +build: $(OUT) $(OUT): $(IN) $(STUB) # clean @@ -31,13 +33,19 @@ $(OUT): $(IN) $(STUB) # clean rm -rf $(TMP_DIR) - -run: $(OUT) - java -jar $(OUT) -w ../.rogue-save -clean: - rm -rf $(OUT) +run: $(OUT) + java -jar $(OUT) -w .rogue-save + +debug: $(OUT) + java -jar $(OUT) -w .rogue-save --verbose + +runs: $(OUT) + java -jar $(OUT) -w .rogue-save --silent + +runh: $(OUT) + java -jar $(OUT) -w .rogue-save --help deploy: $(OUT) - cp -f $(OUT) /home/ondra/Dokumenty/Dropbox/Public/Rogue + cp -f $(OUT) /home/ondra/Dropbox/Public/Rogue diff --git a/README.md b/README.md index 9be6058..2d139e2 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,9 @@ Manual on [Google Drive](https://docs.google.com/document/d/1Ak9oVOnCKSqWux4Hm_- ## BUILDING FROM SOURCE -1. Export a jar with the `mightypork.*` packages and the `res` folder into `./build/in/build.jar` -2. CD into `./build` -3. Run `make` to create a stand-alone executable jar in `./build/out/release.jar` -4. Use `make run` to execute it +1. Export a jar with the `mightypork.*` packages and the `res` folder into `build/in/build.jar` +2. Run `make` to create a stand-alone executable jar in `build/out/release.jar` +3. Use `make run` to execute it diff --git a/src/mightypork/gamecore/core/BaseApp.java b/src/mightypork/gamecore/core/BaseApp.java index 853eea1..4231d8f 100644 --- a/src/mightypork/gamecore/core/BaseApp.java +++ b/src/mightypork/gamecore/core/BaseApp.java @@ -70,6 +70,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { private ResourceLoader resourceLoader = new AsyncResourceLoader(); private Level logLevel = Level.ALL; public boolean sigleInstance; + private Level logSoutLevel; public void setConfigFile(String filename, String comment) @@ -136,9 +137,10 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { } - public void setLogLevel(Level logLevel) + public void setLogLevel(Level logLevel, Level soutLevel) { this.logLevel = logLevel; + this.logSoutLevel = soutLevel; } } @@ -229,7 +231,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { final LogWriter log = Log.create(opt.logFilePrefix, new File(WorkDir.getDir(opt.logDir), opt.logFilePrefix + ".log"), opt.logArchiveCount); Log.setMainLogger(log); Log.setLevel(opt.logLevel); - Log.setSysoutLevel(opt.logLevel); + Log.setSysoutLevel(opt.logSoutLevel); // connect slickutil to the logger org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log)); diff --git a/src/mightypork/rogue/Launcher.java b/src/mightypork/rogue/Launcher.java index 22e4b29..14db4a3 100644 --- a/src/mightypork/rogue/Launcher.java +++ b/src/mightypork/rogue/Launcher.java @@ -6,7 +6,6 @@ import java.util.Arrays; import java.util.logging.Level; import mightypork.gamecore.core.BaseApp; -import mightypork.gamecore.logging.Log; import mightypork.gamecore.util.files.OsUtils; @@ -19,9 +18,10 @@ public class Launcher { */ public static void main(String[] args) { - Log.f3("Arguments: " + Arrays.toString(args)); + System.out.println("argv = " + Arrays.toString(args)+"\n"); - boolean verbose = false; + Level llSyso = Level.FINER; + Level llFile = Level.ALL; File workdir = null; @@ -37,11 +37,27 @@ public class Launcher { lwdDir = args[i + 1]; i++; continue; - } - - if (arg.equals("--verbose") || arg.equals("-v")) { - verbose = true; + + } else if (arg.equals("--silent") || arg.equals("-s")) { + llSyso = Level.OFF; + continue; + + } else if (arg.equals("--warnings") || arg.equals("-e")) { + llSyso = Level.WARNING; continue; + + } else if (arg.equals("--verbose") || arg.equals("-v")) { + llSyso = Level.ALL; + continue; + + } else if (arg.equals("--help") || arg.equals("-h")) { + printHelp(); + System.exit(0); + + } else { + System.err.println("Unknown argument: " + arg); + printHelp(); + System.exit(1); } } @@ -51,14 +67,32 @@ public class Launcher { workdir = new File(lwdDir); } - } catch (final ArrayIndexOutOfBoundsException e) { - Log.e("Malformed arguments."); + } catch (final Exception e) { + System.out.println("Error parsing arguments:"); + e.printStackTrace(); + printHelp(); + System.exit(1); } final BaseApp app = new RogueApp(workdir, true); - app.opt().setLogLevel(verbose ? Level.ALL : Level.FINER); - + app.opt().setLogLevel(llFile, llSyso); + + System.out.println("\nStarting the game...\n"); app.start(); } + + + private static void printHelp() + { + //@formatter:off + System.out.println( + "Arguments:\n" + + "\t--workdir , -w .... specify working directory\n" + + "\t--verbose, -v .................. print all messages\n" + + "\t--silent, -s ................... print no messages\n" + + "\t--warnings, -e ................. print only warning and error messages\n" + + "\t--help, -h ..................... show this help\n"); + //@formatter:on + } }