lib/reports/Report.rb in taskjuggler-0.0.6 vs lib/reports/Report.rb in taskjuggler-0.0.7
- old
+ new
@@ -45,65 +45,57 @@
# The generate function is where the action happens in this class. The
# report defined by all the class attributes and report elements is
# generated according the the requested output format(s).
def generate
- begin
- generateIntermediateFormat
+ generateIntermediateFormat
- # Then generate the actual output format.
- get('formats').each do |format|
- case format
- when :html
- generateHTML
- copyAuxiliaryFiles
- when :csv
- generateCSV
- when :niku
- generateNiku
- when :tjp
- generateTJP
- else
- raise 'Unknown report output format #{format}.'
- end
+ # Then generate the actual output format.
+ get('formats').each do |format|
+ case format
+ when :html
+ generateHTML
+ copyAuxiliaryFiles
+ when :csv
+ generateCSV
+ when :niku
+ generateNiku
+ when :tjp
+ generateTJP
+ else
+ raise 'Unknown report output format #{format}.'
end
- rescue TjException
- error('reporting_failed', $!.message)
end
- 0
+ true
end
# Generate an output format agnostic version that can later be turned into
# the respective output formats.
def generateIntermediateFormat
- begin
- @content = nil
- case @typeSpec
- when :export
- @content = TjpExportRE.new(self)
- when :niku
- @content = NikuReport.new(self)
- when :resourcereport
- @content = ResourceListRE.new(self)
- when :textreport
- @content = TextReport.new(self)
- when :taskreport
- @content = TaskListRE.new(self)
- when :statusSheet
- @content = StatusSheetReport.new(self)
- when :timeSheet
- @content = TimeSheetReport.new(self)
- else
- raise "Unknown report type"
- end
-
- # Most output format can be generated from a common intermediate
- # representation of the elements. We generate that IR first.
- @content.generateIntermediateFormat if @content
- rescue TjException
- error('report_IR_generattion_failed', $!.message)
+ @content = nil
+ case @typeSpec
+ when :export
+ @content = TjpExportRE.new(self)
+ when :niku
+ @content = NikuReport.new(self)
+ when :resourcereport
+ @content = ResourceListRE.new(self)
+ when :textreport
+ @content = TextReport.new(self)
+ when :taskreport
+ @content = TaskListRE.new(self)
+ when :statusSheet
+ @content = StatusSheetReport.new(self)
+ when :timeSheet
+ @content = TimeSheetReport.new(self)
+ else
+ raise "Unknown report type"
end
+
+ # Most output format can be generated from a common intermediate
+ # representation of the elements. We generate that IR first.
+ @content.generateIntermediateFormat if @content
end
# Render the content of the report as HTML (without the framing).
def to_html
@content ? @content.to_html : nil
@@ -114,10 +106,26 @@
# interactive setting.
def interactive?
@project.reportContexts.first.report.get('interactive')
end
+ def error(id, message)
+ if message && !message.empty?
+ @project.messageHandler.error(id, message, @sourceFileInfo)
+ else
+ # We have no message, so the error has already been reported to the
+ # MessageHandler. Just trigger another exception to signal the error.
+ raise TjException
+ end
+ end
+
+ def warning(id, message)
+ if message && !message.empty?
+ @project.messageHandler.warning(id, message, @sourceFileInfo)
+ end
+ end
+
private
# Convenience function to access a report attribute
def a(attribute)
get(attribute)
end
@@ -202,11 +210,12 @@
# Generate a CSV version of the report.
def generateCSV
return nil unless @content
# CSV format can only handle the first element.
- csv = @content.to_csv
+ return nil unless (csv = @content.to_csv)
+
# Expand nested tables into the outer table.
columnIdx = 0
while columnIdx < csv[0].length do
if csv[0][columnIdx].is_a?(Array)
# We've found a nested table.
@@ -284,14 +293,14 @@
copyDirectory('scripts')
end
def copyDirectory(dirName)
# The directory needs to be in the same directory as the HTML report.
- auxDstDir = File.dirname((@name[0] == '/' ? '' : @project.outputDir) +
- @name) + '/'
+ auxDstDir = (File.dirname((@name[0] == '/' ? '' : @project.outputDir) +
+ @name) + '/').untaint
# Find the data directory that came with the TaskJuggler installation.
- auxSrcDir = AppConfig.dataDirs("data/#{dirName}")[0]
+ auxSrcDir = AppConfig.dataDirs("data/#{dirName}")[0].untaint
# Raise an error if we haven't found the data directory
dataDirError(dirName) if auxSrcDir.nil? || !File.exists?(auxSrcDir)
# Don't copy directory if all files are up-to-date.
return if directoryUpToDate?(auxSrcDir, auxDstDir + dirName)
@@ -312,21 +321,17 @@
end
true
end
def dataDirError(dirName)
- raise TjException.new, <<"EOT"
+ error('data_dir_error', <<"EOT"
Cannot find the #{dirName} directory. This is usually the result of an
improper TaskJuggler installation. If you know the directory, you can use the
TASKJUGGLER_DATA_PATH environment variable to specify the location. The
variable should be set to the path without the /data at the end. Multiple
directories must be separated by colons.
EOT
- end
-
- def error(id, message)
- @project.messageHandler.send(Message.new(id, 'error', message, nil, nil,
- @sourceFileInfo))
+ )
end
end
end