-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
electrostatic4j: added buildSrc Core
- Loading branch information
1 parent
c0ef89c
commit a65684d
Showing
21 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+133 Bytes
...ostatic4j/buildSrc/build/classes/groovy/main/com/jme3/serial4j/actions/package-info.class
Binary file not shown.
Binary file added
BIN
+4.28 KB
...rk/electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/CompileX86.class
Binary file not shown.
Binary file added
BIN
+3.52 KB
...ctrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/UnixScriptRunner.class
Binary file not shown.
Binary file added
BIN
+4.81 KB
...tatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/Permissioning.class
Binary file not shown.
Binary file added
BIN
+6.01 KB
...atic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/actions/ScriptExecutor.class
Binary file not shown.
Binary file added
BIN
+126 Bytes
.../electrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/package-info.class
Binary file not shown.
Binary file added
BIN
+4.23 KB
...trostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/ConsoleUtils.class
Binary file not shown.
Binary file added
BIN
+5.73 KB
...ctrostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/JarMetadata.class
Binary file not shown.
Binary file added
BIN
+131 Bytes
...trostatic4j/buildSrc/build/classes/groovy/main/com/serial4j/build/util/package-info.class
Binary file not shown.
Binary file added
BIN
+16.5 KB
electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/libs/buildSrc.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
...c-sandbox-framework/electrostatic4j/buildSrc/build/source-roots/buildSrc/source-roots.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
src/main/resources | ||
src/main/java | ||
src/main/groovy | ||
src/test/resources | ||
src/test/java | ||
src/test/groovy |
2 changes: 2 additions & 0 deletions
2
electrostatic-sandbox-framework/electrostatic4j/buildSrc/build/tmp/jar/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Manifest-Version: 1.0 | ||
|
67 changes: 67 additions & 0 deletions
67
...x-framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/CompileX86.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...ework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/UnixScriptRunner.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/Permissioning.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/ScriptExecutor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>) Arrays.asList(runner.getScriptArgs())); | ||
} catch(IOException | InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void executeScript(final String script, final ArrayList<String> args) throws IOException, InterruptedException { | ||
ArrayList<String> 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"; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...k/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/actions/package-info.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Holds the task actions for the {@link com.jme3.build.UnixScriptRunner}. | ||
*/ | ||
package com.jme3.serial4j.actions; |
4 changes: 4 additions & 0 deletions
4
...framework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/package-info.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Holds the native build implementation for the jme3-alloc-native project. | ||
*/ | ||
package com.serial4j.build; |
64 changes: 64 additions & 0 deletions
64
...work/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/ConsoleUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ework/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/JarMetadata.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...work/electrostatic4j/buildSrc/src/main/groovy/com/serial4j/build/util/package-info.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Holds the utilities for the build api. | ||
*/ | ||
package com.serial4j.build.util; |