1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.PrintStream ; 28 import java.util.Collections ; 29 import java.util.HashSet ; 30 import java.util.Iterator ; 31 import java.util.Properties ; 32 import java.util.Set ; 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.Project; 35 import org.netbeans.junit.NbTestCase; 36 37 41 public class FixTestDependenciesTest extends NbTestCase { 42 43 public FixTestDependenciesTest(String testName) { 44 super(testName); 45 } 46 47 public void testSimple() throws IOException , Exception { 48 File prjFile = copyFile("FixTestDependenciesProject.xml"); 49 File propertiesFile = copyFile("FixTestDependencies.properties"); 50 doFixProjectXml(propertiesFile, prjFile); 51 doFixProjectXml(propertiesFile, copyFile("FixTestDependenciesProject2.xml")); 52 } 53 54 public void testStandalone() throws IOException , Exception { 55 File prjFile = copyFile("FixTestDependenciesProjectStandalone.xml"); 56 File propertiesFile = copyFile("FixTestDependencies.properties"); 57 FixTestDependencies ftd = newFixTestDependencies(); 58 ftd.setPropertiesFile(propertiesFile); 59 ftd.setProjectXml(prjFile); 60 ftd.cachedEntries = getEntries(); 61 ftd.execute(); 62 assertFile(copyFile("FixTestDependenciesProjectStandalonePass.xml"),prjFile); 63 assertFile(copyFile("FixTestDependenciesPass.properties"),propertiesFile); 64 } 65 66 public void testWrongBuilClassDep() throws IOException { 67 FixTestDependencies ftd = newFixTestDependencies(); 68 Set cnb = new HashSet (); 69 Set testCnb = new HashSet (); 70 71 Properties props = new Properties (); 72 String PNAME = "cp.extra"; 73 String PVALUE = "../build/test/unit/classes"; 74 props.setProperty(PNAME,PVALUE); 75 ftd.readCodeNameBases(cnb,testCnb,props,"cp.extra",Collections.EMPTY_SET,Collections.EMPTY_SET); 76 assertEquals("No dependency on module.",0,cnb.size()); 77 assertEquals("No test dependency on module.",0,testCnb.size()); 78 assertEquals("property value",PVALUE,props.getProperty(PNAME)); 79 } 80 81 private FixTestDependencies newFixTestDependencies() throws IOException , BuildException { 82 Project project = new Project(); 83 project.setBaseDir(getWorkDir()); 84 FixTestDependencies ftd = new FixTestDependencies(); 85 ftd.setProject(project); 86 return ftd; 87 } 88 private void doFixProjectXml(final File propertiesFile, final File prjFile) throws Exception , IOException { 89 FixTestDependencies ftd = newFixTestDependencies(); 90 ftd.setPropertiesFile(propertiesFile); 91 ftd.setProjectXml(prjFile); 92 ftd.cachedEntries = getEntries(); 93 ftd.execute(); 94 assertFile(copyFile("FixTestDependenciesProjectPass.xml"),prjFile); 95 assertFile(copyFile("FixTestDependenciesPass.properties"),propertiesFile); 96 } 97 98 private File copyFile(String resourceName) throws IOException { 99 InputStream is = getClass().getResourceAsStream(resourceName); 100 byte buf[] = new byte[10000]; 101 File retFile = new File (getWorkDir(),resourceName); 102 FileOutputStream fos = new FileOutputStream (retFile); 103 int size; 104 while ((size = is.read(buf)) > 0 ) { 105 fos.write(buf,0,size); 106 } 107 is.close(); 108 fos.close(); 109 return retFile; 110 } 111 112 115 private void logEntries(HashSet cachedCNB, Set entries) throws FileNotFoundException , IOException { 116 FileOutputStream fos = new FileOutputStream ("/tmp/test",true); 117 try { 118 PrintStream ps = new PrintStream (fos); 119 ps.println("Set getEntris() {"); 120 ps.println(" Set entries = new HashSet();"); 121 for (Iterator it = cachedCNB.iterator(); it.hasNext();) { 122 String cnb = (String ) it.next(); 123 for (Iterator eIt = entries.iterator() ; eIt.hasNext() ;) { 124 ModuleListParser.Entry entry = (ModuleListParser.Entry) eIt.next(); 125 if (!cnb.equals(entry.getCnb())) { 126 continue; 127 } 128 ps.println("entries.add(new ModuleListParser.Entry(\"" + entry.getCnb() + "\"," + 129 getLogFileName(entry.getJar()) + ","); 130 File files[] = entry.getClassPathExtensions(); 131 if (files.length == 0) { 132 ps.print(" new File[0],"); 133 } else { 134 ps.print(" new File[]{"); 135 for (int ce = 0 ; ce < files.length ; ce++) { 136 if (ce != 0) { 137 ps.print(","); 138 } 139 ps.print(getLogFileName(files[ce])); 140 } 141 ps.println("},"); 142 } 143 ps.println(" null,\"" + entry.getNetbeansOrgPath() + "\","); 144 145 146 String bp[] = entry.getBuildPrerequisites(); 147 if (bp.length == 0) { 148 ps.println(" new String[0],"); 149 } else { 150 ps.print(" new String[]{"); 151 for (int ce = 0 ; ce < bp.length ; ce++) { 152 if (ce != 0) { 153 ps.print(","); 154 } 155 ps.print("\"" + bp[ce] + "\""); 156 } 157 ps.println("},"); 158 } 159 ps.println(" \"" + entry.getClusterName() + "\","); 160 bp = entry.getRuntimeDependencies(); 161 if (bp.length == 0) { 162 ps.print(" new String[0]"); 163 } else { 164 ps.print(" new String[]{"); 165 for (int ce = 0 ; ce < bp.length ; ce++) { 166 if (ce != 0) { 167 ps.print(","); 168 } 169 ps.print("\"" + bp[ce] + "\""); 170 } 171 ps.print("}"); 172 } 173 ps.println("));"); 174 } 175 } 176 ps.println("}"); 177 } finally { 178 fos.close(); 179 } 180 } 181 182 private String getLogFileName(File file) { 183 String path = file.getAbsolutePath(); 184 String NB = "/netbeans/"; 185 int idx = path.indexOf(NB); 186 String name = (idx == -1) ? "nonsence:" + file.getPath() : path.substring(idx + NB.length()); 187 return "new File(\"" + name + "\")"; 188 189 } 190 191 private Set getEntries() { 192 Set entries = new HashSet (); 193 entries.add(new ModuleListParser.Entry("org.openide.io",new File ("extra/modules/org-openide-io.jar"), 194 new File [0], null,"openide/io", 195 new String []{"org.openide.util"}, 196 "extra", 197 new String []{"org.openide.util"})); 198 entries.add(new ModuleListParser.Entry("org.openide.compat",new File ("extra/modules/org-openide-compat.jar"), 199 new File [0], null,"openide/compat", 200 new String []{"org.netbeans.core","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.nodes","org.openide.options","org.openide.text","org.openide.util","org.openide.windows"}, 201 "extra", 202 new String []{"org.netbeans.core","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.nodes","org.openide.options","org.openide.text","org.openide.util","org.openide.windows"})); 203 entries.add(new ModuleListParser.Entry("org.netbeans.modules.projectapi",new File ("extra/modules/org-netbeans-modules-projectapi.jar"), 204 new File [0], null,"projects/projectapi", 205 new String []{"org.netbeans.modules.queries","org.openide.filesystems","org.openide.util"}, 206 "extra", 207 new String []{"org.netbeans.modules.queries","org.openide.filesystems","org.openide.util"})); 208 entries.add(new ModuleListParser.Entry("org.openide.loaders",new File ("extra/modules/org-openide-loaders.jar"), 209 new File [0], null,"openide/loaders", 210 new String []{"org.netbeans.api.progress","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.modules","org.openide.nodes","org.openide.text","org.openide.util","org.openide.windows"}, 211 "extra", 212 new String []{"org.netbeans.api.progress","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.modules","org.openide.nodes","org.openide.text","org.openide.util","org.openide.windows"})); 213 entries.add(new ModuleListParser.Entry("org.netbeans.core",new File ("extra/modules/org-netbeans-core.jar"), 214 new File [0], null,"core", 215 new String []{"org.netbeans.bootstrap","org.netbeans.core.startup","org.netbeans.swing.plaf","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.loaders","org.openide.modules","org.openide.nodes","org.openide.options","org.openide.text","org.openide.util","org.openide.windows"}, 216 "extra", 217 new String []{"org.netbeans.bootstrap","org.netbeans.core.startup","org.netbeans.swing.plaf","org.openide.actions","org.openide.awt","org.openide.dialogs","org.openide.explorer","org.openide.filesystems","org.openide.loaders","org.openide.modules","org.openide.nodes","org.openide.options","org.openide.text","org.openide.util","org.openide.windows"})); 218 entries.add(new ModuleListParser.Entry("org.netbeans.modules.masterfs",new File ("extra/modules/org-netbeans-modules-masterfs.jar"), 219 new File [0], null,"openide/masterfs", 220 new String []{"org.openide.filesystems","org.openide.util","org.openide.options","org.netbeans.modules.queries"}, 221 "extra", 222 new String []{"org.openide.filesystems","org.openide.util","org.openide.options","org.netbeans.modules.queries"})); 223 entries.add(new ModuleListParser.Entry("org.netbeans.bootstrap",new File ("extra/lib/boot.jar"), 224 new File [0], null,"core/bootstrap", 225 new String []{"org.openide.modules","org.openide.util"}, 226 "extra", 227 new String []{"org.openide.modules","org.openide.util"})); 228 entries.add(new ModuleListParser.Entry("org.netbeans.libs.xerces",new File ("extra/modules/org-netbeans-libs-xerces.jar"), 229 new File []{new File ("nonsence:/home/pzajac/cvss/freshtrunk/libs/external/xerces-2.8.0.jar"),new File ("nonsence:/home/pzajac/cvss/freshtrunk/libs/external/xml-commons-dom-ranges-1.0.b2.jar")}, 230 null,"libs/xerces", 231 new String [0], 232 "extra", 233 new String [0])); 234 entries.add(new ModuleListParser.Entry("org.netbeans.api.progress",new File ("extra/modules/org-netbeans-api-progress.jar"), 235 new File [0], null,"core/progress", 236 new String []{"org.openide.util","org.openide.awt"}, 237 "extra", 238 new String []{"org.openide.util","org.openide.awt"})); 239 entries.add(new ModuleListParser.Entry("org.openide.options",new File ("extra/modules/org-openide-options.jar"), 240 new File [0], null,"openide/options", 241 new String []{"org.openide.util"}, 242 "extra", 243 new String []{"org.openide.util"})); 244 entries.add(new ModuleListParser.Entry("org.openide.explorer",new File ("extra/modules/org-openide-explorer.jar"), 245 new File [0], null,"openide/explorer", 246 new String []{"org.openide.util","org.openide.nodes","org.openide.awt","org.openide.dialogs","org.openide.options"}, 247 "extra", 248 new String []{"org.openide.util","org.openide.nodes","org.openide.awt","org.openide.dialogs","org.openide.options"})); 249 entries.add(new ModuleListParser.Entry("org.openide.dialogs",new File ("extra/modules/org-openide-dialogs.jar"), 250 new File [0], null,"openide/dialogs", 251 new String []{"org.netbeans.api.progress","org.openide.awt","org.openide.util"}, 252 "extra", 253 new String []{"org.netbeans.api.progress","org.openide.awt","org.openide.util"})); 254 entries.add(new ModuleListParser.Entry("org.openide.nodes",new File ("extra/modules/org-openide-nodes.jar"), 255 new File [0], null,"openide/nodes", 256 new String []{"org.openide.util","org.openide.awt","org.openide.dialogs"}, 257 "extra", 258 new String []{"org.openide.util","org.openide.awt","org.openide.dialogs"})); 259 entries.add(new ModuleListParser.Entry("org.openide.awt",new File ("extra/modules/org-openide-awt.jar"), 260 new File [0], null,"openide/awt", 261 new String []{"org.openide.util"}, 262 "extra", 263 new String []{"org.openide.util"})); 264 entries.add(new ModuleListParser.Entry("org.openide.text",new File ("extra/modules/org-openide-text.jar"), 265 new File [0], null,"openide/text", 266 new String []{"org.netbeans.modules.editor.mimelookup","org.openide.awt","org.openide.dialogs","org.openide.nodes","org.openide.options","org.openide.util","org.openide.windows"}, 267 "extra", 268 new String []{"org.netbeans.modules.editor.mimelookup","org.openide.awt","org.openide.dialogs","org.openide.nodes","org.openide.options","org.openide.util","org.openide.windows"})); 269 entries.add(new ModuleListParser.Entry("org.openide.actions",new File ("extra/modules/org-openide-actions.jar"), 270 new File [0], null,"openide/actions", 271 new String []{"org.openide.util","org.openide.nodes","org.openide.awt","org.openide.options","org.openide.text","org.openide.explorer","org.openide.dialogs","org.openide.windows"}, 272 "extra", 273 new String []{"org.openide.util","org.openide.nodes","org.openide.awt","org.openide.options","org.openide.text","org.openide.explorer","org.openide.dialogs","org.openide.windows"})); 274 entries.add(new ModuleListParser.Entry("org.openide.util",new File ("extra/lib/org-openide-util.jar"), 275 new File [0], null,"openide/util", 276 new String [0], 277 "extra", 278 new String [0])); 279 entries.add(new ModuleListParser.Entry("org.netbeans.core.startup",new File ("extra/core/core.jar"), 280 new File [0], null,"core/startup", 281 new String []{"org.netbeans.bootstrap","org.openide.filesystems","org.openide.modules","org.openide.util"}, 282 "extra", 283 new String []{"org.netbeans.bootstrap","org.openide.filesystems","org.openide.modules","org.openide.util"})); 284 entries.add(new ModuleListParser.Entry("org.openide.modules",new File ("extra/lib/org-openide-modules.jar"), 285 new File [0], null,"openide/modules", 286 new String []{"org.openide.util"}, 287 "extra", 288 new String []{"org.openide.util"})); 289 entries.add(new ModuleListParser.Entry("org.openide.filesystems",new File ("extra/core/org-openide-filesystems.jar"), 290 new File [0], null,"openide/fs", 291 new String []{"org.openide.util"}, 292 "extra", 293 new String []{"org.openide.util"})); 294 return entries; 295 } 296 } 297 | Popular Tags |