1 19 20 package org.netbeans.modules.apisupport.project.universe; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Arrays ; 25 import java.util.HashSet ; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.modules.apisupport.project.EditableManifest; 28 import org.netbeans.modules.apisupport.project.ManifestManager; 29 import org.netbeans.modules.apisupport.project.NbModuleProject; 30 import org.netbeans.modules.apisupport.project.ProjectXMLManager; 31 import org.netbeans.modules.apisupport.project.TestBase; 32 import org.netbeans.modules.apisupport.project.Util; 33 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 34 import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; 35 import org.netbeans.spi.project.support.ant.AntProjectHelper; 36 import org.netbeans.spi.project.support.ant.EditableProperties; 37 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 38 import org.netbeans.spi.project.support.ant.PropertyUtils; 39 import org.openide.util.Mutex; 40 41 45 public class ModuleListTest extends TestBase { 46 47 public ModuleListTest(String name) { 48 super(name); 49 } 50 51 private File suite1, suite2, standaloneSuite3; 52 53 protected void setUp() throws Exception { 54 super.setUp(); 55 suite1 = resolveEEPFile("suite1"); 56 suite2 = resolveEEPFile("suite2"); 57 standaloneSuite3 = resolveEEPFile("suite3"); 58 } 59 60 public void testParseProperties() throws Exception { 61 File basedir = file("ant/browsetask"); 62 PropertyEvaluator eval = ModuleList.parseProperties(basedir, nbCVSRootFile(), false, false, "org.netbeans.modules.ant.browsetask"); 63 String nbdestdir = eval.getProperty("netbeans.dest.dir"); 64 assertNotNull(nbdestdir); 65 assertEquals(file("nbbuild/netbeans"), PropertyUtils.resolveFile(basedir, nbdestdir)); 66 assertEquals("modules/org-netbeans-modules-ant-browsetask.jar", eval.getProperty("module.jar")); 67 assertEquals(file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE), PropertyUtils.resolveFile(basedir, eval.getProperty("cluster"))); 68 assertNull(eval.getProperty("suite.dir")); 69 basedir = file("openide/loaders"); 70 eval = ModuleList.parseProperties(basedir, nbCVSRootFile(), false, false, "org.openide.loaders"); 71 assertEquals("modules/org-openide-loaders.jar", eval.getProperty("module.jar")); 72 basedir = new File (suite1, "action-project"); 73 eval = ModuleList.parseProperties(basedir, suite1, true, false, "org.netbeans.examples.modules.action"); 74 nbdestdir = eval.getProperty("netbeans.dest.dir"); 75 assertNotNull(nbdestdir); 76 assertEquals(file("nbbuild/netbeans"), PropertyUtils.resolveFile(basedir, nbdestdir)); 77 assertEquals(suite1, PropertyUtils.resolveFile(basedir, eval.getProperty("suite.dir"))); 78 basedir = new File (suite2, "misc-project"); 79 eval = ModuleList.parseProperties(basedir, suite2, true, false, "org.netbeans.examples.modules.misc"); 80 nbdestdir = eval.getProperty("netbeans.dest.dir"); 81 assertNotNull(nbdestdir); 82 assertEquals(file("nbbuild/netbeans"), PropertyUtils.resolveFile(basedir, nbdestdir)); 83 assertEquals(file(suite2, "build/cluster"), PropertyUtils.resolveFile(basedir, eval.getProperty("cluster"))); 84 assertEquals(suite2, PropertyUtils.resolveFile(basedir, eval.getProperty("suite.dir"))); 85 basedir = new File (standaloneSuite3, "dummy-project"); 86 eval = ModuleList.parseProperties(basedir, standaloneSuite3, false, true, "org.netbeans.examples.modules.dummy"); 87 nbdestdir = eval.getProperty("netbeans.dest.dir"); 88 assertNotNull(nbdestdir); 89 assertEquals(file(standaloneSuite3, "nbplatform"), PropertyUtils.resolveFile(basedir, nbdestdir)); 90 assertEquals(file(standaloneSuite3, "dummy-project/build/cluster"), PropertyUtils.resolveFile(basedir, eval.getProperty("cluster"))); 91 assertNull(eval.getProperty("suite.dir")); 92 } 93 94 public void testFindModulesInSuite() throws Exception { 95 assertEquals("correct modules in suite1", new HashSet (Arrays.asList(new File [] { 96 file(suite1, "action-project"), 97 file(suite1, "support/lib-project"), 98 })), new HashSet (Arrays.asList(ModuleList.findModulesInSuite(suite1)))); 99 assertEquals("correct modules in suite2", new HashSet (Arrays.asList(new File [] { 100 file(suite2, "misc-project"), 101 })), new HashSet (Arrays.asList(ModuleList.findModulesInSuite(suite2)))); 102 } 103 104 public void testNetBeansOrgEntries() throws Exception { 105 long start = System.currentTimeMillis(); 106 ModuleList ml = ModuleList.getModuleList(file("ant/browsetask")); System.err.println("Time to scan netbeans.org sources: " + (System.currentTimeMillis() - start) + "msec"); 108 System.err.println("Directories traversed: " + ModuleList.directoriesChecked); 109 System.err.println("XML files parsed: " + ModuleList.xmlFilesParsed + " in " + ModuleList.timeSpentInXmlParsing + "msec"); 110 ModuleEntry e = ml.getEntry("org.netbeans.modules.java.project"); 111 assertNotNull("have org.netbeans.modules.java.project", e); 112 assertEquals("right jarLocation", file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-java-project.jar"), e.getJarLocation()); 113 assertTrue("in all entries", ml.getAllEntries().contains(e)); 114 assertEquals("right path", "java/project", e.getNetBeansOrgPath()); 115 assertEquals("right source location", file("java/project"), e.getSourceLocation()); 116 assertTrue("same by JAR", ModuleList.getKnownEntries(e.getJarLocation()).contains(e)); 117 assertTrue("same by other random file", ModuleList.getKnownEntries(file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/config/Modules/org-netbeans-modules-java-project.xml")).contains(e)); 118 assertEquals("right codeNameBase", "org.netbeans.modules.java.project", e.getCodeNameBase()); 119 assertEquals(file("nbbuild/netbeans"), e.getDestDir()); 120 assertEquals("", e.getClassPathExtensions()); 121 assertNotNull("localized name", e.getLocalizedName()); 122 assertNotNull("display category", e.getCategory()); 123 assertNotNull("short description", e.getShortDescription()); 124 assertNotNull("long description", e.getLongDescription()); 125 assertNotNull("release version", e.getReleaseVersion()); 126 assertNotNull("specification version", e.getSpecificationVersion()); 127 assertEquals("number of public packages for " + e, new Integer (6), new Integer (e.getPublicPackages().length)); 128 assertFalse("not deprecated", e.isDeprecated()); 129 e = ml.getEntry("org.openide.filesystems"); 131 assertNotNull("have org.openide.filesystems", e); 132 assertEquals("right jarLocation", file("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/core/org-openide-filesystems.jar"), e.getJarLocation()); 133 assertEquals("right source location", file("openide/fs"), e.getSourceLocation()); 134 assertTrue("same by JAR", ModuleList.getKnownEntries(e.getJarLocation()).contains(e)); 135 assertEquals("right path", "openide/fs", e.getNetBeansOrgPath()); 136 e = ml.getEntry("org.netbeans.libs.xerces"); 138 assertNotNull(e); 139 assertEquals("correct CP extensions (using <binary-origin> and relative paths)", 140 ":" + file("libs/external/xerces-2.8.0.jar") + ":" + file("libs/external/xml-commons-dom-ranges-1.0.b2.jar"), 141 e.getClassPathExtensions()); 142 e = ml.getEntry("javax.jmi.model"); 143 assertNotNull(e); 144 assertEquals("correct CP extensions (using <binary-origin> and property substitutions #1)", 145 ":" + file("mdr/external/mof.jar"), 146 e.getClassPathExtensions()); 147 e = ml.getEntry("org.netbeans.modules.css"); 148 assertNotNull(e); 149 assertEquals("correct CP extensions (using <binary-origin> and property substitutions #2)", 150 ":" + file("xml/external/flute.jar") + ":" + file("xml/external/sac.jar"), 151 e.getClassPathExtensions()); 152 e = ml.getEntry("org.netbeans.modules.xml.tax"); 153 assertNotNull(e); 154 assertEquals("correct CP extensions (using runtime-relative-path)", 155 ":" + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/ext/org-netbeans-tax.jar"), 156 e.getClassPathExtensions()); 157 e = ml.getEntry("org.openide.util.enumerations"); 158 assertNotNull(e); 159 assertTrue("this one is deprecated", e.isDeprecated()); 160 e = ml.getEntry("org.netbeans.modules.projectui"); 161 assertNotNull(e); 162 assertNotNull(e.getProvidedTokens()); 163 assertTrue("There are some provided tokens", e.getProvidedTokens().length > 0); 164 e = ml.getEntry("org.netbeans.modules.looks"); 167 assertNotNull(e); 168 assertEquals("right path", "openide/looks", e.getNetBeansOrgPath()); 169 } 170 171 public void testExternalEntries() throws Exception { 172 long start = System.currentTimeMillis(); 174 ModuleList ml = ModuleList.getModuleList(file(suite1, "support/lib-project")); 175 System.err.println("Time to scan suite + NB binaries: " + (System.currentTimeMillis() - start) + "msec"); 176 ModuleEntry e = ml.getEntry("org.netbeans.examples.modules.action"); 177 assertNotNull("action-project found", e); 178 File jar = resolveEEPFile("/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"); 179 assertEquals("right JAR location", jar, e.getJarLocation()); 180 assertTrue("in all entries", ml.getAllEntries().contains(e)); 181 assertNull("no nb.org path", e.getNetBeansOrgPath()); 182 assertEquals("right source location", file(suite1, "action-project"), e.getSourceLocation()); 183 assertTrue("same by JAR", ModuleList.getKnownEntries(e.getJarLocation()).contains(e)); 184 assertEquals("right codeNameBase", "org.netbeans.examples.modules.action", e.getCodeNameBase()); 185 e = ml.getEntry("org.netbeans.modules.classfile"); 186 assertNotNull("can find nb.org sources too (classfile module must be built)", e); 187 assertEquals("correct nb.org source location", file("classfile"), e.getSourceLocation()); 188 assertNotNull("localized name", e.getLocalizedName()); 189 assertNotNull("display category", e.getCategory()); 190 assertNotNull("short description", e.getShortDescription()); 191 assertNotNull("long description", e.getLongDescription()); 192 assertNotNull("release version", e.getReleaseVersion()); 193 assertNotNull("specification version", e.getSpecificationVersion()); 194 assertNotNull(e.getProvidedTokens()); 195 assertEquals("there are no provided tokens", 0, e.getProvidedTokens().length); 196 202 e = ml.getEntry("org.netbeans.libs.xerces"); 203 assertEquals("correct CP exts for a nb.org module (using Class-Path only)", 204 ":" + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/ext/xerces-2.8.0.jar") + ":" + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/ext/xml-commons-dom-ranges-1.0.b2.jar"), 205 e.getClassPathExtensions()); 206 ml = ModuleList.getModuleList(file(suite2, "misc-project")); 208 e = ml.getEntry("org.netbeans.examples.modules.misc"); 209 assertNotNull("can find module from my own suite", e); 210 assertEquals("correct JAR location", resolveEEPFile("/suite2/build/cluster/modules/org-netbeans-examples-modules-misc.jar"), e.getJarLocation()); 211 assertNotNull("localized name", e.getLocalizedName()); 212 assertNotNull("display category", e.getCategory()); 213 assertNotNull("short description", e.getShortDescription()); 214 assertNotNull("long description", e.getLongDescription()); 215 assertEquals("right codeNameBase", "org.netbeans.examples.modules.misc", e.getCodeNameBase()); 216 assertNotNull("release version", e.getReleaseVersion()); 217 assertNotNull("specification version", e.getSpecificationVersion()); 218 assertNotNull(e.getProvidedTokens()); 219 assertEquals("there are no provided tokens", 0, e.getProvidedTokens().length); 220 assertEquals("number of public packages for " + e, new Integer (1), new Integer (e.getPublicPackages().length)); 221 e = ml.getEntry("org.netbeans.libs.xerces"); 222 assertNotNull("can find nb.org binary module too", e); 223 assertEquals("have sources for that", file("libs/xerces"), e.getSourceLocation()); 224 assertEquals("and correct JAR location", file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/org-netbeans-libs-xerces.jar"), e.getJarLocation()); 225 assertEquals("and correct CP exts (using Class-Path only)", 226 ":" + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/ext/xerces-2.8.0.jar") + ":" + file("nbbuild/netbeans/" + TestBase.CLUSTER_IDE + "/modules/ext/xml-commons-dom-ranges-1.0.b2.jar"), 227 e.getClassPathExtensions()); 228 e = ml.getEntry("org.openide.util"); 229 assertNotNull(e); 230 assertFalse("binary API not deprecated", e.isDeprecated()); 231 e = ml.getEntry("org.openide.util.enumerations"); 232 assertNotNull(e); 233 assertTrue("this one is deprecated", e.isDeprecated()); 234 ml = ModuleList.getModuleList(file(standaloneSuite3, "dummy-project")); 236 e = ml.getEntry("org.netbeans.examples.modules.dummy"); 237 assertNotNull("can find myself", e); 238 e = ml.getEntry("org.netbeans.modules.classfile"); 239 assertNotNull("found (fake) nb.org module", e); 240 assertNull("...without sources", e.getSourceLocation()); 241 assertEquals("and with a special JAR location", file(standaloneSuite3, "nbplatform/random/modules/random.jar"), e.getJarLocation()); 242 assertEquals("correct CP extensions (using Class-Path only, and ignoring sources completely)", 243 ":" + file(standaloneSuite3, "nbplatform/random/modules/ext/stuff.jar"), 244 e.getClassPathExtensions()); 245 } 246 247 public void testNewlyAddedModule() throws Exception { 248 } 251 252 public void testFindNetBeansOrg() throws Exception { 253 assertEquals(nbCVSRootFile(), ModuleList.findNetBeansOrg(file("xml"))); 254 assertEquals(nbCVSRootFile(), ModuleList.findNetBeansOrg(file("xml/tax"))); 255 assertEquals(nbCVSRootFile(), ModuleList.findNetBeansOrg(file("xml/tax/lib"))); 256 assertEquals(null, ModuleList.findNetBeansOrg(file("xml/tax/lib/src"))); 257 assertEquals(null, ModuleList.findNetBeansOrg(File.listRoots()[0])); 258 } 259 260 public void testRefreshSuiteModuleList() throws Exception { 261 SuiteProject suite1 = generateSuite("suite1"); 262 final NbModuleProject p = TestBase.generateSuiteComponent(suite1, "module1a"); 263 ModuleList ml = ModuleList.getModuleList( 264 p.getProjectDirectoryFile(), 265 NbPlatform.getDefaultPlatform().getDestDir()); 266 assertNotNull("module1a is in the suite1's module list", ml.getEntry("org.example.module1a")); 267 assertEquals("no public packages in the ModuleEntry", 0, ml.getEntry("org.example.module1a").getPublicPackages().length); 268 269 Boolean result = (Boolean ) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 271 public Object run() throws IOException { 272 ProjectXMLManager pxm = new ProjectXMLManager(p); 273 String [] newPP = new String [] { "org.example.module1a" }; 274 pxm.replacePublicPackages(newPP); 275 return Boolean.TRUE; 276 } 277 }); 278 assertTrue("replace public packages", result.booleanValue()); 279 ProjectManager.getDefault().saveProject(p); 280 281 ModuleList.refreshSuiteModuleList(suite1.getProjectDirectoryFile()); 282 ml = ModuleList.getModuleList(p.getProjectDirectoryFile(), 283 NbPlatform.getDefaultPlatform().getDestDir()); 284 assertEquals("one public packages in the refreshed ModuleEntry", 1, ml.getEntry("org.example.module1a").getPublicPackages().length); 285 } 286 287 public void testSpecVersionBaseSourceEntries() throws Exception { SuiteProject suite = generateSuite("suite"); 289 NbModuleProject p = TestBase.generateSuiteComponent(suite, "module"); 290 ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile()); 291 ModuleEntry e = ml.getEntry("org.example.module"); 292 assertNotNull("have entry", e); 293 assertEquals("right initial spec vers from manifest", "1.0", e.getSpecificationVersion()); 294 EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 295 ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.1.0"); 296 p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 297 EditableManifest em = Util.loadManifest(p.getManifestFile()); 298 em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null); 299 Util.storeManifest(p.getManifestFile(), em); 300 ProjectManager.getDefault().saveProject(p); 301 assertEquals("right spec.version.base", "1.1", e.getSpecificationVersion()); 302 ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.2.0"); 303 p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 304 ProjectManager.getDefault().saveProject(p); 305 assertEquals("right modified spec.version.base", "1.2", e.getSpecificationVersion()); 306 } 307 308 } 309 | Popular Tags |