This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 71129
Collapse All | Expand All

(-)antsrc/org/netbeans/nbbuild/MakeJNLP.java (-15 / +83 lines)
Lines 45-50 Link Here
45
import java.util.jar.JarFile;
45
import java.util.jar.JarFile;
46
import java.util.jar.JarInputStream;
46
import java.util.jar.JarInputStream;
47
import java.util.jar.Manifest;
47
import java.util.jar.Manifest;
48
import java.util.regex.Matcher;
49
import java.util.regex.Pattern;
48
import java.util.zip.ZipEntry;
50
import java.util.zip.ZipEntry;
49
import java.util.zip.ZipFile;
51
import java.util.zip.ZipFile;
50
import org.apache.tools.ant.BuildException;
52
import org.apache.tools.ant.BuildException;
Lines 170-178 Link Here
170
                shrt = prop.getProperty("OpenIDE-Module-Long-Description", oneline);
172
                shrt = prop.getProperty("OpenIDE-Module-Long-Description", oneline);
171
            }
173
            }
172
            
174
            
173
            if (verify) {
175
            Map localizedFiles = verifyExtensions(jar, theJar.getManifest(), dashcnb, codenamebase, verify);
174
                verifyExtensions(jar, theJar.getManifest(), dashcnb, codenamebase);
175
            }
176
            
176
            
177
177
178
            File signed = new File(target, jar.getName());
178
            File signed = new File(target, jar.getName());
Lines 194-199 Link Here
194
            processExtensions(jar, theJar.getManifest(), writeJNLP, dashcnb, codebase);
194
            processExtensions(jar, theJar.getManifest(), writeJNLP, dashcnb, codebase);
195
            
195
            
196
            writeJNLP.write("  </resources>\n");
196
            writeJNLP.write("  </resources>\n");
197
            
198
            {
199
                // write down locales
200
                Iterator it = localizedFiles.entrySet().iterator();
201
                while (it.hasNext()) {
202
                    Map.Entry e = (Map.Entry)it.next();
203
                    String locale = (String)e.getKey();
204
                    List files = (List)e.getValue();
205
                    
206
                    writeJNLP.write("  <resources locale='" + locale + "'>\n");
207
208
                    Iterator fit = files.iterator();
209
                    while (fit.hasNext()) {
210
                        File n = (File)fit.next();
211
                        File t = new File(target, n.getName());
212
                        
213
                        getSignTask().setJar(n);
214
                        getSignTask().setSignedjar(t);
215
                        getSignTask().execute();
216
                        
217
                        writeJNLP.write("     <jar href='"); writeJNLP.write(n.getName()); writeJNLP.write("'/>\n");
218
                    }
219
220
                    writeJNLP.write("  </resources>\n");
221
                    
222
                }
223
            }        
224
            
197
            writeJNLP.write("  <component-desc/>\n");
225
            writeJNLP.write("  <component-desc/>\n");
198
            writeJNLP.write("</jnlp>\n");
226
            writeJNLP.write("</jnlp>\n");
199
            writeJNLP.close();
227
            writeJNLP.close();
Lines 212-218 Link Here
212
        
240
        
213
    }
241
    }
214
    
242
    
215
    private void verifyExtensions(File f, Manifest mf, String dashcnb, String codebasename) throws IOException, BuildException {
243
    private Map verifyExtensions(File f, Manifest mf, String dashcnb, String codebasename, boolean verify) throws IOException, BuildException {
244
        Map localizedFiles = new HashMap();
245
        
246
        
216
        File clusterRoot = f.getParentFile();
247
        File clusterRoot = f.getParentFile();
217
        String moduleDirPrefix = "";
248
        String moduleDirPrefix = "";
218
        File updateTracking;
249
        File updateTracking;
Lines 224-229 Link Here
224
            moduleDirPrefix = clusterRoot.getName() + "/" + moduleDirPrefix;
255
            moduleDirPrefix = clusterRoot.getName() + "/" + moduleDirPrefix;
225
            clusterRoot = clusterRoot.getParentFile();
256
            clusterRoot = clusterRoot.getParentFile();
226
            if (clusterRoot == null || !clusterRoot.exists()) {
257
            if (clusterRoot == null || !clusterRoot.exists()) {
258
                if (!verify) {
259
                    return localizedFiles;
260
                }
261
                
227
                throw new BuildException("Cannot find update_tracking directory for module " + f);
262
                throw new BuildException("Cannot find update_tracking directory for module " + f);
228
            }
263
            }
229
        }
264
        }
