diff --git a/artifact/.cvsignore b/artifact/.cvsignore new file mode 100644 index 00000000..e5e33942 --- /dev/null +++ b/artifact/.cvsignore @@ -0,0 +1,3 @@ +target +velocity.log +maven.log diff --git a/artifact/plugin.jelly b/artifact/plugin.jelly new file mode 100644 index 00000000..07b0feda --- /dev/null +++ b/artifact/plugin.jelly @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Creating MANIFEST file:${filename} + Mainclass: ${mainclass} + addExtensions ${addExtensions} + + + + + + + + + + + diff --git a/artifact/plugin.properties b/artifact/plugin.properties new file mode 100644 index 00000000..9d91664c --- /dev/null +++ b/artifact/plugin.properties @@ -0,0 +1,7 @@ +# ------------------------------------------------------------------- +# P L U G I N P R O P E R T I E S +# ------------------------------------------------------------------- +maven.artifact.manifest.extensions.add=false + +maven.artifact.manifest.basedir=${plugin.dir}/plugin-resources/templates +maven.artifact.manifest.template=manifest.vm diff --git a/artifact/project.properties b/artifact/project.properties new file mode 100644 index 00000000..c43339ba --- /dev/null +++ b/artifact/project.properties @@ -0,0 +1,3 @@ +# ------------------------------------------------------------------- +# P R O J E C T P R O P E R T I E S +# ------------------------------------------------------------------- diff --git a/artifact/project.xml b/artifact/project.xml new file mode 100644 index 00000000..0b1076d0 --- /dev/null +++ b/artifact/project.xml @@ -0,0 +1,83 @@ + + + + ${basedir}/../project.xml + 3 + maven-artifact-plugin + Maven Artifact Plug-in + 1.0 + + Java Project Management Tools + http://maven.apache.org/reference/plugins/artifact/ + /www/maven.apache.org/reference/plugins/artifact/ + + scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/artifact/ + http://cvs.apache.org/viewcvs/maven/src/plugins-build/artifact/ + + + + + + + maven + maven + SNAPSHOT + jar + + + + commons-io + commons-io + 20030203.000550 + jar + + + + commons-net + commons-net + 1.0.0 + jar + + + + + commons-httpclient + commons-httpclient + 2.0-beta1 + jar + + + + + jsch + jsch + 0.0.9 + jar + + + + + + commons-jelly + commons-jelly + 20030310.073407 + http://jakarta.apache.org/commons/jelly/ + jar + + + + commons-jelly + commons-jelly-tags-velocity + 20030303.205659 + jar + + + + velocity + velocity + 1.3 + jar + + + + diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java new file mode 100644 index 00000000..7be1483d --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java @@ -0,0 +1,114 @@ +package org.apache.maven.artifact.deployer; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.apache.maven.MavenException; +import org.apache.maven.project.Project; + +/** + * + * The Bean which serves as Proxy To Hibernate API + *
+ * + * + * + * @author Michal Maczka + * @version $Id: ArtifactDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public interface ArtifactDeployer +{ + + /** + * Deploy given artifact to remote repository + * @param artifact + * @param type + * @param project + * @throws MavenException + */ + public void deploy(String artifact, String type, Project project) + throws MavenException; + + /** + * Deploy given artifact as a snapshot to remote repository + * @param artifact + * @param type + * @param project + * @throws MavenException + */ + public void deploySnapshot(String artifact, String type, Project project) + throws MavenException; + + /** + * Install given artifact in local repository + * @param artifact + * @param type + * @param project + * @throws MavenException + */ + public void install(String artifact, String type, Project project) + throws MavenException; + + /** + * Install given artifact as snapshot in local repository + * @param artifact + * @param type + * @param project + * @throws MavenException + */ + public void installSnapshot(String artifact, String type, Project project) + throws MavenException; +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java new file mode 100644 index 00000000..dd572b5c --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -0,0 +1,356 @@ +package org.apache.maven.artifact.deployer; +/* ==================================================================== +* The Apache Software License, Version 1.1 +* +* Copyright (c) 2001 The Apache Software Foundation. All rights +* reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* +* 3. The end-user documentation included with the redistribution, +* if any, must include the following acknowledgment: +* "This product includes software developed by the +* Apache Software Foundation (http://www.apache.org/)." +* Alternately, this acknowledgment may appear in the software itself, +* if and wherever such third-party acknowledgments normally appear. +* +* 4. The names "Apache" and "Apache Software Foundation" and +* "Apache MavenSession" must not be used to endorse or promote products +* derived from this software without prior written permission. For +* written permission, please contact apache@apache.org. +* +* 5. Products derived from this software may not be called "Apache", +* "Apache MavenSession", nor may "Apache" appear in their name, without +* prior written permission of the Apache Software Foundation. +* +* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR +* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +* ==================================================================== +* +* This software consists of voluntary contributions made by many +* individuals on behalf of the Apache Software Foundation. For more +* information on the Apache Software Foundation, please see +* . +* +* ==================================================================== +*/ + +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.commons.io.FileUtils; +import org.apache.maven.MavenConstants; +import org.apache.maven.MavenException; +import org.apache.maven.artifact.deployer.deploy.Deployer; +import org.apache.maven.artifact.deployer.deploy.FtpDeployer; +import org.apache.maven.artifact.deployer.deploy.HttpDeployer; +import org.apache.maven.artifact.deployer.deploy.SshDeployer; +import org.apache.maven.project.Project; + +/** + * + * Default implemenataion of Artifact Deployer interface + * + * @author Michal Maczka + * @version $Id: DefaultArtifactDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public class DefaultArtifactDeployer implements ArtifactDeployer +{ + + /** + * + */ + public final static DateFormat SNAPSHOT_MARKER = + new SimpleDateFormat("yyyyMMdd.HHmmss"); + + /** + * @see ArtifactDeployer#deploy(String, String, Project) + */ + public void deploy(String file, String type, Project project) + throws MavenException + { + System.out.println("deploy"); + doDeploy(file, type, project, project.getCurrentVersion()); + } + + /** + * @see DefaultArtifactDeployer#deploySnapshot(String, String, Project) + */ + public void deploySnapshot(String file, String type, Project project) + throws MavenException + { + doDeploy(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER); + } + + /** + * @see ArtifactDeployer#install(String, String, Project) + */ + public void install(String artifact, String type, Project project) + throws MavenException + { + doInstall(artifact, type, project, project.getCurrentVersion()); + } + + /** + * @see ArtifactDeployer#installSnapshot(String, String, Project) + */ + public void installSnapshot(String artifact, String type, Project project) + throws MavenException + { + System.out.println("Installing snapshot of:'" + artifact + "''"); + try + { + doInstall( + artifact, + type, + project, + MavenConstants.SNAPSHOT_SIGNIFIER); + } + catch (MavenException e) + { + System.out.println(e.getMessage()); + } + try + { + doInstall(artifact, type, project, getSnapshotVersion()); + } + catch (MavenException e) + { + System.out.println(e.getMessage()); + } + } + + /** + * Istall given file in repsoitory + * @param artifact the artifact file to insatall + * @param type The type of the artiafct + * @param project + * @param version String denominating the version of the artifact + * @throws MavenException + */ + private void doInstall( + String artifact, + String type, + Project project, + String version) + throws MavenException + { + String repositoryPath = getRepositoryPath(type, project, version); + try + { + String dest = getLocalRepository(project) + "/" + repositoryPath; + System.out.println( + "Copying: from '" + artifact + "' to: '" + dest + "'"); + FileUtils.copyFile(new File(artifact), new File(dest)); + } + catch (IOException e) + { + String msg = + "Cannot install file: '" + + repositoryPath + + "'. Reason: " + + e.getMessage(); + throw new MavenException(msg); + } + + } + + /** + * @param artifact + * @param type + * @param project + * @param snapshot + */ + private void doDeploy( + String artifact, + String type, + Project project, + String version) + throws MavenException + { + String repoPath = getRepositoryPath(type, project, version); + String host = getDistributionHost(project); + String remotePath = getDistributionDirectory(project) + "/" + repoPath; + Deployer deployer = getDeployer(host); + + //Cut of protcol prefix from host name + + host = host.substring( host.indexOf("://") + 3 ); + + System.out.println( + "Deploying: '" + + artifact + + "' to host: '" + + host + + "' remote path: '" + + remotePath); + MavenAuthenticationInfo authInfo = new MavenAuthenticationInfo(project); + deployer.deploy(authInfo, host, artifact, remotePath); + System.out.println("Deployment finished"); + } + + /** + * @param project + * @return + */ + private String getDistributionHost(Project project) throws MavenException + { + String host = host = project.getDistributionSite(); + if (host == null || host.length() == 0) + { + host = + (String) project.getContext().getVariable( + "maven.deployer.host"); + } + if (host == null) + { + throw new MavenException("Distribution host is not set"); + } + + return host; + } + + /** + * + * @param project + * @return + * @throws MavenException + */ + private String getDistributionDirectory(Project project) + throws MavenException + { + + String dir = project.getDistributionDirectory(); + + if (dir == null || dir.length() == 0) + { + dir = + (String) project.getContext().getVariable( + "maven.deployer.remote.directory"); + + } + if (dir == null) + { + throw new MavenException("Distribution directory is not set"); + } + return dir; + + } + + /** + * + * @param project + */ + private String getLocalRepository(Project project) + { + return project.getContext().getMavenRepoLocal(); + } + + /** + * + * @param type + * @param project + * @param snapshot + * @return + */ + private String getRepositoryPath( + String type, + Project project, + String version) + { + StringBuffer path = new StringBuffer(); + path.append(project.getArtifactDirectory()); + path.append("/"); + path.append(type + "s"); + path.append("/"); + path.append(project.getArtifactId()); + path.append("-"); + path.append(version); + path.append("."); + path.append(extensionForType(type)); + return path.toString(); + + } + + /** + * + * @return + */ + private String getSnapshotVersion() + { + Date date = new Date(); + return SNAPSHOT_MARKER.format(date); + + } + + /** + * + * @todo Dirty hack util Repository Layout Service is used + * @return + */ + private String extensionForType(String type) + { + if (type.equals("ejb")) + { + return "jar"; + } + return type; + } + + /** + * + * @param host + * @param project + * @return + * @throws MavenException + */ + private Deployer getDeployer(String host) throws MavenException + { + Deployer deployer = null; + + if (host.startsWith("http://")) + { + deployer = new HttpDeployer(); + } + else + if (host.startsWith("ssh://")) + { + deployer = new SshDeployer(); + } + else + if (host.startsWith("ftp://")) + { + deployer = new FtpDeployer(); + } + else + { + throw new MavenException( + "unsupported protocol: '" + host + "'"); + } + return deployer; + } + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/DeployBean.java b/artifact/src/main/org/apache/maven/artifact/deployer/DeployBean.java new file mode 100644 index 00000000..2129c5c2 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/DeployBean.java @@ -0,0 +1,190 @@ +package org.apache.maven.artifact.deployer; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.apache.maven.MavenException; +import org.apache.maven.artifact.deployer.ArtifactDeployer; +import org.apache.maven.artifact.deployer.DefaultArtifactDeployer; +import org.apache.maven.project.Project; + +/** + * + * The Bean which serves as Proxy for Jelly scripts To Artifact Deployement API + * + * @author Michal Maczka + * @version $Id: DeployBean.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public class DeployBean +{ + ArtifactDeployer artifactDeployer = null; + + private Project project = null; + private String artifact = null; + private String type = null; + + public DeployBean() + { + artifactDeployer = new DefaultArtifactDeployer(); + } + + /** + * @return + */ + public String getArtifact() + { + return artifact; + } + + /** + * @param artifact + */ + public void setArtifact(String artifact) + { + this.artifact = artifact; + } + + /** + * @return + */ + public Project getProject() + { + return project; + } + + /** + * @param project + */ + public void setProject(Project project) + { + this.project = project; + } + + /** + * @return + */ + public String getType() + { + return type; + } + + /** + * @param type + */ + public void setType(String type) + { + this.type = type; + } + + /** + * + * @throws MavenException + */ + protected void checkAttributes() throws MavenException + { + if (project == null) + { + throw new MavenException("attribute 'project' is required"); + } + + if (artifact == null) + { + throw new MavenException("attribute 'artifact' is required"); + } + if (type == null) + { + throw new MavenException("attribute 'type' is required"); + } + } + + /** + * + */ + public void deploy() throws MavenException + { + System.out.println("deploy called"); + checkAttributes(); + artifactDeployer.deploy(artifact, type, project); + } + + /** + * + */ + public void deploySnapshot() throws MavenException + { + checkAttributes(); + artifactDeployer.deploySnapshot(artifact, type, project); + } + + /** + * + */ + public void install() throws MavenException + { + checkAttributes(); + artifactDeployer.install(artifact, type, project); + } + + /** + * + */ + public void installSnapshot() throws MavenException + { + checkAttributes(); + artifactDeployer.installSnapshot(artifact, type, project); + } + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/MavenAuthenticationInfo.java b/artifact/src/main/org/apache/maven/artifact/deployer/MavenAuthenticationInfo.java new file mode 100644 index 00000000..70b9a105 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/MavenAuthenticationInfo.java @@ -0,0 +1,94 @@ +package org.apache.maven.artifact.deployer; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import org.apache.maven.project.Project; +import org.apache.maven.artifact.deployer.deploy.GenericAuthenticationInfo; + + +/** + * + * Maps information kept in POM to AuthetificationInfo interface + *
+ * + * + * + * @author Michal Maczka + * @version $Id: MavenAuthenticationInfo.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public class MavenAuthenticationInfo extends GenericAuthenticationInfo +{ + + + public MavenAuthenticationInfo(Project project) + { + String username = + (String) project.getContext().getVariable( + "maven.deployer.username"); + String password = + (String) project.getContext().getVariable( + "maven.deployer.password"); + String passphrase = + (String) project.getContext().getVariable( + "maven.deployer.passphrase"); + + setUsername(username); + setPassword(password); + setPassphrase(passphrase); + } + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AbstractDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AbstractDeployer.java new file mode 100644 index 00000000..f4b97923 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AbstractDeployer.java @@ -0,0 +1,77 @@ +package org.apache.maven.artifact.deployer.deploy; +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * Base deployer from which all deployers are derived. + * + * @author Jason van Zyl + * @author Michal Maczka + * @version $Id: AbstractDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public abstract class AbstractDeployer implements Deployer +{ + + /** + * + */ + public abstract void deploy( + AuthenticationInfo authInfo, + String host, + String localPath, + String remotePath); + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AuthenticationInfo.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AuthenticationInfo.java new file mode 100644 index 00000000..9d5f85aa --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/AuthenticationInfo.java @@ -0,0 +1,101 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + + +/** + * Holder of the infomarmation which is used to authentificate user + * during deployment process. + * + * @author Michal Maczka + * @version $Revision: 1.1 $ $Date: 2003/06/16 14:26:01 $ + */ +public interface AuthenticationInfo +{ + /** + * @return + */ + public abstract String getPassphrase(); + /** + * @param passphrase + */ + public abstract void setPassphrase(String passphrase); + /** + * @return + */ + public abstract String getPassword(); + /** + * @param password + */ + public abstract void setPassword(String password); + /** + * @return + */ + public abstract String getUsername(); + /** + * @param username + */ + public abstract void setUsername(String username); + /** + * @return + */ + public abstract String getRemoteGroup(); + /** + * @param remoteGroup + */ + public abstract void setRemoteGroup(String remoteGroup); +} \ No newline at end of file diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/Deployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/Deployer.java new file mode 100644 index 00000000..a9d35d48 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/Deployer.java @@ -0,0 +1,79 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +/** + * Interface for all Maven deployers. + * + * @author Jason van Zyl + * @version $Id: Deployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public interface Deployer +{ + /** + * + * @param authInfo + * @param host + * @param localPath + * @param remotePath + */ + public void deploy( + AuthenticationInfo authInfo, + String host, + String localPath, + String remotePath); +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/FtpDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/FtpDeployer.java new file mode 100644 index 00000000..dcfba96c --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/FtpDeployer.java @@ -0,0 +1,219 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.apache.commons.net.ProtocolCommandEvent; +import org.apache.commons.net.ProtocolCommandListener; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPConnectionClosedException; +import org.apache.commons.net.ftp.FTPReply; + + + + + +/** + * An FTP deployer based on the FTPClient in the Commons Net package. + * + * @author Jason van Zyl + * + * @version $Id: FtpDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + * + * @todo account for username and password. + */ +public class FtpDeployer extends AbstractDeployer +{ + + /** + * Description of the Method + */ + public void deploy(AuthenticationInfo authInfo, String host, String localPath, String remotePath) + { + String username = authInfo.getUsername(); + String password = authInfo.getPassword(); + + + FTPClient ftp = new FTPClient(); + ftp.addProtocolCommandListener( + new PrintCommandListener(new PrintWriter(System.out))); + + try + { + int reply; + ftp.connect(host); + System.out.println("Connected to " + host + "."); + + // After connection attempt, you should check the reply code to verify + // success. + reply = ftp.getReplyCode(); + + if (FTPReply.isPositiveCompletion(reply) == false) + { + ftp.disconnect(); + System.err.println("FTP server refused connection."); + System.exit(1); + } + } + catch (IOException e) + { + if (ftp.isConnected()) + { + try + { + ftp.disconnect(); + } + catch (IOException f) + { + // do nothing + } + } + System.err.println("Could not connect to server."); + e.printStackTrace(); + System.exit(1); + } + + __main : try + { + if (ftp.login(username, password) == false) + { + ftp.logout(); + break __main; + } + + System.out.println("Remote system is " + ftp.getSystemName()); + + // Set to binary mode. + ftp.setFileType(FTP.BINARY_FILE_TYPE); + // Use passive mode as default because most of us are + // behind firewalls these days. + ftp.enterLocalPassiveMode(); + String workingDir = remotePath.substring(0, remotePath.lastIndexOf("/")); + String filename = remotePath.substring(remotePath.lastIndexOf("/")+1); + System.out.println("Working directory " + workingDir); + System.out.println("Filename: " + filename); + System.out.println("LocalPath: " + localPath); + ftp.makeDirectory(workingDir); + ftp.changeWorkingDirectory( workingDir); + ftp.storeFile(filename, new FileInputStream(localPath)); + ftp.logout(); + } + catch (FTPConnectionClosedException e) + { + System.err.println("Server closed connection."); + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + finally + { + if (ftp.isConnected()) + { + try + { + ftp.disconnect(); + } + catch (IOException f) + { + // do nothing + } + } + } + } + + /** + * Description of the Class + */ + public class PrintCommandListener implements ProtocolCommandListener + { + private PrintWriter writer; + + /** + * Constructor for the PrintCommandListener object + * + * @param writer + */ + public PrintCommandListener(PrintWriter writer) + { + this.writer = writer; + } + + /** + * Description of the Method + */ + public void protocolCommandSent(ProtocolCommandEvent event) + { + writer.print(event.getMessage()); + writer.flush(); + } + + /** + * Description of the Method + */ + public void protocolReplyReceived(ProtocolCommandEvent event) + { + writer.print(event.getMessage()); + writer.flush(); + } + } + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/GenericAuthenticationInfo.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/GenericAuthenticationInfo.java new file mode 100644 index 00000000..269963e3 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/GenericAuthenticationInfo.java @@ -0,0 +1,143 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + + + +/** + * + * The Bean which serves as Proxy To Hibernate API + *
+ * + * + * + * @author Michal Maczka + * @version $Id: GenericAuthenticationInfo.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + */ +public class GenericAuthenticationInfo implements AuthenticationInfo +{ + private String username; + private String password; + private String passphrase; + private String remoteGroup; + + + /** + * @return + */ + public String getPassphrase() + { + return passphrase; + } + + /** + * @param passphrase + */ + public void setPassphrase(String passphrase) + { + this.passphrase = passphrase; + } + + /** + * @return + */ + public String getPassword() + { + return password; + } + + /** + * @param password + */ + public void setPassword(String password) + { + this.password = password; + } + + /** + * @return + */ + public String getUsername() + { + return username; + } + + /** + * @param username + */ + public void setUsername(String username) + { + this.username = username; + } + + /** + * @return + */ + public String getRemoteGroup() + { + return remoteGroup; + } + + /** + * @param remoteGroup + */ + public void setRemoteGroup(String remoteGroup) + { + this.remoteGroup = remoteGroup; + } + +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/HttpDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/HttpDeployer.java new file mode 100644 index 00000000..0589bb37 --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/HttpDeployer.java @@ -0,0 +1,177 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.URI; +import org.apache.commons.httpclient.URIException; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.methods.PutMethod; + + +/** + * An HTTP deployer based the Commons HttpClient library. + * + * @author Jason van Zyl + * @version $Id: HttpDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + * + * @todo still have to account for differing setups for people deploying to + * their own sites and to the central repository. + * + * @todo deal with proxies + * @todo deal with authentication + */ +public class HttpDeployer extends AbstractDeployer +{ + + /** + * Description of the Method + */ + public void deploy( + AuthenticationInfo authInfo, + String host, + String localPath, + String remotePath) + { + URL url = null; + try + { + url = new URL(remotePath); + } + catch (MalformedURLException murle) + { + } + + Credentials creds = + new UsernamePasswordCredentials( + authInfo.getUsername(), + authInfo.getPassphrase()); + + //create a singular HttpClient object + HttpClient client = new HttpClient(); + + //establish a connection within 5 seconds + client.setConnectionTimeout(5000); + + //set username / password + if (creds != null) + { + client.getState().setCredentials(null, creds); + } + + // + HostConfiguration hc = new HostConfiguration(); + try + { + hc.setHost(new URI(url)); + } + catch (URIException e) + { + throw new RuntimeException(e.toString()); + } + + //start a session with the webserver + client.setHostConfiguration(hc); + + //create a method object + PutMethod method = new PutMethod(url.getPath()); + method.setRequestBody(new File(localPath).toString()); + + //turn follow redirects off + method.setFollowRedirects(false); + + //turn strict mode on + method.setStrictMode(false); + + //execute the method + try + { + client.executeMethod(method); + } + catch (HttpException he) + { + System.err.println("Http error connecting to '" + url + "'"); + System.err.println(he.getMessage()); + System.exit(-4); + } + catch (IOException ioe) + { + System.err.println("Unable to connect to '" + url + "'"); + System.exit(-3); + } + + //get the request headers + Header[] requestHeaders = method.getRequestHeaders(); + + //get the response headers + Header[] responseHeaders = method.getResponseHeaders(); + + //get the response body + byte[] responseBody = method.getResponseBody(); + + method.releaseConnection(); + } +} diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/deploy/SshDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/SshDeployer.java new file mode 100644 index 00000000..d6f5c30f --- /dev/null +++ b/artifact/src/main/org/apache/maven/artifact/deployer/deploy/SshDeployer.java @@ -0,0 +1,262 @@ +package org.apache.maven.artifact.deployer.deploy; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache MavenSession" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache MavenSession", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * ==================================================================== + */ + +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.UserInfo; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.Session; +import com.jcraft.jsch.Channel; + +import java.io.File; +import java.io.FileInputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + + + +/** + * An ssh2 deployer that uses the JSch library and the JCE. We will first try to + * use public keys for authentication and if that doesn't work then we fall back + * to using the login and password of the user in question. NOTE: We are + * assuming the standard port of 22. + * + * @author Jason van Zyl + * @version $Id: SshDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $ + * @todo still have to account for differing setups for people deploying to + * their own sites and to the central repository. + */ +public class SshDeployer extends AbstractDeployer +{ + + private AuthenticationInfo authInfo = null; + + /** + * @see Deployer#project + */ + public void deploy( + AuthenticationInfo authInfo, + String host, + String localArtifactPath, + String remoteArtifactPath) + { + try + { + this.authInfo = authInfo; + JSch jsch = new JSch(); + Session session = jsch.getSession(host, 22); + + // Look for the private key and use it if available. + File privateKey = + new File( + new File(System.getProperty("user.home"), ".ssh"), + "id_dsa"); + + if (privateKey.exists()) + { + session.setIdentity(privateKey.getPath()); + } + + // username and password will be given via UserInfo interface. + UserInfo ui = new MavenUserInfo(); + session.setUserInfo(ui); + session.connect(); + + // exec 'scp -t remoteArtifactPath' remotely + String command = "scp -t " + remoteArtifactPath; + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + + // plug I/O streams for remote scp + PipedOutputStream out = new PipedOutputStream(); + channel.setInputStream(new PipedInputStream(out)); + PipedInputStream in = new PipedInputStream(); + channel.setOutputStream(new PipedOutputStream(in)); + + channel.connect(); + + byte[] tmp = new byte[1]; + + // wait for '\0' + do + { + in.read(tmp, 0, 1); + } + while (tmp[0] != 0); + + // send "C0644 filesize filename", where filename should not include '/' + int filesize = (int) (new File(localArtifactPath)).length(); + command = "C0644 " + filesize + " "; + if (localArtifactPath.lastIndexOf('/') > 0) + { + command + += localArtifactPath.substring( + localArtifactPath.lastIndexOf('/') + 1); + } + else + { + command += localArtifactPath; + } + command += "\n"; + out.write(command.getBytes()); + out.flush(); + + // wait for '\0' + do + { + in.read(tmp, 0, 1); + } + while (tmp[0] != 0); + + // send a content of localArtifactPath + FileInputStream fis = new FileInputStream(localArtifactPath); + 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(); + } + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + // wait for '\0' + do + { + in.read(tmp, 0, 1); + } + while (tmp[0] != 0); + } + catch (Exception e) + { + System.out.println(e); + } + } + + /** + * MavenUserInfo class which returns the necessary name and password from + * the POM to secure an ssh connection. + */ + public class MavenUserInfo implements UserInfo + { + + + + /** + * Gets the name attribute of the MavenUserInfo object + */ + public String getName() + { + return authInfo.getUsername(); + } + + /** + * Gets the password attribute of the MavenUserInfo object + */ + public String getPassword() + { + return authInfo.getPassword(); + } + + /** + * Gets the passphrase attribute of the MavenUserInfo object + */ + public String getPassphrase(String message) + { + return authInfo.getPassphrase(); + } + + /** + * Required to satisfy UserInfo interface. Not used currently. + */ + public boolean promptNameAndPassphrase(String message) + { + return true; + } + + /** + * Required to satisfy UserInfo interface. Not used currently. + */ + public boolean promptNameAndPassword(String message) + { + return true; + } + + /** + * Required to satisfy UserInfo interface. Not used currently. + */ + public boolean retry() + { + return true; + } + + /** + * Required to satisfy UserInfo interface. Not used currently. + */ + public boolean prompt(String message) + { + return true; + } + } +} diff --git a/artifact/src/plugin-resources/templates/manifest.vm b/artifact/src/plugin-resources/templates/manifest.vm new file mode 100644 index 00000000..8925765f --- /dev/null +++ b/artifact/src/plugin-resources/templates/manifest.vm @@ -0,0 +1,56 @@ +Built-By: ${jellyContext.getVarable("user.name")} +Created-By: Apache Jakarta Maven +#if (${pom.Package}) +Package: ${pom.Package} +#end +Build-Jdk: ${jellyContext.getVarable("java.version")} +#if (${pom.ArtifactId}) +Extension-Name: ${pom.ArtifactId} +#end +#if (${pom.SpecificationVersion}) +Specification-Version: ${pom.SpecificationVersion} +#end +#if (${pom.Organization.Name}) +Specification-Vendor: ${pom.Organization.Name} +#end +#if (${pom.ShortDescription}) +Specification-Title: ${pom.ShortDescription} +#end +#if (${pom.CurrentVersion}) +Implementation-Version: ${pom.CurrentVersion} +#end +#if (${pom.Organization.Name}) +Implementation-Vendor: ${pom.Organization.Name} +Implementation-Vendor-Id: ${pom.Organization.Name} +#end + +#if(${mainclass}) +Main-Class=${mainclass} +#end + + +#if( ${addExtensions}) + #set($extensionList = "") + #foreach($artifact in $pom.Artifacts) + #set ($dep= $artifact.Dependency ) + #if( $dep.Type == "jar" ) + #set($extensionList = "$extensionList $artifact.Dependency.ArtifactId") + #end + #end + +Extension-List: ${extensionList} + + #foreach($artifact in $pom.Artifacts) + #set ($dep= $artifact.Dependency ) + #if( $dep.Type == "jar" ) + +${dep.ArtifactId}-Extension-Name: ${dep.ArtifactId} +${dep.ArtifactId}-Implementation-Version: ${dep.Version} + #if($dep.Url) +${dep.ArtifactId}-Implementation-URL: ${dep.Url} + #else +${dep.ArtifactId}-Implementation-URL: http://www.ibiblio.org/maven/ + #end + #end + #end +#end