Coverage Report - org.apache.maven.plugin.assembly.archive.archiver.AssemblyProxyArchiver
 
Classes in this File Line Coverage Branch Coverage Complexity
AssemblyProxyArchiver
34%
115/340
42%
38/90
0
AssemblyProxyArchiver$DefaultFileInfo
71%
5/7
N/A
0
 
 1  
 package org.apache.maven.plugin.assembly.archive.archiver;
 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.assembly.filter.ContainerDescriptorHandler;
 23  
 import org.codehaus.plexus.archiver.ArchiveFinalizer;
 24  
 import org.codehaus.plexus.archiver.ArchivedFileSet;
 25  
 import org.codehaus.plexus.archiver.Archiver;
 26  
 import org.codehaus.plexus.archiver.ArchiverException;
 27  
 import org.codehaus.plexus.archiver.FileSet;
 28  
 import org.codehaus.plexus.archiver.FinalizerEnabled;
 29  
 import org.codehaus.plexus.archiver.ResourceIterator;
 30  
 import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;
 31  
 import org.codehaus.plexus.archiver.util.DefaultFileSet;
 32  
 import org.codehaus.plexus.components.io.fileselectors.FileInfo;
 33  
 import org.codehaus.plexus.components.io.fileselectors.FileSelector;
 34  
 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
 35  
 import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
 36  
 import org.codehaus.plexus.logging.Logger;
 37  
 
 38  
 import java.io.File;
 39  
 import java.io.FileInputStream;
 40  
 import java.io.IOException;
 41  
 import java.io.InputStream;
 42  
 import java.util.ArrayList;
 43  
 import java.util.Arrays;
 44  
 import java.util.HashSet;
 45  
 import java.util.Iterator;
 46  
 import java.util.List;
 47  
 import java.util.Map;
 48  
 import java.util.Set;
 49  
 
 50  
 /**
 51  
  * Delegating archiver implementation that supports:
 52  
  * <ul>
 53  
  * <li>dry-running (where the delegate archiver is never actually called)</li>
 54  
  * <li>prefixing (where all paths have a set global prefix prepended before addition)</li>
 55  
  * <li>duplication checks on archive additions (for archive-file path + prefix)</li>
 56  
  * </ul>
 57  
  * 
 58  
  * @author jdcasey
 59  
  * @version $Id: AssemblyProxyArchiver.java 1032512 2010-11-08 10:00:58Z dennisl $
 60  
  */
 61  
 public class AssemblyProxyArchiver
 62  
     implements Archiver
 63  
 {
 64  
 
 65  1
     private static final String[] STR_TEMPLATE = new String[0];
 66  
 
 67  
     private final Archiver delegate;
 68  
 
 69  
     private String rootPrefix;
 70  
 
 71  
     private FileSelector[] selectors;
 72  
 
 73  9
     private final ThreadLocal<Boolean> inPublicApi = new ThreadLocal<Boolean>();
 74  
 
 75  
     private final Logger logger;
 76  
 
 77  
     private final boolean dryRun;
 78  
 
 79  
     private boolean forced;
 80  
 
 81  9
     private final Set<String> seenPaths = new HashSet<String>();
 82  
 
 83  
     private final String assemblyWorkPath;
 84  
 
 85  
     /**
 86  
      * @since 2.2
 87  
      */
 88  
     private boolean useJvmChmod;
 89  
 
 90  
     public AssemblyProxyArchiver( final String rootPrefix, final Archiver delegate,
 91  
                                   final List<ContainerDescriptorHandler> containerDescriptorHandlers,
 92  
                                   final List<FileSelector> extraSelectors,
 93  
                                   final List<ArchiveFinalizer> extraFinalizers, final File assemblyWorkDir,
 94  
                                   final Logger logger, final boolean dryRun )
 95  9
     {
 96  9
         this.rootPrefix = rootPrefix;
 97  9
         this.delegate = delegate;
 98  
 
 99  9
         assemblyWorkPath = assemblyWorkDir.getAbsolutePath()
 100  
                                           .replace( '\\', '/' );
 101  
 
 102  9
         this.logger = logger;
 103  9
         this.dryRun = dryRun;
 104  
 
 105  9
         if ( !"".equals( rootPrefix ) && !rootPrefix.endsWith( "/" ) )
 106  
         {
 107  1
             this.rootPrefix += "/";
 108  
         }
 109  
 
 110  9
         final List<FileSelector> selectors = new ArrayList<FileSelector>();
 111  
 
 112  9
         final boolean isFinalizerEnabled = ( delegate instanceof FinalizerEnabled );
 113  
 
 114  9
         if ( containerDescriptorHandlers != null )
 115  
         {
 116  1
             for ( final Iterator<ContainerDescriptorHandler> it = containerDescriptorHandlers.iterator(); it.hasNext(); )
 117  
             {
 118  1
                 final ContainerDescriptorHandler handler = it.next();
 119  
 
 120  1
                 selectors.add( handler );
 121  
 
 122  1
                 if ( isFinalizerEnabled )
 123  
                 {
 124  0
                     ( (FinalizerEnabled) delegate ).addArchiveFinalizer( handler );
 125  
                 }
 126  1
             }
 127  
         }
 128  
 
 129  9
         if ( extraSelectors != null )
 130  
         {
 131  7
             for ( final Iterator<FileSelector> it = extraSelectors.iterator(); it.hasNext(); )
 132  
             {
 133  3
                 final FileSelector selector = it.next();
 134  3
                 selectors.add( selector );
 135  3
             }
 136  
         }
 137  
 
 138  9
         if ( ( extraFinalizers != null ) && isFinalizerEnabled )
 139  
         {
 140  3
             for ( final Iterator<ArchiveFinalizer> it = extraFinalizers.iterator(); it.hasNext(); )
 141  
             {
 142  1
                 ( (FinalizerEnabled) delegate ).addArchiveFinalizer( it.next() );
 143  
             }
 144  
         }
 145  
 
 146  9
         if ( !selectors.isEmpty() )
 147  
         {
 148  4
             this.selectors = selectors.toArray( new FileSelector[selectors.size()] );
 149  
         }
 150  9
     }
 151  
 
 152  
     public void addArchivedFileSet( final File archiveFile, final String prefix, final String[] includes,
 153  
                                     final String[] excludes )
 154  
         throws ArchiverException
 155  
     {
 156  0
         final String archiveKey = getArchiveKey( archiveFile, prefix );
 157  0
         if ( seenPaths.contains( archiveKey ) )
 158  
         {
 159  0
             warn( "Archive: " + archiveFile + " has already been added. Skipping." );
 160  0
             return;
 161  
         }
 162  
 
 163  0
         inPublicApi.set( Boolean.TRUE );
 164  
         try
 165  
         {
 166  0
             final DefaultArchivedFileSet fs = new DefaultArchivedFileSet();
 167  
 
 168  0
             fs.setArchive( archiveFile );
 169  0
             fs.setIncludes( includes );
 170  0
             fs.setExcludes( excludes );
 171  0
             fs.setPrefix( rootPrefix + prefix );
 172  0
             fs.setFileSelectors( selectors );
 173  
 
 174  0
             debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() );
 175  
 
 176  0
             if ( dryRun )
 177  
             {
 178  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 179  
             }
 180  
             else
 181  
             {
 182  0
                 delegate.addArchivedFileSet( fs );
 183  0
                 seenPaths.add( archiveKey );
 184  
             }
 185  
         }
 186  
         finally
 187  
         {
 188  0
             inPublicApi.set( null );
 189  0
         }
 190  0
     }
 191  
 
 192  
     private String getArchiveKey( final File archiveFile, final String prefix )
 193  
     {
 194  0
         return archiveFile.getAbsolutePath() + ":" + prefix;
 195  
     }
 196  
 
 197  
     private void debug( final String message )
 198  
     {
 199  4
         if ( ( logger != null ) && logger.isDebugEnabled() )
 200  
         {
 201  4
             logger.debug( message );
 202  
         }
 203  4
     }
 204  
 
 205  
     private void warn( final String message )
 206  
     {
 207  0
         if ( ( logger != null ) && logger.isWarnEnabled() )
 208  
         {
 209  0
             logger.warn( message );
 210  
         }
 211  0
     }
 212  
 
 213  
     public void addArchivedFileSet( final File archiveFile, final String prefix )
 214  
         throws ArchiverException
 215  
     {
 216  0
         final String archiveKey = getArchiveKey( archiveFile, prefix );
 217  0
         if ( seenPaths.contains( archiveKey ) )
 218  
         {
 219  0
             warn( "Archive: " + archiveFile + " has already been added. Skipping." );
 220  0
             return;
 221  
         }
 222  
 
 223  0
         inPublicApi.set( Boolean.TRUE );
 224  
         try
 225  
         {
 226  0
             final DefaultArchivedFileSet fs = new DefaultArchivedFileSet();
 227  
 
 228  0
             fs.setArchive( archiveFile );
 229  0
             fs.setPrefix( rootPrefix + prefix );
 230  0
             fs.setFileSelectors( selectors );
 231  
 
 232  0
             debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() );
 233  
 
 234  0
             if ( dryRun )
 235  
             {
 236  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 237  
             }
 238  
             else
 239  
             {
 240  0
                 delegate.addArchivedFileSet( fs );
 241  0
                 seenPaths.add( archiveKey );
 242  
             }
 243  
         }
 244  
         finally
 245  
         {
 246  0
             inPublicApi.set( null );
 247  0
         }
 248  0
     }
 249  
 
 250  
     public void addArchivedFileSet( final File archiveFile, final String[] includes, final String[] excludes )
 251  
         throws ArchiverException
 252  
     {
 253  0
         final String archiveKey = getArchiveKey( archiveFile, "" );
 254  0
         if ( seenPaths.contains( archiveKey ) )
 255  
         {
 256  0
             warn( "Archive: " + archiveFile + " has already been added. Skipping." );
 257  0
             return;
 258  
         }
 259  
 
 260  0
         inPublicApi.set( Boolean.TRUE );
 261  
         try
 262  
         {
 263  0
             final DefaultArchivedFileSet fs = new DefaultArchivedFileSet();
 264  
 
 265  0
             fs.setArchive( archiveFile );
 266  0
             fs.setIncludes( includes );
 267  0
             fs.setExcludes( excludes );
 268  0
             fs.setPrefix( rootPrefix );
 269  0
             fs.setFileSelectors( selectors );
 270  
 
 271  0
             debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() );
 272  
 
 273  0
             if ( dryRun )
 274  
             {
 275  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 276  
             }
 277  
             else
 278  
             {
 279  0
                 delegate.addArchivedFileSet( fs );
 280  0
                 seenPaths.add( archiveKey );
 281  
             }
 282  
         }
 283  
         finally
 284  
         {
 285  0
             inPublicApi.set( null );
 286  0
         }
 287  0
     }
 288  
 
 289  
     public void addArchivedFileSet( final File archiveFile )
 290  
         throws ArchiverException
 291  
     {
 292  0
         final String archiveKey = getArchiveKey( archiveFile, "" );
 293  0
         if ( seenPaths.contains( archiveKey ) )
 294  
         {
 295  0
             warn( "Archive: " + archiveFile + " has already been added. Skipping." );
 296  0
             return;
 297  
         }
 298  
 
 299  0
         inPublicApi.set( Boolean.TRUE );
 300  
         try
 301  
         {
 302  0
             final DefaultArchivedFileSet fs = new DefaultArchivedFileSet();
 303  
 
 304  0
             fs.setArchive( archiveFile );
 305  0
             fs.setPrefix( rootPrefix );
 306  0
             fs.setFileSelectors( selectors );
 307  
 
 308  0
             debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() );
 309  
 
 310  0
             if ( dryRun )
 311  
             {
 312  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 313  
             }
 314  
             else
 315  
             {
 316  0
                 delegate.addArchivedFileSet( fs );
 317  0
                 seenPaths.add( archiveKey );
 318  
             }
 319  
         }
 320  
         finally
 321  
         {
 322  0
             inPublicApi.set( null );
 323  0
         }
 324  0
     }
 325  
 
 326  
     public void addDirectory( final File directory, final String prefix, final String[] includes,
 327  
                               final String[] excludes )
 328  
         throws ArchiverException
 329  
     {
 330  0
         inPublicApi.set( Boolean.TRUE );
 331  
         try
 332  
         {
 333  0
             final DefaultFileSet fs = new DefaultFileSet();
 334  
 
 335  0
             fs.setDirectory( directory );
 336  0
             fs.setIncludes( includes );
 337  0
             fs.setExcludes( excludes );
 338  0
             fs.setPrefix( rootPrefix + prefix );
 339  0
             fs.setFileSelectors( selectors );
 340  
 
 341  0
             debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() );
 342  
 
 343  0
             if ( dryRun )
 344  
             {
 345  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 346  
             }
 347  
             else
 348  
             {
 349  0
                 doAddFileSet( fs );
 350  
             }
 351  
         }
 352  
         finally
 353  
         {
 354  0
             inPublicApi.set( null );
 355  0
         }
 356  0
     }
 357  
 
 358  
     public void addDirectory( final File directory, final String prefix )
 359  
         throws ArchiverException
 360  
     {
 361  0
         inPublicApi.set( Boolean.TRUE );
 362  
         try
 363  
         {
 364  0
             final DefaultFileSet fs = new DefaultFileSet();
 365  
 
 366  0
             fs.setDirectory( directory );
 367  0
             fs.setPrefix( rootPrefix + prefix );
 368  0
             fs.setFileSelectors( selectors );
 369  
 
 370  0
             debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() );
 371  
 
 372  0
             if ( dryRun )
 373  
             {
 374  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 375  
             }
 376  
             else
 377  
             {
 378  0
                 doAddFileSet( fs );
 379  
             }
 380  
         }
 381  
         finally
 382  
         {
 383  0
             inPublicApi.set( null );
 384  0
         }
 385  0
     }
 386  
 
 387  
     public void addDirectory( final File directory, final String[] includes, final String[] excludes )
 388  
         throws ArchiverException
 389  
     {
 390  0
         inPublicApi.set( Boolean.TRUE );
 391  
         try
 392  
         {
 393  0
             final DefaultFileSet fs = new DefaultFileSet();
 394  
 
 395  0
             fs.setDirectory( directory );
 396  0
             fs.setIncludes( includes );
 397  0
             fs.setExcludes( excludes );
 398  0
             fs.setPrefix( rootPrefix );
 399  0
             fs.setFileSelectors( selectors );
 400  
 
 401  0
             debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() );
 402  
 
 403  0
             if ( dryRun )
 404  
             {
 405  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 406  
             }
 407  
             else
 408  
             {
 409  0
                 doAddFileSet( fs );
 410  
             }
 411  
         }
 412  
         finally
 413  
         {
 414  0
             inPublicApi.set( null );
 415  0
         }
 416  0
     }
 417  
 
 418  
     public void addDirectory( final File directory )
 419  
         throws ArchiverException
 420  
     {
 421  1
         inPublicApi.set( Boolean.TRUE );
 422  
         try
 423  
         {
 424  1
             final DefaultFileSet fs = new DefaultFileSet();
 425  
 
 426  1
             fs.setDirectory( directory );
 427  1
             fs.setPrefix( rootPrefix );
 428  1
             fs.setFileSelectors( selectors );
 429  
 
 430  1
             debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() );
 431  
 
 432  1
             if ( dryRun )
 433  
             {
 434  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 435  
             }
 436  
             else
 437  
             {
 438  1
                 doAddFileSet( fs );
 439  
             }
 440  
         }
 441  
         finally
 442  
         {
 443  1
             inPublicApi.set( null );
 444  1
         }
 445  1
     }
 446  
 
 447  
     public void addFile( final File inputFile, final String destFileName, final int permissions )
 448  
         throws ArchiverException
 449  
     {
 450  0
         if ( acceptFile( inputFile ) )
 451  
         {
 452  0
             inPublicApi.set( Boolean.TRUE );
 453  
             try
 454  
             {
 455  0
                 debug( "Adding file: " + inputFile + " to archive location: " + rootPrefix + destFileName );
 456  
 
 457  0
                 if ( dryRun )
 458  
                 {
 459  0
                     debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 460  
                 }
 461  
                 else
 462  
                 {
 463  0
                     delegate.addFile( inputFile, rootPrefix + destFileName, permissions );
 464  
                 }
 465  
             }
 466  
             finally
 467  
             {
 468  0
                 inPublicApi.set( null );
 469  0
             }
 470  
         }
 471  0
     }
 472  
 
 473  
     public void addFile( final File inputFile, final String destFileName )
 474  
         throws ArchiverException
 475  
     {
 476  1
         if ( acceptFile( inputFile ) )
 477  
         {
 478  1
             inPublicApi.set( Boolean.TRUE );
 479  
             try
 480  
             {
 481  1
                 debug( "Adding file: " + inputFile + " to archive location: " + rootPrefix + destFileName );
 482  
 
 483  1
                 if ( dryRun )
 484  
                 {
 485  0
                     debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 486  
                 }
 487  
                 else
 488  
                 {
 489  1
                     delegate.addFile( inputFile, rootPrefix + destFileName );
 490  
                 }
 491  
             }
 492  
             finally
 493  
             {
 494  1
                 inPublicApi.set( null );
 495  1
             }
 496  
         }
 497  1
     }
 498  
 
 499  
     public void createArchive()
 500  
         throws ArchiverException, IOException
 501  
     {
 502  2
         inPublicApi.set( Boolean.TRUE );
 503  
         try
 504  
         {
 505  2
             if ( dryRun )
 506  
             {
 507  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 508  
             }
 509  
             else
 510  
             {
 511  2
                 delegate.setForced( forced );
 512  2
                 delegate.createArchive();
 513  
             }
 514  
         }
 515  
         finally
 516  
         {
 517  2
             inPublicApi.set( null );
 518  2
         }
 519  2
     }
 520  
 
 521  
     public int getDefaultDirectoryMode()
 522  
     {
 523  0
         inPublicApi.set( Boolean.TRUE );
 524  
         try
 525  
         {
 526  0
             return delegate.getDefaultDirectoryMode();
 527  
         }
 528  
         finally
 529  
         {
 530  0
             inPublicApi.set( null );
 531  
         }
 532  
     }
 533  
 
 534  
     public int getDefaultFileMode()
 535  
     {
 536  0
         inPublicApi.set( Boolean.TRUE );
 537  
         try
 538  
         {
 539  0
             return delegate.getDefaultFileMode();
 540  
         }
 541  
         finally
 542  
         {
 543  0
             inPublicApi.set( null );
 544  
         }
 545  
     }
 546  
 
 547  
     public File getDestFile()
 548  
     {
 549  0
         inPublicApi.set( Boolean.TRUE );
 550  
         try
 551  
         {
 552  0
             return delegate.getDestFile();
 553  
         }
 554  
         finally
 555  
         {
 556  0
             inPublicApi.set( null );
 557  
         }
 558  
     }
 559  
 
 560  
     @SuppressWarnings( { "rawtypes", "deprecation" } )
 561  
     public Map getFiles()
 562  
     {
 563  0
         inPublicApi.set( Boolean.TRUE );
 564  
         try
 565  
         {
 566  0
             return delegate.getFiles();
 567  
         }
 568  
         finally
 569  
         {
 570  0
             inPublicApi.set( null );
 571  
         }
 572  
     }
 573  
 
 574  
     public boolean getIncludeEmptyDirs()
 575  
     {
 576  0
         inPublicApi.set( Boolean.TRUE );
 577  
         try
 578  
         {
 579  0
             return delegate.getIncludeEmptyDirs();
 580  
         }
 581  
         finally
 582  
         {
 583  0
             inPublicApi.set( null );
 584  
         }
 585  
     }
 586  
 
 587  
     public boolean isForced()
 588  
     {
 589  0
         inPublicApi.set( Boolean.TRUE );
 590  
         try
 591  
         {
 592  0
             return delegate.isForced();
 593  
         }
 594  
         finally
 595  
         {
 596  0
             inPublicApi.set( null );
 597  
         }
 598  
     }
 599  
 
 600  
     public boolean isSupportingForced()
 601  
     {
 602  0
         inPublicApi.set( Boolean.TRUE );
 603  
         try
 604  
         {
 605  0
             return delegate.isSupportingForced();
 606  
         }
 607  
         finally
 608  
         {
 609  0
             inPublicApi.set( null );
 610  
         }
 611  
     }
 612  
 
 613  
     public void setDefaultDirectoryMode( final int mode )
 614  
     {
 615  0
         inPublicApi.set( Boolean.TRUE );
 616  
         try
 617  
         {
 618  0
             delegate.setDefaultDirectoryMode( mode );
 619  
         }
 620  
         finally
 621  
         {
 622  0
             inPublicApi.set( null );
 623  0
         }
 624  0
     }
 625  
 
 626  
     public void setDefaultFileMode( final int mode )
 627  
     {
 628  0
         inPublicApi.set( Boolean.TRUE );
 629  
         try
 630  
         {
 631  0
             delegate.setDefaultFileMode( mode );
 632  
         }
 633  
         finally
 634  
         {
 635  0
             inPublicApi.set( null );
 636  0
         }
 637  0
     }
 638  
 
 639  
     public void setDestFile( final File destFile )
 640  
     {
 641  1
         inPublicApi.set( Boolean.TRUE );
 642  
         try
 643  
         {
 644  1
             delegate.setDestFile( destFile );
 645  
         }
 646  
         finally
 647  
         {
 648  1
             inPublicApi.set( null );
 649  1
         }
 650  1
     }
 651  
 
 652  
     public void setForced( final boolean forced )
 653  
     {
 654  9
         inPublicApi.set( Boolean.TRUE );
 655  
         try
 656  
         {
 657  9
             this.forced = forced;
 658  9
             delegate.setForced( forced );
 659  
         }
 660  
         finally
 661  
         {
 662  9
             inPublicApi.set( null );
 663  9
         }
 664  9
     }
 665  
 
 666  
     public void setIncludeEmptyDirs( final boolean includeEmptyDirs )
 667  
     {
 668  0
         inPublicApi.set( Boolean.TRUE );
 669  
         try
 670  
         {
 671  0
             delegate.setIncludeEmptyDirs( includeEmptyDirs );
 672  
         }
 673  
         finally
 674  
         {
 675  0
             inPublicApi.set( null );
 676  0
         }
 677  0
     }
 678  
 
 679  
     public void setDotFileDirectory( final File dotFileDirectory )
 680  
     {
 681  0
         throw new UnsupportedOperationException( "Undocumented feature of plexus-archiver; this is not yet supported." );
 682  
     }
 683  
 
 684  
     public void addArchivedFileSet( final ArchivedFileSet fileSet )
 685  
         throws ArchiverException
 686  
     {
 687  0
         final String archiveKey = getArchiveKey( fileSet.getArchive(), "" );
 688  0
         if ( seenPaths.contains( archiveKey ) )
 689  
         {
 690  0
             warn( "Archive: " + fileSet.getArchive() + " has already been added. Skipping." );
 691  0
             return;
 692  
         }
 693  
 
 694  0
         inPublicApi.set( Boolean.TRUE );
 695  
         try
 696  
         {
 697  0
             final PrefixedArchivedFileSet fs = new PrefixedArchivedFileSet( fileSet, rootPrefix, selectors );
 698  
 
 699  0
             debug( "Adding archived file-set in: " + fileSet.getArchive() + " to archive location: " + fs.getPrefix() );
 700  
 
 701  0
             if ( dryRun )
 702  
             {
 703  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 704  
             }
 705  
             else
 706  
             {
 707  0
                 delegate.addArchivedFileSet( fs );
 708  0
                 seenPaths.add( archiveKey );
 709  
             }
 710  
         }
 711  
         finally
 712  
         {
 713  0
             inPublicApi.set( null );
 714  0
         }
 715  0
     }
 716  
 
 717  
     public void addFileSet( final FileSet fileSet )
 718  
         throws ArchiverException
 719  
     {
 720  2
         inPublicApi.set( Boolean.TRUE );
 721  
         try
 722  
         {
 723  2
             final PrefixedFileSet fs = new PrefixedFileSet( fileSet, rootPrefix, selectors );
 724  
 
 725  2
             debug( "Adding file-set in: " + fileSet.getDirectory() + " to archive location: " + fs.getPrefix() );
 726  
 
 727  2
             if ( dryRun )
 728  
             {
 729  0
                 debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
 730  
             }
 731  
             else
 732  
             {
 733  2
                 doAddFileSet( fs );
 734  
             }
 735  
         }
 736  
         finally
 737  
         {
 738  2
             inPublicApi.set( null );
 739  2
         }
 740  2
     }
 741  
 
 742  
     private void doAddFileSet( final FileSet fs )
 743  
         throws ArchiverException
 744  
     {
 745  3
         final String fsPath = fs.getDirectory()
 746  
                                 .getAbsolutePath()
 747  
                                 .replace( '\\', '/' );
 748  
 
 749  3
         if ( fsPath.equals( assemblyWorkPath ) )
 750  
         {
 751  1
             logger.debug( "SKIPPING fileset with source directory matching assembly working-directory: " + fsPath );
 752  1
             return;
 753  
         }
 754  2
         else if ( assemblyWorkPath.startsWith( fsPath ) )
 755  
         {
 756  1
             final List<String> newEx = new ArrayList<String>();
 757  1
             if ( fs.getExcludes() != null )
 758  
             {
 759  0
                 newEx.addAll( Arrays.asList( fs.getExcludes() ) );
 760  
             }
 761  
 
 762  1
             final String workDirExclude = assemblyWorkPath.substring( fsPath.length() + 1 );
 763  
 
 764  1
             logger.debug( "Adding exclude for assembly working-directory: " + workDirExclude
 765  
                             + "\nFile-Set source directory: " + fsPath );
 766  
 
 767  1
             newEx.add( workDirExclude );
 768  
 
 769  1
             final List<String> newIn = new ArrayList<String>();
 770  1
             if ( fs.getIncludes() != null )
 771  
             {
 772  0
                 for ( final String include : fs.getIncludes() )
 773  
                 {
 774  0
                     if ( !include.startsWith( workDirExclude ) )
 775  
                     {
 776  0
                         newIn.add( include );
 777  
                     }
 778  
                 }
 779  
             }
 780  
 
 781  1
             final DefaultFileSet dfs = new DefaultFileSet();
 782  
 
 783  1
             dfs.setCaseSensitive( fs.isCaseSensitive() );
 784  1
             dfs.setDirectory( fs.getDirectory() );
 785  1
             dfs.setExcludes( newEx.toArray( STR_TEMPLATE ) );
 786  1
             dfs.setFileSelectors( fs.getFileSelectors() );
 787  1
             dfs.setIncludes( newIn.toArray( STR_TEMPLATE ) );
 788  1
             dfs.setIncludingEmptyDirectories( fs.isIncludingEmptyDirectories() );
 789  1
             dfs.setPrefix( fs.getPrefix() );
 790  1
             dfs.setUsingDefaultExcludes( fs.isUsingDefaultExcludes() );
 791  
 
 792  1
             delegate.addFileSet( dfs );
 793  1
         }
 794  
         else
 795  
         {
 796  1
             delegate.addFileSet( fs );
 797  
         }
 798  2
     }
 799  
 
 800  
     private String getMethodName()
 801  
     {
 802  0
         final NullPointerException npe = new NullPointerException();
 803  0
         final StackTraceElement[] trace = npe.getStackTrace();
 804  
 
 805  0
         final StackTraceElement methodElement = trace[1];
 806  
 
 807  0
         return methodElement.getMethodName() + " (archiver line: " + methodElement.getLineNumber() + ")";
 808  
     }
 809  
 
 810  
     private boolean acceptFile( final File inputFile )
 811  
         throws ArchiverException
 812  
     {
 813  1
         if ( Boolean.TRUE != inPublicApi.get() )
 814  
         {
 815  1
             if ( selectors != null )
 816  
             {
 817  1
                 final FileInfo fileInfo = new DefaultFileInfo( inputFile );
 818  
 
 819  2
                 for ( int i = 0; i < selectors.length; i++ )
 820  
                 {
 821  1
                     final FileSelector selector = selectors[i];
 822  
 
 823  
                     try
 824  
                     {
 825  1
                         if ( !selector.isSelected( fileInfo ) )
 826  
                         {
 827  0
                             return false;
 828  
                         }
 829  
                     }
 830  0
                     catch ( final IOException e )
 831  
                     {
 832  0
                         throw new ArchiverException( "Error processing file: " + inputFile + " using selector: "
 833  
                                         + selectors[i], e );
 834  1
                     }
 835  
                 }
 836  
             }
 837  
         }
 838  
 
 839  1
         return true;
 840  
     }
 841  
 
 842  
     private static final class DefaultFileInfo
 843  
         implements FileInfo
 844  
     {
 845  
 
 846  
         private final File inputFile;
 847  
 
 848  
         DefaultFileInfo( final File inputFile )
 849  1
         {
 850  1
             this.inputFile = inputFile;
 851  1
         }
 852  
 
 853  
         public InputStream getContents()
 854  
             throws IOException
 855  
         {
 856  0
             return new FileInputStream( inputFile );
 857  
         }
 858  
 
 859  
         public String getName()
 860  
         {
 861  1
             return inputFile.getName();
 862  
         }
 863  
 
 864  
         public boolean isDirectory()
 865  
         {
 866  0
             return inputFile.isDirectory();
 867  
         }
 868  
 
 869  
         public boolean isFile()
 870  
         {
 871  1
             return inputFile.isFile();
 872  
         }
 873  
 
 874  
     }
 875  
 
 876  
     public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions )
 877  
         throws ArchiverException
 878  
     {
 879  0
         inPublicApi.set( Boolean.TRUE );
 880  
         try
 881  
         {
 882  0
             delegate.addResource( resource, destFileName, permissions );
 883  
         }
 884  
         finally
 885  
         {
 886  0
             inPublicApi.set( null );
 887  0
         }
 888  0
     }
 889  
 
 890  
     public void addResources( final PlexusIoResourceCollection resources )
 891  
         throws ArchiverException
 892  
     {
 893  0
         inPublicApi.set( Boolean.TRUE );
 894  
         try
 895  
         {
 896  0
             delegate.addResources( resources );
 897  
         }
 898  
         finally
 899  
         {
 900  0
             inPublicApi.set( null );
 901  0
         }
 902  0
     }
 903  
 
 904  
     public ResourceIterator getResources()
 905  
         throws ArchiverException
 906  
     {
 907  0
         return delegate.getResources();
 908  
     }
 909  
 
 910  
     public String getDuplicateBehavior()
 911  
     {
 912  0
         return delegate.getDuplicateBehavior();
 913  
     }
 914  
 
 915  
     public void setDuplicateBehavior( final String duplicate )
 916  
     {
 917  0
         inPublicApi.set( Boolean.TRUE );
 918  
         try
 919  
         {
 920  0
             delegate.setDuplicateBehavior( duplicate );
 921  
         }
 922  
         finally
 923  
         {
 924  0
             inPublicApi.set( null );
 925  0
         }
 926  0
     }
 927  
 
 928  
     public int getDirectoryMode()
 929  
     {
 930  0
         return delegate.getDirectoryMode();
 931  
     }
 932  
 
 933  
     public int getFileMode()
 934  
     {
 935  0
         return delegate.getFileMode();
 936  
     }
 937  
 
 938  
     public int getOverrideDirectoryMode()
 939  
     {
 940  0
         return delegate.getOverrideDirectoryMode();
 941  
     }
 942  
 
 943  
     public int getOverrideFileMode()
 944  
     {
 945  0
         return delegate.getOverrideFileMode();
 946  
     }
 947  
 
 948  
     public void setDirectoryMode( final int mode )
 949  
     {
 950  0
         inPublicApi.set( Boolean.TRUE );
 951  
         try
 952  
         {
 953  0
             delegate.setDirectoryMode( mode );
 954  
         }
 955  
         finally
 956  
         {
 957  0
             inPublicApi.set( null );
 958  0
         }
 959  0
     }
 960  
 
 961  
     public void setFileMode( final int mode )
 962  
     {
 963  0
         inPublicApi.set( Boolean.TRUE );
 964  
         try
 965  
         {
 966  0
             delegate.setFileMode( mode );
 967  
         }
 968  
         finally
 969  
         {
 970  0
             inPublicApi.set( null );
 971  0
         }
 972  0
     }
 973  
 
 974  
     public boolean isUseJvmChmod()
 975  
     {
 976  0
         return useJvmChmod;
 977  
     }
 978  
 
 979  
     public void setUseJvmChmod( final boolean useJvmChmod )
 980  
     {
 981  5
         this.useJvmChmod = useJvmChmod;
 982  5
     }
 983  
 
 984  
     public boolean isIgnorePermissions()
 985  
     {
 986  0
         return delegate.isIgnorePermissions();
 987  
     }
 988  
 
 989  
     public void setIgnorePermissions( final boolean ignorePermissions )
 990  
     {
 991  5
         delegate.setIgnorePermissions( ignorePermissions );
 992  5
     }
 993  
 
 994  
 }