1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.util.Iterator ; 24 import java.util.SortedSet ; 25 import java.util.TreeSet ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.modules.apisupport.project.TestBase; 29 import org.netbeans.spi.project.SubprojectProvider; 30 import org.netbeans.spi.project.support.ant.PropertyUtils; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 38 public class SubprojectProviderImplTest extends TestBase { 39 40 public SubprojectProviderImplTest(String name) { 41 super(name); 42 } 43 44 public void testNetBeansOrgSubprojects() throws Exception { 45 checkSubprojects("ant", new String [] { 47 "openide/fs", 48 "openide/util", 49 "openide/modules", 50 "openide/nodes", 51 "openide/awt", 52 "openide/dialogs", 53 "openide/windows", 54 "openide/text", 55 "openide/actions", 56 "openide/execution", 57 "openide/io", 58 "openide/loaders", 59 "xml/api", 60 "core/navigator", 61 "openide/explorer", 62 "core/options", 63 "libs/swing-layout", 64 "core/progress", 65 "projects/projectapi", 66 "projects/projectuiapi", 67 }); 68 } 69 70 public void testExternalSubprojects() throws Exception { 71 checkSubprojects(resolveEEPPath("/suite1/action-project"), new String [] { 72 resolveEEPPath("/suite1/support/lib-project"), 73 file("openide/dialogs").getAbsolutePath(), 74 }); 75 checkSubprojects(resolveEEPPath("/suite1/support/lib-project"), new String [0]); 76 checkSubprojects(resolveEEPPath("/suite3/dummy-project"), new String [0]); 78 } 79 80 81 public void testAdHocSubprojects() throws Exception { 82 assertDepends("mdr/module", "mdr"); 83 assertDepends("ide/applemenu", "ide/applemenu/eawtstub"); 84 } 85 86 87 public void testSelfRefWithClassPathExts() throws Exception { 88 checkSubprojects("apisupport/samples/PaintApp-suite/ColorChooser", new String [0]); 89 } 90 91 92 public void testInclusionOfHigherBin() throws Exception { 93 checkSubprojects("httpserver/servletapi", new String [0]); 94 } 95 96 private void checkSubprojects(String project, String [] subprojects) throws Exception { 97 Project p = project(project); 98 SubprojectProvider spp = (SubprojectProvider) p.getLookup().lookup(SubprojectProvider.class); 99 assertNotNull("have SPP in " + p, spp); 100 SortedSet expected = new TreeSet (); 101 for (int i = 0; i < subprojects.length; i++) { 102 File f = new File (subprojects[i]); 103 if (!f.isAbsolute()) { 104 f = file(subprojects[i]); 105 } 106 expected.add(f.toURI().toString()); 107 } 108 SortedSet actual = new TreeSet (); 109 Iterator it = spp.getSubprojects().iterator(); 110 while (it.hasNext()) { 111 actual.add(((Project) it.next()).getProjectDirectory().getURL().toExternalForm()); 112 } 113 assertEquals("correct subprojects for " + project, expected.toString(), actual.toString()); 114 } 115 116 private Project project(String path) throws Exception { 117 FileObject dir = FileUtil.toFileObject(PropertyUtils.resolveFile(nbCVSRootFile(), path)); 118 assertNotNull("have " + path, dir); 120 Project p = ProjectManager.getDefault().findProject(dir); 121 assertNotNull("have project in " + path, p); 122 return p; 123 } 124 125 private void assertDepends(String parent, String child) throws Exception { 126 Project p1 = project(parent); 127 Project p2 = project(child); 128 SubprojectProvider spp = (SubprojectProvider) p1.getLookup().lookup(SubprojectProvider.class); 129 assertNotNull("have SPP in " + p1, spp); 130 assertTrue(parent + " includes " + child, spp.getSubprojects().contains(p2)); 131 } 132 133 } 134 | Popular Tags |