Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
First colored edition (not tested on Windows!); updated a few Message…
Browse files Browse the repository at this point in the history
…s; removed UpdaterTest (again and maybe finally)
  • Loading branch information
menzerath committed Aug 9, 2014
1 parent d949fd1 commit 6d2fdff
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 53 deletions.
16 changes: 9 additions & 7 deletions src/main/java/eu/menzerath/imwd/ConsoleApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import eu.menzerath.util.Helper;
import eu.menzerath.util.Messages;
import eu.menzerath.util.Updater;
import org.fusesource.jansi.Ansi;

public class ConsoleApplication {
private String url;
Expand All @@ -25,7 +26,7 @@ public ConsoleApplication(String url, String interval, boolean createLog) {
this.createLog = createLog;
run();
} else {
System.out.println(Messages.INVALID_PARAMETERS);
System.out.println(new Ansi().bold().fg(Ansi.Color.RED).a("Error: ").fg(Ansi.Color.DEFAULT).a(Messages.INVALID_PARAMETERS).boldOff());
System.exit(1);
}
}
Expand All @@ -38,7 +39,7 @@ private void run() {
updateCheck();

// Display the used values
System.out.println(Messages.CONSOLE_START);
System.out.println(new Ansi().bold().a(Messages.CONSOLE_START).boldOff());
System.out.println("URL: " + url);
System.out.println("Interval: " + interval + "s");
System.out.println("Log-File: " + createLog + "\n");
Expand All @@ -52,15 +53,16 @@ private void run() {
* An update-check for the "ConsoleApplication": If there is an update available, it will show an url to get the update.
*/
private void updateCheck() {
Ansi a = new Ansi();

Updater myUpdater = new Updater();
if (myUpdater.getServerVersion().equalsIgnoreCase("Error")) {
System.out.println(Messages.UPDATE_ERROR + "\n");
System.out.println(a.fg(Ansi.Color.RED).a(Messages.UPDATE_ERROR).fg(Ansi.Color.DEFAULT) + "\n");
} else if (myUpdater.getServerVersion().equals("SNAPSHOT")) {
System.out.println(Messages.UPDATE_SNAPSHOT + "\n");
System.out.println(a.fg(Ansi.Color.RED).a(Messages.UPDATE_SNAPSHOT).fg(Ansi.Color.DEFAULT) + "\n");
} else if (myUpdater.isUpdateAvailable()) {
System.out.println(Messages.UPDATE_AVAILABLE.replace("%version", myUpdater.getServerVersion()));
System.out.println(Messages.UPDATE_AVAILABLE_CHANGES.replace("%changes", myUpdater.getServerChangelog()));
System.out.println(Messages.UPDATE_MANUAL.replace("%version", myUpdater.getServerVersion()) + "\n");
System.out.println(a.fg(Ansi.Color.RED).bold().a(Messages.UPDATE_AVAILABLE.replace("%version", myUpdater.getServerVersion())).fg(Ansi.Color.DEFAULT).boldOff());
System.out.println(Messages.UPDATE_AVAILABLE_CHANGES.replace("%changes", myUpdater.getServerChangelog()) + "\n");
}
}
}
20 changes: 16 additions & 4 deletions src/main/java/eu/menzerath/imwd/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package eu.menzerath.imwd;

import eu.menzerath.util.Messages;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;

import java.awt.*;

Expand All @@ -21,16 +23,18 @@ public class Main {
* @param args Passed arguments for start
*/
public static void main(String[] args) {
AnsiConsole.systemInstall();

if (args.length == 0) { // Running on a setup without graphical desktop and no arguments passed: show the needed arguments
if (GraphicsEnvironment.isHeadless()) {
System.out.println(Messages.CONSOLE_HELP);
printHelp();
System.exit(1);
} else { // Otherwise: Open the GUI
GuiApplication.startGUI();
}
} else if (args.length == 1 && args[0].equalsIgnoreCase("--help")) { // Give the user some help
sayHello();
System.out.println(Messages.CONSOLE_HELP);
printHelp();
} else if (args.length == 2) { // Start a ConsoleApplication and create a Log-File
new ConsoleApplication(args[0].trim(), args[1].trim(), true);
} else if (args.length == 3 && args[2].equalsIgnoreCase("--nolog")) { // Start a ConsoleApplication but do not create a Log-File
Expand All @@ -39,7 +43,7 @@ public static void main(String[] args) {
new QuickTest(args[0].trim()).run();
} else { // Something went wrong (blame the user!)
sayHello();
System.out.println(Messages.CONSOLE_HELP);
printHelp();
}
}

Expand All @@ -51,10 +55,18 @@ public static void sayHello() {
for (int i = lineVersion.length(); i < 42; i++) lineVersion += " ";

System.out.println("##################################################");
System.out.println("### " + lineVersion + " ###");
System.out.println("### " + new Ansi().fg(Ansi.Color.GREEN).bold().a(lineVersion).fg(Ansi.Color.DEFAULT).boldOff() + " ###");
System.out.println("### ###");
System.out.println("### " + Messages.COPYRIGHT + " ###");
System.out.println("### " + URL.substring(8) + " ###");
System.out.println("##################################################\n");
}

/**
* Gives the user a colored help-message including a few examples
*/
public static void printHelp() {
System.out.println(new Ansi().bold().a(Messages.CONSOLE_HELP).boldOff());
System.out.println(Messages.CONSOLE_HELP_EXAMPLES);
}
}
3 changes: 2 additions & 1 deletion src/main/java/eu/menzerath/imwd/QuickTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.menzerath.util.Helper;
import eu.menzerath.util.Messages;
import org.fusesource.jansi.Ansi;

public class QuickTest {
private String url;
Expand All @@ -15,7 +16,7 @@ public QuickTest(String url) {
if (Helper.validateUrlInput(url)) {
this.url = url;
} else {
System.out.println(Messages.INVALID_PARAMETERS);
System.out.println(new Ansi().bold().fg(Ansi.Color.RED).a("Error: ").fg(Ansi.Color.DEFAULT).a(Messages.INVALID_PARAMETERS).boldOff());
System.exit(1);
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/eu/menzerath/util/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.menzerath.imwd.Checker;
import eu.menzerath.imwd.GuiApplication;
import org.fusesource.jansi.Ansi;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -35,30 +36,30 @@ public Logger(Checker checker, boolean createFile, boolean logValidChecks, boole
* The Checker started it's work
*/
public void start() {
write(getLogHead() + "[INFO] " + Messages.LOG_START.replace("%url", CHECKER.URL).replace("%interval", "" + CHECKER.INTERVAL));
write(getLogHead() + new Ansi().fg(Ansi.Color.CYAN).a("[INFO] ").fg(Ansi.Color.DEFAULT) + Messages.LOG_START.replace("%url", CHECKER.URL).replace("%interval", "" + CHECKER.INTERVAL));
}

/**
* This was a successful check
*/
public void ok() {
if (LOG_VALID_CHECKS) write(getLogHead() + "[OK] " + Messages.LOG_OK);
if (LOG_VALID_CHECKS) write(getLogHead() + new Ansi().fg(Ansi.Color.GREEN).a("[OK] ").fg(Ansi.Color.DEFAULT) + Messages.LOG_OK);
updateGui(1);
}

/**
* This is only a warning - it might get worse
*/
public void warning() {
write(getLogHead() + "[WARNING] " + Messages.LOG_PING_ONLY);
write(getLogHead() + new Ansi().fg(Ansi.Color.YELLOW).a("[WARNING] ").fg(Ansi.Color.DEFAULT) + Messages.LOG_PING_ONLY);
updateGui(2);
}

/**
* Website is gone
*/
public void error() {
write(getLogHead() + "[ERROR] " + Messages.LOG_ERROR);
write(getLogHead() + new Ansi().fg(Ansi.Color.RED).a("[ERROR] ").fg(Ansi.Color.DEFAULT) + Messages.LOG_ERROR);
updateGui(3);
}

Expand All @@ -71,7 +72,7 @@ public void noConnection() {
updateGui(4);
return;
}
write(getLogHead().replace("[0]", "[A]") + "[ERROR] " + Messages.LOG_NO_CONNECTION);
write(getLogHead().replace("[0]", "[A]") + new Ansi().fg(Ansi.Color.RED).a("[ERROR] ").fg(Ansi.Color.DEFAULT) + Messages.LOG_NO_CONNECTION);
updateGui(4);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/eu/menzerath/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
public class Messages {
// START: Main
public static final String COPYRIGHT = "© 2012-2014: Marvin Menzerath";
public static final String CONSOLE_HELP = "You have to use the following syntax: java -jar IMWD.jar [URL] [INTERVAL] {ARG}\nExamples:\n java -jar IMWD.jar\n java -jar IMWD.jar http://website.com 30\n java -jar IMWD.jar http://website.com 30 --nolog\n java -jar IMWD.jar http://website.com 0 --once";
public static final String INVALID_PARAMETERS = "Sorry, but you have to enter a valid url (including the specific protocol) and interval (numbers only - between " + Main.MIN_INTERVAL + " and " + Main.MAX_INTERVAL + " seconds).";
public static final String CONSOLE_HELP = "You have to use the following syntax: java -jar IMWD.jar [URL] [INTERVAL] {ARG}";
public static final String CONSOLE_HELP_EXAMPLES = "Examples:\n java -jar IMWD.jar\n java -jar IMWD.jar http://website.com 30\n java -jar IMWD.jar http://website.com 30 --nolog\n java -jar IMWD.jar http://website.com 0 --once";
public static final String INVALID_PARAMETERS = "You have to enter a valid url (including the specific protocol) and interval (numbers only - between " + Main.MIN_INTERVAL + " and " + Main.MAX_INTERVAL + " seconds).";
// END: Main

// START: Message-Bubbles
Expand Down Expand Up @@ -42,10 +43,9 @@ public class Messages {
public static final String UPDATE_NO_UPDATE_LONG = "You are running the latest version of \"" + Main.APPLICATION + "\" (v" + Main.VERSION + ").";
public static final String UPDATE_ERROR = "Unable to search for Updates. Please visit \"" + Main.URL_RELEASE + "\".";
public static final String UPDATE_SNAPSHOT = "This is a SNAPSHOT-Release. The Updater is therefore deactivated!\nPlease visit \"" + Main.URL_RELEASE + "\".";
public static final String UPDATE_AVAILABLE_TITLE = "Update available";
public static final String UPDATE_AVAILABLE = "There is an Update for " + Main.APPLICATION_SHORT + " to version %version available.";
public static final String UPDATE_AVAILABLE_CHANGES = "Changes: %changes\nVisit \"" + Main.URL_RELEASE + "\" for a full Changelog.";
public static final String UPDATE_AVAILABLE_TITLE = "Update available!";
public static final String UPDATE_AVAILABLE = "There is an Update to version %version available.";
public static final String UPDATE_AVAILABLE_CHANGES = "Changes: %changes\nVisit \"" + Main.URL_RELEASE + "\" for a full Changelog and to Download this Update.";
public static final String UPDATE_NOW = "Do you want to Download it now?";
public static final String UPDATE_MANUAL = "Download Update using \"wget " + Main.URL_RELEASE + "/download/v%version/IMWD.jar\".";
// END: Updates
}
30 changes: 0 additions & 30 deletions src/test/java/eu/menzerath/util/UpdaterTest.java

This file was deleted.

0 comments on commit 6d2fdff

Please sign in to comment.