Track events when we skip querying artifact cache because a dep is re-built.

Summary: Also, use a static method instead of a `Predicate` and cleanup
copypasta.

Test Plan: Unit tests.
Offer `.nobuckcheck` when we fail to fetch from git.

Summary:
If a user updates their main repository, disconnects from the network,
then tries to build, buck will fail to update itself and refuse to build
anything, which is a safe default.

This diff adds an extra message to that path that tells the user that
that they can create a nobuckcheck file as a workaround.

Test Plan:
- Modified my buck repository to make the origin invalid.
- Changed the .buckversion file in my main repository.
- Attempted a build and saw

```
$ buck build fb4a
ssh: Could not resolve hostname invalid.facebook.com: No such file or directory
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Failed to fetch Buck updates from git.
You can disable this by creating a '.nobuckcheck' file in your repository,
but this might lead to strange bugs or build failures.
```
Use ant instead of Buck for building dx.

Summary:
Running buck during the buck build process is proving to be problematic.
Let's just use ant to build dx instead.  I'm leaving the buck files in
there for now since they might be convenient for development.

Test Plan:
Cleaned up almost all untracked files, then went to my fbandroid
repository and ran "buck build fb4a".  It successfully built dx and
fb4a.
Use a specific file to represent a successful build of buck.

Summary:
Previously, we were getting cases where dx or the nailgun client would
fail to build.  Buck would fail, but the next run of buck would see
buck.jar present, and try to build, causing weird failures down the
road.

This diff replaces buck.jar (which was just being used as a flag,
really) with an explicit successful-build file, which is created at the
end of the build.

Test Plan:
Injected a fail in to the dx build.  Ran buck repeatedly, and saw that
it never actually executed the buck java code.
Change `getInputSupplierForRelativePath()` to take a `Path` instead of a `String`.

Test Plan: Sandcastle builds.
Attempt to fix flakiness in `AbstractCachingBuildRuleTest`.

Summary: Ensures that events get posted to the event bus.

Test Plan: Sandcastle tests.
Revert "Revert "Modify BuildFileToJsonParser to use Gson's streaming parser.""

Summary:
This reverts commit 9f4e82d6af06f72cf2d4b7624cdac7fa73b70605.
Yiding has upcoming diffs that need full JSON parsing.

Test Plan:
Sandcastle builds.
This does not appear to have a substantial impact on parse times,
as `buck targets` takes between 19 and 20 seconds both with and
without this change on my machine.
Disable SuperConsole when `-v 2` or above is specified.

Summary:
When building with `-v 2` or above, the verbose output disables the
SuperConsole, which then fails to print messages posted to the event
bus.  As a workaround until this is resolved, this diff disabled the
SuperConsole if `-v 2` or above is specified.  The fallback
SimpleConsole prints the messages properly.

Test Plan: Did a build with -v 2 and saw proper error messages.
Use API 19 by default in buck.

Summary: Default buck to use API 19 as we'll be using API 19 features in
the near future.

Test Plan: Build fbandroid with API 19.
Log the rulekey.

Test Plan: Unit tests.
Fix buck unit tests.

Summary: Fix unit tests.

Test Plan: Unit tests.
Lazily initialize variables on parameter parsing.

Summary:
https://github.com/facebook/buck/pull/43
This is the spirit of the pull request, but up to date.

It saves ~200ms on `buck --version`.  If this is too complicated, I'm OK
rejecting the pull request since it's kind of an edge case.

Test Plan: Ran `buck --version`, verified it was 200ms faster.
Rename `primary_dex_substrings` to `primary_dex_patterns`.

Summary:
I'm going to add support for prefix, suffix, and exact match to allow us
to have tighter patterns.  Preemptively renaming these to make that diff
easier to read.

This requires a corresponding rename diff in fbandroid when we bump
buckversion.

This feature is not used outside of Facebook, so there is no need for an
external migration plan or documentation update.

Test Plan: Built FB4A.
Genralize primary dex filtering.

Summary:
Instead of just substring, support prefix, suffix, and exact match.
This will let us use tighter patterns in fbandroid and avoid pulling
things in by accident.

Test Plan: Unit tests, plus a separate fbandroid diff that uses this.
Introduce `TracesHelper` for reading data out of build traces.

Summary:
Moved common code out of `TraceDataHandler` and `TracesHandlerDelegate` and
into `TracesHelper`. Moving forward, it will be easier to mock/fake the
`TracesHelper` rather than the `ProjectFilesystem`.

Test Plan:
Created a unit test for `TracesHelper`: `TracesHelperTest`.
Had to introduce `FakeInputStreams` to support the test.
Include the command used to create the trace in `/traces`.

Summary:
This makes the `/traces` page easier to use, as you can see
what command was executed to produce the trace.

I will also include this information on the individual `/trace`
page in a follow-up diff.

Test Plan:
Updated `TracesHandlerTest`.  Visited the `/traces` servlet from buckd's
web server and verified that the correct command appears for the trace.
Include more information about the trace on the individual trace page.

Summary:
The trace page now includes the command that was run to produce the
trace as well as the time it was created (based on the last-modified time
of the trace file).

Test Plan: Updated unit test and viewed web server when running buckd.
Change `traces.soy` so links no longer open in a new tab by default.

Summary: After using this for a bit, I find this behavior annoying.

Test Plan: Sandcastle builds and manual testing of the buckd web server.
Add `--json` for `audit input`.

Summary:
For `--json`, output a single json object that maps each given target to
a list of paths relative to the repo root. I have a concrete use case
for this and (bonus) this makes the CLI a little more consistent.

The existing alternatives are not super palatable:

* `buck targets` and parse the entire output (inefficient)
* `buck audit input` and use heuristics to map target names to
  the files they own (imprecise aka wrong)
* repeated calls to `buck audit input`, one for each buck target
  of interest (very inefficient)

Test Plan:
`buck audit input --json java/com/facebook/tools/buckapi:buckapi`

Observe reasonable looking output.
Add support for `ANDROID_SERIAL` env variable.

Summary: The target device can be specified by setting the
`ANDROID_SERIAL` environment variable, in addition to using the `-s`
option.

Test Plan:
 - `./bin/buck test --all` – nothing is broken.
 - Attach at least two devices/emulators.
 - `buck install fb4a` – Fails because more than one device available.
 - Set `ANDROID_SERIAL` to the serial number of one of the devices.
 - `buck install fb4a`
 - Set ANDROID_SERIAL to an invalid serial number.
 - `buck install fb4a` – Fails because no devices match filter.