diff --git a/.gitattributes b/.gitattributes index 82b366934..ad0584b01 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,6 +33,8 @@ # Batch files *.sh text eol=lf +ffdec text eol=lf +ffdec-cli text eol=lf *.bat text eol=crlf # PHP scripts diff --git a/.gitignore b/.gitignore index abe9ff8b2..1863c4c21 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,10 @@ exported1.all.bin /libsrc/miterstroke/nbproject/private/ /libsrc/miterstroke/build/ /libsrc/miterstroke/dist/ +/libsrc/ffdec_cli/build/ +/libsrc/ffdec_cli/nbproject/private/ +/libsrc/ffdec_cli/javadoc/ +/libsrc/ffdec_cli/coverage/ +/libsrc/ffdec_cli/reports/ +/libsrc/ffdec_cli/dist/ +/libsrc/ffdec_cli/coverage.ec \ No newline at end of file diff --git a/build.properties b/build.properties index 93d29bfb7..82d9d8680 100644 --- a/build.properties +++ b/build.properties @@ -77,6 +77,7 @@ Key Features: \n \ app.installer.dir = mac/installer app.bundle.dir = mac/bundle +cli.script = libsrc/ffdec_cli/build.xml #------------- COMMMON SCRIPT PROPERTIES, supposed not to change ------------- diff --git a/build.xml b/build.xml index 936729920..60ec8b22f 100644 --- a/build.xml +++ b/build.xml @@ -558,6 +558,8 @@ + + @@ -701,6 +703,7 @@ + @@ -962,6 +965,10 @@ + + + + diff --git a/libsrc/ffdec_cli/antlib/jacocoant.jar b/libsrc/ffdec_cli/antlib/jacocoant.jar new file mode 100644 index 000000000..fce63087c Binary files /dev/null and b/libsrc/ffdec_cli/antlib/jacocoant.jar differ diff --git a/libsrc/ffdec_cli/antlib/testng-6.8.jar b/libsrc/ffdec_cli/antlib/testng-6.8.jar new file mode 100644 index 000000000..dd6c8bbf3 Binary files /dev/null and b/libsrc/ffdec_cli/antlib/testng-6.8.jar differ diff --git a/libsrc/ffdec_cli/build.properties b/libsrc/ffdec_cli/build.properties new file mode 100644 index 000000000..4dfe77317 --- /dev/null +++ b/libsrc/ffdec_cli/build.properties @@ -0,0 +1,36 @@ +run.params = + +builder = jpexs +project.name = FFDec_Cli + +prefix.filename = ffdec-cli +target.java = 1.8 + + +src.dir = src +test.dir = test +test.lib.dir = testlib +test.result.dir = reports/tests +coverage.result.dir = reports/coverage +dist.dir = dist +compile.dir = build/classes +coverage.dir = coverage +compile.test.dir = build/test +lib.dir = ../../lib +liblib.dir = lib +releases.dir = releases +properties.name = project.properties +dist.lib.dirname = lib +javadoc.dir = javadoc +lexers.dir = lexers +ant.lib.dir = antlib + +version_info = version.properties + +#for run task (MB): +max.heap.size.run = 8094 + +main.class = com.jpexs.decompiler.flash.cli.CommandlineInterface + +app.dir = ../../dist +app.lib.dir = ../../dist/lib diff --git a/libsrc/ffdec_cli/build.xml b/libsrc/ffdec_cli/build.xml new file mode 100644 index 000000000..70b463675 --- /dev/null +++ b/libsrc/ffdec_cli/build.xml @@ -0,0 +1,175 @@ + + + Builds project FFDec CLI + + + + + + + + + + + Builds project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libsrc/ffdec_cli/lib/jansi-2.4.0.jar b/libsrc/ffdec_cli/lib/jansi-2.4.0.jar new file mode 100644 index 000000000..d6bb12fc3 Binary files /dev/null and b/libsrc/ffdec_cli/lib/jansi-2.4.0.jar differ diff --git a/libsrc/ffdec_cli/nbproject/project.xml b/libsrc/ffdec_cli/nbproject/project.xml new file mode 100644 index 000000000..9f85fa8e9 --- /dev/null +++ b/libsrc/ffdec_cli/nbproject/project.xml @@ -0,0 +1,76 @@ + + + org.netbeans.modules.ant.freeform + + + + FFDec CLI + + + + + java + src + + + + + build + + + clean + + + javadoc + + + run + + + test + + + clean + build + + + + folder + build/classes + build + + + + + + src + + + build.xml + + + + + + + + + + + + + + + src + lib/jansi-2.4.0.jar;../../lib/ffdec_lib.jar + build/classes + 1.8 + + + + diff --git a/src/com/jpexs/decompiler/flash/console/NewCommandLine.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/CommandlineInterface.java similarity index 87% rename from src/com/jpexs/decompiler/flash/console/NewCommandLine.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/CommandlineInterface.java index a37a9f777..cfd6cff59 100644 --- a/src/com/jpexs/decompiler/flash/console/NewCommandLine.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/CommandlineInterface.java @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console; +package com.jpexs.decompiler.flash.cli; -import com.jpexs.decompiler.flash.console.commands.Main; +import com.jpexs.decompiler.flash.cli.commands.Main; import org.fusesource.jansi.AnsiConsole; import picocli.CommandLine; @@ -24,7 +24,7 @@ import picocli.CommandLine; * * @author JPEXS */ -public class NewCommandLine { +public class CommandlineInterface { public static void main(String[] args) { AnsiConsole.systemInstall(); diff --git a/src/com/jpexs/decompiler/flash/console/commands/Export.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Export.java similarity index 90% rename from src/com/jpexs/decompiler/flash/console/commands/Export.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Export.java index e454269eb..d1f6db90f 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/Export.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Export.java @@ -14,13 +14,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands; -import com.jpexs.decompiler.flash.console.commands.types.ConfigConverter; -import com.jpexs.decompiler.flash.console.commands.types.ExportObject; -import com.jpexs.decompiler.flash.console.commands.types.ExportObjectFormat; -import com.jpexs.decompiler.flash.console.commands.types.ExportObjectFormatConverter; -import com.jpexs.decompiler.flash.console.commands.types.Selection; -import com.jpexs.decompiler.flash.console.commands.types.SelectionConverter; +package com.jpexs.decompiler.flash.cli.commands; +import com.jpexs.decompiler.flash.cli.commands.types.ConfigConverter; +import com.jpexs.decompiler.flash.cli.commands.types.ExportObject; +import com.jpexs.decompiler.flash.cli.commands.types.ExportObjectFormat; +import com.jpexs.decompiler.flash.cli.commands.types.ExportObjectFormatConverter; +import com.jpexs.decompiler.flash.cli.commands.types.Selection; +import com.jpexs.decompiler.flash.cli.commands.types.SelectionConverter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/com/jpexs/decompiler/flash/console/commands/Main.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java similarity index 70% rename from src/com/jpexs/decompiler/flash/console/commands/Main.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java index 189041b78..b19f74ac9 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/Main.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/Main.java @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands; +package com.jpexs.decompiler.flash.cli.commands; import com.jpexs.decompiler.flash.ApplicationInfo; -import com.jpexs.decompiler.flash.console.commands.types.ConfigConverter; +import com.jpexs.decompiler.flash.cli.commands.types.ConfigConverter; import java.io.File; import java.util.HashMap; import java.util.Map; @@ -32,7 +32,7 @@ import picocli.CommandLine.ScopeType; * * @author JPEXS */ -@Command(name="", +@Command(name="ffdec-cli", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class, subcommands = { @@ -43,18 +43,13 @@ import picocli.CommandLine.ScopeType; optionListHeading = "%n@|bold,underline Options|@:%n", parameterListHeading = "%n@|bold,underline Parameters|@:%n", synopsisHeading = "@|bold,underline Usage|@:", - customSynopsis = {" [@|fg(yellow) FILE|@...]", + /*customSynopsis = {" [@|fg(yellow) FILE|@...]", " or [@|fg(yellow) -hV|@]", - " or @|fg(yellow) --cli|@ [COMMAND]"}, - description = {"JPEXS Free Flash Decompiler commandline interface", - "", - "@|bold,underline Executable|@:", - " ffdec.sh on Linux/MacOs, ffdec.bat on Windows", - " or 'java -jar ffdec.jar' on all java" - }, - commandListHeading = "%n@|bold,underline Commands|@:%n" + " or @|fg(yellow) --cli|@ [COMMAND]"},*/ + description = {"JPEXS Free Flash Decompiler commandline interface"}, + commandListHeading = "%n@|bold,underline Commands|@:%n" ) -public class Main implements Runnable { +public class Main { @Option(names = "--config", paramLabel = "=[,=...]", @@ -67,19 +62,9 @@ public class Main implements Runnable { ) private Map configs = new HashMap<>(); - @Parameters(paramLabel = "FILE", description = "one or more files to open in GUI") - private File[] files; - - @Option(names = "--cli", - required = true, - description = "Use new commandline mode", - scope = ScopeType.INHERIT) - private boolean cli = false; - - @Override - public void run() { - System.out.println("Main command"); - } + /*@Parameters(paramLabel = "FILE", description = "one or more files to open in GUI") + private File[] files; */ + } class VersionProvider implements IVersionProvider { diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/ConfigConverter.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ConfigConverter.java similarity index 96% rename from src/com/jpexs/decompiler/flash/console/commands/types/ConfigConverter.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ConfigConverter.java index 9eb8dfa59..42b08330b 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/ConfigConverter.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ConfigConverter.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; import com.jpexs.decompiler.flash.configuration.Configuration; import java.lang.reflect.Field; diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObject.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObject.java similarity index 98% rename from src/com/jpexs/decompiler/flash/console/commands/types/ExportObject.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObject.java index 8a8dd9719..7f3e6b216 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObject.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObject.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; import com.jpexs.decompiler.flash.exporters.modes.BinaryDataExportMode; import com.jpexs.decompiler.flash.exporters.modes.ButtonExportMode; diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormat.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormat.java similarity index 94% rename from src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormat.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormat.java index 08bc31531..b8d0beddb 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormat.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormat.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; /** * diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormatConverter.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormatConverter.java similarity index 97% rename from src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormatConverter.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormatConverter.java index e59e147dd..4e3f7a522 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/ExportObjectFormatConverter.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/ExportObjectFormatConverter.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; import java.util.ArrayList; import java.util.List; diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/Range.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Range.java similarity index 94% rename from src/com/jpexs/decompiler/flash/console/commands/types/Range.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Range.java index b562f4d59..b2a1ecf4c 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/Range.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Range.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; /** * diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/Selection.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Selection.java similarity index 95% rename from src/com/jpexs/decompiler/flash/console/commands/types/Selection.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Selection.java index 602bd0a45..9e339fa98 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/Selection.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/Selection.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; import java.util.ArrayList; import java.util.List; diff --git a/src/com/jpexs/decompiler/flash/console/commands/types/SelectionConverter.java b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/SelectionConverter.java similarity index 91% rename from src/com/jpexs/decompiler/flash/console/commands/types/SelectionConverter.java rename to libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/SelectionConverter.java index c9ddb2657..c14058b56 100644 --- a/src/com/jpexs/decompiler/flash/console/commands/types/SelectionConverter.java +++ b/libsrc/ffdec_cli/src/com/jpexs/decompiler/flash/cli/commands/types/SelectionConverter.java @@ -14,10 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash.console.commands.types; +package com.jpexs.decompiler.flash.cli.commands.types; -import com.jpexs.decompiler.flash.console.CommandLineArgumentParser; -import static com.jpexs.decompiler.flash.console.CommandLineArgumentParser.badArguments; import java.util.ArrayList; import java.util.List; import picocli.CommandLine; diff --git a/src/picocli/CommandLine.java b/libsrc/ffdec_cli/src/picocli/CommandLine.java similarity index 100% rename from src/picocli/CommandLine.java rename to libsrc/ffdec_cli/src/picocli/CommandLine.java diff --git a/nbproject/project.xml b/nbproject/project.xml index e08e22046..07619cb24 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -27,6 +27,12 @@ test UTF-8 + + + java + libsrc/ffdec_cli/src + UTF-8 + java @@ -237,6 +243,10 @@ test + + + libsrc/ffdec_cli/src + libsrc/ffdec_lib/src @@ -340,6 +350,10 @@ build/test 1.8 + + libsrc/ffdec_cli/src + 1.8 + libsrc/ffdec_lib/src 1.8 diff --git a/resources/ffdec b/resources/ffdec new file mode 100644 index 000000000..412385cb6 --- /dev/null +++ b/resources/ffdec @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# This is a comment, it starts with "#". + +# Uncomment following and set it to higher value if you want more memory +# You need 64 bit OS and 64 bit java to set it to higher values +# FFDEC_MEMORY=1024m + +# Uncomment following when you encounter StackOverFlowErrors. +# If the app then terminates with OutOfMemory you can experiment with lower value. +# FFDEC_STACK_SIZE=32m + +# Hide VLC error output +export VLC_VERBOSE=-1 +export FFDEC_JARFILENAME=ffdec.jar +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +exec $SCRIPT_DIR/run-java.sh "$@" diff --git a/resources/ffdec-cli b/resources/ffdec-cli new file mode 100644 index 000000000..34fdbadda --- /dev/null +++ b/resources/ffdec-cli @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# This is a comment, it starts with "#". + +# Uncomment following and set it to higher value if you want more memory +# You need 64 bit OS and 64 bit java to set it to higher values +# FFDEC_MEMORY=1024m + +# Uncomment following when you encounter StackOverFlowErrors. +# If the app then terminates with OutOfMemory you can experiment with lower value. +# FFDEC_STACK_SIZE=32m + +# Hide VLC error output +export VLC_VERBOSE=-1 +export FFDEC_JARFILENAME=ffdec-cli.jar +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +exec $SCRIPT_DIR/run-java.sh "$@" diff --git a/resources/ffdec-cli.exe b/resources/ffdec-cli.exe new file mode 100644 index 000000000..c098934e8 Binary files /dev/null and b/resources/ffdec-cli.exe differ diff --git a/resources/ffdec.sh b/resources/ffdec.sh index bd34678be..412385cb6 100644 --- a/resources/ffdec.sh +++ b/resources/ffdec.sh @@ -12,121 +12,6 @@ # Hide VLC error output export VLC_VERBOSE=-1 - -# Based on Freerapid Downloader startup script - created by Petris 2009 - -# FFDec requires Oracle Java 8 -# Look for java in these directories -LOOKUP_JRE_DIRS="/usr/lib/jvm/* /opt/java* /opt/jre*" -# Required version -REQ_JVER1=1 -REQ_JVER2=8 -REQ_JVER3=0 -REQ_JVER4=0 - -search_jar_file() { - JAR_FILE_CANDIDATES='./ffdec.jar ../dist/ffdec.jar /usr/share/java/ffdec.jar /usr/share/java/ffdec/ffdec.jar /usr/share/java/jpexs-decompiler/ffdec.jar' - for f in $JAR_FILE_CANDIDATES ; do - [ -r "$f" ] && JAR_FILE="$f" && return 0 - done - echo Unable to find ffdec.jar in the following locations: - echo "${JAR_FILE_CANDIDATES// /$'\n'}" - return 1 -} - -check_java_version () { - JVER1=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "\([0-9]*\)\.[0-9]*\.[0-9]*\(_[0-9]*\)\?".*/\1/') - JVER2=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.\([0-9]*\)\.[0-9]*\(_[0-9]*\)\?".*/\1/') - JVER3=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.[0-9]*\.\([0-9]*\)\(_[0-9]*\)\?".*/\1/') - JVER4=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.[0-9]*\.[0-9]*\(_\([0-9]*\)\)\?".*/\2/' | sed 's/^$/0/') - - if [ "$JVER1" -gt $REQ_JVER1 ]; then - return 0 - elif [ "$JVER1" -lt $REQ_JVER1 ]; then - return 1 - fi - - if [ "$JVER2" -gt $REQ_JVER2 ]; then - return 0 - elif [ "$JVER2" -lt $REQ_JVER2 ]; then - return 1 - fi - - if [ "$JVER3" -gt $REQ_JVER3 ]; then - return 0 - elif [ "$JVER3" -lt $REQ_JVER3 ]; then - return 1 - fi - - if [ "$JVER4" -lt $REQ_JVER4 ]; then - return 1 - fi - - return 0 -} - -# Handle symlinks -PROGRAM="$0" -while [ -L "$PROGRAM" ]; do - PROGRAM=$(readlink -f "$PROGRAM") -done -pushd "$(dirname "$PROGRAM")" > /dev/null - -search_jar_file || exit 1 - -if [ "${JAR_FILE:0:1}" != '/' ] ; then - JAR_FILE=$(pwd)/$JAR_FILE -fi - -popd > /dev/null - -if [ -z ${FFDEC_MEMORY+x} ]; then - FFDEC_MEMORY=1024m -fi - -STACK_SIZE_PARAM="" -MEMORY_PARAM="" -if [ -n "$FFDEC_STACK_SIZE" ]; then - STACK_SIZE_PARAM=" -Xss$FFDEC_STACK_SIZE" -fi -if [ -n "$FFDEC_MEMORY" ]; then - MEMORY_PARAM=" -Xmx$FFDEC_MEMORY" -fi - -args=(-Djava.net.preferIPv4Stack=true${MEMORY_PARAM}${STACK_SIZE_PARAM} -jar $JAR_FILE "$@") - -if [ "$(uname)" = "Darwin" ]; then - args=(-Xdock:name=FFDec -Xdock:icon=icon.png "${args[@]}") -fi - -# Check default java -if [ -x "$(which java)" ]; then - JAVA_VERSION_OUTPUT=$(java -version 2>&1) - JAVA_VERSION_OUTPUT=$(echo $JAVA_VERSION_OUTPUT | sed 's/openjdk version/java version/') - check_java_version && exec java "${args[@]}" -fi - -# Test other possible Java locations -for JRE_PATH in $LOOKUP_JRE_DIRS; do - if [ -x "$JRE_PATH/bin/java" ]; then - JAVA_VERSION_OUTPUT=$("$JRE_PATH/bin/java" -version 2>&1) - JAVA_VERSION_OUTPUT=`echo $JAVA_VERSION_OUTPUT | sed 's/openjdk version/java version/'` - check_java_version && { - export JRE_PATH - exec "$JRE_PATH/bin/java" "${args[@]}" - } - fi -done - -# Failed -if [ -x "$(which xmessage)" ]; then - xmessage -nearmouse -file - < /dev/null && pwd ) +exec $SCRIPT_DIR/run-java.sh "$@" diff --git a/resources/run-java.sh b/resources/run-java.sh new file mode 100644 index 000000000..72c9bf4e5 --- /dev/null +++ b/resources/run-java.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash + +# This is a comment, it starts with "#". + +# Uncomment following and set it to higher value if you want more memory +# You need 64 bit OS and 64 bit java to set it to higher values +# FFDEC_MEMORY=1024m + +# Uncomment following when you encounter StackOverFlowErrors. +# If the app then terminates with OutOfMemory you can experiment with lower value. +# FFDEC_STACK_SIZE=32m + +# FFDec requires Oracle Java 8 +# Look for java in these directories +LOOKUP_JRE_DIRS="/usr/lib/jvm/* /opt/java* /opt/jre*" +# Required version +REQ_JVER1=1 +REQ_JVER2=8 +REQ_JVER3=0 +REQ_JVER4=0 + + +if [ -z ${FFDEC_JARFILENAME+x} ]; then + FFDEC_JARFILENAME=ffdec.jar +fi + +search_jar_file() { + JAR_FILE_CANDIDATES="./${FFDEC_JARFILENAME} ../dist/${FFDEC_JARFILENAME} /usr/share/java/${FFDEC_JARFILENAME} /usr/share/java/ffdec/${FFDEC_JARFILENAME} /usr/share/java/jpexs-decompiler/${FFDEC_JARFILENAME}" + for f in $JAR_FILE_CANDIDATES ; do + [ -r "$f" ] && JAR_FILE="$f" && return 0 + done + echo Unable to find ${FFDEC_JARFILE} in the following locations: + echo "${JAR_FILE_CANDIDATES// /$'\n'}" + return 1 +} + +check_java_version () { + JVER1=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "\([0-9]*\)\.[0-9]*\.[0-9]*\(_[0-9]*\)\?".*/\1/') + JVER2=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.\([0-9]*\)\.[0-9]*\(_[0-9]*\)\?".*/\1/') + JVER3=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.[0-9]*\.\([0-9]*\)\(_[0-9]*\)\?".*/\1/') + JVER4=$(echo $JAVA_VERSION_OUTPUT | sed 's/java version "[0-9]*\.[0-9]*\.[0-9]*\(_\([0-9]*\)\)\?".*/\2/' | sed 's/^$/0/') + + if [ "$JVER1" -gt $REQ_JVER1 ]; then + return 0 + elif [ "$JVER1" -lt $REQ_JVER1 ]; then + return 1 + fi + + if [ "$JVER2" -gt $REQ_JVER2 ]; then + return 0 + elif [ "$JVER2" -lt $REQ_JVER2 ]; then + return 1 + fi + + if [ "$JVER3" -gt $REQ_JVER3 ]; then + return 0 + elif [ "$JVER3" -lt $REQ_JVER3 ]; then + return 1 + fi + + if [ "$JVER4" -lt $REQ_JVER4 ]; then + return 1 + fi + + return 0 +} + +# Handle symlinks +PROGRAM="$0" +while [ -L "$PROGRAM" ]; do + PROGRAM=$(readlink -f "$PROGRAM") +done +pushd "$(dirname "$PROGRAM")" > /dev/null + +search_jar_file || exit 1 + +if [ "${JAR_FILE:0:1}" != '/' ] ; then + JAR_FILE=$(pwd)/$JAR_FILE +fi + +popd > /dev/null + +if [ -z ${FFDEC_MEMORY+x} ]; then + FFDEC_MEMORY=1024m +fi + +STACK_SIZE_PARAM="" +MEMORY_PARAM="" +if [ -n "$FFDEC_STACK_SIZE" ]; then + STACK_SIZE_PARAM=" -Xss$FFDEC_STACK_SIZE" +fi +if [ -n "$FFDEC_MEMORY" ]; then + MEMORY_PARAM=" -Xmx$FFDEC_MEMORY" +fi + +args=(-Djava.net.preferIPv4Stack=true${MEMORY_PARAM}${STACK_SIZE_PARAM} -jar $JAR_FILE "$@") + +if [ "$(uname)" = "Darwin" ]; then + args=(-Xdock:name=FFDec -Xdock:icon=icon.png "${args[@]}") +fi + +# Check default java +if [ -x "$(which java)" ]; then + JAVA_VERSION_OUTPUT=$(java -version 2>&1) + JAVA_VERSION_OUTPUT=$(echo $JAVA_VERSION_OUTPUT | sed 's/openjdk version/java version/') + check_java_version && exec java "${args[@]}" +fi + +# Test other possible Java locations +for JRE_PATH in $LOOKUP_JRE_DIRS; do + if [ -x "$JRE_PATH/bin/java" ]; then + JAVA_VERSION_OUTPUT=$("$JRE_PATH/bin/java" -version 2>&1) + JAVA_VERSION_OUTPUT=`echo $JAVA_VERSION_OUTPUT | sed 's/openjdk version/java version/'` + check_java_version && { + export JRE_PATH + exec "$JRE_PATH/bin/java" "${args[@]}" + } + fi +done + +# Failed +if [ -x "$(which xmessage)" ]; then + xmessage -nearmouse -file - <