1 19 20 package org.netbeans.modules.projectimport.eclipse; 21 22 import java.io.BufferedInputStream ; 23 import java.io.BufferedOutputStream ; 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.zip.ZipEntry ; 31 import java.util.zip.ZipInputStream ; 32 import org.netbeans.junit.NbTestCase; 33 34 39 public class ProjectImporterTestCase extends NbTestCase { 40 41 private static final int BUFFER = 2048; 42 43 47 private static boolean verbose; 48 49 50 public ProjectImporterTestCase(String name) { 51 super(name); 52 } 53 54 protected void setUp() throws Exception { 55 super.setUp(); 56 57 clearWorkDir(); 59 } 60 61 protected void tearDown() throws Exception { 62 super.tearDown(); 63 clearWorkDir(); 64 } 65 66 protected void setVerbose(boolean verbose) { 67 ProjectImporterTestCase.verbose = verbose; 68 } 69 70 74 protected File extractToWorkDir(String archiveFile) throws IOException { 75 ZipInputStream zis = null; 76 BufferedOutputStream dest = null; 77 try { 78 FileInputStream fis = new FileInputStream (new File (getDataDir(), archiveFile)); 79 zis = new ZipInputStream (new BufferedInputStream (fis)); 80 ZipEntry entry; 81 while((entry = zis.getNextEntry()) != null) { 82 byte data[] = new byte[BUFFER]; 83 File entryFile = new File (getWorkDir(), entry.getName()); 84 if (entry.isDirectory()) { 85 entryFile.mkdirs(); 86 } else { 87 FileOutputStream fos = new FileOutputStream (entryFile); 88 dest = new BufferedOutputStream (fos, BUFFER); 89 int count; 90 while ((count = zis.read(data, 0, BUFFER)) != -1) { 91 dest.write(data, 0, count); 92 } 93 dest.flush(); 94 } 95 } 96 } finally { 97 if (zis != null) { zis.close(); } 98 if (dest != null) { dest.close(); } 99 } 100 return new File (getWorkDir(), archiveFile.substring(0, archiveFile.length() - 4)); 102 } 103 104 protected static void printMessage(String message, boolean newLine) { 105 if (verbose) { 106 if (newLine) { 107 System.out.println(message); 108 } else { 109 System.out.print(message); 110 } 111 } 112 } 113 114 protected static void printMessage(String message) { 115 printMessage(message, true); 116 } 117 118 protected static void printCollection(String name, Collection col) { 119 if (col != null && !col.isEmpty()) { 120 printMessage(" " + name + ":"); 121 for (Iterator it = col.iterator(); it.hasNext(); ) { 122 ClassPathEntry entry = (ClassPathEntry) it.next(); 123 printMessage(" \"" + entry.getRawPath() + "\" ", false); 124 if (entry.getAbsolutePath() != null) { 125 printMessage("converted to \"" + entry.getAbsolutePath() + "\""); 126 } else { 127 printMessage("cannot be resolved !!!!"); 128 } 129 } 130 } 131 } 132 } 133 | Popular Tags |