1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.io.File ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.jar.Manifest ; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.junit.NbTestCase; 33 import org.netbeans.modules.apisupport.project.EditableManifest; 34 import org.netbeans.modules.apisupport.project.ManifestManager; 35 import org.netbeans.modules.apisupport.project.NbModuleProject; 36 import org.netbeans.modules.apisupport.project.TestBase; 37 import org.netbeans.modules.apisupport.project.Util; 38 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 39 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo; 40 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 41 import org.openide.modules.Dependency; 42 import org.openide.modules.SpecificationVersion; 43 44 48 public class SuiteCustomizerLibrariesTest extends NbTestCase { 49 50 public SuiteCustomizerLibrariesTest(String name) { 51 super(name); 52 } 53 54 private NbPlatform platform; 55 private SuiteProject suite; 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 clearWorkDir(); 60 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 62 File install = new File (getWorkDir(), "install"); 63 TestBase.makePlatform(install); 64 Manifest mani = new Manifest (); 66 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "foo/1"); 67 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, "1.0"); 68 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_IMPLEMENTATION_VERSION, "foo-1"); 69 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, "foo/Bundle.properties"); 70 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_PROVIDES, "tok1, tok1a"); 71 Map contents = new HashMap (); 72 contents.put("foo/Bundle.properties", "OpenIDE-Module-Name=Foo Module"); 73 TestBase.createJar(new File (new File (new File (install, "somecluster"), "modules"), "foo.jar"), contents, mani); 74 mani = new Manifest (); 76 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "bar"); 77 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_REQUIRES, "tok1"); 78 TestBase.createJar(new File (new File (new File (install, "somecluster"), "modules"), "bar.jar"), Collections.EMPTY_MAP, mani); 79 mani = new Manifest (); 81 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "foo2"); 82 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_PROVIDES, "tok1b"); 83 contents = new HashMap (); 84 TestBase.createJar(new File (new File (new File (install, "somecluster"), "modules"), "foo2.jar"), contents, mani); 85 mani = new Manifest (); 87 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "bar2"); 88 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE_NEEDS, "tok1b"); 89 TestBase.createJar(new File (new File (new File (install, "somecluster"), "modules"), "bar2.jar"), Collections.EMPTY_MAP, mani); 90 mani = new Manifest (); 92 mani.getMainAttributes().putValue(ManifestManager.OPENIDE_MODULE, "baz"); 93 mani.getMainAttributes().putValue("OpenIDE-Module-Module-Dependencies", "foo/1 > 1.0"); 94 mani.getMainAttributes().putValue("OpenIDE-Module-Requires", "org.openide.modules.ModuleFormat1, org.openide.modules.os.Windows"); 95 TestBase.createJar(new File (new File (new File (install, "anothercluster"), "modules"), "baz.jar"), Collections.EMPTY_MAP, mani); 96 platform = NbPlatform.addPlatform("custom", install, "custom"); 97 suite = TestBase.generateSuite(getWorkDir(), "suite", "custom"); 99 NbModuleProject module = TestBase.generateSuiteComponent(suite, "module1"); 101 EditableManifest em = Util.loadManifest(module.getManifestFile()); 102 em.setAttribute(ManifestManager.OPENIDE_MODULE, "org.example.module1/2", null); 103 em.setAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, "2.0", null); 104 em.setAttribute(ManifestManager.OPENIDE_MODULE_PROVIDES, "tok2", null); 105 Util.storeManifest(module.getManifestFile(), em); 106 LocalizedBundleInfo lbinfo = ((LocalizedBundleInfo.Provider) module.getLookup().lookup(LocalizedBundleInfo.Provider.class)).getLocalizedBundleInfo(); 107 lbinfo.setDisplayName("Module One"); 108 lbinfo.store(); 109 module = TestBase.generateSuiteComponent(suite, "module2"); 111 em = Util.loadManifest(module.getManifestFile()); 112 em.removeAttribute(ManifestManager.OPENIDE_MODULE_SPECIFICATION_VERSION, null); 113 em.setAttribute(ManifestManager.OPENIDE_MODULE_REQUIRES, "tok2", null); 114 Util.storeManifest(module.getManifestFile(), em); 115 lbinfo = ((LocalizedBundleInfo.Provider) module.getLookup().lookup(LocalizedBundleInfo.Provider.class)).getLocalizedBundleInfo(); 116 lbinfo.setDisplayName("Module Two"); 117 lbinfo.store(); 118 module = TestBase.generateSuiteComponent(suite, "module3"); 120 Util.addDependency(module, "org.example.module2"); 121 Util.addDependency(module, "bar"); 122 lbinfo = ((LocalizedBundleInfo.Provider) module.getLookup().lookup(LocalizedBundleInfo.Provider.class)).getLocalizedBundleInfo(); 123 lbinfo.setDisplayName("Module Three"); 124 lbinfo.store(); 125 ProjectManager.getDefault().saveAllProjects(); 126 } 127 128 public void testUniverseModules() throws Exception { Set modules = SuiteCustomizerLibraries.loadUniverseModules(platform.getModules(), SuiteUtils.getSubProjects(suite)); 130 Map modulesByName = new HashMap (); 131 for (Iterator it = modules.iterator(); it.hasNext(); ) { 132 SuiteCustomizerLibraries.UniverseModule m = (SuiteCustomizerLibraries.UniverseModule) it.next(); 133 modulesByName.put(m.getCodeNameBase(), m); 134 } 135 assertEquals(modules.size(), modulesByName.size()); 136 SuiteCustomizerLibraries.UniverseModule m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("core"); 137 assertNotNull(m); 138 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("foo"); 140 assertNotNull(m); 141 assertEquals("somecluster", m.getCluster()); 142 assertEquals("Foo Module", m.getDisplayName()); 143 assertEquals(1, m.getReleaseVersion()); 144 assertEquals(new SpecificationVersion("1.0"), m.getSpecificationVersion()); 145 assertEquals("foo-1", m.getImplementationVersion()); 146 assertEquals(new HashSet (Arrays.asList(new String [] {"tok1", "tok1a"})), m.getProvidedTokens()); 147 assertEquals(Collections.EMPTY_SET, m.getRequiredTokens()); 148 assertEquals(Collections.EMPTY_SET, m.getModuleDependencies()); 149 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("bar"); 150 assertNotNull(m); 151 assertEquals(Collections.EMPTY_SET, m.getProvidedTokens()); 152 assertEquals(Collections.singleton("tok1"), m.getRequiredTokens()); 153 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("baz"); 154 assertNotNull(m); 155 assertEquals(Dependency.create(Dependency.TYPE_MODULE, "foo/1 > 1.0"), m.getModuleDependencies()); 156 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module1"); 157 assertNotNull(m); 158 assertNull(m.getCluster()); 159 assertEquals("Module One", m.getDisplayName()); 160 assertEquals(2, m.getReleaseVersion()); 161 assertEquals(new SpecificationVersion("2.0"), m.getSpecificationVersion()); 162 assertNull(m.getImplementationVersion()); 163 assertEquals(Collections.singleton("tok2"), m.getProvidedTokens()); 164 assertEquals(Collections.EMPTY_SET, m.getRequiredTokens()); 165 assertEquals(Collections.EMPTY_SET, m.getModuleDependencies()); 166 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module2"); 167 assertNotNull(m); 168 assertEquals(-1, m.getReleaseVersion()); 169 assertNull(m.getSpecificationVersion()); 170 assertNull(m.getImplementationVersion()); 171 assertEquals(Collections.EMPTY_SET, m.getProvidedTokens()); 172 assertEquals(Collections.singleton("tok2"), m.getRequiredTokens()); 173 m = (SuiteCustomizerLibraries.UniverseModule) modulesByName.get("org.example.module3"); 174 assertNotNull(m); 175 assertEquals(Dependency.create(Dependency.TYPE_MODULE, "org.example.module2, bar"), m.getModuleDependencies()); 176 } 177 178 public void testDependencyWarnings() throws Exception { Set modules = SuiteCustomizerLibraries.loadUniverseModules(platform.getModules(), SuiteUtils.getSubProjects(suite)); 180 Set bothClusters = new HashSet (Arrays.asList(new String [] {"somecluster", "anothercluster"})); 181 assertEquals(null, join(SuiteCustomizerLibraries.findWarning(modules, bothClusters, Collections.EMPTY_SET))); 182 assertEquals("[ERR_platform_excluded_dep, baz, anothercluster, Foo Module, somecluster]", 183 join(SuiteCustomizerLibraries.findWarning(modules, Collections.singleton("anothercluster"), Collections.EMPTY_SET))); 184 assertNull(join(SuiteCustomizerLibraries.findWarning(modules, Collections.singleton("somecluster"), Collections.EMPTY_SET))); 185 assertEquals("[ERR_suite_excluded_dep, Module Three, bar, somecluster]", 186 join(SuiteCustomizerLibraries.findWarning(modules, Collections.EMPTY_SET, Collections.EMPTY_SET))); 187 assertEquals("[ERR_platform_only_excluded_providers, tok1, bar, somecluster, Foo Module, somecluster]", 188 join(SuiteCustomizerLibraries.findWarning(modules, bothClusters, Collections.singleton("foo")))); 189 assertEquals("[ERR_platform_only_excluded_providers, tok1b, bar2, somecluster, foo2, somecluster]", 190 join(SuiteCustomizerLibraries.findWarning(modules, bothClusters, Collections.singleton("foo2")))); 191 } 193 194 private static String join(String [] elements) { 195 if (elements != null) { 196 return Arrays.asList(elements).toString(); 197 } else { 198 return null; 199 } 200 } 201 202 } 203 | Popular Tags |