Coverage Report - org.codehaus.plexus.archiver.diags.TrackingArchiver
 
Classes in this File Line Coverage Branch Coverage Complexity
TrackingArchiver
0%
0/67
N/A
1,13
TrackingArchiver$Addition
0%
0/19
0%
0/10
1,13
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.codehaus.plexus.archiver.diags;
 20  
 
 21  
 import java.io.File;
 22  
 import java.io.IOException;
 23  
 import java.nio.charset.Charset;
 24  
 import java.util.ArrayList;
 25  
 import java.util.HashMap;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 import javax.annotation.Nonnull;
 29  
 import org.codehaus.plexus.archiver.ArchiveEntry;
 30  
 import org.codehaus.plexus.archiver.ArchivedFileSet;
 31  
 import org.codehaus.plexus.archiver.Archiver;
 32  
 import org.codehaus.plexus.archiver.ArchiverException;
 33  
 import org.codehaus.plexus.archiver.FileSet;
 34  
 import org.codehaus.plexus.archiver.ResourceIterator;
 35  
 import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
 36  
 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
 37  
 import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
 38  
 import org.codehaus.plexus.util.StringUtils;
 39  
 
 40  
 /**
 41  
  * A diagnostic archiver that keeps track of stuff that has been added.
 42  
  */
 43  0
 public class TrackingArchiver
 44  
     implements Archiver
 45  
 {
 46  
 
 47  
     private File destFile;
 48  
 
 49  0
     public final List<Addition> added = new ArrayList<Addition>();
 50  
 
 51  
     private boolean useJvmChmod;
 52  
 
 53  
     private boolean ignorePermissions;
 54  
 
 55  
     @Override
 56  
     public void createArchive()
 57  
         throws ArchiverException, IOException
 58  
     {
 59  0
     }
 60  
 
 61  
     @Override
 62  
     public void addDirectory( final @Nonnull File directory )
 63  
         throws ArchiverException
 64  
     {
 65  0
         added.add( new Addition( directory, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 66  0
     }
 67  
 
 68  
     @Override
 69  
     public void addDirectory( final @Nonnull File directory, final String prefix )
 70  
         throws ArchiverException
 71  
     {
 72  0
         added.add( new Addition( directory, prefix, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 73  0
     }
 74  
 
 75  
     @Override
 76  
     public void addDirectory( final @Nonnull File directory, final String[] includes, final String[] excludes )
 77  
         throws ArchiverException
 78  
     {
 79  0
         added.add( new Addition( directory, null, includes, excludes, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public void addDirectory( final @Nonnull File directory, final String prefix, final String[] includes,
 84  
                               final String[] excludes )
 85  
         throws ArchiverException
 86  
     {
 87  0
         added.add( new Addition( directory, prefix, includes, excludes,
 88  
                                  PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 89  
 
 90  0
     }
 91  
 
 92  
     @Override
 93  
     public void addFileSet( final @Nonnull FileSet fileSet )
 94  
         throws ArchiverException
 95  
     {
 96  0
         added.add( new Addition( fileSet, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 97  0
     }
 98  
 
 99  
     @Override
 100  
     public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName )
 101  
         throws ArchiverException
 102  
     {
 103  0
         added.add( new Addition( inputFile, destFileName, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 104  0
     }
 105  
 
 106  
     @Override
 107  
     public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName, final int permissions )
 108  
         throws ArchiverException
 109  
     {
 110  0
         added.add( new Addition( inputFile, destFileName, null, null, permissions ) );
 111  0
     }
 112  
 
 113  
     @Override
 114  
     public void addArchivedFileSet( final @Nonnull File archiveFile )
 115  
         throws ArchiverException
 116  
     {
 117  0
         added.add( new Addition( archiveFile, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 118  0
     }
 119  
 
 120  
     @Override
 121  
     public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix )
 122  
         throws ArchiverException
 123  
     {
 124  0
         added.add( new Addition( archiveFile, prefix, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 125  0
     }
 126  
 
 127  
     @Override
 128  
     public void addSymlink( String s, String s2 )
 129  
         throws ArchiverException
 130  
     {
 131  0
         added.add( new Addition( s, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 132  0
     }
 133  
 
 134  
     @Override
 135  
     public void addSymlink( String s, int i, String s2 )
 136  
         throws ArchiverException
 137  
     {
 138  0
         added.add( new Addition( s, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 139  
 
 140  0
     }
 141  
 
 142  
     @Override
 143  
     public void addArchivedFileSet( final File archiveFile, final String[] includes, final String[] excludes )
 144  
         throws ArchiverException
 145  
     {
 146  0
         added.add( new Addition( archiveFile, null, includes, excludes,
 147  
                                  PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 148  
 
 149  0
     }
 150  
 
 151  
     @Override
 152  
     public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix, final String[] includes,
 153  
                                     final String[] excludes )
 154  
         throws ArchiverException
 155  
     {
 156  0
         added.add( new Addition( archiveFile, prefix, includes, excludes,
 157  
                                  PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 158  
 
 159  0
     }
 160  
 
 161  
     @Override
 162  
     public void addArchivedFileSet( final ArchivedFileSet fileSet )
 163  
         throws ArchiverException
 164  
     {
 165  0
         added.add( new Addition( fileSet, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 166  0
     }
 167  
 
 168  
     @Override
 169  
     public void addArchivedFileSet( final ArchivedFileSet fileSet, Charset charset )
 170  
         throws ArchiverException
 171  
     {
 172  0
         added.add( new Addition( fileSet, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 173  0
     }
 174  
 
 175  
     @Override
 176  
     public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions )
 177  
         throws ArchiverException
 178  
     {
 179  0
         added.add( new Addition( resource, destFileName, null, null, permissions ) );
 180  0
     }
 181  
 
 182  
     @Override
 183  
     public void addResources( final PlexusIoResourceCollection resources )
 184  
         throws ArchiverException
 185  
     {
 186  0
         added.add( new Addition( resources, null, null, null, PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ) );
 187  0
     }
 188  
 
 189  
     @Override
 190  
     public File getDestFile()
 191  
     {
 192  0
         return destFile;
 193  
     }
 194  
 
 195  
     @Override
 196  
     public void setDestFile( final File destFile )
 197  
     {
 198  0
         this.destFile = destFile;
 199  0
     }
 200  
 
 201  
     @Override
 202  
     public void setFileMode( final int mode )
 203  
     {
 204  0
     }
 205  
 
 206  
     @Override
 207  
     public int getFileMode()
 208  
     {
 209  0
         return Integer.parseInt( "0644", 8 );
 210  
     }
 211  
 
 212  
     @Override
 213  
     public int getOverrideFileMode()
 214  
     {
 215  0
         return Integer.parseInt( "0644", 8 );
 216  
     }
 217  
 
 218  
     @Override
 219  
     public void setDefaultFileMode( final int mode )
 220  
     {
 221  0
     }
 222  
 
 223  
     @Override
 224  
     public int getDefaultFileMode()
 225  
     {
 226  0
         return Integer.parseInt( "0644", 8 );
 227  
     }
 228  
 
 229  
     @Override
 230  
     public void setDirectoryMode( final int mode )
 231  
     {
 232  0
     }
 233  
 
 234  
     @Override
 235  
     public int getDirectoryMode()
 236  
     {
 237  0
         return Integer.parseInt( "0755", 8 );
 238  
     }
 239  
 
 240  
     @Override
 241  
     public int getOverrideDirectoryMode()
 242  
     {
 243  0
         return Integer.parseInt( "0755", 8 );
 244  
     }
 245  
 
 246  
     @Override
 247  
     public void setDefaultDirectoryMode( final int mode )
 248  
     {
 249  0
     }
 250  
 
 251  
     @Override
 252  
     public int getDefaultDirectoryMode()
 253  
     {
 254  0
         return Integer.parseInt( "0755", 8 );
 255  
     }
 256  
 
 257  
     @Override
 258  
     public boolean getIncludeEmptyDirs()
 259  
     {
 260  0
         return false;
 261  
     }
 262  
 
 263  
     @Override
 264  
     public void setIncludeEmptyDirs( final boolean includeEmptyDirs )
 265  
     {
 266  0
     }
 267  
 
 268  
     @Override
 269  
     public void setDotFileDirectory( final File dotFileDirectory )
 270  
     {
 271  0
     }
 272  
 
 273  
     public @Nonnull
 274  
     @Override
 275  
     ResourceIterator getResources()
 276  
         throws ArchiverException
 277  
     {
 278  0
         throw new RuntimeException( "Not implemented" );
 279  
     }
 280  
 
 281  
     @SuppressWarnings( "rawtypes" )
 282  
     @Override
 283  
     public Map<String, ArchiveEntry> getFiles()
 284  
     {
 285  0
         return new HashMap<String, ArchiveEntry>();
 286  
     }
 287  
 
 288  
     @Override
 289  
     public boolean isForced()
 290  
     {
 291  0
         return false;
 292  
     }
 293  
 
 294  
     @Override
 295  
     public void setForced( final boolean forced )
 296  
     {
 297  0
     }
 298  
 
 299  
     @Override
 300  
     public boolean isSupportingForced()
 301  
     {
 302  0
         return true;
 303  
     }
 304  
 
 305  
     @Override
 306  
     public String getDuplicateBehavior()
 307  
     {
 308  0
         return null;
 309  
     }
 310  
 
 311  
     @Override
 312  
     public void setDuplicateBehavior( final String duplicate )
 313  
     {
 314  0
     }
 315  
 
 316  0
     public class Addition
 317  
     {
 318  
 
 319  
         /**
 320  
          * {@inheritDoc}
 321  
          *
 322  
          * @see Object#toString()
 323  
          */
 324  
         @Override
 325  
         public String toString()
 326  
         {
 327  0
             return "Addition (\n    resource= " + resource + "\n    directory= " + directory + "\n    destination= "
 328  
                        + destination + "\n    permissions= " + permissions + "\n    includes= "
 329  
                        + ( includes == null ? "-none-" : StringUtils.join( includes, ", " ) )
 330  
                        + "\n    excludes= "
 331  
                        + ( excludes == null ? "-none-" : StringUtils.join( excludes, ", " ) ) + "\n)";
 332  
 
 333  
         }
 334  
 
 335  
         public final Object resource;
 336  
 
 337  
         public final File directory;
 338  
 
 339  
         public final String destination;
 340  
 
 341  
         public final int permissions;
 342  
 
 343  
         public final String[] includes;
 344  
 
 345  
         public final String[] excludes;
 346  
 
 347  
         public Addition( final Object resource, final String destination, final String[] includes,
 348  
                          final String[] excludes, final int permissions )
 349  0
         {
 350  0
             this.resource = resource;
 351  0
             if ( resource instanceof FileSet )
 352  
             {
 353  0
                 final FileSet fs = (FileSet) resource;
 354  0
                 directory = fs.getDirectory();
 355  0
                 this.destination = fs.getPrefix();
 356  0
                 this.includes = fs.getIncludes();
 357  0
                 this.excludes = fs.getExcludes();
 358  0
                 this.permissions = permissions;
 359  0
             }
 360  
             else
 361  
             {
 362  0
                 if ( resource instanceof File && ( (File) resource ).isDirectory() )
 363  
                 {
 364  0
                     directory = (File) resource;
 365  
                 }
 366  
                 else
 367  
                 {
 368  0
                     directory = null;
 369  
                 }
 370  
 
 371  0
                 this.destination = destination;
 372  0
                 this.includes = includes;
 373  0
                 this.excludes = excludes;
 374  0
                 this.permissions = permissions;
 375  
             }
 376  0
         }
 377  
 
 378  
     }
 379  
 
 380  
     @Override
 381  
     public boolean isUseJvmChmod()
 382  
     {
 383  0
         return useJvmChmod;
 384  
     }
 385  
 
 386  
     @Override
 387  
     public void setUseJvmChmod( final boolean useJvmChmod )
 388  
     {
 389  0
         this.useJvmChmod = useJvmChmod;
 390  0
     }
 391  
 
 392  
     @Override
 393  
     public boolean isIgnorePermissions()
 394  
     {
 395  0
         return ignorePermissions;
 396  
     }
 397  
 
 398  
     @Override
 399  
     public void setIgnorePermissions( final boolean ignorePermissions )
 400  
     {
 401  0
         this.ignorePermissions = ignorePermissions;
 402  0
     }
 403  
 
 404  
 }