Skip to content

Commit 7786b17

Browse files
committed
Added dry run archiver
1 parent 8261d74 commit 7786b17

File tree

1 file changed

+236
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)