Added example project and Ant file for the Makefile generator project.

This commit is contained in:
LoRd_MuldeR 2020-10-02 14:52:23 +02:00
parent ce03d84430
commit 7a66aedfff
11 changed files with 140 additions and 32 deletions

6
etc/example/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/.classpath
/.project
/.settings
/bin
/build
/dist

29
etc/example/build.xml Normal file
View File

@ -0,0 +1,29 @@
<project name="com.muldersoft.l5j.example" default="dist" basedir=".">
<description>Launch5j example code</description>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<mkdir dir="${dist}"/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source">
<javac srcdir="${src}" destdir="${build}" source="1.8" target="1.8" debuglevel="lines,vars,source" includeantruntime="false"/>
</target>
<target name="dist" depends="clean,compile" description="generate the distribution">
<jar destfile="${dist}/example.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="com.muldersoft.l5j.example.Main"/>
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

View File

@ -0,0 +1,64 @@
/************************************************************/
/* Launch5j, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* 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;
}
}

6
etc/makefile-generator/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/.classpath
/.project
/.settings
/bin
/build
/dist

View File

@ -0,0 +1,31 @@
<project name="com.muldersoft.l5j.makefile.generator" default="dist" basedir=".">
<description>Launch5j example code</description>
<property name="src" location="src"/>
<property name="res" location="res"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<mkdir dir="${dist}"/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init" description="compile the source">
<javac srcdir="${src}" destdir="${build}" source="1.8" target="1.8" debuglevel="lines,vars,source" includeantruntime="false"/>
</target>
<target name="dist" depends="clean,compile" description="generate the distribution">
<jar destfile="${dist}/generator.jar" basedir="${build}">
<fileset dir="${res}" includes="/.assets/**/*"/>
<manifest>
<attribute name="Main-Class" value="com.muldersoft.l5j.makefile.Generator"/>
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>

View File

@ -11,6 +11,8 @@
/* https://sourceforge.net/p/launch4j/ */ /* https://sourceforge.net/p/launch4j/ */
/************************************************************/ /************************************************************/
package com.muldersoft.l5j.makefile;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -24,7 +26,7 @@ import java.util.regex.Pattern;
/* /*
* Helper program to generate the Makefile rules for Launch5j * Helper program to generate the Makefile rules for Launch5j
*/ */
public class MakefileGenerator { public class Generator {
private final static String EMPTY = ""; private final static String EMPTY = "";
private final static Pattern RTRIM = Pattern.compile("\\s+$"); 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 { 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) { if(in == null) {
throw new IOException("Failed to open '" + name + "' template file!"); throw new IOException("Failed to open '" + name + "' template file!");
} }

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="res"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,2 +0,0 @@
/.settings
/bin

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MakefileGenerator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>