Project Report: fawkez

Packagesummary org.jcoderz.commons.taskdefs

org.jcoderz.commons.taskdefs.XtremeDocs

LineHitsNoteSource
1  /*
2   * $Id: XtremeDocs.java 1307 2009-03-24 20:16:31Z 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.commons.taskdefs;
34  
35  
36  import java.io.File;
37  import java.io.FileInputStream;
38  import java.io.FileOutputStream;
39  import java.io.FilenameFilter;
40  import java.io.IOException;
41  import java.io.OutputStream;
42  import java.util.ArrayList;
43  import java.util.Iterator;
44  import java.util.List;
45  
46  import javax.xml.transform.Transformer;
47  
48  import org.apache.batik.transcoder.TranscoderException;
49  import org.apache.batik.transcoder.TranscoderInput;
50  import org.apache.batik.transcoder.TranscoderOutput;
51  import org.apache.batik.transcoder.XMLAbstractTranscoder;
52  import org.apache.batik.transcoder.image.PNGTranscoder;
53  import org.apache.tools.ant.BuildException;
54  import org.apache.tools.ant.Project;
55  import org.apache.tools.ant.Task;
56  import org.apache.tools.ant.types.FileSet;
57  import org.apache.tools.ant.types.Path;
58  import org.jcoderz.commons.util.Constants;
59  import org.jcoderz.commons.util.IoUtil;
60  import org.jcoderz.commons.util.StringUtil;
61  
62  
63  /**
64   * Xtreme Documentation Ant task.
65   *
66   * @author Michael Griffel
67   */
680 public class XtremeDocs
69      extends Task
70  {
71      private static final String FORMAT_PDF = "PDF";
72  
73      private static final String FORMAT_HTML = "HTML";
74  
75      private static final String FORMAT_ALL = "ALL";
76  
77      private static final String FORMAT_NONE = "NONE";
78  
79      private static final String TYPE_QUALITY_REPORT = "Quality-Report";
80      
81      private static final String TYPE_KPI_STATS = "KPI-Stats";
82      
83      private static final String TYPE_KPI_REPORT = "KPI-Report";
84  
85      private static final String TYPE_RELEASE_NOTES = "Release-Notes";
86  
87      private static final String TYPE_TEST_SPEC = "TestSpec";
88  
89      private static final String TYPE_USE_CASE = "UseCase";
90  
91      private static final String TYPE_SAD = "SAD";
92  
93      private static final String IMAGE_DIR = "images";
94  
95      private static final String APIDOC_DIR = "apidoc";
96  
97      private static final String DEFAULT_COMPANY_NAME = "jCoderZ.org";
98  
99      private static final String DEFAULT_COMPANY_LOGO = "jcoderz-org";
100  
101      private static final boolean DEFAULT_VALIDATION_ONLY_FLAG = false;
102  
103      /** The output directory. */
104      private File mOutDir;
105  
106      /** XEP home directory. */
107      private File mXepHome;
108  
109      /** The input file. */
110      private File mInFile;
111  
112      /** terminate ant build on error. */
113      private boolean mFailOnError;
114  
115      /** Type of document. (SAD|UseCase) */
116      private String mType;
117  
118      /** Format of document. (NONE|HTML|PDF|ALL) */
119      private String mFormat;
120  
121      private String mTypeLowerCase;
122  
1230     private final Path mDocletPath = new Path(getProject());
124  
1250     private final Path mClassPath = new Path(getProject());
126  
1270     private final List mFormatters = new ArrayList();
128  
129      /** Source path - list of SourceDirectory. */
1300     private final List mSources = new ArrayList();
131  
132      /** Cruise Control label */
133      private String mCcLabel;
134  
135      /** company name */
1360     private String mCompanyName = DEFAULT_COMPANY_NAME;
137  
138      /** company logo without suffix */
1390     private String mCompanyLogo = DEFAULT_COMPANY_LOGO;
140  
141      /** flag for execution of validation tasks only */
1420     private boolean mValidationOnly = DEFAULT_VALIDATION_ONLY_FLAG;
143  
144      /** List of Variables set as Properties in the Transformer context. */
1450     private final List mTransformerProperties = new ArrayList();
146  
147      private HibernateInfoData mHibernateInfoData;
148  
149      /**
150       * Add the given property to be sent to the transformer.
151       *
152       * @param var the property to be sent to the transformer.
153       */
154      public void addParam (org.apache.tools.ant.types.Environment.Variable var)
155      {
1560         mTransformerProperties.add(var);
1570     }
158  
159      void setXdocTransformerParams (Transformer transformer)
160      {
161 (1)        // TODO: Implement this in the corresponding first pass style
162          // sheets
163          // or remove this!
1640         transformer.setParameter("basedir", getProject().getBaseDir()
165              .toString());
1660         transformer.setParameter("cclabel", mCcLabel);
1670         transformer.setParameter("user", System.getProperty("user.name"));
1680         transformer.setParameter("companyname", mCompanyName);
1690         transformer.setParameter("companylogo", mCompanyLogo);
1700         final Iterator i = mTransformerProperties.iterator();
1710         while (i.hasNext())
172          {
1730(2)            final org.apache.tools.ant.types.Environment.Variable var = (org.apache.tools.ant.types.Environment.Variable) i
174                  .next();
1750             transformer.setParameter(var.getKey(), var.getValue());
1760         }
1770     }
178  
179      /**
180       * Sets the XML input file that contains the document.
181       *
182       * @param f the XML input file (log message info).
183       */
184      public void setIn (File f)
185      {
1860         mInFile = f;
1870     }
188  
189      /**
190       * Set the destination directory into which the result files should
191       * be copied to. This parameter is required.
192       *
193       * @param dir the name of the destination directory.
194       */
195      public void setOut (File dir)
196      {
1970         mOutDir = dir;
1980     }
199  
200      /**
201       * Set the XEP home directory.
202       *
203       * @param dir the name of the XEP home directory.
204       */
205      public void setXephome (File dir)
206      {
2070         mXepHome = dir;
2080     }
209  
210      /**
211       * Set the document type.
212       *
213       * @param type the document type.
214       */
215      public void setType (String type)
216      {
2170         mType = type;
2180         mTypeLowerCase = type.toLowerCase(Constants.SYSTEM_LOCALE);
2190     }
220  
221      /**
222       * Set the document format.
223       *
224       * @param format the document format.
225       */
226      public void setFormat (String format)
227      {
2280         mFormat = format;
2290     }
230  
231      /**
232       * Set the document type.
233       *
234       * @param label the cruise control label.
235       */
236      public void setCclabel (String label)
237      {
2380         mCcLabel = label;
2390     }
240  
241      /**
242       * Set the name of the company or organisation.
243       *
244       * @param companyName The mCompanyName to set.
245       */
246      public void setCompanyName (String companyName)
247      {
2480         mCompanyName = companyName;
2490     }
250  
251      /**
252       * Set the flag, whether only validation should be executed or not.
253       *
254       * @param validationOnly The mValidationOnly to set.
255       */
256      public void setValidationOnly (boolean validationOnly)
257      {
2580         mValidationOnly = validationOnly;
2590     }
260  
261      /**
262       * Set the name of the company logo without suffix.
263       *
264       * @param companyLogo The mCompanyLogo to set.
265       */
266      public void setCompanyLogo (String companyLogo)
267      {
2680         mCompanyLogo = companyLogo;
2690     }
270  
271      /**
272       * Set whether we should fail on an error.
273       *
274       * @param b Whether we should fail on an error.
275       */
276      public void setFailonerror (boolean b)
277      {
2780         mFailOnError = b;
2790     }
280  
281      /**
282       * Additional path that is used to find the javadoc doclets.
283       *
284       * @return a path.
285       */
286      public Path createDocletpath ()
287      {
2880         return mDocletPath;
289      }
290  
291      /**
292       * The classpath that is used to find the classes for the DocBook
293       * formatters.
294       *
295       * @return a path.
296       */
297      public Path createClasspath ()
298      {
2990         return mClassPath;
300      }
301  
302      /**
303       * Creates a new FormatterInfoData object used as nested element to
304       * describe the DocBook formatters.
305       *
306       * @return a new FormatterInfoData object.
307       */
308      public FormatterInfoData createFormatter ()
309      {
3100         final FormatterInfoData result = FormatterInfoData.create();
3110         mFormatters.add(result);
3120         return result;
313      }
314  
315      /**
316       * Creates a new HibernateInfoData object used as nested element to
317       * describe the Hibernate Generator options.
318       *
319       * @return a new FormatterInfoData object.
320       */
321      public HibernateInfoData createHibernate ()
322      {
3230         final HibernateInfoData hibernateInfoData = HibernateInfoData.create();
3240         mHibernateInfoData = hibernateInfoData;
3250         return hibernateInfoData;
326      }
327  
328      /**
329       * Returns the classpath element.
330       *
331       * @return the classpath element.
332       */
333      public Path getClassPath ()
334      {
3350         return mClassPath;
336      }
337  
338      /**
339       * Returns <tt>true</tt> if this task (or subtasks) should fail on
340       * any error; <tt>false</tt> otherwise.
341       *
342       * @return <tt>true</tt> if this task (or subtasks) should fail on
343       *         any error; <tt>false</tt> otherwise.
344       */
345      public boolean failOnError ()
346      {
3470         return mFailOnError;
348      }
349  
350      /**
351       * Set the source path to be used for this task run.
352       *
353       * @param src an Ant FileSet object containing the compilation
354       *        source path.
355       */
356      public void addSrc (SourceDirectory src)
357      {
3580         mSources.add(src);
3590     }
360  
361      /**
362       * Execute this task.
363       *
364       * @throws BuildException An building exception occurred.
365       */
366 (3)    public void execute ()
367          throws BuildException
368      {
369          try
370          {
3710             checkAttributes();
3720             log("Generating documentation into directory " + mOutDir);
3730             final File imageDir = new File(mOutDir, IMAGE_DIR);
374              // convertPackageHtml2DocBook();
3750             final File filePassOne = transformPassOne(mInFile);
3760             if (TYPE_SAD.equals(mType))
377              {
3780                 generateApiDocs(filePassOne);
3790                 generateSadDiagrams(filePassOne);
380              }
3810             else if (TYPE_USE_CASE.equals(mType))
382              {
3830                 if (!mValidationOnly)
384                  {
3850                     generateUseCaseDiagrams(filePassOne, imageDir);
386                      //exportToXmi(filePassOne, imageDir);
3870                     AntTaskUtil.renderDotFiles(this, imageDir, mFailOnError);
3880                     exportToHbCfg(filePassOne);
3890                     exportToHbm(filePassOne);
390                  }
391              }
3920             else if (TYPE_KPI_STATS.equals(mType))
393              {
3940                 final File kpiFile = transformPassTwo(filePassOne);
3950(4)                File newFile = new File(AntTaskUtil.stripFileExtension(AntTaskUtil
396                      .stripFileExtension(kpiFile.getAbsolutePath())));
3970(5)                kpiFile.renameTo(newFile);
3980             }
3990             else if (TYPE_KPI_REPORT.equals(mType))
400              {
4010                 generateKeyPerformanceDiagrams(filePassOne, imageDir);
4020                 AntTaskUtil.renderGnuplotFiles(this, imageDir, mFailOnError);
403              }
4040             else if (TYPE_TEST_SPEC.equals(mType))
405              {
406                  // Nothing to do
407              }
4080             else if (TYPE_QUALITY_REPORT.equals(mType))
409              {
410                  // Nothing to do
411              }
4120             else if (TYPE_RELEASE_NOTES.equals(mType))
413              {
414                  // Nothing to do
415              }
416              else
417              {
4180                 throw new RuntimeException("Unsupported type " + mType);
419              }
420              
4210             if (TYPE_KPI_STATS.equals(mType))
422              {
423                  // do nothing
424              }
425              else
426              {
4270                 if (!mValidationOnly)
428                  {
4290                     if (isOutputEnabled(FORMAT_HTML))
430                      {
4310                         rasterizeSvgFiles(imageDir);
432                      }
4330                     if (isOutputEnabled(FORMAT_PDF))
434                      {
4350                         scaleSvgImages(imageDir);
436                      }
437                  }
438              }
439              
4400             if (TYPE_TEST_SPEC.equals(mType))
441              {
4420                 renderDocbookFilesFromPassOne(filePassOne);
443              }
4440             else if (TYPE_KPI_STATS.equals(mType))
445              {
446                  // do nothing
447              }
4480             else if (TYPE_KPI_REPORT.equals(mType))
449              {
4500                 final File docBookFile = transformPassTwo(filePassOne);
451 (6)                // rendering is placed here, thus PassTwo will also generate diagrams
4520                 AntTaskUtil.renderGnuplotFiles(this, imageDir, mFailOnError);
4530                 renderDocBook(docBookFile, mInFile);
4540             }
455              else
456              {
4570                 final File docBookFile = transformPassTwo(filePassOne);
4580                 renderDocBook(docBookFile, mInFile);
459              }
460          }
4610         catch (BuildException e)
462          {
4630             if (mFailOnError)
464              {
4650                 throw e;
466              }
4670             log(e.getMessage(), Project.MSG_ERR);
4680         }
4690     }
470  
471      private boolean isOutputEnabled (String format)
472      {
473          final boolean result;
4740(7)        if (StringUtil.isEmptyOrNull(mFormat)
475              || mFormat.equals(FORMAT_ALL) || mFormat.equals(format))
476          {
4770             result = true;
478          }
4790(8)        else if (mFormat.equals(FORMAT_NONE))
480          {
4810             result = false;
482          }
483          else
484          {
4850             result = true;
486          }
4870         return result;
488      }
489  
490      File getXepHome ()
491      {
4920         return mXepHome;
493      }
494  
495      private void renderDocBook (File docBookFile, File inFile)
496      {
4970         for (final Iterator i = mFormatters.iterator(); i.hasNext();)
498          {
4990             final FormatterInfoData f = (FormatterInfoData) i.next();
5000             final Formatter formatter = Formatter.getInstance(f);
5010             final File out = new File(docBookFile.getParentFile(), AntTaskUtil
502                  .stripFileExtension(inFile.getName())
503                  + "." + formatter.getFileExtension());
5040             if (isOutputEnabled(formatter.getInfoData().getType()))
505              {
5060                 formatter.transform(this, docBookFile, out);
507              }
5080         }
5090     }
510  
511      private void renderDocbookFilesFromPassOne (File filePassOne)
512      {
5130         File docbookDir = new File(filePassOne.getParent());
5140         transformPassTwo(filePassOne);
5150         log("Search files to render in directory: " + docbookDir.getParent());
5160         final File[] docbookFiles = docbookDir.listFiles(new FilenameFilter()
5170(9)        {
518              public boolean accept (File dir, String name)
519              {
520                  final boolean result;
5210                 if (name.endsWith(".p2"))
522                  {
5230                     result = true;
524                  }
525                  else
526                  {
5270                     result = false;
528                  }
5290                 return result;
530              }
531          });
5320         if (docbookFiles != null)
533          {
5340             for (int i = 0; i < docbookFiles.length; i++)
535              {
5360                 final File docbookFile = docbookFiles[i];
5370                 final File passOneFile = new File(AntTaskUtil
538                      .stripFileExtension(AntTaskUtil
539                          .stripFileExtension(docbookFile.getName())));
5400                 renderDocBook(docbookFile, passOneFile);
5410                 log("Will render file: " + docbookFile.getName(),
542                      Project.MSG_VERBOSE);
543              }
544          }
545          else
546          {
5470             log("No .xml files found to render", Project.MSG_VERBOSE);
548          }
5490     }
550  
551      private File transformPassOne (File in)
552      {
5530         final XsltBasedTask task = new XsltBasedTask()
5540         {
555              String getDefaultStyleSheet ()
556              {
5570                 return mTypeLowerCase + "-pass-one.xsl";
558              }
559  
560              void setAdditionalTransformerParameters (Transformer transformer)
561              {
5620                 setXdocTransformerParams(transformer);
5630             }
564          };
5650         task.setProject(getProject());
5660         task.setTaskName(mTypeLowerCase + "-p1");
5670         task.setIn(in);
5680(10)        task.setForce(true); // FIXME
5690         final File outFile = new File(mOutDir, in.getName() + ".p1");
5700         task.setOut(outFile);
5710         task.setFailonerror(mFailOnError);
5720         task.setDestdir(outFile.getParentFile());
5730         task.execute();
5740         return outFile;
575      }
576  
577      private File transformPassTwo (File filePassOne)
578      {
5790         final XsltBasedTask task = new XsltBasedTask()
5800         {
581              String getDefaultStyleSheet ()
582              {
5830                 return mTypeLowerCase + "-pass-two.xsl";
584              }
585  
586              void setAdditionalTransformerParameters (Transformer transformer)
587              {
5880                 setXdocTransformerParams(transformer);
5890             }
590          };
5910         task.setProject(getProject());
5920         task.setTaskName(mTypeLowerCase + "-p2");
5930         task.setIn(filePassOne);
5940(11)        task.setForce(true); // FIXME
5950         final File outFile = new File(mOutDir, filePassOne.getName() + ".p2");
5960         task.setOut(outFile);
5970         task.setFailonerror(mFailOnError);
5980         task.setDestdir(outFile.getParentFile());
5990         task.execute();
6000         return outFile;
601      }
602  
603      private void generateUseCaseDiagrams (File filePassOne, final File imageDir)
604      {
6050         if (isOutputEnabled(FORMAT_PDF) || isOutputEnabled(FORMAT_HTML))
606          {
6070             final XsltBasedTask task = new XsltBasedTask()
6080(12)            {
609                  String getDefaultStyleSheet ()
610                  {
6110                     return "usecase_diagrams.xsl";
612                  }
613  
614                  void setAdditionalTransformerParameters (
615                      Transformer transformer)
616                  {
6170                     transformer.setParameter(
618                          "basedir", getProject().getBaseDir().toString());
6190                     transformer.setParameter("imagedir", imageDir.toString());
6200                 }
621              };
6220             task.setProject(getProject());
6230             task.setTaskName("diagrams");
6240             task.setIn(filePassOne);
6250(13)            task.setForce(true); // FIXME
6260             final File outFile
627 (14)                = new File(mOutDir, "use-case-diagrams" + ".tmp");
6280             task.setOut(outFile);
6290             task.setFailonerror(mFailOnError);
6300             task.setDestdir(outFile.getParentFile());
6310             task.execute();
632          }
6330     }
634      
635      private void generateKeyPerformanceDiagrams (
636          File filePassOne, final File imageDir)
637      {
6380         if (isOutputEnabled(FORMAT_PDF) || isOutputEnabled(FORMAT_HTML))
639          {
6400             final XsltBasedTask task = new XsltBasedTask()
6410             {
642                  String getDefaultStyleSheet ()
643                  {
6440                     return "key-performance-diagrams.xsl";
645                  }
646  
647                  void setAdditionalTransformerParameters (
648                      Transformer transformer)
649                  {
6500                     setXdocTransformerParams(transformer);
6510                     transformer.setParameter("imagedir", imageDir.toString());
6520                 }
653              };
6540             task.setProject(getProject());
6550             task.setTaskName("diagrams");
6560             task.setIn(filePassOne);
6570(15)            task.setForce(true); // FIXME
6580             final File outFile
659                  = new File(mOutDir, "key-performance-diagrams" + ".tmp");
6600             task.setOut(outFile);
6610             task.setFailonerror(mFailOnError);
6620             task.setDestdir(outFile.getParentFile());
6630             task.execute();
664          }
6650     }
666  
667 (16)    private void exportToXmi (File filePassOne, final File imageDir)
668      {
6690         final XsltBasedTask task = new XsltBasedTask()
6700(17)        {
671              String getDefaultStyleSheet ()
672              {
6730                 return "usecase_xmi_export.xsl";
674              }
675  
676              void setAdditionalTransformerParameters (Transformer transformer)
677              {
6780                 transformer.setParameter("basedir", getProject().getBaseDir()
679                      .toString());
6800                 transformer.setParameter("imagedir", imageDir.toString());
6810             }
682          };
6830         task.setProject(getProject());
6840         task.setTaskName("uc-xmi");
6850         task.setIn(filePassOne);
6860(18)        task.setForce(true); // FIXME
6870         final File outFile = new File(mOutDir, "use-case-xmi" + ".tmp");
6880         task.setOut(outFile);
6890         task.setFailonerror(mFailOnError);
6900         task.setDestdir(outFile.getParentFile());
6910         task.execute();
6920     }
693  
694      private void exportToHbm (File filePassOne)
695      {
6960         final String targetdir = buildTargetDir(filePassOne.getName());
6970         File dir = new File(targetdir);
6980(19)        dir.mkdir();
699  
7000         final XsltBasedTask task = new XsltBasedTask()
7010         {
702              String getDefaultStyleSheet ()
703              {
7040                 return "usecase_hbm_export.xsl";
705              }
706  
707              void setAdditionalTransformerParameters (Transformer transformer)
708              {
7090                 transformer.setParameter("targetdir", targetdir);
7100                 transformer.setParameter("package-prefix",
711                      mHibernateInfoData.getPackagePrefix());
7120                 transformer.setParameter("package-suffix",
713                      mHibernateInfoData.getPackageSuffix());
7140                 transformer.setParameter("tablename-prefix",
715                      mHibernateInfoData.getTableNamePrefix());
7160                 transformer.setParameter("tablename-suffix",
717                      mHibernateInfoData.getTableNameSuffix());
7180                 transformer.setParameter("foreign-key-prefix",
719                      mHibernateInfoData.getForeignKeyPrefix());
7200                 transformer.setParameter("foreign-key-suffix",
721                      mHibernateInfoData.getForeignKeySuffix());
7220             }
723          };
7240         task.setProject(getProject());
7250         task.setTaskName("uc-hbm");
7260         task.setIn(filePassOne);
7270(20)        task.setForce(true); // FIXME
7280         final File outFile = new File(mOutDir, "use-case-hbm" + ".tmp");
7290         task.setOut(outFile);
7300         task.setFailonerror(mFailOnError);
7310         task.setDestdir(outFile.getParentFile());
7320         task.execute();
7330     }
734  
735      private void exportToHbCfg (File filePassOne)
736      {
7370         final String targetdir = buildTargetDir(filePassOne.getName());
7380         File dir = new File(targetdir);
7390(21)        dir.mkdir();
740  
7410         final XsltBasedTask task = new XsltBasedTask()
7420         {
743              String getDefaultStyleSheet ()
744              {
7450                 return "usecase_hbcfg_export.xsl";
746              }
747  
748              void setAdditionalTransformerParameters (Transformer transformer)
749              {
7500                 transformer.setParameter("targetdir", targetdir);
7510                 transformer.setParameter("session-factory",
752                      mHibernateInfoData.getSessionFactory());
7530             }
754          };
7550         task.setProject(getProject());
7560         task.setTaskName("uc-hbm");
7570         task.setIn(filePassOne);
7580(22)        task.setForce(true); // FIXME
7590         final File outFile = new File(mOutDir, "use-case-hbcfg" + ".tmp");
7600         task.setOut(outFile);
7610         task.setFailonerror(mFailOnError);
7620         task.setDestdir(outFile.getParentFile());
7630         task.execute();
7640     }
765  
766      private String buildTargetDir (String name)
767      {
7680         String strippedName = name.substring(0, name.lastIndexOf(".xml.p1"));
7690         String dir = mOutDir + File.separator + strippedName
770                         + File.separator + "hibernate";
7710(23)        return dir;
772      }
773  
774      private void generateSadDiagrams (File in)
775      {
7760         final DiagramTask task = new DiagramTask();
7770         task.setTaskName(DiagramTask.NAME);
7780         task.setProject(getProject());
7790         task.setIn(in);
7800         for (final Iterator i = mSources.iterator(); i.hasNext();)
781          {
7820             final SourceDirectory src = (SourceDirectory) i.next();
7830             task.addSrc(src);
7840         }
7850         task.setFailonerror(mFailOnError);
7860         final File out = new File(mOutDir, IMAGE_DIR);
7870         task.setOut(out);
7880         task.setDocletPath(mDocletPath);
7890         task.execute();
7900     }
791  
792      private void scaleSvgImages (File dir)
793      {
7940         final XsltBatchProcessor x = new XsltBatchProcessor();
7950         x.setProject(getProject());
7960         x.setTaskName("svg-scale");
7970         x.setFailonerror(mFailOnError);
7980         x.setXsl("svg-image-transform.xsl");
7990         x.resolveExternalEntities(false);
8000         final FileSet fs = new FileSet();
8010         fs.setDir(dir);
8020         fs.setIncludes("*.svg");
8030         x.addFiles(fs);
8040         x.execute();
8050     }
806  
807      private void generateApiDocs (File in)
808      {
8090         final ApiDocTask task = new ApiDocTask();
8100         task.setTaskName(ApiDocTask.NAME);
8110         task.setProject(getProject());
8120         task.setIn(in);
8130         for (final Iterator i = mSources.iterator(); i.hasNext();)
814          {
8150             final SourceDirectory src = (SourceDirectory) i.next();
8160             task.addSrc(src);
8170         }
8180         task.setFailonerror(mFailOnError);
8190         final File out = new File(mOutDir, APIDOC_DIR);
8200(24)        out.mkdirs();
8210         task.setOut(out);
8220         task.setDocletPath(mDocletPath);
8230         task.execute();
824          // Transform to DocBook
8250         final XsltBatchProcessor x = new XsltBatchProcessor();
8260         x.setProject(getProject());
8270         x.setTaskName("java2docbook");
8280         x.setFailonerror(mFailOnError);
8290         x.setXsl("java2docbook.xsl");
8300         final FileSet fs = new FileSet();
8310         fs.setDir(out);
8320         fs.setIncludes("*.xml");
8330         x.addFiles(fs);
8340         x.execute();
8350     }
836  
837      /**
838       * Checks the attributes provided by this class.
839       *
840       * @throws BuildException
841    */
842      private void checkAttributes ()
843          throws BuildException
844      {
8450         checkAttributeInFile();
8460         XsltBasedTask.checkXercesVersion(this);
8470     }
848  
849      private void checkAttributeInFile ()
850      {
8510         if (mInFile == null)
852          {
8530             throw new BuildException("Missing mandatory attribute 'in'.",
854                  getLocation());
855          }
8560         if (!mInFile.exists())
857          {
8580             throw new BuildException("Input file '" + mInFile + "' not found.",
859                  getLocation());
860          }
8610     }
862  
863      private void rasterizeSvgFiles (File directory)
864      {
8650         final File[] svgFiles = directory.listFiles(new FilenameFilter()
8660(25)        {
867              public boolean accept (File dir, String name)
868              {
869                  final boolean result;
8700                 if (name.endsWith(".svg"))
871                  {
8720                     result = true;
873                  }
874                  else
875                  {
8760                     result = false;
877                  }
8780                 return result;
879              }
880          });
8810         log("Creating raster images for " + svgFiles.length
882              + " images", Project.MSG_INFO);
8830         for (int i = 0; i < svgFiles.length; i++)
884          {
8850             final File svgFile = svgFiles[i];
886              try
887              {
8880                 log("Creating raster image for '" + svgFile.getCanonicalPath()
889                      + "'", Project.MSG_VERBOSE);
890                  /*
891                   * final String[] args = new String[] { "-maxw",
892                   * "700.0", "-scriptSecurityOff",
893                   * svgFile.getCanonicalPath()}; final Main conv = new
894                   * Main(args); // execute the conversion conv.execute();
895                   */
8960                 final File pngFile = new File(svgFile.getParentFile(), svgFile
897                      .getName().substring(0, svgFile.getName().indexOf('.'))
898                      + ".png");
8990                 Rasterizer.rasterize(svgFile, pngFile);
900              }
9010             catch (Exception ex)
902              {
9030                 throw new BuildException(
904                      "Could not generate raster image for '" + svgFile.getName()
905                          + "' (" + ex + ")");
9060             }
907          }
9080     }
909  
910      private static final class Rasterizer
911      {
912          private static final PNGTranscoder TRANSCODER;
913          static
914          {
9150             TRANSCODER = new PNGTranscoder();
916              // force Xerces as XML Reader
9170             TRANSCODER.addTranscodingHint(
918                  XMLAbstractTranscoder.KEY_XML_PARSER_CLASSNAME,
919                  "org.apache.xerces.parsers.SAXParser");
9200         }
921  
922          private Rasterizer ()
9230         {
924              // utility class -- provides only static methods
9250         }
926  
927          public static void rasterize (File in, File out)
928              throws TranscoderException, IOException
929          {
9300             final OutputStream ostream = new FileOutputStream(out);
931              try
932              {
933                  // Create the transcoder input
9340                 final TranscoderInput input = new TranscoderInput(
935                      new FileInputStream(in));
9360(26)                input.setURI(in.toURL().toExternalForm());
937                  // Create the transcoder output
9380                 final TranscoderOutput output = new TranscoderOutput(ostream);
939                  // Transform the SVG document into a PNG image
9400                 TRANSCODER.transcode(input, output);
9410                 ostream.flush();
942              }
943              finally
944              {
9450                 IoUtil.close(ostream);
9460             }
9470         }
948      }
949  
950      /**
951       * The Class FormatterInfoData.
952       */
9530     public static class FormatterInfoData
954      {
955          private File mStyleSheet;
956  
957          private File mCascadingStyleSheet;
958  
959          private String mType;
960  
961          /**
962           * Gets the cascading style sheet.
963           *
964           * @return the cascading style sheet
965           */
966          public File getCascadingStyleSheet ()
967          {
9680             return mCascadingStyleSheet;
969          }
970  
971          /**
972           * Sets the cascading style sheet.
973           *
974           * @param cascadingStyleSheet the new cascading style sheet
975           */
976          public void setCss (File cascadingStyleSheet)
977          {
9780             mCascadingStyleSheet = cascadingStyleSheet;
9790         }
980  
981          /**
982           * Gets the style sheet.
983           *
984           * @return the style sheet
985           */
986          public File getStyleSheet ()
987          {
9880             return mStyleSheet;
989          }
990  
991          /**
992           * Sets the style.
993           *
994           * @param styleSheet the new style
995           */
996          public void setStyle (File styleSheet)
997          {
9980             mStyleSheet = styleSheet;
9990         }
1000  
1001          /**
1002           * Gets the type.
1003           *
1004           * @return the type
1005           */
1006          public String getType ()
1007          {
10080             return mType;
1009          }
1010  
1011          /**
1012           * Sets the type.
1013           *
1014           * @param type the new type
1015           */
1016          public void setType (String type)
1017          {
10180             mType = type;
10190         }
1020  
1021          /**
1022           * Create the formatter info data.
1023           *
1024           * @return the formatter info data
1025           */
1026          public static FormatterInfoData create ()
1027          {
10280             return new FormatterInfoData();
1029          }
1030      }
1031  
1032      /**
1033       * The Class HibernateInfoData.
1034       */
10350     public static class HibernateInfoData
1036      {
1037          private static final String DEFAULT_PACKAGE_PREFIX
1038              = "org.jcoderz.hibernate";
1039          private static final String DEFAULT_PACKAGE_SUFFIX = "";
1040  
1041          private static final String DEFAULT_TABLE_NAME_PREFIX = "JC_";
1042          private static final String DEFAULT_TABLE_NAME_SUFFIX = "S";
1043  
1044          private static final String DEFAULT_FOREIGN_KEY_PREFIX = "FK_";
1045          private static final String DEFAULT_FOREIGN_KEY_SUFFIX = "";
1046  
1047          private static final String DEFAULT_HIBERNATE_SESSION_FACTORY
1048              = "Default";
1049  
1050          /** Package prefix. */
10510         private String mPackagePrefix = DEFAULT_PACKAGE_PREFIX;
1052  
1053          /** Package suffix. */
10540         private String mPackageSuffix = DEFAULT_PACKAGE_SUFFIX;
1055  
1056          /** Table name prefix. */
10570         private String mTableNamePrefix = DEFAULT_TABLE_NAME_PREFIX;
1058  
1059          /** Table name suffix. */
10600         private String mTableNameSuffix = DEFAULT_TABLE_NAME_SUFFIX;
1061  
1062          /** Foreign key name prefix. */
10630         private String mForeignKeyPrefix = DEFAULT_FOREIGN_KEY_PREFIX;
1064  
1065          /** Foreign key name suffix. */
10660         private String mForeignKeySuffix = DEFAULT_FOREIGN_KEY_SUFFIX;
1067  
1068          /** Hibernate session factory. */
10690(27)        private String mHibernateSessionFactory = DEFAULT_HIBERNATE_SESSION_FACTORY;
1070  
1071          /**
1072           * Create the hibernate info data.
1073           *
1074           * @return the hibernate info data
1075           */
1076          public static HibernateInfoData create ()
1077          {
10780             return new HibernateInfoData();
1079          }
1080  
1081          /**
1082           * Sets the session factory.
1083           *
1084           * @param hibernateSessionFactory the new session factory
1085           */
1086          public void setSessionFactory (
1087              String hibernateSessionFactory)
1088          {
10890             this.mHibernateSessionFactory = hibernateSessionFactory;
10900         }
1091  
1092          /**
1093           * Gets the session factory.
1094           *
1095           * @return the session factory
1096           */
1097          public String getSessionFactory ()
1098          {
10990             return mHibernateSessionFactory;
1100          }
1101  
1102          /**
1103           * Sets the package prefix.
1104           *
1105           * @param packagePrefix the new package prefix
1106           */
1107          public void setPackagePrefix (String packagePrefix)
1108          {
11090             mPackagePrefix = packagePrefix;
11100         }
1111  
1112          /**
1113           * Gets the package prefix.
1114           *
1115           * @return the package prefix
1116           */
1117          public String getPackagePrefix ()
1118          {
11190             return mPackagePrefix;
1120          }
1121  
1122          /**
1123           * Sets the package suffix.
1124           *
1125           * @param packageSuffix the new package suffix
1126           */
1127          public void setPackageSuffix (String packageSuffix)
1128          {
11290             mPackageSuffix = packageSuffix;
11300         }
1131  
1132          /**
1133           * Gets the package suffix.
1134           *
1135           * @return the package suffix
1136           */
1137          public String getPackageSuffix ()
1138          {
11390             return mPackageSuffix;
1140          }
1141  
1142          /**
1143           * Sets the table name prefix.
1144           *
1145           * @param mTableNamePrefix the new table name prefix
1146           */
1147 (28)        public void setTableNamePrefix (String tableNamePrefix)
1148          {
11490             mTableNamePrefix = tableNamePrefix;
11500         }
1151  
1152          /**
1153           * Gets the table name prefix.
1154           *
1155           * @return the table name prefix
1156           */
1157          public String getTableNamePrefix ()
1158          {
11590             return mTableNamePrefix;
1160          }
1161  
1162          /**
1163           * Sets the table name suffix.
1164           *
1165           * @param mTableNameSuffix the new table name suffix
1166           */
1167 (29)        public void setTableNameSuffix (String tableNameSuffix)
1168          {
11690             mTableNameSuffix = tableNameSuffix;
11700         }
1171  
1172          /**
1173           * Gets the table name suffix.
1174           *
1175           * @return the table name suffix
1176           */
1177          public String getTableNameSuffix ()
1178          {
11790             return mTableNameSuffix;
1180          }
1181  
1182          /**
1183           * Sets the foreign key prefix.
1184           *
1185           * @param mForeignKeyPrefix the new foreign key prefix
1186           */
1187 (30)        public void setForeignKeyPrefix (String foreignKeyPrefix)
1188          {
11890             mForeignKeyPrefix = foreignKeyPrefix;
11900         }
1191  
1192          /**
1193           * Gets the foreign key prefix.
1194           *
1195           * @return the foreign key prefix
1196           */
1197          public String getForeignKeyPrefix ()
1198          {
11990             return mForeignKeyPrefix;
1200          }
1201  
1202          /**
1203           * Sets the foreign key suffix.
1204           *
1205           * @param mForeignKeySuffix the new foreign key suffix
1206           */
1207 (31)        public void setForeignKeySuffix (String foreignKeySuffix)
1208          {
12090             mForeignKeySuffix = foreignKeySuffix;
12100         }
1211  
1212          public String getForeignKeySuffix ()
1213          {
12140             return mForeignKeySuffix;
1215          }
1216  
1217      }
1218  
1219  }

