Class: Rake::RemotePackage
- Inherits:
-
Task
- Object
- Task
- Rake::RemotePackage
show all
- Includes:
- DSL
- Defined in:
- lib/rake-plus/remote_package.rb
Constant Summary
collapse
- GITHUB_MATCH =
%r[^https?://github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.*)]
- SF_MATCH =
%r[^https?://sourceforge.net/.*/([^/]+)/download$]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Task
#file_missing?, #out_of_date?
Class Method Details
.scope_name(scope, task_name) ⇒ Object
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.
65
66
67
|
# File 'lib/rake-plus/remote_package.rb', line 65
def scope_name(scope, task_name)
task_name
end
|
Instance Method Details
#basename ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/rake-plus/remote_package.rb', line 17
def basename
if name =~ GITHUB_MATCH
"#{$1}-#{$2}-#{$4}#{$3 == "zip" ? ".zip" : ".tar.gz"}"
elsif name =~ SF_MATCH
$1
else
File.basename(name.sub(/\?.*/,''))
end
end
|
#execute(args = nil) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/rake-plus/remote_package.rb', line 27
def execute(args=nil)
if needed?
FileUtils.mkdir_p File.dirname(local_path)
sh "curl -L -o \"#{local_path}.tmp\" \"#{name}\""
mv "#{local_path}.tmp", local_path
end
super
end
|
#local_path ⇒ Object
13
14
15
|
# File 'lib/rake-plus/remote_package.rb', line 13
def local_path
RakePlus.cache_dir / "pkg" / basename
end
|
#needed? ⇒ Boolean
9
10
11
|
# File 'lib/rake-plus/remote_package.rb', line 9
def needed?
:package_missing unless File.exist?(local_path)
end
|
#timestamp ⇒ Object
Time stamp for file task.
54
55
56
57
58
59
60
|
# File 'lib/rake-plus/remote_package.rb', line 54
def timestamp
if File.exist?(local_path)
File.mtime(local_path)
else
Rake::EARLY
end
end
|
#unpack_to(dir) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/rake-plus/remote_package.rb', line 37
def unpack_to(dir)
abs_local_path = local_path.expand
Dir.chdir(dir) do
case abs_local_path
when /\.tar\.gz$/, /\.tgz$/
sh "tar xzvf \"#{abs_local_path}\""
when /\.tar\.bz2$/
sh "tar xjvf \"#{abs_local_path}\""
when /\.tar$/
sh "tar xvf \"#{abs_local_path}\""
else
raise "Unsupported file extensions of #{abs_local_path}"
end
end
end
|