# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/tomas/nb_src/apisupport/project # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java *** /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java Base (1.35) --- /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ProjectXMLManagerTest.java Locally Modified (Based On 1.35) *************** *** 28,33 **** --- 28,34 ---- import java.util.Collections; import java.util.HashSet; import java.util.Iterator; + import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; *************** *** 37,43 **** --- 38,46 ---- import org.netbeans.api.project.ProjectManager; import org.netbeans.modules.apisupport.project.ui.customizer.ModuleDependency; import org.netbeans.modules.apisupport.project.universe.ModuleEntry; + import org.netbeans.modules.apisupport.project.universe.ModuleList; import org.netbeans.modules.apisupport.project.universe.NbPlatform; + import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; *************** *** 472,477 **** --- 475,576 ---- validate(testingProject, true); } + + public void testRemoveTestDependency() throws Exception { + final String UNIT = TestModuleDependency.UNIT; + final String QAFUNC = TestModuleDependency.QA_FUNCTIONAL; + final NbModuleProject testingProject = generateTestingProject(); + final ProjectXMLManager pxm = new ProjectXMLManager(testingProject); + final String cnb = "org.netbeans.modules.java.project"; + final String cnb2 = "org.netbeans.modules.project.ant"; + File projectDir = FileUtil.toFile(testingProject.getProjectDirectory()); + ModuleList ml = ModuleList.getModuleList(projectDir); + ModuleEntry meJP = testingProject.getModuleList().getEntry(cnb); + ModuleEntry meAnt = testingProject.getModuleList().getEntry(cnb2); + TestModuleDependency tdJP_001 = new TestModuleDependency(meJP, false, false, true); + TestModuleDependency tdAnt_111 = new TestModuleDependency(meAnt, true, true, true); + //add two unit test dependencies + pxm.addTestDependency(UNIT, tdJP_001); + pxm.addTestDependency(UNIT, tdAnt_111); + ProjectManager.getDefault().saveProject(testingProject); + //try wrong usage of remove + assertFalse("no such cnb under QA func.", pxm.removeTestDependency(QAFUNC, cnb)); + assertFalse("no such cnb under UNIT func.", pxm.removeTestDependency(UNIT, "someCNB")); + Set setBefore = (Set) pxm.getTestDependencies(ml).get(UNIT); + assertEquals("unit test type contains two TD", 2 , setBefore.size()); + //remove first one + assertTrue("one should be found && removed", pxm.removeTestDependency(UNIT, cnb)); + ProjectManager.getDefault().saveProject(testingProject); + //try to remove just removed + assertFalse("this was just removed", pxm.removeTestDependency(UNIT, cnb)); + Set setNow = (Set) pxm.getTestDependencies(ml).get(UNIT); + assertEquals("unit test type contains one TD", 1 , setNow.size()); + //remove last one + assertTrue("all unit test deps have been removed", pxm.removeTestDependency(UNIT, cnb2)); + ProjectManager.getDefault().saveProject(testingProject); + Set setAfter = (Set) pxm.getTestDependencies(ml).get(UNIT); + assertTrue("unit test type is empty now", setAfter.isEmpty()); + } + + public void testAddTestDependency () throws Exception{ + final String UNIT = TestModuleDependency.UNIT; + final String QAFUNC = TestModuleDependency.QA_FUNCTIONAL; + + final NbModuleProject testingProject = generateTestingProject(); + final ProjectXMLManager pxm = new ProjectXMLManager(testingProject); + File projectDir = FileUtil.toFile(testingProject.getProjectDirectory()); + ModuleList ml = ModuleList.getModuleList(projectDir); + ModuleEntry meJP = testingProject.getModuleList().getEntry( + "org.netbeans.modules.java.project"); + ModuleEntry meAnt = testingProject.getModuleList().getEntry( + "org.netbeans.modules.project.ant"); + ModuleEntry meDialogs = testingProject.getModuleList().getEntry( + "org.openide.dialogs"); + + TestModuleDependency tdJP_001 = new TestModuleDependency(meJP, false, false, true); + TestModuleDependency tdJP_010 = new TestModuleDependency(meJP, false, true, false); + TestModuleDependency tdAnt_111 = new TestModuleDependency(meAnt, true, true, true); + TestModuleDependency tdDialogs_000 = new TestModuleDependency(meDialogs, false, false, false); + + Map mapOfTD; + HashSet unitTD; + HashSet qafuncTD; + + mapOfTD = pxm.getTestDependencies(ml); + assertTrue("currently no TD", mapOfTD.isEmpty()); + //first, add one unit test dep + pxm.addTestDependency(UNIT, tdJP_001); + ProjectManager.getDefault().saveProject(testingProject); + mapOfTD = pxm.getTestDependencies(ml); + assertEquals("map has already unit test type", 1, mapOfTD.size()); + unitTD = (HashSet) mapOfTD.get(UNIT); + qafuncTD = (HashSet) mapOfTD.get(QAFUNC); + assertEquals("set with unit TD has one TD", 1, unitTD.size()); + assertNull("set with qafunc TD does not exist", qafuncTD); + //now add 2 other unit test dep; + pxm.addTestDependency(UNIT, tdDialogs_000); + ProjectManager.getDefault().saveProject(testingProject); + pxm.addTestDependency(UNIT, tdAnt_111); + ProjectManager.getDefault().saveProject(testingProject); + mapOfTD = pxm.getTestDependencies(ml); + assertEquals("map still has only unit test type", 1, mapOfTD.size()); + unitTD = (HashSet) mapOfTD.get(UNIT); + assertEquals("set with unit TD has now three TD", 3, unitTD.size()); + //now add qa-func test dependency + pxm.addTestDependency(QAFUNC, tdJP_010); + ProjectManager.getDefault().saveProject(testingProject); + mapOfTD = pxm.getTestDependencies(ml); + unitTD = (HashSet) mapOfTD.get(UNIT); + qafuncTD = (HashSet) mapOfTD.get(QAFUNC); + assertEquals("map has both test types", 2, mapOfTD.size()); + assertEquals("set with unit TD has still three TD", 3, unitTD.size()); + assertEquals("set with qafunc TD has one TD", 1, qafuncTD.size()); + //TODO: rewrite order checking method to be able to check properly test dependencies order + validate(testingProject, false); + } + + + private NbModuleProject generateTestingProject() throws Exception { FileObject fo = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "testing"); FileObject projectXMLFO = fo.getFileObject("nbproject/project.xml"); Index: src/org/netbeans/modules/apisupport/project/ui/Bundle.properties *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties Base (1.40) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/Bundle.properties Locally Modified (Based On 1.40) *************** *** 63,68 **** --- 63,69 ---- LBL_extra_javadoc_files=Extra Javadoc Files LBL_important_files=Important Files LBL_libraries=Libraries + LBL_unit_test_libraries=Unit Test Libraries LBL_module_manifest=Module Manifest LBL_arch_desc=Architecture Description LBL_api_changes=API Changes *************** *** 92,97 **** --- 93,103 ---- CTL_NeededToCompile=Needed to compile CTL_MajorReleaseVersion=Major release version: {0} CTL_SpecificationVersion=Specification version: {0} + #Unit test dependency node + CTL_test=Include also tests of module + CTL_compile=Compile-time dependency + CTL_recursive=Include dependencies recursively + CTL_AddTestDependency=Add Unit Test Dependency # SuiteActions SUITE_ACTION_build=Build All Index: test/unit/src/org/netbeans/modules/apisupport/project/universe/TestModuleDependencyTest.java *** /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestModuleDependencyTest.java No Base Revision --- /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/universe/TestModuleDependencyTest.java Locally New *************** *** 1,0 **** --- 1,125 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.apisupport.project.universe; + + import org.netbeans.api.project.ProjectManager; + import org.netbeans.modules.apisupport.project.NbModuleProject; + import org.netbeans.modules.apisupport.project.TestBase; + import org.openide.filesystems.FileObject; + + + /** + * + * @author Tomas Musil + */ + public class TestModuleDependencyTest extends TestBase { + + private final static String ANT_PROJECT_SUPPORT = "org.netbeans.modules.project.ant"; + private final static String DIALOGS = "org.openide.dialogs"; + private TestModuleDependency tdJP_001; + private TestModuleDependency tdJP_101; + private TestModuleDependency tdJP_101otherInstance; + private TestModuleDependency tdAnt_111; + + public TestModuleDependencyTest(String testName) { + super(testName); + } + + protected void setUp() throws Exception { + clearWorkDir(); + super.setUp(); + final NbModuleProject testingProject = generateTestingProject(); + final String cnb = "org.netbeans.modules.java.project"; + final String cnb2 = "org.netbeans.modules.project.ant"; + ModuleEntry meJP = testingProject.getModuleList().getEntry(cnb); + ModuleEntry meAnt = testingProject.getModuleList().getEntry(cnb2); + tdJP_001 = new TestModuleDependency(meJP, false, false, true); + tdJP_101 = new TestModuleDependency(meJP, true, false, true); + tdJP_101otherInstance = new TestModuleDependency(meJP, true, false, true); + tdAnt_111 = new TestModuleDependency(meAnt, true, true, true); + } + + + public void testEquals() throws Exception{ + assertFalse("001!=101" , tdJP_001.equals((TestModuleDependency)tdJP_101)); + assertTrue("these are equal", tdJP_101.equals((TestModuleDependency)tdJP_101otherInstance)); + assertFalse(tdAnt_111.equals(null)); + assertFalse(tdAnt_111.equals("")); + } + + public void testCompareTo() { + assertEquals("equals", 0, tdJP_101.compareTo((TestModuleDependency) tdJP_101otherInstance)); + assertTrue("o.n.m.java.project < o.n.m.project.ant", tdJP_001.compareTo(tdAnt_111) < 0); + assertTrue("o.n.m.project.ant > o.n.m.java.project", tdAnt_111.compareTo(tdJP_101) > 0); + } + + public void testHashCode() { + assertEquals("the same hashcodes", tdJP_101.hashCode(),tdJP_101otherInstance.hashCode()); + assertTrue("the same hashcodes", tdJP_101.hashCode() == tdJP_001.hashCode()); + assertTrue("different hashcodes", tdJP_101.hashCode() != tdAnt_111.hashCode()); + } + + private NbModuleProject generateTestingProject() throws Exception { + FileObject fo = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "testing"); + FileObject projectXMLFO = fo.getFileObject("nbproject/project.xml"); + String xml = "\n" + + "\n" + + "org.netbeans.modules.apisupport.project\n" + + "\n" + + "\n" + + "org.example.testing\n" + + "\n" + + "\n" + + "\n" + + "" + DIALOGS + "\n" + + "\n" + + "\n" + + "\n" + + "6.2\n" + + "\n" + + "\n" + + "\n" + + "" + ANT_PROJECT_SUPPORT + "\n" + + "\n" + + "\n" + + "\n" + + "1\n" + + "1.10\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "org.module.examplemodule\n" + + "org.netbeans.examples.modules.misc\n" + + "\n" + + "\n" + + "ext/jsr88javax.jar\n" + + "../external/jsr88javax.jar\n" + + "\n" + + "\n" + + "\n" + + "\n"; + TestBase.dump(projectXMLFO, xml); + return (NbModuleProject) ProjectManager.getDefault().findProject(fo); + } + + + } Index: src/org/netbeans/modules/apisupport/project/ui/LibrariesNode.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNode.java Base (1.14) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/LibrariesNode.java Locally Modified (Based On 1.14) *************** *** 49,54 **** --- 49,55 ---- import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; import org.netbeans.modules.apisupport.project.universe.ModuleEntry; import org.netbeans.modules.apisupport.project.universe.NbPlatform; + import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; import org.netbeans.spi.java.project.support.ui.PackageView; import org.netbeans.spi.project.support.ant.AntProjectEvent; import org.netbeans.spi.project.support.ant.AntProjectHelper; *************** *** 282,288 **** private final NbModuleProject project; ProjectDependencyNode(final ModuleDependency dep, final NbModuleProject project) { ! super(Children.LEAF, Lookups.fixed(new Object[] { dep, project })); this.dep = dep; this.project = project; ModuleEntry me = dep.getModuleEntry(); --- 283,289 ---- private final NbModuleProject project; ProjectDependencyNode(final ModuleDependency dep, final NbModuleProject project) { ! super(Children.LEAF, Lookups.fixed(new Object[] { dep, project, dep.getModuleEntry() })); this.dep = dep; this.project = project; ModuleEntry me = dep.getModuleEntry(); *************** *** 473,488 **** } ! private static final class OpenProjectAction extends CookieAction { protected void performAction(Node[] activatedNodes) { try { final Project[] projects = new Project[activatedNodes.length]; for (int i = 0; i < activatedNodes.length; i++) { ! ModuleDependency dep = (ModuleDependency) activatedNodes[i]. ! getLookup().lookup(ModuleDependency.class); ! assert dep != null; ! File prjDir = dep.getModuleEntry().getSourceLocation(); assert prjDir != null; Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDir)); assert project != null; --- 474,488 ---- } ! static final class OpenProjectAction extends CookieAction { protected void performAction(Node[] activatedNodes) { try { final Project[] projects = new Project[activatedNodes.length]; for (int i = 0; i < activatedNodes.length; i++) { ! ModuleEntry me = (ModuleEntry) activatedNodes[i].getLookup().lookup(ModuleEntry.class); ! assert me != null; ! File prjDir = me.getSourceLocation(); assert prjDir != null; Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDir)); assert project != null; *************** *** 521,527 **** } protected Class[] cookieClasses() { ! return new Class[] { ModuleDependency.class }; } } --- 521,527 ---- } protected Class[] cookieClasses() { ! return new Class[] { ModuleDependency.class, TestModuleDependency.class }; } } Index: src/org/netbeans/modules/apisupport/project/ui/customizer/Bundle.properties *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/Bundle.properties Base (1.80) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/Bundle.properties Locally Modified (Based On 1.80) *************** *** 304,306 **** --- 304,316 ---- ERR_platform_no_providers=Module {1} in cluster {2} requests the token {0} but there are no known providers. ERR_suite_no_providers=Module {1} requests the token {0} but there are no known providers. + # edit test dependency + EditTestDependencyPanel.moduleJar.text=&Module JAR\: + EditTestDependencyPanel.tests.text=Include &Tests of Module + EditTestDependencyPanel.moduleJarValue.text= + EditTestDependencyPanel.dependencies.text=Include Dependencies &Recursively + EditTestDependencyPanel.compile.text=Include in &Compile Classpath + EditTestDependencyPanel.tests.AccessibleContext.accessibleDescription=includes also tests of module + EditTestDependencyPanel.dependencies.AccessibleContext.accessibleDescription=includes dependencies recursively + EditTestDependencyPanel.compile.AccessibleContext.accessibleDescription=includes in compile classpath + EditTestDependencyPanel.moduleJar.AccessibleContext.accessibleDescription=Jar representing module Index: src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java No Base Revision --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNode.java Locally New *************** *** 1,0 **** --- 1,529 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.apisupport.project.ui; + + import java.awt.Dialog; + import java.awt.Image; + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; + import java.io.File; + import java.io.IOException; + import java.net.URL; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Collections; + import java.util.HashMap; + import java.util.HashSet; + import java.util.Iterator; + import java.util.LinkedHashSet; + import java.util.List; + import java.util.Map; + import java.util.Set; + import java.util.SortedSet; + import java.util.TreeSet; + import javax.swing.AbstractAction; + import javax.swing.Action; + import javax.swing.Icon; + import javax.swing.ImageIcon; + import org.netbeans.api.project.ProjectManager; + import org.netbeans.modules.apisupport.project.NbModuleProject; + import org.netbeans.modules.apisupport.project.ProjectXMLManager; + import org.netbeans.modules.apisupport.project.Util; + import org.netbeans.modules.apisupport.project.ui.customizer.AddModulePanel; + import org.netbeans.modules.apisupport.project.ui.customizer.EditTestDependencyPanel; + import org.netbeans.modules.apisupport.project.ui.customizer.ModuleDependency; + import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; + import org.netbeans.modules.apisupport.project.universe.ModuleEntry; + import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; + import org.netbeans.spi.java.project.support.ui.PackageView; + import org.netbeans.spi.project.support.ant.AntProjectEvent; + import org.netbeans.spi.project.support.ant.AntProjectHelper; + import org.netbeans.spi.project.support.ant.AntProjectListener; + import org.openide.DialogDescriptor; + import org.openide.DialogDisplayer; + import org.openide.ErrorManager; + import org.openide.actions.FindAction; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.URLMapper; + import org.openide.nodes.AbstractNode; + import org.openide.nodes.Children; + import org.openide.nodes.FilterNode; + import org.openide.nodes.Node; + import org.openide.util.HelpCtx; + import org.openide.util.Lookup; + import org.openide.util.Mutex; + import org.openide.util.MutexException; + import org.openide.util.NbBundle; + import org.openide.util.Utilities; + import org.openide.util.actions.CookieAction; + import org.openide.util.actions.SystemAction; + import org.openide.util.lookup.Lookups; + import org.openide.util.lookup.ProxyLookup; + + /** + * @author Tomas Musil + */ + final class UnitTestLibrariesNode extends AbstractNode { + + static final String UNIT_TEST_LIBRARIES_NAME = "unit libraries"; // NOI18N + + private static final String DISPLAY_NAME = getMessage("LBL_unit_test_libraries"); + + private final Action[] actions; + + public UnitTestLibrariesNode(final NbModuleProject project) { + super(new LibrariesChildren(project)); + setName(UNIT_TEST_LIBRARIES_NAME); + setDisplayName(DISPLAY_NAME); + actions = new Action[] { + new AddUnitTestDependencyAction(project) + }; + } + + public Image getIcon(int type) { + return getIcon(false); + } + + public Image getOpenedIcon(int type) { + return getIcon(true); + } + + private Image getIcon(boolean opened) { + Image badge = Utilities.loadImage("org/netbeans/modules/apisupport/project/ui/resources/libraries-badge.png", true); + return Utilities.mergeImages(UIUtil.getTreeFolderIcon(opened), badge, 8, 8); + } + + public Action[] getActions(boolean context) { + return actions; + } + + private static String createHtmlDescription(final TestModuleDependency dep) { + StringBuffer shortDesc = new StringBuffer("" + dep.getModule().getCodeNameBase() + "
"); // NOI18N + if (dep.isTest()) { + shortDesc.append("
" + getMessage("CTL_test")); + } + if (dep.isCompile()) { + shortDesc.append("
").append(getMessage("CTL_compile")); + } + if (dep.isRecursive()) { + shortDesc.append("
").append(getMessage("CTL_recursive")); + } + shortDesc.append(""); // NOI18N + return shortDesc.toString(); + } + + private static String getMessage(String bundleKey) { + return NbBundle.getMessage(UnitTestLibrariesNode.class, bundleKey); + } + + + private static final class LibrariesChildren extends Children.Keys implements AntProjectListener { + + private static final String JUNIT = "junit"; //NOI18N + + private static final String JUNIT_CNB = "org.netbeans.modules.junit"; + + private static final String NBJUNIT = "nbjunit"; //NOI18N + + private static final String NBJUNIT_CNB = "org.netbeans.modules.nbjunit"; + + private static final String LIBRARIES_ICON = + "org/netbeans/modules/apisupport/project/ui/resources/libraries.gif"; // NOI18N + + static final Action REMOVE_DEPENDENCY_ACTION = new RemoveDependencyAction(); + + private final NbModuleProject project; + + private ImageIcon librariesIcon; + + LibrariesChildren(final NbModuleProject project) { + this.project = project; + } + + protected void addNotify() { + super.addNotify(); + project.getHelper().addAntProjectListener(this); + refreshKeys(); + } + + protected void removeNotify() { + setKeys(Collections.EMPTY_SET); + project.getHelper().removeAntProjectListener(this); + super.removeNotify(); + } + + private void refreshKeys() { + try { + ProjectManager.mutex().readAccess(new Mutex.ExceptionAction() { + public Object run() throws Exception { + ProjectXMLManager pxm = new ProjectXMLManager(project); + List keys = new ArrayList(); + if(isModuleInModuleList(JUNIT_CNB)) { + keys.add(JUNIT); + } + if(isModuleInModuleList(NBJUNIT_CNB)) { + keys.add(NBJUNIT); + } + SortedSet deps = new TreeSet(TestModuleDependency.CNB_COMPARATOR); + Set d = pxm.getTestDependencies( + project.getModuleList()).get(TestModuleDependency.UNIT); + //draw only compile time deps + if(d != null){ + for (TestModuleDependency tmd : d) { + if(tmd.isCompile()) { + deps.add(tmd); + }; + } + keys.addAll(deps); + } + setKeys(Collections.unmodifiableList(keys)); + return null; + } + }); + } catch (MutexException e) { + assert false : e.getException(); + } + } + + private boolean isModuleInModuleList(String cnb){ + ModuleEntry me = null; + boolean result = false; + try { + me = project.getModuleList().getEntry(cnb); + if(me != null) { + File moduleJar = me.getJarLocation(); + result = moduleJar.exists(); + + } + } catch (IOException ex) { + java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, + ex.getMessage(), + ex); + }; + return result; + } + + + protected Node[] createNodes(Object key) { + Node node = null; + //special nodes - junit, nbjunit + if (JUNIT.equals(key) || NBJUNIT.equals(key)) { + String cnb = null; + if (JUNIT.equals(key)) { + cnb = JUNIT_CNB; + } else { + cnb = NBJUNIT_CNB; + } + try { + ModuleEntry me = project.getModuleList().getEntry(cnb); + Icon icon = getLibrariesIcon(); // TODO a better icon for JUNIT + File junitJar = me.getJarLocation(); + URL junitURL = Util.urlForJar(junitJar); + assert junitURL != null; + FileObject junitFO = URLMapper.findFileObject(junitURL); + String name = me.getLocalizedName(); + node = ActionFilterNode.create( + PackageView.createPackageView(new LibrariesSourceGroup(junitFO, name, icon, icon))); + node.setName(name); //node does not have a name by default + } catch (IOException ex) { + ex.printStackTrace(); + } + } else { + TestModuleDependency dep = (TestModuleDependency) key; + File srcF = dep.getModule().getSourceLocation(); + if (srcF == null) { + File jarF = dep.getModule().getJarLocation(); + URL jarRootURL = Util.urlForJar(jarF); + assert jarRootURL != null; + FileObject root = URLMapper.findFileObject(jarRootURL); + ModuleEntry me = dep.getModule(); + String name = me.getLocalizedName() + " - " + me.getCodeNameBase(); // NOI18N + Icon icon = getLibrariesIcon(); + Node pvNode = ActionFilterNode.create( + PackageView.createPackageView(new LibrariesSourceGroup(root, name, icon, icon))); + node = new LibraryDependencyNode(dep, project, pvNode); + node.setName(me.getLocalizedName()); + } else { + node = new ProjectDependencyNode(dep, project); + node.setName(dep.getModule().getLocalizedName()); + } + + } + + assert node != null; + return new Node[] { node }; + } + + public void configurationXmlChanged(AntProjectEvent ev) { + // XXX this is a little strange but happens during project move. Bad ordering. + // Probably bug in moving implementation (our or in general Project API). + if (project.getHelper().resolveFileObject(AntProjectHelper.PROJECT_XML_PATH) != null) { + refreshKeys(); + } + } + + public void propertiesChanged(AntProjectEvent ev) { + // do not need + } + + + private Icon getLibrariesIcon() { + if (librariesIcon == null) { + librariesIcon = new ImageIcon(Utilities.loadImage(LIBRARIES_ICON, true)); + } + return librariesIcon; + } + + } + + private static final class ProjectDependencyNode extends AbstractNode { + + private final TestModuleDependency dep; + private final NbModuleProject project; + private Action[] actions; + + ProjectDependencyNode(final TestModuleDependency dep, final NbModuleProject project) { + super(Children.LEAF, Lookups.fixed(new Object[] { dep, project, dep.getModule()})); + this.dep = dep; + this.project = project; + ModuleEntry me = dep.getModule(); + setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH); + setDisplayName(me.getLocalizedName()); + setShortDescription(UnitTestLibrariesNode.createHtmlDescription(dep)); + } + + public Action[] getActions(boolean context) { + + if (actions == null) { + Set result = new LinkedHashSet(); + // Open project action + result.add(SystemAction.get(LibrariesNode.OpenProjectAction.class)); + // Edit dependency action + result.add(new EditTestDependencyAction(dep, project)); + // Remove dependency + result.add(LibrariesChildren.REMOVE_DEPENDENCY_ACTION); + actions = (Action[]) result.toArray(new Action[result.size()]); + } + return actions; + } + + public Action getPreferredAction() { + return getActions(false)[0]; // open + } + + } + + private static final class LibraryDependencyNode extends FilterNode { + + private final TestModuleDependency dep; + private final NbModuleProject project; + private Action[] actions; + + LibraryDependencyNode(final TestModuleDependency dep, + final NbModuleProject project, final Node original) { + super(original, null, new ProxyLookup(new Lookup[] { + original.getLookup(), + Lookups.fixed(new Object[] { dep, project }) + })); + this.dep = dep; + this.project = project; + setShortDescription(UnitTestLibrariesNode.createHtmlDescription(dep)); + } + + public Action[] getActions(boolean context) { + if (actions == null) { + Set result = new LinkedHashSet(); + result.add(new EditTestDependencyAction(dep, project)); + Action[] superActions = super.getActions(false); + for (int i = 0; i < superActions.length; i++) { + if (superActions[i] instanceof FindAction) { + result.add(superActions[i]); + } + } + result.add(LibrariesChildren.REMOVE_DEPENDENCY_ACTION); + actions = (Action[]) result.toArray(new Action[result.size()]); + } + return actions; + } + + public Action getPreferredAction() { + return getActions(false)[0]; + } + + } + + static final class AddUnitTestDependencyAction extends AbstractAction { + + private final NbModuleProject project; + + AddUnitTestDependencyAction(final NbModuleProject project) { + super(getMessage("CTL_AddTestDependency")); + this.project = project; + } + + //COPIED FROM LIBRARIES MOSTLY + public void actionPerformed(ActionEvent ev) { + SingleModuleProperties props = SingleModuleProperties.getInstance(project); + final AddModulePanel addPanel = new AddModulePanel(props); + final DialogDescriptor descriptor = new DialogDescriptor(addPanel, + getMessage("CTL_AddTestDependency")); + descriptor.setHelpCtx(new HelpCtx(AddModulePanel.class)); + descriptor.setClosingOptions(new Object[0]); + final Dialog d = DialogDisplayer.getDefault().createDialog(descriptor); + descriptor.setButtonListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (DialogDescriptor.OK_OPTION.equals(e.getSource()) && + addPanel.getSelectedDependencies().length == 0) { + return; + } + d.setVisible(false); + d.dispose(); + } + }); + d.setVisible(true); + if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { + // dialog returns + ModuleDependency[] newDeps = addPanel.getSelectedDependencies(); + ProjectXMLManager pxm = new ProjectXMLManager(project); + try { + for (int i = 0; i < newDeps.length; i++) { + // by default, add compile-time dependency + pxm.addTestDependency(TestModuleDependency.UNIT + ,new TestModuleDependency(newDeps[i].getModuleEntry(), false, false, true)); + ProjectManager.getDefault().saveProject(project); + } + } catch (Exception e) { + //IOEX + ErrorManager.getDefault().annotate(e, "Cannot add dependencies, probably IO error: " + Arrays.asList(newDeps)); // NOI18N + ErrorManager.getDefault().notify(e); + } + } + d.dispose(); + } + + + + } + + + + static final class RemoveDependencyAction extends CookieAction { + + protected void performAction(Node[] activatedNodes) { + Map/*>*/ map = new HashMap(); + for (int i = 0; i < activatedNodes.length; i++) { + TestModuleDependency dep = (TestModuleDependency) activatedNodes[i].getLookup().lookup(TestModuleDependency.class); + assert dep != null; + NbModuleProject project = (NbModuleProject) activatedNodes[i].getLookup().lookup(NbModuleProject.class); + assert project != null; + Set deps = (Set) map.get(project); + if (deps == null) { + deps = new HashSet(); + map.put(project, deps); + } + deps.add(dep); + } + for (Iterator it = map.entrySet().iterator(); it.hasNext();) { + Map.Entry me = (Map.Entry) it.next(); + NbModuleProject project = (NbModuleProject) me.getKey(); + Set deps = (Set) me.getValue(); + ProjectXMLManager pxm = new ProjectXMLManager(project); + //remove dep one by one + for (Iterator it2 = deps.iterator(); it2.hasNext();) { + TestModuleDependency rem = (TestModuleDependency) it2.next(); + pxm.removeTestDependency(TestModuleDependency.UNIT, rem.getModule().getCodeNameBase()); + } + try { + ProjectManager.getDefault().saveProject(project); + } catch (IOException e) { + ErrorManager.getDefault().annotate(e, "Problem during test dependencies removing"); // NOI18N + ErrorManager.getDefault().notify(e); + } + } + + } + + public String getName() { + return getMessage("CTL_RemoveDependency"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + protected boolean asynchronous() { + return false; + } + + protected int mode() { + return CookieAction.MODE_ALL; + } + + protected Class[] cookieClasses() { + return new Class[] {TestModuleDependency.class, NbModuleProject.class }; + } + + + } + + + static final class EditTestDependencyAction extends AbstractAction { + + private final TestModuleDependency testDep; + private final NbModuleProject project; + + EditTestDependencyAction(final TestModuleDependency testDep, final NbModuleProject project) { + super(getMessage("CTL_EditDependency")); + this.testDep = testDep; + this.project = project; + } + + + public void actionPerformed(ActionEvent ev) { + final EditTestDependencyPanel editTestPanel = new EditTestDependencyPanel(testDep); + DialogDescriptor descriptor = new DialogDescriptor(editTestPanel, + NbBundle.getMessage(LibrariesNode.class, "CTL_EditModuleDependencyTitle", + testDep.getModule().getLocalizedName())); + descriptor.setHelpCtx(new HelpCtx(EditTestDependencyPanel.class)); + Dialog d = DialogDisplayer.getDefault().createDialog(descriptor); + d.setVisible(true); + if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { + TestModuleDependency editedDep = editTestPanel.getEditedDependency(); + try { + ProjectXMLManager pxm = new ProjectXMLManager(project); + final String UNIT = TestModuleDependency.UNIT; + pxm.removeTestDependency(UNIT, testDep.getModule().getCodeNameBase()); + pxm.addTestDependency(UNIT, editedDep); + ProjectManager.getDefault().saveProject(project); + + + } catch (IOException e) { + ErrorManager.getDefault().annotate(e, "Cannot store dependency: " + editedDep); // NOI18N + ErrorManager.getDefault().notify(e); + } + + + } + d.dispose(); + } + } + + } + Index: src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java Base (1.53) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ProjectXMLManager.java Locally Modified (Based On 1.53) *************** *** 47,52 **** --- 47,53 ---- import org.netbeans.modules.apisupport.project.universe.ModuleList; import org.netbeans.modules.apisupport.project.universe.NbPlatform; import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; + import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** *************** *** 92,97 **** --- 93,99 ---- private static final String TEST_DEPENDENCY_RECURSIVE = "recursive"; // NOI18N private static final String TEST_DEPENDENCY_COMPILE = "compile-dependency"; // NOI18N private static final String TEST_DEPENDENCY_TEST = "test"; // NOI18N + private static final String TEST_TYPE = "test-type"; //NOI18N private final NbModuleProject project; private NbPlatform customPlaf; *************** *** 374,383 **** } /** * Gives a map from test type (e.g. unit or qa-functional) * to the set of {@link TestModuleDependency dependencies} belonging to it. */ ! Map> getTestDependencies(final ModuleList ml) { Element testDepsEl = findTestDependenciesElement(getConfData()); Map> testDeps = new HashMap(); --- 376,529 ---- } /** + * Removes test dependency under type testType, indentified + * by cnbToRemove. Does not remove whole 610test type even if + * removed test dependency was the last one. + */ + public boolean removeTestDependency(String testType, String cnbToRemove){ + boolean wasRemoved = false; + Element confData = getConfData(); + Element testModuleDependenciesEl = findTestDependenciesElement(confData); + List/**/ testTypesList = Util.findSubElements(testModuleDependenciesEl); + Element testTypeRemoveEl = null; + for (Iterator it = testTypesList.iterator(); it.hasNext(); ) { + Element type = (Element)it.next(); + Element nameEl = findElement(type, TEST_TYPE_NAME); + String nameOfType = Util.findText(nameEl); + if (testType.equals(nameOfType)) { + testTypeRemoveEl = type; + } + } + //found such a test type + if (testTypeRemoveEl != null){ + List/**/ testDepList = Util.findSubElements(testTypeRemoveEl); + for (Iterator it = testDepList.iterator(); it.hasNext();) { + Element el = (Element) it.next(); + Element cnbEl = findElement(el, TEST_DEPENDENCY_CNB); + if(cnbEl == null) { + continue; //name node, continue + } + String cnb = Util.findText(cnbEl); + if (cnbToRemove.equals(cnb)) { + // found test dependency with desired CNB + testTypeRemoveEl.removeChild(el); + wasRemoved = true; + project.putPrimaryConfigurationData(confData); + } + } + } + return wasRemoved; + } + + /** + * Adds new test dependency to project.xml. Currently only two test types are + * supported - UNIT and QA_FUNCTIONAL. Test dependencies under + * test types are sorted by CNB. + */ + public void addTestDependency(String testType, TestModuleDependency newTestDep) throws IOException { + final String UNIT = TestModuleDependency.UNIT; + final String QA_FUNCTIONAL = TestModuleDependency.QA_FUNCTIONAL; + assert (UNIT.equals(testType) || QA_FUNCTIONAL.equals(testType)) : "Current impl.supports only " + QA_FUNCTIONAL + + " or " + UNIT + " tests"; // NOI18N + File projectDir = FileUtil.toFile(project.getProjectDirectory()); + ModuleList ml = ModuleList.getModuleList(projectDir); + Map map = new HashMap(getTestDependencies(ml)); + Set testDependenciesSet = (Set) map.get(testType); + if(testDependenciesSet == null) { + testDependenciesSet = new TreeSet(); + map.put(testType, testDependenciesSet); + } else { + testDependenciesSet = new TreeSet(); + testDependenciesSet.addAll((Set) map.get(testType)); + } + if (!testDependenciesSet.add(newTestDep)) { + return; //nothing new to add, dep is already there, finished + } + Element confData = getConfData(); + Document doc = confData.getOwnerDocument(); + Element testModuleDependenciesEl = findTestDependenciesElement(confData); + if (testModuleDependenciesEl == null) { // test dependencies element does not exist, create it + Element before = findPublicPackagesElement(confData); + if (before == null) { + before = findFriendsElement(confData); + } + assert before != null : "There must be " + PUBLIC_PACKAGES + " or " // NOI18N + + FRIEND_PACKAGES + " element according to XSD"; // NOI18N + testModuleDependenciesEl= createModuleElement(doc, TEST_DEPENDENCIES); + confData.insertBefore(testModuleDependenciesEl, before); + } + Element testTypeEl = null; + List listOfTestTypes = Util.findSubElements(testModuleDependenciesEl); + //iterate through test types to determine if testType exist + for (Iterator it = listOfTestTypes.iterator(); it.hasNext();) { + Element tt = (Element) it.next(); + Node nameNode = findElement(tt, "name"); + assert nameNode!=null : "should be some child with name"; + //Node nameNode = tt.getFirstChild(); + //nameNode.getNodeName() + assert (TEST_TYPE_NAME.equals(nameNode.getLocalName())) : "name node should be first child, but was:"+nameNode.getLocalName() + + "or" + nameNode.getNodeName(); //NOI18N + //equals + if(nameNode.getTextContent() == testType) { + testTypeEl = tt; + } + } + //? new or existing test type? + if (testTypeEl == null){ + //this test type, does not exist, create it, and add new test dependency + Element newTestTypeEl = createNewTestTypeElement(doc, testType); + testModuleDependenciesEl.appendChild(newTestTypeEl); + createTestModuleDependencyElement(newTestTypeEl, newTestDep); + project.putPrimaryConfigurationData(confData); + return; + } else { + //testtype exists, refresh it + Node beforeWhat = testTypeEl.getNextSibling(); + testModuleDependenciesEl.removeChild(testTypeEl); + Element refreshedTestTypeEl = createNewTestTypeElement(doc, testType); + if(beforeWhat == null) { + testModuleDependenciesEl.appendChild(refreshedTestTypeEl); + } else { + testModuleDependenciesEl.insertBefore(refreshedTestTypeEl, beforeWhat); + } + for (Iterator it = testDependenciesSet.iterator(); it.hasNext(); ) { + TestModuleDependency tmd = (TestModuleDependency) it.next(); + createTestModuleDependencyElement(refreshedTestTypeEl, tmd); + project.putPrimaryConfigurationData(confData); + } + } + } + + private Element createNewTestTypeElement(Document doc, String testTypeName){ + Element newTestTypeEl = createModuleElement(doc, TEST_TYPE); + Element nameOfTestTypeEl = createModuleElement(doc, TEST_TYPE_NAME, testTypeName); + newTestTypeEl.appendChild(nameOfTestTypeEl); + return newTestTypeEl; + } + + + private void createTestModuleDependencyElement(Element testTypeElement, TestModuleDependency tmd) { + Document doc = testTypeElement.getOwnerDocument(); + Element tde = createModuleElement(doc, TEST_DEPENDENCY); + testTypeElement.appendChild(tde); + tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_CNB, tmd.getModule().getCodeNameBase())); + if(tmd.isRecursive()) { + tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_RECURSIVE)); + } + if(tmd.isCompile()) { + tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_COMPILE)); + } + if(tmd.isTest()) { + tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_TEST)); + } + } + + + /** * Gives a map from test type (e.g. unit or qa-functional) * to the set of {@link TestModuleDependency dependencies} belonging to it. */ ! public Map> getTestDependencies(final ModuleList ml) { Element testDepsEl = findTestDependenciesElement(getConfData()); Map> testDeps = new HashMap(); Index: src/org/netbeans/modules/apisupport/project/ui/ModuleLogicalView.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/ModuleLogicalView.java Base (1.28) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/ModuleLogicalView.java Locally Modified (Based On 1.28) *************** *** 242,250 **** --- 242,261 ---- } l.add(IMPORTANT_FILES_NAME); l.add(LibrariesNode.LIBRARIES_NAME); + if(resolveFileObjectFromProperty("test.unit.src.dir") != null) { //NOI18N + l.add(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME); + } setKeys(l); } + private FileObject resolveFileObjectFromProperty(String property){ + String filename = project.evaluator().getProperty(property); + if (filename == null) { + return null; + } + return project.getHelper().resolveFileObject(filename); + } + protected void removeNotify() { ProjectUtils.getSources(project).removeChangeListener(this); setKeys(Collections.EMPTY_SET); *************** *** 259,280 **** n = new ImportantFilesNode(project); } else if (key == LibrariesNode.LIBRARIES_NAME) { n = new LibrariesNode(project); } else { throw new AssertionError("Unknown key: " + key); } return new Node[] {n}; } private SourceGroup makeJavadocDocfilesSourceGroup() { String propname = "javadoc.docfiles"; // NOI18N ! String prop = project.evaluator().getProperty(propname); ! if (prop == null) { return null; } - FileObject root = project.getHelper().resolveFileObject(prop); - if (root == null) { - return null; - } return GenericSources.group(project, root, propname, NbBundle.getMessage(ModuleLogicalView.class, "LBL_extra_javadoc_files"), null, null); } --- 270,293 ---- n = new ImportantFilesNode(project); } else if (key == LibrariesNode.LIBRARIES_NAME) { n = new LibrariesNode(project); + } else if (key == UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME) { + n = new UnitTestLibrariesNode(project); } else { throw new AssertionError("Unknown key: " + key); } return new Node[] {n}; } + private SourceGroup makeJavadocDocfilesSourceGroup() { String propname = "javadoc.docfiles"; // NOI18N ! FileObject root = resolveFileObjectFromProperty(propname); ! if(root == null) { return null; } return GenericSources.group(project, root, propname, NbBundle.getMessage(ModuleLogicalView.class, "LBL_extra_javadoc_files"), null, null); } Index: src/org/netbeans/modules/apisupport/project/universe/TestModuleDependency.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/universe/TestModuleDependency.java Base (1.2) --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/universe/TestModuleDependency.java Locally Modified (Based On 1.2) *************** *** 27,33 **** * * @author pzajac */ ! public class TestModuleDependency { public static final String UNIT = "unit"; // NOI18N public static final String QA_FUNCTIONAL = "qa-functional"; // NOI18N --- 27,33 ---- * * @author pzajac */ ! public class TestModuleDependency implements Comparable { public static final String UNIT = "unit"; // NOI18N public static final String QA_FUNCTIONAL = "qa-functional"; // NOI18N *************** *** 84,90 **** --- 84,120 ---- this.compile = compile; } + // td1 equals td2 iff cnb and all three boolean fileds of td are the same + public boolean equals(Object o){ + if(o instanceof TestModuleDependency) { + TestModuleDependency tmd = (TestModuleDependency) o; + return tmd.isCompile() == this.isCompile() + && tmd.isRecursive() == this.isRecursive() + && tmd.isTest() == this.isTest() + && tmd.getModule().getCodeNameBase().equals(this.getModule().getCodeNameBase()); + } else { + return false; } + } + + //compare only on cnb. ATTENTION, compareTo is not consistent with equals method! + //i.e. two instances of TestModuleDependency can be nonequal, and tmd1.compareTo(tmd2) + // can return 0 + public int compareTo(Object o) { + TestModuleDependency tmd = (TestModuleDependency) o; + return this.module.getCodeNameBase().compareTo(tmd.module.getCodeNameBase()); + } + + //hash from CNB only + public int hashCode(){ + int hash = module.getCodeNameBase().hashCode(); + // if(test) hash*=5; + // if(recursive) hash*=7; + // if(compile) hash*=11; + return hash; + } + } Index: test/unit/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNodeTest.java *** /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNodeTest.java No Base Revision --- /home/tomas/nb_src/apisupport/project/test/unit/src/org/netbeans/modules/apisupport/project/ui/UnitTestLibrariesNodeTest.java Locally New *************** *** 1,0 **** --- 1,120 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.apisupport.project.ui; + + import java.util.Set; + import javax.swing.Action; + import org.netbeans.api.project.ProjectManager; + import org.netbeans.modules.apisupport.project.NbModuleProject; + import org.netbeans.modules.apisupport.project.ProjectXMLManager; + import org.netbeans.modules.apisupport.project.TestBase; + import org.netbeans.modules.apisupport.project.ui.UnitTestLibrariesNode.RemoveDependencyAction; + import org.netbeans.modules.apisupport.project.universe.ModuleEntry; + import org.netbeans.modules.apisupport.project.universe.ModuleList; + import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; + import org.netbeans.spi.project.ui.LogicalViewProvider; + import org.openide.nodes.AbstractNode; + import org.openide.nodes.Node; + + /** + * @author Tomas Musil + */ + public class UnitTestLibrariesNodeTest extends TestBase { + private static final String UNIT = TestModuleDependency.UNIT; + private static final String DEP_CNB = "org.openide.filesystems"; + private static final String JUNIT_CNB = "org.netbeans.modules.junit"; + private static final String NBJUNIT_CNB = "org.netbeans.modules.nbjunit"; + private static int nc = 0; //says if junit or nbjunit is present + + public UnitTestLibrariesNodeTest(String testName) { + super(testName); + } + + //this tests if node draws subnodes + public void testLibrariesNodeDrawingDeps() throws Exception { + //initial check + NbModuleProject p = generateStandaloneModule("module"); + if((p.getModuleList().getEntry(JUNIT_CNB)) != null) { + nc++; + } + if((p.getModuleList().getEntry(NBJUNIT_CNB)) != null) { + nc++; + } + + LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class); + assertNotNull("have a LogicalViewProvider", lvp); + Node root = lvp.createLogicalView(); + Node libs = root.getChildren().findChild(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME); + assertNotNull("have the Libraries node", libs); + libs.getChildren().getNodes(); + assertEquals("nc node", nc, libs.getChildren().getNodes(true).length); + + //add tests dependecy + ProjectXMLManager pxm = new ProjectXMLManager(p); + addTestDependency(p); + ModuleList ml = p.getModuleList(); + Set unitDeps = pxm.getTestDependencies(ml).get(TestModuleDependency.UNIT); + assertNotNull("Have unit deps now", unitDeps); + assertEquals("one dep now", 1, unitDeps.size()); + assertEquals("nc+1 nodes now", nc+1, libs.getChildren().getNodes().length); + + //remove test dependency + pxm.removeTestDependency(UNIT, DEP_CNB); + ProjectManager.getDefault().saveProject(p); + assertEquals("nc nodes now", nc, libs.getChildren().getNodes().length); + } + + //test action on node + public void testActions() throws Exception{ + NbModuleProject p = generateStandaloneModule("module"); + LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class); + assertNotNull("have a LogicalViewProvider", lvp); + Node root = lvp.createLogicalView(); + Node libs = root.getChildren().findChild(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME); + assertNotNull("have the Libraries node", libs); + //test removedep action + addTestDependency(p); + String depName = p.getModuleList().getEntry(DEP_CNB).getLocalizedName(); + AbstractNode depNode = (AbstractNode) + libs.getChildren().findChild(depName); + + assertNotNull("have a node with dependency", depNode); + Action[] act = depNode.getActions(false); + assertEquals("have three actions", 3, act.length); + RemoveDependencyAction removeAct = (RemoveDependencyAction) act[2]; + assertEquals("nc+1 nodes now", nc+1, libs.getChildren().getNodes().length); + removeAct.performAction(new Node[] {depNode}); + assertEquals("nc nodes now, dep removed", nc, libs.getChildren().getNodes().length); + } + + //TODO add more tests, try to invoke all actions on nodes, etc + + private void addTestDependency(NbModuleProject project) throws Exception{ + ProjectXMLManager pxm = new ProjectXMLManager(project); + ModuleList ml = project.getModuleList(); + ModuleEntry me = ml.getEntry(DEP_CNB); + assertNotNull("me exist", me); + TestModuleDependency tmd = new TestModuleDependency(me, true, true, true); + pxm.addTestDependency(UNIT, tmd); + ProjectManager.getDefault().saveProject(project); + } + + + } Index: src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.java *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.java No Base Revision --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.java Locally New *************** *** 1,0 **** --- 1,131 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + + package org.netbeans.modules.apisupport.project.ui.customizer; + + import org.netbeans.modules.apisupport.project.universe.TestModuleDependency; + + /** + * + * @author Tomas Musil + */ + public class EditTestDependencyPanel extends javax.swing.JPanel { + private TestModuleDependency tmd ; + + /** Creates new form EditTestDependencyPanel */ + public EditTestDependencyPanel(final TestModuleDependency originalDep) { + tmd = originalDep; + initComponents(); + fillOriginal(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + moduleJar = new javax.swing.JLabel(); + moduleJarValue = new javax.swing.JTextField(); + tests = new javax.swing.JCheckBox(); + compile = new javax.swing.JCheckBox(); + dependencies = new javax.swing.JCheckBox(); + + moduleJar.setLabelFor(moduleJarValue); + org.openide.awt.Mnemonics.setLocalizedText(moduleJar, org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.moduleJar.text")); // NOI18N + + moduleJarValue.setEditable(false); + moduleJarValue.setText(org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.moduleJarValue.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(tests, org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.tests.text")); // NOI18N + tests.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + tests.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + org.openide.awt.Mnemonics.setLocalizedText(compile, org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.compile.text")); // NOI18N + compile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + compile.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + org.openide.awt.Mnemonics.setLocalizedText(dependencies, org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.dependencies.text")); // NOI18N + dependencies.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); + dependencies.setMargin(new java.awt.Insets(0, 0, 0, 0)); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(moduleJar) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(moduleJarValue, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)) + .add(tests) + .add(dependencies) + .add(compile)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(moduleJar) + .add(moduleJarValue, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(15, 15, 15) + .add(tests) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(dependencies) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(compile) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + moduleJar.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.moduleJar.AccessibleContext.accessibleDescription")); // NOI18N + tests.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.tests.AccessibleContext.accessibleDescription")); // NOI18N + compile.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.compile.AccessibleContext.accessibleDescription")); // NOI18N + dependencies.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditTestDependencyPanel.class, "EditTestDependencyPanel.dependencies.AccessibleContext.accessibleDescription")); // NOI18N + }// //GEN-END:initComponents + + private void fillOriginal(){ + moduleJarValue.setText(tmd.getModule().getCodeNameBase()); + tests.setSelected(tmd.isTest()); + compile.setSelected(tmd.isCompile()); + dependencies.setSelected(tmd.isRecursive()); + } + + + public TestModuleDependency getEditedDependency(){ + + return new TestModuleDependency(tmd.getModule(), tests.isSelected(), dependencies.isSelected(), + compile.isSelected()); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox compile; + private javax.swing.JCheckBox dependencies; + private javax.swing.JLabel moduleJar; + private javax.swing.JTextField moduleJarValue; + private javax.swing.JCheckBox tests; + // End of variables declaration//GEN-END:variables + + } Index: src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.form *** /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.form No Base Revision --- /home/tomas/nb_src/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/customizer/EditTestDependencyPanel.form Locally New *************** *** 1,0 **** --- 1,136 ---- + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +