Fix infinite loop in the build if file does not have a header

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/889f4c1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/889f4c1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/889f4c1b

Branch: refs/heads/master
Commit: 889f4c1b8fdd1b23a339a38c74382e8f55cfaf90
Parents: 60666b0
Author: Simon MacDonald <simon.macdon...@gmail.com>
Authored: Wed Sep 19 13:46:41 2012 -0400
Committer: Simon MacDonald <simon.macdon...@gmail.com>
Committed: Wed Sep 19 13:46:41 2012 -0400

----------------------------------------------------------------------
 build/packager.js |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/889f4c1b/build/packager.js
----------------------------------------------------------------------
diff --git a/build/packager.js b/build/packager.js
index 6c1b846..7b8eff0 100644
--- a/build/packager.js
+++ b/build/packager.js
@@ -179,7 +179,7 @@ function collectFiles(dir, id) {
 function writeScript(oFile, fileName, debug) {
     var contents = getContents(fileName, 'utf8')
 
-    contents = stripHeader(contents)
+    contents = stripHeader(contents, fileName)
     
     writeContents(oFile, fileName, contents, debug)    
 }
@@ -188,7 +188,7 @@ function writeScript(oFile, fileName, debug) {
 function writeModule(oFile, fileName, moduleId, debug) {
     var contents = getContents(fileName, 'utf8')
 
-    contents = '\n' + stripHeader(contents) + '\n'
+    contents = '\n' + stripHeader(contents, fileName) + '\n'
 
        // Windows fix, '\' is an escape, but defining requires '/' -jm
     moduleId = path.join('cordova', moduleId).split("\\").join("/");
@@ -251,7 +251,7 @@ function copyProps(target, source) {
 }
 //-----------------------------------------------------------------------------
 // Strips the license header. Basically only the first multi-line comment up 
to to the closing */
-function stripHeader(contents) {
+function stripHeader(contents, fileName) {
     var ls = contents.split('\n');
     while (ls[0]) {
         if (ls[0].match(/^\s*\/\*/) || ls[0].match(/^\s*\*/)) ls.shift();
@@ -259,6 +259,10 @@ function stripHeader(contents) {
             ls.shift();
             break;
         }
+        else {
+               console.log("WARNING: file name " + fileName + " is missing the 
license header");
+               break;
+       }
     }
     return ls.join('\n');
 }

Reply via email to