Changeset 1331

Show
Ignore:
Timestamp:
03/28/09 20:29:42 (3 years ago)
Author:
amandel
Message:

#2 Quick implementation to detect new findings.
Fixed findings in file.

Location:
trunk/src/java/org/jcoderz
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/java/org/jcoderz/commons/util/FileUtils.java

    r1286 r1331  
    448448    * 
    449449    * @param dir the directory to be created. 
    450     * @throws IOException the directory could not be created. 
     450    * @throws IOException if the file could not be created. 
    451451    * @see File#mkdir() 
    452452    */ 
     
    462462      } 
    463463   } 
     464 
     465   /** 
     466    * Creates the given file. 
     467    * @param newFile the file to create 
     468    * @throws IOException the file could not be created. 
     469    * @see File#createNewFile() 
     470    */ 
     471    public static void createNewFile (File newFile)  
     472        throws IOException 
     473    { 
     474        if (!newFile.createNewFile()) 
     475        { 
     476            throw new IOException("Failed to create new File " + newFile); 
     477        } 
     478    } 
    464479} 
  • trunk/src/java/org/jcoderz/phoenix/report/ReportMerger.java

    r1329 r1331  
    4545import javax.xml.bind.JAXBException; 
    4646import javax.xml.bind.Marshaller; 
     47import javax.xml.bind.PropertyException; 
    4748import javax.xml.transform.Transformer; 
    4849import javax.xml.transform.TransformerException; 
     
    5657import org.jcoderz.commons.util.IoUtil; 
    5758import org.jcoderz.commons.util.LoggingUtils; 
    58 import org.jcoderz.commons.util.ObjectUtil; 
    59 import org.jcoderz.commons.util.StringUtil; 
    6059import org.jcoderz.phoenix.report.jaxb.Item; 
    6160import org.jcoderz.phoenix.report.jaxb.ObjectFactory; 
     
    8180 
    8281   /** The out file. */ 
    83    private File mOutFile; 
     82   private File mOutFile = null; 
    8483 
    8584   /** The reports. */ 
     
    102101   { 
    103102     logger.log(Level.FINE, "Merging jcoderz-report.xml files..."); 
    104      // prepare JAXB 
    105      final JAXBContext mJaxbContext 
    106          = JAXBContext.newInstance("org.jcoderz.phoenix.report.jaxb", 
    107            this.getClass().getClassLoader()); 
    108      final Marshaller mMarshaller = mJaxbContext.createMarshaller(); 
    109      mMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
    110              Boolean.TRUE); 
    111  
    112103     // merge the reports 
    113104     final Report mergedReport = new ObjectFactory().createReport(); 
     
    127118        } 
    128119     } 
    129      // create the file 
    130      mMarshaller.marshal(mergedReport, new FileOutputStream(mOutFile)); 
     120     writeResult(mergedReport, mOutFile); 
    131121   } 
    132122 
     
    149139           final File tempOutputFile  
    150140               = new File(mOutFile.getCanonicalPath() + ".tmp"); 
    151            tempOutputFile.createNewFile(); 
     141           FileUtils.createNewFile(tempOutputFile); 
    152142 
    153143           final FileOutputStream out = new FileOutputStream(tempOutputFile); 
     
    169159       logger.log(Level.FINE, "Searching for NEW findings..."); 
    170160       final Report currentReport  
    171            = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOutFile); 
     161           = (Report) new ObjectFactory().createUnmarshaller().unmarshal( 
     162               mOutFile); 
    172163       final Report oldReport  
    173            = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOldReport); 
     164           = (Report) new ObjectFactory().createUnmarshaller().unmarshal( 
     165               mOldReport); 
    174166       for(org.jcoderz.phoenix.report.jaxb.File newFile :  
    175167           (List<org.jcoderz.phoenix.report.jaxb.File>) currentReport.getFile()) 
     
    188180       } 
    189181        
    190        final FileOutputStream out = new FileOutputStream(mOutFile); 
    191        try 
    192        { 
    193            new ObjectFactory().createMarshaller().marshal(currentReport, out); 
    194        } 
    195        finally 
    196        { 
    197            IoUtil.close(out); 
    198        } 
     182       writeResult(currentReport, mOutFile); 
    199183   } 
    200184 
     
    418402        if (mOutFile.isDirectory()) 
    419403        { 
    420             mOutFile.mkdirs(); 
     404            FileUtils.mkdirs(mOutFile); 
    421405            mOutFile = new File(mOutFile, 
    422406                ReportNormalizer.JCODERZ_REPORT_XML).getCanonicalFile(); 
     
    428412 
    429413    } 
     414 
     415    private void writeResult (final Report mergedReport, File outFile) 
     416        throws JAXBException, PropertyException, FileNotFoundException 
     417    { 
     418        // create the file 
     419         final JAXBContext mJaxbContext 
     420             = JAXBContext.newInstance("org.jcoderz.phoenix.report.jaxb", 
     421           this.getClass().getClassLoader()); 
     422         final Marshaller marshaller = mJaxbContext.createMarshaller(); 
     423         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, 
     424                 Boolean.TRUE); 
     425         final FileOutputStream out = new FileOutputStream(outFile); 
     426         try 
     427         { 
     428             marshaller.marshal(mergedReport, out); 
     429         } 
     430         finally 
     431         { 
     432             IoUtil.close(out); 
     433         } 
     434    } 
     435     
     436 
    430437}