KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > NbModuleProjectTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project;
21
22 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
23 import java.io.File JavaDoc;
24 import org.netbeans.api.project.FileOwnerQuery;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.api.project.ProjectManager;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.api.project.SourceGroup;
29 import org.netbeans.api.project.Sources;
30 import org.netbeans.spi.project.support.ant.AntProjectHelper;
31 import org.netbeans.spi.project.support.ant.EditableProperties;
32 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
33 import org.netbeans.spi.project.support.ant.PropertyUtils;
34 import org.openide.filesystems.FileObject;
35 import org.openide.filesystems.FileUtil;
36
37 /**
38  * Test functionality of NbModuleProject.
39  * @author Jesse Glick
40  */

41 public class NbModuleProjectTest extends TestBase {
42     
43     public NbModuleProjectTest(String JavaDoc name) {
44         super(name);
45     }
46     
47     private NbModuleProject javaProjectProject;
48     private NbModuleProject loadersProject;
49     private File JavaDoc userPropertiesFile;
50     
51     protected void setUp() throws Exception JavaDoc {
52         super.setUp();
53         userPropertiesFile = TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
54         FileObject dir = nbCVSRoot().getFileObject("java/project");
55         assertNotNull("have java/project checked out", dir);
56         Project p = ProjectManager.getDefault().findProject(dir);
57         javaProjectProject = (NbModuleProject)p;
58         dir = nbCVSRoot().getFileObject("openide/loaders");
59         assertNotNull("have openide/loaders checked out", dir);
60         p = ProjectManager.getDefault().findProject(dir);
61         loadersProject = (NbModuleProject)p;
62     }
63
64     /** #56457 */
65     public void testExternalSourceRoots() throws Exception JavaDoc {
66         FileObject documentFinderJava = nbCVSRoot().getFileObject("editor/libsrc/org/netbeans/editor/DocumentFinder.java");
67         assertNotNull("have DocumentFinder.java", documentFinderJava);
68         FileObject editorLib = nbCVSRoot().getFileObject("editor/lib");
69         assertNotNull("have editor/lib", editorLib);
70         Project editorLibProject = ProjectManager.getDefault().findProject(editorLib);
71         assertNotNull("have editor/lib project", editorLibProject);
72         Thread.sleep(1000); // XXX why?
73
assertEquals("correct owner of DocumentFinder.java", editorLibProject, FileOwnerQuery.getOwner(documentFinderJava));
74     }
75
76     public void testExternalModules() throws Exception JavaDoc {
77         FileObject suite1 = resolveEEP("suite1");
78         FileObject action = suite1.getFileObject("action-project");
79         NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(action);
80         PropertyEvaluator eval = actionProject.evaluator();
81         String JavaDoc nbdestdir = eval.getProperty("netbeans.dest.dir");
82         assertNotNull("defined netbeans.dest.dir", nbdestdir);
83         assertEquals("right netbeans.dest.dir", file("nbbuild/netbeans"), PropertyUtils.resolveFile(FileUtil.toFile(action), nbdestdir));
84         FileObject suite3 = resolveEEP("suite3");
85         FileObject dummy = suite3.getFileObject("dummy-project");
86         NbModuleProject dummyProject = (NbModuleProject) ProjectManager.getDefault().findProject(dummy);
87         eval = dummyProject.evaluator();
88         assertEquals("right netbeans.dest.dir", resolveEEPFile("suite3/nbplatform"), PropertyUtils.resolveFile(FileUtil.toFile(dummy), eval.getProperty("netbeans.dest.dir")));
89         // XXX more...
90
}
91
92     public void testGetType() throws Exception JavaDoc {
93         assertEquals(NbModuleProvider.NETBEANS_ORG, Util.getModuleType(javaProjectProject));
94         FileObject suite1 = resolveEEP("suite1");
95         FileObject action = suite1.getFileObject("action-project");
96         NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(action);
97         assertEquals(NbModuleProvider.SUITE_COMPONENT, Util.getModuleType(actionProject));
98         FileObject suite3 = resolveEEP("suite3");
99         FileObject dummy = suite3.getFileObject("dummy-project");
100         NbModuleProject dummyProject = (NbModuleProject) ProjectManager.getDefault().findProject(dummy);
101         assertEquals(NbModuleProvider.STANDALONE, Util.getModuleType(dummyProject));
102     }
103
104     public void testSupportsJavadoc() throws Exception JavaDoc {
105         assertTrue(javaProjectProject.supportsJavadoc());
106         FileObject dir = nbCVSRoot().getFileObject("beans");
107         assertNotNull("have beans checked out", dir);
108         Project p = ProjectManager.getDefault().findProject(dir);
109         NbModuleProject beansProject = (NbModuleProject) p;
110         assertFalse(beansProject.supportsJavadoc());
111     }
112
113     public void testGetNbrootFile() throws Exception JavaDoc {
114         NbModuleProject actionProject = (NbModuleProject) ProjectManager.getDefault().findProject(resolveEEP("suite1/action-project"));
115         assertEquals(file("xtest/lib/insanelib.jar"), actionProject.getNbrootFile("xtest/lib/insanelib.jar"));
116     }
117
118     public void testThatModuleWithOverriddenSrcDirPropertyDoesNotThrowNPE() throws Exception JavaDoc {
119         FileObject prjFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1");
120         FileObject srcFO = prjFO.getFileObject("src");
121         FileUtil.moveFile(srcFO, prjFO, "src2");
122         ProjectManager.getDefault().findProject(prjFO);
123     }
124     
125     public void testGenericSourceGroupForExternalUnitTests() throws Exception JavaDoc {
126         FileObject prjFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1");
127         FileUtil.createData(prjFO, "../myunitsrc/a/b/c/Dummy.java");
128         FileObject propsFO = FileUtil.createData(prjFO, AntProjectHelper.PROJECT_PROPERTIES_PATH);
129         EditableProperties ep = Util.loadProperties(propsFO);
130         ep.setProperty("test.unit.src.dir", "../myunitsrc");
131         Util.storeProperties(propsFO, ep);
132         Project module = ProjectManager.getDefault().findProject(prjFO);
133         Sources sources = ProjectUtils.getSources(module);
134         SourceGroup[] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
135         assertEquals("two generic source group", 2, sourceGroups.length); // prjFolder and unitFolder
136
}
137
138 }
139
Popular Tags