KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > resolver > AbstractSshBasedResolver


1 package fr.jayasoft.ivy.resolver;
2
3 import java.io.File JavaDoc;
4
5 import fr.jayasoft.ivy.Ivy;
6 import fr.jayasoft.ivy.repository.ssh.AbstractSshBasedRepository;
7
8 /**
9  * Abstract base class for all resolvers using SSH
10  *
11  * All necessary connection parameters can be set here via attributes.
12  * However all attributes defined in the pattern url of the resolver will have higher
13  * priority and will overwrite the values given here. To specify connection parameters
14  * in the pattern, you have to specify a full url and not just a path as pattern.
15  * e.g. pattern="/path/to/my/repos/[artifact].[ext]" will use all connection parameters
16  * from this class
17  * e.g. pattern="ssh://myserver.com/path/to/my/repos/[artifact].[ext]" will use all parameters
18  * from this class with the exception of the host, which will be "myserver.com"
19  * e.g. pattern="sftp://user:geheim@myserver.com:8022/path/to/my/repos/[artifact].[ext]" will
20  * use only the keyFile and keyFilePassword from this class (if needed). Rest will come from the url.
21  */

22 public abstract class AbstractSshBasedResolver extends RepositoryResolver {
23
24     private boolean passfileSet = false;
25
26     public AbstractSshBasedResolver() {
27         super();
28     }
29
30     private AbstractSshBasedRepository getSshBasedRepository() {
31         return ((AbstractSshBasedRepository)getRepository());
32     }
33
34     /**
35      * Sets the location of the Public Key file to use for authentication
36      * @param filePath full file path name
37      */

38     public void setKeyFile(String JavaDoc filePath) {
39         getSshBasedRepository().setKeyFile(new File JavaDoc(filePath));
40     }
41
42     /**
43      * Optional password file. If set the repository will use it as an encypted property file, to load
44      * username and passwd entries, and to store them if the user choose to do so.
45      *
46      * Defaults to user.dir/.ivy/[host].sftp.passwd, set it to null to disable this feature.
47      */

48     public void setPassfile(String JavaDoc passfile) {
49         getSshBasedRepository().setPassFile(passfile == null ? null : new File JavaDoc(passfile));
50         passfileSet = true;
51     }
52
53     public void setIvy(Ivy ivy) {
54         super.setIvy(ivy);
55         if (!passfileSet) {
56             getSshBasedRepository().setPassFile(new File JavaDoc(ivy.getDefaultIvyUserDir(), getSshBasedRepository().getHost()+".ssh.passwd"));
57         }
58     }
59
60     /**
61      * Sets the password to authenticate the user if password based login is used
62      * if no password is set and password based login is used, user will be prompted for it
63      * the password can also be set by using a full url for the pattern, like
64      * "sftp://user:password@myserver.com/path/to/repos/[artifact].[ext]"
65      * @param password to use
66      */

67     public void setUserPassword(String JavaDoc password) {
68         getSshBasedRepository().setUserPassword(password);
69     }
70
71     /**
72      * Sets the password to use for decrypting key file (if it is encrypted)
73      * if no password is set and the keyfile is encrypted, the user will be prompted for the password
74      * if the keyfile is passwordless, this parameter will be ignored if given
75      * @param password to use
76      */

77     public void setKeyFilePassword(String JavaDoc password) {
78         getSshBasedRepository().setKeyFilePassword(password);
79     }
80
81     /**
82      * sets the user to use for the ssh communication
83      * the user can also be set by using a full url for the pattern, like
84      * "ssh://user@myserver.com/path/to/repos/[artifact].[ext]"
85      * @param user on the target system
86      */

87     public void setUser(String JavaDoc user) {
88         getSshBasedRepository().setUser(user);
89     }
90
91     /**
92      * sets the host to use for the ssh communication
93      * the host can also be set by using a full url for the pattern, like
94      * "ssh://myserver.com/path/to/repos/[artifact].[ext]"
95      * @param host of the target system
96      */

97     public void setHost(String JavaDoc host) {
98         getSshBasedRepository().setHost(host);
99     }
100
101     /**
102      * sets the port to use for the ssh communication
103      * port 22 is default
104      * the port can also be set by using a full url for the pattern, like
105      * "sftp://myserver.com:8022/path/to/repos/[artifact].[ext]"
106      * @param port of the target system
107      */

108     public void setPort(int port) {
109         getSshBasedRepository().setPort(port);
110     }
111     
112     abstract public String JavaDoc getTypeName();
113 }
Popular Tags