Lines 247-262 Link Here
247
        log("project files: " + fileToOwningModule, Project.MSG_DEBUG);
282
        log("project files: " + fileToOwningModule, Project.MSG_DEBUG);
248
        String name = relative(f, clusterRoot);
283
        String name = relative(f, clusterRoot);
249
        log("  removing: " + name, Project.MSG_DEBUG);
284
        log("  removing: " + name, Project.MSG_DEBUG);
250
        fileToOwningModule.remove(name);
285
        removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles);
251
        name = "config/Modules/" + dashcnb + ".xml";
286
        name = "config/Modules/" + dashcnb + ".xml";
252
        log("  removing: " + name, Project.MSG_DEBUG);
287
        log("  removing: " + name, Project.MSG_DEBUG);
253
        fileToOwningModule.remove(name);
288
        removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles);
254
        name = "config/ModuleAutoDeps/" + dashcnb + ".xml";
289
        name = "config/ModuleAutoDeps/" + dashcnb + ".xml";
255
        log("  removing: " + name, Project.MSG_DEBUG);
290
        log("  removing: " + name, Project.MSG_DEBUG);
256
        fileToOwningModule.remove(name);
291
        removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles);
257
        name = "update_tracking/" + dashcnb + ".xml";
292
        name = "update_tracking/" + dashcnb + ".xml";
258
        log("  removing: " + name, Project.MSG_DEBUG);
293
        log("  removing: " + name, Project.MSG_DEBUG);
259
        fileToOwningModule.remove(name);
294
        removeWithLocales(fileToOwningModule, name, clusterRoot, localizedFiles);
295
        
296
        
297
        
260
        
298
        
261
        String path = mf.getMainAttributes().getValue("Class-Path");
299
        String path = mf.getMainAttributes().getValue("Class-Path");
262
        if (path != null) {
300
        if (path != null) {
Lines 265-287 Link Here
265
                String s = tok.nextToken();
303
                String s = tok.nextToken();
266
                File e = new File(f.getParentFile(), s);
304
                File e = new File(f.getParentFile(), s);
267
                String r = relative(e, clusterRoot);
305
                String r = relative(e, clusterRoot);
268
                fileToOwningModule.remove(r);
306
                removeWithLocales(fileToOwningModule, r, clusterRoot, localizedFiles);
269
            }
307
            }
270
        }
308
        }
271
        
309
        
272
        if (verifyExcludes != null) {
310
        if (verifyExcludes != null) {
273
            StringTokenizer tok = new StringTokenizer(verifyExcludes, ", ");
311
            StringTokenizer tok = new StringTokenizer(verifyExcludes, ", ");
274
            while(tok.hasMoreElements()) {
312
            while(tok.hasMoreElements()) {
275
                fileToOwningModule.remove(tok.nextToken());
313
                removeWithLocales(fileToOwningModule, tok.nextToken(), clusterRoot, localizedFiles);
276
            }
314
            }
277
        }
315
        }
278
            
316
            
279
        
317
        
280
        if (!fileToOwningModule.isEmpty()) {
318
        if (verify) {
281
            throw new BuildException(
319
            if (!fileToOwningModule.isEmpty()) {
282
                "Cannot build JNLP for module " + f + " as these files are in " +
320
                throw new BuildException(
283
                "module's NBM, but are not referenced from any path:\n" + fileToOwningModule.keySet()
321
                    "Cannot build JNLP for module " + f + " as these files are in " +
284
            );
322
                    "module's NBM, but are not referenced from any path:\n" + fileToOwningModule.keySet()
323
                );
324
            }
325
        }
326
        
327
        return localizedFiles;
328
    }
329
    
