View Javadoc
1 /* 2 Bloof - visualize the evolution of your software project 3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de> 4 http://bloof.sf.net/ 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 $RCSfile: DepsDownloader.java,v $ 19 Created on $Date: 2003/06/28 06:51:42 $ 20 */ 21 package net.sf.bloof.util; 22 23 import java.io.File; 24 import java.io.IOException; 25 import java.net.MalformedURLException; 26 import java.net.URL; 27 28 /*** 29 * Downloads bloof dependencies from bloof website 30 * As the binary distribution does not include external jars, 31 * this class gets them before bloof is started. 32 * It is invoked by the bloof shell script only if any 33 * dependency is not meet yet. 34 * @author Lukasz Pekacki <pekacki@users.sourceforge.net> 35 * @version $Id: DepsDownloader.java,v 1.6 2003/06/28 06:51:42 pekacki Exp $ 36 */ 37 public class DepsDownloader implements FileDownloadListener { 38 /*** 39 * Main method, starts the downloader program. 40 * @param aArgs list of URLs to be downloaded into the lib directory 41 */ 42 public static void main(String[] aArgs) { 43 DepsDownloader dd = new DepsDownloader(); 44 println("Need to download external jars."); 45 File libTempDir = new File(LIB_TEMP_DIR); 46 File libDir = new File(LIB_DIR); 47 if (!libTempDir.exists()) { 48 println("Creating directory " + libTempDir); 49 libTempDir.mkdir(); 50 } 51 File file = null; 52 URL url = null; 53 for (int i = 0; i < aArgs.length; i++) { 54 try { 55 url = new URL(aArgs[i]); 56 int lastDashIndex = aArgs[i].lastIndexOf('/'); 57 file = new File(libTempDir, aArgs[i].substring(lastDashIndex)); 58 if (file.exists()) { 59 System.err.println("File " + file + " already exists. Skipping this file"); 60 continue; 61 } 62 FileDownload fDown = new FileDownload(url, file); 63 fDown.addDownloadListener(dd); 64 fDown.startDownload(); 65 } catch (MalformedURLException e) { 66 System.err.println(aArgs[i] + " is not a valid URL"); 67 } catch (IOException ioex) { 68 System.err.println( 69 "Could not download and save file " + file + " from " + url + "."); 70 sAllFinished = false; 71 } 72 73 } 74 if (sAllFinished) { 75 println("Finished downloading."); 76 libTempDir.renameTo(libDir); 77 } else { 78 println("Could not download and save all dependencies. Try again."); 79 } 80 81 } 82 private static void println(String aS) { 83 System.out.print(aS); 84 System.out.print("\n"); 85 } 86 /*** 87 * @see net.sf.bloof.util.FileDownloadListener#downloadEventOccured( DownloadEvent ) 88 */ 89 public void downloadEventOccured(DownloadEvent aE) { 90 switch (aE.getType()) { 91 case DownloadEvent.START : 92 { 93 sAlreadyDownloaded = 0; 94 sCurrentDiff = 0; 95 println( 96 "Getting " 97 + aE.getFileName() 98 + " (" 99 + aE.getTotalSize()/1024 100 + " kb) from " 101 + aE.getSource()); 102 System.out.print(" ["); 103 break; 104 } 105 case DownloadEvent.RUNNING : 106 { 107 sAlreadyDownloaded += aE.getAlreadyDownloaded(); 108 sCurrentDiff += aE.getAlreadyDownloaded(); 109 int chunk = (aE.getTotalSize() / (PRORGRESS_LENGTH)); 110 if (sCurrentDiff >= chunk) { 111 int times = sCurrentDiff / chunk; 112 int rest = sCurrentDiff % chunk; 113 for (int i = 0; i < times; i++) { 114 System.out.print(":"); 115 } 116 sCurrentDiff = rest; 117 } 118 break; 119 } 120 case DownloadEvent.END : 121 { 122 if (sCurrentDiff > (aE.getTotalSize() / (PRORGRESS_LENGTH))) { 123 System.out.print(":"); 124 } 125 sCurrentDiff = 0; 126 System.out.print("] 100%"); 127 println(""); 128 break; 129 } 130 } 131 } 132 private static final String LIB_DIR = System.getProperty("user.dir") + "/lib"; 133 private static final String LIB_TEMP_DIR = System.getProperty("user.dir") + "/lib_tmp"; 134 private static final int PRORGRESS_LENGTH = 30; 135 private static boolean sAllFinished = true; 136 private static int sAlreadyDownloaded = 0; 137 private static int sCurrentDiff = 0; 138 }

This page was automatically generated by Maven