o store temp file in temp directory, not target which may not exist

o error out if site doesn't exist to copy.
o clean up

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-20 21:05:00 +00:00
parent 1b96369116
commit abdfbe1c74
1 changed files with 58 additions and 46 deletions

View File

@ -1,8 +1,21 @@
/*
* Copyright (c) 2005 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.doxia; package org.apache.maven.doxia;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Site; import org.apache.maven.model.Site;
@ -23,13 +36,13 @@ import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
/** /**
* Deploys website using scp protocol. * Deploys website using scp protocol.
* First website files are packaged into zip archive, * First website files are packaged into zip archive,
* then archive is transfred to remote host, nextly it is un-archived. * then archive is transfred to remote host, nextly it is un-archived.
* This method of deployment should normally be much faster * This method of deployment should normally be much faster
* then making file by file copy. * then making file by file copy.
*
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a> * @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$ * @version $Id$
* @goal deploy * @goal deploy
@ -41,13 +54,7 @@ public class ScpSiteDeployMojo
* @parameter alias="siteDirectory" expression="${project.build.directory}/site" * @parameter alias="siteDirectory" expression="${project.build.directory}/site"
* @required * @required
*/ */
private String inputDirectory; private File inputDirectory;
/**
* @parameter expression="${project.build.directory}"
* @required
*/
private String workingDirectory;
/** /**
* @parameter * @parameter
@ -71,22 +78,22 @@ public class ScpSiteDeployMojo
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
File baseDir = new File( inputDirectory ); if ( !inputDirectory.exists() )
{
throw new MojoExecutionException( "The site does not exist, please run site:site first" );
}
File zipFile; File zipFile;
try try
{ {
zipFile = File.createTempFile( "site", ".zip", new File( workingDirectory ) ); zipFile = File.createTempFile( "site", ".zip" );
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MojoExecutionException( "Cannot create site archive!", e ); throw new MojoExecutionException( "Cannot create site archive!", e );
} }
SshCommandExecutor commandExecutor = null;
try
{
DistributionManagement distributionManagement = project.getDistributionManagement(); DistributionManagement distributionManagement = project.getDistributionManagement();
if ( distributionManagement == null ) if ( distributionManagement == null )
@ -98,7 +105,8 @@ public class ScpSiteDeployMojo
if ( site == null ) if ( site == null )
{ {
throw new MojoExecutionException( "Missing site information in the distribution management element in the project.." ); throw new MojoExecutionException(
"Missing site information in the distribution management element in the project.." );
} }
String url = site.getUrl(); String url = site.getUrl();
@ -114,18 +122,23 @@ public class ScpSiteDeployMojo
if ( !"scp".equals( repository.getProtocol() ) ) if ( !"scp".equals( repository.getProtocol() ) )
{ {
throw new MojoExecutionException( "The deploy mojo currently only supports site deployment using the 'scp' protocol." ); throw new MojoExecutionException(
"The deploy mojo currently only supports site deployment using the 'scp' protocol." );
} }
SshCommandExecutor commandExecutor = null;
try
{
commandExecutor = (SshCommandExecutor) wagonManager.getWagon( "scp" ); commandExecutor = (SshCommandExecutor) wagonManager.getWagon( "scp" );
commandExecutor.connect( repository, wagonManager.getAuthenticationInfo( id ) ); commandExecutor.connect( repository, wagonManager.getAuthenticationInfo( id ) );
String basedir = repository.getBasedir(); String basedir = repository.getBasedir();
List files = FileUtils.getFileNames( baseDir, "**/**", "", false ); List files = FileUtils.getFileNames( inputDirectory, "**/**", "", false );
createZip( files, zipFile, baseDir ); createZip( files, zipFile, inputDirectory );
Debug debug = new Debug(); Debug debug = new Debug();
@ -171,7 +184,6 @@ public class ScpSiteDeployMojo
if ( !zipFile.delete() ) if ( !zipFile.delete() )
{ {
zipFile.deleteOnExit(); zipFile.deleteOnExit();
} }
} }