Skip to content

Commit

Permalink
Fixes for FileList support.
Browse files Browse the repository at this point in the history
Reviewed by me.
  • Loading branch information
Francisco Tolmasky committed Sep 28, 2009
1 parent 7aa6e34 commit 68a8fd1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/jake.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ exports.filedir = function()
exports.directory (fileDirectory);
exports.file (fileTask.name(), fileDirectory);
}

exports.FileList = require("jake/filelist").FileList;
/*
# Return the original directory where the Rake application was started.
def original_dir
Expand Down
28 changes: 20 additions & 8 deletions lib/jake/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function FileList(/*Strings, vararg*/)
this._excludedProcs = DEFAULT_IGNORE_PROCS.slice();
this._items = [];

Array.prototype.forEach.apply(arguments, function(anArgument)
Array.prototype.forEach.call(arguments, function(anArgument)
{
this.include(anArgument);
}, this);
Expand Down Expand Up @@ -185,7 +185,7 @@ FileList.prototype.add = FileList.prototype.include;
//
FileList.prototype.exclude = function(/*Strings|Functions*/)
{
Array.prototype.forEach.apply(arguments, function(/*String|Function*/ anObject)
Array.prototype.forEach.call(arguments, function(/*String|Function*/ anObject)
{
if (typeof anObject === "function")
this._excludedProcs.push(anObject);
Expand Down Expand Up @@ -278,15 +278,27 @@ FileList.prototype._resolveExclude = function()

FileList.prototype._shouldExclude = function(aFilename)
{
var failedFilters = this._excludedPatterns.filter(function(aPattern){
return aPattern.test(aFilename);
}, this);
return this._excludedPatterns.some(function(aPattern)
{
if (aPattern.constructor === RegExp && aPattern.test(aFilename))
return true;

if (aPattern.match && aPattern.match(/[*?]/))
{
var OS = require("os");

var failedProcs = this._excludedProcs.filter(function(aFunction){
OS.system("echo \"puts File.fnmatch?(" + OS.enquote(aPattern) + ", " + OS.enquote(aFilename) + ", File::FNM_PATHNAME)\" | ruby > /tmp/fnmatch_fixme.txt");

return FILE.read("/tmp/fnmatch_fixme.txt", {charsert:"UTF-8"}).indexOf("true") !== -1;
}

if (aFilename === aPattern)
return true;
}) ||
this._excludedProcs.some(function(aFunction)
{
return aFunction.apply(this, [aFilename]);
}, this);

return (failedFilters.length !== 0 || failedProcs.length !== 0);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions lib/jake/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ Task.prototype.application = function()
return this._application;
}

Task.prototype.enhance = function(/*Array*/ prerequisites, /*Function*/ anAction)
Task.prototype.enhance = function(/*Array|FileList*/ prerequisites, /*Function*/ anAction)
{
if (prerequisites)
this._prerequisites = this._prerequisites.concat(prerequisites);
this._prerequisites = this._prerequisites.concat(prerequisites.toArray ? prerequisites.toArray() : prerequisites);

if (anAction)
this._actions.push(anAction);
Expand Down

0 comments on commit 68a8fd1

Please sign in to comment.