diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/jme3/serial4j/actions/package-info.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/jme3/serial4j/actions/package-info.class new file mode 100644 index 0000000..cbf02fb Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/jme3/serial4j/actions/package-info.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/CompileX86.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/CompileX86.class new file mode 100644 index 0000000..d2ed080 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/CompileX86.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/UnixScriptRunner.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/UnixScriptRunner.class new file mode 100644 index 0000000..a467b7a Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/UnixScriptRunner.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/Permissioning.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/Permissioning.class new file mode 100644 index 0000000..bac6e06 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/Permissioning.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/ScriptExecutor.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/ScriptExecutor.class new file mode 100644 index 0000000..a1cb0a7 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/ScriptExecutor.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/package-info.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/package-info.class new file mode 100644 index 0000000..fc3afcf Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/package-info.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/ConsoleUtils.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/ConsoleUtils.class new file mode 100644 index 0000000..79889b7 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/ConsoleUtils.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/JarMetadata.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/JarMetadata.class new file mode 100644 index 0000000..c5a28e3 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/JarMetadata.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/package-info.class b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/package-info.class new file mode 100644 index 0000000..4abb9a7 Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/package-info.class differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/libs/buildSrc.jar b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/libs/buildSrc.jar new file mode 100644 index 0000000..79d843b Binary files /dev/null and b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/libs/buildSrc.jar differ diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/source-roots/buildSrc/source-roots.txt b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/source-roots/buildSrc/source-roots.txt new file mode 100755 index 0000000..b004ef4 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/source-roots/buildSrc/source-roots.txt @@ -0,0 +1,6 @@ +src/main/resources +src/main/java +src/main/groovy +src/test/resources +src/test/java +src/test/groovy diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/tmp/jar/MANIFEST.MF b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/tmp/jar/MANIFEST.MF new file mode 100755 index 0000000..58630c0 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/CompileX86.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/CompileX86.groovy new file mode 100755 index 0000000..43b9a77 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/CompileX86.groovy @@ -0,0 +1,67 @@ +package com.serial4j.build; + +import org.gradle.api.DefaultTask; +import org.gradle.api.tasks.Input; + +/** + * Compiles a x86 binary to a specific system. + * + * @author pavl_g + */ +public class CompileX86 extends UnixScriptRunner { + + /** Placeholders for gradle properties */ + @Input + protected String compileWindowsX86 = ""; + + @Input + protected String compileMacX86 = ""; + + @Input + protected String compileLinuxX86 = ""; + + protected final boolean isWindows = System.getProperty("os.name").contains("Windows"); + protected final boolean isMacos = System.getProperty("os.name").contains("Mac"); + protected final boolean isLinux = System.getProperty("os.name").contains("Linux"); + + @Override + protected void scriptExecution() { + boolean isCompileWindowsX86 = getConditionFromValue(compileWindowsX86); + boolean isCompileMacX86 = getConditionFromValue(compileMacX86); + boolean isCompileLinuxX86 = getConditionFromValue(compileLinuxX86); + + if (isWindows && !isCompileWindowsX86) { + /* terminate when on windows if the compile flag is disabled */ + return; + } + + if (isMacos && !isCompileMacX86) { + /* terminate when on MacOS if the compile flag is disabled */ + return; + } + + if (isLinux && !isCompileLinuxX86) { + /* terminate when on linux if the compile flag is disabled */ + return; + } + + super.scriptExecution(); + } + + private boolean getConditionFromValue(final String value) { + return value.equals("true"); + } + + public String getCompileLinuxX86() { + return compileLinuxX86; + } + + public String getCompileWindowsX86() { + return compileWindowsX86; + } + + public String getCompileMacX86() { + return compileMacX86; + } + +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/UnixScriptRunner.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/UnixScriptRunner.groovy new file mode 100755 index 0000000..f4a0cee --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/UnixScriptRunner.groovy @@ -0,0 +1,58 @@ +package com.serial4j.build; + +import org.gradle.api.tasks.TaskAction; +import org.gradle.api.DefaultTask; +import org.gradle.api.tasks.Input; +import com.serial4j.build.actions.Permissioning; +import com.serial4j.build.actions.ScriptExecutor; + +/** + * The abstract entity for running unix scripts in bash shell environments. + * It consists of 2 sequential tasks: a [permissioning] task and a [script-executor] task. + * + * @author pavl_g + */ +public class UnixScriptRunner extends DefaultTask { + + /** + * The unix script to execute. + */ + @Input + protected String script = ""; + + @Input + protected String[] scriptArgs; + + @TaskAction + protected void scriptExecution() { + final ScriptExecutor executor = new ScriptExecutor(); + executor.execute(this); + } + + @TaskAction + protected void permissioning() { + final Permissioning permissioningTask = new Permissioning(); + permissioningTask.execute(this); + } + + /** + * Sets the unix-script to run. + * + * @param script a string representing the absolute path to the script ending with the script name and file extension + */ + public void setScript(final String script) { + this.script = script; + } + + public final String getScript() { + return script; + } + + public void setScriptArgs(final String[] scriptArgs) { + this.scriptArgs = scriptArgs; + } + + public String[] getScriptArgs() { + return scriptArgs; + } +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/Permissioning.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/Permissioning.groovy new file mode 100755 index 0000000..383c3e6 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/Permissioning.groovy @@ -0,0 +1,45 @@ +package com.serial4j.build.actions; + +import org.gradle.api.resources.MissingResourceException; +import com.serial4j.build.util.ConsoleUtils; +import com.serial4j.build.UnixScriptRunner; +import java.lang.Process; +import org.gradle.api.Task; +import java.io.IOException; +import java.lang.InterruptedException; + +/** + * A task that gives a [+rwx] permission to a script. + * + * @author pavl_g + */ +public final class Permissioning { + + public void execute(Task task) { + final UnixScriptRunner runner = ((UnixScriptRunner) task); + if (runner.getScript() == null || runner.getScript().equals("")) { + throw new MissingResourceException("Cannot find a script to permissionize !"); + } + try { + permissionizeScript(runner.getScript()); + } catch(IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + private void permissionizeScript(final String script) throws IOException, InterruptedException { + String[] chmod = new String[] { "chmod", "+rwx" }; + /* execute the shell script in a unix process that inheirt from the current environment */ + Process permissioning = Runtime.getRuntime().exec(new String[] { chmod[0], chmod[1], script }); + + permissioning.waitFor(); + + ConsoleUtils.printConsoleInput(permissioning); + ConsoleUtils.printConsoleError(permissioning); + + /* release resources */ + permissioning.destroy(); + permissioning = null; + chmod = null; + } +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/ScriptExecutor.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/ScriptExecutor.groovy new file mode 100755 index 0000000..7df2996 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/ScriptExecutor.groovy @@ -0,0 +1,70 @@ +package com.serial4j.build.actions; + +import org.gradle.api.resources.MissingResourceException; +import com.serial4j.build.util.ConsoleUtils; +import com.serial4j.build.UnixScriptRunner; +import java.util.Arrays; +import java.util.ArrayList; +import java.lang.Process; +import org.gradle.api.Task; +import java.io.IOException; +import java.lang.InterruptedException; + +/** + * A task that executes a script and print its stream. + * + * @author pavl_g + */ +public final class ScriptExecutor { + + public void execute(Task task) { + final UnixScriptRunner runner = ((UnixScriptRunner) task); + if (runner.getScript() == null || runner.getScript().equals("")) { + throw new MissingResourceException("Cannot find a script to execute !"); + } + try { + executeScript(runner.getScript(), (ArrayList) Arrays.asList(runner.getScriptArgs())); + } catch(IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + private void executeScript(final String script, final ArrayList args) throws IOException, InterruptedException { + ArrayList command = new ArrayList<>(); + command.add(getBash()); + command.add(script); + + /* copy the args into the shell command */ + for (int i = 0; i < args.size(); i++) { + command.add(args.get(i)); + } + + Process run = Runtime.getRuntime().exec((String[]) command.toArray()); + + if (run.waitFor() == 1) { + System.out.println("Run Failed !"); + } + + ConsoleUtils.printConsoleInput(run); + ConsoleUtils.printConsoleError(run); + + /* release resources */ + run.destroy(); + run = null; + command.clear(); + command = null; + } + + /** + * Retrieves the system specific bash binary. + * + * @return a string representation of the bash (bourne-again-shell) + */ + private String getBash() { + if (!System.getProperty("os.name").contains("Windows")) { + return "bash"; + } + return "C:\\Program Files\\Git\\bin\\bash.exe"; + } + +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/package-info.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/package-info.groovy new file mode 100755 index 0000000..97fb36a --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/package-info.groovy @@ -0,0 +1,4 @@ +/** + * Holds the task actions for the {@link com.jme3.build.UnixScriptRunner}. + */ +package com.jme3.serial4j.actions; \ No newline at end of file diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/package-info.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/package-info.groovy new file mode 100755 index 0000000..f7dac21 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/package-info.groovy @@ -0,0 +1,4 @@ +/** + * Holds the native build implementation for the jme3-alloc-native project. + */ +package com.serial4j.build; \ No newline at end of file diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/ConsoleUtils.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/ConsoleUtils.groovy new file mode 100755 index 0000000..5e11edb --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/ConsoleUtils.groovy @@ -0,0 +1,64 @@ +package com.serial4j.build.util; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.InputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.Process; + +/** + * Some useful console io utils to provide log errors and info. + * + * @author pavl_g + */ +public final class ConsoleUtils { + private ConsoleUtils() { + } + + /** + * Prints the process input-stream to the [stdout]. + * + * @param process a {@link java.lang.Process} process + */ + public static void printConsoleInput(final Process process) { + try { + printInputStream(process.getInputStream(), System.out); + } catch(IOException e) { + e.printStackTrace(); + } + } + + /** + * Prints the process input-stream to the [stderr]. + * + * @param process a {@link java.lang.Process} process + */ + public static void printConsoleError(final Process process) { + try { + printInputStream(process.getErrorStream(), System.err); + } catch(IOException e) { + e.printStackTrace(); + } + } + + /** + * Prints an input-stream content to a stream [e.g: stdout, stderr]. + * + * @param in an input-stream to print its content + * @param stream an output-stream to print on it + */ + public static int printInputStream(final InputStream in, final PrintStream stream) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + try { + for (String out = null; (out = reader.readLine()) != null;) { + stream.println(out); + } + } finally { + reader.close(); + in.close(); + reader = null; + } + return 0; + } +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/JarMetadata.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/JarMetadata.groovy new file mode 100755 index 0000000..2401d41 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/JarMetadata.groovy @@ -0,0 +1,19 @@ +package com.serial4j.build.util; + +public enum JarMetadata { + BASE_NAME("serial4j"), VERSION("0.1-A"), EXT(".jar"), TARGET("desktop"); + + String data; + + JarMetadata(final String data) { + this.data = data; + } + + public void setData(final String data) { + this.data = data; + } + + public String getData() { + return data; + } +} diff --git a/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/package-info.groovy b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/package-info.groovy new file mode 100755 index 0000000..cfe6420 --- /dev/null +++ b/electrostatic-sandbox-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/package-info.groovy @@ -0,0 +1,4 @@ +/** + * Holds the utilities for the build api. + */ +package com.serial4j.build.util; \ No newline at end of file