lib/TaskJuggler.rb in taskjuggler-0.0.3 vs lib/TaskJuggler.rb in taskjuggler-0.0.4
- old
+ new
@@ -1,19 +1,21 @@
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = TaskJuggler.rb -- The TaskJuggler III Project Management Software
#
-# Copyright (c) 2006, 2007, 2008, 2009 by Chris Schlaeger <cs@kde.org>
+# Copyright (c) 2006, 2007, 2008, 2009, 2010 by Chris Schlaeger <cs@kde.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
+require 'drb'
require 'Project'
require 'MessageHandler'
+require 'RemoteServiceManager'
require 'Log'
# The TaskJuggler class models the object that provides access to the
# fundamental features of the TaskJuggler software. It can read project
# files, schedule them and generate the reports.
@@ -24,40 +26,45 @@
# Create a new TaskJuggler object. _console_ is a boolean that determines
# whether or not messsages can be written to $stderr.
def initialize(console)
@project = nil
+ @parser = nil
@messageHandler = MessageHandler.new(console)
@maxCpuCores = 1
end
# Read in the files passed as file names in _files_, parse them and
# construct a Project object. In case of success true is returned.
# Otherwise false.
- def parse(files)
+ def parse(files, keepParser = false)
Log.enter('parser', 'Parsing files ...')
master = true
@project = nil
- parser = ProjectFileParser.new(@messageHandler)
+ @parser = ProjectFileParser.new(@messageHandler)
files.each do |file|
begin
- parser.open(file, master)
+ @parser.open(file, master)
rescue TjException
Log.exit('parser')
return false
end
if master
- @project = parser.parse('project')
+ @project = @parser.parse('project')
master = false
else
- parser.setGlobalMacros
- parser.parse('properties')
+ @parser.setGlobalMacros
+ @parser.parse('properties')
end
- parser.close
+ @parser.close
end
+ # For the report server mode we may need to keep the parser. Otherwise,
+ # destroy it.
+ @parser = nil unless keepParser
+
Log.exit('parser')
@messageHandler.messages.empty?
end
# Schedule all scenarios in the project. Return true if no error was
@@ -77,9 +84,25 @@
@project.outputDir = outputDir
Log.enter('reports', 'Generating reports ...')
res = @project.generateReports(@maxCpuCores)
Log.exit('reports')
res
+ end
+
+ def serveReports
+ $SAFE = 1
+ Log.enter('reportserver', 'Starting Server Mode ...')
+ Log.status("Report Server is now active!")
+ serviceManager = RemoteServiceManager.new(@parser, @project)
+ DRb.start_service('druby://localhost:8474', serviceManager)
+ DRb.thread.join
+ # We'll probably never get here. The DRb threads may call exit().
+ Log.exit('reportserver')
+ end
+
+ # Return the number of errors that had been reported during processing.
+ def errors
+ @project.messageHandler.errors
end
end