ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r632729 - in /ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository: ./ sftp/ ssh/ url/ vfs/ vsftp/
Date Sun, 02 Mar 2008 09:58:00 GMT
Author: xavier
Date: Sun Mar  2 01:57:58 2008
New Revision: 632729

URL: http://svn.apache.org/viewvc?rev=632729&view=rev
Log:
checkstyle fix in repository packages

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LazyResource.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LazyResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LazyResource.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LazyResource.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/LazyResource.java Sun Mar
 2 01:57:58 2008
@@ -18,53 +18,53 @@
 package org.apache.ivy.plugins.repository;
 
 public abstract class LazyResource implements Resource {
-    private boolean _init = false;
+    private boolean init = false;
 
-    private boolean _local;
+    private boolean local;
 
-    private String _name;
+    private String name;
 
-    private long _lastModified;
+    private long lastModified;
 
-    private long _contentLength;
+    private long contentLength;
 
-    private boolean _exists;
+    private boolean exists;
 
     public LazyResource(String name) {
-        _name = name;
+        this.name = name;
     }
 
     protected abstract void init();
 
     private void checkInit() {
-        if (!_init) {
+        if (!init) {
             init();
-            _init = true;
+            init = true;
         }
     }
 
     public boolean exists() {
         checkInit();
-        return _exists;
+        return exists;
     }
 
     public long getContentLength() {
         checkInit();
-        return _contentLength;
+        return contentLength;
     }
 
     public long getLastModified() {
         checkInit();
-        return _lastModified;
+        return lastModified;
     }
 
     public String getName() {
-        return _name;
+        return name;
     }
 
     public boolean isLocal() {
         checkInit();
-        return _local;
+        return local;
     }
 
     public String toString() {
@@ -72,19 +72,19 @@
     }
 
     protected void setContentLength(long contentLength) {
-        _contentLength = contentLength;
+        this.contentLength = contentLength;
     }
 
     protected void setExists(boolean exists) {
-        _exists = exists;
+        this.exists = exists;
     }
 
     protected void setLastModified(long lastModified) {
-        _lastModified = lastModified;
+        this.lastModified = lastModified;
     }
 
     protected void setLocal(boolean local) {
-        _local = local;
+        this.local = local;
     }
 
     protected void init(Resource r) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java
Sun Mar  2 01:57:58 2008
@@ -46,6 +46,8 @@
  * 0, 1, 2 and 3
  */
 public class SFTPRepository extends AbstractSshBasedRepository {
+    private static final int MILLIS_PER_SECOND = 1000;
+
     private final class MyProgressMonitor implements SftpProgressMonitor {
         private long totalLength;
 
@@ -91,7 +93,7 @@
                         LsEntry entry = (LsEntry) obj;
                         SftpATTRS attrs = entry.getAttrs();
                         return new BasicResource(path, true, attrs.getSize(),
-                                attrs.getMTime() * 1000, false);
+                                attrs.getMTime() * MILLIS_PER_SECOND, false);
                     }
                 }
             }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPResource.java Sun
