Lines 45-50
Link Here
|
45 |
import java.io.InputStream; |
45 |
import java.io.InputStream; |
46 |
import java.io.OutputStream; |
46 |
import java.io.OutputStream; |
47 |
import java.io.PrintWriter; |
47 |
import java.io.PrintWriter; |
|
|
48 |
import java.util.Arrays; |
48 |
import java.util.Collection; |
49 |
import java.util.Collection; |
49 |
import java.util.logging.Level; |
50 |
import java.util.logging.Level; |
50 |
import java.util.logging.Logger; |
51 |
import java.util.logging.Logger; |
Lines 70-75
Link Here
|
70 |
import org.openide.util.Mutex; |
71 |
import org.openide.util.Mutex; |
71 |
import org.openide.util.MutexException; |
72 |
import org.openide.util.MutexException; |
72 |
import org.openide.util.NbBundle; |
73 |
import org.openide.util.NbBundle; |
|
|
74 |
import org.openide.util.Parameters; |
73 |
import org.openide.xml.XMLUtil; |
75 |
import org.openide.xml.XMLUtil; |
74 |
import org.w3c.dom.Document; |
76 |
import org.w3c.dom.Document; |
75 |
import org.w3c.dom.Element; |
77 |
import org.w3c.dom.Element; |
Lines 93-98
Link Here
|
93 |
|
95 |
|
94 |
private static final String JWS_ANT_TASKS_LIB_NAME = "JWSAntTasks"; // NOI18N |
96 |
private static final String JWS_ANT_TASKS_LIB_NAME = "JWSAntTasks"; // NOI18N |
95 |
private static final String BUILD_TEMPLATE = "Templates/JWS/jnlp-impl.xml"; //NOI18N |
97 |
private static final String BUILD_TEMPLATE = "Templates/JWS/jnlp-impl.xml"; //NOI18N |
|
|
98 |
private static final String CURRENT_EXTENSION = "jws"; //NOI18N |
99 |
private static final String[] OLD_EXTENSIONS = new String[0]; |
100 |
private static final String JNLP_BUILD_IMPL_PATH = "nbproject/jnlp-impl.xml"; //NOI18N |
96 |
|
101 |
|
97 |
private static final Logger LOG = Logger.getLogger(JWSProjectPropertiesUtils.class.getName()); |
102 |
private static final Logger LOG = Logger.getLogger(JWSProjectPropertiesUtils.class.getName()); |
98 |
|
103 |
|
Lines 101-107
Link Here
|
101 |
private JWSProjectPropertiesUtils() { |
106 |
private JWSProjectPropertiesUtils() { |
102 |
} |
107 |
} |
103 |
|
108 |
|
104 |
public static void updateMasterFiles(JWSProjectProperties props, Project proj) { |
109 |
public static String getCurrentExtensionName() { |
|
|
110 |
return CURRENT_EXTENSION; |
111 |
} |
112 |
|
113 |
public static Iterable<? extends String> getOldExtensionNames() { |
114 |
return Arrays.asList(OLD_EXTENSIONS); |
115 |
} |
116 |
|
117 |
public static void copyJnlpImplTemplate(Project proj) throws IOException { |
118 |
final FileObject projDir = proj.getProjectDirectory(); |
119 |
FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH); |
120 |
if (jnlpBuildFile != null && !isJnlpImplUpToDate(proj)) { |
121 |
// try to close the file just in case the file is already opened in editor |
122 |
DataObject dobj = DataObject.find(jnlpBuildFile); |
123 |
CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class); |
124 |
if (closeCookie != null) { |
125 |
closeCookie.close(); |
126 |
} |
127 |
final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N |
128 |
final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml"); //NOI18N |
129 |
if (backupFile != null) { |
130 |
backupFile.delete(); |
131 |
} |
132 |
FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup"); //NOI18N |
133 |
jnlpBuildFile = null; |
134 |
} |
135 |
if (jnlpBuildFile == null) { |
136 |
FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE); |
137 |
if (templateFO != null) { |
138 |
FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N |
139 |
} |
140 |
} |
141 |
} |
142 |
|
143 |
public static boolean isJnlpImplUpToDate(final Project prj) { |
144 |
Parameters.notNull("prj", prj); //NOI18N |
145 |
final FileObject jnlpImlpFO = prj.getProjectDirectory().getFileObject(JNLP_BUILD_IMPL_PATH); |
146 |
if (jnlpImlpFO == null) { |
147 |
return false; |
148 |
} |
149 |
try { |
150 |
String _currentJnlpImplCRC = currentJnlpImplCRCCache; |
151 |
if (_currentJnlpImplCRC == null) { |
152 |
final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE); |
153 |
currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(template); |
154 |
} |
155 |
return _currentJnlpImplCRC.equals(computeCrc32(jnlpImlpFO)); |
156 |
} catch (IOException ex) { |
157 |
LOG.log( |
158 |
Level.INFO, |
159 |
"Cannot read: " + JNLP_BUILD_IMPL_PATH, //NOI18N |
160 |
ex); |
161 |
return false; |
162 |
} |
163 |
} |
164 |
|
165 |
public static void updateJnlpExtension(final Project project) throws IOException { |
166 |
copyJnlpImplTemplate(project); |
167 |
modifyBuildXml(project); |
168 |
copyJWSAntTasksLibrary(project); |
169 |
} |
170 |
|
171 |
static void updateJnlpExtensionAndSave( |
172 |
final JWSProjectProperties props, |
173 |
final Project project) { |
174 |
updateMasterFiles(props, project); |
175 |
savePropsAndUpdateMetaFiles(props, project); |
176 |
} |
177 |
|
178 |
private static void updateMasterFiles(JWSProjectProperties props, Project proj) { |
105 |
try { |
179 |
try { |
106 |
if (props.isJWSEnabled()) { |
180 |
if (props.isJWSEnabled()) { |
107 |
// test if the file already exists, if so do not generate, just set as active |
181 |
// test if the file already exists, if so do not generate, just set as active |
Lines 257-263
Link Here
|
257 |
} |
331 |
} |
258 |
} |
332 |
} |
259 |
|
333 |
|
260 |
public static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) { |
334 |
private static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) { |
261 |
try { |
335 |
try { |
262 |
try { |
336 |
try { |
263 |
props.store(); |
337 |
props.store(); |
Lines 268-274
Link Here
|
268 |
proj.getLookup().lookup(ProjectConfigurationProvider.class); |
342 |
proj.getLookup().lookup(ProjectConfigurationProvider.class); |
269 |
if (props.wasJWSActivated()) { |
343 |
if (props.wasJWSActivated()) { |
270 |
setActiveConfig(configProvider, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart")); // NOI18N |
344 |
setActiveConfig(configProvider, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart")); // NOI18N |
271 |
copyTemplate(proj); |
345 |
copyJnlpImplTemplate(proj); |
272 |
modifyBuildXml(proj); |
346 |
modifyBuildXml(proj); |
273 |
copyJWSAntTasksLibrary(proj); |
347 |
copyJWSAntTasksLibrary(proj); |
274 |
} else if (props.wasJWSDeactivated()){ |
348 |
} else if (props.wasJWSDeactivated()){ |
Lines 298-341
Link Here
|
298 |
} |
372 |
} |
299 |
} |
373 |
} |
300 |
} |
374 |
} |
301 |
} |
375 |
} |
302 |
|
|
|
303 |
public static void copyTemplate(Project proj) throws IOException { |
304 |
boolean isJnlpCurrent = true; |
305 |
FileObject projDir = proj.getProjectDirectory(); |
306 |
FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N |
307 |
if (jnlpBuildFile != null) { |
308 |
final InputStream in = jnlpBuildFile.getInputStream(); |
309 |
if(in != null) { |
310 |
try { |
311 |
isJnlpCurrent = isJnlpImplCurrentVer(computeCrc32( in )); |
312 |
} finally { |
313 |
in.close(); |
314 |
} |
315 |
} |
316 |
} |
317 |
if (!isJnlpCurrent) { |
318 |
// try to close the file just in case the file is already opened in editor |
319 |
DataObject dobj = DataObject.find(jnlpBuildFile); |
320 |
CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class); |
321 |
if (closeCookie != null) { |
322 |
closeCookie.close(); |
323 |
} |
324 |
final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N |
325 |
final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml"); //NOI18N |
326 |
if (backupFile != null) { |
327 |
backupFile.delete(); |
328 |
} |
329 |
FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup"); //NOI18N |
330 |
jnlpBuildFile = null; |
331 |
} |
332 |
if (jnlpBuildFile == null) { |
333 |
FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE); |
334 |
if (templateFO != null) { |
335 |
FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N |
336 |
} |
337 |
} |
338 |
} |
339 |
|
376 |
|
340 |
private static void modifyBuildXml(Project proj) throws IOException { |
377 |
private static void modifyBuildXml(Project proj) throws IOException { |
341 |
FileObject projDir = proj.getProjectDirectory(); |
378 |
FileObject projDir = proj.getProjectDirectory(); |
Lines 350-361
Link Here
|
350 |
} catch (SAXException ex) { |
387 |
} catch (SAXException ex) { |
351 |
Exceptions.printStackTrace(ex); |
388 |
Exceptions.printStackTrace(ex); |
352 |
} |
389 |
} |
353 |
FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N |
390 |
FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH); |
354 |
AntBuildExtender extender = proj.getLookup().lookup(AntBuildExtender.class); |
391 |
AntBuildExtender extender = proj.getLookup().lookup(AntBuildExtender.class); |
355 |
if (extender != null) { |
392 |
if (extender != null) { |
356 |
assert jnlpBuildFile != null; |
393 |
assert jnlpBuildFile != null; |
357 |
if (extender.getExtension("jws") == null) { // NOI18N |
394 |
if (extender.getExtension(CURRENT_EXTENSION) == null) { // NOI18N |
358 |
AntBuildExtender.Extension ext = extender.addExtension("jws", jnlpBuildFile); // NOI18N |
395 |
AntBuildExtender.Extension ext = extender.addExtension(CURRENT_EXTENSION, jnlpBuildFile); // NOI18N |
359 |
ext.addDependency("jar", "jnlp"); // NOI18N |
396 |
ext.addDependency("jar", "jnlp"); // NOI18N |
360 |
ext.addDependency("-post-jar", "jnlp"); //NOI18N |
397 |
ext.addDependency("-post-jar", "jnlp"); //NOI18N |
361 |
} |
398 |
} |
Lines 397-403
Link Here
|
397 |
nl = docElem.getElementsByTagName("import"); // NOI18N |
434 |
nl = docElem.getElementsByTagName("import"); // NOI18N |
398 |
for (int i = 0; i < nl.getLength(); i++) { |
435 |
for (int i = 0; i < nl.getLength(); i++) { |
399 |
Element e = (Element) nl.item(i); |
436 |
Element e = (Element) nl.item(i); |
400 |
if (e.getAttribute("file") != null && "nbproject/jnlp-impl.xml".equals(e.getAttribute("file"))) { // NOI18N |
437 |
if (e.getAttribute("file") != null && JNLP_BUILD_IMPL_PATH.equals(e.getAttribute("file"))) { // NOI18N |
401 |
e.getParentNode().removeChild(e); |
438 |
e.getParentNode().removeChild(e); |
402 |
changed = true; |
439 |
changed = true; |
403 |
break; |
440 |
break; |
Lines 450-493
Link Here
|
450 |
return prj.getProjectDirectory().getFileObject (buildScriptPath); |
487 |
return prj.getProjectDirectory().getFileObject (buildScriptPath); |
451 |
} |
488 |
} |
452 |
|
489 |
|
453 |
static String computeCrc32(InputStream is) throws IOException { |
490 |
private static String computeCrc32(final FileObject fo) throws IOException { |
454 |
Checksum crc = new CRC32(); |
491 |
final Checksum crc = new CRC32(); |
455 |
int last = -1; |
492 |
final InputStream in = fo.getInputStream(); |
456 |
int curr; |
493 |
try { |
457 |
while ((curr = is.read()) != -1) { |
494 |
int last = -1; |
458 |
if (curr != '\n' && last == '\r') { |
495 |
int curr; |
459 |
crc.update('\n'); |
496 |
while ((curr = in.read()) != -1) { |
|
|
497 |
if (curr != '\n' && last == '\r') { //NOI18N |
498 |
crc.update('\n'); //NOI18N |
499 |
} |
500 |
if (curr != '\r') { //NOI18N |
501 |
crc.update(curr); |
502 |
} |
503 |
last = curr; |
460 |
} |
504 |
} |
461 |
if (curr != '\r') { |
505 |
if (last == '\r') { //NOI18N |
462 |
crc.update(curr); |
506 |
crc.update('\n'); //NOI18N |
463 |
} |
507 |
} |
464 |
last = curr; |
508 |
} finally { |
465 |
} |
509 |
in.close(); |
466 |
if (last == '\r') { |
|
|
467 |
crc.update('\n'); |
468 |
} |
510 |
} |
469 |
int val = (int)crc.getValue(); |
511 |
int val = (int)crc.getValue(); |
470 |
String hex = Integer.toHexString(val); |
512 |
String hex = Integer.toHexString(val); |
471 |
while (hex.length() < 8) { |
513 |
while (hex.length() < 8) { |
472 |
hex = "0" + hex; // NOI18N |
514 |
hex = "0" + hex; // NOI18N |
473 |
} |
515 |
} |
474 |
return hex; |
516 |
return hex; |
475 |
} |
517 |
} |
476 |
|
|
|
477 |
static boolean isJnlpImplCurrentVer(String crc) throws IOException { |
478 |
String _currentJnlpImplCRC = currentJnlpImplCRCCache; |
479 |
if (_currentJnlpImplCRC == null) { |
480 |
final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE); |
481 |
final InputStream in = template.getInputStream(); |
482 |
if(in != null) { |
483 |
try { |
484 |
currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(in); |
485 |
} finally { |
486 |
in.close(); |
487 |
} |
488 |
} |
489 |
} |
490 |
return _currentJnlpImplCRC.equals(crc); |
491 |
} |
492 |
|
493 |
} |
518 |
} |