From 7a66aedfff5e7860eab2dc222ff15b0deafb0a40 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 2 Oct 2020 14:52:23 +0200 Subject: [PATCH] Added example project and Ant file for the Makefile generator project. --- etc/example/.gitignore | 6 ++ etc/example/build.xml | 29 +++++++++ .../src/com/muldersoft/l5j/example/Main.java | 64 +++++++++++++++++++ etc/makefile-generator/.gitignore | 6 ++ etc/makefile-generator/build.xml | 31 +++++++++ .../res/.assets}/templates/footer.mak | 0 .../res/.assets}/templates/header.mak | 0 .../muldersoft/l5j/makefile/Generator.java} | 6 +- etc/utils/MakefileGenerator/.classpath | 11 ---- etc/utils/MakefileGenerator/.gitignore | 2 - etc/utils/MakefileGenerator/.project | 17 ----- 11 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 etc/example/.gitignore create mode 100644 etc/example/build.xml create mode 100644 etc/example/src/com/muldersoft/l5j/example/Main.java create mode 100644 etc/makefile-generator/.gitignore create mode 100644 etc/makefile-generator/build.xml rename etc/{utils/MakefileGenerator/res => makefile-generator/res/.assets}/templates/footer.mak (100%) rename etc/{utils/MakefileGenerator/res => makefile-generator/res/.assets}/templates/header.mak (100%) rename etc/{utils/MakefileGenerator/src/MakefileGenerator.java => makefile-generator/src/com/muldersoft/l5j/makefile/Generator.java} (96%) delete mode 100644 etc/utils/MakefileGenerator/.classpath delete mode 100644 etc/utils/MakefileGenerator/.gitignore delete mode 100644 etc/utils/MakefileGenerator/.project diff --git a/etc/example/.gitignore b/etc/example/.gitignore new file mode 100644 index 0000000..81bc9b5 --- /dev/null +++ b/etc/example/.gitignore @@ -0,0 +1,6 @@ +/.classpath +/.project +/.settings +/bin +/build +/dist diff --git a/etc/example/build.xml b/etc/example/build.xml new file mode 100644 index 0000000..e968470 --- /dev/null +++ b/etc/example/build.xml @@ -0,0 +1,29 @@ + + Launch5j example code + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/example/src/com/muldersoft/l5j/example/Main.java b/etc/example/src/com/muldersoft/l5j/example/Main.java new file mode 100644 index 0000000..a5979c4 --- /dev/null +++ b/etc/example/src/com/muldersoft/l5j/example/Main.java @@ -0,0 +1,64 @@ +/************************************************************/ +/* Launch5j, by LoRd_MuldeR */ +/* Java JAR wrapper for creating Windows native executables */ +/* https://github.com/lordmulder/ */ +/* */ +/* The sample code in this file has been released under the */ +/* CC0 1.0 Universal license. */ +/* https://creativecommons.org/publicdomain/zero/1.0/ */ +/************************************************************/ + +package com.muldersoft.l5j.example; + +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import javax.swing.JOptionPane; + +public class Main { + public static void main(final String[] args) { + initCommandlineArgs(args); + final String message = String.format( + "Hello world!\nRunning on Java %s\n\nCommand-line args:\n%s", + System.getProperty("java.version", "(unknown)"), + dumpCommandLine(args)); + JOptionPane.showMessageDialog(null, message, "Launch5j", JOptionPane.INFORMATION_MESSAGE); + } + + private static void initCommandlineArgs(final String[] argv) { + if (System.getProperty("l5j.pid") == null) { + return; /*nothing to do*/ + } + final String enc = StandardCharsets.UTF_8.name(); + for (int i = 0; i < argv.length; ++i) { + try { + argv[i] = URLDecoder.decode(argv[i], enc); + } catch (Exception e) { } + } + } + + private static String dumpCommandLine(final String[] argv) { + final StringBuilder sb = new StringBuilder(); + final Pattern pattern = Pattern.compile(Pattern.quote("\"")); + int argc = 0; + for (final String str : argv) { + sb.append(String.format( + needQuotes(str) ? "argv[%d] = \"%s\"\n" : "argv[%d] = %s\n", + argc++, pattern.matcher(str).replaceAll("\\\\\""))); + } + return (sb.length() > 0) ? sb.toString() : "(none)"; + } + + private static boolean needQuotes(final String arg) { + if((arg == null) || arg.isEmpty()) { + return true; + } + for (int i = 0; i < arg.length(); ++i) { + if (Character.isSpaceChar(arg.charAt(i))) { + return true; + } + } + return false; + } +} diff --git a/etc/makefile-generator/.gitignore b/etc/makefile-generator/.gitignore new file mode 100644 index 0000000..81bc9b5 --- /dev/null +++ b/etc/makefile-generator/.gitignore @@ -0,0 +1,6 @@ +/.classpath +/.project +/.settings +/bin +/build +/dist diff --git a/etc/makefile-generator/build.xml b/etc/makefile-generator/build.xml new file mode 100644 index 0000000..69968bb --- /dev/null +++ b/etc/makefile-generator/build.xml @@ -0,0 +1,31 @@ + + Launch5j example code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/utils/MakefileGenerator/res/templates/footer.mak b/etc/makefile-generator/res/.assets/templates/footer.mak similarity index 100% rename from etc/utils/MakefileGenerator/res/templates/footer.mak rename to etc/makefile-generator/res/.assets/templates/footer.mak diff --git a/etc/utils/MakefileGenerator/res/templates/header.mak b/etc/makefile-generator/res/.assets/templates/header.mak similarity index 100% rename from etc/utils/MakefileGenerator/res/templates/header.mak rename to etc/makefile-generator/res/.assets/templates/header.mak diff --git a/etc/utils/MakefileGenerator/src/MakefileGenerator.java b/etc/makefile-generator/src/com/muldersoft/l5j/makefile/Generator.java similarity index 96% rename from etc/utils/MakefileGenerator/src/MakefileGenerator.java rename to etc/makefile-generator/src/com/muldersoft/l5j/makefile/Generator.java index e6e23c2..40c93e2 100644 --- a/etc/utils/MakefileGenerator/src/MakefileGenerator.java +++ b/etc/makefile-generator/src/com/muldersoft/l5j/makefile/Generator.java @@ -11,6 +11,8 @@ /* https://sourceforge.net/p/launch4j/ */ /************************************************************/ +package com.muldersoft.l5j.makefile; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -24,7 +26,7 @@ import java.util.regex.Pattern; /* * Helper program to generate the Makefile rules for Launch5j */ -public class MakefileGenerator { +public class Generator { private final static String EMPTY = ""; private final static Pattern RTRIM = Pattern.compile("\\s+$"); @@ -57,7 +59,7 @@ public class MakefileGenerator { } private static void outputTemplate(final PrintStream out, final String name) throws IOException { - try(final InputStream in = MakefileGenerator.class.getResourceAsStream(String.format("/templates/%s.mak", name))) { + try(final InputStream in = Generator.class.getResourceAsStream(String.format("/.assets/templates/%s.mak", name))) { if(in == null) { throw new IOException("Failed to open '" + name + "' template file!"); } diff --git a/etc/utils/MakefileGenerator/.classpath b/etc/utils/MakefileGenerator/.classpath deleted file mode 100644 index 02507f3..0000000 --- a/etc/utils/MakefileGenerator/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/etc/utils/MakefileGenerator/.gitignore b/etc/utils/MakefileGenerator/.gitignore deleted file mode 100644 index 249a49e..0000000 --- a/etc/utils/MakefileGenerator/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/.settings -/bin diff --git a/etc/utils/MakefileGenerator/.project b/etc/utils/MakefileGenerator/.project deleted file mode 100644 index b1aa838..0000000 --- a/etc/utils/MakefileGenerator/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - MakefileGenerator - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - -