Class SshRepository
- java.lang.Object
-
- org.apache.ivy.plugins.repository.AbstractRepository
-
- org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository
-
- org.apache.ivy.plugins.repository.ssh.SshRepository
-
- All Implemented Interfaces:
Repository
public class SshRepository extends AbstractSshBasedRepository
Ivy Repository based on SSH
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringARGUMENT_PLACEHOLDERprivate static intBUFFER_SIZEprivate java.lang.StringcreateDirCommandprivate java.lang.StringexistCommandprivate charfileSeparatorprivate java.lang.StringlistCommandprivate static intPOLL_SLEEP_TIMEprivate java.lang.StringpublishPermissions
-
Constructor Summary
Constructors Constructor Description SshRepository()SshRepository(TimeoutConstraint timeoutConstraint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleancheckExistence(java.lang.String filePath, com.jcraft.jsch.Session session)check for existence of file or dir on target systemvoidget(java.lang.String source, java.io.File destination)Fetch a resource from the repository.java.lang.StringgetCreateDirCommand()private com.jcraft.jsch.ChannelExecgetExecChannel(com.jcraft.jsch.Session session)java.lang.StringgetExistCommand()java.lang.StringgetListCommand()protected java.lang.StringgetRepositoryScheme()return ssh as scheme use the Resolver type name here? would be nice if it would be static, so we could use SshResolver.getTypeName()ResourcegetResource(java.lang.String source)create a new resource with lazy initializingjava.util.List<java.lang.String>list(java.lang.String parent)Return a listing of resources namesprivate voidmakePath(java.lang.String path, com.jcraft.jsch.Session session)Tries to create a directory path on the target systemjava.io.InputStreamopenStream(SshResource resource)Not really streaming...need to implement a proper streaming approach?voidput(java.io.File source, java.lang.String destination, boolean overwrite)private voidreadSessionOutput(com.jcraft.jsch.ChannelExec channel, java.lang.StringBuilder strStdout, java.lang.StringBuilder strStderr)Reads out the output of a ssh session execprivate java.lang.StringreplaceArgument(java.lang.String command, java.lang.String argument)Replace the argument placeholder with argument or append the argument if no placeholder is presentSshResourceresolveResource(java.lang.String source)Fetch the needed file information for a given file (size, last modification time) and report it back in a SshResourcevoidsetCreateDirCommand(java.lang.String createDirCommand)voidsetExistCommand(java.lang.String existCommand)voidsetFileSeparator(char fileSeparator)The file separator is the separator to use on the target system On a unix system it is '/', but I don't know, how this is solved on different ssh implementations.voidsetListCommand(java.lang.String cmd)sets the list command to use for a directory listing listing must be only the filename and each filename on a separate linevoidsetPublishPermissions(java.lang.String permissions)A four digit string (e.g., 0644, see "man chmod", "man open") specifying the permissions of the published files.-
Methods inherited from class org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository
getHost, getKeyFile, getKeyFilePassword, getPassFile, getPort, getSession, getSshConfig, getUser, getUserPassword, isAllowedAgentUse, releaseSession, setAllowedAgentUse, setHost, setKeyFile, setKeyFilePassword, setPassFile, setPort, setSshConfig, setUser, setUserPassword
-
Methods inherited from class org.apache.ivy.plugins.repository.AbstractRepository
addTransferListener, fireTransferCompleted, fireTransferCompleted, fireTransferError, fireTransferError, fireTransferEvent, fireTransferInitiated, fireTransferProgress, fireTransferStarted, fireTransferStarted, getFileSeparator, getName, getTimeoutConstraint, hasTransferListener, put, removeTransferListener, setName, standardize, toString
-
-
-
-
Field Detail
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
ARGUMENT_PLACEHOLDER
private static final java.lang.String ARGUMENT_PLACEHOLDER
- See Also:
- Constant Field Values
-
POLL_SLEEP_TIME
private static final int POLL_SLEEP_TIME
- See Also:
- Constant Field Values
-
fileSeparator
private char fileSeparator
-
listCommand
private java.lang.String listCommand
-
existCommand
private java.lang.String existCommand
-
createDirCommand
private java.lang.String createDirCommand
-
publishPermissions
private java.lang.String publishPermissions
-
-
Constructor Detail
-
SshRepository
public SshRepository()
-
SshRepository
public SshRepository(TimeoutConstraint timeoutConstraint)
-
-
Method Detail
-
getResource
public Resource getResource(java.lang.String source)
create a new resource with lazy initializing- Parameters:
source- String- Returns:
- Resource
-
resolveResource
public SshResource resolveResource(java.lang.String source)
Fetch the needed file information for a given file (size, last modification time) and report it back in a SshResource- Parameters:
source- ssh uri for the file to get info for- Returns:
- SshResource filled with the needed information
- See Also:
Repository.getResource(java.lang.String)
-
readSessionOutput
private void readSessionOutput(com.jcraft.jsch.ChannelExec channel, java.lang.StringBuilder strStdout, java.lang.StringBuilder strStderr) throws java.io.IOExceptionReads out the output of a ssh session exec- Parameters:
channel- Channel to read fromstrStdout- StringBuilder that receives Session Stdout outputstrStderr- StringBuilder that receives Session Stderr output- Throws:
java.io.IOException- in case of trouble with the network
-
list
public java.util.List<java.lang.String> list(java.lang.String parent) throws java.io.IOExceptionDescription copied from interface:RepositoryReturn a listing of resources names- Parameters:
parent- The parent directory from which to generate the listing.- Returns:
- A listing of the parent directory's file content
- Throws:
java.io.IOException- On listing failure.
-
getExecChannel
private com.jcraft.jsch.ChannelExec getExecChannel(com.jcraft.jsch.Session session) throws java.io.IOException- Parameters:
session- Session- Returns:
- ChannelExec
- Throws:
java.io.IOException
-
replaceArgument
private java.lang.String replaceArgument(java.lang.String command, java.lang.String argument)Replace the argument placeholder with argument or append the argument if no placeholder is present- Parameters:
command- with argument placeholder or notargument- ditto- Returns:
- replaced full command
-
put
public void put(java.io.File source, java.lang.String destination, boolean overwrite) throws java.io.IOException- Overrides:
putin classAbstractRepository- Throws:
java.io.IOException
-
makePath
private void makePath(java.lang.String path, com.jcraft.jsch.Session session) throws java.io.IOExceptionTries to create a directory path on the target system- Parameters:
path- to createsession- to use- Throws:
java.io.IOException
-
checkExistence
private boolean checkExistence(java.lang.String filePath, com.jcraft.jsch.Session session) throws java.io.IOExceptioncheck for existence of file or dir on target system- Parameters:
filePath- to the object to checksession- to use- Returns:
- true: object exists, false otherwise
- Throws:
java.io.IOException
-
get
public void get(java.lang.String source, java.io.File destination) throws java.io.IOExceptionDescription copied from interface:RepositoryFetch a resource from the repository.- Parameters:
source- A string identifying the resource to be fetched.destination- Where to place the fetched resource.- Throws:
java.io.IOException- On retrieval failure.
-
setListCommand
public void setListCommand(java.lang.String cmd)
sets the list command to use for a directory listing listing must be only the filename and each filename on a separate line- Parameters:
cmd- to use. default is "ls -1"
-
getListCommand
public java.lang.String getListCommand()
- Returns:
- the list command to use
-
getCreateDirCommand
public java.lang.String getCreateDirCommand()
- Returns:
- the createDirCommand
-
setCreateDirCommand
public void setCreateDirCommand(java.lang.String createDirCommand)
- Parameters:
createDirCommand- the createDirCommand to set
-
getExistCommand
public java.lang.String getExistCommand()
- Returns:
- the existCommand
-
setExistCommand
public void setExistCommand(java.lang.String existCommand)
- Parameters:
existCommand- the existCommand to set
-
setFileSeparator
public void setFileSeparator(char fileSeparator)
The file separator is the separator to use on the target system On a unix system it is '/', but I don't know, how this is solved on different ssh implementations. Using the default might be fine- Parameters:
fileSeparator- The fileSeparator to use. default '/'
-
setPublishPermissions
public void setPublishPermissions(java.lang.String permissions)
A four digit string (e.g., 0644, see "man chmod", "man open") specifying the permissions of the published files.- Parameters:
permissions- String
-
getRepositoryScheme
protected java.lang.String getRepositoryScheme()
return ssh as scheme use the Resolver type name here? would be nice if it would be static, so we could use SshResolver.getTypeName()- Specified by:
getRepositorySchemein classAbstractSshBasedRepository- Returns:
- String
-
openStream
public java.io.InputStream openStream(SshResource resource) throws java.io.IOException
Not really streaming...need to implement a proper streaming approach?- Parameters:
resource- to stream- Returns:
- InputStream of the resource data
- Throws:
java.io.IOException- if something goes wrong
-
-