1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.Collections ; 26 import java.util.HashMap ; 27 import java.util.HashSet ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import java.util.TreeSet ; 31 import java.util.jar.Manifest ; 32 import org.netbeans.api.project.Project; 33 import org.netbeans.api.project.ProjectManager; 34 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 35 import org.netbeans.modules.apisupport.project.suite.SuiteProjectGenerator; 36 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 37 import org.netbeans.spi.project.SubprojectProvider; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileUtil; 40 41 46 public class NbModuleProjectGeneratorTest extends TestBase { 47 50 public NbModuleProjectGeneratorTest(String testName) { 51 super(testName); 52 } 53 54 private static final String [] BASIC_CREATED_FILES = { 55 "build.xml", 56 "manifest.mf", 57 "nbproject/project.xml", 58 "nbproject/build-impl.xml", 59 "src/org/example/testModule/resources/Bundle.properties", 60 "src/org/example/testModule/resources/layer.xml", 61 "test/unit/src", 62 }; 63 64 private static final String [] STANDALONE_CREATED_FILES = { 65 "nbproject/platform.properties", 66 }; 67 68 private static final String [] SUITE_COMP_REL_CREATED_FILES = { 69 "nbproject/suite.properties", 70 }; 71 72 public void testCreateStandAloneModule() throws Exception { 73 File targetPrjDir = new File (getWorkDir(), "testModule"); 74 NbModuleProjectGenerator.createStandAloneModule( 75 targetPrjDir, 76 "org.example.testModule", "Testing Module", "org/example/testModule/resources/Bundle.properties", 79 "org/example/testModule/resources/layer.xml", 80 NbPlatform.PLATFORM_ID_DEFAULT); FileObject fo = FileUtil.toFileObject(targetPrjDir); 82 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(fo); 84 assertNotNull("have a project in " + targetPrjDir, p); 85 p.open(); 86 for (int i=0; i < BASIC_CREATED_FILES.length; i++) { 88 assertNotNull(BASIC_CREATED_FILES[i]+" file/folder cannot be found", 89 fo.getFileObject(BASIC_CREATED_FILES[i])); 90 } 91 for (int i=0; i < STANDALONE_CREATED_FILES.length; i++) { 92 assertNotNull(STANDALONE_CREATED_FILES[i]+" file/folder cannot be found", 93 fo.getFileObject(STANDALONE_CREATED_FILES[i])); 94 } 95 } 96 97 public void testCreateSuiteComponentModule() throws Exception { 98 File suiteDir = new File (getWorkDir(), "testSuite"); 100 SuiteProjectGenerator.createSuiteProject(suiteDir, NbPlatform.PLATFORM_ID_DEFAULT); 101 FileObject fo = FileUtil.toFileObject(suiteDir); 102 Project suiteProject = ProjectManager.getDefault().findProject(fo); 103 assertNotNull("have a project in " + suiteDir, suiteProject); 104 SubprojectProvider spp = (SubprojectProvider) suiteProject.getLookup().lookup(SubprojectProvider.class); 105 assertNotNull("has a SubprojectProvider", spp); 106 107 File targetPrjDir = new File (suiteDir, "testModuleRel"); 109 NbModuleProjectGenerator.createSuiteComponentModule( 110 targetPrjDir, 111 "org.example.testModuleRel", "Testing Module", "org/example/testModule/resources/Bundle.properties", 114 "org/example/testModule/resources/layer.xml", 115 suiteDir); fo = FileUtil.toFileObject(targetPrjDir); 117 NbModuleProject moduleProjectRel = (NbModuleProject) ProjectManager.getDefault().findProject(fo); 119 assertNotNull("have a project in " + targetPrjDir, moduleProjectRel); 120 moduleProjectRel.open(); 121 for (int i=0; i < BASIC_CREATED_FILES.length; i++) { 123 assertNotNull(BASIC_CREATED_FILES[i]+" file/folder cannot be found", 124 fo.getFileObject(BASIC_CREATED_FILES[i])); 125 } 126 for (int i=0; i < SUITE_COMP_REL_CREATED_FILES.length; i++) { 127 assertNotNull(SUITE_COMP_REL_CREATED_FILES[i]+" file/folder cannot be found", 128 fo.getFileObject(SUITE_COMP_REL_CREATED_FILES[i])); 129 } 130 assertEquals("listed as the sole suite component", Collections.singleton(moduleProjectRel), spp.getSubprojects()); 131 132 targetPrjDir = new File (getWorkDir(), "testModuleAbs"); 134 NbModuleProjectGenerator.createSuiteComponentModule( 135 targetPrjDir, 136 "org.example.testModuleAbs", "Testing Module", "org/example/testModule/resources/Bundle.properties", 139 "org/example/testModule/resources/layer.xml", 140 suiteDir); fo = FileUtil.toFileObject(targetPrjDir); 142 NbModuleProject moduleProjectAbs = (NbModuleProject) ProjectManager.getDefault().findProject(fo); 144 assertNotNull("have a project in " + targetPrjDir, moduleProjectAbs); 145 moduleProjectAbs.open(); 146 for (int i=0; i < BASIC_CREATED_FILES.length; i++) { 148 assertNotNull(BASIC_CREATED_FILES[i]+" file/folder cannot be found", 149 fo.getFileObject(BASIC_CREATED_FILES[i])); 150 } 151 assertEquals("now have two suite components", new HashSet (Arrays.asList(new Project[] {moduleProjectRel, moduleProjectAbs})), spp.getSubprojects()); 152 } 153 154 public void testCreateSuiteLibraryModule() throws Exception { 155 Map contents = new HashMap (); 156 contents.put("lib/pkg/Clazz3.class", ""); 157 contents.put("lib/pkg2/Clazz4.class", ""); 158 contents.put("1.0/oldlib/Clazz5.class", ""); File jar = new File (getWorkDir(), "some.jar"); 160 createJar(jar, contents, new Manifest ()); 161 SuiteProject sweet = generateSuite("sweet"); 162 File moduleDir = new File (getWorkDir(), "module"); 163 NbModuleProjectGenerator.createSuiteLibraryModule( 164 moduleDir, "module", "Module", "module/Bundle.properties", 165 sweet.getProjectDirectoryFile(), null, new File [] {jar}); 166 NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(moduleDir)); 167 ManifestManager.PackageExport[] exports = new ProjectXMLManager(p).getPublicPackages(); 168 Set packages = new TreeSet (); 169 for (int i = 0; i < exports.length; i++) { 170 assertFalse(exports[i].isRecursive()); 171 packages.add(exports[i].getPackage()); 172 } 173 assertEquals(Arrays.asList(new String [] {"lib.pkg", "lib.pkg2"}), new ArrayList (packages)); 174 } 175 176 189 } 190 | Popular Tags |