Class ScriptfileUtils
- java.lang.Object
-
- com.dtolabs.rundeck.core.execution.script.ScriptfileUtils
-
public class ScriptfileUtils extends java.lang.Object
Utility methods for writing temp files for scripts and setting file permissions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScriptfileUtils.LineEndingStyle
Line ending style
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SHOULD_ADD_BOM
-
Constructor Summary
Constructors Constructor Description ScriptfileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.File
createTempFile(Framework framework)
Creates a temp file and marks it for deleteOnExit, to clean up proactively callreleaseTempFile(java.io.File)
with the result when completestatic ScriptfileUtils.LineEndingStyle
lineEndingStyleForNode(INodeEntry node)
static boolean
releaseTempFile(java.io.File file)
Remove a file that may have been created bycreateTempFile(com.dtolabs.rundeck.core.common.Framework)
.static void
setExecutePermissions(java.io.File scriptfile)
Set the executable flag on a file if supported by the OSstatic boolean
shouldAddBomForNode(INodeEntry node)
static void
writeScriptFile(java.io.InputStream stream, java.lang.String scriptString, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style, java.io.File scriptfile)
Write script content to a destination file from one of the sourcesstatic void
writeScriptFile(java.io.InputStream stream, java.lang.String scriptString, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style, java.io.File scriptfile, boolean addBom)
Write script content to a destination file from one of the sourcesstatic java.io.File
writeScriptTempfile(Framework framework, java.io.InputStream stream, java.lang.String source, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style)
Copy a source stream or string content to a tempfile for script executionstatic java.io.File
writeScriptTempfile(Framework framework, java.io.Reader source, ScriptfileUtils.LineEndingStyle style)
Copy reader content to a tempfile for script execution
-
-
-
Field Detail
-
SHOULD_ADD_BOM
public static final java.lang.String SHOULD_ADD_BOM
- See Also:
- Constant Field Values
-
-
Method Detail
-
lineEndingStyleForNode
public static ScriptfileUtils.LineEndingStyle lineEndingStyleForNode(INodeEntry node)
- Parameters:
node
- node- Returns:
- the line ending style for the node, based on the osFamily, or use LOCAL if undetermined
-
shouldAddBomForNode
public static boolean shouldAddBomForNode(INodeEntry node)
-
writeScriptTempfile
public static java.io.File writeScriptTempfile(Framework framework, java.io.Reader source, ScriptfileUtils.LineEndingStyle style) throws java.io.IOException
Copy reader content to a tempfile for script execution- Parameters:
framework
- frameworksource
- string contentstyle
- style- Returns:
- tempfile
- Throws:
java.io.IOException
- if an error occurs
-
writeScriptTempfile
public static java.io.File writeScriptTempfile(Framework framework, java.io.InputStream stream, java.lang.String source, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style) throws java.io.IOException
Copy a source stream or string content to a tempfile for script execution- Parameters:
framework
- frameworkstream
- source streamsource
- contentstyle
- file line ending style to usereader
- reader- Returns:
- tempfile
- Throws:
java.io.IOException
- if an error occurs
-
writeScriptFile
public static void writeScriptFile(java.io.InputStream stream, java.lang.String scriptString, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style, java.io.File scriptfile, boolean addBom) throws java.io.IOException
Write script content to a destination file from one of the sources- Parameters:
stream
- stream sourcescriptString
- script contentreader
- reader sourcestyle
- line ending stylescriptfile
- destination file- Throws:
java.io.IOException
- on io error
-
writeScriptFile
public static void writeScriptFile(java.io.InputStream stream, java.lang.String scriptString, java.io.Reader reader, ScriptfileUtils.LineEndingStyle style, java.io.File scriptfile) throws java.io.IOException
Write script content to a destination file from one of the sources- Parameters:
stream
- stream sourcescriptString
- script contentreader
- reader sourcestyle
- line ending stylescriptfile
- destination file- Throws:
java.io.IOException
- on io error
-
createTempFile
public static java.io.File createTempFile(Framework framework) throws java.io.IOException
Creates a temp file and marks it for deleteOnExit, to clean up proactively callreleaseTempFile(java.io.File)
with the result when complete- Parameters:
framework
- fwk- Returns:
- Create a temp file in the framework
- Throws:
java.io.IOException
- on io error
-
releaseTempFile
public static boolean releaseTempFile(java.io.File file)
Remove a file that may have been created bycreateTempFile(com.dtolabs.rundeck.core.common.Framework)
. If the file was not created that way, it will not be deleted.- Parameters:
file
- a temp file created withcreateTempFile(com.dtolabs.rundeck.core.common.Framework)
- Returns:
- true if the temp file was known and was deleted
-
setExecutePermissions
public static void setExecutePermissions(java.io.File scriptfile) throws java.io.IOException
Set the executable flag on a file if supported by the OS- Parameters:
scriptfile
- target file- Throws:
java.io.IOException
- if an error occurs
-
-