Class: Disloku::Tasks::FolderTask

Inherits:
BaseTask
  • Object
show all
Defined in:
lib/disloku/tasks/FolderTask.rb

Instance Attribute Summary

Attributes inherited from BaseTask

#changesets

Instance Method Summary collapse

Methods inherited from BaseTask

#execute, #getInputParam

Constructor Details

#initialize(input) ⇒ FolderTask

Returns a new instance of FolderTask.



12
13
14
15
16
17
18
19
20
# File 'lib/disloku/tasks/FolderTask.rb', line 12

def initialize(input)
	super()
	@options = getInputParam(input, :options, Config::Options)
	@changesets = getInputParam(input, :changesets, Array)
	@target = getInputParam(input, :target, Config::Target)
	@deletes = StringIO.new()

	@targetDirectory = File.join(@options.packageDir, @target.name)
end

Instance Method Details

#addDelete(fullPath) ⇒ Object



74
75
76
# File 'lib/disloku/tasks/FolderTask.rb', line 74

def addDelete(fullPath)
	@deletes << "#{fullPath}\n"
end

#afterExecuteObject



68
69
70
71
72
# File 'lib/disloku/tasks/FolderTask.rb', line 68

def afterExecute()
	if (@options.createDeletesFile)
		File.write(File.join(@targetDirectory, ".deletes"), @deletes.string)
	end
end

#beforeExecuteObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/disloku/tasks/FolderTask.rb', line 22

def beforeExecute()
	if (!Dir.exists?(@targetDirectory))
		FileUtils.mkpath(@targetDirectory)
	elsif (Dir.exists?(@targetDirectory) and !@options.allowOverride)
		raise Exception.new("Directory '#{@targetDirectory}' already exists")
	elsif (Dir.exists?(@targetDirectory))
		FileUtils.rm_r(@targetDirectory, :force => true)
		Dir::mkdir(@targetDirectory)
	end

	@result[:directory] = @targetDirectory
	@result[:files] = []
end

#executeOnFileChange(change) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/disloku/tasks/FolderTask.rb', line 42

def executeOnFileChange(change)
	file = change.getFile(@target)
	if (!file.hasMapping?())
		return
	end

	destination = file.getAbsoluteDstPath(@targetDirectory)

	case change.changeType
		when :modified, :added
			Log.instance.info("adding file #{file.srcPath}")
			if (!Dir.exists?(File.dirname(destination)))
				FileUtils.mkpath(File.dirname(destination))
			end
			FileUtils.cp(file.srcPath, destination)
		when :deleted
			Log.instance.info("adding file #{file.srcPath} to deletion list")
			addDelete(file.getAbsoluteDstPath())
		else
			Log.instance.warn("ignoring change type #{change.changeType}")
			return
	end

	@result[:files].push(file)
end

#executeTaskObject



36
37
38
39
40
# File 'lib/disloku/tasks/FolderTask.rb', line 36

def executeTask()
	@changesets.each() do |changeset|
		changeset.each(&method(:executeOnFileChange))
	end
end