1 19 20 package org.netbeans.modules.apisupport.project.queries; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.Arrays ; 25 import java.util.Collections ; 26 import java.util.jar.Manifest ; 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 43 public class SourceForBinaryImplTest extends TestBase { 44 45 public SourceForBinaryImplTest(String name) { 46 super(name); 47 } 48 49 public void testFindSourceRootForCompiledClasses() throws Exception { 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 { 57 doTestFindSourceRootForCompiledClasses("ant/src-bridge", "ant/build/bridge-classes"); 58 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 { 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 { 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 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 { 86 SuiteProject suite = generateSuite("suite"); 87 NbModuleProject project = TestBase.generateSuiteComponent(suite, "module"); 88 File library = new File (getWorkDir(), "test-library-0.1_01.jar"); 89 createJar(library, Collections.EMPTY_MAP, new Manifest ()); 90 FileObject libraryFO = FileUtil.toFileObject(library); 91 FileObject yyJar = FileUtil.copyFile(libraryFO, FileUtil.toFileObject(getWorkDir()), "yy"); 92 93 File suiteDir = suite.getProjectDirectoryFile(); 95 File wrapperDirF = new File (new File (getWorkDir(), "suite"), "wrapper"); 96 NbModuleProjectGenerator.createSuiteLibraryModule( 97 wrapperDirF, 98 "yy", "Testing Wrapper (yy)", "org/example/wrapper/resources/Bundle.properties", 101 suiteDir, null, 103 new File [] { FileUtil.toFile(yyJar)} ); 104 105 Util.addDependency(project, "yy"); 106 ProjectManager.getDefault().saveProject(project); 107 108 URL wrappedJar = Util.urlForJar(new File (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 srcS, File jarF) throws Exception { 113 File srcF = PropertyUtils.resolveFile(nbCVSRootFile(), srcS); 114 FileObject src = FileUtil.toFileObject(srcF); 115 assertNotNull("have " + srcF, src); 116 URL 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 srcS, String jarS) throws Exception { 123 check(srcS, file("nbbuild/netbeans/" + jarS)); 124 } 125 126 private void doTestFindSourceRootForCompiledClasses(String srcPath, String classesPath) throws Exception { 127 File classesF = file(classesPath); 128 File srcF = file(srcPath); 129 FileObject src = FileUtil.toFileObject(srcF); 130 assertNotNull("have " + srcF, src); 131 URL 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 |