Findings in this File

c (32) Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'BuildException'.
i (1) 161 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
c (2) 173 : 0 Line is longer than 80 characters.
c (3) 366 : 12 The method execute() has an NPath complexity of 218
c (4) 395 : 0 Line is longer than 80 characters.
w (5) 397 : 0 org.jcoderz.commons.taskdefs.XtremeDocs.execute() ignores exceptional return value of java.io.File.renameTo(File)
c (6) 451 : 0 Line is longer than 80 characters.
i (7) 474 : 0 method org.jcoderz.commons.taskdefs.XtremeDocs.isOutputEnabled(String) makes literal string comparisons passing the literal as an argument
i (8) 479 : 0 method org.jcoderz.commons.taskdefs.XtremeDocs.isOutputEnabled(String) makes literal string comparisons passing the literal as an argument
i (9) 517 : 0 The class org.jcoderz.commons.taskdefs.XtremeDocs$1 could be refactored into a named _static_ inner class
i (10) 568 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (11) 594 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (12) 608 : 0 The class org.jcoderz.commons.taskdefs.XtremeDocs$4 could be refactored into a named _static_ inner class
i (13) 625 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (14) 627 : 59 The String literal ".tmp" appears 5 times in this file; the first occurrence is on line 627
i (15) 657 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (16) 667 : 18 Avoid unused private methods such as 'exportToXmi(File,File)'.
i (17) 670 : 0 The class org.jcoderz.commons.taskdefs.XtremeDocs$6 could be refactored into a named _static_ inner class
i (18) 686 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
w (19) 698 : 0 org.jcoderz.commons.taskdefs.XtremeDocs.exportToHbm(File) ignores exceptional return value of java.io.File.mkdir()
i (20) 727 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
w (21) 739 : 0 org.jcoderz.commons.taskdefs.XtremeDocs.exportToHbCfg(File) ignores exceptional return value of java.io.File.mkdir()
i (22) 758 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
w (23) 771 : 0 method org.jcoderz.commons.taskdefs.XtremeDocs.buildTargetDir(String) stores return result in local before immediately returning it
w (24) 820 : 0 org.jcoderz.commons.taskdefs.XtremeDocs.generateApiDocs(File) ignores exceptional return value of java.io.File.mkdirs()
i (25) 866 : 0 The class org.jcoderz.commons.taskdefs.XtremeDocs$9 could be refactored into a named _static_ inner class
d (26) 936 : 32 [deprecation] toURL() in java.io.File has been deprecated
c (27) 1069 : 0 Line is longer than 80 characters.
d (28) 1147 : 0 @param argument "mTableNamePrefix" is not a parameter name.
d (29) 1167 : 0 @param argument "mTableNameSuffix" is not a parameter name.
d (30) 1187 : 0 @param argument "mForeignKeyPrefix" is not a parameter name.
d (31) 1207 : 0 @param argument "mForeignKeySuffix" is not a parameter name.