001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project;
043:
044: import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
045: import java.io.File;
046: import org.netbeans.api.project.FileOwnerQuery;
047: import org.netbeans.api.project.Project;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.api.project.ProjectUtils;
050: import org.netbeans.api.project.SourceGroup;
051: import org.netbeans.api.project.Sources;
052: import org.netbeans.spi.project.support.ant.AntProjectHelper;
053: import org.netbeans.spi.project.support.ant.EditableProperties;
054: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
055: import org.netbeans.spi.project.support.ant.PropertyUtils;
056: import org.openide.filesystems.FileObject;
057: import org.openide.filesystems.FileUtil;
058:
059: /**
060: * Test functionality of NbModuleProject.
061: * @author Jesse Glick
062: */
063: public class NbModuleProjectTest extends TestBase {
064:
065: public NbModuleProjectTest(String name) {
066: super (name);
067: }
068:
069: private NbModuleProject javaProjectProject;
070: private NbModuleProject loadersProject;
071: private File userPropertiesFile;
072:
073: protected void setUp() throws Exception {
074: super .setUp();
075: userPropertiesFile = TestBase.initializeBuildProperties(
076: getWorkDir(), getDataDir());
077: FileObject dir = nbRoot().getFileObject("java.project");
078: assertNotNull("have java.project checked out", dir);
079: Project p = ProjectManager.getDefault().findProject(dir);
080: javaProjectProject = (NbModuleProject) p;
081: dir = nbRoot().getFileObject("openide.loaders");
082: assertNotNull("have openide.loaders checked out", dir);
083: p = ProjectManager.getDefault().findProject(dir);
084: loadersProject = (NbModuleProject) p;
085: }
086:
087: /** #56457 */
088: // XXX no longer have editor/libsrc test case: testExternalSourceRoots
089: public void testExternalModules() throws Exception {
090: FileObject suite1 = resolveEEP("suite1");
091: FileObject action = suite1.getFileObject("action-project");
092: NbModuleProject actionProject = (NbModuleProject) ProjectManager
093: .getDefault().findProject(action);
094: PropertyEvaluator eval = actionProject.evaluator();
095: String nbdestdir = eval.getProperty("netbeans.dest.dir");
096: assertNotNull("defined netbeans.dest.dir", nbdestdir);
097: assertEquals("right netbeans.dest.dir",
098: file("nbbuild/netbeans"), PropertyUtils.resolveFile(
099: FileUtil.toFile(action), nbdestdir));
100: FileObject suite3 = resolveEEP("suite3");
101: FileObject dummy = suite3.getFileObject("dummy-project");
102: NbModuleProject dummyProject = (NbModuleProject) ProjectManager
103: .getDefault().findProject(dummy);
104: eval = dummyProject.evaluator();
105: assertEquals("right netbeans.dest.dir",
106: resolveEEPFile("suite3/nbplatform"), PropertyUtils
107: .resolveFile(FileUtil.toFile(dummy), eval
108: .getProperty("netbeans.dest.dir")));
109: // XXX more...
110: }
111:
112: public void testGetType() throws Exception {
113: assertEquals(NbModuleProvider.NETBEANS_ORG, Util
114: .getModuleType(javaProjectProject));
115: FileObject suite1 = resolveEEP("suite1");
116: FileObject action = suite1.getFileObject("action-project");
117: NbModuleProject actionProject = (NbModuleProject) ProjectManager
118: .getDefault().findProject(action);
119: assertEquals(NbModuleProvider.SUITE_COMPONENT, Util
120: .getModuleType(actionProject));
121: FileObject suite3 = resolveEEP("suite3");
122: FileObject dummy = suite3.getFileObject("dummy-project");
123: NbModuleProject dummyProject = (NbModuleProject) ProjectManager
124: .getDefault().findProject(dummy);
125: assertEquals(NbModuleProvider.STANDALONE, Util
126: .getModuleType(dummyProject));
127: }
128:
129: public void testSupportsJavadoc() throws Exception {
130: assertTrue(javaProjectProject.supportsJavadoc());
131: FileObject dir = nbRoot().getFileObject("beans");
132: assertNotNull("have beans checked out", dir);
133: Project p = ProjectManager.getDefault().findProject(dir);
134: NbModuleProject beansProject = (NbModuleProject) p;
135: assertFalse(beansProject.supportsJavadoc());
136: }
137:
138: public void testGetNbrootFile() throws Exception {
139: NbModuleProject actionProject = (NbModuleProject) ProjectManager
140: .getDefault().findProject(
141: resolveEEP("suite1/action-project"));
142: assertEquals(file("xtest/lib/insanelib.jar"), actionProject
143: .getNbrootFile("xtest/lib/insanelib.jar"));
144: }
145:
146: public void testThatModuleWithOverriddenSrcDirPropertyDoesNotThrowNPE()
147: throws Exception {
148: FileObject prjFO = TestBase.generateStandaloneModuleDirectory(
149: getWorkDir(), "module1");
150: FileObject srcFO = prjFO.getFileObject("src");
151: FileUtil.moveFile(srcFO, prjFO, "src2");
152: ProjectManager.getDefault().findProject(prjFO);
153: }
154:
155: public void testGenericSourceGroupForExternalUnitTests()
156: throws Exception {
157: FileObject prjFO = TestBase.generateStandaloneModuleDirectory(
158: getWorkDir(), "module1");
159: FileUtil.createData(prjFO, "../myunitsrc/a/b/c/Dummy.java");
160: FileObject propsFO = FileUtil.createData(prjFO,
161: AntProjectHelper.PROJECT_PROPERTIES_PATH);
162: EditableProperties ep = Util.loadProperties(propsFO);
163: ep.setProperty("test.unit.src.dir", "../myunitsrc");
164: Util.storeProperties(propsFO, ep);
165: Project module = ProjectManager.getDefault().findProject(prjFO);
166: Sources sources = ProjectUtils.getSources(module);
167: SourceGroup[] sourceGroups = sources
168: .getSourceGroups(Sources.TYPE_GENERIC);
169: assertEquals("two generic source group", 2, sourceGroups.length); // prjFolder and unitFolder
170: }
171:
172: }
|