Class: Juicer::Install::ClosureCompilerInstaller

Inherits:
Base
  • Object
show all
Defined in:
lib/juicer/install/closure_compiler_installer.rb

Overview

Install and uninstall routines for the Google Closure Compiler. Installation downloads the Closure Compiler distribution, unzips it and storesthe jar file on disk along with the README.

Instance Attribute Summary

Attributes inherited from Base

#install_dir

Instance Method Summary collapse

Methods inherited from Base

#bin_path, #dependencies, #dependency, #download, #installed?, #log, #name, #path

Constructor Details

#initialize(install_dir = Juicer.home) ⇒ ClosureCompilerInstaller

Returns a new instance of ClosureCompilerInstaller.



13
14
15
16
17
18
# File 'lib/juicer/install/closure_compiler_installer.rb', line 13

def initialize(install_dir = Juicer.home)
  super(install_dir)
  @latest = nil
  @website = "http://code.google.com/p/closure-compiler/downloads/list"
  @download_link = "http://closure-compiler.googlecode.com/files/compiler-%s.zip"
end

Instance Method Details

#install(version = nil) ⇒ Object

Install the Closure Compiler. Downloads the distribution and keeps the jar file inside PATH/closure_compiler/bin and the README in PATH/closere_compiler/yyyymmdd/ where yyyymmdd is the version, most recent if not specified otherwise.

Path defaults to environment variable $JUICER_HOME or default Juicer home



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/juicer/install/closure_compiler_installer.rb', line 29

def install(version = nil)
  version = super(version)
  base = "closure-compiler-#{version}"
  filename = download(@download_link % version)
  target = File.join(@install_dir, path)

  Zip::ZipFile.open(filename) do |file|
    file.extract("README", File.join(target, version, "README"))
    file.extract("compiler.jar", File.join(target, "bin", "#{base}.jar"))
  end
end

#latestObject

Check which version is the most recent



60
61
62
63
64
65
66
# File 'lib/juicer/install/closure_compiler_installer.rb', line 60

def latest
  return @latest if @latest
  webpage = Nokogiri::HTML(open(@website))
  @latest = (webpage / "//table[@id='resultstable']//td/a[contains(@href, 'compiler')]").map{|link|
    link.get_attribute('href')[/\d{8}/].to_i
  }.sort.last.to_s
end

#uninstall(version = nil) ⇒ Object

Uninstalls the given version of Closure Compiler. If no location is provided the environment variable $JUICER_HOME or Juicers default home directory is used.

If no version is provided the most recent version is assumed.

If there are no more files left in INSTALLATION_PATH/closure_compiler, the whole directory is removed.



51
52
53
54
55
# File 'lib/juicer/install/closure_compiler_installer.rb', line 51

def uninstall(version = nil)
  super(version) do |dir, version|
    File.delete(File.join(dir, "bin/closure-compiler-#{version}.jar"))
  end
end