001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.resolver;
019:
020: import java.io.File;
021:
022: import org.apache.ivy.core.settings.IvySettings;
023: import org.apache.ivy.plugins.repository.ssh.AbstractSshBasedRepository;
024:
025: /**
026: * Abstract base class for all resolvers using SSH All necessary connection parameters can be set
027: * here via attributes. However all attributes defined in the pattern url of the resolver will have
028: * higher priority and will overwrite the values given here. To specify connection parameters in the
029: * pattern, you have to specify a full url and not just a path as pattern. e.g.
030: * pattern="/path/to/my/repos/[artifact].[ext]" will use all connection parameters from this class
031: * e.g. pattern="ssh://myserver.com/path/to/my/repos/[artifact].[ext]" will use all parameters from
032: * this class with the exception of the host, which will be "myserver.com" e.g.
033: * pattern="sftp://user:geheim@myserver.com:8022/path/to/my/repos/[artifact].[ext]" will use only
034: * the keyFile and keyFilePassword from this class (if needed). Rest will come from the url.
035: */
036: public abstract class AbstractSshBasedResolver extends
037: RepositoryResolver {
038:
039: private boolean passfileSet = false;
040:
041: public AbstractSshBasedResolver() {
042: super ();
043: }
044:
045: private AbstractSshBasedRepository getSshBasedRepository() {
046: return ((AbstractSshBasedRepository) getRepository());
047: }
048:
049: /**
050: * Sets the location of the Public Key file to use for authentication
051: *
052: * @param filePath
053: * full file path name
054: */
055: public void setKeyFile(String filePath) {
056: getSshBasedRepository().setKeyFile(new File(filePath));
057: }
058:
059: /**
060: * Optional password file. If set the repository will use it as an encypted property file, to
061: * load username and passwd entries, and to store them if the user choose to do so. Defaults to
062: * user.dir/.ivy/[host].sftp.passwd, set it to null to disable this feature.
063: */
064: public void setPassfile(String passfile) {
065: getSshBasedRepository().setPassFile(
066: passfile == null ? null : new File(passfile));
067: passfileSet = true;
068: }
069:
070: public void setSettings(IvySettings settings) {
071: super .setSettings(settings);
072: if (!passfileSet) {
073: getSshBasedRepository().setPassFile(
074: new File(settings.getDefaultIvyUserDir(),
075: getSshBasedRepository().getHost()
076: + ".ssh.passwd"));
077: }
078: }
079:
080: /**
081: * Sets the password to authenticate the user if password based login is used if no password is
082: * set and password based login is used, user will be prompted for it the password can also be
083: * set by using a full url for the pattern, like
084: * "sftp://user:password@myserver.com/path/to/repos/[artifact].[ext]"
085: *
086: * @param password
087: * to use
088: */
089: public void setUserPassword(String password) {
090: getSshBasedRepository().setUserPassword(password);
091: }
092:
093: /**
094: * Sets the password to use for decrypting key file (if it is encrypted) if no password is set
095: * and the keyfile is encrypted, the user will be prompted for the password if the keyfile is
096: * passwordless, this parameter will be ignored if given
097: *
098: * @param password
099: * to use
100: */
101: public void setKeyFilePassword(String password) {
102: getSshBasedRepository().setKeyFilePassword(password);
103: }
104:
105: /**
106: * sets the user to use for the ssh communication the user can also be set by using a full url
107: * for the pattern, like "ssh://user@myserver.com/path/to/repos/[artifact].[ext]"
108: *
109: * @param user
110: * on the target system
111: */
112: public void setUser(String user) {
113: getSshBasedRepository().setUser(user);
114: }
115:
116: /**
117: * sets the host to use for the ssh communication the host can also be set by using a full url
118: * for the pattern, like "ssh://myserver.com/path/to/repos/[artifact].[ext]"
119: *
120: * @param host
121: * of the target system
122: */
123: public void setHost(String host) {
124: getSshBasedRepository().setHost(host);
125: }
126:
127: /**
128: * sets the port to use for the ssh communication port 22 is default the port can also be set by
129: * using a full url for the pattern, like
130: * "sftp://myserver.com:8022/path/to/repos/[artifact].[ext]"
131: *
132: * @param port
133: * of the target system
134: */
135: public void setPort(int port) {
136: getSshBasedRepository().setPort(port);
137: }
138:
139: public abstract String getTypeName();
140: }
|