1 19 20 package org.netbeans.modules.apisupport.project.suite; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.Enumeration ; 27 import java.util.List ; 28 import java.util.jar.JarEntry ; 29 import java.util.jar.JarFile ; 30 import java.util.logging.Level ; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.modules.apisupport.project.DialogDisplayerImpl; 33 import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl; 34 import org.netbeans.modules.apisupport.project.NbModuleProject; 35 import org.netbeans.modules.apisupport.project.TestBase; 36 import org.netbeans.modules.apisupport.project.layers.LayerTestBase; 37 import org.netbeans.modules.apisupport.project.ui.SuiteActions; 38 import org.netbeans.spi.project.ActionProvider; 39 import org.netbeans.spi.project.support.ant.AntProjectHelper; 40 import org.netbeans.spi.project.support.ant.EditableProperties; 41 import org.openide.DialogDescriptor; 42 import org.openide.execution.ExecutorTask; 43 import org.openide.filesystems.FileObject; 44 import org.openide.filesystems.FileUtil; 45 46 50 public class BuildZipDistributionTest extends TestBase { 51 52 static { 53 System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true"); 55 LayerTestBase.Lkp.setLookup(new Object [0]); 56 } 57 58 private SuiteProject suite; 59 60 public BuildZipDistributionTest(String name) { 61 super(name); 62 } 63 64 @Override ![JavaDoc](../../../../../../../cmn/javadoc.gif) 65 protected Level logLevel() { 66 return Level.FINE; 67 } 68 69 70 protected void setUp() throws Exception { 71 clearWorkDir(); 72 73 super.setUp(); 74 75 InstalledFileLocatorImpl.registerDestDir(destDirF); 76 77 suite = TestBase.generateSuite(new File (getWorkDir(), "projects"), "suite"); 78 NbModuleProject proj = TestBase.generateSuiteComponent(suite, "mod1"); 79 80 SuiteProjectTest.openSuite(suite); 81 proj.open(); 82 } 83 84 public void testBuildTheZipAppWhenAppNamePropIsNotSet() throws Exception { 85 SuiteActions p = (SuiteActions) suite.getLookup().lookup(ActionProvider.class); 86 assertNotNull("Provider is here", p); 87 88 List l = Arrays.asList(p.getSupportedActions()); 89 assertTrue("We support build-zip: " + l, l.contains("build-zip")); 90 91 DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION); 92 ExecutorTask task = p.invokeActionImpl("build-zip", suite.getLookup()); 93 assertNull("did not even run task", task); 94 } 95 96 public void testBuildTheZipAppWhenAppNamePropIsSet() throws Exception { 97 EditableProperties ep = suite.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 98 ep.setProperty("app.name", "fakeapp"); 99 100 ep.setProperty("enabled.clusters", TestBase.CLUSTER_PLATFORM); 101 ep.setProperty("disabled.modules", "org.netbeans.modules.autoupdate," + 102 "org.openide.compat," + 103 "org.netbeans.api.progress," + 104 "org.netbeans.core.multiview," + 105 "org.openide.util.enumerations" + 106 ""); 107 suite.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 108 ProjectManager.getDefault().saveProject(suite); 109 110 SuiteActions p = (SuiteActions)suite.getLookup().lookup(ActionProvider.class); 111 assertNotNull("Provider is here", p); 112 113 List l = Arrays.asList(p.getSupportedActions()); 114 assertTrue("We support build-zip: " + l, l.contains("build-zip")); 115 116 DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION); 117 ExecutorTask task = p.invokeActionImpl("build-zip", suite.getLookup()); 118 119 assertNotNull("Task was started", task); 120 assertEquals("Finished ok", 0, task.result()); 121 122 FileObject[] arr = suite.getProjectDirectory().getChildren(); 123 List subobj = new ArrayList (Arrays.asList(arr)); 124 subobj.remove(suite.getProjectDirectory().getFileObject("mod1")); 125 subobj.remove(suite.getProjectDirectory().getFileObject("nbproject")); 126 subobj.remove(suite.getProjectDirectory().getFileObject("build.xml")); 127 subobj.remove(suite.getProjectDirectory().getFileObject("build")); 128 FileObject dist = suite.getProjectDirectory().getFileObject("dist"); 129 assertNotNull("dist created", dist); 130 subobj.remove(dist); 131 132 if (!subobj.isEmpty()) { 133 fail("There should be no created directories in the suite dir: " + subobj); 134 } 135 136 FileObject zip = dist.getFileObject("fakeapp.zip"); 137 assertNotNull("ZIP file created: " + zip, zip); 138 139 File zipF = FileUtil.toFile(zip); 140 JarFile zipJ = new JarFile (zipF); 141 Enumeration en = zipJ.entries(); 142 int cntzip = 0; 143 144 StringBuffer sb = new StringBuffer (); 145 StringBuffer hidden = new StringBuffer (); 146 while (en.hasMoreElements()) { 147 JarEntry entry = (JarEntry )en.nextElement(); 148 sb.append("\n"); 149 sb.append(entry.getName()); 150 cntzip++; 151 152 if (entry.getName().endsWith("_hidden")) { 153 hidden.append("\n"); 154 hidden.append(entry.getName()); 155 } 156 } 157 158 if (cntzip == 0) { 159 fail("There should be at least one zip entry: " + sb); 160 } 161 162 if (hidden.length() != 0) { 163 fail("There should be no hidden files in the zip file: " + hidden); 164 } 165 } 166 167 private File createNewJarFile (String prefix) throws IOException { 168 if (prefix == null) { 169 prefix = "modules"; 170 } 171 172 File dir = new File (this.getWorkDir(), prefix); 173 dir.mkdirs(); 174 175 int i = 0; 176 for (;;) { 177 File f = new File (dir, i++ + ".jar"); 178 if (!f.exists ()) { 179 f.createNewFile(); 180 return f; 181 } 182 } 183 } 184 } 185 | Popular Tags |