Mar  2 01:57:58 2008
@@ -23,53 +23,53 @@
 import org.apache.ivy.plugins.repository.Resource;
 
 public class SFTPResource implements Resource {
-    private SFTPRepository _repository;
+    private SFTPRepository repository;
 
-    private String _path;
+    private String path;
 
-    private transient boolean _init = false;
+    private transient boolean init = false;
 
-    private transient boolean _exists;
+    private transient boolean exists;
 
-    private transient long _lastModified;
+    private transient long lastModified;
 
-    private transient long _contentLength;
+    private transient long contentLength;
 
     public SFTPResource(SFTPRepository repository, String path) {
-        _repository = repository;
-        _path = path;
+        this.repository = repository;
+        this.path = path;
     }
 
     public String getName() {
-        return _path;
+        return path;
     }
 
     public Resource clone(String cloneName) {
-        return new SFTPResource(_repository, cloneName);
+        return new SFTPResource(repository, cloneName);
     }
 
     public long getLastModified() {
         init();
-        return _lastModified;
+        return lastModified;
     }
 
     public long getContentLength() {
         init();
-        return _contentLength;
+        return contentLength;
     }
 
     public boolean exists() {
         init();
-        return _exists;
+        return exists;
     }
 
     private void init() {
-        if (!_init) {
-            Resource r = _repository.resolveResource(_path);
-            _contentLength = r.getContentLength();
-            _lastModified = r.getLastModified();
-            _exists = r.exists();
-            _init = true;
+        if (!init) {
+            Resource r = repository.resolveResource(path);
+            contentLength = r.getContentLength();
+            lastModified = r.getLastModified();
+            exists = r.exists();
+            init = true;
         }
     }
 
@@ -82,6 +82,6 @@
     }
 
     public InputStream openStream() throws IOException {
-        return _repository.openStream(this);
+        return repository.openStream(this);
     }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java Sun Mar  2
01:57:58 2008
@@ -44,6 +44,22 @@
  * Nevertheless credit should go to the original author.
  */
 public class Scp {
+    private static final int MODE_LENGTH = 4;
+
+    private static final int SEND_FILE_BUFFER_LENGTH = 40000;
+
+    private static final int SEND_BYTES_BUFFER_LENGTH = 512;
+
+    private static final int MIN_TLINE_LENGTH = 8;
+
+    private static final int CLINE_SPACE_INDEX2 = 5;
+
+    private static final int CLINE_SPACE_INDEX1 = 4;
+
+    private static final int MIN_C_LINE_LENGTH = 8;
+
+    private static final int DEFAULT_LINE_BUFFER_LENGTH = 30;
+
     private static final int BUFFER_SIZE = 64 * 1024;
 
     /*
@@ -138,7 +154,7 @@
     }
 
     private String receiveLine(InputStream is) throws IOException, RemoteScpException {
-        StringBuffer sb = new StringBuffer(30);
+        StringBuffer sb = new StringBuffer(DEFAULT_LINE_BUFFER_LENGTH);
 
         while (true) {
 
@@ -167,29 +183,31 @@
 
         long len;
 
-        if (line.length() < 8) {
+        if (line.length() < MIN_C_LINE_LENGTH) {
             throw new RemoteScpException(
                     "Malformed C line sent by remote SCP binary, line too short.");
         }
 
-        if ((line.charAt(4) != ' ') || (line.charAt(5) == ' ')) {
+        if ((line.charAt(CLINE_SPACE_INDEX1) != ' ') 
+                || (line.charAt(CLINE_SPACE_INDEX2) == ' ')) {
             throw new RemoteScpException("Malformed C line sent by remote SCP binary.");
         }
 
-        int lengthNameSep = line.indexOf(' ', 5);
+        int lengthNameSep = line.indexOf(' ', CLINE_SPACE_INDEX2);
 
         if (lengthNameSep == -1) {
             throw new RemoteScpException("Malformed C line sent by remote SCP binary.");
         }
 
-        String lengthSubstring = line.substring(5, lengthNameSep);
+        String lengthSubstring = line.substring(CLINE_SPACE_INDEX2, lengthNameSep);
         String nameSubstring = line.substring(lengthNameSep + 1);
 
         if ((lengthSubstring.length() <= 0) || (nameSubstring.length() <= 0)) {
             throw new RemoteScpException("Malformed C line sent by remote SCP binary.");
         }
 
-        if ((6 + lengthSubstring.length() + nameSubstring.length()) != line.length()) {
+        if ((CLINE_SPACE_INDEX2 + 1 + lengthSubstring.length() + nameSubstring.length())

+                != line.length()) {
             throw new RemoteScpException("Malformed C line sent by remote SCP binary.");
         }
 
@@ -217,7 +235,7 @@
         long atime;
         long secondMsec;
 
-        if (line.length() < 8) {
+        if (line.length() < MIN_TLINE_LENGTH) {
             throw new RemoteScpException(
                     "Malformed T line sent by remote SCP binary, line too short.");
         }
@@ -261,7 +279,8 @@
     private void sendBytes(Channel channel, byte[] data, String fileName, String mode)
             throws IOException, RemoteScpException {
         OutputStream os = channel.getOutputStream();
-        InputStream is = new BufferedInputStream(channel.getInputStream(), 512);
+        InputStream is = new BufferedInputStream(
+            channel.getInputStream(), SEND_BYTES_BUFFER_LENGTH);
 
         try {
             if (channel.isConnected()) {
@@ -296,8 +315,10 @@
             throws IOException, RemoteScpException {
         byte[] buffer = new byte[BUFFER_SIZE];
 
-        OutputStream os = new BufferedOutputStream(channel.getOutputStream(), 40000);
-        InputStream is = new BufferedInputStream(channel.getInputStream(), 512);
+        OutputStream os = new BufferedOutputStream(
+            channel.getOutputStream(), SEND_FILE_BUFFER_LENGTH);
+        InputStream is = new BufferedInputStream(
+            channel.getInputStream(), SEND_BYTES_BUFFER_LENGTH);
 
         try {
             if (channel.isConnected()) {
@@ -527,7 +548,7 @@
             throw new IllegalArgumentException("Null argument.");
         }
 
-        if (mode.length() != 4) {
+        if (mode.length() != MODE_LENGTH) {
             throw new IllegalArgumentException("Invalid mode.");
         }
 
@@ -591,7 +612,7 @@
             throw new IllegalArgumentException("Null argument.");
         }
 
-        if (mode.length() != 4) {
+        if (mode.length() != MODE_LENGTH) {
             throw new IllegalArgumentException("Invalid mode.");
         }
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLRepository.java Sun
Mar  2 01:57:58 2008
@@ -35,15 +35,15 @@
 import org.apache.ivy.util.url.ApacheURLLister;
 
 public class URLRepository extends AbstractRepository {
-    private RepositoryCopyProgressListener _progress = new RepositoryCopyProgressListener(this);
+    private RepositoryCopyProgressListener progress = new RepositoryCopyProgressListener(this);
 
-    private Map _resourcesCache = new HashMap();
+    private Map resourcesCache = new HashMap();
 
     public Resource getResource(String source) throws IOException {
-        Resource res = (Resource) _resourcesCache.get(source);
+        Resource res = (Resource) resourcesCache.get(source);
         if (res == null) {
             res = new URLResource(new URL(source));
-            _resourcesCache.put(source, res);
+            resourcesCache.put(source, res);
         }
         return res;
     }
@@ -54,9 +54,9 @@
             Resource res = getResource(source);
             long totalLength = res.getContentLength();
             if (totalLength > 0) {
-                _progress.setTotalLength(new Long(totalLength));
+                progress.setTotalLength(new Long(totalLength));
             }
-            FileUtil.copy(new URL(source), destination, _progress);
+            FileUtil.copy(new URL(source), destination, progress);
         } catch (IOException ex) {
             fireTransferError(ex);
             throw ex;
@@ -64,7 +64,7 @@
             fireTransferError(ex);
             throw ex;
         } finally {
-            _progress.setTotalLength(null);
+            progress.setTotalLength(null);
         }
     }
 
@@ -73,11 +73,11 @@
                 "URL repository is not able to put files for the moment");
     }
 
-    private ApacheURLLister _lister = new ApacheURLLister();
+    private ApacheURLLister lister = new ApacheURLLister();
 
     public List list(String parent) throws IOException {
         if (parent.startsWith("http")) {
-            List urls = _lister.listAll(new URL(parent));
+            List urls = lister.listAll(new URL(parent));
             if (urls != null) {
                 List ret = new ArrayList(urls.size());
                 for (ListIterator iter = urls.listIterator(); iter.hasNext();) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/url/URLResource.java Sun
Mar  2 01:57:58 2008
@@ -27,22 +27,22 @@
 import org.apache.ivy.util.url.URLHandler.URLInfo;
 
 public class URLResource implements Resource {
-    private URL _url;
+    private URL url;
 
-    private boolean _init = false;
+    private boolean init = false;
 
-    private long _lastModified;
+    private long lastModified;
 
-    private long _contentLength;
+    private long contentLength;
 
-    private boolean _exists;
+    private boolean exists;
 
     public URLResource(URL url) {
-        _url = url;
+        this.url = url;
     }
 
     public String getName() {
-        return _url.toExternalForm();
+        return url.toExternalForm();
     }
 
     public Resource clone(String cloneName) {
@@ -55,36 +55,36 @@
     }
 
     public long getLastModified() {
-        if (!_init) {
+        if (!init) {
             init();
         }
-        return _lastModified;
+        return lastModified;
     }
 
     private void init() {
-        URLInfo info = URLHandlerRegistry.getDefault().getURLInfo(_url);
-        _contentLength = info.getContentLength();
-        _lastModified = info.getLastModified();
-        _exists = info.isReachable();
-        _init = true;
+        URLInfo info = URLHandlerRegistry.getDefault().getURLInfo(url);
+        contentLength = info.getContentLength();
+        lastModified = info.getLastModified();
+        exists = info.isReachable();
+        init = true;
     }
 
     public long getContentLength() {
-        if (!_init) {
+        if (!init) {
             init();
         }
-        return _contentLength;
+        return contentLength;
     }
 
     public boolean exists() {
-        if (!_init) {
+        if (!init) {
             init();
         }
-        return _exists;
+        return exists;
     }
 
     public URL getURL() {
-        return _url;
+        return url;
     }
 
     public String toString() {
@@ -96,6 +96,6 @@
     }
 
     public InputStream openStream() throws IOException {
-        return _url.openStream();
+        return url.openStream();
     }
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsRepository.java Sun
Mar  2 01:57:58 2008
@@ -48,9 +48,9 @@
      */
     private static final String IVY_VFS_CONFIG = "ivy_vfs.xml";
 
-    private StandardFileSystemManager _manager = null;
+    private StandardFileSystemManager manager = null;
 
-    private final CopyProgressListener _progress = new RepositoryCopyProgressListener(this);
+    private final CopyProgressListener progress = new RepositoryCopyProgressListener(this);
 
     /**
      * Create a new Ivy VFS Repository Instance
@@ -60,11 +60,11 @@
 
     private FileSystemManager getVFSManager() throws IOException {
         synchronized (this) {
-            if (_manager == null) {
-                _manager = createVFSManager();
+            if (manager == null) {
+                manager = createVFSManager();
             }
         }
-        return _manager;
+        return manager;
     }
 
     private StandardFileSystemManager createVFSManager() throws IOException {
@@ -109,9 +109,9 @@
     }
 
     protected void finalize() {
-        if (_manager != null) {
-            _manager.close();
-            _manager = null;
+        if (manager != null) {
+            manager.close();
+            manager = null;
         }
     }
 
@@ -146,7 +146,7 @@
                 throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI
                         + ": no content found");
             }
-            FileUtil.copy(content.getInputStream(), destination, _progress);
+            FileUtil.copy(content.getInputStream(), destination, progress);
         } catch (IOException ex) {
             fireTransferError(ex);
             throw ex;
@@ -210,7 +210,7 @@
                     + " to put data to: resource has no content");
         }
 
-        FileUtil.copy(new FileInputStream(source), dest.getContent().getOutputStream(), _progress);
+        FileUtil.copy(new FileInputStream(source), dest.getContent().getOutputStream(), progress);
     }
 
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vfs/VfsResource.java Sun
Mar  2 01:57:58 2008
@@ -35,46 +35,46 @@
  * VFS implementation of the Resource interface
  */
 public class VfsResource implements Resource {
-    private String _vfsURI;
+    private String vfsURI;
 
-    private FileSystemManager _fsManager;
+    private FileSystemManager fsManager;
 
-    private transient boolean _init = false;
+    private transient boolean init = false;
 
-    private transient boolean _exists;
+    private transient boolean exists;
 
-    private transient long _lastModified;
+    private transient long lastModified;
 
-    private transient long _contentLength;
+    private transient long contentLength;
 
-    private transient FileContent _content = null;
+    private transient FileContent content = null;
 
-    private transient FileObject _resourceImpl;
+    private transient FileObject resourceImpl;
 
     // Constructor
     public VfsResource(String vfsURI, FileSystemManager fsManager) {
-        this._vfsURI = vfsURI;
-        this._fsManager = fsManager;
-        this._init = false;
+        this.vfsURI = vfsURI;
+        this.fsManager = fsManager;
+        this.init = false;
     }
 
     private void init() {
-        if (!_init) {
+        if (!init) {
             try {
-                _resourceImpl = _fsManager.resolveFile(_vfsURI);
-                _content = _resourceImpl.getContent();
+                resourceImpl = fsManager.resolveFile(vfsURI);
+                content = resourceImpl.getContent();
 
-                _exists = _resourceImpl.exists();
-                _lastModified = _content.getLastModifiedTime();
-                _contentLength = _content.getSize();
+                exists = resourceImpl.exists();
+                lastModified = content.getLastModifiedTime();
+                contentLength = content.getSize();
             } catch (FileSystemException e) {
                 Message.verbose(e.getLocalizedMessage());
-                _exists = false;
-                _lastModified = 0;
-                _contentLength = 0;
+                exists = false;
+                lastModified = 0;
+                contentLength = 0;
             }
 
-            _init = true;
+            init = true;
         }
     }
 
@@ -89,9 +89,9 @@
         init();
         ArrayList list = new ArrayList();
         try {
-            if ((_resourceImpl != null) && _resourceImpl.exists()
-                    && (_resourceImpl.getType() == FileType.FOLDER)) {
-                FileObject[] children = _resourceImpl.getChildren();
+            if ((resourceImpl != null) && resourceImpl.exists()
+                    && (resourceImpl.getType() == FileType.FOLDER)) {
+                FileObject[] children = resourceImpl.getChildren();
                 for (int i = 0; i < children.length; i++) {
                     FileObject child = children[i];
                     list.add(normalize(child.getName().getURI()));
@@ -105,7 +105,7 @@
 
     public FileContent getContent() {
         init();
-        return _content;
+        return content;
     }
 
     /**
@@ -114,11 +114,11 @@
      * @return a <code>String</code> representing the Resource URL.
      */
     public String getName() {
-        return normalize(_vfsURI);
+        return normalize(vfsURI);
     }
 
     public Resource clone(String cloneName) {
-        return new VfsResource(cloneName, _fsManager);
+        return new VfsResource(cloneName, fsManager);
     }
 
     /**
@@ -146,7 +146,7 @@
      */
     public long getLastModified() {
         init();
-        return _lastModified;
+        return lastModified;
     }
 
     /**
@@ -156,7 +156,7 @@
      */
     public long getContentLength() {
         init();
-        return _contentLength;
+        return contentLength;
     }
 
     /**
@@ -167,7 +167,7 @@
      */
     public boolean exists() {
         init();
-        return _exists;
+        return exists;
     }
 
     /**
@@ -181,7 +181,7 @@
         init();
 
         try {
-            return _resourceImpl.exists();
+            return resourceImpl.exists();
             // originally I only checked for a FileSystemException. I expanded it to
             // include all exceptions when I found it would throw a NPE exception when the
query was
             // run on non-wellformed VFS URI.

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
Sun Mar  2 01:57:58 2008
@@ -47,6 +47,39 @@
  * to be in the PATH. Tested with SecureCRT 5.0.5
  */
 public class VsftpRepository extends AbstractRepository {
+    private static final int LS_DATE_INDEX4 = 7;
+
+    private static final int LS_DATE_INDEX3 = 6;
+
+    private static final int LS_DATE_INDEX2 = 5;
+
+    private static final int LS_DATE_INDEX1 = 4;
+
+    private static final int LS_SIZE_INDEX = 3;
+
+    private static final int LS_PARTS_NUMBER = 9;
+
+    private static final int DISCONNECT_COMMAND_TIMEOUT = 300;
+
+    private static final int REUSE_CONNECTION_SLEEP_TIME = 10;
+
+    private static final int READER_ALIVE_SLEEP_TIME = 100;
+
+    private static final int MAX_READER_ALIVE_ATTEMPT = 5;
+
+    private static final int ERROR_SLEEP_TIME = 30;
+
+    private static final int PROMPT_SLEEP_TIME = 50;
+
+    private static final int MAX_READ_PROMPT_ATTEMPT = 5;
+
+    private static final int GET_JOIN_MAX_TIME = 100;
+
+    private static final int DEFAULT_REUSE_CONNECTION_TIME = 300000;
+        // reuse connection during 5 minutes by default
+
+    private static final int DEFAULT_READ_TIMEOUT = 30000;
+
     private static final String PROMPT = "vsftp> ";
 
     private static final SimpleDateFormat FORMAT = new SimpleDateFormat("MMM dd, yyyy HH:mm",
@@ -66,9 +99,9 @@
 
     private volatile StringBuffer errors = new StringBuffer();
 
-    private long readTimeout = 30000;
+    private long readTimeout = DEFAULT_READ_TIMEOUT;
 
-    private long reuseConnection = 5 * 60 * 1000; // reuse connection during 5 minutes by
default
+    private long reuseConnection = DEFAULT_REUSE_CONNECTION_TIME; 
 
     private volatile long lastCommand;
 
@@ -155,7 +188,7 @@
                     }
                 }
                 try {
-                    get.join(100);
+                    get.join(GET_JOIN_MAX_TIME);
                 } catch (InterruptedException e) {
                     if (to.exists()) {
                         to.delete();
@@ -343,7 +376,8 @@
                         boolean getPrompt = false;
                         // the reading is done in a for loop making five attempts to read
the stream
                         // if we do not reach the next prompt
-                        for (int attempts = 0; !getPrompt && attempts < 5; attempts++)
{
+                        for (int attempts = 0; 
+                                !getPrompt && attempts < MAX_READ_PROMPT_ATTEMPT;
attempts++) {
                             while ((c = in.read()) != -1) {
                                 attempts = 0; // we manage to read something, reset numer
of
                                 // attempts
@@ -358,7 +392,7 @@
                             }
                             if (!getPrompt) {
                                 try {
-                                    Thread.sleep(50);
+                                    Thread.sleep(PROMPT_SLEEP_TIME);
                                 } catch (InterruptedException e) {
                                     break;
                                 }
@@ -371,9 +405,10 @@
                                 errorsLastUpdateTime = lastCommand;
                             }
 
-                            while ((System.currentTimeMillis() - errorsLastUpdateTime) <
50) {
+                            while ((System.currentTimeMillis() - errorsLastUpdateTime) 
+                                            < PROMPT_SLEEP_TIME) {
                                 try {
-                                    Thread.sleep(30);
+                                    Thread.sleep(ERROR_SLEEP_TIME);
                                 } catch (InterruptedException e) {
                                     break;
                                 }
@@ -415,9 +450,9 @@
         } else if (!done[0]) {
             if (reader != null && reader.isAlive()) {
                 reader.interrupt();
-                for (int i = 0; i < 5 && reader.isAlive(); i++) {
+                for (int i = 0; i < MAX_READER_ALIVE_ATTEMPT && reader.isAlive();
i++) {
                     try {
-                        Thread.sleep(100);
+                        Thread.sleep(READER_ALIVE_SLEEP_TIME);
                     } catch (InterruptedException e) {
                         break;
                     }
@@ -456,7 +491,7 @@
                         public void run() {
                             initContext();
                             try {
-                                long sleep = 10;
+                                long sleep = REUSE_CONNECTION_SLEEP_TIME;
                                 while (in != null && sleep > 0) {
                                     sleep(sleep);
                                     sleep = reuseConnection
@@ -508,10 +543,12 @@
                 initContext();
                 int c;
                 try {
+                    // CheckStyle:InnerAssignment OFF
                     while (err != null && (c = err.read()) != -1) {
                         errors.append((char) c);
                         errorsLastUpdateTime = System.currentTimeMillis();
                     }
+                    // CheckStyle:InnerAssignment ON
                 } catch (IOException e) {
                     //nothing to do
                 }
@@ -550,7 +587,7 @@
         if (in != null) {
             Message.verbose("disconnecting from " + getHost() + "... ");
             try {
-                sendCommand("exit", false, 300);
+                sendCommand("exit", false, DISCONNECT_COMMAND_TIMEOUT);
             } catch (IOException e) {
                 //nothing I can do
             } finally {
@@ -609,13 +646,14 @@
             return new BasicResource(file, false, 0, 0, false);
         } else {
             String[] parts = responseLine.split("\\s+");
-            if (parts.length != 9) {
+            if (parts.length != LS_PARTS_NUMBER) {
                 Message.debug("unrecognized ls format: " + responseLine);
                 return new BasicResource(file, false, 0, 0, false);
             } else {
                 try {
-                    long contentLength = Long.parseLong(parts[3]);
-                    String date = parts[4] + " " + parts[5] + " " + parts[6] + " " + parts[7];
+                    long contentLength = Long.parseLong(parts[LS_SIZE_INDEX]);
+                    String date = parts[LS_DATE_INDEX1] + " " + parts[LS_DATE_INDEX2] 
+                                     + " " + parts[LS_DATE_INDEX3] + " " + parts[LS_DATE_INDEX4];
                     return new BasicResource(file, true, contentLength, FORMAT.parse(date)
                             .getTime(), false);
                 } catch (Exception ex) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java?rev=632729&r1=632728&r2=632729&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpResource.java
Sun Mar  2 01:57:58 2008
@@ -25,16 +25,16 @@
 import org.apache.ivy.util.Message;
 
 public class VsftpResource extends LazyResource {
-    private VsftpRepository _repository;
+    private VsftpRepository repository;
 
     public VsftpResource(VsftpRepository repository, String file) {
         super(file);
-        _repository = repository;
+        this.repository = repository;
     }
 
     protected void init() {
         try {
-            init(_repository.getInitResource(getName()));
+            init(repository.getInitResource(getName()));
         } catch (IOException e) {
             Message.verbose(e.toString());
         }
@@ -47,7 +47,7 @@
 
     public Resource clone(String cloneName) {
         try {
-            return _repository.getResource(cloneName);
+            return repository.getResource(cloneName);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }



Mime
View raw message