1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Hashtable ; 26 import junit.framework.TestCase; 27 import org.apache.tools.ant.BuildEvent; 28 import org.apache.tools.ant.BuildListener; 29 import org.apache.tools.ant.Project; 30 31 35 public class ModuleListParserTest extends TestCase { 36 37 public ModuleListParserTest(String name) { 38 super(name); 39 } 40 41 private File nball; 42 43 private File file(File root, String relpath) { 44 return new File (root, relpath.replace('/', File.separatorChar)); 45 } 46 47 private String filePath(File root, String relpath) { 48 return file(root, relpath).getAbsolutePath(); 49 } 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 String prop = System.getProperty("nb_all"); 54 assertNotNull("${nb_all} defined", prop); 55 nball = new File (prop); 56 } 57 58 public void testScanSourcesInNetBeansOrg() throws Exception { 59 Hashtable properties = new Hashtable (); 60 properties.put("nb_all", nball.getAbsolutePath()); 61 File build = file(nball, "build"); 62 properties.put("netbeans.dest.dir", build.getAbsolutePath()); 63 properties.put("nb.cluster.foo", "beans,clazz"); 64 properties.put("nb.cluster.foo.dir", "foodir"); 65 properties.put("nb.cluster.bar", "core/startup"); 66 properties.put("nb.cluster.bar.dir", "bardir"); 67 long start = System.currentTimeMillis(); 68 ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_NB_ORG, null); 69 System.err.println("Scanned " + nball + " sources in " + (System.currentTimeMillis() - start) + "msec"); 70 ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.modules.beans"); 71 assertNotNull(e); 72 assertEquals("org.netbeans.modules.beans", e.getCnb()); 73 assertEquals(file(build, "foodir/modules/org-netbeans-modules-beans.jar"), e.getJar()); 74 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 75 e = p.findByCodeNameBase("org.netbeans.libs.xerces"); 76 assertNotNull("found module in a subdir", e); 77 assertEquals("org.netbeans.libs.xerces", e.getCnb()); 78 assertEquals("unknown module put in extra cluster by default", file(build, "extra/modules/org-netbeans-libs-xerces.jar"), e.getJar()); 79 assertEquals("correct CP extensions (using <binary-origin> and relative paths)", Arrays.asList(new File [] { 80 file(nball, "libs/external/xerces-2.8.0.jar"), 81 file(nball, "libs/external/xml-commons-dom-ranges-1.0.b2.jar"), 82 }), Arrays.asList(e.getClassPathExtensions())); 83 e = p.findByCodeNameBase("javax.jmi.model"); 84 assertNotNull(e); 85 assertEquals("correct CP extensions (using <binary-origin> and property substitutions #1)", Arrays.asList(new File [] { 86 file(nball, "mdr/external/mof.jar"), 87 }), Arrays.asList(e.getClassPathExtensions())); 88 e = p.findByCodeNameBase("org.netbeans.modules.css"); 89 assertNotNull(e); 90 assertEquals("correct CP extensions (using <binary-origin> and property substitutions #2)", Arrays.asList(new File [] { 91 file(nball, "xml/external/flute.jar"), 92 file(nball, "xml/external/sac.jar"), 93 }), Arrays.asList(e.getClassPathExtensions())); 94 e = p.findByCodeNameBase("org.netbeans.swing.tabcontrol"); 95 assertNotNull("found module in a subsubdir", e); 96 e = p.findByCodeNameBase("org.netbeans.core.startup"); 97 assertNotNull(e); 98 assertEquals("org.netbeans.core.startup", e.getCnb()); 99 assertEquals("handling special JAR names correctly", file(build, "bardir/core/core.jar"), e.getJar()); 100 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 101 e = p.findByCodeNameBase("org.netbeans.modules.xml.tax"); 102 assertNotNull("found xml/tax", e); 103 assertEquals("org.netbeans.modules.xml.tax", e.getCnb()); 104 assertEquals(file(build, "extra/modules/org-netbeans-modules-xml-tax.jar"), e.getJar()); 105 assertEquals("correct CP extensions (using runtime-relative-path)", Arrays.asList(new File [] { 106 file(build, "extra/modules/ext/org-netbeans-tax.jar"), 107 }), Arrays.asList(e.getClassPathExtensions())); 108 } 109 110 public void testScanSourcesAndBinariesForExternalSuite() throws Exception { 111 Project fakeproj = new Project(); 112 fakeproj.addBuildListener(new BuildListener() { 113 public void messageLogged(BuildEvent buildEvent) { 114 if (buildEvent.getPriority() <= Project.MSG_VERBOSE) { 115 System.err.println(buildEvent.getMessage()); 116 } 117 } 118 public void taskStarted(BuildEvent buildEvent) {} 119 public void taskFinished(BuildEvent buildEvent) {} 120 public void targetStarted(BuildEvent buildEvent) {} 121 public void targetFinished(BuildEvent buildEvent) {} 122 public void buildStarted(BuildEvent buildEvent) {} 123 public void buildFinished(BuildEvent buildEvent) {} 124 }); 125 Hashtable properties = new Hashtable (); 126 properties.put("netbeans.dest.dir", filePath(nball, "nbbuild/netbeans")); 127 properties.put("basedir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/action-project")); 128 properties.put("suite.dir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite1")); 129 long start = System.currentTimeMillis(); 130 ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_SUITE, fakeproj); 131 System.err.println("Scanned " + nball + " binaries in " + (System.currentTimeMillis() - start) + "msec"); 132 ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.examples.modules.action"); 133 assertNotNull("found myself", e); 134 assertEquals("org.netbeans.examples.modules.action", e.getCnb()); 135 assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"), e.getJar()); 136 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 137 e = p.findByCodeNameBase("org.netbeans.examples.modules.lib"); 138 assertNotNull("found sister project in suite", e); 139 assertEquals("org.netbeans.examples.modules.lib", e.getCnb()); 140 assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite1/build/cluster/modules/org-netbeans-examples-modules-lib.jar"), e.getJar()); 141 File jar = file(nball, "nbbuild/netbeans/ide8/modules/org-netbeans-libs-xerces.jar"); 142 assertTrue("Build all-libs/xerces first!", jar.isFile()); 143 e = p.findByCodeNameBase("org.netbeans.libs.xerces"); 144 assertNotNull("found netbeans.org module by its binary", e); 145 assertEquals("org.netbeans.libs.xerces", e.getCnb()); 146 assertEquals(jar, e.getJar()); 147 assertEquals("correct CP extensions (using Class-Path header in manifest)", Arrays.asList(new File [] { 148 file(nball, "nbbuild/netbeans/ide8/modules/ext/xerces-2.8.0.jar"), 149 file(nball, "nbbuild/netbeans/ide8/modules/ext/xml-commons-dom-ranges-1.0.b2.jar"), 150 }), Arrays.asList(e.getClassPathExtensions())); 151 e = p.findByCodeNameBase("org.openide.loaders"); 152 assertNotNull(e); 153 assertEquals("org.openide.loaders", e.getCnb()); 154 assertEquals(file(nball, "nbbuild/netbeans/platform7/modules/org-openide-loaders.jar"), e.getJar()); 155 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 156 e = p.findByCodeNameBase("org.netbeans.bootstrap"); 157 assertNotNull(e); 158 assertEquals("org.netbeans.bootstrap", e.getCnb()); 159 assertEquals(file(nball, "nbbuild/netbeans/platform7/lib/boot.jar"), e.getJar()); 160 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 161 jar = file(nball, "nbbuild/netbeans/ide8/modules/org-netbeans-modules-xml-tax.jar"); 162 assertTrue("Build all-xml/tax first!", jar.isFile()); 163 e = p.findByCodeNameBase("org.netbeans.modules.xml.tax"); 164 assertNotNull(e); 165 assertEquals("org.netbeans.modules.xml.tax", e.getCnb()); 166 assertEquals(jar, e.getJar()); 167 assertEquals(Arrays.asList(new File [] { 168 file(nball, "nbbuild/netbeans/ide8/modules/ext/org-netbeans-tax.jar"), 169 }), Arrays.asList(e.getClassPathExtensions())); 170 } 171 172 public void testScanSourcesAndBinariesForExternalStandaloneModule() throws Exception { 173 Hashtable properties = new Hashtable (); 174 properties.put("netbeans.dest.dir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/nbplatform")); 175 properties.put("basedir", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project")); 176 properties.put("project", filePath(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project")); 177 ModuleListParser p = new ModuleListParser(properties, ParseProjectXml.TYPE_STANDALONE, null); 178 ModuleListParser.Entry e = p.findByCodeNameBase("org.netbeans.examples.modules.dummy"); 179 assertNotNull("found myself", e); 180 assertEquals("org.netbeans.examples.modules.dummy", e.getCnb()); 181 assertEquals(file(nball, "apisupport/project/test/unit/data/example-external-projects/suite3/dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"), e.getJar()); 182 assertEquals(Collections.EMPTY_LIST, Arrays.asList(e.getClassPathExtensions())); 183 e = p.findByCodeNameBase("org.netbeans.modules.classfile"); 184 assertNotNull("found (fake) netbeans.org module by its binary", e); 185 assertEquals("org.netbeans.modules.classfile", e.getCnb()); 186 } 187 188 } 189 | Popular Tags |