Class DefaultFileCopierUtil
- java.lang.Object
-
- com.dtolabs.rundeck.core.execution.impl.common.DefaultFileCopierUtil
-
- All Implemented Interfaces:
FileCopierUtil
public class DefaultFileCopierUtil extends java.lang.Object implements FileCopierUtil
Created by greg on 7/15/16.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.dtolabs.rundeck.core.execution.impl.common.FileCopierUtil
FileCopierUtil.ContentModifier
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_UNIX_FILE_EXTstatic java.lang.StringDEFAULT_WINDOWS_FILE_EXTstatic java.lang.StringFILE_COPY_DESTINATION_DIRstatic java.lang.StringFRAMEWORK_FILE_COPY_DESTINATION_DIRstatic java.lang.StringPROJECT_FILE_COPY_DESTINATION_DIR
-
Constructor Summary
Constructors Constructor Description DefaultFileCopierUtil()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringappendRemoteFileExtension(java.lang.String filepath, java.lang.String fileext)java.lang.StringdefaultRemoteFileExtensionForNode(INodeEntry node)java.lang.StringgenerateRemoteFilepathForNode(INodeEntry node, IRundeckProject project, IFramework framework, java.lang.String scriptfileName, java.lang.String fileExtension, java.lang.String identity)Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)java.lang.StringgenerateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName)Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)java.lang.StringgenerateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName, java.lang.String fileExtension)Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)java.lang.StringgenerateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName, java.lang.String fileExtension, java.lang.String identity)java.lang.StringgetRemoteDirForNode(INodeEntry node)Return a remote destination temp dir path for the given node.java.lang.StringgetRemoteDirForNode(INodeEntry node, IRundeckProject project, IFramework framework)Return a remote destination temp dir path for the given node.java.io.FilewriteLocalFile(java.io.File original, java.io.InputStream input, java.lang.String script, java.io.File destinationFile)java.io.FilewriteScriptTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script, INodeEntry node, boolean expandTokens, FileCopierUtil.ContentModifier modifier)Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two.java.io.FilewriteScriptTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script, INodeEntry node, java.io.File destination, boolean expandTokens, FileCopierUtil.ContentModifier modifier)Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two.java.io.FilewriteTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script)Write the file, stream, or text to a local temp file and return the file
-
-
-
Field Detail
-
FILE_COPY_DESTINATION_DIR
public static final java.lang.String FILE_COPY_DESTINATION_DIR
- See Also:
- Constant Field Values
-
FRAMEWORK_FILE_COPY_DESTINATION_DIR
public static final java.lang.String FRAMEWORK_FILE_COPY_DESTINATION_DIR
- See Also:
- Constant Field Values
-
PROJECT_FILE_COPY_DESTINATION_DIR
public static final java.lang.String PROJECT_FILE_COPY_DESTINATION_DIR
- See Also:
- Constant Field Values
-
DEFAULT_WINDOWS_FILE_EXT
public static final java.lang.String DEFAULT_WINDOWS_FILE_EXT
- See Also:
- Constant Field Values
-
DEFAULT_UNIX_FILE_EXT
public static final java.lang.String DEFAULT_UNIX_FILE_EXT
- See Also:
- Constant Field Values
-
-
Method Detail
-
writeScriptTempFile
public java.io.File writeScriptTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script, INodeEntry node, boolean expandTokens, FileCopierUtil.ContentModifier modifier) throws FileCopierException
Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two. Marks the file as executable and delete-on-exit. This will not rewrite any content if the input is originally a file.- Specified by:
writeScriptTempFilein interfaceFileCopierUtil- Parameters:
context- execution contextoriginal- local system file, or nullinput- input stream to write, or nullscript- file content string, or nullnode- destination node entry, to provide node data contextexpandTokens- if true, expand tokens in the stream or string- Returns:
- file where the script was stored, this file should later be cleaned up by calling
ScriptfileUtils.releaseTempFile(java.io.File) - Throws:
FileCopierException- if an IO problem occurs
-
writeScriptTempFile
public java.io.File writeScriptTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script, INodeEntry node, java.io.File destination, boolean expandTokens, FileCopierUtil.ContentModifier modifier) throws FileCopierException
Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two. Marks the file as executable and delete-on-exit. This will not rewrite any content if the input is originally a file.- Specified by:
writeScriptTempFilein interfaceFileCopierUtil- Parameters:
context- execution contextoriginal- local system file, or nullinput- input stream to write, or nullscript- file content string, or nullnode- destination node entry, to provide node data contextdestination- destination file, or null to generate a new temp file- Returns:
- file where the script was stored
- Throws:
FileCopierException- if an IO problem occurs
-
defaultRemoteFileExtensionForNode
public java.lang.String defaultRemoteFileExtensionForNode(INodeEntry node)
- Specified by:
defaultRemoteFileExtensionForNodein interfaceFileCopierUtil- Parameters:
node- node- Returns:
- the default file extension for a temp file based on the type of node
-
appendRemoteFileExtension
public java.lang.String appendRemoteFileExtension(java.lang.String filepath, java.lang.String fileext)- Specified by:
appendRemoteFileExtensionin interfaceFileCopierUtil- Parameters:
filepath- the file path stringfileext- the file extension, if it does not start with a "." one will be prepended first. If null, the unmodified filepath will be returned.- Returns:
- a string with a file extension appended if it is not already on the file path provided.
-
getRemoteDirForNode
public java.lang.String getRemoteDirForNode(INodeEntry node)
Return a remote destination temp dir path for the given node. If specified, the node attribute named "file-copy-destination-dir" is used, otherwise a temp directory appropriate for the os-family of the node is returned.- Specified by:
getRemoteDirForNodein interfaceFileCopierUtil- Parameters:
node- the node entry- Returns:
- a path to destination dir for the node
-
getRemoteDirForNode
public java.lang.String getRemoteDirForNode(INodeEntry node, IRundeckProject project, IFramework framework)
Return a remote destination temp dir path for the given node. If specified, the node attribute named "file-copy-destination-dir" is used, otherwise a temp directory appropriate for the os-family of the node is returned.- Specified by:
getRemoteDirForNodein interfaceFileCopierUtil- Parameters:
node- the node entryproject- projectframework- framework- Returns:
- a path to destination dir for the node
-
generateRemoteFilepathForNode
public java.lang.String generateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName)
Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)- Specified by:
generateRemoteFilepathForNodein interfaceFileCopierUtil- Parameters:
node- the destination nodescriptfileName- the name of the file to copy- Returns:
- a filepath specifying destination of the file to copy that should be unique for the node and current date.
-
generateRemoteFilepathForNode
public java.lang.String generateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName, java.lang.String fileExtension)
Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)- Specified by:
generateRemoteFilepathForNodein interfaceFileCopierUtil- Parameters:
node- the destination nodescriptfileName- the name of the file to copyfileExtension- optional extension to use for the temp file, or null for default- Returns:
- a filepath specifying destination of the file to copy that should be unique
-
generateRemoteFilepathForNode
public java.lang.String generateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName, java.lang.String fileExtension, java.lang.String identity)
Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)- Specified by:
generateRemoteFilepathForNodein interfaceFileCopierUtil- Parameters:
node- the destination nodescriptfileName- the name of the file to copyfileExtension- optional extension to use for the temp file, or null for defaultidentity- unique identifier, or null to include a random string- Returns:
- a filepath specifying destination of the file to copy that should be unique
-
generateRemoteFilepathForNode
public java.lang.String generateRemoteFilepathForNode(INodeEntry node, IRundeckProject project, IFramework framework, java.lang.String scriptfileName, java.lang.String fileExtension, java.lang.String identity)
Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)- Specified by:
generateRemoteFilepathForNodein interfaceFileCopierUtil- Parameters:
node- the destination nodeproject- projectframework- frameworkscriptfileName- the name of the file to copyfileExtension- optional extension to use for the temp file, or null for defaultidentity- unique identifier, or null to include a random string- Returns:
- a filepath specifying destination of the file to copy that should be unique
-
writeTempFile
public java.io.File writeTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script) throws FileCopierException
Write the file, stream, or text to a local temp file and return the file- Specified by:
writeTempFilein interfaceFileCopierUtil- Parameters:
context- contextoriginal- source file, or nullinput- source inputstream or nullscript- source text, or null- Returns:
- temp file, this file should later be cleaned up by calling
ScriptfileUtils.releaseTempFile(java.io.File) - Throws:
FileCopierException- if IOException occurs
-
writeLocalFile
public java.io.File writeLocalFile(java.io.File original, java.io.InputStream input, java.lang.String script, java.io.File destinationFile) throws FileCopierException- Specified by:
writeLocalFilein interfaceFileCopierUtil- Parameters:
original- source fileinput- source streamscript- source stringdestinationFile- destination- Returns:
- local file
- Throws:
FileCopierException- on error
-
-