330
    private static void removeWithLocales(Map removeFrom, String removeWhat, File clusterRoot, Map/*<String,List<File>>*/ recordLocales) {
331
        if (removeFrom.remove(removeWhat) != null && removeWhat.endsWith(".jar")) {
332
            int basedir = removeWhat.indexOf('/');
333
            String base = basedir == -1 ? "" : removeWhat.substring(0, basedir);
334
            String name = removeWhat.substring(basedir + 1, removeWhat.length() - 4);
335
            Pattern p = Pattern.compile(base + "/locale/" + name + "(|_[a-zA-Z0-9_]+)\\.jar");
336
            
337
            Iterator it = removeFrom.keySet().iterator();
338
            while (it.hasNext()) {
339
                String s = (String)it.next();
340
                Matcher m = p.matcher(s);
341
                if (m.matches()) {
342
                    String locale = m.group(1).substring(1);
343
                    
344
                    List l = (List)recordLocales.get(locale);
345
                    if (l == null) {
346
                        l = new ArrayList();
347
                        recordLocales.put(locale, l);
348
                    }
349
                    l.add(new File(clusterRoot, s.replace('/', File.separatorChar)));
350
                    it.remove();
351
                }
352
            }
285
        }
353
        }
286
    }
354
    }
287
355
(-)test/unit/src/org/netbeans/nbbuild/MakeJNLPTest.java (+119 lines)
Lines 16-22 Link Here
16
import java.io.FileOutputStream;
16
import java.io.FileOutputStream;
17
import java.io.FileWriter;
17
import java.io.FileWriter;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.util.Arrays;
19
import java.util.Enumeration;
20
import java.util.Enumeration;
21
import java.util.HashSet;
20
import java.util.Properties;
22
import java.util.Properties;
21
import java.util.jar.JarEntry;
23
import java.util.jar.JarEntry;
22
import java.util.jar.JarFile;
24
import java.util.jar.JarFile;
Lines 113-118 Link Here
113
        }
115
        }
114
    }
116
    }
115
    
117
    
118
    public void testGenerateJNLPAndSignedJarForSimpleLocalizedModule() throws Exception {
119
        Manifest m;
120
        
121
        m = ModuleDependenciesTest.createManifest ();
122
        m.getMainAttributes ().putValue ("OpenIDE-Module", "org.my.module/3");
123
        File simpleJar = generateJar ("modules/", new String[0], m, null);
124
125
        File parent = simpleJar.getParentFile ();
126
        File localizedJarCZ = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null);
127
        assertEquals("There need to have the same name", simpleJar.getName(), localizedJarCZ.getName());
128
        assertTrue("Successful rename", localizedJarCZ.renameTo(new File(localizedJarCZ.getParent(), "0_cs.jar")));
129
        
130
        File localizedJarZH = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null);
131
        assertEquals("There need to have the same name", simpleJar.getName(), localizedJarZH.getName());
132
        assertTrue("Successful rename", localizedJarZH.renameTo(new File(localizedJarCZ.getParent(), "0_zh_CN.jar")));
133
        
134
        File localizedJarJA = generateJar("modules/locale/", new String[0], ModuleDependenciesTest.createManifest(), null);
135
        assertEquals("There need to have the same name", simpleJar.getName(), localizedJarJA.getName());
136
        assertTrue("Successful rename", localizedJarJA.renameTo(new File(localizedJarCZ.getParent(), "0_ja.jar")));
137
138
        File updateTracking = new File(getWorkDir(), "update_tracking");
139
        updateTracking.mkdirs();
140
        assertTrue("Created", updateTracking.isDirectory());
141
        
142
        File trackingFile = new File(updateTracking, "org-my-module.xml");
143
        FileWriter w = new FileWriter(trackingFile);
144
        w.write(
145
"<?xml version='1.0' encoding='UTF-8'?>\n" +
146
"<module codename='org.my.module/3'>\n" +
147
    "<module_version specification_version='3.22' origin='installer' last='true' install_time='1124194231878'>\n" +
148
        "<file name='modules/" + simpleJar.getName() + "' crc='3245456472'/>\n" +
149
        "<file name='config/Modules/org-my-module.xml' crc='43434' />\n" +
150
        "<file name='modules/locale/0_cs.jar' crc='454244' />\n" +
151
        "<file name='modules/locale/0_ja.jar' crc='779831' />\n" +
152
        "<file name='modules/locale/0_zh_CN.jar' crc='475345' />\n" +
153
"    </module_version>\n" +
154
"</module>\n"
155
        );
