KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > queries > SourceForBinaryImplTest


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.queries;
21
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.jar.Manifest JavaDoc;
27 import org.netbeans.api.java.classpath.ClassPath;
28 import org.netbeans.api.java.queries.SourceForBinaryQuery;
29 import org.netbeans.api.project.ProjectManager;
30 import org.netbeans.modules.apisupport.project.NbModuleProject;
31 import org.netbeans.modules.apisupport.project.NbModuleProjectGenerator;
32 import org.netbeans.modules.apisupport.project.TestBase;
33 import org.netbeans.modules.apisupport.project.Util;
34 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
35 import org.netbeans.spi.project.support.ant.PropertyUtils;
36 import org.openide.filesystems.FileObject;
37 import org.openide.filesystems.FileUtil;
38
39 /**
40  * Test functionality of SourceForBinaryImpl.
41  * @author Jesse Glick
42  */

43 public class SourceForBinaryImplTest extends TestBase {
44     
45     public SourceForBinaryImplTest(String JavaDoc name) {
46         super(name);
47     }
48     
49     public void testFindSourceRootForCompiledClasses() throws Exception JavaDoc {
50         doTestFindSourceRootForCompiledClasses("java/project/src", "java/project/build/classes");
51         doTestFindSourceRootForCompiledClasses("java/project/test/unit/src", "java/project/build/test/unit/classes");
52         doTestFindSourceRootForCompiledClasses("ant/freeform/src", "ant/freeform/build/classes");
53         doTestFindSourceRootForCompiledClasses("ant/freeform/test/unit/src", "ant/freeform/build/test/unit/classes");
54     }
55     
56     public void testExtraCompilationUnits() throws Exception JavaDoc {
57         doTestFindSourceRootForCompiledClasses("ant/src-bridge", "ant/build/bridge-classes");
58         // Have to load at least one module to get the scan going.
59
ClassPath.getClassPath(FileUtil.toFileObject(file("beans/src")), ClassPath.COMPILE);
60         check("ant/src-bridge", TestBase.CLUSTER_IDE + "/ant/nblib/bridge.jar");
61     }
62     
63     public void testFindSourceRootForModuleJar() throws Exception JavaDoc {
64         ClassPath.getClassPath(FileUtil.toFileObject(file("ant/src")), ClassPath.COMPILE);
65         check("java/project/src", TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-java-project.jar");
66         check("openide/loaders/src", TestBase.CLUSTER_PLATFORM + "/modules/org-openide-loaders.jar");
67         check("core/bootstrap/src", TestBase.CLUSTER_PLATFORM + "/lib/boot.jar");
68         check("diff/src", TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-diff.jar");
69         check("editor/libsrc", TestBase.CLUSTER_IDE + "/modules/org-netbeans-modules-editor-lib.jar");
70         check("xtest/nbjunit/src", "testtools/modules/org-netbeans-modules-nbjunit.jar");
71         check("apisupport/project/test/unit/src",file("nbbuild/build/testdist/unit/" + TestBase.CLUSTER_IDE + "/org-netbeans-modules-apisupport-project/tests.jar"));
72     }
73     
74     public void testExternalModules() throws Exception JavaDoc {
75         ClassPath.getClassPath(resolveEEP("/suite1/action-project/src"), ClassPath.COMPILE);
76         check(resolveEEPPath("/suite1/action-project/src"), resolveEEPFile("/suite1/build/cluster/modules/org-netbeans-examples-modules-action.jar"));
77         ClassPath.getClassPath(resolveEEP("/suite3/dummy-project/src"), ClassPath.COMPILE);
78         check(resolveEEPPath("/suite3/dummy-project/src"),
79               resolveEEPFile("/suite3/dummy-project/build/cluster/modules/org-netbeans-examples-modules-dummy.jar"));
80         // test dependencies
81
ClassPath.getClassPath(resolveEEP("/suite4/module1/test/unit/src"),ClassPath.COMPILE);
82         check(resolveEEPPath("/suite4/module1/test/unit/src"),resolveEEPFile("/suite4/build/testdist/unit/cluster/module1/tests.jar"));
83     }
84     
85     public void testCompletionWorks_69735() throws Exception JavaDoc {
86         SuiteProject suite = generateSuite("suite");
87         NbModuleProject project = TestBase.generateSuiteComponent(suite, "module");
88         File JavaDoc library = new File JavaDoc(getWorkDir(), "test-library-0.1_01.jar");
89         createJar(library, Collections.EMPTY_MAP, new Manifest JavaDoc());
90         FileObject libraryFO = FileUtil.toFileObject(library);
91         FileObject yyJar = FileUtil.copyFile(libraryFO, FileUtil.toFileObject(getWorkDir()), "yy");
92         
93         // library wrapper
94
File JavaDoc suiteDir = suite.getProjectDirectoryFile();
95         File JavaDoc wrapperDirF = new File JavaDoc(new File JavaDoc(getWorkDir(), "suite"), "wrapper");
96         NbModuleProjectGenerator.createSuiteLibraryModule(
97                 wrapperDirF,
98                 "yy", // 69735 - the same name as jar
99
"Testing Wrapper (yy)", // display name
100
"org/example/wrapper/resources/Bundle.properties",
101                 suiteDir, // suite directory
102
null,
103                 new File JavaDoc[] { FileUtil.toFile(yyJar)} );
104         
105         Util.addDependency(project, "yy");
106         ProjectManager.getDefault().saveProject(project);
107         
108         URL JavaDoc wrappedJar = Util.urlForJar(new File JavaDoc(wrapperDirF, "release/modules/ext/yy.jar"));
109         assertEquals("no sources for wrapper", 0, SourceForBinaryQuery.findSourceRoots(wrappedJar).getRoots().length);
110     }
111     
112     private void check(String JavaDoc srcS, File JavaDoc jarF) throws Exception JavaDoc {
113         File JavaDoc srcF = PropertyUtils.resolveFile(nbCVSRootFile(), srcS);
114         FileObject src = FileUtil.toFileObject(srcF);
115         assertNotNull("have " + srcF, src);
116         URL JavaDoc u = FileUtil.getArchiveRoot(jarF.toURI().toURL());
117         assertEquals("right results for " + u,
118             Collections.singletonList(src),
119             Arrays.asList(SourceForBinaryQuery.findSourceRoots(u).getRoots()));
120     }
121     
122     private void check(String JavaDoc srcS, String JavaDoc jarS) throws Exception JavaDoc {
123         check(srcS, file("nbbuild/netbeans/" + jarS));
124     }
125     
126     private void doTestFindSourceRootForCompiledClasses(String JavaDoc srcPath, String JavaDoc classesPath) throws Exception JavaDoc {
127         File JavaDoc classesF = file(classesPath);
128         File JavaDoc srcF = file(srcPath);
129         FileObject src = FileUtil.toFileObject(srcF);
130         assertNotNull("have " + srcF, src);
131         URL JavaDoc u = Util.urlForDir(classesF);
132         assertEquals("right source root for " + u,
133             Collections.singletonList(src),
134             Arrays.asList(SourceForBinaryQuery.findSourceRoots(u).getRoots()));
135     }
136     
137 }
138
Popular Tags