1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.text.Collator ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import java.util.TreeSet ; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.modules.apisupport.project.EditableManifest; 29 import org.netbeans.modules.apisupport.project.ManifestManager; 30 import org.netbeans.modules.apisupport.project.NbModuleProject; 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.universe.ModuleEntry; 35 import org.netbeans.modules.apisupport.project.universe.ModuleList; 36 import org.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.netbeans.spi.project.support.ant.EditableProperties; 38 39 42 public class ModuleDependencyTest extends TestBase { 43 44 public ModuleDependencyTest(String testName) { 45 super(testName); 46 } 47 48 public void testHashCodeAndEqualsAndCompareTo() throws Exception { 49 NbModuleProject module = generateStandaloneModule("module"); 50 ModuleList ml = module.getModuleList(); 51 ModuleEntry antME = ml.getEntry("org.apache.tools.ant.module"); 52 ModuleDependency d1 = new ModuleDependency(antME); 53 ModuleDependency sameAsD1 = new ModuleDependency(antME); 54 ModuleDependency alsoSameAsD1 = new ModuleDependency(antME, antME.getReleaseVersion(), antME.getSpecificationVersion(), true, false); 55 ModuleDependency d2 = new ModuleDependency(antME, "0-1", null, true, false); 56 ModuleDependency d3 = new ModuleDependency(antME, null, null, true, false); 57 ModuleDependency d4 = new ModuleDependency(antME, antME.getReleaseVersion(), null, true, true); 58 ModuleDependency d5 = new ModuleDependency(antME, antME.getReleaseVersion(), null, true, false); 59 60 Set set = new HashSet (); 62 Set sorted = new TreeSet (); 63 set.add(d1); 64 sorted.add(d1); 65 assertFalse("already there", set.add(sameAsD1)); 66 assertFalse("already there", sorted.add(sameAsD1)); 67 assertFalse("already there", set.add(alsoSameAsD1)); 68 assertFalse("already there", sorted.add(alsoSameAsD1)); 69 assertTrue("is not there yet", set.add(d2)); 70 assertTrue("is not there yet", sorted.add(d2)); 71 assertTrue("is not there yet", set.add(d3)); 72 assertTrue("is not there yet", sorted.add(d3)); 73 assertTrue("is not there yet", set.add(d4)); 74 assertTrue("is not there yet", sorted.add(d4)); 75 assertTrue("is not there yet", set.add(d5)); 76 assertTrue("is not there yet", sorted.add(d5)); 77 78 ModuleDependency[] expectedOrder = new ModuleDependency[] { 79 d3, d2, d5, d4, d1 80 }; 81 Iterator it = sorted.iterator(); 82 for (int i = 0; i < expectedOrder.length; i++) { 83 assertSame("expected order", expectedOrder[i], it.next()); 84 } 85 assertFalse("sanity check", it.hasNext()); 86 } 87 88 public void testLocalizedNameComparator() throws Exception { 89 NbModuleProject module = generateStandaloneModule("module"); 90 ModuleList ml = module.getModuleList(); 91 ModuleDependency[] deps = new ModuleDependency[] { 92 new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")), 93 new ModuleDependency(ml.getEntry("org.openide.loaders")), 94 new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")), 95 new ModuleDependency(ml.getEntry("org.openide.io")), 96 new ModuleDependency(ml.getEntry("org.jdesktop.layout")), 97 new ModuleDependency(ml.getEntry("org.openide.filesystems")), 98 new ModuleDependency(ml.getEntry("org.openide.execution")), 99 }; 100 101 for (int i = 0; i < deps.length; i++) { 102 for (int j = 0; j < deps.length; j++) { 103 int locNameResult = Collator.getInstance().compare( 104 deps[i].getModuleEntry().getLocalizedName(), 105 deps[j].getModuleEntry().getLocalizedName()); 106 int realResult = ModuleDependency.LOCALIZED_NAME_COMPARATOR.compare(deps[i], deps[j]); 107 assertTrue("ordering works: " + deps[i] + " <--> " + deps[j], 108 locNameResult > 0 ? realResult > 0 : 109 (locNameResult == 0 ? realResult == 0 : realResult < 0)); 110 } 112 } 113 } 114 115 public void testSpecVersionBaseSourceEntries() throws Exception { SuiteProject suite = generateSuite("suite"); 117 NbModuleProject p = TestBase.generateSuiteComponent(suite, "module"); 118 ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile()); 119 ModuleEntry e = ml.getEntry("org.example.module"); 120 assertNotNull("have entry", e); 121 ModuleDependency dep = new ModuleDependency(e); 122 assertEquals("right initial spec vers from manifest", "1.0", dep.getSpecificationVersion()); 123 EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 124 ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.1.0"); 125 p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 126 EditableManifest em = Util.loadManifest(p.getManifestFile()); 127 em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null); 128 Util.storeManifest(p.getManifestFile(), em); 129 ProjectManager.getDefault().saveProject(p); 130 dep = new ModuleDependency(e); 131 assertEquals("right spec.version.base", "1.1", dep.getSpecificationVersion()); 132 ep.setProperty(SingleModuleProperties.SPEC_VERSION_BASE, "1.2.0"); 133 p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 134 ProjectManager.getDefault().saveProject(p); 135 dep = new ModuleDependency(e); 136 assertEquals("right modified spec.version.base", "1.2", dep.getSpecificationVersion()); 137 dep = new ModuleDependency(e, null, "1.0", true, false); 138 assertEquals("right explicit spec vers", "1.0", dep.getSpecificationVersion()); 139 } 140 141 public void testAppropriateDefaultCompileDependency() throws Exception { NbModuleProject p = generateStandaloneModule("module"); 143 ModuleList ml = ModuleList.getModuleList(p.getProjectDirectoryFile()); 144 ModuleDependency d = new ModuleDependency(ml.getEntry("org.example.module")); 145 assertFalse("no public packages -> no compile dependency by default", d.hasCompileDependency()); 146 } 147 148 } 149 | Popular Tags |