Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1B06DDEBD for ; Mon, 3 Sep 2012 20:23:48 +0000 (UTC) Received: (qmail 77956 invoked by uid 500); 3 Sep 2012 20:23:47 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 77907 invoked by uid 500); 3 Sep 2012 20:23:47 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 77898 invoked by uid 99); 3 Sep 2012 20:23:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2012 20:23:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2012 20:23:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 96D802388C6C for ; Mon, 3 Sep 2012 20:21:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r831046 [19/20] - in /websites/production/maventest/content: plugins/maven-patch-tracker-plugin/ sandbox/ sandbox/plugins/ sandbox/plugins/maven-patch-tracker-plugin/ sandbox/plugins/maven-scm-publish-plugin/ sandbox/plugins/maven-scm-publi... Date: Mon, 03 Sep 2012 20:21:40 -0000 To: commits@maven.apache.org From: olamy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120903202145.96D802388C6C@eris.apache.org> Added: websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.html ============================================================================== --- websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.html (added) +++ websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.html Mon Sep 3 20:21:36 2012 @@ -0,0 +1,95 @@ + + + + +ScmPublishInventoryMojo xref + + + +
+
+1   package org.apache.maven.plugins.scmpublish;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import java.io.File;
+23  import java.util.List;
+24  
+25  import org.apache.commons.io.FileUtils;
+26  import org.apache.maven.plugin.MojoExecutionException;
+27  import org.apache.maven.plugin.MojoFailureException;
+28  
+29  /**
+30   * Prepare a directory for version-managed site generation. This checks out the specified directory from the SCM,
+31   * then takes inventory of all the resulting files then deletes every files.
+32   * This inventory then allows the 'publish' target to tee up deletions
+33   * as well as modifications and additions.
+34   * 
+35   * There's an assumption here that an entire directory in SCM is dedicated to
+36   * the publication process for this project. In the aggregate case, this is going to take some doing. 
+37   * 
+38   * If we allow this to be non-aggregate, then each module has to configure pathnames, which would be a pain. So
+39   * we assume that in an aggregate project this runs once, at the top -- then all of the projects site-deploy
+40   * into the file: url this creates. 
+41   * 
+42   * 
+43   * TODO: we want
+44   * multiple includes/excludes, but the scm API doesn't go there.
+45   * 
+46   * @goal prepare
+47   * @phase pre-site
+48   * @aggregate
+49   */
+50  public class ScmPublishInventoryMojo
+51      extends AbstractScmPublishMojo
+52  {
+53      /**
+54       * Clear out the data, so we can tell what's left after the run of the site plugin.
+55       * For now, don't bother with deleting empty directories. They are fairly harmless,
+56       * and leaving them around allows this to work with pre-1.7 svn.
+57       */
+58      private void deleteInventory( List<File> inventory ) 
+59      {
+60          for ( File f : inventory )
+61          {
+62              if ( f.isFile() )
+63              {
+64                  FileUtils.deleteQuietly( f );
+65              }
+66          }
+67      }
+68  
+69      public void scmPublishExecute()
+70          throws MojoExecutionException, MojoFailureException
+71      {
+72          checkoutExisting();
+73  
+74          List<File> inventory =
+75              ScmPublishInventory.listInventoryFiles( checkoutDirectory, scmProvider.getScmSpecificFilename() );
+76  
+77          ScmPublishInventory.writeInventory( inventory, inventoryFile );
+78  
+79          deleteInventory( inventory );
+80      }
+81  }
+
+
+ + Added: websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishLifecycleMojo.html ============================================================================== --- websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishLifecycleMojo.html (added) +++ websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishLifecycleMojo.html Mon Sep 3 20:21:36 2012 @@ -0,0 +1,57 @@ + + + + +ScmPublishLifecycleMojo xref + + + +
+
+1   package org.apache.maven.plugins.scmpublish;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import org.apache.maven.plugin.AbstractMojo;
+23  import org.apache.maven.plugin.MojoExecutionException;
+24  import org.apache.maven.plugin.MojoFailureException;
+25  
+26  /**
+27   * Empty goal, provided only to set loose the lifecycle.
+28   * 
+29   * @goal scmpublish
+30   * @execute lifecycle="scmpublish" phase="scmpublish-publish"
+31   * @aggregate
+32   */
+33  public class ScmPublishLifecycleMojo
+34      extends AbstractMojo
+35  {
+36  
+37      public void execute()
+38          throws MojoExecutionException, MojoFailureException
+39      {
+40          // nothing to do.
+41      }
+42  
+43  }
+
+
+ + Added: websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.html ============================================================================== --- websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.html (added) +++ websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.html Mon Sep 3 20:21:36 2012 @@ -0,0 +1,354 @@ + + + + +ScmPublishPublishMojo xref + + + +
+
+1   package org.apache.maven.plugins.scmpublish;
+2   
+3   /*
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *  http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   */
+21  
+22  import java.io.BufferedReader;
+23  import java.io.File;
+24  import java.io.FileInputStream;
+25  import java.io.FileOutputStream;
+26  import java.io.IOException;
+27  import java.io.InputStreamReader;
+28  import java.io.OutputStreamWriter;
+29  import java.io.PrintWriter;
+30  import java.util.ArrayList;
+31  import java.util.Collection;
+32  import java.util.HashSet;
+33  import java.util.List;
+34  import java.util.Set;
+35  import java.util.TreeSet;
+36  
+37  import org.apache.commons.io.FileUtils;
+38  import org.apache.commons.io.FilenameUtils;
+39  import org.apache.commons.io.IOUtils;
+40  import org.apache.maven.plugin.MojoExecutionException;
+41  import org.apache.maven.plugin.MojoFailureException;
+42  import org.apache.maven.scm.ScmException;
+43  import org.apache.maven.scm.ScmFileSet;
+44  import org.apache.maven.scm.command.add.AddScmResult;
+45  import org.apache.maven.scm.command.checkin.CheckInScmResult;
+46  import org.apache.maven.scm.command.remove.RemoveScmResult;
+47  
+48  /**
+49   * Compare the list of files now on disk to the original inventory, then fire off scm adds and deletes as needed.
+50   * 
+51   * @goal publish
+52   * @phase post-site
+53   * @aggregate
+54   */
+55  public class ScmPublishPublishMojo
+56      extends AbstractScmPublishMojo
+57  {
+58  
+59      /**
+60       * Display list of added, deleted, and changed files, but do not do any actual SCM operations.
+61       * 
+62       * @parameter expression="${scmpublish.dryRun}"
+63       */
+64      private boolean dryRun;
+65  
+66      /**
+67       * Run add and delete commands, but leave the actually checkin for the user to run manually.
+68       * 
+69       * @parameter expression="${scmpublish.skipCheckin}"
+70       */
+71      private boolean skipCheckin;
+72  
+73      /**
+74       * SCM log/checkin comment for this publication.
+75       * @parameter expression="${scmpublish.checkinComment}" default-value="Site checkin for project ${project.name}"
+76       */
+77      private String checkinComment;
+78  
+79      /**
+80       * Filename extensions of files which need new line normalization.
+81       */
+82      private final static String[] NORMALIZE_EXTENSIONS = { "html", "css", "js" };
+83  
+84      private File relativize( File base, File file )
+85      {
+86          return new File( base.toURI().relativize( file.toURI() ).getPath() );
+87      }
+88  
+89      protected boolean requireNormalizeNewlines( File f )
+90          throws IOException
+91      {
+92          return FilenameUtils.isExtension( f.getName(), NORMALIZE_EXTENSIONS );
+93      }
+94  
+95      private void normalizeNewlines( File f )
+96          throws IOException
+97      {
+98          File tmpFile = null;
+99          BufferedReader in = null;
+100         PrintWriter out = null;
+101         try
+102         {
+103             tmpFile = File.createTempFile( "maven-site-scm-plugin-", ".tmp" );
+104             FileUtils.copyFile( f, tmpFile );
+105             in = new BufferedReader( new InputStreamReader( new FileInputStream( tmpFile ), siteOutputEncoding ) );
+106             out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( f ), siteOutputEncoding ) );
+107             String line;
+108             while ( ( line = in.readLine() ) != null ) 
+109             {
+110                 if ( in.ready() )
+111                 {
+112                     out.println( line );
+113                 }
+114                 else
+115                 {
+116                     out.print( line );
+117                 }
+118             }
+119         }
+120         finally
+121         {
+122             IOUtils.closeQuietly( out );
+123             IOUtils.closeQuietly( in );
+124             FileUtils.deleteQuietly( tmpFile );
+125         }
+126     }
+127 
+128     private void normalizeNewLines( Set<File> files )
+129         throws MojoFailureException
+130     {
+131         for ( File f : files )
+132         {
+133             try
+134             {
+135                 if ( requireNormalizeNewlines( f ) )
+136                 {
+137                     normalizeNewlines( f );
+138                 }
+139             }
+140             catch ( IOException e )
+141             {
+142                 throw new MojoFailureException( "Failed to normalize newlines in " + f.getAbsolutePath(), e );
+143             }
+144         }
+145     }
+146 
+147     public void scmPublishExecute()
+148         throws MojoExecutionException, MojoFailureException
+149     {
+150         if ( siteOutputEncoding == null )
+151         {
+152             getLog().warn( "No output encoding, defaulting to UTF-8." );
+153             siteOutputEncoding = "utf-8";
+154         }
+155 
+156         // read in the list left behind by prepare; fail if it's not there.
+157         List<File> inventory = ScmPublishInventory.readInventory( inventoryFile );
+158 
+159         // what files are in stock now?
+160         Collection<File> newInventory =
+161             ScmPublishInventory.listInventoryFiles( checkoutDirectory, scmProvider.getScmSpecificFilename() );
+162 
+163         Set<File> deleted = new HashSet<File>( inventory );
+164         deleted.removeAll( newInventory ); // old - new = deleted. (Added is the complete new inventory at this point.)
+165 
+166         Set<File> added = new HashSet<File>( newInventory );
+167         added.removeAll( inventory ); // new - old = added.
+168 
+169         Set<File> updated = new HashSet<File>( newInventory );
+170         updated.retainAll( inventory ); // set intersection
+171 
+172         logInfo( "Publish files: %d addition(s), %d update(s), %d delete(s)", added.size(), updated.size(),
+173                  deleted.size() );
+174 
+175         if ( isDryRun() )
+176         {
+177             for ( File addedFile : added )
+178             {
+179                 logInfo( "Added %s", addedFile.getAbsolutePath() );
+180             }
+181             for ( File deletedFile : deleted )
+182             {
+183                 logInfo( "Deleted %s", deletedFile.getAbsolutePath() );
+184             }
+185             for ( File updatedFile : updated )
+186             {
+187                 logInfo( "Updated %s", updatedFile.getAbsolutePath() );
+188             }
+189             return;
+190         }
+191 
+192         if ( !added.isEmpty() )
+193         {
+194             normalizeNewLines( added );
+195 
+196             addFiles( added );
+197         }
+198 
+199         if ( !deleted.isEmpty() )
+200         {
+201             deleteFiles( deleted );
+202         }
+203 
+204         normalizeNewLines( updated );
+205 
+206         checkinFiles();
+207     }
+208 
+209     /**
+210      * Check-in content from scm checkout.
+211      * 
+212      * @throws MojoExecutionException
+213      */
+214     protected void checkinFiles()
+215         throws MojoExecutionException
+216     {
+217         if ( skipCheckin )
+218         {
+219             return;
+220         }
+221 
+222         ScmFileSet updatedFileSet = new ScmFileSet( checkoutDirectory );
+223         try
+224         {
+225             CheckInScmResult checkinResult = scmProvider.checkIn( scmRepository, updatedFileSet, checkinComment );
+226             if ( !checkinResult.isSuccess() )
+227             {
+228                 logError( "checkin operation failed: %s",
+229                           checkinResult.getProviderMessage() + " " + checkinResult.getCommandOutput() );
+230                 throw new MojoExecutionException( "Failed to checkin files: " + checkinResult.getProviderMessage()
+231                     + " " + checkinResult.getCommandOutput() );
+232             }
+233         }
+234         catch ( ScmException e )
+235         {
+236             throw new MojoExecutionException( "Failed to perform checkin SCM", e );
+237         }
+238     }
+239 
+240     protected void deleteFiles( Collection<File> deleted )
+241         throws MojoExecutionException
+242     {
+243         List<File> deletedList = new ArrayList<File>();
+244         for ( File f : deleted )
+245         {
+246             deletedList.add( relativize( checkoutDirectory, f ) );
+247         }
+248         ScmFileSet deletedFileSet = new ScmFileSet( checkoutDirectory, deletedList );
+249         try
+250         {
+251             RemoveScmResult deleteResult =
+252                 scmProvider.remove( scmRepository, deletedFileSet, "Deleting obsolete site files." );
+253             if ( !deleteResult.isSuccess() )
+254             {
+255                 logError( "delete operation failed: %s",
+256                           deleteResult.getProviderMessage() + " " + deleteResult.getCommandOutput() );
+257                 throw new MojoExecutionException( "Failed to delete files: " + deleteResult.getProviderMessage()
+258                     + " " + deleteResult.getCommandOutput() );
+259             }
+260         }
+261         catch ( ScmException e )
+262         {
+263             throw new MojoExecutionException( "Failed to delete removed files to SCM", e );
+264         }
+265     }
+266 
+267     /**
+268      * Add files to scm.
+269      * 
+270      * @param added files to be added
+271      * @throws MojoFailureException
+272      * @throws MojoExecutionException
+273      */
+274     protected void addFiles( Collection<File> added )
+275         throws MojoFailureException, MojoExecutionException
+276     {
+277         List<File> addedList = new ArrayList<File>();
+278         Set<File> createdDirs = new HashSet<File>();
+279         Set<File> dirsToAdd = new TreeSet<File>();
+280 
+281         createdDirs.add( relativize( checkoutDirectory, checkoutDirectory ) );
+282 
+283         for ( File f : added )
+284         {
+285             for ( File dir = f.getParentFile(); !dir.equals( checkoutDirectory ); dir = dir.getParentFile() )
+286             {
+287                 File relativized = relativize( checkoutDirectory, dir );
+288                 //  we do the best we can with the directories
+289                 if ( createdDirs.add( relativized ) )
+290                 {
+291                     dirsToAdd.add( relativized );
+292                 }
+293                 else
+294                 {
+295                     break;
+296                 }
+297             }
+298             addedList.add( relativize( checkoutDirectory, f ) );
+299         }
+300 
+301         for ( File relativized : dirsToAdd )
+302         {
+303             try 
+304             {
+305                 ScmFileSet fileSet = new ScmFileSet( checkoutDirectory , relativized );
+306                 AddScmResult addDirResult = scmProvider.add( scmRepository, fileSet, "Adding directory" );
+307                 if ( !addDirResult.isSuccess() )
+308                 {
+309                     getLog().debug( " Error adding directory " + relativized + " " + addDirResult.getCommandOutput() );
+310                 }
+311             }
+312             catch ( ScmException e )
+313             {
+314                 //
+315             }
+316         }
+317 
+318         ScmFileSet addedFileSet = new ScmFileSet( checkoutDirectory, addedList );
+319         try
+320         {
+321             AddScmResult addResult = scmProvider.add( scmRepository, addedFileSet, "Adding new site files." );
+322             if ( !addResult.isSuccess() )
+323             {
+324                 logError( "add operation failed: %s",
+325                           addResult.getProviderMessage() + " " + addResult.getCommandOutput() );
+326                 throw new MojoExecutionException( "Failed to add new files: " + addResult.getProviderMessage()
+327                     + " " + addResult.getCommandOutput() );
+328             }
+329         }
+330         catch ( ScmException e )
+331         {
+332             throw new MojoExecutionException( "Failed to add new files to SCM", e );
+333         }
+334     }
+335 
+336     public boolean isDryRun()
+337     {
+338         return dryRun;
+339     }
+340 }
+
+
+ + Added: websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.html ============================================================================== --- websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.html (added) +++ websites/production/maventest/content/sandbox/plugins/maven-scm-publish-plugin/xref/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.html Mon Sep 3 20:21:36 2012 @@ -0,0 +1,264 @@ + + + + +ScmPublishPublishScmMojo xref + + + +
+
+1   package org.apache.maven.plugins.scmpublish;
+2   
+3   import java.io.BufferedReader;
+4   import java.io.File;
+5   import java.io.FileInputStream;
+6   import java.io.FileOutputStream;
+7   import java.io.IOException;
+8   import java.io.InputStreamReader;
+9   import java.io.OutputStreamWriter;
+10  import java.io.PrintWriter;
+11  import java.util.ArrayList;
+12  import java.util.Arrays;
+13  import java.util.Collections;
+14  import java.util.HashSet;
+15  import java.util.List;
+16  import java.util.Set;
+17  
+18  import org.apache.commons.io.FileUtils;
+19  import org.apache.commons.io.IOUtils;
+20  import org.apache.maven.plugin.MojoExecutionException;
+21  import org.apache.maven.plugin.MojoFailureException;
+22  import org.apache.maven.project.MavenProject;
+23  
+24  /*
+25   * Licensed to the Apache Software Foundation (ASF) under one
+26   * or more contributor license agreements.  See the NOTICE file
+27   * distributed with this work for additional information
+28   * regarding copyright ownership.  The ASF licenses this file
+29   * to you under the Apache License, Version 2.0 (the
+30   * "License"); you may not use this file except in compliance
+31   * with the License.  You may obtain a copy of the License at
+32   *
+33   *  http://www.apache.org/licenses/LICENSE-2.0
+34   *
+35   * Unless required by applicable law or agreed to in writing,
+36   * software distributed under the License is distributed on an
+37   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+38   * KIND, either express or implied.  See the License for the
+39   * specific language governing permissions and limitations
+40   * under the License.
+41   */
+42  
+43  /**
+44   * Publish a content to scm in one step. By default, content is taken from default site staging directory
+45   * <code>${project.build.directory}/staging</code>.
+46   * Could be extended to work without project, so usable to update any SCM with any content.
+47   * 
+48   * @goal publish-scm
+49   * @aggregate
+50   * @requiresProject false
+51   */
+52  public class ScmPublishPublishScmMojo
+53      extends ScmPublishPublishMojo
+54  {
+55      /**
+56       * The content to be published.
+57       * 
+58       * @parameter expression="${scmpublish.content}" default-value="${project.build.directory}/staging"
+59       */
+60      private File content;
+61  
+62      /**
+63       * @parameter default-value="${project}"
+64       * @readonly
+65       */
+66      protected MavenProject project;
+67  
+68      private List<File> deleted = new ArrayList<File>();
+69      private List<File> added = new ArrayList<File>();
+70      private List<File> updated = new ArrayList<File>();
+71  
+72      /**
+73       * Update scm checkout directory with content.
+74       *
+75       * @param checkout the scm checkout directory
+76       * @param dir the content to put in scm (can be <code>null</code>)
+77       * @param doNotDeleteDirs directory names that should not be deleted from scm even if not in new content:
+78       *   used for modules, which content is available only when staging
+79       * @throws IOException
+80       */
+81      private void update( File checkout, File dir, List<String> doNotDeleteDirs )
+82          throws IOException
+83      {
+84          Set<String> checkoutContent =
+85              new HashSet<String>( ScmPublishInventory.listInventory( checkout, scmProvider.getScmSpecificFilename() ) );
+86          List<String> dirContent = ( dir != null ) ? Arrays.asList( dir.list() ) : Collections.<String>emptyList();
+87  
+88          Set<String> deleted = new HashSet<String>( checkoutContent );
+89          deleted.removeAll( dirContent );
+90  
+91          for ( String name : deleted )
+92          {
+93              File file = new File( checkout, name );
+94  
+95              if ( ( doNotDeleteDirs != null ) && file.isDirectory() && ( doNotDeleteDirs.contains( name ) ) )
+96              {
+97                  // ignore directory not available
+98                  continue;
+99              }
+100 
+101             if ( file.isDirectory() )
+102             {
+103                 update( file, null, null );
+104             }
+105             this.deleted.add( file );
+106         }
+107 
+108         for ( String name : dirContent )
+109         {
+110             File file = new File( checkout, name );
+111             File source = new File( dir, name );
+112 
+113             if ( source.isDirectory() )
+114             {
+115                 if ( !checkoutContent.contains( name ) )
+116                 {
+117                     this.added.add( file );
+118                     file.mkdir();
+119                 }
+120 
+121                 update( file, source, null );
+122             }
+123             else
+124             {
+125                 if ( checkoutContent.contains( name ) )
+126                 {
+127                     this.updated.add( file );
+128                 }
+129                 else
+130                 {
+131                     this.added.add( file );
+132                 }
+133 
+134                 copyFile( source, file ); 
+135             }
+136         }
+137     }
+138 
+139     /**
+140      * Copy a file content, normalizing newlines when necessary.
+141      *
+142      * @param srcFile the source file
+143      * @param destFile the destination file
+144      * @throws IOException
+145      * @see #requireNormalizeNewlines(File)
+146      */
+147     private void copyFile( File srcFile, File destFile )
+148         throws IOException
+149     {
+150         if ( requireNormalizeNewlines( srcFile ) )
+151         {
+152             normalizeNewlines( srcFile, destFile );
+153         }
+154         else
+155         {
+156             FileUtils.copyFile( srcFile, destFile );
+157         }
+158     }
+159 
+160     /**
+161      * Copy and normalize newlines.
+162      *
+163      * @param srcFile the source file
+164      * @param destFile the destination file
+165      * @throws IOException
+166      */
+167     private void normalizeNewlines( File srcFile, File destFile )
+168         throws IOException
+169     {
+170         BufferedReader in = null;
+171         PrintWriter out = null;
+172         try
+173         {
+174             in = new BufferedReader( new InputStreamReader( new FileInputStream( srcFile ), siteOutputEncoding ) );
+175             out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( destFile ), siteOutputEncoding ) );
+176             String line;
+177             while ( ( line = in.readLine() ) != null )
+178             {
+179                 if ( in.ready() )
+180                 {
+181                     out.println( line );
+182                 }
+183                 else
+184                 {
+185                     out.print( line );
+186                 }
+187             }
+188         }
+189         finally
+190         {
+191             IOUtils.closeQuietly( out );
+192             IOUtils.closeQuietly( in );
+193         }
+194     }
+195 
+196     public void scmPublishExecute()
+197         throws MojoExecutionException, MojoFailureException
+198     {
+199         if ( siteOutputEncoding == null )
+200         {
+201             getLog().warn( "No output encoding, defaulting to UTF-8." );
+202             siteOutputEncoding = "utf-8";
+203         }
+204 
+205         checkoutExisting();
+206 
+207         try
+208         {
+209             logInfo( "Updating content..." );
+210             update( checkoutDirectory, content, ( project == null ) ? null : project.getModel().getModules() );
+211         }
+212         catch ( IOException ioe )
+213         {
+214             throw new MojoExecutionException( "could not copy content to scm checkout", ioe );
+215         }
+216 
+217         logInfo( "Publish files: %d addition(s), %d update(s), %d delete(s)", added.size(), updated.size(),
+218                  deleted.size() );
+219 
+220         if ( isDryRun() )
+221         {
+222             for ( File addedFile : added )
+223             {
+224                 logInfo( "Added %s", addedFile.getAbsolutePath() );
+225             }
+226             for ( File deletedFile : deleted )
+227             {
+228                 logInfo( "Deleted %s", deletedFile.getAbsolutePath() );
+229             }
+230             for ( File updatedFile : updated )
+231             {
+232                 logInfo( "Updated %s", updatedFile.getAbsolutePath() );
+233             }
+234             return;
+235         }
+236 
+237         if ( !added.isEmpty() )
+238         {
+239             addFiles( added );
+240         }
+241 
+242         if ( !deleted.isEmpty() )
+243         {
+244             deleteFiles( deleted );
+245         }
+246 
+247         logInfo( "Checking in SCM..." );
+248         checkinFiles();
+249     }
+250 }
+
+
+ +