Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import java.util.zip.ZipEntry
class FileExtensionMethods {

public static final String ZIP_EXTENSION = ".zip"
public static final String JAR_EXTENSION = ".jar"

static File zip ( File self ) {
zip( self, null, null )
Expand Down Expand Up @@ -96,8 +97,8 @@ class FileExtensionMethods {
created = true
}
try {
if (file && !file.isFile()) throw new IllegalArgumentException("'destination' has to be a *.zip file.")
if (file && !file.name.toLowerCase().endsWith(ZIP_EXTENSION)) throw new IllegalArgumentException("'destination' has to be a *.zip file.")
if (file && !file.isFile()) throw new IllegalArgumentException("'destination' has to be a *.zip or *.jar file.")
if (file && !file.name.toLowerCase().endsWith(ZIP_EXTENSION) && !file.name.toLowerCase().endsWith(JAR_EXTENSION)) throw new IllegalArgumentException("'destination' has to be a *.zip or *.jar file.")
}
catch( e ) {
if( created ) {
Expand Down Expand Up @@ -168,10 +169,10 @@ class FileExtensionMethods {
}

private static void checkUnzipFileType(File self) {
if (!self.isFile()) throw new IllegalArgumentException("File#unzip() has to be called on a *.zip file.")
if (!self.isFile()) throw new IllegalArgumentException("File#unzip() has to be called on a *.zip or *.jar file.")

def filename = self.name
if (!filename.toLowerCase().endsWith(ZIP_EXTENSION)) throw new IllegalArgumentException("File#unzip() has to be called on a *.zip file.")
if (!filename.toLowerCase().endsWith(ZIP_EXTENSION) && !filename.toLowerCase().endsWith(JAR_EXTENSION)) throw new IllegalArgumentException("File#unzip() has to be called on a *.zip or *.jar file.")
}

private static void checkUnzipDestination(File file) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/tests/ZipFileTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class ZipFileTests extends Specification {

then:
IllegalArgumentException ex = thrown()
ex.message == "'destination' has to be a *.zip file."
ex.message == "'destination' has to be a *.zip or *.jar file."
}

def 'put zip file to the given destination'() {
Expand Down Expand Up @@ -130,7 +130,7 @@ public class ZipFileTests extends Specification {

then:
IllegalArgumentException ex = thrown()
ex.message == "File#unzip() has to be called on a *.zip file."
ex.message == "File#unzip() has to be called on a *.zip or *.jar file."
}

def 'unzip single file'() {
Expand All @@ -143,4 +143,4 @@ public class ZipFileTests extends Specification {
files[0].name.endsWith('test1.txt')
files[0].length() == len1
}
}
}