Lines 104-116
Link Here
|
104 |
private List<String> autoloadNames = new ArrayList<String>(10); |
104 |
private List<String> autoloadNames = new ArrayList<String>(10); |
105 |
private List<String> eagerNames = new ArrayList<String>(10); |
105 |
private List<String> eagerNames = new ArrayList<String>(10); |
106 |
private List<String> hiddenNames = new ArrayList<String>(10); |
106 |
private List<String> hiddenNames = new ArrayList<String>(10); |
107 |
|
107 |
private String hiddenList; |
|
|
108 |
|
109 |
/** |
110 |
* In addition to >hidden< nested fileset, list of hidden modules can |
111 |
* be specified as comma-separated list in attribute 'hidden'. |
112 |
* @param hiddenList |
113 |
*/ |
114 |
public void setHidden(String hiddenList) { |
115 |
// Only hidden parameters can be specified as list of absolute file paths, |
116 |
// enabled, eager and autoload modules need relative path to create proper module xml |
117 |
this.hiddenList = hiddenList; |
118 |
} |
119 |
|
108 |
public void execute() throws BuildException { |
120 |
public void execute() throws BuildException { |
109 |
if (xmldir == null) throw new BuildException("Must set xmldir attribute", getLocation()); |
121 |
if (xmldir == null) throw new BuildException("Must set xmldir attribute", getLocation()); |
110 |
if (!xmldir.exists ()) { |
122 |
if (!xmldir.exists ()) { |
111 |
if (!xmldir.mkdirs()) throw new BuildException("Cannot create directory " + xmldir, getLocation()); |
123 |
if (!xmldir.mkdirs()) throw new BuildException("Cannot create directory " + xmldir, getLocation()); |
112 |
} |
124 |
} |
113 |
if (enabled.isEmpty() && disabled.isEmpty() && autoload.isEmpty() && eager.isEmpty() && hidden.isEmpty()) { |
125 |
if (enabled.isEmpty() && disabled.isEmpty() && autoload.isEmpty() && eager.isEmpty() && hidden.isEmpty() |
|
|
126 |
&& hiddenList == null) { |
114 |
log("Warning: <createmodulexml> with no modules listed", Project.MSG_WARN); |
127 |
log("Warning: <createmodulexml> with no modules listed", Project.MSG_WARN); |
115 |
} |
128 |
} |
116 |
for (FileSet fs : enabled) { |
129 |
for (FileSet fs : enabled) { |
Lines 128-133
Link Here
|
128 |
for (FileSet fs : hidden) { |
141 |
for (FileSet fs : hidden) { |
129 |
scanModules(fs, false, false, false, true, hiddenNames); |
142 |
scanModules(fs, false, false, false, true, hiddenNames); |
130 |
} |
143 |
} |
|
|
144 |
if (hiddenList != null && hiddenList.length() > 0) |
145 |
scanModulesInList(hiddenList, false, false, false, true, hiddenNames); |
131 |
Collections.sort(enabledNames); |
146 |
Collections.sort(enabledNames); |
132 |
Collections.sort(disabledNames); |
147 |
Collections.sort(disabledNames); |
133 |
Collections.sort(autoloadNames); |
148 |
Collections.sort(autoloadNames); |
Lines 155-273
Link Here
|
155 |
File dir = scan.getBasedir(); |
170 |
File dir = scan.getBasedir(); |
156 |
for (String kid : scan.getIncludedFiles()) { |
171 |
for (String kid : scan.getIncludedFiles()) { |
157 |
File module = new File(dir, kid); |
172 |
File module = new File(dir, kid); |
158 |
if (!module.exists()) throw new BuildException("Module file does not exist: " + module, getLocation()); |
173 |
scanOneModule(module, kid, isEnabled, isAutoload, isEager, isHidden, names); |
159 |
if (!module.getName().endsWith(".jar")) throw new BuildException("Only *.jar may be listed, check the fileset: " + module, getLocation()); |
174 |
} |
|
|
175 |
} |
176 |
|
177 |
private void scanModulesInList(String modulesList, boolean isEnabled, boolean isAutoload, |
178 |
boolean isEager, boolean isHidden, List<String> names) throws BuildException { |
179 |
String[] modules = modulesList.split(","); |
180 |
for (String modulePath : modules) { |
181 |
File module = new File(modulePath); |
182 |
scanOneModule(module, null, isEnabled, isAutoload, isEager, isHidden, names); |
183 |
} |
184 |
} |
185 |
|
186 |
private void scanOneModule(File module, String kid, boolean isEnabled,boolean isAutoload, boolean isEager, boolean isHidden, List<String> names) throws BuildException { |
187 |
if (!module.exists()) { |
188 |
throw new BuildException("Module file does not exist: " + module, getLocation()); |
189 |
} |
190 |
if (!module.getName().endsWith(".jar")) { |
191 |
throw new BuildException("Only *.jar may be listed, check the fileset: " + module, getLocation()); |
192 |
} |
193 |
try { |
194 |
JarFile jar = new JarFile(module); |
160 |
try { |
195 |
try { |
161 |
JarFile jar = new JarFile(module); |
196 |
Manifest m = jar.getManifest(); |
162 |
try { |
197 |
Attributes attr = m.getMainAttributes(); |
163 |
Manifest m = jar.getManifest(); |
198 |
String codename = attr.getValue("OpenIDE-Module"); |
164 |
Attributes attr = m.getMainAttributes(); |
199 |
if (codename == null) { |
165 |
String codename = attr.getValue("OpenIDE-Module"); |
200 |
throw new BuildException("Missing manifest tag OpenIDE-Module; " + module + " is not a module", getLocation()); |
166 |
if (codename == null) { |
201 |
} |
167 |
throw new BuildException("Missing manifest tag OpenIDE-Module; " + module + " is not a module", getLocation()); |
202 |
if (codename.endsWith(" ") || codename.endsWith("\t")) { |
|
|
203 |
// #62887 |
204 |
throw new BuildException("Illegal trailing space in OpenIDE-Module value from " + module, getLocation()); |
205 |
} |
206 |
int idx = codename.lastIndexOf('/'); |
207 |
String codenamebase; |
208 |
int rel; |
209 |
if (idx == -1) { |
210 |
codenamebase = codename; |
211 |
rel = -1; |
212 |
} else { |
213 |
codenamebase = codename.substring(0, idx); |
214 |
try { |
215 |
rel = Integer.parseInt(codename.substring(idx + 1)); |
216 |
} catch (NumberFormatException e) { |
217 |
throw new BuildException("Invalid OpenIDE-Module '" + codename + "' in " + module, getLocation()); |
168 |
} |
218 |
} |
169 |
if (codename.endsWith(" ") || codename.endsWith("\t")) { // #62887 |
219 |
} |
170 |
throw new BuildException("Illegal trailing space in OpenIDE-Module value from " + module, getLocation()); |
220 |
File xml = new File(xmldir, codenamebase.replace('.', '-') + ".xml"); |
171 |
} |
221 |
if (xml.exists()) { |
172 |
int idx = codename.lastIndexOf('/'); |
222 |
// XXX should check that the old file actually matches what we would have written |
173 |
String codenamebase; |
223 |
log("Will not overwrite " + xml + "; skipping...", Project.MSG_VERBOSE); |
174 |
int rel; |
224 |
return; |
175 |
if (idx == -1) { |
225 |
} |
176 |
codenamebase = codename; |
226 |
String displayname = attr.getValue("OpenIDE-Module-Name"); |
177 |
rel = -1; |
227 |
if (displayname == null) { |
178 |
} else { |
228 |
String bundle = attr.getValue("OpenIDE-Module-Localizing-Bundle"); |
179 |
codenamebase = codename.substring(0, idx); |
229 |
if (bundle != null) { |
|
|
230 |
// Display name actually found in a bundle, not manifest. |
231 |
ZipEntry entry = jar.getEntry(bundle); |
232 |
InputStream is; |
233 |
if (entry != null) { |
234 |
is = jar.getInputStream(entry); |
235 |
} else { |
236 |
File moduleloc = new File(new File(module.getParentFile(), "locale"), module.getName()); |
237 |
if (!moduleloc.isFile()) { |
238 |
throw new BuildException("Expecting localizing bundle: " + bundle + " in: " + module); |
239 |
} |
240 |
JarFile jarloc = new JarFile(moduleloc); |
241 |
try { |
242 |
ZipEntry entry2 = jarloc.getEntry(bundle); |
243 |
if (entry2 == null) { |
244 |
throw new BuildException("Expecting localizing bundle: " + bundle + " in: " + module); |
245 |
} |
246 |
is = jarloc.getInputStream(entry2); |
247 |
} finally { |
248 |
jarloc.close(); |
249 |
} |
250 |
} |
180 |
try { |
251 |
try { |
181 |
rel = Integer.parseInt(codename.substring(idx + 1)); |
252 |
Properties p = new Properties(); |
182 |
} catch (NumberFormatException e) { |
253 |
p.load(is); |
183 |
throw new BuildException("Invalid OpenIDE-Module '" + codename + "' in " + module, getLocation()); |
254 |
displayname = p.getProperty("OpenIDE-Module-Name"); |
|
|
255 |
} finally { |
256 |
is.close(); |
184 |
} |
257 |
} |
185 |
} |
258 |
} |
186 |
File xml = new File(xmldir, codenamebase.replace('.', '-') + ".xml"); |
259 |
} |
187 |
if (xml.exists()) { |
260 |
if (displayname == null) { |
188 |
// XXX should check that the old file actually matches what we would have written |
261 |
displayname = codename; |
189 |
log("Will not overwrite " + xml + "; skipping...", Project.MSG_VERBOSE); |
262 |
} |
190 |
continue; |
263 |
names.add(displayname); |
|
|
264 |
String spec = attr.getValue("OpenIDE-Module-Specification-Version"); |
265 |
if (isHidden) { |
266 |
File h = new File(xml.getParentFile(), xml.getName() + "_hidden"); |
267 |
h.createNewFile(); |
268 |
} |
269 |
if (isEager || isAutoload || isEnabled) { |
270 |
OutputStream os = new FileOutputStream(xml); |
271 |
try { |
272 |
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); |
273 |
// Please make sure formatting matches what the IDE actually spits |
274 |
// out; it could matter. |
275 |
pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
276 |
pw.println("<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\""); |
277 |
pw.println(" \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">"); |
278 |
pw.println("<module name=\"" + codenamebase + "\">"); |
279 |
pw.println(" <param name=\"autoload\">" + isAutoload + "</param>"); |
280 |
pw.println(" <param name=\"eager\">" + isEager + "</param>"); |
281 |
if (!isAutoload && !isEager) { |
282 |
pw.println(" <param name=\"enabled\">" + isEnabled + "</param>"); |
283 |
} |
284 |
pw.println(" <param name=\"jar\">" + kid.replace(File.separatorChar, '/') + "</param>"); |
285 |
if (rel != -1) { |
286 |
pw.println(" <param name=\"release\">" + rel + "</param>"); |
287 |
} |
288 |
pw.println(" <param name=\"reloadable\">false</param>"); |
289 |
if (spec != null) { |
290 |
pw.println(" <param name=\"specversion\">" + spec + "</param>"); |
291 |
} |
292 |
pw.println("</module>"); |
293 |
pw.flush(); |
294 |
pw.close(); |
295 |
} finally { |
296 |
os.close(); |
191 |
} |
297 |
} |
192 |
String displayname = attr.getValue("OpenIDE-Module-Name"); |
|
|
193 |
if (displayname == null) { |
194 |
String bundle = attr.getValue("OpenIDE-Module-Localizing-Bundle"); |
195 |
if (bundle != null) { |
196 |
// Display name actually found in a bundle, not manifest. |
197 |
ZipEntry entry = jar.getEntry(bundle); |
198 |
InputStream is; |
199 |
if (entry != null) { |
200 |
is = jar.getInputStream(entry); |
201 |
} else { |
202 |
File moduleloc = new File(new File(module.getParentFile(), "locale"), module.getName()); |
203 |
if (! moduleloc.isFile()) { |
204 |
throw new BuildException("Expecting localizing bundle: " + bundle + " in: " + module); |
205 |
} |
206 |
JarFile jarloc = new JarFile(moduleloc); |
207 |
try { |
208 |
ZipEntry entry2 = jarloc.getEntry(bundle); |
209 |
if (entry2 == null) { |
210 |
throw new BuildException("Expecting localizing bundle: " + bundle + " in: " + module); |
211 |
} |
212 |
is = jarloc.getInputStream(entry2); |
213 |
} finally { |
214 |
jarloc.close(); |
215 |
} |
216 |
} |
217 |
try { |
218 |
Properties p = new Properties(); |
219 |
p.load(is); |
220 |
displayname = p.getProperty("OpenIDE-Module-Name"); |
221 |
} finally { |
222 |
is.close(); |
223 |
} |
224 |
} |
225 |
} |
226 |
if (displayname == null) displayname = codename; |
227 |
names.add(displayname); |
228 |
String spec = attr.getValue("OpenIDE-Module-Specification-Version"); |
229 |
|
230 |
if (isHidden) { |
231 |
File h = new File(xml.getParentFile(), xml.getName() + "_hidden"); |
232 |
h.createNewFile(); |
233 |
} |
234 |
|
235 |
if (isEager || isAutoload || isEnabled) { |
236 |
OutputStream os = new FileOutputStream(xml); |
237 |
try { |
238 |
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); |
239 |
// Please make sure formatting matches what the IDE actually spits |
240 |
// out; it could matter. |
241 |
pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
242 |
pw.println("<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\""); |
243 |
pw.println(" \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">"); |
244 |
pw.println("<module name=\"" + codenamebase + "\">"); |
245 |
pw.println(" <param name=\"autoload\">" + isAutoload + "</param>"); |
246 |
pw.println(" <param name=\"eager\">" + isEager + "</param>"); |
247 |
if (!isAutoload && !isEager) { |
248 |
pw.println(" <param name=\"enabled\">" + isEnabled + "</param>"); |
249 |
} |
250 |
pw.println(" <param name=\"jar\">" + kid.replace(File.separatorChar, '/') + "</param>"); |
251 |
if (rel != -1) { |
252 |
pw.println(" <param name=\"release\">" + rel + "</param>"); |
253 |
} |
254 |
pw.println(" <param name=\"reloadable\">false</param>"); |
255 |
if (spec != null) { |
256 |
pw.println(" <param name=\"specversion\">" + spec + "</param>"); |
257 |
} |
258 |
pw.println("</module>"); |
259 |
pw.flush(); |
260 |
pw.close(); |
261 |
} finally { |
262 |
os.close(); |
263 |
} |
264 |
} |
265 |
} finally { |
266 |
jar.close(); |
267 |
} |
298 |
} |
268 |
} catch (IOException ioe) { |
299 |
} finally { |
269 |
throw new BuildException("Caught while processing " + module + ": " + ioe, ioe, getLocation()); |
300 |
jar.close(); |
270 |
} |
301 |
} |
|
|
302 |
} catch (IOException ioe) { |
303 |
throw new BuildException("Caught while processing " + module + ": " + ioe, ioe, getLocation()); |
271 |
} |
304 |
} |
272 |
} |
305 |
} |
273 |
|
306 |
|