1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.OutputStream ; 25 import java.net.URL ; 26 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.Collections ; 29 import java.util.HashSet ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Properties ; 33 import java.util.Set ; 34 import java.util.TreeSet ; 35 import org.netbeans.api.java.classpath.ClassPath; 36 import org.netbeans.api.project.FileOwnerQuery; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.api.project.ProjectManager; 39 import org.netbeans.modules.apisupport.project.NbModuleProject; 40 import org.netbeans.modules.apisupport.project.NbModuleProjectType; 41 import org.netbeans.modules.apisupport.project.ProjectXMLManager; 42 import org.netbeans.modules.apisupport.project.TestBase; 43 import org.netbeans.modules.apisupport.project.Util; 44 import org.netbeans.modules.apisupport.project.suite.SuiteProjectTest; 45 import org.netbeans.modules.apisupport.project.ui.customizer.ModuleDependency; 46 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 47 import org.netbeans.spi.project.support.ant.AntProjectHelper; 48 import org.netbeans.spi.project.support.ant.EditableProperties; 49 import org.netbeans.spi.project.support.ant.PropertyUtils; 50 import org.openide.filesystems.FileObject; 51 import org.openide.filesystems.FileUtil; 52 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 53 import org.openide.xml.XMLUtil; 54 import org.w3c.dom.Document ; 55 import org.w3c.dom.Element ; 56 import org.w3c.dom.NodeList ; 57 import org.xml.sax.InputSource ; 58 59 61 65 public class ClassPathProviderImplTest extends TestBase { 66 67 public ClassPathProviderImplTest(String name) { 68 super(name); 69 } 70 71 private File copyOfSuite2; 72 private FileObject copyOfMiscDir; 73 private NbModuleProject copyOfMiscProject; 74 private ProjectXMLManager copyOfMiscXMLManager; 75 76 protected void setUp() throws Exception { 77 super.setUp(); 78 copyOfSuite2 = copyFolder(resolveEEPFile("/suite2")); 79 File miscF = new File (copyOfSuite2, "misc-project"); 80 copyOfMiscDir = FileUtil.toFileObject(miscF); 81 copyOfMiscProject = (NbModuleProject) ProjectManager.getDefault().findProject(copyOfMiscDir); 82 assertNotNull(copyOfMiscProject); 83 copyOfMiscXMLManager = new ProjectXMLManager(copyOfMiscProject); 84 Project copyOfSuite2P = ProjectManager.getDefault().findProject(FileUtil.toFileObject(copyOfSuite2)); 86 SuiteProjectTest.openSuite(copyOfSuite2P); 87 } 88 89 private String urlForJar(String path) { 90 return Util.urlForJar(PropertyUtils.resolveFile(nbCVSRootFile(), path)).toExternalForm(); 91 } 92 93 private String urlForDir(String path) { 94 return Util.urlForDir(file(path)).toExternalForm(); 95 } 96 97 private Set urlsOfCp(ClassPath cp) { 98 Set s = new TreeSet (); 99 Iterator it = cp.entries().iterator(); 100 while (it.hasNext()) { 101 s.add(((ClassPath.Entry) it.next()).getURL().toExternalForm()); 102 } 103 return s; 104 } 105 106 private static final Set TESTLIBS = new HashSet (Arrays.asList(new String [] { 107 "junit.jar", "nbjunit.jar", "nbjunit-ide.jar", "insanelib.jar", 108 "org-netbeans-modules-nbjunit.jar", 109 "org-netbeans-modules-nbjunit-ide.jar", 110 })); 111 112 private void assertSets(String message,Set set1, Set set2 ) { 113 StringBuffer result = new StringBuffer (); 114 boolean pass = true; 115 for (Iterator it = set1.iterator() ; it.hasNext() ; ) { 116 Object obj = it.next(); 117 if (!set2.contains(obj)) { 118 pass = false; 119 result.append("- " + obj + "\n"); 120 } 121 } 122 for (Iterator it = set2.iterator() ; it.hasNext() ; ) { 123 Object obj = it.next(); 124 if (!set1.contains(obj)) { 125 pass = false; 126 result.append("+ " + obj + "\n"); 127 } 128 } 129 assertTrue(message + "\n" + result,pass); 130 } 131 132 private Set urlsOfCp4Tests(ClassPath cp) { 133 Set s = new TreeSet (); 134 Iterator it = cp.entries().iterator(); 135 while (it.hasNext()) { 136 String url = ((ClassPath.Entry) it.next()).getURL().toExternalForm(); 137 if (url.indexOf("$%7B") != -1) { 138 continue; 140 } 141 String simplifiedJarName = url.replaceFirst("^.+/([^/]+?)[0-9_.-]*\\.jar!/$", "$1.jar"); 142 if (TESTLIBS.contains(simplifiedJarName)) { 143 s.add(simplifiedJarName); 144 } else { 145 s.add(url); 146 } 147 } 148 return s; 149 } 150 151 public void testMainClasspath() throws Exception { 152 FileObject src = nbCVSRoot().getFileObject("ant/src"); 153 assertNotNull("have ant/src", src); 154 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 155 assertNotNull("have a COMPILE classpath", cp); 156 Set expectedRoots = new TreeSet (); 157 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-api-xml.jar")); 160 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar")); 161 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 162 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-modules.jar")); 163 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 164 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-awt.jar")); 165 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 166 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 167 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-text.jar")); 168 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-actions.jar")); 169 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-execution.jar")); 170 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); 171 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); 172 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-explorer.jar")); 173 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-spi-navigator.jar")); 174 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-jdesktop-layout.jar")); 175 expectedRoots.add(urlForJar("libs/external/swing-layout-1.0.1.jar")); 176 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-options-api.jar")); 177 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-api-progress.jar")); 178 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-projectapi.jar")); 179 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-projectuiapi.jar")); 180 assertEquals("right COMPILE classpath for ant/src", expectedRoots.toString(), urlsOfCp(cp).toString()); 181 cp = ClassPath.getClassPath(src, ClassPath.EXECUTE); 182 assertNotNull("have an EXECUTE classpath", cp); 183 expectedRoots.add(urlForDir("ant/build/classes")); 185 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-queries.jar")); 187 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-editor-mimelookup.jar")); 188 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-options.jar")); 189 assertEquals("right EXECUTE classpath (COMPILE plus classes)", expectedRoots.toString(), urlsOfCp(cp).toString()); 190 cp = ClassPath.getClassPath(src, ClassPath.SOURCE); 191 assertNotNull("have a SOURCE classpath", cp); 192 assertEquals("right SOURCE classpath", Collections.singleton(src), new HashSet (Arrays.asList(cp.getRoots()))); 193 } 195 196 public void testMainClasspathExternalModules() throws Exception { 197 FileObject src = resolveEEP("suite3/dummy-project/src"); 198 assertNotNull("have .../dummy-project/src", src); 199 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 200 assertNotNull("have a COMPILE classpath", cp); 201 Set expectedRoots = new TreeSet (); 202 expectedRoots.add(urlForJar(resolveEEPPath("/suite3/nbplatform/random/modules/random.jar"))); 203 expectedRoots.add(urlForJar(resolveEEPPath("/suite3/nbplatform/random/modules/ext/stuff.jar"))); 204 assertEquals("right COMPILE classpath", expectedRoots, urlsOfCp(cp)); 205 } 206 207 210 public void testClasspathExtensions() throws Exception { 211 FileObject src = nbCVSRoot().getFileObject("java/javacore/src"); 213 assertNotNull("have java/javacore/src", src); 214 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 215 assertNotNull("have a COMPILE classpath", cp); 216 Set expectedRoots = new TreeSet (); 217 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-api-java.jar")); 219 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-classfile.jar")); 220 expectedRoots.add(urlForJar("nbbuild/netbeans/extra/modules/org-netbeans-jmi-javamodel.jar")); 221 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/javax-jmi-reflect.jar")); 222 expectedRoots.add(urlForJar("mdr/external/jmi.jar")); 223 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/javax-jmi-model.jar")); 224 expectedRoots.add(urlForJar("mdr/external/mof.jar")); 225 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-api-mdr.jar")); 226 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-projectapi.jar")); 227 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-api-progress.jar")); 228 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-mdr.jar")); 229 expectedRoots.add(urlForJar("mdr/dist/mdr.jar")); 230 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-jmiutils.jar")); 231 expectedRoots.add(urlForJar("mdr/jmiutils/dist/jmiutils.jar")); 232 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); 233 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar")); 234 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 235 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-modules.jar")); 236 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 237 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-awt.jar")); 238 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 239 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 240 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-text.jar")); 241 expectedRoots.add(urlForJar("java/parser/dist/java-parser.jar")); 242 assertEquals("right COMPILE classpath", expectedRoots.toString(), urlsOfCp(cp).toString()); 243 assertTrue("#76341: EXECUTE classpath also has extension", 244 urlsOfCp(ClassPath.getClassPath(src, ClassPath.EXECUTE)).contains(urlForJar("java/parser/dist/java-parser.jar"))); 245 } 246 247 public void testExtraCompilationUnits() throws Exception { 248 FileObject srcbridge = nbCVSRoot().getFileObject("ant/src-bridge"); 249 assertNotNull("have ant/src-bridge", srcbridge); 250 ClassPath cp = ClassPath.getClassPath(srcbridge, ClassPath.COMPILE); 251 assertNotNull("have a COMPILE classpath", cp); 252 Set expectedRoots = new TreeSet (); 253 expectedRoots.add(urlForDir("ant/build/classes")); 255 expectedRoots.add(urlForJar("ant/external/lib/ant.jar")); 256 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-api-xml.jar")); 258 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar")); 259 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 260 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-modules.jar")); 261 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 262 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-awt.jar")); 263 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 264 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 265 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-text.jar")); 266 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-actions.jar")); 267 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-execution.jar")); 268 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); 269 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); 270 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-explorer.jar")); 271 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-spi-navigator.jar")); 272 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-jdesktop-layout.jar")); 273 expectedRoots.add(urlForJar("libs/external/swing-layout-1.0.1.jar")); 274 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-options-api.jar")); 275 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-api-progress.jar")); 276 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-projectapi.jar")); 277 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-projectuiapi.jar")); 278 assertEquals("right COMPILE classpath for ant/src-bridge", expectedRoots.toString(), urlsOfCp(cp).toString()); 279 cp = ClassPath.getClassPath(srcbridge, ClassPath.EXECUTE); 280 assertNotNull("have an EXECUTE classpath", cp); 281 expectedRoots.add(urlForDir("ant/build/bridge-classes")); 282 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/ant/nblib/bridge.jar")); 283 assertEquals("right EXECUTE classpath (COMPILE plus classes plus JAR)", expectedRoots, urlsOfCp(cp)); 284 cp = ClassPath.getClassPath(srcbridge, ClassPath.SOURCE); 285 assertNotNull("have a SOURCE classpath", cp); 286 assertEquals("right SOURCE classpath", Collections.singleton(srcbridge), new HashSet (Arrays.asList(cp.getRoots()))); 287 } 289 290 public void testUnitTestClasspaths() throws Exception { 291 FileObject src = nbCVSRoot().getFileObject("autoupdate/test/unit/src"); 292 assertNotNull("have autoupdate/test/unit/src", src); 293 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 294 assertNotNull("have a COMPILE classpath", cp); 295 Set expectedRoots = new TreeSet (); 296 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar")); 299 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 300 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-modules.jar")); 301 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/boot.jar")); 302 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 303 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-explorer.jar")); 304 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-awt.jar")); 305 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 306 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-options.jar")); 307 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 308 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-actions.jar")); 309 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); 310 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-core.jar")); 311 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-api-progress.jar")); 312 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/core.jar")); 313 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-editor-mimelookup.jar")); 314 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/ext/updater.jar")); 316 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-autoupdate.jar")); 318 expectedRoots.add("junit.jar"); 319 expectedRoots.add("nbjunit.jar"); 320 expectedRoots.add("nbjunit-ide.jar"); 321 expectedRoots.add("insanelib.jar"); 322 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-swing-plaf.jar")); 324 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-text.jar")); 325 326 assertSets("right COMPILE classpath", expectedRoots, urlsOfCp4Tests(cp)); 327 328 cp = ClassPath.getClassPath(src, ClassPath.EXECUTE); 329 assertNotNull("have an EXECUTE classpath", cp); 330 expectedRoots.add(urlForDir("autoupdate/build/test/unit/classes")); 331 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/boot.jar")); 333 assertSets("right EXECUTE classpath (COMPILE plus classes)", expectedRoots, urlsOfCp4Tests(cp)); 334 cp = ClassPath.getClassPath(src, ClassPath.SOURCE); 335 assertNotNull("have a SOURCE classpath", cp); 336 assertEquals("right SOURCE classpath", Collections.singleton(src), new HashSet (Arrays.asList(cp.getRoots()))); 337 } 339 340 public void testUnitTestClasspathsExternalModules() throws Exception { 341 FileObject src = resolveEEP("suite1/support/lib-project/test/unit/src"); 342 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 343 assertNotNull("have a COMPILE classpath", cp); 344 Set expectedRoots = new TreeSet (); 345 expectedRoots.add(urlForJar(resolveEEPPath("/suite1/build/cluster/modules/org-netbeans-examples-modules-lib.jar"))); 346 expectedRoots.add("junit.jar"); 347 expectedRoots.add("nbjunit.jar"); 348 expectedRoots.add("insanelib.jar"); 349 expectedRoots.add("org-netbeans-modules-nbjunit.jar"); 350 expectedRoots.add("org-netbeans-modules-nbjunit-ide.jar"); 351 assertEquals("right COMPILE classpath", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 352 src = resolveEEP("suite3/dummy-project/test/unit/src"); 354 cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 355 assertNotNull("have a COMPILE classpath", cp); 356 expectedRoots = new TreeSet (); 357 expectedRoots.add(urlForJar(resolveEEPPath("/suite3/dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"))); 358 expectedRoots.add(urlForJar(resolveEEPPath("/suite3/nbplatform/random/modules/random.jar"))); 359 expectedRoots.add(urlForJar(resolveEEPPath("/suite3/nbplatform/random/modules/ext/stuff.jar"))); 360 expectedRoots.add("junit.jar"); 361 expectedRoots.add("nbjunit.jar"); 362 expectedRoots.add("insanelib.jar"); 363 expectedRoots.add("org-netbeans-modules-nbjunit.jar"); 364 expectedRoots.add("org-netbeans-modules-nbjunit-ide.jar"); 365 assertEquals("right COMPILE classpath", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 366 367 expectedRoots.clear(); 369 src = resolveEEP("/suite4/module2/test/unit/src"); 370 expectedRoots.add(urlForJar(resolveEEPPath("/suite4/build/testdist/unit/cluster/module1/tests.jar"))); 371 expectedRoots.add(urlForJar(resolveEEPPath("/suite4/build/cluster/modules/module1.jar"))); 372 expectedRoots.add(urlForJar(resolveEEPPath("/suite4/build/cluster/modules/module2.jar"))); 373 expectedRoots.add("junit.jar"); 374 expectedRoots.add("nbjunit.jar"); 375 expectedRoots.add("insanelib.jar"); 376 expectedRoots.add("org-netbeans-modules-nbjunit.jar"); 377 expectedRoots.add("org-netbeans-modules-nbjunit-ide.jar"); 378 cp = ClassPath.getClassPath(src,ClassPath.COMPILE); 379 FileObject roots[] = cp.getRoots(); 380 assertSets("right compileclasspath",expectedRoots, urlsOfCp4Tests(cp)); 381 } 382 383 public void testQaFunctionalTestClasspath() throws Exception { 384 FileObject qaftsrc = nbCVSRoot().getFileObject("performance/test/qa-functional/src"); 385 if (qaftsrc == null) { 386 System.err.println("Skipping testQaFunctionalTestClasspath since performance not checked out"); 387 return; 388 } 389 ClassPath cp = ClassPath.getClassPath(qaftsrc, ClassPath.COMPILE); 390 assertNotNull("have a COMPILE classpath", cp); 391 Set expectedRoots = new TreeSet (); 392 expectedRoots.add("junit.jar"); 395 expectedRoots.add("nbjunit.jar"); 396 expectedRoots.add("nbjunit-ide.jar"); 397 expectedRoots.add("insanelib.jar"); 398 expectedRoots.add(urlForJar("jemmy/builds/jemmy.jar")); 400 expectedRoots.add(urlForJar("jellytools/builds/jelly2-nb.jar")); 401 assertEquals("right COMPILE classpath", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 403 cp = ClassPath.getClassPath(qaftsrc, ClassPath.EXECUTE); 404 assertNotNull("have an EXECUTE classpath", cp); 405 expectedRoots.add(urlForDir("performance/build/test/qa-functional/classes")); 406 assertEquals("right EXECUTE classpath (COMPILE plus classes)", expectedRoots, urlsOfCp4Tests(cp)); 407 cp = ClassPath.getClassPath(qaftsrc, ClassPath.SOURCE); 408 assertNotNull("have a SOURCE classpath", cp); 409 assertEquals("right SOURCE classpath", Collections.singleton(qaftsrc), new HashSet (Arrays.asList(cp.getRoots()))); 410 } 412 413 public void testQaFunctionalTestClasspathExternalModules() throws Exception { 414 FileObject qaftsrc = resolveEEP("suite1/action-project/test/qa-functional/src"); 415 assertNotNull("have action-project/test/qa-functional/src", qaftsrc); 416 ClassPath cp = ClassPath.getClassPath(qaftsrc, ClassPath.COMPILE); 417 assertNotNull("have a COMPILE classpath", cp); 418 Set expectedRoots = new TreeSet (); 419 expectedRoots.add("junit.jar"); 420 expectedRoots.add("nbjunit.jar"); 421 expectedRoots.add("nbjunit-ide.jar"); 422 expectedRoots.add("insanelib.jar"); 423 expectedRoots.add(urlForJar("jemmy/builds/jemmy.jar")); 424 expectedRoots.add(urlForJar("jellytools/builds/jelly2-nb.jar")); 425 expectedRoots.add("org-netbeans-modules-nbjunit.jar"); 426 expectedRoots.add("org-netbeans-modules-nbjunit-ide.jar"); 427 assertEquals("right COMPILE classpath", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 428 TestBase.TestPCL l = new TestBase.TestPCL(); 429 cp.addPropertyChangeListener(l); 430 NbModuleProject p = (NbModuleProject) FileOwnerQuery.getOwner(qaftsrc); 431 EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 432 File added = file("xtest/lib/xtest.jar"); 433 ep.setProperty("test.qa-functional.cp.extra", added.getAbsolutePath()); 434 p.getHelper().putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 435 assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS)); 437 expectedRoots.add(urlForJar("xtest/lib/xtest.jar")); 438 assertEquals("right COMPILE classpath after added to .extra", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 439 } 440 441 public void testBuildClassPath () throws Exception { 442 FileObject srcRoot = nbCVSRoot().getFileObject("ant/project/src/"); 443 assertNotNull("have ant/project/src",srcRoot); 444 ClassPath ccp = ClassPath.getClassPath(srcRoot, ClassPath.COMPILE); 445 assertNotNull("No compile ClassPath for sources",ccp); 446 FileObject buildClasses = nbCVSRoot().getFileObject("ant/project/build/classes/"); 447 assertNotNull("have ant/project/build/classes",buildClasses); 448 449 assertNull ("ClassPath.SOURCE for build must be null",ClassPath.getClassPath(buildClasses, ClassPath.SOURCE)); 450 assertNull ("ClassPath.COMPILE for build must be null",ClassPath.getClassPath(buildClasses, ClassPath.COMPILE)); 451 ClassPath cp = ClassPath.getClassPath(buildClasses, ClassPath.EXECUTE); 452 assertNotNull("ClassPath.EXECUTE for build must NOT be null",cp); 453 ClassPath expectedCp = ClassPathSupport.createProxyClassPath(new ClassPath[] { 454 ClassPathSupport.createClassPath(new FileObject[] {buildClasses}), 455 ccp 456 }); 457 assertClassPathsHaveTheSameResources(cp, expectedCp); 458 459 FileObject testSrcRoot = nbCVSRoot().getFileObject("ant/project/test/unit/src/"); 460 assertNotNull("have ant/project/test/unit/src/",testSrcRoot); 461 ClassPath tccp = ClassPath.getClassPath(testSrcRoot, ClassPath.COMPILE); 462 assertNotNull("No compile ClassPath for tests",tccp); 463 Project prj = FileOwnerQuery.getOwner(testSrcRoot); 464 assertNotNull("No project found",prj); 465 assertTrue("Invalid project type", prj instanceof NbModuleProject); 466 FileObject testBuildClasses = nbCVSRoot().getFileObject ("ant/project/build/test/unit/classes/"); 467 if (testBuildClasses == null) { 468 testBuildClasses = FileUtil.createFolder(nbCVSRoot(), "ant/project/build/test/unit/classes"); 470 } 471 assertNull ("ClassPath.SOURCE for build/test must be null",ClassPath.getClassPath(testBuildClasses, ClassPath.SOURCE)); 472 assertNull ("ClassPath.COMPILE for build/test must be null",ClassPath.getClassPath(testBuildClasses, ClassPath.COMPILE)); 473 cp = ClassPath.getClassPath(testBuildClasses, ClassPath.EXECUTE); 474 475 String path = ((NbModuleProject)prj).evaluator().getProperty("test.unit.run.cp.extra"); List trExtra = new ArrayList (); 477 if (path != null) { 478 String [] pieces = PropertyUtils.tokenizePath(path); 479 for (int i = 0; i < pieces.length; i++) { 480 File f = ((NbModuleProject)prj).getHelper().resolveFile(pieces[i]); 481 URL url = f.toURI().toURL(); 482 if (FileUtil.isArchiveFile(url)) { 483 url = FileUtil.getArchiveRoot (url); 484 } 485 else { 486 String stringifiedURL = url.toString (); 487 if (!stringifiedURL.endsWith("/")) { url = new URL (stringifiedURL+"/"); } 490 } 491 trExtra.add(ClassPathSupport.createResource(url)); 492 } 493 } 494 assertNotNull("ClassPath.EXECUTE for build/test must NOT be null", cp); 495 expectedCp = ClassPathSupport.createProxyClassPath(new ClassPath[] { 496 ClassPathSupport.createClassPath(new FileObject[] {testBuildClasses}), 497 tccp, 498 ClassPathSupport.createClassPath(trExtra), 499 ClassPathSupport.createClassPath(new URL [] {new URL (urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-modules-masterfs.jar"))}) 500 }); 501 assertClassPathsHaveTheSameResources(cp, expectedCp); 502 503 File jarFile = ((NbModuleProject) prj).getModuleJarLocation(); 504 FileObject jarFO = FileUtil.toFileObject(jarFile); 505 assertNotNull("No module jar", jarFO); 506 FileObject jarRoot = FileUtil.getArchiveRoot(jarFO); 507 assertNull("ClassPath.SOURCE for module jar must be null", ClassPath.getClassPath(jarRoot, ClassPath.SOURCE)); 509 assertNull("ClassPath.COMPILE for module jar must be null", ClassPath.getClassPath(jarRoot, ClassPath.COMPILE)); 510 cp = ClassPath.getClassPath(jarRoot, ClassPath.EXECUTE); 511 assertNotNull("ClassPath.EXECUTE for module jar must NOT be null", cp); 512 expectedCp = ClassPathSupport.createProxyClassPath(new ClassPath[] { 513 ClassPathSupport.createClassPath(new FileObject[] {jarRoot}), 514 ccp 515 }); 516 assertClassPathsHaveTheSameResources(cp, expectedCp); 517 } 518 519 public void testCompileClasspathChanges() throws Exception { 520 ClassPath cp = ClassPath.getClassPath(copyOfMiscDir.getFileObject("src"), ClassPath.COMPILE); 521 Set expectedRoots = new TreeSet (); 522 assertEquals("right initial COMPILE classpath", expectedRoots, urlsOfCp(cp)); 523 TestBase.TestPCL l = new TestBase.TestPCL(); 524 cp.addPropertyChangeListener(l); 525 ModuleEntry ioEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.io"); 526 assertNotNull(ioEntry); 527 copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(ioEntry))); 528 assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS)); 529 l.changed.clear(); 530 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); 531 assertEquals("right COMPILE classpath after changing project.xml", expectedRoots, urlsOfCp(cp)); 532 ModuleEntry utilEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.util"); 533 assertNotNull(utilEntry); 534 copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(utilEntry))); 535 assertTrue("got changes again", l.changed.contains(ClassPath.PROP_ROOTS)); 536 l.changed.clear(); 537 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 538 assertEquals("right COMPILE classpath after changing project.xml again", expectedRoots, urlsOfCp(cp)); 539 } 540 541 public void testExecuteClasspathChanges() throws Exception { 542 ClassPath cp = ClassPath.getClassPath(copyOfMiscDir.getFileObject("src"), ClassPath.EXECUTE); 543 Set expectedRoots = new TreeSet (); 544 expectedRoots.add(Util.urlForDir(file(FileUtil.toFile(copyOfMiscDir), "build/classes")).toExternalForm()); 545 assertEquals("right initial EXECUTE classpath", expectedRoots, urlsOfCp(cp)); 546 TestBase.TestPCL l = new TestBase.TestPCL(); 547 cp.addPropertyChangeListener(l); 548 ModuleEntry ioEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.io"); 549 assertNotNull(ioEntry); 550 copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(ioEntry))); 551 assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS)); 552 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); 553 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 555 assertEquals("right EXECUTE classpath after changing project.xml", expectedRoots.toString(), urlsOfCp(cp).toString()); 556 } 557 558 public void testUnitTestCompileClasspathChanges() throws Exception { 559 ClassPath cp = ClassPath.getClassPath(copyOfMiscDir.getFileObject("test/unit/src"), ClassPath.COMPILE); 560 Set expectedRoots = new TreeSet (); 561 expectedRoots.add(Util.urlForJar(file(copyOfSuite2, "build/cluster/modules/org-netbeans-examples-modules-misc.jar")).toExternalForm()); 562 expectedRoots.add("junit.jar"); 563 expectedRoots.add("nbjunit.jar"); 564 expectedRoots.add("insanelib.jar"); 565 expectedRoots.add("org-netbeans-modules-nbjunit.jar"); 566 expectedRoots.add("org-netbeans-modules-nbjunit-ide.jar"); 567 assertEquals("right initial COMPILE classpath", expectedRoots.toString(), urlsOfCp4Tests(cp).toString()); 568 TestBase.TestPCL l = new TestBase.TestPCL(); 569 cp.addPropertyChangeListener(l); 570 ModuleEntry ioEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.io"); 571 assertNotNull(ioEntry); 572 copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(ioEntry))); 573 assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS)); 574 l.changed.clear(); 575 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar")); 576 assertEquals("right COMPILE classpath after changing project.xml", expectedRoots, urlsOfCp4Tests(cp)); 577 EditableProperties props = copyOfMiscProject.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 578 props.setProperty("test.unit.cp.extra", "${netbeans.dest.dir}/lib/fnord.jar"); 579 copyOfMiscProject.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 580 assertTrue("got changes again", l.changed.contains(ClassPath.PROP_ROOTS)); 581 expectedRoots.add(urlForJar("nbbuild/netbeans/lib/fnord.jar")); 582 assertEquals("right COMPILE classpath after changing project.properties", expectedRoots, urlsOfCp4Tests(cp)); 583 } 584 585 public void testBinaryOriginAbsolutePath() throws Exception { 586 File jmfhome = new File (getWorkDir(), "jmfhome"); 587 File audioFiles = file("platform/samples/audio-files"); 588 if (!audioFiles.isDirectory()) { 589 System.err.println("Skipping testBinaryOriginAbsolutePath since platform not checked out"); 590 return; 591 } 592 File audioviewer = copyFolder(audioFiles); 593 File pp = new File (audioviewer, "nbproject/private/private.properties".replace('/', File.separatorChar)); 595 pp.getParentFile().mkdirs(); 596 OutputStream os = new FileOutputStream (pp); 597 try { 598 Properties p = new Properties (); 599 p.setProperty("jmf.home", jmfhome.getAbsolutePath()); 600 p.store(os, null); 601 } finally { 602 os.close(); 603 } 604 pp = new File (audioviewer, "nbproject/private/platform-private.properties".replace('/', File.separatorChar)); 605 pp.getParentFile().mkdirs(); 606 os = new FileOutputStream (pp); 607 try { 608 Properties p = new Properties (); 609 p.setProperty("netbeans.dest.dir", file("nbbuild/netbeans").getAbsolutePath()); 610 p.store(os, null); 611 } finally { 612 os.close(); 613 } 614 File px = new File (audioviewer, "nbproject/project.xml".replace('/', File.separatorChar)); 615 Document doc = XMLUtil.parse(new InputSource (px.toURI().toString()), false, true, null, null); 616 NodeList nl = doc.getDocumentElement().getElementsByTagNameNS(NbModuleProjectType.NAMESPACE_SHARED_2, "data"); 617 assertEquals(1, nl.getLength()); 618 Element data = (Element ) nl.item(0); 619 data.appendChild(doc.createElementNS(NbModuleProjectType.NAMESPACE_SHARED_2, "standalone")); 621 os = new FileOutputStream (px); 622 try { 623 XMLUtil.write(doc, os, "UTF-8"); 624 } finally { 625 os.close(); 626 } 627 FileObject audioviewerFO = FileUtil.toFileObject(audioviewer); 628 Project p = ProjectManager.getDefault().findProject(audioviewerFO); 629 assertNotNull(p); 630 FileObject src = audioviewerFO.getFileObject("src"); 631 ClassPath cp = ClassPath.getClassPath(src, ClassPath.COMPILE); 632 assertNotNull("have a COMPILE classpath", cp); 633 Set expectedRoots = new TreeSet (); 634 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-actions.jar")); 635 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 636 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar")); 637 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar")); 638 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 639 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-text.jar")); 640 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 641 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 642 File lib = new File (jmfhome, "lib"); 643 expectedRoots.add(Util.urlForJar(new File (lib, "jmf.jar")).toExternalForm()); 644 expectedRoots.add(Util.urlForJar(new File (lib, "mediaplayer.jar")).toExternalForm()); 645 assertEquals("right COMPILE classpath incl. absolute locations of JARs", 646 expectedRoots.toString(), urlsOfCp(cp).toString()); 647 } 648 649 private void assertClassPathsHaveTheSameResources(ClassPath actual, ClassPath expected) { 650 assertSets("cls: ",urlsOfCp(expected), urlsOfCp(actual)); 651 } 652 653 public void testTransitiveExecuteClasspath() throws Exception { NbModuleProject p = TestBase.generateStandaloneModule(getWorkDir(), "prj"); 655 Util.addDependency(p, "org.openide.windows"); 656 ProjectManager.getDefault().saveProject(p); 657 ClassPath cp = ClassPath.getClassPath(p.getSourceDirectory(), ClassPath.EXECUTE); 658 Set expectedRoots = new TreeSet (); 659 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-windows.jar")); 661 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-dialogs.jar")); 663 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-nodes.jar")); 664 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-awt.jar")); 665 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar")); 666 expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-netbeans-api-progress.jar")); 668 expectedRoots.add(Util.urlForDir(new File (p.getProjectDirectoryFile(), "build/classes")).toExternalForm()); 670 assertEquals("right EXECUTE classpath incl. transitive deps", 671 expectedRoots.toString(), urlsOfCp(cp).toString()); 672 } 673 674 } 675 | Popular Tags |