001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.jnlp;
043:
044: import java.io.File;
045: import java.io.FileInputStream;
046: import java.io.FileNotFoundException;
047: import java.io.FileOutputStream;
048: import java.io.FileWriter;
049: import java.io.IOException;
050: import java.io.InputStream;
051: import java.io.OutputStream;
052: import java.util.ArrayList;
053: import java.util.Arrays;
054: import java.util.Enumeration;
055: import java.util.List;
056: import java.util.jar.JarEntry;
057: import java.util.jar.JarFile;
058: import java.util.logging.Level;
059: import java.util.logging.Logger;
060: import javax.xml.transform.Result;
061: import javax.xml.transform.Source;
062: import javax.xml.transform.Transformer;
063: import javax.xml.transform.TransformerFactory;
064: import javax.xml.transform.stream.StreamResult;
065: import javax.xml.transform.stream.StreamSource;
066: import junit.framework.Test;
067: import org.netbeans.api.project.ProjectManager;
068: import org.netbeans.junit.NbTestSuite;
069: import org.netbeans.modules.apisupport.project.DialogDisplayerImpl;
070: import org.netbeans.modules.apisupport.project.InstalledFileLocatorImpl;
071: import org.netbeans.modules.apisupport.project.NbModuleProject;
072: import org.netbeans.modules.apisupport.project.TestBase;
073: import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
074: import org.netbeans.modules.apisupport.project.suite.SuiteProject;
075: import org.netbeans.modules.apisupport.project.ui.SuiteActions;
076: import org.netbeans.spi.project.ActionProvider;
077: import org.netbeans.spi.project.support.ant.AntProjectHelper;
078: import org.netbeans.spi.project.support.ant.EditableProperties;
079: import org.openide.DialogDescriptor;
080: import org.openide.execution.ExecutorTask;
081: import org.openide.filesystems.FileLock;
082: import org.openide.filesystems.FileObject;
083: import org.openide.filesystems.FileUtil;
084: import org.openide.util.Lookup;
085:
086: /**
087: * Checks JNLP support behaviour.
088: * @author Jaroslav Tulach
089: */
090: public class GenerateJNLPApplicationTest extends TestBase {
091:
092: static {
093: // #65461: do not try to load ModuleInfo instances from ant module
094: System.setProperty(
095: "org.netbeans.core.startup.ModuleSystem.CULPRIT",
096: "true");
097: LayerTestBase.Lkp.setLookup(new Object[0]);
098: }
099:
100: private SuiteProject suite;
101: private Logger LOG;
102:
103: public GenerateJNLPApplicationTest(String name) {
104: super (name);
105: }
106:
107: @Override
108: protected Level logLevel() {
109: return Level.FINE;
110: }
111:
112: public static Test suite() {
113: //return new GenerateJNLPApplicationTest("testBuildJNLPWhenLocalizedFilesAreMissing");
114: return new NbTestSuite(GenerateJNLPApplicationTest.class);
115: }
116:
117: protected @Override
118: void setUp() throws Exception {
119: LOG = Logger.getLogger("test." + getName());
120:
121: super .setUp();
122:
123: InstalledFileLocatorImpl.registerDestDir(destDirF);
124:
125: suite = TestBase.generateSuite(new File(getWorkDir(),
126: "projects"), "suite");
127: NbModuleProject proj = TestBase.generateSuiteComponent(suite,
128: "mod1");
129:
130: suite.open();
131: proj.open();
132: }
133:
134: public void testBuildTheJNLPAppWhenAppNamePropIsNotSet()
135: throws Exception {
136: SuiteActions p = (SuiteActions) suite.getLookup().lookup(
137: ActionProvider.class);
138: assertNotNull("Provider is here");
139:
140: List l = Arrays.asList(p.getSupportedActions());
141: assertTrue("We support build-jnlp: " + l, l
142: .contains("build-jnlp"));
143:
144: DialogDisplayerImpl
145: .returnFromNotify(DialogDescriptor.NO_OPTION);
146: ExecutorTask task = p.invokeActionImpl("build-jnlp", suite
147: .getLookup());
148: assertNull("did not even run task", task);
149: }
150:
151: public void testBuildTheJNLPAppWhenAppNamePropIsSet()
152: throws Exception {
153: EditableProperties ep = suite.getHelper().getProperties(
154: AntProjectHelper.PROJECT_PROPERTIES_PATH);
155: ep.setProperty("app.name", "fakeapp");
156:
157: File someJar = createNewJarFile("fake-jnlp-servlet");
158:
159: ep.setProperty("enabled.clusters", TestBase.CLUSTER_PLATFORM);
160: ep.setProperty("disabled.modules",
161: "org.netbeans.modules.autoupdate,"
162: + "org.openide.compat,"
163: + "org.netbeans.api.progress,"
164: + "org.netbeans.core.multiview,"
165: + "org.openide.filesystems,"
166: + "org.openide.modules," + "org.openide.util,"
167: + "org.netbeans.core.execution,"
168: + "org.netbeans.core.output2,"
169: + "org.netbeans.core.ui,"
170: + "org.netbeans.core.windows,"
171: + "org.netbeans.core,"
172: + "org.netbeans.modules.favorites,"
173: + "org.netbeans.modules.javahelp,"
174: + "org.netbeans.modules.masterfs,"
175: + "org.netbeans.modules.queries,"
176: + "org.netbeans.modules.settings,"
177: + "org.netbeans.swing.plaf,"
178: + "org.netbeans.swing.tabcontrol,"
179: + "org.openide.actions," + "org.openide.awt,"
180: + "org.openide.dialogs,"
181: + "org.openide.execution,"
182: + "org.openide.explorer," + "org.openide.io,"
183: + "org.openide.loaders," + "org.openide.nodes,"
184: + "org.openide.options," + "org.openide.text,"
185: + "org.openide.windows,"
186: + "org.openide.util.enumerations" + "");
187: ep.setProperty("jnlp.servlet.jar", someJar.toString());
188: suite.getHelper().putProperties(
189: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
190: ProjectManager.getDefault().saveProject(suite);
191: LOG.info("Properties stored");
192:
193: SuiteActions p = (SuiteActions) suite.getLookup().lookup(
194: ActionProvider.class);
195: assertNotNull("Provider is here");
196:
197: List l = Arrays.asList(p.getSupportedActions());
198: assertTrue("We support build-jnlp: " + l, l
199: .contains("build-jnlp"));
200:
201: DialogDisplayerImpl.returnFromNotify(null);
202: LOG.info("invoking build-jnlp");
203: ExecutorTask task = p.invokeActionImpl("build-jnlp", suite
204: .getLookup());
205: LOG.info("Invocation started");
206:
207: assertNotNull("Task was started", task);
208: LOG.info("Waiting for task to finish");
209: task.waitFinished();
210: LOG.info("Checking the result");
211: assertEquals("Finished ok", 0, task.result());
212: LOG.info("Testing the content of the directory");
213:
214: FileObject[] arr = suite.getProjectDirectory().getChildren();
215: List<FileObject> subobj = new ArrayList<FileObject>(Arrays
216: .asList(arr));
217: subobj
218: .remove(suite.getProjectDirectory().getFileObject(
219: "mod1"));
220: subobj.remove(suite.getProjectDirectory().getFileObject(
221: "nbproject"));
222: subobj.remove(suite.getProjectDirectory().getFileObject(
223: "build.xml"));
224: FileObject master = suite.getProjectDirectory().getFileObject(
225: "master.jnlp");
226: assertNotNull("Master must be created", master);
227: FileObject branding = suite.getProjectDirectory()
228: .getFileObject("branding.jnlp");
229: assertNotNull("Branding must be created", branding);
230: subobj.remove(master);
231: subobj.remove(branding);
232: subobj.remove(suite.getProjectDirectory()
233: .getFileObject("build"));
234: FileObject dist = suite.getProjectDirectory().getFileObject(
235: "dist");
236: assertNotNull("dist created", dist);
237: subobj.remove(dist);
238:
239: if (!subobj.isEmpty()) {
240: fail("There should be no created directories in the suite dir: "
241: + subobj);
242: }
243:
244: FileObject war = dist.getFileObject("fakeapp.war");
245: assertNotNull("War file created: " + war, war);
246:
247: File warF = FileUtil.toFile(war);
248: JarFile warJ = new JarFile(warF);
249: Enumeration en = warJ.entries();
250: int cntJnlp = 0;
251: while (en.hasMoreElements()) {
252: JarEntry entry = (JarEntry) en.nextElement();
253: if (!entry.getName().endsWith(".jnlp")) {
254: continue;
255: }
256: cntJnlp++;
257:
258: byte[] data = new byte[(int) entry.getSize()];
259: int len = 0;
260: InputStream is = warJ.getInputStream(entry);
261: for (int pos = 0; pos < data.length;) {
262: int r = is.read(data, pos, data.length - pos);
263: pos += r;
264: len += r;
265: }
266: is.close();
267: assertEquals("Correct data read: " + entry, data.length,
268: len);
269:
270: String s = new String(data);
271: if (s.indexOf(getWorkDir().getName()) >= 0) {
272: fail("Name of work dir in a file, means that there is very likely local reference to a file: "
273: + entry + "\n" + s);
274: }
275: }
276:
277: if (cntJnlp == 0) {
278: fail("There should be at least one jnlp entry");
279: }
280: }
281:
282: public void testItIsPossibleToGenerateStaticRepository()
283: throws Exception {
284: EditableProperties ep = suite.getHelper().getProperties(
285: AntProjectHelper.PROJECT_PROPERTIES_PATH);
286: ep.setProperty("app.name", "fakeapp");
287:
288: ep.setProperty("enabled.clusters", TestBase.CLUSTER_PLATFORM);
289: ep.setProperty("disabled.modules",
290: "org.netbeans.modules.autoupdate,"
291: + "org.openide.compat,"
292: + "org.netbeans.api.progress,"
293: + "org.netbeans.core.multiview,"
294: + "org.openide.filesystems,"
295: + "org.openide.modules," + "org.openide.util,"
296: + "org.netbeans.core.execution,"
297: + "org.netbeans.core.output2,"
298: + "org.netbeans.core.ui,"
299: + "org.netbeans.core.windows,"
300: + "org.netbeans.core,"
301: + "org.netbeans.modules.favorites,"
302: + "org.netbeans.modules.javahelp,"
303: + "org.netbeans.modules.masterfs,"
304: + "org.netbeans.modules.queries,"
305: + "org.netbeans.modules.settings,"
306: + "org.netbeans.swing.plaf,"
307: + "org.netbeans.swing.tabcontrol,"
308: + "org.openide.actions," + "org.openide.awt,"
309: + "org.openide.dialogs,"
310: + "org.openide.execution,"
311: + "org.openide.explorer," + "org.openide.io,"
312: + "org.openide.loaders," + "org.openide.nodes,"
313: + "org.openide.options," + "org.openide.text,"
314: + "org.openide.windows,"
315: + "org.openide.util.enumerations" + "");
316: suite.getHelper().putProperties(
317: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
318: ProjectManager.getDefault().saveProject(suite);
319: LOG.info("Properties stored");
320:
321: FileObject fo = suite.getProjectDirectory().getFileObject(
322: "build.xml");
323: assertNotNull("There should be a build script", fo);
324:
325: {
326: String s = readFile(fo);
327: int insert = s.indexOf("</project>");
328: if (insert == -1) {
329: fail("there should be insert place: " + s);
330: }
331:
332: s = s.substring(0, insert)
333: + " <target name='build-jnlp' depends='build,-jdk-init' description='Builds a static JNLP version of the app.' >"
334: + " <ant antfile='${harness.dir}/jnlp.xml' target='build-jnlp-nowar'>"
335: + " <property name='jnlp.codebase' value='http://www.netbeans.org/download/samples/jnlp/htmleditor/' />"
336: + " </ant>" + "</target>" + s.substring(insert);
337: FileLock lock = fo.lock();
338: OutputStream os = fo.getOutputStream(lock);
339: try {
340: os.write(s.getBytes());
341: } finally {
342: os.close();
343: lock.releaseLock();
344: }
345: }
346:
347: SuiteActions p = (SuiteActions) suite.getLookup().lookup(
348: ActionProvider.class);
349: assertNotNull("Provider is here");
350:
351: List l = Arrays.asList(p.getSupportedActions());
352: assertTrue("We support build-jnlp: " + l, l
353: .contains("build-jnlp"));
354:
355: DialogDisplayerImpl.returnFromNotify(null);
356: LOG.info("invoking build-jnlp");
357: ExecutorTask task = p.invokeActionImpl("build-jnlp", suite
358: .getLookup());
359: LOG.info("Invocation started");
360:
361: assertNotNull("Task was started", task);
362: LOG.info("Waiting for task to finish");
363: task.waitFinished();
364: LOG.info("Checking the result");
365: assertEquals("Finished ok", 0, task.result());
366: LOG.info("Testing the content of the directory");
367:
368: FileObject[] arr = suite.getProjectDirectory().getChildren();
369: List<FileObject> subobj = new ArrayList<FileObject>(Arrays
370: .asList(arr));
371: subobj
372: .remove(suite.getProjectDirectory().getFileObject(
373: "mod1"));
374: subobj.remove(suite.getProjectDirectory().getFileObject(
375: "nbproject"));
376: FileObject buildXML = suite.getProjectDirectory()
377: .getFileObject("build.xml");
378: subobj.remove(buildXML);
379: FileObject master = suite.getProjectDirectory().getFileObject(
380: "master.jnlp");
381: assertNotNull("Master must be created", master);
382: subobj.remove(master);
383: FileObject build = suite.getProjectDirectory().getFileObject(
384: "build");
385: subobj.remove(build);
386:
387: {
388: // check content of build
389: FileObject jnlpDir = build.getFileObject("jnlp/app/");
390: assertNotNull("app dir exists", jnlpDir);
391: FileObject[] arrX = jnlpDir.getChildren();
392: int cnt = 0;
393: for (int i = 0; i < arrX.length; i++) {
394: if (arrX[i].hasExt("jnlp")) {
395: cnt++;
396: String jnlpContent = readFile(arrX[i]);
397: if (jnlpContent
398: .indexOf("http://www.netbeans.org/download/samples/jnlp/htmleditor/app/") == -1) {
399: fail(" for " + arrX[i]
400: + " URL with /app/ must be present: "
401: + jnlpContent);
402: }
403: }
404: }
405:
406: if (cnt == 0)
407: fail("At least one jnlp file in app dir");
408: }
409:
410: {
411: // check content of netbeans default dir
412: FileObject jnlpDir = build.getFileObject("jnlp/netbeans/");
413: assertNotNull("netbeans dir exists", jnlpDir);
414: FileObject[] arrX = jnlpDir.getChildren();
415: int cnt = 0;
416: for (int i = 0; i < arrX.length; i++) {
417: if (arrX[i].hasExt("jnlp")) {
418: cnt++;
419: String jnlpContent = readFile(arrX[i]);
420: if (jnlpContent
421: .indexOf("http://www.netbeans.org/download/samples/jnlp/htmleditor/netbeans/") == -1) {
422: fail(" for "
423: + arrX[i]
424: + " URL with /netbeans/ must be present: "
425: + jnlpContent);
426: }
427: }
428: }
429:
430: if (cnt == 0)
431: fail("At least one jnlp file in app dir");
432: }
433:
434: // check master file has it
435: String masterContent = readFile(master);
436: if (masterContent
437: .indexOf("http://www.netbeans.org/download/samples/jnlp/htmleditor/") == -1) {
438: fail("URL must be present in master: " + masterContent);
439: }
440:
441: FileObject dist = suite.getProjectDirectory().getFileObject(
442: "dist");
443: assertNull("no dist created", dist);
444:
445: FileObject branding = suite.getProjectDirectory()
446: .getFileObject("branding.jnlp");
447: assertNotNull("Branding must be created", branding);
448: subobj.remove(branding);
449:
450: if (!subobj.isEmpty()) {
451: fail("There should be no created directories in the suite dir: "
452: + subobj);
453: }
454:
455: }
456:
457: public void testBuildJNLPWhenLocalizedFilesAreMissing()
458: throws Exception {
459: File openideUtil = new File(Lookup.class.getProtectionDomain()
460: .getCodeSource().getLocation().toURI());
461: File platformC = openideUtil.getParentFile().getParentFile();
462:
463: File copyP = new File(new File(getWorkDir(), "netbeans"),
464: "platform8");
465: copyP.mkdirs();
466:
467: copyFiles(platformC, copyP);
468:
469: EditableProperties ep = suite.getHelper().getProperties(
470: AntProjectHelper.PROJECT_PROPERTIES_PATH);
471: ep.setProperty("app.name", "fakeapp");
472:
473: File someJar = createNewJarFile("fake-jnlp-servlet");
474:
475: File platformProp = new File(new File(suite
476: .getProjectDirectoryFile(), "nbproject"),
477: "platform.properties");
478: FileWriter os = new FileWriter(platformProp, true);
479: os.write("\nharness.dir=" + platformC.getParent() + "/harness");
480: os.write("\nnetbeans.dest.dir=" + copyP.getParent());
481: os.write("\napp.name=fakeapp\n");
482: os.write("\njnlp.servlet.jar=" + someJar);
483: os.close();
484:
485: File where = new File(copyP, "update_tracking");
486: Source xslt = new StreamSource(getClass().getResourceAsStream(
487: "GenerateJNLPApplicationTest.xsl"));
488: Transformer t = TransformerFactory.newInstance()
489: .newTransformer(xslt);
490: File f = new File(where, "org-netbeans-core-startup.xml");
491: assertTrue("core exists: " + f, f.exists());
492: {
493: Source s = new StreamSource(f);
494: File tmp = new File(f.getParent(), f.getName() + ".copy");
495: Result r = new StreamResult(tmp);
496: t.clearParameters();
497: t.setParameter("file", "core/locale/core_cs.jar");
498: t.transform(s, r);
499: f.delete();
500: tmp.renameTo(f);
501: }
502:
503: ProjectManager.getDefault().saveProject(suite);
504:
505: ep.setProperty("enabled.clusters", TestBase.CLUSTER_PLATFORM);
506: ep.setProperty("disabled.modules",
507: "org.netbeans.modules.autoupdate,"
508: + "org.openide.compat,"
509: + "org.netbeans.api.progress,"
510: + "org.netbeans.core.multiview,"
511: + "org.openide.filesystems,"
512: + "org.openide.modules," + "org.openide.util,"
513: + "org.netbeans.core.execution,"
514: + "org.netbeans.core.output2,"
515: + "org.netbeans.core.ui,"
516: + "org.netbeans.core.windows,"
517: + "org.netbeans.core,"
518: + "org.netbeans.modules.favorites,"
519: + "org.netbeans.modules.javahelp,"
520: + "org.netbeans.modules.masterfs,"
521: + "org.netbeans.modules.queries,"
522: + "org.netbeans.modules.settings,"
523: + "org.netbeans.swing.plaf,"
524: + "org.netbeans.swing.tabcontrol,"
525: + "org.openide.actions," + "org.openide.awt,"
526: + "org.openide.dialogs,"
527: + "org.openide.execution,"
528: + "org.openide.explorer," + "org.openide.io,"
529: + "org.openide.loaders," + "org.openide.nodes,"
530: + "org.openide.options," + "org.openide.text,"
531: + "org.openide.windows,"
532: + "org.openide.util.enumerations" + "");
533: ep.setProperty("jnlp.servlet.jar", someJar.toString());
534: suite.getHelper().putProperties(
535: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
536: ProjectManager.getDefault().saveProject(suite);
537: LOG.info("Properties stored");
538:
539: SuiteActions p = (SuiteActions) suite.getLookup().lookup(
540: ActionProvider.class);
541: assertNotNull("Provider is here");
542:
543: List l = Arrays.asList(p.getSupportedActions());
544: assertTrue("We support build-jnlp: " + l, l
545: .contains("build-jnlp"));
546: /*
547: WeakReference<?> ref = new WeakReference<Object>(suite);
548: suite = null;
549: assertGC("Project can go away", ref);
550:
551: NbPlatform nbp = suite.getPlatform(false);
552: assertNotNull("Platform is associated", nbp);
553: assertEquals(copyP.getParentFile(), nbp.getDestDir());
554: */
555: DialogDisplayerImpl.returnFromNotify(null);
556: LOG.info("invoking build-jnlp");
557: ExecutorTask task = p.invokeActionImpl("build-jnlp", suite
558: .getLookup());
559: LOG.info("Invocation started");
560:
561: assertNotNull("Task was started", task);
562: LOG.info("Waiting for task to finish");
563: task.waitFinished();
564: LOG.info("Checking the result");
565: assertEquals("Finished ok", 0, task.result());
566: LOG.info("Testing the content of the directory");
567:
568: FileObject[] arr = suite.getProjectDirectory().getChildren();
569: List<FileObject> subobj = new ArrayList<FileObject>(Arrays
570: .asList(arr));
571: subobj
572: .remove(suite.getProjectDirectory().getFileObject(
573: "mod1"));
574: subobj.remove(suite.getProjectDirectory().getFileObject(
575: "nbproject"));
576: subobj.remove(suite.getProjectDirectory().getFileObject(
577: "build.xml"));
578: FileObject master = suite.getProjectDirectory().getFileObject(
579: "master.jnlp");
580: assertNotNull("Master must be created", master);
581: FileObject branding = suite.getProjectDirectory()
582: .getFileObject("branding.jnlp");
583: assertNotNull("Branding must be created", branding);
584: subobj.remove(master);
585: subobj.remove(branding);
586: subobj.remove(suite.getProjectDirectory()
587: .getFileObject("build"));
588: FileObject dist = suite.getProjectDirectory().getFileObject(
589: "dist");
590: assertNotNull("dist created", dist);
591: subobj.remove(dist);
592:
593: if (!subobj.isEmpty()) {
594: fail("There should be no created directories in the suite dir: "
595: + subobj);
596: }
597:
598: FileObject war = dist.getFileObject("fakeapp.war");
599: assertNotNull("War file created: " + war, war);
600:
601: File warF = FileUtil.toFile(war);
602: JarFile warJ = new JarFile(warF);
603: Enumeration en = warJ.entries();
604: int cntJnlp = 0;
605: while (en.hasMoreElements()) {
606: JarEntry entry = (JarEntry) en.nextElement();
607: if (!entry.getName().endsWith(".jnlp")) {
608: continue;
609: }
610: cntJnlp++;
611:
612: byte[] data = new byte[(int) entry.getSize()];
613: int len = 0;
614: InputStream is = warJ.getInputStream(entry);
615: for (int pos = 0; pos < data.length;) {
616: int r = is.read(data, pos, data.length - pos);
617: pos += r;
618: len += r;
619: }
620: is.close();
621: assertEquals("Correct data read: " + entry, data.length,
622: len);
623:
624: String s = new String(data);
625: if (s.indexOf(getWorkDir().getName()) >= 0) {
626: fail("Name of work dir in a file, means that there is very likely local reference to a file: "
627: + entry + "\n" + s);
628: }
629: }
630:
631: if (cntJnlp == 0) {
632: fail("There should be at least one jnlp entry");
633: }
634: }
635:
636: private static String readFile(final FileObject fo)
637: throws IOException, FileNotFoundException {
638: // write user modified version of the file
639: byte[] arr = new byte[(int) fo.getSize()];
640: InputStream is = fo.getInputStream();
641: int len = is.read(arr);
642: assertEquals("Read all", arr.length, len);
643: String s = new String(arr);
644: is.close();
645: return s;
646: }
647:
648: private void copyFiles(File from, File to) throws IOException {
649: LOG.fine("Copy " + from + " to " + to);
650: if (from.isDirectory()) {
651: to.mkdirs();
652: for (File f : from.listFiles()) {
653: copyFiles(f, new File(to, f.getName()));
654: }
655: } else {
656: byte[] arr = new byte[4096];
657: FileInputStream is = new FileInputStream(from);
658: FileOutputStream os = new FileOutputStream(to);
659: for (;;) {
660: int r = is.read(arr);
661: if (r == -1) {
662: break;
663: }
664: os.write(arr, 0, r);
665: }
666: is.close();
667: os.close();
668: }
669:
670: }
671:
672: private File createNewJarFile(String prefix) throws IOException {
673: if (prefix == null) {
674: prefix = "modules";
675: }
676:
677: File dir = new File(this .getWorkDir(), prefix);
678: dir.mkdirs();
679:
680: int i = 0;
681: for (;;) {
682: File f = new File(dir, i++ + ".jar");
683: if (!f.exists()) {
684: f.createNewFile();
685: return f;
686: }
687: }
688: }
689: }
|