Index: src/org/netbeans/modules/apisupport/project/ui/UIUtil.java =================================================================== RCS file: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UIUtil.java,v retrieving revision 1.20 diff -u -w -r1.20 UIUtil.java --- src/org/netbeans/modules/apisupport/project/ui/UIUtil.java 9 Dec 2005 19:17:25 -0000 1.20 +++ src/org/netbeans/modules/apisupport/project/ui/UIUtil.java 14 Dec 2005 12:33:36 -0000 @@ -313,7 +313,7 @@ public int compareTo(Object o) { int res = Collator.getInstance().compare(getDisplayName(), ((LayerItemPresenter) o).getDisplayName()); - if (res != -1) { + if (res != 0) { return res; } else { return getFullPath().compareTo(((LayerItemPresenter) o).getFullPath()); Index: src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependency.java =================================================================== RCS file: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependency.java,v retrieving revision 1.15 diff -u -w -r1.15 ModuleDependency.java --- src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependency.java 9 Dec 2005 19:17:25 -0000 1.15 +++ src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependency.java 14 Dec 2005 12:33:36 -0000 @@ -90,7 +90,7 @@ int result = LOC_COLLATOR.compare( getModuleEntry().getLocalizedName(), ((ModuleDependency) o).getModuleEntry().getLocalizedName()); - if (result != -1) { + if (result != 0) { return result; } else { return getModuleEntry().getCodeNameBase().compareTo(((ModuleDependency) o).getModuleEntry().getCodeNameBase()); Index: src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactory.java =================================================================== RCS file: /cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactory.java,v retrieving revision 1.4 diff -u -w -r1.4 PlatformComponentFactory.java --- src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactory.java 9 Dec 2005 19:17:24 -0000 1.4 +++ src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactory.java 14 Dec 2005 12:33:36 -0000 @@ -144,7 +144,7 @@ Arrays.sort(platforms, new Comparator() { public int compare(Object o1, Object o2) { int res = Collator.getInstance().compare(((NbPlatform) o1).getLabel(), ((NbPlatform) o2).getLabel()); - if (res != -1) { + if (res != 0) { return res; } else { return System.identityHashCode(o1) - System.identityHashCode(o2); Index: test/unit/src/org/netbeans/modules/apisupport/project/BrokenPlatformReferenceTest.java =================================================================== RCS file: /cvs/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/BrokenPlatformReferenceTest.java,v retrieving revision 1.5 diff -u -w -r1.5 BrokenPlatformReferenceTest.java --- test/unit/src/org/netbeans/modules/apisupport/project/BrokenPlatformReferenceTest.java 6 Dec 2005 02:38:03 -0000 1.5 +++ test/unit/src/org/netbeans/modules/apisupport/project/BrokenPlatformReferenceTest.java 14 Dec 2005 12:33:36 -0000 @@ -14,9 +14,7 @@ package org.netbeans.modules.apisupport.project; import java.io.File; -import java.io.IOException; import java.util.Collections; -import java.util.jar.Manifest; import org.netbeans.api.project.ProjectManager; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.apisupport.project.suite.SuiteProject; @@ -55,24 +53,16 @@ user.mkdirs(); System.setProperty("netbeans.user", user.getAbsolutePath()); install = new File(getWorkDir(), "install"); - makePlatform(install); + TestBase.makePlatform(install); // Now set up build.properties accordingly: InstalledFileLocatorImpl.registerDestDir(install); ((Install) SharedClassObject.findObject(Install.class, true)).restored(); assertEquals("set up run correctly", install.getAbsolutePath(), PropertyUtils.getGlobalProperties().getProperty("nbplatform.default.netbeans.dest.dir")); install2 = new File(getWorkDir(), "install2"); - makePlatform(install2); + TestBase.makePlatform(install2); NbPlatform.addPlatform("install2", install2, "install2"); } - private static void makePlatform(File d) throws IOException { - // To satisfy NbPlatform.defaultPlatformLocation and NbPlatform.isValid, and make at least one module: - Manifest mani = new Manifest(); - mani.getMainAttributes().putValue("OpenIDE-Module", "core"); - TestBase.createJar(new File(new File(new File(d, "platform"), "core"), "core.jar"), Collections.EMPTY_MAP, mani); - TestBase.dump(new File(new File(d, "harness"), "suite.xml"), ""); - } - /** Make sure everything is working as expected when there are no breakages. */ public void testEverythingNormal() throws Exception { // Try making a standalone module w/ default platform, confirm loaded OK. Index: test/unit/src/org/netbeans/modules/apisupport/project/TestBase.java =================================================================== RCS file: /cvs/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/TestBase.java,v retrieving revision 1.28 diff -u -w -r1.28 TestBase.java --- test/unit/src/org/netbeans/modules/apisupport/project/TestBase.java 6 Dec 2005 02:37:55 -0000 1.28 +++ test/unit/src/org/netbeans/modules/apisupport/project/TestBase.java 14 Dec 2005 12:33:36 -0000 @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -392,6 +393,14 @@ } } + public static void makePlatform(File d) throws IOException { + // To satisfy NbPlatform.defaultPlatformLocation and NbPlatform.isValid, and make at least one module: + Manifest mani = new Manifest(); + mani.getMainAttributes().putValue("OpenIDE-Module", "core"); + TestBase.createJar(new File(new File(new File(d, "platform"), "core"), "core.jar"), Collections.EMPTY_MAP, mani); + TestBase.dump(new File(new File(d, "harness"), "suite.xml"), ""); + } + public static void delete(File f) throws IOException { if (f.isDirectory()) { File[] kids = f.listFiles(); Index: test/unit/src/org/netbeans/modules/apisupport/project/ui/UIUtilTest.java =================================================================== RCS file: /cvs/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ui/UIUtilTest.java,v retrieving revision 1.3 diff -u -w -r1.3 UIUtilTest.java --- test/unit/src/org/netbeans/modules/apisupport/project/ui/UIUtilTest.java 31 Oct 2005 13:36:56 -0000 1.3 +++ test/unit/src/org/netbeans/modules/apisupport/project/ui/UIUtilTest.java 14 Dec 2005 12:33:36 -0000 @@ -18,8 +18,13 @@ import javax.swing.ComboBoxModel; import javax.swing.KeyStroke; import org.netbeans.api.project.Project; +import org.netbeans.modules.apisupport.project.NbModuleProject; import org.netbeans.modules.apisupport.project.TestBase; import org.netbeans.modules.apisupport.project.layers.LayerTestBase; +import org.netbeans.modules.apisupport.project.layers.LayerUtils; +import org.netbeans.modules.apisupport.project.ui.UIUtil.LayerItemPresenter; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; /** * @author Martin Krauskopf @@ -59,8 +64,26 @@ assertKeyLogicalString("ENTER", "pressed ENTER"); } - public void assertKeyLogicalString(String expected, String swingKeyStroke) { + private void assertKeyLogicalString(String expected, String swingKeyStroke) { assertEquals(swingKeyStroke + " corresponding to " + expected, expected, UIUtil.keyToLogicalString(KeyStroke.getKeyStroke(swingKeyStroke))); + } + + public void testLayerItemPresenterCompareTo() throws Exception { + TestBase.initializeBuildProperties(getWorkDir()); + NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module"); + FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(project); + FileObject root = fs.getRoot().getFileObject("Templates/Project/APISupport"); + FileObject module = root.getFileObject("emptyModule"); + FileObject suite = root.getFileObject("emptySuite"); + FileObject library = root.getFileObject("libraryModule"); + LayerItemPresenter moduleLIP = new LayerItemPresenter(module, root); + LayerItemPresenter moduleLIP1 = new LayerItemPresenter(module, root); + LayerItemPresenter suiteLIP = new LayerItemPresenter(suite, root); + LayerItemPresenter libraryLIP = new LayerItemPresenter(library, root); + assertTrue("'Module Project' < 'Module Suite Project'", moduleLIP.compareTo(suiteLIP) < 0); + assertTrue("'Module Project' == 'Module Project'", moduleLIP.compareTo(moduleLIP1) == 0); + assertTrue("'Library Wrapper Module Project < 'Module Project'", libraryLIP.compareTo(moduleLIP) < 0); + assertTrue("'Library Wrapper Module Project < 'Module Suite Project'", libraryLIP.compareTo(suiteLIP) < 0); } } Index: test/unit/src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependencyTest.java =================================================================== RCS file: test/unit/src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependencyTest.java diff -N test/unit/src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependencyTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/unit/src/org/netbeans/modules/apisupport/project/ui/customizer/ModuleDependencyTest.java 14 Dec 2005 12:33:36 -0000 @@ -0,0 +1,59 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.apisupport.project.ui.customizer; + +import java.text.Collator; +import org.netbeans.modules.apisupport.project.NbModuleProject; +import org.netbeans.modules.apisupport.project.TestBase; +import org.netbeans.modules.apisupport.project.universe.ModuleList; +import org.openide.filesystems.FileUtil; + +/** + * @author Martin Krauskopf + */ +public class ModuleDependencyTest extends TestBase { + + public ModuleDependencyTest(String testName) { + super(testName); + } + + public void testCompareTo() throws Exception { + NbModuleProject module = TestBase.generateStandaloneModule(getWorkDir(), "module"); + ModuleList ml = ModuleList.getModuleList(FileUtil.toFile(module.getProjectDirectory())); + ModuleDependency[] deps = new ModuleDependency[] { + new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")), + new ModuleDependency(ml.getEntry("org.openide.loaders")), + new ModuleDependency(ml.getEntry("org.apache.tools.ant.module")), + new ModuleDependency(ml.getEntry("org.openide.io")), + new ModuleDependency(ml.getEntry("org.jdesktop.layout")), + new ModuleDependency(ml.getEntry("org.openide.filesystems")), + new ModuleDependency(ml.getEntry("org.openide.execution")), + }; + + for (int i = 0; i < deps.length; i++) { + for (int j = 0; j < deps.length; j++) { + int locNameResult = Collator.getInstance().compare( + deps[i].getModuleEntry().getLocalizedName(), + deps[j].getModuleEntry().getLocalizedName()); + int realResult = deps[i].compareTo(deps[j]); + assertTrue("ordering works: " + deps[i] + " <--> " + deps[j], + locNameResult > 0 ? realResult > 0 : + (locNameResult == 0 ? realResult == 0 : realResult < 0)); +// (int) Math.signum(locNameResult), (int) Math.signum(realResult)); + } + } + + } + +} Index: test/unit/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactoryTest.java =================================================================== RCS file: test/unit/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactoryTest.java diff -N test/unit/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactoryTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/unit/src/org/netbeans/modules/apisupport/project/ui/platform/PlatformComponentFactoryTest.java 14 Dec 2005 12:33:36 -0000 @@ -0,0 +1,54 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.apisupport.project.ui.platform; + +import java.io.File; +import org.netbeans.modules.apisupport.project.TestBase; +import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory.NbPlatformListModel; +import org.netbeans.modules.apisupport.project.universe.NbPlatform; + +/** + * @author Martin Krauskopf + */ +public class PlatformComponentFactoryTest extends TestBase { + + public PlatformComponentFactoryTest(String testName) { + super(testName); + } + + public void testNbPlatformListModelSorting() throws Exception { + File first = new File(getWorkDir(), "first"); + TestBase.makePlatform(first); + NbPlatform.addPlatform("first", first, "AAA first"); + + File between = new File(getWorkDir(), "between"); + TestBase.makePlatform(between); + NbPlatform.addPlatform("between", between, "KKK between"); + + File last = new File(getWorkDir(), "last"); + TestBase.makePlatform(last); + NbPlatform.addPlatform("last", last, "ZZZ last"); + + NbPlatform.reset(); + + NbPlatformListModel model = new NbPlatformListModel(); + assertEquals("four platforms " + NbPlatform.getPlatforms(), 5, model.getSize()); + assertSame("first (AAA first)", NbPlatform.getPlatformByID("first"), model.getElementAt(0)); + assertSame("second (Invalid Platform)", NbPlatform.getPlatformByID("custom"), model.getElementAt(1)); + assertSame("third (KKK between)", NbPlatform.getPlatformByID("between"), model.getElementAt(2)); + assertSame("fourth (NetBeans IDE....)", NbPlatform.getDefaultPlatform(), model.getElementAt(3)); + assertSame("fifth (ZZZ last)", NbPlatform.getPlatformByID("last"), model.getElementAt(4)); + } + +}