Changeset 1331
- Timestamp:
- 03/28/09 20:29:42 (3 years ago)
- Location:
- trunk/src/java/org/jcoderz
- Files:
-
- 2 modified
-
commons/util/FileUtils.java (modified) (2 diffs)
-
phoenix/report/ReportMerger.java (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/java/org/jcoderz/commons/util/FileUtils.java
r1286 r1331 448 448 * 449 449 * @param dir the directory to be created. 450 * @throws IOException the directorycould not be created.450 * @throws IOException if the file could not be created. 451 451 * @see File#mkdir() 452 452 */ … … 462 462 } 463 463 } 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 } 464 479 } -
trunk/src/java/org/jcoderz/phoenix/report/ReportMerger.java
r1329 r1331 45 45 import javax.xml.bind.JAXBException; 46 46 import javax.xml.bind.Marshaller; 47 import javax.xml.bind.PropertyException; 47 48 import javax.xml.transform.Transformer; 48 49 import javax.xml.transform.TransformerException; … … 56 57 import org.jcoderz.commons.util.IoUtil; 57 58 import org.jcoderz.commons.util.LoggingUtils; 58 import org.jcoderz.commons.util.ObjectUtil;59 import org.jcoderz.commons.util.StringUtil;60 59 import org.jcoderz.phoenix.report.jaxb.Item; 61 60 import org.jcoderz.phoenix.report.jaxb.ObjectFactory; … … 81 80 82 81 /** The out file. */ 83 private File mOutFile ;82 private File mOutFile = null; 84 83 85 84 /** The reports. */ … … 102 101 { 103 102 logger.log(Level.FINE, "Merging jcoderz-report.xml files..."); 104 // prepare JAXB105 final JAXBContext mJaxbContext106 = 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 112 103 // merge the reports 113 104 final Report mergedReport = new ObjectFactory().createReport(); … … 127 118 } 128 119 } 129 // create the file 130 mMarshaller.marshal(mergedReport, new FileOutputStream(mOutFile)); 120 writeResult(mergedReport, mOutFile); 131 121 } 132 122 … … 149 139 final File tempOutputFile 150 140 = new File(mOutFile.getCanonicalPath() + ".tmp"); 151 tempOutputFile.createNewFile();141 FileUtils.createNewFile(tempOutputFile); 152 142 153 143 final FileOutputStream out = new FileOutputStream(tempOutputFile); … … 169 159 logger.log(Level.FINE, "Searching for NEW findings..."); 170 160 final Report currentReport 171 = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOutFile); 161 = (Report) new ObjectFactory().createUnmarshaller().unmarshal( 162 mOutFile); 172 163 final Report oldReport 173 = (Report) new ObjectFactory().createUnmarshaller().unmarshal(mOldReport); 164 = (Report) new ObjectFactory().createUnmarshaller().unmarshal( 165 mOldReport); 174 166 for(org.jcoderz.phoenix.report.jaxb.File newFile : 175 167 (List<org.jcoderz.phoenix.report.jaxb.File>) currentReport.getFile()) … … 188 180 } 189 181 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); 199 183 } 200 184 … … 418 402 if (mOutFile.isDirectory()) 419 403 { 420 mOutFile.mkdirs();404 FileUtils.mkdirs(mOutFile); 421 405 mOutFile = new File(mOutFile, 422 406 ReportNormalizer.JCODERZ_REPORT_XML).getCanonicalFile(); … … 428 412 429 413 } 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 430 437 }
