diff --git a/maven-plugins/maven-site-plugin/.cvsignore b/maven-plugins/maven-site-plugin/.cvsignore new file mode 100644 index 0000000000..de48b91cfe --- /dev/null +++ b/maven-plugins/maven-site-plugin/.cvsignore @@ -0,0 +1,10 @@ +*.log +target +.classpath +.project +default.lst +test.out +default.ajsym +*.ipr +*.iws +*.iml diff --git a/maven-plugins/maven-site-plugin/pom.xml b/maven-plugins/maven-site-plugin/pom.xml new file mode 100644 index 0000000000..441b01c6df --- /dev/null +++ b/maven-plugins/maven-site-plugin/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + + maven-plugin-parent + org.apache.maven.plugins + 2.0-alpha-1 + + maven-site-plugin + 1.0-SNAPSHOT + maven-plugin + Maven Site plugin + + + org.apache.maven + maven-core + 2.0-SNAPSHOT + + + doxia + doxia-core + 1.0-alpha-2-SNAPSHOT + + + org.apache.maven.wagon + wagon-provider-api + 1.0-alpha-2 + + + org.apache.maven.wagon + wagon-ssh + 1.0-alpha-2 + + + + diff --git a/maven-plugins/maven-site-plugin/src/.cvsignore b/maven-plugins/maven-site-plugin/src/.cvsignore new file mode 100644 index 0000000000..308c49f7a8 --- /dev/null +++ b/maven-plugins/maven-site-plugin/src/.cvsignore @@ -0,0 +1 @@ +maven.log diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java new file mode 100644 index 0000000000..3a0b8a4044 --- /dev/null +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -0,0 +1,86 @@ +package org.apache.maven.doxia; + +import org.apache.maven.plugin.Plugin; +import org.apache.maven.plugin.PluginExecutionRequest; +import org.apache.maven.plugin.PluginExecutionResponse; +import org.apache.maven.plugin.AbstractPlugin; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.doxia.site.renderer.SiteRenderer; + +/** + * @goal site + * @description Doxia plugin + * @parameter name="siteDirectory" + * type="" + * required="" + * validator="" + * expression="#basedir/src/site" + * description="" + * @parameter name="generatedSiteDirectory" + * type="" + * required="" + * validator="" + * expression="#project.build.directory/site-generated" + * description="" + * @parameter name="outputDirectory" + * type="" + * required="" + * validator="" + * expression="#project.build.directory/site" + * description="" + * @parameter name="project" + * type="" + * required="" + * validator="" + * expression="#project" + * description="" + * @parameter name="siteRenderer" + * type="" + * required="" + * validator="" + * expression="#component.org.codehaus.doxia.site.renderer.SiteRenderer" + * description="" + * @parameterx name="reportManager" + * type="" + * required="" + * validator="" + * expression="#component.org.apache.maven.reporting.MavenReportManager" + * description="" + */ +public class DoxiaMojo + extends AbstractPlugin +{ + private String siteDirectory; + + private String generatedSiteDirectory; + + private String outputDirectory; + + private SiteRenderer siteRenderer; + + private MavenProject project; + + public void execute() + throws PluginExecutionException + { + try + { + /* + for ( Iterator i = project.getReports().iterator(); i.hasNext(); ) + { + String name = (String) i.next(); + + reportManager.executeReport( name, project.getModel(), siteRenderer, outputDirectory ); + } + */ + + siteRenderer.render( siteDirectory, generatedSiteDirectory, outputDirectory ); + } + catch ( Exception e ) + { + // TODO: handle it + e.printStackTrace(); + } + } +} diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/ScpSiteDeployMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/ScpSiteDeployMojo.java new file mode 100644 index 0000000000..473f811cc5 --- /dev/null +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/ScpSiteDeployMojo.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2005 Your Corporation. All Rights Reserved. + */ +package org.apache.maven.doxia; + +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.plugin.Plugin; +import org.apache.maven.plugin.PluginExecutionRequest; +import org.apache.maven.plugin.PluginExecutionResponse; +import org.apache.maven.plugin.AbstractPlugin; +import org.apache.maven.plugin.PluginExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.WagonUtils; +import org.apache.maven.wagon.observers.Debug; +import org.apache.maven.wagon.providers.ssh.SshCommandExecutor; +import org.apache.maven.wagon.providers.ssh.ScpWagon; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + + +/** + * @author Michal Maczka + * @version $Id$ + * @goal deploy + * @description deploys website using scp protocol. + * First website files are packaged into zip archive, + * then archive is transfred to remote host, nextly it is un-archived. + * This method of deployment should normally be much faster + * then making file by file copy. + * @parameter name="inputDirectory" + * type="String" + * required="true" + * validator="" + * expression="#project.build.directory/site" + * description="" + * @parameter name="workingDirectory" + * type="String" + * required="true" + * validator="" + * expression="#project.build.directory" + * description="" + * @parameter name="unzipCommand" + * type="String" + * required="true" + * validator="" + * expression="unzip -o" + * description="" + * @parameter name="project" + * type="org.apache.maven.project.MavenProject" + * required="true" + * validator="" + * expression="#project" + * description="" + */ +public class ScpSiteDeployMojo + extends AbstractPlugin +{ + private String inputDirectory; + + private String workingDirectory; + + private String unzipCommand; + + private MavenProject project; + + public void execute() + throws PluginExecutionException + { + File baseDir = new File( inputDirectory ); + + File zipFile = null; + + try + { + zipFile = File.createTempFile( "site", ".zip", new File( workingDirectory ) ); + } + catch ( IOException e ) + { + throw new PluginExecutionException( "Cannot create site archive!", e ); + } + + SshCommandExecutor commandExecutor = new ScpWagon(); + + try + { + DistributionManagement distributionManagement = project.getDistributionManagement(); + + if ( distributionManagement == null ) + { + + String msg = "distributionManagement element is missing in the POM: " + + project.getId(); + + throw new PluginExecutionException( msg ); + + } + + if ( distributionManagement.getSite() == null ) + { + String msg = "distributionManagement/repository element is missing in the POM: " + + project.getId(); + + throw new PluginExecutionException( msg ); + + } + + String url = distributionManagement.getSite().getUrl(); + + String id = distributionManagement.getSite().getId(); + + if ( url == null ) + { + String msg = "distributionManagement/site/url element is missing in the POM: " + + project.getId(); + + throw new PluginExecutionException( msg ); + + } + + Repository repository = new Repository( id, url ); + + //@todo dirty hack to make artifact uploading work + repository.setAuthenticationInfo( WagonUtils.getAuthInfo() ); + + commandExecutor.connect( repository ); + + String basedir = repository.getBasedir(); + + List files = FileUtils.getFileNames( baseDir, "**/**", "", false ); + + createZip( files, zipFile, baseDir ); + + Debug debug = new Debug(); + + commandExecutor.addSessionListener( debug ); + + commandExecutor.addTransferListener( debug ); + + String cmd = " mkdir -p " + basedir; + + commandExecutor.executeCommand( cmd ); + + commandExecutor.put( zipFile, zipFile.getName() ); + + cmd = " cd " + basedir + ";" + unzipCommand + " " + zipFile.getName() + "\n"; + + commandExecutor.executeCommand( cmd ); + + String rmCommand = "rm " + basedir + "/" + zipFile.getName(); + + commandExecutor.executeCommand( rmCommand ); + + } + catch( Exception e ) + { + throw new PluginExecutionException( "Error transfering site archive!", e ); + } + finally + { + if ( commandExecutor != null ) + { + try + { + commandExecutor.disconnect(); + } + catch ( ConnectionException e ) + { + //what to to here? + } + } + + if ( !zipFile.delete() ) + { + + zipFile.deleteOnExit(); + } + } + } + + + public void createZip( List files, File zipName, File basedir ) + throws Exception + { + ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zipName ) ); + + try + { + for ( int i = 0; i < files.size(); i++ ) + { + String file = (String) files.get( i ); + + writeZipEntry( zos, new File( basedir, file ), file ); + } + } + finally + { + zos.close(); + } + } + + private void writeZipEntry( ZipOutputStream jar, File source, String entryName ) + throws Exception + { + byte[] buffer = new byte[1024]; + + int bytesRead; + + FileInputStream is = new FileInputStream( source ); + + try + { + ZipEntry entry = new ZipEntry( entryName ); + + jar.putNextEntry( entry ); + + while ( ( bytesRead = is.read( buffer ) ) != -1 ) + { + jar.write( buffer, 0, bytesRead ); + } + } + + finally + { + is.close(); + } + } +}