-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test to check if a file is a valid .zip. New plublic method i…
…sValidZip and unzip now trows an UnzipException if the file is not a valid .zip. git-svn-id: http://svn.codehaus.org/grails-plugins/grails-grails-ant/trunk@72308 832c1c66-4827-0410-8465-ccb17913cd09
- Loading branch information
Showing
4 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +0,0 @@ | ||
<plugin name='grails-ant' version='0.1.1' grailsVersion='1.2.3 > *'> | ||
<author>Brad Rhoads</author> | ||
<authorEmail>[email protected]</authorEmail> | ||
<title>Grails Ant Plugin</title> | ||
<description> | ||
Provides ant to Grails applications | ||
</description> | ||
<documentation>http://grails.org/plugin/grails-ant</documentation> | ||
<resources> | ||
<resource>BuildConfig</resource> | ||
<resource>Config</resource> | ||
<resource>DataSource</resource> | ||
<resource>UrlMappings</resource> | ||
<resource>org.grails.plugins.grailsant.AntUtilsService</resource> | ||
</resources> | ||
<dependencies /> | ||
<behavior /> | ||
</plugin> | ||
8 changes: 8 additions & 0 deletions
8
src/groovy/org/grails/plugins/grailsant/UnzipException.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
package org.grails.plugins.grailsant | ||
|
||
|
||
class UnzipException extends RuntimeException { | ||
String message | ||
String fileName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.grails.plugins.grailsant; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.zip.ZipException; | ||
import java.util.zip.ZipFile; | ||
|
||
|
||
public class AntUtils { | ||
|
||
/** | ||
* Tests if a file is a valid .zip. | ||
* | ||
* Reference: http://stackoverflow.com/questions/2085637/java-how-to-check-if-a-generated-zip-file-is-corrupted | ||
* | ||
* @param file - the file to test | ||
* @return true if file is a valid .zip, false otherwise | ||
*/ | ||
static boolean isValid(final File file) { | ||
ZipFile zipfile = null; | ||
try { | ||
zipfile = new ZipFile(file); | ||
return true; | ||
} catch (ZipException e) { | ||
return false; | ||
} catch (IOException e) { | ||
return false; | ||
} finally { | ||
try { | ||
if (zipfile != null) { | ||
zipfile.close(); | ||
zipfile = null; | ||
} | ||
} catch (IOException e) { | ||
} | ||
} | ||
} | ||
|
||
} |