1 19 package org.netbeans.nbbuild; 20 21 import java.io.FileOutputStream ; 22 import java.io.FileWriter ; 23 import java.util.jar.JarEntry ; 24 import java.util.jar.JarOutputStream ; 25 import java.util.jar.Manifest ; 26 import junit.framework.*; 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.util.HashSet ; 30 import java.util.Set ; 31 import java.util.StringTokenizer ; 32 import java.util.jar.JarFile ; 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.types.Parameter; 35 import org.apache.tools.ant.types.selectors.SelectorUtils; 36 37 import org.netbeans.junit.NbTestCase; 38 39 43 public class CreateModuleXMLTest extends NbTestCase { 44 45 public CreateModuleXMLTest(String testName) { 46 super(testName); 47 } 48 49 public void testIncludesAllModulesByDefault() throws Exception { 50 Manifest m = ModuleDependenciesTest.createManifest (); 51 m.getMainAttributes().putValue("OpenIDE-Module", "org.my.module"); 52 File aModule = generateJar(new String [0], m); 53 54 File output = new File (getWorkDir(), "output"); 55 56 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 57 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 58 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 59 " <taskdef name=\"createmodulexml\" classname=\"org.netbeans.nbbuild.CreateModuleXML\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 60 "<target name=\"all\" >" + 61 " <mkdir dir='" + output + "' />" + 62 " <createmodulexml xmldir='" + output + "' >" + 63 " <hidden dir='" + aModule.getParent() + "' >" + 64 " <include name='" + aModule.getName() + "' />" + 65 " </hidden>" + 66 " </createmodulexml>" + 67 "</target>" + 68 "</project>" 69 ); 70 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { "-verbose" }); 71 72 assertTrue ("Output exists", output.exists ()); 73 assertTrue ("Output directory created", output.isDirectory()); 74 75 String [] files = output.list(); 76 assertEquals("It one file", 1, files.length); 77 assertEquals("Its name reflects the code name of the module", "org-my-module.xml_hidden", files[0]); 78 79 } 80 81 82 private final File createNewJarFile () throws IOException { 83 File dir = new File (this.getWorkDir(), "modules"); 84 dir.mkdirs(); 85 86 int i = 0; 87 for (;;) { 88 File f = new File (dir, i++ + ".jar"); 89 if (!f.exists ()) return f; 90 } 91 } 92 93 protected final File generateJar (String [] content, Manifest manifest) throws IOException { 94 File f = createNewJarFile (); 95 96 JarOutputStream os; 97 if (manifest != null) { 98 os = new JarOutputStream (new FileOutputStream (f), manifest); 99 } else { 100 os = new JarOutputStream (new FileOutputStream (f)); 101 } 102 103 for (int i = 0; i < content.length; i++) { 104 os.putNextEntry(new JarEntry (content[i])); 105 os.closeEntry(); 106 } 107 os.closeEntry (); 108 os.close(); 109 110 return f; 111 } 112 113 } 114 | Popular Tags |