156
        w.close();
157
        
158
        
159
        File output = new File(parent, "output");
160
        File ks = genereteKeystore("jnlp", "netbeans-test");
161
        
162
        java.io.File f = PublicPackagesInProjectizedXMLTest.extractString (
163
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
164
            "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" +
165
            "  <taskdef name=\"jnlp\" classname=\"org.netbeans.nbbuild.MakeJNLP\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" +
166
            "<target name=\"all\" >" +
167
            "  <mkdir dir='" + output + "' />" + 
168
            "  <jnlp dir='" + output + "' alias='jnlp' storepass='netbeans-test' keystore='" + ks + "' verify='true' >" +
169
            "    <modules dir='" + parent + "' >" +
170
            "      <include name='" + simpleJar.getName() + "' />" +
171
            "    </modules>" +
172
            "  </jnlp>" +
173
            "</target>" +
174
            "</project>"
175
        );
176
        PublicPackagesInProjectizedXMLTest.execute (f, new String[] { "-verbose" });
177
        
178
        assertTrue ("Output exists", output.exists ());
179
        assertTrue ("Output directory created", output.isDirectory());
180
        
181
        String[] files = output.list();
182
        assertEquals("It has two files plus localized ones", 5, files.length);
183
        
184
        HashSet setFiles = new HashSet(Arrays.asList(files));
185
       
186
        if (!setFiles.contains("0.jar")) fail("0.jar shall be there: " + setFiles);
187
        if (!setFiles.contains("org-my-module.jnlp")) fail("org-my-module.jnlp shall be there: " + setFiles);
188
        if (!setFiles.contains("0_cs.jar")) fail("0_cs.jar shall be there: " + setFiles);
189
        if (!setFiles.contains("0_zh_CN.jar")) fail("0_zh_CN.jar shall be there: " + setFiles);
190
        if (!setFiles.contains("0_ja.jar")) fail("0_ja.jar shall be there: " + setFiles);
191
192
193
        File jnlp = new File(output, "org-my-module.jnlp");
194
        String res = ModuleDependenciesTest.readFile (jnlp);
195
        
196
        
197
        assertTrue ("Component JNLP type: " + res, res.indexOf ("<component-desc/>") >= 0);
198
        assertTrue ("We support all permitions by default: " + res, res.indexOf ("<all-permissions/>") >= 0);
199
        
200
        Matcher match = Pattern.compile(".*codebase=['\\\"]([^'\\\"]*)['\\\"]").matcher(res);
201
        assertTrue("codebase is there", match.find());
202
        assertEquals("one group found", 1, match.groupCount());
203
        String base = match.group(1);
204
        
205
        assertEquals("By default the dest directory is $$codebase: ", "$$codebase", base);
206
        
207
        assertResource(res, "cs", "0_cs.jar");
208
        assertResource(res, "ja", "0_ja.jar");
209
        assertResource(res, "zh", "0_zh_CN.jar");
210
211
        CHECK_SIGNED: for (int i = 0; i < files.length; i++) {
212
            if (!files[i].endsWith(".jar")) {
213
                continue;
214
            }
215
            
216
            File jar = new File(output, files[i]);
217
218
            JarFile signed = new JarFile(jar);
219
            Enumeration it = signed.entries();
220
            while (it.hasMoreElements()) {
221
                JarEntry entry = (JarEntry)it.nextElement();
222
                if (entry.getName().endsWith(".SF")) {
223
                    continue CHECK_SIGNED;
224
                }
225
            }
226
            fail ("File does not seem to be signed: " + jar);
227
        }
228
    }
229
    
230
    private static void assertResource(String where, String locale, String file) {
231
        where = where.replace('\n', ' ');
232
        Matcher match = Pattern.compile("<resources *locale='" + locale + "' *>.*<jar href='" + file + "' */>.*</resources>").matcher(where);
233
        assertTrue("File really referenced " + file + " in locale " + locale + "\n" + where, match.find());
234
    }
116
    
235
    
117
    public void testOneCanChangeTheCodeBase() throws Exception {
236
    public void testOneCanChangeTheCodeBase() throws Exception {
118
        Manifest m;
237
        Manifest m;

Return to bug 71129