ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Coene (JIRA)" <j...@apache.org>
Subject [jira] Updated: (IVY-661) Incorrect parsing artifactPattern attribute in a sftp resolver
Date Fri, 07 Dec 2007 20:05:43 GMT

     [ https://issues.apache.org/jira/browse/IVY-661?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Maarten Coene updated IVY-661:
------------------------------

    Fix Version/s:     (was: 2.0.0-beta-1)
      Description: 
PROBLEM:

Ivy settings file contains description of resolver:
	<resolvers>
		<sftp name="remote">
			<ivy pattern="sftp://user:password@host:12345/repository/[module]/[module]-[revision].xml"/>
			<artifact pattern="sftp://user:password@host:12345/repository/[module]/[artifact]-[revision].[ext]"/>
		</sftp>
	</resolvers>

Then we try to publish to a repository for the first time on empty server we get a java.io.IOException
and a following directory structure created on the server ~user/sftp:/.
Afterwards when we publish for the second time we get following directory structure ~user/sftp:/user:password@host:12435/repository/module/
and successfully published artifact.
During the first run the java.io.IOException caused by creation of a directory with empty
name. Creation of the directory with empty name caused by double slash (//) following "sftp:".

SOLUTION:

Solution of this problem is in the patch listed below.

{code}
Index: SFTPRepository.java
===================================================================
--- SFTPRepository.java	(revision 601711)
+++ SFTPRepository.java	(working copy)
@@ -20,6 +20,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -132,14 +134,33 @@
     public void put(File source, String destination, boolean overwrite) throws IOException
{
         fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT);
         ChannelSftp c = getSftpChannel(destination);
+		
+		String path = null;
+		try {
+            URI uri = new URI(destination);
+			path = uri.getPath();
+			
+            if (path == null) {
+                throw new URISyntaxException(destination, "Missing path in URI.");
+            }
+        } catch (URISyntaxException e) {
+			IOException ex = new IOException(e.getMessage() + " The uri is in the wrong format. Please
use scheme://user:pass@hostname/path/to/repository.");
+			ex.initCause(e);
+			throw ex;
+        }
+
         try {
-            if (!overwrite && checkExistence(destination, c)) {
+            if (!overwrite && checkExistence(path, c)) {
                 throw new IOException("destination file exists and overwrite == true");
             }
-            if (destination.indexOf('/') != -1) {
-                mkdirs(destination.substring(0, destination.lastIndexOf('/')), c);
+			
+			if (path.indexOf('/') == 0) {
+				path = path.substring(1, path.length());
+			}
+            if (path.indexOf('/') != -1) {
+                mkdirs(path.substring(0, path.lastIndexOf('/')), c);
             }
-            c.put(source.getAbsolutePath(), destination, new MyProgressMonitor());
+            c.put(source.getAbsolutePath(), path, new MyProgressMonitor());
         } catch (SftpException e) {
             IOException ex = new IOException(e.getMessage());
             ex.initCause(e);
{code}

  was:
PROBLEM:

Ivy settings file contains description of resolver:
	<resolvers>
		<sftp name="remote">
			<ivy pattern="sftp://user:password@host:12345/repository/[module]/[module]-[revision].xml"/>
			<artifact pattern="sftp://user:password@host:12345/repository/[module]/[artifact]-[revision].[ext]"/>
		</sftp>
	</resolvers>

Then we try to publish to a repository for the first time on empty server we get a java.io.IOException
and a following directory structure created on the server ~user/sftp:/.
Afterwards when we publish for the second time we get following directory structure ~user/sftp:/user:password@host:12435/repository/module/
and successfully published artifact.
During the first run the java.io.IOException caused by creation of a directory with empty
name. Creation of the directory with empty name caused by double slash (//) following "sftp:".

SOLUTION:

Solution of this problem is in the patch listed below.

Index: SFTPRepository.java
===================================================================
--- SFTPRepository.java	(revision 601711)
+++ SFTPRepository.java	(working copy)
@@ -20,6 +20,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -132,14 +134,33 @@
     public void put(File source, String destination, boolean overwrite) throws IOException
{
         fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT);
         ChannelSftp c = getSftpChannel(destination);
+		
+		String path = null;
+		try {
+            URI uri = new URI(destination);
+			path = uri.getPath();
+			
+            if (path == null) {
+                throw new URISyntaxException(destination, "Missing path in URI.");
+            }
+        } catch (URISyntaxException e) {
+			IOException ex = new IOException(e.getMessage() + " The uri is in the wrong format. Please
use scheme://user:pass@hostname/path/to/repository.");
+			ex.initCause(e);
+			throw ex;
+        }
+
         try {
-            if (!overwrite && checkExistence(destination, c)) {
+            if (!overwrite && checkExistence(path, c)) {
                 throw new IOException("destination file exists and overwrite == true");
             }
-            if (destination.indexOf('/') != -1) {
-                mkdirs(destination.substring(0, destination.lastIndexOf('/')), c);
+			
+			if (path.indexOf('/') == 0) {
+				path = path.substring(1, path.length());
+			}
+            if (path.indexOf('/') != -1) {
+                mkdirs(path.substring(0, path.lastIndexOf('/')), c);
             }
-            c.put(source.getAbsolutePath(), destination, new MyProgressMonitor());
+            c.put(source.getAbsolutePath(), path, new MyProgressMonitor());
         } catch (SftpException e) {
             IOException ex = new IOException(e.getMessage());
             ex.initCause(e);



> Incorrect parsing artifactPattern attribute in a sftp resolver
> --------------------------------------------------------------
>
>                 Key: IVY-661
>                 URL: https://issues.apache.org/jira/browse/IVY-661
>             Project: Ivy
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.0-beta-1
>         Environment: Developer: Windows XP, jdk1.6.0_02, ant-1.7.0, jsch-0.1.36
> SFTP Server: FreeBSD-6.2-RELEASE.
>            Reporter: Alexey Kiselev
>            Priority: Minor
>
> PROBLEM:
> Ivy settings file contains description of resolver:
> 	<resolvers>
> 		<sftp name="remote">
> 			<ivy pattern="sftp://user:password@host:12345/repository/[module]/[module]-[revision].xml"/>
> 			<artifact pattern="sftp://user:password@host:12345/repository/[module]/[artifact]-[revision].[ext]"/>
> 		</sftp>
> 	</resolvers>
> Then we try to publish to a repository for the first time on empty server we get a java.io.IOException
and a following directory structure created on the server ~user/sftp:/.
> Afterwards when we publish for the second time we get following directory structure ~user/sftp:/user:password@host:12435/repository/module/
and successfully published artifact.
> During the first run the java.io.IOException caused by creation of a directory with empty
name. Creation of the directory with empty name caused by double slash (//) following "sftp:".
> SOLUTION:
> Solution of this problem is in the patch listed below.
> {code}
> Index: SFTPRepository.java
> ===================================================================
> --- SFTPRepository.java	(revision 601711)
> +++ SFTPRepository.java	(working copy)
> @@ -20,6 +20,8 @@
>  import java.io.File;
>  import java.io.IOException;
>  import java.io.InputStream;
> +import java.net.URI;
> +import java.net.URISyntaxException;
>  import java.util.ArrayList;
>  import java.util.Collection;
>  import java.util.Iterator;
> @@ -132,14 +134,33 @@
>      public void put(File source, String destination, boolean overwrite) throws IOException
{
>          fireTransferInitiated(getResource(destination), TransferEvent.REQUEST_PUT);
>          ChannelSftp c = getSftpChannel(destination);
> +		
> +		String path = null;
> +		try {
> +            URI uri = new URI(destination);
> +			path = uri.getPath();
> +			
> +            if (path == null) {
> +                throw new URISyntaxException(destination, "Missing path in URI.");
> +            }
> +        } catch (URISyntaxException e) {
> +			IOException ex = new IOException(e.getMessage() + " The uri is in the wrong format.
Please use scheme://user:pass@hostname/path/to/repository.");
> +			ex.initCause(e);
> +			throw ex;
> +        }
> +
>          try {
> -            if (!overwrite && checkExistence(destination, c)) {
> +            if (!overwrite && checkExistence(path, c)) {
>                  throw new IOException("destination file exists and overwrite == true");
>              }
> -            if (destination.indexOf('/') != -1) {
> -                mkdirs(destination.substring(0, destination.lastIndexOf('/')), c);
> +			
> +			if (path.indexOf('/') == 0) {
> +				path = path.substring(1, path.length());
> +			}
> +            if (path.indexOf('/') != -1) {
> +                mkdirs(path.substring(0, path.lastIndexOf('/')), c);
>              }
> -            c.put(source.getAbsolutePath(), destination, new MyProgressMonitor());
> +            c.put(source.getAbsolutePath(), path, new MyProgressMonitor());
>          } catch (SftpException e) {
>              IOException ex = new IOException(e.getMessage());
>              ex.initCause(e);
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message