incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r759494 - /incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
Date Sat, 28 Mar 2009 16:14:47 GMT
Author: cziegeler
Date: Sat Mar 28 16:14:47 2009
New Revision: 759494

URL: http://svn.apache.org/viewvc?rev=759494&view=rev
Log:
SLING-653 : Properly handle closing of file, json file might be a json array.

Modified:
    incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java

Modified: incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java?rev=759494&r1=759493&r2=759494&view=diff
==============================================================================
--- incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
(original)
+++ incubator/sling/trunk/maven/maven-sling-plugin/src/main/java/org/apache/sling/maven/bundlesupport/ValidationMojo.java
Sat Mar 28 16:14:47 2009
@@ -28,6 +28,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
 import org.codehaus.plexus.util.DirectoryScanner;
@@ -110,16 +111,27 @@
         final File file = new File(directory, fileName);
         if ( file.isFile() ) {
             if ( fileName.endsWith(".json") && !this.skipJson ) {
+                getLog().debug("Validation JSON file " + fileName);
+                FileInputStream fis = null;
+                String json = null;
                 try {
-                    final FileInputStream fis = new FileInputStream(file);
-                    getLog().debug("Validation JSON file " + fileName);
-                    final String json = IOUtils.toString(fis);
-                    new JSONObject(json);
-                    fis.close();
-                } catch (JSONException e) {
-                    throw new MojoExecutionException("An Error occured while validating the
file '"+fileName+"'", e);
+                    fis = new FileInputStream(file);
+                    json = IOUtils.toString(fis);
                 } catch (IOException e) {
                     throw new MojoExecutionException("An Error occured while validating the
file '"+fileName+"'", e);
+                } finally {
+                    IOUtils.closeQuietly(fis);
+                }
+                // first, let's see if this is a json array
+                try {
+                    new JSONArray(json);
+                } catch (JSONException e) {
+                    // it might be a json object
+                    try {
+                        new JSONObject(json);
+                    } catch (JSONException je) {
+                        throw new MojoExecutionException("An Error occured while validating
the file '"+fileName+"'", je);
+                    }
                 }
             }
         }



Mime
View raw message