View Javadoc
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 javax.annotation.Nonnull;
25  import org.codehaus.plexus.archiver.ArchivedFileSet;
26  import org.codehaus.plexus.archiver.Archiver;
27  import org.codehaus.plexus.archiver.ArchiverException;
28  import org.codehaus.plexus.archiver.FileSet;
29  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
30  import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
31  import org.codehaus.plexus.logging.Logger;
32  
33  /**
34   * A dry run archiver that does nothing. Some methods fall through to the underlying
35   * archiver, but no actions are executed.
36   */
37  public class DryRunArchiver
38      extends DelgatingArchiver
39  {
40  
41      private final Logger logger;
42  
43      public DryRunArchiver( final Archiver target, final Logger logger )
44      {
45          super( target );
46          this.logger = logger;
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      @Override
53      public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix, final String[] includes,
54                                      final String[] excludes )
55      {
56          debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
57      }
58  
59      private void debug( final String message )
60      {
61          if ( ( logger != null ) && logger.isDebugEnabled() )
62          {
63              logger.debug( message );
64          }
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix )
72          throws ArchiverException
73      {
74          debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public void addArchivedFileSet( final File archiveFile, final String[] includes, final String[] excludes )
82          throws ArchiverException
83      {
84          debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public void addArchivedFileSet( final @Nonnull File archiveFile )
92          throws ArchiverException
93      {
94          debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public void addDirectory( final @Nonnull File directory, final String prefix, final String[] includes,
102                               final String[] excludes )
103         throws ArchiverException
104     {
105         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
106 
107     }
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     public void addSymlink( String symlinkName, String symlinkDestination )
114         throws ArchiverException
115     {
116         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public void addSymlink( String symlinkName, int permissions, String symlinkDestination )
124         throws ArchiverException
125     {
126         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
127     }
128 
129     /**
130      * {@inheritDoc}
131      */
132     @Override
133     public void addDirectory( final @Nonnull File directory, final String prefix )
134         throws ArchiverException
135     {
136         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     @Override
143     public void addDirectory( final @Nonnull File directory, final String[] includes, final String[] excludes )
144         throws ArchiverException
145     {
146         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     @Override
153     public void addDirectory( final @Nonnull File directory )
154         throws ArchiverException
155     {
156         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
157     }
158 
159     /**
160      * {@inheritDoc}
161      */
162     @Override
163     public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName, final int permissions )
164         throws ArchiverException
165     {
166         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
167     }
168 
169     /**
170      * {@inheritDoc}
171      */
172     @Override
173     public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName )
174         throws ArchiverException
175     {
176         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
177     }
178 
179     /**
180      * {@inheritDoc}
181      */
182     @Override
183     public void createArchive()
184         throws ArchiverException, IOException
185     {
186         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
187     }
188 
189     /**
190      * {@inheritDoc}
191      */
192     @Override
193     public void setDotFileDirectory( final File dotFileDirectory )
194     {
195         throw new UnsupportedOperationException(
196             "Undocumented feature of plexus-archiver; this is not yet supported." );
197     }
198 
199     /**
200      * {@inheritDoc}
201      */
202     @Override
203     public void addArchivedFileSet( final ArchivedFileSet fileSet )
204         throws ArchiverException
205     {
206 
207         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
208     }
209 
210     @Override
211     public void addArchivedFileSet( ArchivedFileSet fileSet, Charset charset )
212         throws ArchiverException
213     {
214         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
215     }
216 
217     /**
218      * {@inheritDoc}
219      */
220     @Override
221     public void addFileSet( final @Nonnull FileSet fileSet )
222         throws ArchiverException
223     {
224         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
225     }
226 
227     @Override
228     public void addResource( PlexusIoResource resource, String destFileName, int permissions )
229         throws ArchiverException
230     {
231         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
232     }
233 
234     @Override
235     public void addResources( PlexusIoResourceCollection resources )
236         throws ArchiverException
237     {
238         debug( "DRY RUN: Skipping delegated call to: " + getMethodName() );
239     }
240 
241     private String getMethodName()
242     {
243         final NullPointerException npe = new NullPointerException();
244         final StackTraceElement[] trace = npe.getStackTrace();
245         final StackTraceElement methodElement = trace[1];
246         return methodElement.getMethodName() + " (archiver line: " + methodElement.getLineNumber() + ")";
247     }
248 
249 }