-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a run system command in a path macro and fixes existing docu
Signed-off-by: Juergen Albert <[email protected]>
- Loading branch information
1 parent
38272cf
commit b29830c
Showing
7 changed files
with
197 additions
and
137 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,72 +1,20 @@ | ||
--- | ||
layout: default | ||
class: Macro | ||
title: system ';' STRING ( ';' STRING )? | ||
title: system ';' CMD ( ';' INPUT )? | ||
summary: Execute a system command | ||
--- | ||
|
||
Executes a System command in the current project directory. | ||
This can be used to execute command line tools. If an INPUT is given, it will be given to the process via the Standard Input. | ||
|
||
public String _system(String args[]) throws Exception { | ||
return system_internal(false, args); | ||
} | ||
If the Process exits with anything other than `0`, the result will be become an error. | ||
|
||
public String _system_allow_fail(String args[]) throws Exception { | ||
String result = ""; | ||
try { | ||
result = system_internal(true, args); | ||
} | ||
catch (Throwable t) { | ||
/* ignore */ | ||
} | ||
return result; | ||
} | ||
Usage Example: | ||
``` | ||
# Extracts the current git SHA for the Project | ||
Git-SHA: ${system;git rev-list -1 --no-abbrev-commit HEAD} | ||
/** | ||
* System command. Execute a command and insert the result. | ||
* | ||
* @param args | ||
* @param help | ||
* @param patterns | ||
* @param low | ||
* @param high | ||
*/ | ||
public String system_internal(boolean allowFail, String args[]) throws Exception { | ||
if (nosystem) | ||
throw new RuntimeException("Macros in this mode cannot excute system commands"); | ||
|
||
verifyCommand(args, "${" + (allowFail ? "system-allow-fail" : "system") | ||
+ ";<command>[;<in>]}, execute a system command", null, 2, 3); | ||
String command = args[1]; | ||
String input = null; | ||
|
||
if (args.length > 2) { | ||
input = args[2]; | ||
} | ||
if ( File.separatorChar == '\\') | ||
command = "cmd /c \"" + command + "\""; | ||
|
||
Process process = Runtime.getRuntime().exec(command, null, domain.getBase()); | ||
if (input != null) { | ||
process.getOutputStream().write(input.getBytes("UTF-8")); | ||
} | ||
process.getOutputStream().close(); | ||
|
||
String s = IO.collect(process.getInputStream(), "UTF-8"); | ||
int exitValue = process.waitFor(); | ||
if (exitValue != 0) | ||
return exitValue + ""; | ||
|
||
if (exitValue != 0) { | ||
if (!allowFail) { | ||
domain.error("System command " + command + " failed with exit code " + exitValue); | ||
} else { | ||
domain.warning("System command " + command + " failed with exit code " + exitValue + " (allowed)"); | ||
|
||
} | ||
} | ||
|
||
return s.trim(); | ||
} | ||
|
||
# Extracts the current git SHA for the Project and enters the password as input | ||
Git-SHA: ${system;git rev-list -1 --no-abbrev-commit HEAD;mypassword} | ||
``` |
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 |
---|---|---|
@@ -1,73 +1,20 @@ | ||
--- | ||
layout: default | ||
class: Macro | ||
title: system_allow_fail ';' STRING ( ';' STRING )? | ||
title: system-allow-fail ';' CMD ( ';' INPUT )? | ||
summary: Execute a system command but ignore any failures | ||
--- | ||
|
||
Executes a System command in the current project directory. | ||
This can be used to execute command line tools. If an INPUT is given, it will be given to the process via the Standard Input. | ||
|
||
If the Process exits with anything other than `0`, the result will be be marked as a warning. | ||
|
||
public String _system(String args[]) throws Exception { | ||
return system_internal(false, args); | ||
} | ||
Usage Example: | ||
``` | ||
# Extracts the current git SHA for the Project | ||
Git-SHA: ${system-allow-fail;git rev-list -1 --no-abbrev-commit HEAD} | ||
public String _system_allow_fail(String args[]) throws Exception { | ||
String result = ""; | ||
try { | ||
result = system_internal(true, args); | ||
} | ||
catch (Throwable t) { | ||
/* ignore */ | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* System command. Execute a command and insert the result. | ||
* | ||
* @param args | ||
* @param help | ||
* @param patterns | ||
* @param low | ||
* @param high | ||
*/ | ||
public String system_internal(boolean allowFail, String args[]) throws Exception { | ||
if (nosystem) | ||
throw new RuntimeException("Macros in this mode cannot excute system commands"); | ||
|
||
verifyCommand(args, "${" + (allowFail ? "system-allow-fail" : "system") | ||
+ ";<command>[;<in>]}, execute a system command", null, 2, 3); | ||
String command = args[1]; | ||
String input = null; | ||
|
||
if (args.length > 2) { | ||
input = args[2]; | ||
} | ||
if ( File.separatorChar == '\\') | ||
command = "cmd /c \"" + command + "\""; | ||
|
||
Process process = Runtime.getRuntime().exec(command, null, domain.getBase()); | ||
if (input != null) { | ||
process.getOutputStream().write(input.getBytes("UTF-8")); | ||
} | ||
process.getOutputStream().close(); | ||
|
||
String s = IO.collect(process.getInputStream(), "UTF-8"); | ||
int exitValue = process.waitFor(); | ||
if (exitValue != 0) | ||
return exitValue + ""; | ||
|
||
if (exitValue != 0) { | ||
if (!allowFail) { | ||
domain.error("System command " + command + " failed with exit code " + exitValue); | ||
} else { | ||
domain.warning("System command " + command + " failed with exit code " + exitValue + " (allowed)"); | ||
|
||
} | ||
} | ||
|
||
return s.trim(); | ||
} | ||
|
||
# Extracts the current git SHA for the Project and enters the password as input | ||
Git-SHA: ${system-allow-fail;git rev-list -1 --no-abbrev-commit HEAD;mypassword} | ||
``` |
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,20 @@ | ||
--- | ||
layout: default | ||
class: Macro | ||
title: system-in-path ';' PATH ';' CMD ( ';' INPUT )? | ||
summary: Execute a system command | ||
--- | ||
|
||
Executes a System command in the given path. The path can be anywhere, even outside the current Project. | ||
This can be used to execute command line tools. If an INPUT is given, it will be given to the process via the Standard Input. | ||
|
||
If the Process exits with anything other than `0`, the result will be become an error. | ||
|
||
Usage Example: | ||
``` | ||
# Extracts the current git SHA in the given path | ||
Git-SHA: ${system-in-path; ~/git/someproject; git rev-list -1 --no-abbrev-commit HEAD} | ||
# Extracts the current git SHA in the given path and enters the password as input | ||
Git-SHA: ${system-in-path; ~/git/someproject; git rev-list -1 --no-abbrev-commit HEAD;mypassword} | ||
``` |
Oops, something went wrong.