Index: antsrc/org/netbeans/nbbuild/MakeJNLP.java =================================================================== RCS file: /cvs/nbbuild/antsrc/org/netbeans/nbbuild/MakeJNLP.java,v retrieving revision 1.12 diff -u -r1.12 MakeJNLP.java --- antsrc/org/netbeans/nbbuild/MakeJNLP.java 2 Dec 2005 12:56:46 -0000 1.12 +++ antsrc/org/netbeans/nbbuild/MakeJNLP.java 9 Jan 2006 09:38:18 -0000 @@ -45,6 +45,8 @@ import java.util.jar.JarFile; import java.util.jar.JarInputStream; import java.util.jar.Manifest; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.tools.ant.BuildException; @@ -170,9 +172,7 @@ shrt = prop.getProperty("OpenIDE-Module-Long-Description", oneline); } - if (verify) { - verifyExtensions(jar, theJar.getManifest(), dashcnb, codenamebase); - } + Map localizedFiles = verifyExtensions(jar, theJar.getManifest(), dashcnb, codenamebase, verify); File signed = new File(target, jar.getName()); @@ -194,6 +194,34 @@ processExtensions(jar, theJar.getManifest(), writeJNLP, dashcnb, codebase); writeJNLP.write(" \n"); + + { + // write down locales + Iterator it = localizedFiles.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry e = (Map.Entry)it.next(); + String locale = (String)e.getKey(); + List files = (List)e.getValue(); + + writeJNLP.write(" \n"); + + Iterator fit = files.iterator(); + while (fit.hasNext()) { + File n = (File)fit.next(); + File t = new File(target, n.getName()); + + getSignTask().setJar(n); + getSignTask().setSignedjar(t); + getSignTask().execute(); + + writeJNLP.write(" \n"); + } + + writeJNLP.write(" \n"); + + } + } + writeJNLP.write(" \n"); writeJNLP.write("\n"); writeJNLP.close(); @@ -212,7 +240,10 @@ } - private void verifyExtensions(File f, Manifest mf, String dashcnb, String codebasename) throws IOException, BuildException { + private Map verifyExtensions(File f, Manifest mf, String dashcnb, String codebasename, boolean verify) throws IOException, BuildException { + Map localizedFiles = new HashMap(); + + File clusterRoot = f.getParentFile(); String moduleDirPrefix = ""; File updateTracking; @@ -224,6 +255,10 @@ moduleDirPrefix = clusterRoot.getName() + "/" + moduleDirPrefix; clusterRoot = clusterRoot.getParentFile(); if (clusterRoot == null || !clusterRoot.exists()) { + if (!verify) { + return localizedFiles; + } + throw new BuildException("Cannot find update_tracking directory for module " + f); } } @@ -247,16 +282,19 @@ log("project files: " + fileToOwningModule, Project.MSG_DEBUG); String name = relative(f, clusterRoot); log(" removing: " + name, Project.MSG_DEBUG); - fileToOwningModule.remove(name); + removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles); name = "config/Modules/" + dashcnb + ".xml"; log(" removing: " + name, Project.MSG_DEBUG); - fileToOwningModule.remove(name); + removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles); name = "config/ModuleAutoDeps/" + dashcnb + ".xml"; log(" removing: " + name, Project.MSG_DEBUG); - fileToOwningModule.remove(name); + removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles); name = "update_tracking/" + dashcnb + ".xml"; log(" removing: " + name, Project.MSG_DEBUG); - fileToOwningModule.remove(name); + removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles); + + + String path = mf.getMainAttributes().getValue("Class-Path"); if (path != null) { @@ -265,23 +303,53 @@ String s = tok.nextToken(); File e = new File(f.getParentFile(), s); String r = relative(e, clusterRoot); - fileToOwningModule.remove(r); + removeWithLocales(fileToOwningModule, r, clusterRoot, localizedFiles); } } if (verifyExcludes != null) { StringTokenizer tok = new StringTokenizer(verifyExcludes, ", "); while(tok.hasMoreElements()) { - fileToOwningModule.remove(tok.nextToken()); + removeWithLocales(fileToOwningModule, tok.nextToken(), clusterRoot, localizedFiles); } } - if (!fileToOwningModule.isEmpty()) { - throw new BuildException( - "Cannot build JNLP for module " + f + " as these files are in " + - "module's NBM, but are not referenced from any path:\n" + fileToOwningModule.keySet() - ); + if (verify) { + if (!fileToOwningModule.isEmpty()) { + throw new BuildException( + "Cannot build JNLP for module " + f + " as these files are in " + + "module's NBM, but are not referenced from any path:\n" + fileToOwningModule.keySet() + ); + } + } + + return localizedFiles; + } + + private static void removeWithLocales(Map removeFrom, String removeWhat, File clusterRoot, Map/*>*/ recordLocales) { + if (removeFrom.remove(removeWhat) != null && removeWhat.endsWith(".jar")) { + int basedir = removeWhat.indexOf('/'); + String base = basedir == -1 ? "" : removeWhat.substring(0, basedir); + String name = removeWhat.substring(basedir + 1, removeWhat.length() - 4); + Pattern p = Pattern.compile(base + "/locale/" + name + "(|_[a-zA-Z0-9_]+)\\.jar"); + + Iterator it = removeFrom.keySet().iterator(); + while (it.hasNext()) { + String s = (String)it.next(); + Matcher m = p.matcher(s); + if (m.matches()) { + String locale = m.group(1).substring(1); + + List l = (List)recordLocales.get(locale); + if (l == null) { + l = new ArrayList(); + recordLocales.put(locale, l); + } + l.add(new File(clusterRoot, s.replace('/', File.separatorChar))); + it.remove(); + } + } } } Index: test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java =================================================================== RCS file: /cvs/nbbuild/test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java,v retrieving revision 1.8 diff -u -r1.8 MakeJNLPTest.java --- test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java 2 Dec 2005 12:56:46 -0000 1.8 +++ test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java 9 Jan 2006 09:38:18 -0000 @@ -16,7 +16,9 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.util.Arrays; import java.util.Enumeration; +import java.util.HashSet; import java.util.Properties; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -113,6 +115,123 @@ } } + public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Exception { + Manifest m; + + m = ModuleDependenciesTest.createManifest (); + m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3"); + File simpleJar = generateJar ("modules/", new String[0], m, null); + + File parent = simpleJar.getParentFile (); + File localizedJarCZ = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null); + assertEquals("There need to have the same name", simpleJar.getName(), localizedJarCZ.getName()); + assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "0_cs.jar"))); + + File localizedJarZH = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null); + assertEquals("There need to have the same name", simpleJar.getName(), localizedJarZH.getName()); + assertTrue("Successful rename", localizedJarZH.renameTo(new File(localizedJarCZ.getParent(), "0_zh_CN.jar"))); + + File localizedJarJA = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null); + assertEquals("There need to have the same name", simpleJar.getName(), localizedJarJA.getName()); + assertTrue("Successful rename", localizedJarJA.renameTo(new File(localizedJarCZ.getParent(), "0_ja.jar"))); + + File updateTracking = new File(getWorkDir(), "update_tracking"); + updateTracking.mkdirs(); + assertTrue("Created", updateTracking.isDirectory()); + + File trackingFile = new File(updateTracking, "org-my-module.xml"); + FileWriter w = new FileWriter(trackingFile); + w.write( +"\n" + +"\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + +" \n" + +"\n" + ); + w.close(); + + + File output = new File(parent, "output"); + File ks = genereteKeystore("jnlp", "netbeans-test"); + + java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( + "" + + "" + + " " + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + "" + + "" + ); + PublicPackagesInProjectizedXMLTest.execute (f, new String[] { "-verbose" }); + + assertTrue ("Output exists", output.exists ()); + assertTrue ("Output directory created", output.isDirectory()); + + String[] files = output.list(); + assertEquals("It has two files plus localized ones", 5, files.length); + + HashSet setFiles = new HashSet(Arrays.asList(files)); + + if (!setFiles.contains("0.jar")) fail("0.jar shall be there: " + setFiles); + if (!setFiles.contains("org-my-module.jnlp")) fail("org-my-module.jnlp shall be there: " + setFiles); + if (!setFiles.contains("0_cs.jar")) fail("0_cs.jar shall be there: " + setFiles); + if (!setFiles.contains("0_zh_CN.jar")) fail("0_zh_CN.jar shall be there: " + setFiles); + if (!setFiles.contains("0_ja.jar")) fail("0_ja.jar shall be there: " + setFiles); + + + File jnlp = new File(output, "org-my-module.jnlp"); + String res = ModuleDependenciesTest.readFile (jnlp); + + + assertTrue ("Component JNLP type: " + res, res.indexOf ("") >= 0); + assertTrue ("We support all permitions by default: " + res, res.indexOf ("") >= 0); + + Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res); + assertTrue("codebase is there", match.find()); + assertEquals("one group found", 1, match.groupCount()); + String base = match.group(1); + + assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base); + + assertResource(res, "cs", "0_cs.jar"); + assertResource(res, "ja", "0_ja.jar"); + assertResource(res, "zh", "0_zh_CN.jar"); + + CHECK_SIGNED: for (int i = 0; i < files.length; i++) { + if (!files[i].endsWith(".jar")) { + continue; + } + + File jar = new File(output, files[i]); + + JarFile signed = new JarFile(jar); + Enumeration it = signed.entries(); + while (it.hasMoreElements()) { + JarEntry entry = (JarEntry)it.nextElement(); + if (entry.getName().endsWith(".SF")) { + continue CHECK_SIGNED; + } + } + fail ("File does not seem to be signed: " + jar); + } + } + + private static void assertResource(String where, String locale, String file) { + where = where.replace('\n', ' '); + Matcher match = Pattern.compile(".*.*").matcher(where); + assertTrue("File really referenced " + file + " in locale " + locale + "\n" + where, match.find()); + } public void testOneCanChangeTheCodeBase() throws Exception { Manifest m;