001 /* 002 * Cobertura - http://cobertura.sourceforge.net/ 003 * 004 * Copyright (C) 2003 jcoverage ltd. 005 * Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net> 006 * 007 * Cobertura is free software; you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published 009 * by the Free Software Foundation; either version 2 of the License, 010 * or (at your option) any later version. 011 * 012 * Cobertura is distributed in the hope that it will be useful, but 013 * WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Cobertura; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 020 * USA 021 */ 022 023 package net.sourceforge.cobertura.reporting.html.files; 024 025 import java.io.File; 026 import java.io.FileOutputStream; 027 import java.io.IOException; 028 import java.io.InputStream; 029 030 public abstract class CopyFiles 031 { 032 033 public static void copy(File outputDir) throws IOException 034 { 035 File cssOutputDir = new File(outputDir, "css"); 036 File imagesOutputDir = new File(outputDir, "images"); 037 File jsOutputDir = new File(outputDir, "js"); 038 039 outputDir.mkdirs(); 040 cssOutputDir.mkdir(); 041 imagesOutputDir.mkdir(); 042 jsOutputDir.mkdir(); 043 044 copyResourceFromJar("help.css", cssOutputDir); 045 copyResourceFromJar("main.css", cssOutputDir); 046 copyResourceFromJar("sortabletable.css", cssOutputDir); 047 copyResourceFromJar("source-viewer.css", cssOutputDir); 048 copyResourceFromJar("tooltip.css", cssOutputDir); 049 050 copyResourceFromJar("blank.png", imagesOutputDir); 051 copyResourceFromJar("downsimple.png", imagesOutputDir); 052 copyResourceFromJar("upsimple.png", imagesOutputDir); 053 054 //copyResourceFromJar("numberksorttype.js", jsOutputDir); 055 copyResourceFromJar("percentagesorttype.js", jsOutputDir); 056 copyResourceFromJar("popup.js", jsOutputDir); 057 copyResourceFromJar("sortabletable.js", jsOutputDir); 058 copyResourceFromJar("stringbuilder.js", jsOutputDir); 059 //copyResourceFromJar("uscurrencysorttype.js", jsOutputDir); 060 061 copyResourceFromJar("help.html", outputDir); 062 copyResourceFromJar("index.html", outputDir); 063 } 064 065 /** 066 * Copy a file from the jar to a directory on the local machine. 067 * 068 * @param resourceName The name of the file in the jar. This file 069 * must exist the same package as this method. 070 * @param directory The directory to copy the jar to. 071 * @throws IOException If the file could not be read from the 072 * jar or written to the disk. 073 */ 074 private static void copyResourceFromJar(String resourceName, 075 File directory) throws IOException 076 { 077 int n; 078 byte[] buf = new byte[1024]; 079 080 InputStream in = null; 081 FileOutputStream out = null; 082 directory.mkdirs(); 083 try 084 { 085 in = CopyFiles.class.getResourceAsStream(resourceName); 086 if (in == null) 087 throw new IllegalArgumentException("Resource " + resourceName 088 + " does not exist in this package."); 089 out = new FileOutputStream(new File(directory, resourceName)); 090 while ((n = in.read(buf, 0, buf.length)) != -1) 091 { 092 out.write(buf, 0, n); 093 } 094 } 095 finally 096 { 097 if (in != null) 098 { 099 in.close(); 100 } 101 if (out != null) 102 { 103 out.close(); 104 } 105 } 106 } 107 108 }