Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch to JavaScript style. Sorry Francisco.

  • Loading branch information...
commit 58ca3906caf6a7ae5c41afbc4a1b089438f2f1a8 1 parent 8eab69d
@tlrobinson tlrobinson authored
View
56 lib/jake.js
@@ -27,11 +27,12 @@ var SYSTEM = require("system");
var UTIL = require("narwhal/util");
var OS = require("os");
-var Task = require("jake/task").Task;
-var FileTask = require("jake/filetask").FileTask;
-var FileCreationTask = require("jake/filecreationtask").FileCreationTask;
-var TaskManager = require("jake/taskmanager").TaskManager;
-var Application = require("jake/application").Application;
+var Task = require("./jake/task").Task;
+var FileTask = require("./jake/filetask").FileTask;
+var FileCreationTask = require("./jake/filecreationtask").FileCreationTask;
+var TaskManager = require("./jake/taskmanager").TaskManager;
+var Application = require("./jake/application").Application;
+var FileList = require("./jake/filelist").FileList;
// Exports
exports.Task = Task;
@@ -39,47 +40,40 @@ exports.FileTask = FileTask;
exports.FileCreationTask = FileCreationTask;
exports.TaskManager = TaskManager;
exports.Application = Application;
+exports.FileList = FileList;
var application = null;
-exports.application = function()
-{
+exports.application = function() {
if (!application)
application = new Application();
return application;
}
-exports.setApplication = function(/*Application*/ anApplication)
-{
+exports.setApplication = function(/*Application*/ anApplication) {
application = anApplication;
}
exports.EARLY = new Date(-10000,1,1,0,0,0,0).getTime();
-exports.task = function()
-{
+exports.task = function() {
return Task.defineTask.apply(Task, arguments);
}
-exports.file = function()
-{
+exports.file = function() {
return FileTask.defineTask.apply(FileTask, arguments);
}
-exports.fileCreate = function()
-{
+exports.fileCreate = function() {
return FileCreationTask.defineTask.apply(FileCreationTask, arguments);
}
-exports.directory = function(aDirectory)
-{
+exports.directory = function(aDirectory) {
var oldLength = null;
- while (aDirectory !== "." && aDirectory.length !== oldLength)
- {
- exports.fileCreate(aDirectory, function(aTask)
- {
+ while (aDirectory !== "." && aDirectory.length !== oldLength) {
+ exports.fileCreate(aDirectory, function(aTask) {
var taskName = aTask.name();
if (!FILE.exists(taskName))
@@ -91,16 +85,14 @@ exports.directory = function(aDirectory)
}
}
-exports.filedir = function()
-{
- var fileTask = FileTask.defineTask.apply(FileTask, arguments),
- fileDirectory = FILE.dirname(fileTask.name());
+exports.filedir = function() {
+ var fileTask = FileTask.defineTask.apply(FileTask, arguments);
+ var fileDirectory = FILE.dirname(fileTask.name());
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
@@ -110,23 +102,19 @@ exports.FileList = require("jake/filelist").FileList;
// record the initial SYSTEM.env so we know what needs to be serialized later
var envInitial = Object.freeze(UTIL.copy(SYSTEM.env));
-function serializeEnv(/*Object*/ env)
-{
+function serializeEnv(/*Object*/ env) {
return Object.keys(env).map(function(key) {
return (env[key] !== envInitial[key]) ? key + "=" + OS.enquote(env[key]) : null;
}).filter(function(x) { return !!x; }).join(" ");
}
-exports.subjake = function(/*Array<String> | String*/ directories, /*String*/ aTaskName, /*Object*/ env)
-{
+exports.subjake = function(/*Array<String> | String*/ directories, /*String*/ aTaskName, /*Object*/ env) {
if (!Array.isArray(directories))
directories = [directories];
- directories.forEach(function(/*String*/ aDirectory)
- {
- if (FILE.isDirectory(aDirectory))
- {
+ directories.forEach(function(/*String*/ aDirectory) {
+ if (FILE.isDirectory(aDirectory)) {
if (OS.system("cd " + OS.enquote(aDirectory) + " && " + serializeEnv(env) + " jake " + OS.enquote(aTaskName)))
OS.exit(1);
}
View
108 lib/jake/application.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env narwhal
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
@@ -26,13 +25,13 @@ var FILE = require("file");
var SYSTEM = require("system");
var printf = require("printf").printf;
-var Task = require("jake/task").Task;
-var FileTask = require("jake/filetask").FileTask;
-var FileCreationTask = require("jake/filecreationtask").FileCreationTask;
-var TaskManager = require("jake/taskmanager").TaskManager;
+var Task = require("./task").Task;
+var FileTask = require("./filetask").FileTask;
+var FileCreationTask = require("./filecreationtask").FileCreationTask;
+var TaskManager = require("./taskmanager").TaskManager;
-var DEFAULT_JAKEFILES = ["jakefile", "Jakefile", "jakefile.js", "Jakefile.js", "jakefile.j", "Jakefile.j"];
+var DEFAULT_JAKEFILES = ["jakefile", "Jakefile", "jakefile.js", "Jakefile.js", "jakefile.j", "Jakefile.j"];
var parser = new (require("narwhal/args").Parser)();
parser.usage("targets...");
@@ -60,8 +59,7 @@ parser.option("--verbose", "-v", "verbose")
parser.helpful();
-var Application = function()
-{
+var Application = function() {
TaskManager.call(this);
this._name = "jake";
@@ -97,37 +95,32 @@ Application.prototype.__proto__ = TaskManager.prototype;
// If you wish to build a custom jake command, you should call +init+ on your
// application. Then define any tasks. Finally, call +topLevel+ to run your top
// level tasks.
-Application.prototype.run = function(options)
-{
+Application.prototype.run = function(options) {
this.init(options);
this.loadJakefile();
this.topLevel();
}
-function timeDeltaString(/*Date*/ aTimeDelta)
-{
+function timeDeltaString(/*Date*/ aTimeDelta) {
var string = "";
- if (aTimeDelta > 1000 * 60 * 60)
- {
+ if (aTimeDelta > 1000 * 60 * 60) {
var hours = Math.floor(aTimeDelta / (1000 * 60 * 60));
aTimeDelta -= hours * 1000 * 60 * 60;
string = hours + (hours === 1 ? " hour" : " hours");
}
-
- if (aTimeDelta > 1000 * 60)
- {
+
+ if (aTimeDelta > 1000 * 60) {
var minutes = Math.floor(aTimeDelta / (1000 * 60))
aTimeDelta -= minutes * 1000 * 60;
string += (string.length ? " " : "" ) + minutes + (minutes === 1 ? " minute" : " minutes");
}
-
- if (aTimeDelta > 1000)
- {
+
+ if (aTimeDelta > 1000) {
var seconds = Math.floor(aTimeDelta / 1000);
aTimeDelta -= seconds * 1000;
@@ -142,22 +135,19 @@ function timeDeltaString(/*Date*/ aTimeDelta)
}
// Initialize the command line parameters and app name.
-Application.prototype.init = function(options)
-{
+Application.prototype.init = function(options) {
this._name = options.appName || "jake";
this.handleOptions(options.args || SYSTEM.args);
this.collectTasks();
}
// Find the rakefile and then load it and any pending imports.
-Application.prototype.loadJakefile = function()
-{
+Application.prototype.loadJakefile = function() {
this.rawLoadJakefile();
}
// Run the top level tasks of a Rake application.
-Application.prototype.topLevel = function()
-{
+Application.prototype.topLevel = function() {
if (this._options.showTasks)
this.displayTasksAndComments();
else if (this._options.showPrereqs)
@@ -189,16 +179,14 @@ Application.prototype.
# private ----------------------------------------------------------------
*/
-Application.prototype.invokeTask = function(/*String*/ aTaskString)
-{
- var result = this.parseTaskString(aTaskString),
- task = this.lookupTask(result[0]);
+Application.prototype.invokeTask = function(/*String*/ aTaskString) {
+ var result = this.parseTaskString(aTaskString);
+ var task = this.lookupTask(result[0]);
task.invoke.apply(task, result[1]);
}
-Application.prototype.parseTaskString = function(/*String*/ aString)
-{
+Application.prototype.parseTaskString = function(/*String*/ aString) {
var matches = aString.match(/^([^\[]+)(\[(.*)\])$/);
if (matches)
@@ -234,10 +222,8 @@ Application.prototype.parseTaskString = function(/*String*/ aString)
// True if one of the files in JAKEFILES is in the current directory.
// If a match is found, it is copied into @jakefile.
-Application.prototype.hasJakefile = function(/*String*/ aDirectory)
-{
- for (var i = 0; i < this._jakefiles.length; ++i)
- {
+Application.prototype.hasJakefile = function(/*String*/ aDirectory) {
+ for (var i = 0; i < this._jakefiles.length; ++i) {
var jakefile = this._jakefiles[i];
if (FILE.exists(FILE.join(aDirectory, jakefile)))
@@ -246,7 +232,7 @@ Application.prototype.hasJakefile = function(/*String*/ aDirectory)
else if (jakefile === "")
return null;
}
-
+
return null;
}
/*
@@ -268,8 +254,7 @@ Application.prototype.hasJakefile = function(/*String*/ aDirectory)
*/
// Display the tasks and comments.
-Application.prototype.displayTasksAndComments = function()
-{
+Application.prototype.displayTasksAndComments = function() {
var displayableTasks = Object.keys(this._tasks).map(function(name) { return this._tasks[name]; }, this).filter(function(t) {
return !!t.fullComment();
}, this);
@@ -327,7 +312,7 @@ Application.prototype.displayTasksAndComments = function()
80
end
- # Calculate the dynamic width of the
+ # Calculate the dynamic width of the
def dynamic_width
@dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
end
@@ -343,7 +328,7 @@ Application.prototype.displayTasksAndComments = function()
def unix?
RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
end
-
+
def windows?
Win32.windows?
end
@@ -358,8 +343,7 @@ Application.prototype.displayTasksAndComments = function()
*/
// Display the tasks and prerequisites
-Application.prototype.displayPrerequisites = function()
-{
+Application.prototype.displayPrerequisites = function() {
this.tasks().forEach(function(t) {
printf("%s %s", this.name(), t.name());
t.prerequisites().forEach(function(pre) {
@@ -415,7 +399,7 @@ Application.prototype.displayPrerequisites = function()
],
['--execute-continue', '-E CODE',
"Execute some Ruby code, then continue with normal task processing.",
- lambda { |value| eval(value) }
+ lambda { |value| eval(value) }
],
['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
lambda { |value| $:.push(value) }
@@ -427,9 +411,9 @@ Application.prototype.displayPrerequisites = function()
lambda { |value| verbose(false) }
],
['--rakefile', '-f [FILE]', "Use FILE as the rakefile.",
- lambda { |value|
+ lambda { |value|
value ||= ''
- @rakefiles.clear
+ @rakefiles.clear
@rakefiles << value
}
],
@@ -497,8 +481,7 @@ Application.prototype.displayPrerequisites = function()
*/
// Read and handle the command line options.
-Application.prototype.handleOptions = function(args)
-{
+Application.prototype.handleOptions = function(args) {
this._options = parser.parse(args.slice());
if (this._options.file)
@@ -550,10 +533,9 @@ Application.prototype.handleOptions = function(args)
end
*/
-Application.prototype.findJakefileLocation = function()
-{
- var directory = FILE.cwd(),
- filename = null;
+Application.prototype.findJakefileLocation = function() {
+ var directory = FILE.cwd();
+ var filename = null;
while (!(filename = this.hasJakefile(directory)) && directory !== "/")// && !this._options.nosearch)
directory = FILE.absolute(FILE.join(directory, ".."));
@@ -564,12 +546,11 @@ Application.prototype.findJakefileLocation = function()
return [filename, directory];
}
-Application.prototype.rawLoadJakefile = function()
-{
- var result = this.findJakefileLocation(),
- jakefile = result ? result[0] : null,
- location = result ? result[1] : null,
- options = this._options;
+Application.prototype.rawLoadJakefile = function() {
+ var result = this.findJakefileLocation();
+ var jakefile = result ? result[0] : null;
+ var location = result ? result[1] : null;
+ var options = this._options;
/*
if (!options.ignore_system && (options.load_system || !rakefile) && system_dir && FILE.directory?(system_dir)
if (options["silent"])
@@ -579,8 +560,7 @@ Application.prototype.rawLoadJakefile = function()
add_import name
end
}
- else*/
- {
+ else*/ {
if (!jakefile)
throw "No Jakefile found (looking for: " + this._jakefiles.join(', ') + ")";
@@ -625,7 +605,7 @@ Application.prototype.rawLoadJakefile = function()
end
end
end
-
+
# The standard directory containing system wide rake files.
def standard_system_dir #:nodoc:
File.join(File.expand_path('~'), '.rake')
@@ -636,14 +616,12 @@ Application.prototype.rawLoadJakefile = function()
// Collect the list of tasks on the command line. If no tasks are
// given, return a list containing only the default task.
// Environmental assignments are processed at this time as well.
-Application.prototype.collectTasks = function()
-{
+Application.prototype.collectTasks = function() {
this._topLevelTasks = [];
var topLevelTasks = this._topLevelTasks;
- this._options.args.forEach(function(/*String*/ anArgument)
- {
+ this._options.args.forEach(function(/*String*/ anArgument) {
var matches = anArgument.match(/^(\w+)=(.*)$/);
if (matches)
SYSTEM.env[matches[1]] = matches[2];
View
38 lib/jake/clean.js
@@ -1,3 +1,4 @@
+
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
//
@@ -34,46 +35,35 @@
// The intent of this task is to return a project to its
// pristine, just unpacked state.
-var FILE = require("file"),
- Jake = require("jake"),
- FileList = require("jake/filelist").FileList;
+var FILE = require("file");
+var JAKE = require("../jake");
+var FileList = require("./filelist").FileList;
var CLEAN = new FileList("**/*~", "**/*.bak", "**/core");
-CLEAN.clearExclude().exclude(function(aFilename)
-{
+CLEAN.clearExclude().exclude(function(aFilename) {
return FILE.basename(aFilename) === "core" && FILE.isDirectory(aFilename);
});
// desc "Remove any temporary products."
-Jake.task("clean", function()
-{
- CLEAN.forEach(function(aFilename)
- {
- try
- {
+JAKE.task("clean", function() {
+ CLEAN.forEach(function(aFilename) {
+ try {
FILE.rmtree(aFilename);
- }
- catch(anException)
- {
+ } catch(anException) {
}
});
});
-var CLOBBER = new Jake.FileList();
+var CLOBBER = new FileList();
// desc "Remove any generated file."
-Jake.task("clobber", ["clean"], function()
-{
- CLOBBER.forEach(function(aFilename)
- {
- try
- {
+JAKE.task("clobber", ["clean"], function() {
+ CLOBBER.forEach(function(aFilename) {
+ try {
FILE.rmtree(aFilename);
- }
- catch(anException)
- {
+ } catch(anException) {
}
});
});
View
19 lib/jake/filecreationtask.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env narwhal
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
@@ -22,9 +21,10 @@
// IN THE SOFTWARE.
//
-var FILE = require("file"),
- Jake = require("jake"),
- FileTask = require("jake/filetask").FileTask;
+var FILE = require("file");
+
+var JAKE = require("../jake");
+var FileTask = require("./filetask").FileTask;
// #########################################################################
// A FileCreationTask is a file task that when used as a dependency will be
@@ -32,8 +32,7 @@ var FILE = require("file"),
// not re-triggered if any of its dependencies are newer, nor does trigger
// any rebuilds of tasks that depend on it whenever it is updated.
//
-var FileCreationTask = function()
-{
+var FileCreationTask = function() {
FileTask.apply(this, arguments);
}
@@ -42,16 +41,14 @@ FileCreationTask.prototype.__proto__ = FileTask.prototype;
//print("IT IS " + FileTask.defineTask + " " + FileCreationTask.defineTask);
// Is this file task needed? Yes if it doesn't exist.
-FileCreationTask.prototype.isNeeded = function()
-{
+FileCreationTask.prototype.isNeeded = function() {
return !FILE.exists(this.name());
}
// Time stamp for file creation task. This time stamp is earlier
// than any other time stamp.
-FileCreationTask.prototype.timestamp = function()
-{
- return Jake.EARLY;
+FileCreationTask.prototype.timestamp = function() {
+ return JAKE.EARLY;
}
// Exports
View
104 lib/jake/filelist.js
@@ -31,18 +31,18 @@ var FILE = require("file");
# return a new Array object. We want to capture the return value of these
# methods and wrap them in a new FileList object. We enumerate these
# methods in the +SPECIAL_RETURN+ list below.
-
+
# List of array methods (that are not in +Object+) that need to be
# delegated.
ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
-
+
# List of additional methods that must be delegated.
MUST_DEFINE = %w[to_a inspect]
-
+
# List of methods that should not be delegated here (we define special
# versions of them explicitly below).
MUST_NOT_DEFINE = %w[to_a to_ary partition *]
-
+
# List of delegated methods that return new array values which need
# wrapping.
SPECIAL_RETURN = %w[
@@ -50,9 +50,9 @@ var FILE = require("file");
compact flatten uniq values_at
+ - & |
]
-
+
DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).collect{ |s| s.to_s }.sort.uniq
-
+
# Now do the delegation.
DELEGATING_METHODS.each_with_index do |sym, i|
if SPECIAL_RETURN.include?(sym)
@@ -98,16 +98,14 @@ var DEFAULT_IGNORE_PATTERNS = [
// fl.exclude(/\bCVS\b/)
// end
//
-function FileList(/*Strings, vararg*/)
-{
+function FileList(/*Strings, vararg*/) {
this._pendingAdd = [];
this._pending = false;
this._excludedPatterns = DEFAULT_IGNORE_PATTERNS.slice();
this._excludedProcs = DEFAULT_IGNORE_PROCS.slice();
this._items = [];
- Array.prototype.forEach.call(arguments, function(anArgument)
- {
+ Array.prototype.forEach.call(arguments, function(anArgument) {
this.include(anArgument);
}, this);
@@ -116,21 +114,18 @@ function FileList(/*Strings, vararg*/)
["forEach", "filter", "map", "select",
"sort", "uniq", "push", "pop", "shift",
-"unshift"].forEach(function(string)
-{
+"unshift"].forEach(function(string) {
FileList.prototype[string] = function() {
return (Array.prototype[string]).apply(this.items(), arguments);
};
});
-FileList.prototype.items = function()
-{
+FileList.prototype.items = function() {
this.resolve();
return this._items;
}
-FileList.prototype.size = function()
-{
+FileList.prototype.size = function() {
return this.items().length;
}
@@ -141,11 +136,9 @@ FileList.prototype.size = function()
// file_list.include("*.java", "*.cfg")
// file_list.include %w( math.c lib.h *.o )
//
-FileList.prototype.include = function(/*Strings | Arrays*/)
-{
+FileList.prototype.include = function(/*Strings | Arrays*/) {
// TODO: check for pending
- Array.prototype.forEach.apply(arguments, [function(/*String|Array|FileList*/ anObject)
- {
+ Array.prototype.forEach.apply(arguments, [function(/*String|Array|FileList*/ anObject) {
if (Array.isArray(anObject))
this.include.apply(this, anObject);
@@ -183,10 +176,8 @@ FileList.prototype.add = FileList.prototype.include;
// If "a.c" is not a file, then ...
// FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
//
-FileList.prototype.exclude = function(/*Strings|Functions*/)
-{
- Array.prototype.forEach.call(arguments, function(/*String|Function*/ anObject)
- {
+FileList.prototype.exclude = function(/*Strings|Functions*/) {
+ Array.prototype.forEach.call(arguments, function(/*String|Function*/ anObject) {
if (typeof anObject === "function")
this._excludedProcs.push(anObject);
@@ -201,8 +192,7 @@ FileList.prototype.exclude = function(/*Strings|Functions*/)
}
// Clear all the exclude patterns so that we exclude nothing.
-FileList.prototype.clearExclude = function()
-{
+FileList.prototype.clearExclude = function() {
this._excludedPatterns = [];
this._excludedProcs = [];
@@ -217,8 +207,7 @@ FileList.prototype.clearExclude = function()
*/
// Return the internal array object.
-FileList.prototype.toArray = function()
-{
+FileList.prototype.toArray = function() {
return this.items().slice();
}
/*
@@ -227,7 +216,7 @@ FileList.prototype.toArray = function()
klass == Array || super(klass)
end
alias kind_of? is_a?
-
+
# Redefine * to return either a string or a new file list.
def *(other)
result = @items * other
@@ -241,13 +230,10 @@ FileList.prototype.toArray = function()
*/
// Resolve all the pending adds now.
-FileList.prototype.resolve = function()
-{
- if (this._pending)
- {
+FileList.prototype.resolve = function() {
+ if (this._pending) {
this._pending = false;
- this._pendingAdd.forEach(function(aFilename)
- {
+ this._pendingAdd.forEach(function(aFilename) {
this._resolveAdd(aFilename);
}, this);
@@ -258,41 +244,34 @@ FileList.prototype.resolve = function()
return this;
}
-FileList.prototype._resolveAdd = function(aFilename)
-{
+FileList.prototype._resolveAdd = function(aFilename) {
if (aFilename.match(/[\*?\[\{]/))
this._addMatching(aFilename);
else
this._items.push(aFilename);
}
-FileList.prototype._resolveExclude = function()
-{
- this._items = this._items.filter(function(/*String*/ aFilename)
- {
+FileList.prototype._resolveExclude = function() {
+ this._items = this._items.filter(function(/*String*/ aFilename) {
return !this._shouldExclude(aFilename);
}, this);
return this;
}
-FileList.prototype._shouldExclude = function(aFilename)
-{
- return this._excludedPatterns.some(function(aPattern)
- {
+FileList.prototype._shouldExclude = function(aFilename) {
+ return this._excludedPatterns.some(function(aPattern) {
if (aPattern.constructor === RegExp && aPattern.test(aFilename))
return true;
- if (aPattern.match && aPattern.match(/[*?]/))
- {
+ if (aPattern.match && aPattern.match(/[*?]/)) {
return FILE.fnmatch(aPattern, aFilename);
}
if (aFilename === aPattern)
return true;
}) ||
- this._excludedProcs.some(function(aFunction)
- {
+ this._excludedProcs.some(function(aFunction) {
return aFunction.apply(this, [aFilename]);
}, this);
}
@@ -330,7 +309,7 @@ def gsub!(pat, rep)
each_with_index { |fn, i| self[i] = fn.gsub(pat,rep) }
self
end
-
+
# Apply the pathmap spec to each of the included file names, returning a
# new file list with the modified paths. (See String#pathmap for
# details.)
@@ -349,7 +328,7 @@ end
def ext(newext='')
collect { |fn| fn.ext(newext) }
end
-
+
# Grep each of the files in the filelist using the given pattern. If a
# block is given, call the block on each matching line, passing the file
# name, line number, and the matching line of text. If no block is given,
@@ -375,20 +354,16 @@ end
*/
// Return a new file list that only contains file names from the current
// file list that exist on the file system.
-FileList.prototype.existing = function(/*String*/ aFilename)
-{
- return (new FileList())._import(this.items().filter(function(aFilename)
- {
+FileList.prototype.existing = function(/*String*/ aFilename) {
+ return (new FileList())._import(this.items().filter(function(aFilename) {
return FILE.exists(aFilename);
}, this));
}
// Modify the current file list so that it contains only file name that
// exist on the file system.
-FileList.prototype.keepExisting = function()
-{
- this._items = this.filter(function(aFilename)
- {
+FileList.prototype.keepExisting = function() {
+ this._items = this.filter(function(aFilename) {
return FILE.exists(aFilename);
}, this);
@@ -407,14 +382,12 @@ FileList.prototype.keepExisting = function()
end
*/
// Convert a FileList to a string by joining all elements with a space.
-FileList.prototype.toString = function()
-{
+FileList.prototype.toString = function() {
return this.items().join(' ');
}
// Add matching glob patterns.
-FileList.prototype._addMatching = function(/*String*/ aPattern)
-{
+FileList.prototype._addMatching = function(/*String*/ aPattern) {
FILE.glob(aPattern).forEach(function(fileName){
this._items.push(fileName);
}, this);
@@ -440,8 +413,7 @@ FileList.prototype._addMatching = function(/*String*/ aPattern)
end
*/
-FileList.prototype._import = function(/*Array*/ anArray)
-{
+FileList.prototype._import = function(/*Array*/ anArray) {
this._items = anArray.slice();
return this;
}
@@ -451,7 +423,7 @@ exports.FileList = FileList;
/*
module Rake
class << self
-
+
# Yield each file or directory component.
def each_dir_parent(dir) # :nodoc:
old_length = nil
View
28 lib/jake/filetask.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env narwhal
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
@@ -22,16 +21,16 @@
// IN THE SOFTWARE.
//
-var FILE = require("file"),
- Jake = require("jake"),
- Task = require("jake/task").Task;
+var FILE = require("file");
+
+var JAKE = require("../jake");
+var Task = require("./task").Task;
// A FileTask is a task that includes time based dependencies. If any of a
// FileTask's prerequisites have a timestamp that is later than the file
// represented by this task, then the file must be rebuilt (using the
// supplied actions).
-var FileTask = function()
-{
+var FileTask = function() {
Task.apply(this, arguments);
}
@@ -40,35 +39,30 @@ FileTask.prototype.__proto__ = Task.prototype;
// Is this file task needed? Yes if it doesn't exist, or if its time stamp
// is out of date.
-FileTask.prototype.isNeeded = function()
-{
+FileTask.prototype.isNeeded = function() {
return !FILE.exists(this.name()) || this.outOfDate(this.timestamp());
}
// Time stamp for file task.
-FileTask.prototype.timestamp = function()
-{
+FileTask.prototype.timestamp = function() {
if (FILE.exists(this.name()))
return FILE.mtime(this.name());
- return Jake.EARLY;
+ return JAKE.EARLY;
}
// Are there any prerequisites with a later time than the given time stamp?
-FileTask.prototype.outOfDate = function(aTimestamp)
-{
+FileTask.prototype.outOfDate = function(aTimestamp) {
var application = this.application();
- return this._prerequisites.some(function(aTaskName)
- {
+ return this._prerequisites.some(function(aTaskName) {
return application.lookupTask(aTaskName).timestamp() > aTimestamp;
}, this);
}
// Apply the scope to the task name according to the rules for this kind
// of task. File based tasks ignore the scope when creating the name.
-FileTask.scopeName = function(/*Array<String>*/ aScope, /*String*/ aTaskName)
-{
+FileTask.scopeName = function(/*Array<String>*/ aScope, /*String*/ aTaskName) {
return aTaskName;
}
View
180 lib/jake/task.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env narwhal
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
@@ -22,11 +21,11 @@
// IN THE SOFTWARE.
//
-var SYSTEM = require("system"),
- jake = require("jake");
+var SYSTEM = require("system");
-var Task = function(/*String*/ aName, /*Application*/ anApplication)
-{
+var JAKE = require("../jake");
+
+var Task = function(/*String*/ aName, /*Application*/ anApplication) {
this._name = aName;
this._prerequisites = [];
this._actions = [];
@@ -39,73 +38,60 @@ var Task = function(/*String*/ aName, /*Application*/ anApplication)
this._argumentNames = [];
}
-Task.prototype.toString = function()
-{
+Task.prototype.toString = function() {
return "Task (" + this.name() + ")";
}
-Task.prototype.name = function()
-{
+Task.prototype.name = function() {
return this._name;
}
-Task.prototype.fullComment = function()
-{
+Task.prototype.fullComment = function() {
return this._fullComment || "";
}
-Task.prototype.comment = function()
-{
+Task.prototype.comment = function() {
return this._comment || "";
}
-Task.prototype.prerequisites = function()
-{
+Task.prototype.prerequisites = function() {
return this._prerequisites;
}
-Task.prototype.actions = function()
-{
+Task.prototype.actions = function() {
return this._actions;
}
-Task.prototype.application = function()
-{
+Task.prototype.application = function() {
return this._application;
}
-Task.prototype.enhance = function(/*Array|FileList*/ prerequisites, /*Function*/ anAction)
-{
+Task.prototype.enhance = function(/*Array|FileList*/ prerequisites, /*Function*/ anAction) {
if (prerequisites)
this._prerequisites = this._prerequisites.concat(prerequisites.toArray ? prerequisites.toArray() : prerequisites);
-
+
if (anAction)
this._actions.push(anAction);
}
-Task.prototype.reenable = function()
-{
+Task.prototype.reenable = function() {
this._alreadyInvoked = false;
}
-Task.prototype.clear = function()
-{
+Task.prototype.clear = function() {
this.clearPrerequisites();
this.clearActions();
}
-Task.prototype.clearPrerequisites = function()
-{
+Task.prototype.clearPrerequisites = function() {
this._prerequisites = [];
}
-Task.prototype.clearActions = function()
-{
+Task.prototype.clearActions = function() {
this._actions = [];
}
-Task.prototype.invoke = function()
-{
+Task.prototype.invoke = function() {
var taskArguments = new TaskArguments(this._argumentNames, Array.prototype.slice.apply(arguments));
this.invokeWithCallChain(taskArguments, InvocationChain.EMPTY);
@@ -113,8 +99,7 @@ Task.prototype.invoke = function()
// Same as invoke, but explicitly pass a call chain to detect
// circular dependencies.
-Task.prototype.invokeWithCallChain = function(taskArguments, anInvocationChain)
-{
+Task.prototype.invokeWithCallChain = function(taskArguments, anInvocationChain) {
var newChain = InvocationChain.append(this, anInvocationChain);
// @lock.synchronize do
// if application.options.trace
@@ -127,16 +112,14 @@ Task.prototype.invokeWithCallChain = function(taskArguments, anInvocationChain)
this._alreadyInvoked = true;
this.invokePrerequisites(taskArguments, newChain);
-
+
if (this.isNeeded())
this.execute(taskArguments);
}
// Invoke all the prerequisites of a task.
-Task.prototype.invokePrerequisites = function(taskArguments, invocationChain)
-{
- this._prerequisites.forEach(function(/*String*/ aPrerequisiteName)
- {
+Task.prototype.invokePrerequisites = function(taskArguments, invocationChain) {
+ this._prerequisites.forEach(function(/*String*/ aPrerequisiteName) {
var prerequisite = this._application.lookupTask(aPrerequisiteName, this._scope);
prerequisiteArguments = taskArguments.newScope(prerequisite.argumentNames());
@@ -144,21 +127,18 @@ Task.prototype.invokePrerequisites = function(taskArguments, invocationChain)
}, this);
}
-Task.prototype.setArgumentNames = function(argumentNames)
-{
+Task.prototype.setArgumentNames = function(argumentNames) {
this._argumentNames = argumentNames;
}
-Task.prototype.argumentNames = function()
-{
+Task.prototype.argumentNames = function() {
return this._argumentNames;
}
// Execute the actions associated with this task.
-Task.prototype.execute = function(taskArguments)
-{
+Task.prototype.execute = function(taskArguments) {
taskArguments = taskArguments || EMPTY_TASK_ARGS;
-
+
// if application.options.dryrun
// puts "** Execute (dry run) #{name}"
// return
@@ -169,65 +149,54 @@ Task.prototype.execute = function(taskArguments)
// application.enhance_with_matching_rule(name) if @actions.empty?
- this._actions.forEach(function(anAction)
- {
+ this._actions.forEach(function(anAction) {
anAction(this);
//anAction(This, args)
}, this);
}
-Task.prototype.isNeeded = function()
-{
+Task.prototype.isNeeded = function() {
return true;
}
-Task.prototype.timestamp = function()
-{
+Task.prototype.timestamp = function() {
if (this._prerequisites.length <= 0)
return new Date().getTime();
- return Math.max.apply(null, this._prerequisites.map(function(/*String*/ aPrerequisiteName)
- {
+ return Math.max.apply(null, this._prerequisites.map(function(/*String*/ aPrerequisiteName) {
return this._application.lookupTask(aPrerequisiteName, this._scope).timestamp();
}, this));
}
-Task.clear = function()
-{
- Jake.application.clear();
+Task.clear = function() {
+ JAKE.application.clear();
}
-Task.tasks = function()
-{
- return Jake.application.tasks();
+Task.tasks = function() {
+ return JAKE.application.tasks();
}
-Task.taskNamed = function(/*String*/ aTaskName)
-{
- return Jake.application.taskWithName(aTaskName);
+Task.taskNamed = function(/*String*/ aTaskName) {
+ return JAKE.application.taskWithName(aTaskName);
}
-Task.taskWithNameIsDefined = function(/*String*/ aTaskName)
-{
- return !!Jake.application.lookupTaskWithName(aTaskName);
+Task.taskWithNameIsDefined = function(/*String*/ aTaskName) {
+ return !!JAKE.application.lookupTaskWithName(aTaskName);
}
-Task.defineTask = function()
-{
+Task.defineTask = function() {
var args = [this];
- application = jake.application();
-
+ var application = JAKE.application();
+
// Can't simply use concat because we don't want to flatten inner arrays.
- Array.prototype.forEach.call(arguments, function(object)
- {
+ Array.prototype.forEach.call(arguments, function(object) {
args.push(object);
});
- return application.defineTask.apply(application, args);
+ return application.defineTask.apply(application, args);
}
-Task.scopeName = function(/*Array<String>*/ aScope, /*String*/ aTaskName)
-{
+Task.scopeName = function(/*Array<String>*/ aScope, /*String*/ aTaskName) {
return aScope.concat(aTaskName).join(':');
}
/*
@@ -236,31 +205,26 @@ Task.scopeName = function(/*Array<String>*/ aScope, /*String*/ aTaskName)
alias :last_comment :last_description # Backwards compatibility
*/
-var TaskArguments = function(/*Array<String>*/ names, /*Array<Object>*/ values, /*TaskArguments*/ aParent)
-{
+var TaskArguments = function(/*Array<String>*/ names, /*Array<Object>*/ values, /*TaskArguments*/ aParent) {
this._names = names.slice();
this._parent = aParent;
this._hash = { };
-
- this._names.forEach(function(/*String*/ aName, /*Number*/ anIndex)
- {
+
+ this._names.forEach(function(/*String*/ aName, /*Number*/ anIndex) {
if (values[anIndex] !== undefined)
this._hash[aName] = values[anIndex];
}, this);
}
-TaskArguments.prototype.newScope = function(/*Array<String>*/ names)
-{
- var values = names.map(function(/*String*/ aName)
- {
+TaskArguments.prototype.newScope = function(/*Array<String>*/ names) {
+ var values = names.map(function(/*String*/ aName) {
return this.lookup(aName);
}, this);
return new TaskArguments(names, values, this);
}
-TaskArguments.prototype.withDefaults = function(/*Object*/ defaults)
-{
+TaskArguments.prototype.withDefaults = function(/*Object*/ defaults) {
var hash = this._hash;
for (key in defaults)
@@ -268,8 +232,7 @@ TaskArguments.prototype.withDefaults = function(/*Object*/ defaults)
hash[key] = defaults[key];
}
-TaskArguments.prototype.forEach = function(/*Function*/ aFunction, /*Object*/ thisObject)
-{
+TaskArguments.prototype.forEach = function(/*Function*/ aFunction, /*Object*/ thisObject) {
if (!aFunction)
return;
@@ -282,18 +245,15 @@ TaskArguments.prototype.forEach = function(/*Function*/ aFunction, /*Object*/ th
aFunction.apply(thisObject, [key, hash[key]]);
}
-TaskArguments.prototype.toHash = function()
-{
+TaskArguments.prototype.toHash = function() {
return this._hash;
}
-TaskArguments.prototype.toString = function()
-{
+TaskArguments.prototype.toString = function() {
return this._hash;
}
-TaskArguments.prototype.lookup = function(/*String*/ aName)
-{
+TaskArguments.prototype.lookup = function(/*String*/ aName) {
var hash = this._hash;
if (hash.hasOwnProperty(aName))
@@ -317,56 +277,46 @@ TaskArguments.prototype.lookup = function(/*String*/ aName)
var EMPTY_TASK_ARGS = new TaskArguments([], []);
-var InvocationChain = function(aValue, /*InvocationChain*/ aTail)
-{
+var InvocationChain = function(aValue, /*InvocationChain*/ aTail) {
this._value = aValue;
this._tail = aTail;
}
-InvocationChain.prototype.isMember = function(/*Object*/ anObject)
-{
+InvocationChain.prototype.isMember = function(/*Object*/ anObject) {
return this._value == anObject || this._tail.isMember(anObject);
}
-InvocationChain.prototype.append = function(/*Object*/ anObject)
-{
+InvocationChain.prototype.append = function(/*Object*/ anObject) {
if (this.isMember(anObject))
throw "Circular dependency detected: " + this + " => " + this._value;
-
+
return new InvocationChain(this._value, this);
}
-InvocationChain.prototype.toString = function()
-{
+InvocationChain.prototype.toString = function() {
return this.prefix() + this._value;
}
-InvocationChain.append = function(aValue, /*InvocationChain*/ aChain)
-{
+InvocationChain.append = function(aValue, /*InvocationChain*/ aChain) {
return aChain.append(aValue);
}
-InvocationChain.prototype.prefix = function()
-{
+InvocationChain.prototype.prefix = function() {
return this._tail + " => ";
}
-var EmptyInvocationChain = function()
-{
+var EmptyInvocationChain = function() {
}
-EmptyInvocationChain.prototype.isMember = function(/*Object*/ anObject)
-{
+EmptyInvocationChain.prototype.isMember = function(/*Object*/ anObject) {
return false;
}
-EmptyInvocationChain.prototype.append = function(/*Object*/ aValue)
-{
+EmptyInvocationChain.prototype.append = function(/*Object*/ aValue) {
return new InvocationChain(aValue, this);
}
-EmptyInvocationChain.prototype.toString = function()
-{
+EmptyInvocationChain.prototype.toString = function() {
return "TOP";
}
View
69 lib/jake/taskmanager.js
@@ -1,4 +1,3 @@
-#!/usr/bin/env narwhal
// Copyright 2009 280 North, Inc. (francisco@280north.com)
// Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Jim Weirich (jim.weirich@gmail.com)
@@ -22,11 +21,11 @@
// IN THE SOFTWARE.
//
-var FILE = require("file"),
- FileTask = require("jake/filetask").FileTask;
+var FILE = require("file");
-TaskManager = function()
-{
+var FileTask = require("./filetask").FileTask;
+
+TaskManager = function() {
this._tasks = { };
this._rules = [];
this._scope = [];
@@ -40,8 +39,7 @@ TaskManager = function()
end
*/
-TaskManager.prototype.defineTask = function(aTaskClass, aTaskName)
-{
+TaskManager.prototype.defineTask = function(aTaskClass, aTaskName) {
if (arguments.length < 1)
throw "No class passed to Task.defineTask";
@@ -50,8 +48,8 @@ TaskManager.prototype.defineTask = function(aTaskClass, aTaskName)
aTaskName = aTaskClass.scopeName(this._scope, aTaskName);
- var task = this.intern(aTaskClass, aTaskName),
- result = this.resolveArguments(Array.prototype.slice.apply(arguments, [2]));
+ var task = this.intern(aTaskClass, aTaskName);
+ var result = this.resolveArguments(Array.prototype.slice.apply(arguments, [2]));
task.setArgumentNames(result[0]);
//task.add_description(@last_description)
@@ -63,12 +61,10 @@ TaskManager.prototype.defineTask = function(aTaskClass, aTaskName)
// Lookup a task. Return an existing task if found, otherwise
// create a task of the current type.
-TaskManager.prototype.intern = function(/*Function*/ aTaskClass, /*String*/ aTaskName)
-{
+TaskManager.prototype.intern = function(/*Function*/ aTaskClass, /*String*/ aTaskName) {
var task = this._tasks[aTaskName];
- if (!task)
- {
+ if (!task) {
task = new aTaskClass(aTaskName, this);
this._tasks[aTaskName] = task;
}
@@ -76,8 +72,7 @@ TaskManager.prototype.intern = function(/*Function*/ aTaskClass, /*String*/ aTas
return task;
}
-TaskManager.prototype.lookupTask = function(/*String*/ aTaskName, /*Array<String>*/ scopes)
-{
+TaskManager.prototype.lookupTask = function(/*String*/ aTaskName, /*Array<String>*/ scopes) {
var task = this.lookup(aTaskName, scopes) || /* enhance_with_matching_rule(task_name) or ||*/ this.synthesizeFileTask(aTaskName);
if (!task)
@@ -86,8 +81,7 @@ TaskManager.prototype.lookupTask = function(/*String*/ aTaskName, /*Array<String
return task;
}
-TaskManager.prototype.synthesizeFileTask = function(/*String*/ aTaskName)
-{
+TaskManager.prototype.synthesizeFileTask = function(/*String*/ aTaskName) {
if (!FILE.exists(aTaskName))
return null;
@@ -104,8 +98,7 @@ TaskManager.prototype.synthesizeFileTask = function(/*String*/ aTaskName)
// task(taskName, [dependency], action)
// task(taskName, [argumentName], [dependency], action)
//
-TaskManager.prototype.resolveArguments = function(args)
-{
+TaskManager.prototype.resolveArguments = function(args) {
var action = null;
if (args.length && (typeof args[args.length - 1] === "function"))
@@ -124,8 +117,7 @@ TaskManager.prototype.resolveArguments = function(args)
return [argumentNames, dependencies, action];
}
-TaskManager.prototype.tasks = function()
-{
+TaskManager.prototype.tasks = function() {
return Object.keys(this._tasks).sort().map(function(name) {
return this._tasks[name];
}, this);
@@ -133,20 +125,17 @@ TaskManager.prototype.tasks = function()
// List of all the tasks defined in the given scope (and its
// sub-scopes).
-TaskManager.prototype.tasksInScope = function(/*Array<String>*/ aScope)
-{
- var prefix = aScope.join(":"),
- regexp = new Regexp("^" + prefix + ":");
+TaskManager.prototype.tasksInScope = function(/*Array<String>*/ aScope) {
+ var prefix = aScope.join(":");
+ var regexp = new Regexp("^" + prefix + ":");
- return this._tasks.filter(function(/*Task*/ aTask)
- {
+ return this._tasks.filter(function(/*Task*/ aTask) {
return !!aTask.name().match(regexp);
});
}
// Clear all tasks in this application.
-TaskManager.prototype.clear = function()
-{
+TaskManager.prototype.clear = function() {
this._tasks = [];
this._rules = [];
}
@@ -156,21 +145,18 @@ TaskManager.prototype.clear = function()
// synthesize file tasks or rules. Special scope names (e.g. '^')
// are recognized. If no scope argument is supplied, use the
// current scope. Return nil if the task cannot be found.
-TaskManager.prototype.lookup = function(/*String*/ aTaskName, /*Array<String>*/ initialScope)
-{
+TaskManager.prototype.lookup = function(/*String*/ aTaskName, /*Array<String>*/ initialScope) {
if (!initialScope)
initialScope = this._scope;
- var scopes = initialScope,
- matches = null;
+ var scopes = initialScope;
+ var matches = null;
- if (aTaskName.match(/^jake:/))
- {
+ if (aTaskName.match(/^jake:/)) {
scopes = [];
aTaskName = aTaskName.replace(/^jake:/, "");
}
- else if (matches = aTaskName.match(/^(\^+)/))
- {
+ else if (matches = aTaskName.match(/^(\^+)/)) {
scopes = initialScope.slice(0, initialScope.length - matches[1].length);
aTaskName = aTaskName.replace(/^(\^+)/, "");
}
@@ -179,12 +165,10 @@ TaskManager.prototype.lookup = function(/*String*/ aTaskName, /*Array<String>*/
}
// Lookup the task name
-TaskManager.prototype.lookupInScope = function(/*String*/ aTaskName, /*Array<String>*/ aScope)
-{
+TaskManager.prototype.lookupInScope = function(/*String*/ aTaskName, /*Array<String>*/ aScope) {
var count = aScope.length;
- while (count >= 0)
- {
+ while (count >= 0) {
var task = this._tasks[aScope.slice(0, count).concat([aTaskName]).join(':')];
if (task)
@@ -198,8 +182,7 @@ TaskManager.prototype.lookupInScope = function(/*String*/ aTaskName, /*Array<Str
// Return the list of scope names currently active in the task
// manager.
-TaskManager.prototype.currentScope = function()
-{
+TaskManager.prototype.currentScope = function() {
return this._scope.slice();
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.