Jump to content

How to Download and Install Closure's Suite of Tools

+ 2
  chco's Photo
Posted Sep 16 2010 08:10 PM

The following excerpt is from Closure: The Definitive Guide. Below the author explains each tool in the Closure suite as well as how to install them.
Currently, each tool in the Closure suite must be downloaded and installed separately. As the tools are independent of one another, each is maintained as its own project on code.google.com. Most projects include a “Featured downloads” section where the tool and its documentation can be downloaded as some sort of zip file. Unfortunately, the Closure Library does not offer such a bundle, so the only way to get the code is to check it out of the Subversion repository associated with the project.

Tip: Because all of the Closure Tools are designed to be used independently, it takes a bit of effort to get them set up and working together. Using plovr eliminates the need for many of the scripts required to build the example in the following section, as well as the dependency on Python. Once you have gone through the example and understand the fundamentals of how building in Closure works, it is worth visiting the plovr website to see how the equivalent could be done using plovr.

At the time of this writing, the tools also lack version numbers (with the exception of the Closure Inspector). Because each is stored in Subversion, they do have revision numbers, but those are simply incremented every time a change is checked in. This is less significant than a version number, which is an explicit branding that generally reflects achieving a particular milestone or achieving some level of stability. Fortunately, each project has a number of tests to prevent regressions in new releases. Therefore, although all of the examples in this post were created using the Closure Tools built from the revision numbers listed in the table below, it is probably safe to use the latest version of each tool to reproduce the results in the examples.

Revision numbers for Closure Tools used to produce the examples in this post. Each is the latest version as of July 4, 2010. Clearly, some of the tools are updated more frequently than others.
ToolRevision numberDate revision was checked in
Closure Library155June 25, 2010
Closure Templates15April 26, 2010
Closure Compiler264July 3, 2010
Closure Inspector5April 8, 2010


This section will walk through downloading and configuring each tool, whereas the next section will provide a comprehensive code example that will demonstrate how each is used. If you are a Mac or Linux user, this section expects that you are familiar with the Terminal and have Subversion installed. Mac users should have Subversion installed by default, but Linux users may have to run sudo apt-get install svn to get it (apt-get is used to install packages on Ubuntu and Debian, so the package management system of your Linux distribution may differ). In either case, running which svn in the Terminal will print the location of the Subversion executable if it is installed.

If you are a Windows user, you will need to install Subversion if you have not done so already. The most popular Subversion client for Windows is TortoiseSVN, and it is freely available at http://tortoisesvn.tigris.org. Unlike the command-line versions for Mac and Linux, TortoiseSVN is an extension to Windows Explorer. This means that it can be used on Windows without using the Command Prompt.

Warning: Many of the examples include commands that can be run from a terminal on Mac or Linux. Running the equivalent script from the Windows command prompt is often a simple matter of replacing the line continuation character for a bash script (which is a backslash: \) with the line continuation character for a Windows batch script (which is a caret: ^). Alternatively, you can install Cygwin (http://www.cygwin.com), which provides a Linux-like terminal on Windows. When using Cygwin, the shell scripts in this book that are designed for Mac and Linux can be run as-is.

These instructions assume that each project will be downloaded in its own directory under a common directory, such as C:\closure\ on Windows or ~/closure/ on Mac and Linux. For simplicity, each directory name will match the project name on code.google.com, so the Closure Library will be downloaded into C:\closure\closure-library\.

Closure Library and Closure Testing Framework

As mentioned at the beginning of this section, the Closure Library cannot be downloaded as a zip file, so it must be downloaded by checking the code out of Subversion. The location of the repository is http://closure-libra....com/svn/trunk/, so that is the value to use for “URL of repository” when using TortoiseSVN on Windows, as shown in Figure 1-2.

Figure 1-2. Using TortoiseSVN to check out the Closure Library on Windows.

Attached Image


Mac and Linux users can run the following commands from Terminal to download the Closure Library:

mkdir ~/closure
cd ~/closure
svn checkout http://closure-library.googlecode.com/svn/trunk/ closure-library


The Closure Library also contains the Closure Testing Framework. Open the URI file:///C:/closure/closure-library/all_tests.html in a web browser and press the “Start” button to kick off the test suite. At the time of this writing, not all of the tests pass, so do not be worried that you downloaded a “bad” version of the Library if you see several test failures. The status of each failure is tracked as an issue on http://code.google.c...ary/issues/list.

Closure Templates

The primary binary for Closure Templates is used to compile templates into Javascript. It can be downloaded from http://closure-templ...ript-latest.zip.

It is also fairly easy to build the Templates binary from source. Download the code using Subversion by following the Closure Library example, but use http://closure-templ....com/svn/trunk/ as the URL of the repository to check out and closure-templates as the destination. All Closure Templates binaries can be built using Apache Ant. The binary for compiling templates into Javascript is named SoyToJsSrcCompiler.jar and can be built using Ant as follows:

cd ~/closure/closure-templates/
ant SoyToJsSrcCompiler


The result will be available at ~/closure/closure-templates/build/SoyToJsSrcCompiler.jar.

Closure Compiler

The simplest way to get the Compiler is to download http://closure-compi...iler-latest.zip and extract compiler.jar from the zipfile.

It is also fairly easy to build the Compiler from source. Download the code using Subversion by following the Closure Library example, but use http://closure-compi....com/svn/trunk/ as the URL of the repository to check out and closure-compiler as the destination. The Compiler can then be built using Apache Ant:

cd ~/closure/closure-compiler/
ant jar


The result will be in ~/closure/closure-compiler/build/compiler.jar.

Closure Inspector

The Closure Inspector is a Firefox extension, so to install it, you must first download the Firefox web browser from http://getfirefox.com. Next, install the Firebug extension for Firefox from http://getfirebug.com.

Once you have Firefox running with Firebug, download http://code.google.c...nspector095.xpi and open it in Firefox using File→Open File.... This will prompt you to install the extension.

In case any of these URLs change, it is worth cross-checking these installation instructions with those provided by Google at http://code.google.c.../inspector.html.

Cover of Closure: The Definitive Guide
Learn more about this topic from Closure: The Definitive Guide. 

None of the Javascript libraries today has a more impressive track record than Google Closure, the tool suite used for Gmail, Google Docs, and Google Maps. Closure: The Definitive Guide has precisely what you need to get started with these tools, including valuable information not available publicly anywhere else.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies