Lines 7-13
Link Here
|
7 |
* http://www.sun.com/ |
7 |
* http://www.sun.com/ |
8 |
* |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
12 |
*/ |
13 |
|
13 |
|
Lines 16-21
Link Here
|
16 |
import java.io.*; |
16 |
import java.io.*; |
17 |
import java.util.*; |
17 |
import java.util.*; |
18 |
import java.util.jar.*; |
18 |
import java.util.jar.*; |
|
|
19 |
import java.util.zip.*; |
19 |
|
20 |
|
20 |
import org.apache.tools.ant.BuildException; |
21 |
import org.apache.tools.ant.BuildException; |
21 |
import org.apache.tools.ant.Location; |
22 |
import org.apache.tools.ant.Location; |
Lines 61-67
Link Here
|
61 |
is.close (); |
62 |
is.close (); |
62 |
} |
63 |
} |
63 |
} catch (IOException ioe) { |
64 |
} catch (IOException ioe) { |
64 |
throw new BuildException ("Exception reading blurb from " + file, ioe, getLocation1 ()); |
65 |
throw new BuildException ("Exception reading blurb from " + file, ioe, getLocation ()); |
65 |
} |
66 |
} |
66 |
} |
67 |
} |
67 |
} |
68 |
} |
Lines 122-148
Link Here
|
122 |
} |
123 |
} |
123 |
} |
124 |
} |
124 |
public String getText () { |
125 |
public String getText () { |
125 |
if (Boolean.valueOf (getProject ().getProperty ("makenbm.nocdata")).booleanValue ()) { |
126 |
String nocdata = getProject().getProperty("makenbm.nocdata"); |
126 |
int max = text.length (); |
127 |
if (nocdata != null && Project.toBoolean(nocdata)) { |
127 |
StringBuffer text2 = new StringBuffer ((int) (max * 1.1 + 1)); |
128 |
return xmlEscape(text.toString()); |
128 |
for (int i = 0; i < max; i++) { |
|
|
129 |
char c = text.charAt (i); |
130 |
switch (c) { |
131 |
case '<': |
132 |
text2.append ("<"); |
133 |
break; |
134 |
case '>': |
135 |
text2.append (">"); |
136 |
break; |
137 |
case '&': |
138 |
text2.append ("&"); |
139 |
break; |
140 |
default: |
141 |
text2.append (c); |
142 |
break; |
143 |
} |
144 |
} |
145 |
return text2.toString (); |
146 |
} else { |
129 |
} else { |
147 |
return "<![CDATA[" + text.toString () + "]]>"; |
130 |
return "<![CDATA[" + text.toString () + "]]>"; |
148 |
} |
131 |
} |
Lines 164-177
Link Here
|
164 |
// Default for the name too, as a convenience. |
147 |
// Default for the name too, as a convenience. |
165 |
if (name == null) name = file.getName (); |
148 |
if (name == null) name = file.getName (); |
166 |
} |
149 |
} |
167 |
// Javac 1.2 workaround, maybe: |
|
|
168 |
private Location getLocation1 () { |
169 |
return getLocation0 (); |
170 |
} |
171 |
} |
150 |
} |
172 |
// Javac 1.2 workaround: |
151 |
|
173 |
private Location getLocation0 () { |
152 |
// Similar to org.openide.xml.XMLUtil methods. |
174 |
return location; |
153 |
private static String xmlEscape(String s) { |
|
|
154 |
int max = s.length(); |
155 |
StringBuffer s2 = new StringBuffer((int)(max * 1.1 + 1)); |
156 |
for (int i = 0; i < max; i++) { |
157 |
char c = s.charAt(i); |
158 |
switch (c) { |
159 |
case '<': |
160 |
s2.append("<"); |
161 |
break; |
162 |
case '>': |
163 |
s2.append(">"); |
164 |
break; |
165 |
case '&': |
166 |
s2.append("&"); |
167 |
break; |
168 |
case '"': |
169 |
s2.append("""); |
170 |
break; |
171 |
default: |
172 |
s2.append(c); |
173 |
break; |
174 |
} |
175 |
} |
176 |
return s2.toString(); |
175 |
} |
177 |
} |
176 |
|
178 |
|
177 |
/** <samp><signature></samp> subelement for signing the NBM. */ |
179 |
/** <samp><signature></samp> subelement for signing the NBM. */ |
Lines 198-209
Link Here
|
198 |
private File file = null; |
200 |
private File file = null; |
199 |
private File topdir = null; |
201 |
private File topdir = null; |
200 |
private File manifest = null; |
202 |
private File manifest = null; |
|
|
203 |
/** see #13850 for explanation */ |
204 |
private File module = null; |
201 |
private String homepage = null; |
205 |
private String homepage = null; |
202 |
private String distribution = null; |
206 |
private String distribution = null; |
203 |
private Blurb license = null; |
207 |
private Blurb license = null; |
204 |
private Blurb description = null; |
208 |
private Blurb description = null; |
205 |
private Signature signature = null; |
209 |
private Signature signature = null; |
206 |
long mostRecentInput = 0L; |
210 |
private long mostRecentInput = 0L; |
207 |
|
211 |
|
208 |
/** Name of resulting NBM file. */ |
212 |
/** Name of resulting NBM file. */ |
209 |
public void setFile (File file) { |
213 |
public void setFile (File file) { |
Lines 217-227
Link Here
|
217 |
public void setTopdir (File topdir) { |
221 |
public void setTopdir (File topdir) { |
218 |
this.topdir = topdir; |
222 |
this.topdir = topdir; |
219 |
} |
223 |
} |
220 |
/** Module manifest needed for versioning. */ |
224 |
/** Module manifest needed for versioning. |
|
|
225 |
* @deprecated Use {@link #setModule} instead. |
226 |
*/ |
221 |
public void setManifest (File manifest) { |
227 |
public void setManifest (File manifest) { |
222 |
this.manifest = manifest; |
228 |
this.manifest = manifest; |
223 |
long lmod = manifest.lastModified (); |
229 |
long lmod = manifest.lastModified (); |
224 |
if (lmod > mostRecentInput) mostRecentInput = lmod; |
230 |
if (lmod > mostRecentInput) mostRecentInput = lmod; |
|
|
231 |
log(getLocation() + "The 'manifest' attr on <makenbm> is deprecated, please use 'module' instead", Project.MSG_WARN); |
232 |
} |
233 |
/** Module JAR needed for generating the info file. |
234 |
* Information may be gotten either from its manifest, |
235 |
* or if it declares OpenIDE-Module-Localizing-Bundle in its |
236 |
* manifest, from that bundle. |
237 |
* The base locale variant, if any, is also checked if necessary |
238 |
* for the named bundle. |
239 |
* Currently no other locale variants of the module are examined; |
240 |
* the information is available but there is no published specification |
241 |
* of what the resulting variant NBMs (or variant information within |
242 |
* the NBM) should look like. |
243 |
*/ |
244 |
public void setModule(File module) { |
245 |
this.module = module; |
246 |
// mostRecentInput updated below... |
225 |
} |
247 |
} |
226 |
/** URL to a home page describing the module. */ |
248 |
/** URL to a home page describing the module. */ |
227 |
public void setHomepage (String homepage) { |
249 |
public void setHomepage (String homepage) { |
Lines 235-240
Link Here
|
235 |
return (license = new Blurb ()); |
257 |
return (license = new Blurb ()); |
236 |
} |
258 |
} |
237 |
public Blurb createDescription () { |
259 |
public Blurb createDescription () { |
|
|
260 |
log(getLocation() + "The <description> subelement in <makenbm> is deprecated except for emergency patches, please ensure your module has an OpenIDE-Module-Long-Description instead", Project.MSG_WARN); |
238 |
return (description = new Blurb ()); |
261 |
return (description = new Blurb ()); |
239 |
} |
262 |
} |
240 |
public Signature createSignature () { |
263 |
public Signature createSignature () { |
Lines 244-255
Link Here
|
244 |
public void execute () throws BuildException { |
267 |
public void execute () throws BuildException { |
245 |
if (file == null) |
268 |
if (file == null) |
246 |
throw new BuildException ("must set file for makenbm", location); |
269 |
throw new BuildException ("must set file for makenbm", location); |
247 |
if (manifest == null) |
270 |
if (manifest == null && module == null) |
248 |
throw new BuildException ("must set manifest for makenbm", location); |
271 |
throw new BuildException ("must set module for makenbm", location); |
|
|
272 |
if (manifest != null && module != null) |
273 |
throw new BuildException("cannot set both manifest and module for makenbm", location); |
249 |
// Will create a file Info/info.xml to be stored alongside netbeans/ contents. |
274 |
// Will create a file Info/info.xml to be stored alongside netbeans/ contents. |
250 |
File infodir = new File (topdir, "Info"); |
275 |
File infodir = new File (topdir, "Info"); |
251 |
infodir.mkdirs (); |
276 |
infodir.mkdirs (); |
252 |
File infofile = new File (infodir, "info.xml"); |
277 |
File infofile = new File (infodir, "info.xml"); |
|
|
278 |
Attributes attr = null; |
279 |
if (module != null) { |
280 |
// The normal case; read attributes from its manifest and maybe bundle. |
281 |
long mMod = module.lastModified(); |
282 |
if (mostRecentInput < mMod) mostRecentInput = mMod; |
283 |
try { |
284 |
JarFile modulejar = new JarFile(module); |
285 |
try { |
286 |
attr = modulejar.getManifest().getMainAttributes(); |
287 |
String bundlename = attr.getValue("OpenIDE-Module-Localizing-Bundle"); |
288 |
if (bundlename != null) { |
289 |
Properties p = new Properties(); |
290 |
ZipEntry bundleentry = modulejar.getEntry(bundlename); |
291 |
if (bundleentry != null) { |
292 |
InputStream is = modulejar.getInputStream(bundleentry); |
293 |
try { |
294 |
p.load(is); |
295 |
} finally { |
296 |
is.close(); |
297 |
} |
298 |
} else { |
299 |
// Not found in main JAR, check locale variant JAR. |
300 |
File variant = new File(new File(module.getParentFile(), "locale"), module.getName()); |
301 |
if (! variant.isFile()) throw new BuildException(bundlename + " not found in " + module, location); |
302 |
long vmMod = variant.lastModified(); |
303 |
if (mostRecentInput < vmMod) mostRecentInput = vmMod; |
304 |
ZipFile variantjar = new ZipFile(variant); |
305 |
try { |
306 |
bundleentry = variantjar.getEntry(bundlename); |
307 |
if (bundleentry == null) throw new BuildException(bundlename + " not found in " + module + " nor in " + variant, location); |
308 |
InputStream is = variantjar.getInputStream(bundleentry); |
309 |
try { |
310 |
p.load(is); |
311 |
} finally { |
312 |
is.close(); |
313 |
} |
314 |
} finally { |
315 |
variantjar.close(); |
316 |
} |
317 |
} |
318 |
// Now pick up attributes from the bundle. |
319 |
Iterator it = p.entrySet().iterator(); |
320 |
while (it.hasNext()) { |
321 |
Map.Entry entry = (Map.Entry)it.next(); |
322 |
String name = (String)entry.getKey(); |
323 |
if (! name.startsWith("OpenIDE-Module-")) continue; |
324 |
attr.putValue(name, (String)entry.getValue()); |
325 |
} |
326 |
} // else all loc attrs in main manifest, OK |
327 |
} finally { |
328 |
modulejar.close(); |
329 |
} |
330 |
} catch (IOException ioe) { |
331 |
throw new BuildException("exception while reading " + module, ioe, location); |
332 |
} |
333 |
} // else we will read attr later if info file is out of date |
253 |
boolean skipInfo = false; |
334 |
boolean skipInfo = false; |
254 |
if (infofile.exists ()) { |
335 |
if (infofile.exists ()) { |
255 |
// Check for up-to-date w.r.t. manifest and maybe license file. |
336 |
// Check for up-to-date w.r.t. manifest and maybe license file. |
Lines 259-283
Link Here
|
259 |
} |
340 |
} |
260 |
if (! skipInfo) { |
341 |
if (! skipInfo) { |
261 |
log ("Creating NBM info file " + infofile); |
342 |
log ("Creating NBM info file " + infofile); |
262 |
Attributes attr; |
343 |
if (manifest != null) { |
263 |
// Read module manifest for main attributes. |
344 |
// Read module manifest for main attributes. |
264 |
try { |
345 |
try { |
265 |
InputStream manifestStream = new FileInputStream (manifest); |
346 |
InputStream manifestStream = new FileInputStream (manifest); |
266 |
try { |
347 |
try { |
267 |
attr = new Manifest (manifestStream).getMainAttributes (); |
348 |
attr = new Manifest (manifestStream).getMainAttributes (); |
268 |
} finally { |
349 |
} finally { |
269 |
manifestStream.close (); |
350 |
manifestStream.close (); |
270 |
} |
351 |
} |
271 |
} catch (IOException e) { |
352 |
} catch (IOException e) { |
272 |
throw new BuildException ("exception when reading manifest " + manifest, e, location); |
353 |
throw new BuildException ("exception when reading manifest " + manifest, e, location); |
273 |
} |
354 |
} |
|
|
355 |
} // else we read attr before |
274 |
try { |
356 |
try { |
275 |
OutputStream infoStream = new FileOutputStream (infofile); |
357 |
OutputStream infoStream = new FileOutputStream (infofile); |
276 |
try { |
358 |
try { |
277 |
PrintStream ps = new PrintStream (infoStream); |
359 |
PrintWriter ps = new PrintWriter(new OutputStreamWriter(infoStream, "UTF-8")); |
278 |
// Begin writing XML. |
360 |
// Begin writing XML. |
279 |
ps.println ("<?xml version='1.0'?>"); |
361 |
ps.println ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
280 |
ps.println (); |
|
|
281 |
String codenamebase = attr.getValue ("OpenIDE-Module"); |
362 |
String codenamebase = attr.getValue ("OpenIDE-Module"); |
282 |
if (codenamebase == null) |
363 |
if (codenamebase == null) |
283 |
throw new BuildException ("invalid manifest, does not contain OpenIDE-Module", location); |
364 |
throw new BuildException ("invalid manifest, does not contain OpenIDE-Module", location); |
Lines 286-300
Link Here
|
286 |
if (idx != -1) codenamebase = codenamebase.substring (0, idx); |
367 |
if (idx != -1) codenamebase = codenamebase.substring (0, idx); |
287 |
ps.println ("<module codenamebase=\"" + codenamebase + "\""); |
368 |
ps.println ("<module codenamebase=\"" + codenamebase + "\""); |
288 |
if (homepage != null) |
369 |
if (homepage != null) |
289 |
ps.println (" homepage=\"" + homepage + "\""); |
370 |
ps.println (" homepage=\"" + xmlEscape(homepage) + "\""); |
290 |
if (distribution != null) |
371 |
if (distribution != null) |
291 |
ps.println (" distribution=\"" + distribution + "\""); |
372 |
ps.println (" distribution=\"" + xmlEscape(distribution) + "\""); |
292 |
// Here we only write a name for the license. |
373 |
// Here we only write a name for the license. |
293 |
if (license != null) { |
374 |
if (license != null) { |
294 |
String name = license.getName (); |
375 |
String name = license.getName (); |
295 |
if (name == null) |
376 |
if (name == null) |
296 |
throw new BuildException ("Every license must have a name or file attribute", location); |
377 |
throw new BuildException ("Every license must have a name or file attribute", location); |
297 |
ps.println (" license=\"" + name + "\""); |
378 |
ps.println (" license=\"" + xmlEscape(name) + "\""); |
298 |
} |
379 |
} |
299 |
ps.println (" downloadsize=\"0\""); |
380 |
ps.println (" downloadsize=\"0\""); |
300 |
ps.println (">"); |
381 |
ps.println (">"); |
Lines 302-339
Link Here
|
302 |
ps.print (" <description>"); |
383 |
ps.print (" <description>"); |
303 |
ps.print (description.getText ()); |
384 |
ps.print (description.getText ()); |
304 |
ps.println ("</description>"); |
385 |
ps.println ("</description>"); |
305 |
/* Not needed since Auto Update now reads this attribute directly: |
|
|
306 |
} else { |
307 |
// Automatically inherit description from manifest. |
308 |
String longDesc = attr.getValue ("OpenIDE-Module-Long-Description"); |
309 |
if (longDesc != null) { |
310 |
ps.print (" <description>"); |
311 |
ps.print (longDesc); |
312 |
ps.println ("</description>"); |
313 |
} |
314 |
*/ |
315 |
} |
386 |
} |
316 |
// Write manifest attributes. |
387 |
// Write manifest attributes. |
317 |
ps.print (" <manifest "); |
388 |
ps.print (" <manifest "); |
318 |
boolean firstline = true; |
389 |
boolean firstline = true; |
319 |
Iterator it = attr.entrySet ().iterator (); |
390 |
Iterator it = attr.entrySet ().iterator (); |
320 |
while (it.hasNext ()) { |
391 |
while (it.hasNext ()) { |
|
|
392 |
Map.Entry entry = (Map.Entry) it.next (); |
393 |
String name = ((Attributes.Name)entry.getKey()).toString(); |
394 |
// Ignore irrelevant attributes: |
395 |
if (! name.startsWith("OpenIDE-Module")) continue; |
396 |
if (name.equals("OpenIDE-Module-Localizing-Bundle")) continue; |
397 |
if (name.equals("OpenIDE-Module-Install")) continue; |
398 |
if (name.equals("OpenIDE-Module-Layer")) continue; |
399 |
if (name.equals("OpenIDE-Module-Description")) continue; |
321 |
if (firstline) |
400 |
if (firstline) |
322 |
firstline = false; |
401 |
firstline = false; |
323 |
else |
402 |
else |
324 |
ps.print (" "); |
403 |
ps.print (" "); |
325 |
Map.Entry entry = (Map.Entry) it.next (); |
404 |
ps.println(name + "=\"" + xmlEscape((String)entry.getValue()) + "\""); |
326 |
// [PENDING] ought to escape the value for characters in ["&<>] |
|
|
327 |
ps.println (entry.getKey () + "=\"" + entry.getValue () + "\""); |
328 |
} |
405 |
} |
329 |
ps.println (" />"); |
406 |
ps.println (" />"); |
330 |
// Maybe write out license text. |
407 |
// Maybe write out license text. |
331 |
if (license != null) { |
408 |
if (license != null) { |
332 |
ps.print (" <license name=\"" + license.getName () + "\">"); |
409 |
ps.print (" <license name=\"" + xmlEscape(license.getName ()) + "\">"); |
333 |
ps.print (license.getText ()); |
410 |
ps.print (license.getText ()); |
334 |
ps.println ("</license>"); |
411 |
ps.println ("</license>"); |
335 |
} |
412 |
} |
336 |
ps.println ("</module>"); |
413 |
ps.println ("</module>"); |
|
|
414 |
ps.flush(); |
337 |
} finally { |
415 |
} finally { |
338 |
infoStream.close (); |
416 |
infoStream.close (); |
339 |
} |
417 |
} |
Lines 347-375
Link Here
|
347 |
Jar jar = (Jar) project.createTask ("jar"); |
425 |
Jar jar = (Jar) project.createTask ("jar"); |
348 |
jar.setJarfile (file); |
426 |
jar.setJarfile (file); |
349 |
//jar.setBasedir (topdir.getAbsolutePath ()); |
427 |
//jar.setBasedir (topdir.getAbsolutePath ()); |
350 |
// jar.setCompress ("true"); |
428 |
jar.setCompress(true); |
351 |
try { |
|
|
352 |
Class[] params = {Boolean.TYPE}; |
353 |
Object[] objs = {Boolean.TRUE}; |
354 |
// Trying to invoke setCompess with parameter Boolean - ANT 1.3 |
355 |
Zip.class.getDeclaredMethod("setCompress",params).invoke(jar,objs); |
356 |
// Looks like ANT 1.3 - I hope that is ANT 1.3 |
357 |
} |
358 |
catch (NoSuchMethodException ex) |
359 |
{ |
360 |
// Looks like ANT 1.2 so use setCompress with String |
361 |
Class[] params = {String.class}; |
362 |
Object[] objs = {"true"}; |
363 |
try { |
364 |
Zip.class.getDeclaredMethod("setCompress",params).invoke(jar,objs); |
365 |
} |
366 |
catch (Exception ex1) { |
367 |
throw new BuildException(ex1.fillInStackTrace()); |
368 |
} |
369 |
} |
370 |
catch (Exception ex) { |
371 |
throw new BuildException(ex.fillInStackTrace()); |
372 |
} |
373 |
//jar.createInclude ().setName ("netbeans/"); |
429 |
//jar.createInclude ().setName ("netbeans/"); |
374 |
//jar.createInclude ().setName ("Info/info.xml"); |
430 |
//jar.createInclude ().setName ("Info/info.xml"); |
375 |
jar.addFileset (getFileSet()); |
431 |
jar.addFileset (getFileSet()); |
Lines 400-405
Link Here
|
400 |
} |
456 |
} |
401 |
} |
457 |
} |
402 |
|
458 |
|
|
|
459 |
// Reflection access from MakeListOfNBM: |
460 |
|
403 |
public FileSet getFileSet() { |
461 |
public FileSet getFileSet() { |
404 |
FileSet fs = fileset; //makes in apperance to excludes and includes files defined in XML |
462 |
FileSet fs = fileset; //makes in apperance to excludes and includes files defined in XML |
405 |
fs.setDir (topdir); |
463 |
fs.setDir (topdir); |
Lines 408-414
Link Here
|
408 |
return fs; |
466 |
return fs; |
409 |
} |
467 |
} |
410 |
|
468 |
|
411 |
public File getManifest() { |
469 |
public Attributes getAttributes() throws IOException { |
412 |
return manifest; |
470 |
if (manifest != null) { |
|
|
471 |
InputStream is = new FileInputStream(manifest); |
472 |
try { |
473 |
return new Manifest(is).getMainAttributes(); |
474 |
} finally { |
475 |
is.close(); |
476 |
} |
477 |
} else if (module != null) { |
478 |
JarFile jar = new JarFile(module); |
479 |
try { |
480 |
return jar.getManifest().getMainAttributes(); |
481 |
} finally { |
482 |
jar.close(); |
483 |
} |
484 |
} else { |
485 |
throw new IOException(location + "must give either 'manifest' or 'module' on <makenbm>"); |
486 |
} |
413 |
} |
487 |
} |
414 |
} |
488 |
} |