1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import java.io.File ; 23 import java.io.InputStream ; 24 import org.apache.tools.ant.module.api.support.ActionUtils; 25 import org.netbeans.api.project.ProjectManager; 26 import org.netbeans.modules.apisupport.project.layers.LayerTestBase; 27 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 28 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 29 import org.openide.DialogDescriptor; 30 import org.openide.execution.ExecutorTask; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 40 public class BuildPaintapplicationTest extends TestBase { 41 42 private File paintFolder = null; 43 44 static { 45 System.setProperty("org.netbeans.core.startup.ModuleSystem.CULPRIT", "true"); 47 LayerTestBase.Lkp.setLookup(new Object [0]); 48 DialogDisplayerImpl.returnFromNotify(DialogDescriptor.NO_OPTION); 49 } 50 51 public BuildPaintapplicationTest(String testName) { 52 super(testName); 53 } 54 55 protected void setUp() throws Exception { 56 clearWorkDir(); 57 noDataDir = true; 58 super.setUp(); 59 InstalledFileLocatorImpl.registerDestDir(destDirF); 60 TestAntLogger.getDefault().setEnabled(true); 61 } 62 63 protected void tearDown() throws Exception { 64 TestAntLogger.getDefault().setEnabled(false); 65 } 66 67 70 public int runAntTargetsOnPaintapp(String [] targets) throws Exception { 71 InputStream is = getClass().getClassLoader().getResourceAsStream("org/netbeans/modules/apisupport/paintapp/PaintAppProject.zip"); 72 assertNotNull(is); 73 paintFolder = new File (getWorkDir(),"paintapp"); 74 paintFolder.mkdir(); 75 FileObject fo = FileUtil.toFileObject(paintFolder); 76 assertNotNull(fo); 77 78 79 try { 80 FileUtil.extractJar(fo,is); 81 } finally { 82 is.close(); 83 } 84 85 File buildProps = new File (getWorkDir(), "build.properties"); 86 File privateFolder = new File (new File (paintFolder, "nbproject"),"private"); 87 privateFolder.mkdir(); 88 89 FileObject platfPrivateProps = FileUtil.copyFile(FileUtil.toFileObject(buildProps), FileUtil.toFileObject(privateFolder), "platform-private"); 90 assertNotNull(platfPrivateProps); 91 SuiteProject PaintappSuite = (SuiteProject) ProjectManager.getDefault().findProject(fo); 92 assertNotNull(PaintappSuite); 93 FileObject buildScript = PaintappSuite.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 94 assertNotNull(buildScript); 95 assertTrue(buildScript.isValid()); 96 97 System.out.println("------------- BUILD OUTPUT --------------"); 98 ExecutorTask et = ActionUtils.runTarget(buildScript, targets, null); 99 et.waitFinished(); 100 System.out.println("-----------------------------------------"); 101 102 return et.result(); 103 } 104 105 108 public void testBuildJNLP() throws Exception { 109 int ret = runAntTargetsOnPaintapp(new String [] {"build-jnlp"}); 110 assertEquals("build-jnlp ant target should return zero - build successful", 0 , ret); 111 File dist = new File (paintFolder,"dist"); 112 File warFile = new File (dist,"paintit.war"); 113 assertTrue("paintit.war file should be in dist folder", warFile.exists()); 114 115 } 116 117 120 public void testBuildZip() throws Exception { 121 int ret = runAntTargetsOnPaintapp(new String [] {"build-zip"}); 122 assertEquals("build-zipant target should return zero - build successful", 0 , ret); 123 File dist = new File (paintFolder,"dist"); 124 File zipFile = new File (dist,"paintit.zip"); 125 assertTrue("paintit.zip file should be in dist folder", zipFile.exists()); 126 } 127 128 131 public void testBuild() throws Exception { 132 int ret = runAntTargetsOnPaintapp(new String [] {"build"}); 133 assertEquals("build ant target should return zero - build successful", 0 , ret); 134 File buildFolder = new File (paintFolder,"build"); 135 assertTrue("build folder should exist", buildFolder.exists() && buildFolder.isDirectory()); 136 String [] children = buildFolder.list(); 137 assertTrue("build folder is not empty", children.length>0); 138 139 } 140 141 144 public void testBuildNBMs() throws Exception { 145 int ret = runAntTargetsOnPaintapp(new String [] {"nbms"}); 146 assertEquals("build ant target should return zero - build successful", 0 , ret); 147 File buildFolder = new File (paintFolder,"build"); 148 File updatesFolder = new File (buildFolder,"updates"); 149 assertTrue("build/update folder exists", updatesFolder.exists() && updatesFolder.isDirectory()); 150 File paintNbm = new File (updatesFolder, "org-netbeans-paint.nbm"); 151 File colorchooserNbm = new File (updatesFolder, "org-netbeans-swing-colorchooser.nbm"); 152 assertTrue("Both nbms(paint+colorchooser) are in build/updates folder", paintNbm.exists() && colorchooserNbm.exists()); 153 } 154 155 158 public void testClean() throws Exception { 159 int ret = runAntTargetsOnPaintapp(new String [] {"clean"}); 160 assertEquals("clean ant target should return zero - build successful", 0 , ret); 161 File buildFolder = new File (paintFolder,"build"); 162 File distFolder = new File (paintFolder,"dist"); 163 assertTrue("build and dist folders are deleted", !distFolder.exists() && !buildFolder.exists()); 164 } 165 166 } 167 168 | Popular Tags |