1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 23 import java.io.File ; 24 import org.netbeans.api.project.FileOwnerQuery; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.api.project.SourceGroup; 29 import org.netbeans.api.project.Sources; 30 import org.netbeans.spi.project.support.ant.AntProjectHelper; 31 import org.netbeans.spi.project.support.ant.EditableProperties; 32 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 33 import org.netbeans.spi.project.support.ant.PropertyUtils; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 37 41 public class NbModuleProjectTest extends TestBase { 42 43 public NbModuleProjectTest(String name) { 44 super(name); 45 } 46 47 private NbModuleProject javaProjectProject; 48 private NbModuleProject loadersProject; 49 private File userPropertiesFile; 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 userPropertiesFile = TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 54 FileObject dir = nbCVSRoot().getFileObject("java/project"); 55 assertNotNull("have java/project checked out", dir); 56 Project p = ProjectManager.getDefault().findProject(dir); 57 javaProjectProject = (NbModuleProject)p; 58 dir = nbCVSRoot().getFileObject("openide/loaders"); 59 assertNotNull("have openide/loaders checked out", dir); 60 p = ProjectManager.getDefault().findProject(dir); 61 loadersProject = (NbModuleProject)p; 62 } 63 64 65 public void testExternalSourceRoots() throws Exception { 66 FileObject documentFinderJava = nbCVSRoot().getFileObject("editor/libsrc/org/netbeans/editor/DocumentFinder.java"); 67 assertNotNull("have DocumentFinder.java", documentFinderJava); 68 FileObject editorLib = nbCVSRoot().getFileObject("editor/lib"); 69 assertNotNull("have editor/lib", editorLib); 70 Project editorLibProject = ProjectManager.getDefault().findProject(editorLib); 71 assertNotNull("have editor/lib project", editorLibProject); 72 Thread.sleep(1000); assertEquals("correct owner of DocumentFinder.java", editorLibProject, FileOwnerQuery.getOwner(documentFinderJava)); 74 } 75 76 public void testExternalModules() throws Exception { 77 FileObject suite1 = resolveEEP("suite1"); 78 FileObject action = suite1.getFileObject("action-project"); 79 NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(action); 80 PropertyEvaluator eval = actionProject.evaluator(); 81 String nbdestdir = eval.getProperty("netbeans.dest.dir"); 82 assertNotNull("defined netbeans.dest.dir", nbdestdir); 83 assertEquals("right netbeans.dest.dir", file("nbbuild/netbeans"), PropertyUtils.resolveFile(FileUtil.toFile(action), nbdestdir)); 84 FileObject suite3 = resolveEEP("suite3"); 85 FileObject dummy = suite3.getFileObject("dummy-project"); 86 NbModuleProject dummyProject = (NbModuleProject) ProjectManager.getDefault().findProject(dummy); 87 eval = dummyProject.evaluator(); 88 assertEquals("right netbeans.dest.dir", resolveEEPFile("suite3/nbplatform"), PropertyUtils.resolveFile(FileUtil.toFile(dummy), eval.getProperty("netbeans.dest.dir"))); 89 } 91 92 public void testGetType() throws Exception { 93 assertEquals(NbModuleProvider.NETBEANS_ORG, Util.getModuleType(javaProjectProject)); 94 FileObject suite1 = resolveEEP("suite1"); 95 FileObject action = suite1.getFileObject("action-project"); 96 NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(action); 97 assertEquals(NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(actionProject)); 98 FileObject suite3 = resolveEEP("suite3"); 99 FileObject dummy = suite3.getFileObject("dummy-project"); 100 NbModuleProject dummyProject = (NbModuleProject) ProjectManager.getDefault().findProject(dummy); 101 assertEquals(NbModuleProvider.STANDALONE, Util.getModuleType(dummyProject)); 102 } 103 104 public void testSupportsJavadoc() throws Exception { 105 assertTrue(javaProjectProject.supportsJavadoc()); 106 FileObject dir = nbCVSRoot().getFileObject("beans"); 107 assertNotNull("have beans checked out", dir); 108 Project p = ProjectManager.getDefault().findProject(dir); 109 NbModuleProject beansProject = (NbModuleProject) p; 110 assertFalse(beansProject.supportsJavadoc()); 111 } 112 113 public void testGetNbrootFile() throws Exception { 114 NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(resolveEEP("suite1/action-project")); 115 assertEquals(file("xtest/lib/insanelib.jar"), actionProject.getNbrootFile("xtest/lib/insanelib.jar")); 116 } 117 118 public void testThatModuleWithOverriddenSrcDirPropertyDoesNotThrowNPE() throws Exception { 119 FileObject prjFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1"); 120 FileObject srcFO = prjFO.getFileObject("src"); 121 FileUtil.moveFile(srcFO, prjFO, "src2"); 122 ProjectManager.getDefault().findProject(prjFO); 123 } 124 125 public void testGenericSourceGroupForExternalUnitTests() throws Exception { 126 FileObject prjFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1"); 127 FileUtil.createData(prjFO, "../myunitsrc/a/b/c/Dummy.java"); 128 FileObject propsFO = FileUtil.createData(prjFO, AntProjectHelper.PROJECT_PROPERTIES_PATH); 129 EditableProperties ep = Util.loadProperties(propsFO); 130 ep.setProperty("test.unit.src.dir", "../myunitsrc"); 131 Util.storeProperties(propsFO, ep); 132 Project module = ProjectManager.getDefault().findProject(prjFO); 133 Sources sources = ProjectUtils.getSources(module); 134 SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC); 135 assertEquals("two generic source group", 2, sourceGroups.length); } 137 138 } 139 | Popular Tags |