Project Report: fawkez

Packagesummary org.jcoderz.phoenix.sqlparser

org.jcoderz.phoenix.sqlparser.SqlTransformerTask

LineHitsNoteSource
1  /*
2   * $Id: SqlTransformerTask.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.sqlparser;
34  
35  import java.io.File;
36  import java.util.ArrayList;
37  import java.util.HashSet;
38  import java.util.Iterator;
39  import java.util.List;
40  import java.util.Set;
41  
42  import org.apache.tools.ant.BuildException;
43  import org.apache.tools.ant.DirectoryScanner;
44  import org.apache.tools.ant.Project;
45  import org.apache.tools.ant.taskdefs.MatchingTask;
46  import org.apache.tools.ant.types.FileSet;
47  
48  /**
49   * Ant task for the SQL Transformer.
50   * 
51   * @author Michael Griffel
52   */
530 public class SqlTransformerTask
54        extends MatchingTask
55  {
56     /** list of input files. */
570    private final List mFilesets = new ArrayList();
58     /** the output directory. */
59     private File mOutputDir;
60     /** terminate ant build on error. */
610    private boolean mFailOnError = false;
62     /** force output of target files even if they already exist. */
630    private boolean mForce = false;
64     /** the metaInf file (optional). */
650    private File mMetaInfFile = null;
66  
67     
68     /**
69      * Specifies the output directory.
70      * @param d the output directory.
71      */
72     public void setTodir (File d)
73     {
740       mOutputDir = d;
750    }
76     
77     /**
78      * Set whether we should fail on an error.
79      *
80      * @param b Whether we should fail on an error.
81      */
82     public void setFailonerror (boolean b)
83     {
840       mFailOnError = b;
850    }
86  
87     /**
88      * Sets the force output of target files flag to the given value.
89      *
90      * @param b Whether we should force the generation of output files.
91      */
92     public void setForce (boolean b)
93     {
940       mForce = b;
950    }
96     
97     /**
98      * Specifies the MetaInf file (optional parameter).
99      * @param f the MetaInf file.
100      */
101     public void setMetainf (File f)
102     {
1030       mMetaInfFile = f;
1040    }
105     
106     /**
107      * Adds the given files to the file set.
108      * @param set the file set to add.
109      */
110     public void addFileset (FileSet set)
111     {
1120       mFilesets.add(set);
1130    }
114     
115     /**
116      * 
117      * Execute this task.
118      * 
119      * @throws BuildException An building exception occurred.
120      */
121     public void execute ()
122           throws BuildException
123     {
124        try
125        {
1260          checkAttributes();
127         
1280          final File[] files = getSuiteFiles();
1290          int transformedFiles = 0;
1300          for (int i = 0; i < files.length; i++)
131           {
1320             final File inFile = files[i];
1330             final File outFile = new File(mOutputDir, inFile.getName());
1340             if (mForce || inFile.lastModified() > outFile.lastModified())
135              {
1360                log("Transforming file: " + inFile, Project.MSG_INFO);
1370                final SqlTransformer transformer
138                       = new SqlTransformer(
139                          inFile.getAbsolutePath(),
140                          outFile.getAbsolutePath(),
141                           mMetaInfFile != null
142                              ? mMetaInfFile.getAbsolutePath() : null, false);
1430                transformer.execute();
1440                transformedFiles++;
1450             }
146              else
147              {
1480                log(inFile + " omitted as "
149                       + outFile + " is up to date.", Project.MSG_VERBOSE);
150              }
151           }
1520          if (transformedFiles > 0)
153           {
1540             log(transformedFiles + " of " + files.length
155                    + " files transformed successfully", Project.MSG_INFO);
156           }
157        }
1580       catch (BuildException e)
159        {
1600          if (mFailOnError)
161           {
1620             throw e;
163           }
1640          log(e.getMessage(), Project.MSG_ERR);
1650       }
1660    }
167  
168     
169     private void checkAttributes ()
170     {
1710       if (mOutputDir == null)
172        {
1730          throw new BuildException(
174                 "Missing mandatory attribute 'todir'.", getLocation());
175        }
1760       ensureDirectoryFor(mOutputDir);
177        
1780       if (mMetaInfFile != null && !mMetaInfFile.exists())
179        {
1800          throw new BuildException(
181                 "Cannot find META-INF file '" + mMetaInfFile + "'.",
182                 getLocation());
183        }
1840    }
185  
186     /**
187      * Ensure the directory exists for a given directory name.
188      *
189      * @param targetFile the directory name that is required.
190      * @exception BuildException if the directories cannot be created.
191      */
192     private static void ensureDirectoryFor (File directory)
193           throws BuildException
194     {
1950        if (!directory.exists())
196         {
1970            if (!directory.mkdirs())
198             {
1990                throw new BuildException("Unable to create directory: "
200                                          + directory.getAbsolutePath());
201             }
202         }
2030    }
204     
205     private File[] getSuiteFiles ()
206     {
2070       final Set set = new HashSet();
208  
2090       final Iterator iterator = mFilesets.iterator();
2100       while (iterator.hasNext())
211        {
2120          final FileSet fs = (FileSet) iterator.next();
213  
2140          final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
2150          final File dir = fs.getDir(getProject());
2160          final String[] filenames = ds.getIncludedFiles();
2170          for (int i = 0; i < filenames.length; i++)
218           {
2190             set.add(new File(dir, filenames[i]));
220           }
2210       }
222  
2230       final int size = set.size();
2240       log("Found " + size + " files in " + mFilesets.size() + " filesets",
225              Project.MSG_VERBOSE);
226  
2270       return (File[]) set.toArray(new File[size]);
228     }
229  }

Findings in this File

c (1) Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'BuildException'.