michal 2003/08/02 15:48:40
Modified: src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
Deployer.java SFtpDeployer.java ScpDeployer.java
FileDeployer.java GenericSshDeployer.java
AbstractDeployer.java
Log:
Added flush() method to Deployer
SCP delpoyer now creates zip, delpoys and then unzip
(need to check how portable accross variuos Unixes this code is)
Revision Changes Path
1.4 +21 -16
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/Deployer.java
Index: Deployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/Deployer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Deployer.java 17 Jul 2003 11:13:16 -0000 1.3
+++ Deployer.java 2 Aug 2003 22:48:39 -0000 1.4
@@ -1,9 +1,6 @@
package org.apache.maven.deploy.deployers;
-import org.apache.maven.deploy.RepositoryInfo;
import org.apache.maven.deploy.DeployRequest;
-import org.apache.maven.deploy.exceptions.AuthenticationException;
-import org.apache.maven.deploy.exceptions.TransferFailedException;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -60,45 +57,53 @@
*
* ====================================================================
*/
+import org.apache.maven.deploy.RepositoryInfo;
+import org.apache.maven.deploy.exceptions.AuthenticationException;
+import org.apache.maven.deploy.exceptions.TransferFailedException;
/**
- *
- * Common interface for classes capable of uploading a file to remote host
-
+ *
+ * Common interface for classes capable of uploading a file to remote host
+
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a>
* @version $Id$
*/
public interface Deployer
{
-
/**
* Set the information about host to which we will deploy.
- * In this method deployer can allocate the resources which will
+ * In this method deployer can allocate the resources which will
* be needed to perform an upload. E.g. connection to remote host
- * can be opened,
+ * can be opened,
* Resources allocated in this metod should
* be release when deloyer is not needed any more
- * @see #release()
+ * @see #release()
*
* @param repoInfo
* @throws AuthenticationException when connection to remote host cannot be
established
*/
- public void init(RepositoryInfo repoInfo)
+ public void init( RepositoryInfo repoInfo )
throws AuthenticationException;
/**
- * Release all resources which were allocated
+ * Release all resources which were allocated
* by this deployer (e.g. a connection to remote host)
*
*/
- public void release();
+ public void release( );
/**
* Perform an upload of single file to remote host
* @param request <code>DeployRequest</code> which should contatin all
parameters
* which are necessery to upload a file
- * to remote host.
+ * to remote host.
+ */
+ public void deploy( DeployRequest request )
+ throws TransferFailedException;
+
+ /**
+ *
*/
- public void deploy(DeployRequest request) throws TransferFailedException;
+ public void flush() throws TransferFailedException;
}
1.7 +5 -5
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java
Index: SFtpDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SFtpDeployer.java 17 Jul 2003 11:13:17 -0000 1.6
+++ SFtpDeployer.java 2 Aug 2003 22:48:39 -0000 1.7
@@ -166,7 +166,7 @@
}
}
- if (getAuthenticationInfo().isDebugOn())
+ if (getRepositoryInfo().isDebugOn())
{
channel.put(
request.getSrcFile(),
@@ -182,12 +182,12 @@
if (groupId != null)
{
- if (getAuthenticationInfo().isDebugOn())
+ if (getRepositoryInfo().isDebugOn())
{
System.out.println("Changing group to: " + groupId);
}
channel.chgrp(groupId.intValue(), request.getDestFile());
- if (getAuthenticationInfo().isDebugOn())
+ if (getRepositoryInfo().isDebugOn())
{
System.out.println("Group successfully changed");
}
@@ -204,7 +204,7 @@
String msg =
"Error occured while deploying to remote host:"
- + getAuthenticationInfo().getHost()
+ + getRepositoryInfo().getHost()
+ ":"
+ e.getMessage();
throw new TransferFailedException(msg, e);
1.6 +202 -24
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java
Index: ScpDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ScpDeployer.java 17 Jul 2003 11:13:17 -0000 1.5
+++ ScpDeployer.java 2 Aug 2003 22:48:39 -0000 1.6
@@ -1,5 +1,4 @@
package org.apache.maven.deploy.deployers;
-
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -56,20 +55,27 @@
* ====================================================================
*/
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.Session;
+
+import org.apache.maven.deploy.DeployRequest;
+import org.apache.maven.deploy.RepositoryInfo;
+import org.apache.maven.deploy.exceptions.AuthenticationException;
+import org.apache.maven.deploy.exceptions.TransferFailedException;
+import org.apache.maven.deploy.util.Packager;
+
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import org.apache.maven.deploy.DeployRequest;
-import org.apache.maven.deploy.exceptions.TransferFailedException;
-
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.Session;
+import java.util.LinkedList;
+import java.util.List;
/**
- * An SSH2/SCP deployer
- *
+ * An SSH2/SCP deployer
+ *
* @author Michal Maczka
* @version $Revision$ $Date$
*/
@@ -80,54 +86,216 @@
/** SSH2 Channel name used to communicate with the server*/
public final static String EXEC_CHANNEL = "exec";
+ public final static String COMPRESS = "maven.deployer.scp.compress";
+
+ /**
+ * I want to have compression by default
+ * so if system property is missing flag will be set to false
+ * that's why I am using deployNotCompressed variable name instead of
+ * straight forward deployCompressed
+ */
+ public boolean deployNotCompressed = true;
+ private List srcFiles = new LinkedList();
+ private List destFiles = new LinkedList();
+
+ /**
+ * @see org.apache.maven.deploy.deployers.Deployer#release()
+ */
+ public void flush() throws TransferFailedException
+ {
+ if (!deployNotCompressed)
+ {
+ doDeployCompressed();
+ }
+
+ super.flush();
+ }
+
+ /**
+ * @return
+ */
+ public boolean isDeployNotCompressed()
+ {
+ return deployNotCompressed;
+ }
+
+ /**
+ * @param deployCompressed
+ */
+ public void setDeployNotCompressed(boolean deployNotCompressed)
+ {
+ this.deployNotCompressed = deployNotCompressed;
+ }
+
+ /**
+ * @todo Find better way to configure deployer
+ * @see
org.apache.maven.deploy.deployers.Deployer#init(org.apache.maven.deploy.RepositoryInfo)
+ */
+ public void init(RepositoryInfo repoInfo) throws AuthenticationException
+ {
+ setDeployNotCompressed(Boolean.getBoolean(COMPRESS));
+ super.init(repoInfo);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.maven.deploy.deployers.Deployer#deploy(org.apache.maven.deploy.DeployRequest)
+ */
+ public void deploy(DeployRequest request) throws TransferFailedException
+ {
+ if (deployNotCompressed)
+ {
+ doDeployNotCompressed(request);
+ }
+ else
+ {
+ srcFiles.add(request.getSrcFile());
+ destFiles.add(request.getDestFile());
+ }
+ }
/**
* @see Deployer#deploy(DeployRequest)
*
*/
- public void deploy(DeployRequest request) throws TransferFailedException
- {
+ public void doDeployNotCompressed(DeployRequest request)
+ throws TransferFailedException
+ {
Session session = getSession();
String mkdirCmd =
"mkdir -p "
- + getAuthenticationInfo().getBasedir()
+ + getRepositoryInfo().getBasedir()
+ "/"
+ request.dirname()
+ "\n";
+
executeSimpleCommand(session, mkdirCmd);
doCopy(session, request);
- if (getAuthenticationInfo().getGroup() != null)
- {
+ if (getRepositoryInfo().getGroup() != null)
+ {
String chgrpCmd =
"chgrp "
- + getAuthenticationInfo().getGroup()
+ + getRepositoryInfo().getGroup()
+ " "
- + getAuthenticationInfo().getBasedir()
+ + getRepositoryInfo().getBasedir()
+ "/"
+ request.getDestFile()
+ "\n";
+
executeSimpleCommand(session, chgrpCmd);
}
+ }
+
+ /**
+ * @see Deployer#deploy(DeployRequest)
+ *
+ */
+ public void doDeployCompressed() throws TransferFailedException
+ {
+ Session session = getSession();
+ File zip = null;
+
+ try
+ {
+ zip = File.createTempFile("maven-deployer-", ".zip");
+ Packager.createZip(srcFiles, destFiles, zip);
+ }
+ catch (IOException e)
+ {
+ if ((zip != null) && zip.exists())
+ {
+ try
+ {
+ zip.delete();
+ }
+ catch (Exception ee)
+ {
+ // ignore
+ // file is left in temp directory
+ // no tragedy
+ }
+ }
+
+ throw new TransferFailedException("Cannot create ZIP file");
+ }
+
+ try
+ {
+ DeployRequest request =
+ new DeployRequest(zip.getAbsolutePath(), zip.getName());
+
+ doCopy(session, request);
+
+ String unzipCmd =
+ "unzip -d -u "
+ + getRepositoryInfo().getBasedir()
+ + " "
+ + getRepositoryInfo().getBasedir()
+ + "/"
+ + request.getDestFile()
+ + "\n";
+ executeSimpleCommand(session, unzipCmd);
+
+ //@ this is not working!
+ String rmCmd =
+ "rm -f "
+ + getRepositoryInfo().getBasedir()
+ + "/"
+ + request.getDestFile()
+ + "\n";
+
+ executeSimpleCommand(session, rmCmd);
+
+ if (getRepositoryInfo().getGroup() != null)
+ {
+ String chgrpCmd =
+ "chgrp -r"
+ + getRepositoryInfo().getGroup()
+ + " "
+ + getRepositoryInfo().getBasedir()
+ + "\n";
+
+ executeSimpleCommand(session, chgrpCmd);
+ }
+ }
+ finally
+ {
+ if ((zip != null) && zip.exists())
+ {
+ try
+ {
+ zip.delete();
+ }
+ catch (Exception ee)
+ {
+ // ignore
+ // file is left in temp directory
+ // no tragedy
+ }
+ }
+ }
}
/**
- * Execute <i>"simple"</i> remote command using exec channel
+ * Execute <i>"simple"</i> remote command using exec channel
*/
private void executeSimpleCommand(Session session, String command)
throws TransferFailedException
{
-
System.out.println("Executing command: " + command);
+
ChannelExec channel = null;
+
try
{
channel = (ChannelExec) session.openChannel(EXEC_CHANNEL);
channel.setCommand(command);
+
OutputStream out = channel.getOutputStream();
InputStream in = channel.getInputStream();
+
channel.connect();
}
catch (Exception e)
@@ -151,23 +319,25 @@
private void doCopy(Session session, DeployRequest request)
throws TransferFailedException
{
-
ChannelExec channel = null;
+
try
{
String srcFile = request.getSrcFile();
String destFile =
- getAuthenticationInfo().getBasedir()
- + "/"
- + request.getDestFile();
+ getRepositoryInfo().getBasedir() + "/" + request.getDestFile();
+
// exec 'scp -t rfile' remotely
String command = "scp -t " + destFile;
+
System.out.println("Executing command: " + command);
channel = (ChannelExec) session.openChannel(EXEC_CHANNEL);
channel.setCommand(command);
+
// get I/O streams for remote scp
OutputStream out = channel.getOutputStream();
InputStream in = channel.getInputStream();
+
channel.connect();
byte[] tmp = new byte[1];
@@ -181,7 +351,9 @@
// send "C0644 filesize filename", where filename should not include '/'
int filesize = (int) (new File(srcFile)).length();
+
command = "C0644 " + filesize + " ";
+
if (srcFile.lastIndexOf('/') > 0)
{
command += srcFile.substring(srcFile.lastIndexOf('/') + 1);
@@ -190,6 +362,7 @@
{
command += srcFile;
}
+
command += "\n";
out.write(command.getBytes());
@@ -205,11 +378,16 @@
// send a content of inputFile
FileInputStream fis = new FileInputStream(srcFile);
byte[] buf = new byte[1024];
+
while (true)
{
int len = fis.read(buf, 0, buf.length);
+
if (len <= 0)
+ {
break;
+ }
+
out.write(buf, 0, len);
out.flush();
}
@@ -230,7 +408,8 @@
{
String msg =
"Error occured while deploying to remote host:"
- + getAuthenticationInfo().getHost();
+ + getRepositoryInfo().getHost();
+
throw new TransferFailedException(msg, e);
}
finally
@@ -241,5 +420,4 @@
}
}
}
-
}
1.9 +2 -2
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java
Index: FileDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FileDeployer.java 17 Jul 2003 11:13:17 -0000 1.8
+++ FileDeployer.java 2 Aug 2003 22:48:39 -0000 1.9
@@ -71,7 +71,7 @@
* @author <a href="[EMAIL PROTECTED]">Michal Maczka</a>
* @version $Id$
*/
-public class FileDeployer implements Deployer
+public class FileDeployer extends AbstractDeployer
{
private RepositoryInfo repoInfo;
1.6 +2 -2
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java
Index: GenericSshDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- GenericSshDeployer.java 18 Jul 2003 07:37:17 -0000 1.5
+++ GenericSshDeployer.java 2 Aug 2003 22:48:39 -0000 1.6
@@ -108,7 +108,7 @@
/* (non-Javadoc)
* @see org.apache.maven.deploy.deployers.Deployer#getAuthenticationInfo()
*/
- public RepositoryInfo getAuthenticationInfo()
+ public RepositoryInfo getRepositoryInfo()
{
return repoInfo;
}
1.2 +7 -2
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/AbstractDeployer.java
Index: AbstractDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/AbstractDeployer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractDeployer.java 17 Jun 2003 22:05:59 -0000 1.1
+++ AbstractDeployer.java 2 Aug 2003 22:48:39 -0000 1.2
@@ -1,4 +1,7 @@
package org.apache.maven.deploy.deployers;
+
+import org.apache.maven.deploy.exceptions.TransferFailedException;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -64,5 +67,7 @@
*/
public abstract class AbstractDeployer implements Deployer
{
-
+ public void flush() throws TransferFailedException
+ {
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]