@@ -26,48 +26,86 @@ var ClosureCompiler = require(__dirname+"/../ClosureCompiler.js"),
26
26
child_process = require ( "child_process" ) ,
27
27
pkg = require ( __dirname + "/../package.json" ) ;
28
28
29
+ console . log ( "Configuring ClosureCompiler.js " + pkg . version + " ...\n" ) ;
30
+
31
+ // Closure Compiler download url
32
+ var ccUrl = "http://closure-compiler.googlecode.com/files/compiler-latest.zip" ;
33
+
34
+ // Temporary file for the download
35
+ var ccTempFile = path . normalize ( __dirname + path . sep + ".." + path . sep + "compiler" + path . sep + "compiler.zip" ) ;
36
+
29
37
// Bundled JRE download url
30
38
var jreUrl = "http://bundled-openjdk-jre.googlecode.com/files/OpenJDK-JRE-7u6_24.zip" ;
31
39
32
40
// Temporary file for the download
33
- var jreTempFile = __dirname + path . sep + ".." + path . sep + "jre" + path . sep + "OpenJDK-JRE.zip" ;
41
+ var jreTempFile = path . normalize ( __dirname + path . sep + ".." + path . sep + "jre" + path . sep + "OpenJDK-JRE.zip" ) ;
42
+
43
+ console . log ( " Downloading Closure Compiler ..." ) ;
44
+ var lastBytes = 0 , currentBytes = 0 , mb = 1024 * 1024 ;
45
+ download ( ccUrl , ccTempFile , function ( error , bytes ) {
46
+ if ( error ) {
47
+ console . log ( " ✖ Download failed: " + error + "\n" ) ;
48
+ fail ( ) ;
49
+ }
50
+ console . log ( " ✔ Download complete: " + ccTempFile + " (" + parseInt ( bytes / mb , 10 ) + " mb)" ) ;
51
+ unpack ( ccTempFile , function ( error ) {
52
+ if ( error ) {
53
+ console . log ( " ✖ Unpack failed: " + error + "\n" ) ;
54
+ fail ( ) ;
55
+ }
56
+ console . log ( " ✔ Unpack complete.\n" ) ;
57
+ configure_jre ( ) ;
58
+ } ) ;
59
+ } , function ( bytes , total ) {
60
+ currentBytes += bytes ;
61
+ if ( currentBytes == bytes || currentBytes - lastBytes >= mb ) {
62
+ console . log ( " | " + parseInt ( currentBytes / mb , 10 ) + " / " + ( total > 0 ? parseInt ( total / mb , 10 ) : "???" ) + " mb" ) ;
63
+ lastBytes = currentBytes ;
64
+ }
65
+ } ) ;
34
66
35
- // Test if there is already a global Java so we don't need to download anything
36
- console . log ( "Configuring ClosureCompiler.js " + pkg . version + " ...\n" ) ;
37
- ClosureCompiler . testJava ( ClosureCompiler . getGlobalJava ( ) , function ( ok ) {
38
- if ( ok ) {
39
- console . log ( " ✔ Global Java is available, perfect!\n" ) ;
40
- // Travis CI for example has one, so we save their bandwidth. And Google's. And yours. And...
41
- finish ( ) ;
42
- } else {
43
- console . log ( " ✖ Global Java not found, we need to install the bundled JRE ..." ) ;
44
- console . log ( " Downloading " + jreUrl + " ..." ) ;
45
- var lastBytes = 0 , currentBytes = 0 , mb = 1024 * 1024 ;
46
- download ( jreUrl , jreTempFile , function ( error , bytes ) {
47
- if ( error ) {
48
- console . log ( " ✖ Download failed: " + error + "\n" ) ;
49
- fail ( ) ;
50
- }
51
- console . log ( " ✔ Download complete: " + jreTempFile + " (" + parseInt ( bytes / mb , 10 ) + " mb)" ) ;
52
- console . log ( " Unpacking " + jreTempFile + " ..." ) ;
53
- unpack ( jreTempFile , function ( error ) {
67
+ /**
68
+ * Configures the JRE.
69
+ */
70
+ function configure_jre ( ) {
71
+ console . log ( " Configuring JRE ..." ) ;
72
+
73
+ // Test if there is already a global Java so we don't need to download anything
74
+ ClosureCompiler . testJava ( ClosureCompiler . getGlobalJava ( ) , function ( ok ) {
75
+ if ( ok ) {
76
+ console . log ( " ✔ Global Java is available, perfect!\n" ) ;
77
+ // Travis CI for example has one, so we save their bandwidth. And Google's. And yours. And...
78
+ finish ( ) ;
79
+ } else {
80
+ console . log ( " ✖ Global Java not found, we need to install the bundled JRE ..." ) ;
81
+ console . log ( " Downloading " + jreUrl + " ..." ) ;
82
+ lastBytes = 0 ; currentBytes = 0 ;
83
+ download ( jreUrl , jreTempFile , function ( error , bytes ) {
54
84
if ( error ) {
55
- console . log ( " ✖ Unpack failed: " + error + "\n" ) ;
85
+ console . log ( " ✖ Download failed: " + error + "\n" ) ;
56
86
fail ( ) ;
57
87
}
58
- console . log ( " ✔ Unpack complete.\n" ) ;
59
- configure ( ) ;
60
- runTest ( ) ;
88
+ console . log ( " ✔ Download complete: " + jreTempFile + " (" + parseInt ( bytes / mb , 10 ) + " mb)" ) ;
89
+ console . log ( " Unpacking " + jreTempFile + " ..." ) ;
90
+ unpack ( jreTempFile , function ( error ) {
91
+ if ( error ) {
92
+ console . log ( " ✖ Unpack failed: " + error + "\n" ) ;
93
+ fail ( ) ;
94
+ }
95
+ console . log ( " ✔ Unpack complete.\n" ) ;
96
+ configure ( ) ;
97
+ runTest ( ) ;
98
+ } ) ;
99
+ } , function ( bytes , total ) {
100
+ currentBytes += bytes ;
101
+ if ( currentBytes == bytes || currentBytes - lastBytes >= mb ) {
102
+ console . log ( " | " + parseInt ( currentBytes / mb , 10 ) + " / " + ( total > 0 ? parseInt ( total / mb , 10 ) : "???" ) + " mb" ) ;
103
+ lastBytes = currentBytes ;
104
+ }
61
105
} ) ;
62
- } , function ( bytes , total ) {
63
- currentBytes += bytes ;
64
- if ( currentBytes == bytes || currentBytes - lastBytes >= mb ) {
65
- console . log ( " | " + parseInt ( currentBytes / mb , 10 ) + " / " + ( total > 0 ? parseInt ( total / mb , 10 ) : "???" ) + " mb" ) ;
66
- lastBytes = currentBytes ;
67
- }
68
- } ) ;
69
- }
70
- } ) ;
106
+ }
107
+ } ) ;
108
+ }
71
109
72
110
/**
73
111
* Downloads a file.
@@ -187,6 +225,7 @@ function runTest() {
187
225
* Cleans up.
188
226
*/
189
227
function cleanUp ( ) {
228
+ try { fs . unlinkSync ( ccTempFile ) ; } catch ( e ) { }
190
229
try { fs . unlinkSync ( jreTempFile ) ; } catch ( e ) { }
191
230
// ...your harddrive's space.
192
231
}
0 commit comments