Skip to content

Commit c24e300

Browse files
vehovskymichael-o
authored andcommitted
Use more specific exception for cases when there are no files to be archived
This closes #51
1 parent 71256f5 commit c24e300

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

src/main/java/org/codehaus/plexus/archiver/dir/DirectoryArchiver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.codehaus.plexus.archiver.ArchiveEntry;
2424
import org.codehaus.plexus.archiver.ArchiverException;
2525
import org.codehaus.plexus.archiver.ResourceIterator;
26+
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
2627
import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
2728
import org.codehaus.plexus.archiver.util.ResourceUtils;
2829
import org.codehaus.plexus.components.io.attributes.SymlinkUtils;
@@ -53,7 +54,7 @@ public void execute()
5354
final ResourceIterator iter = getResources();
5455
if ( !iter.hasNext() )
5556
{
56-
throw new ArchiverException( "You must set at least one file." );
57+
throw new EmptyArchiveException( "You must set at least one file." );
5758
}
5859

5960
final File destDirectory = getDestFile();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2004 The Apache Software Foundation
3+
* <p/>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p/>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p/>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.codehaus.plexus.archiver.exceptions;
17+
18+
import org.codehaus.plexus.archiver.ArchiverException;
19+
20+
public class EmptyArchiveException
21+
extends ArchiverException
22+
{
23+
24+
public EmptyArchiveException(String message )
25+
{
26+
super( message );
27+
}
28+
29+
public EmptyArchiveException(String message, Throwable cause )
30+
{
31+
super( message, cause );
32+
}
33+
34+
}

src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.codehaus.plexus.archiver.ArchiveEntry;
3131
import org.codehaus.plexus.archiver.ArchiverException;
3232
import org.codehaus.plexus.archiver.ResourceIterator;
33+
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
3334
import org.codehaus.plexus.archiver.util.ResourceUtils;
3435
import org.codehaus.plexus.archiver.util.Streams;
3536
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
@@ -110,7 +111,7 @@ protected void execute()
110111
ResourceIterator iter = getResources();
111112
if ( !iter.hasNext() )
112113
{
113-
throw new ArchiverException( "You must set at least one file." );
114+
throw new EmptyArchiveException( "You must set at least one file." );
114115
}
115116

116117
File tarFile = getDestFile();

src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.codehaus.plexus.archiver.ArchiverException;
4141
import org.codehaus.plexus.archiver.ResourceIterator;
4242
import org.codehaus.plexus.archiver.UnixStat;
43+
import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
4344
import org.codehaus.plexus.archiver.util.ResourceUtils;
4445
import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier;
4546
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
@@ -254,7 +255,7 @@ private void createArchiveMain()
254255
ResourceIterator iter = getResources();
255256
if ( !iter.hasNext() && !hasVirtualFiles() )
256257
{
257-
throw new ArchiverException( "You must set at least one file." );
258+
throw new EmptyArchiveException( "You must set at least one file." );
258259
}
259260

260261
zipFile = getDestFile();

0 commit comments

Comments
 (0)