Stop storing the build file on BuildTarget.

Summary:
Historically, `BuildTarget` required its corresponding build file to be passed in
as a constructor argument, where preconditions verified that the build file
existed and its path matched the target's path. These strong preconditions
were introduced in hopes of preventing errors.

In practice, this was a bad choice because it made creating a `BuildTarget`
more difficult, as its constructor had to touch the filesystem. As one could
imagine, this was quite a pain when it came to writing unit tests. Instead of
being a typesafe string, `BuildTarget` was much more complicated. We had
to go to great pains to tolerate null build files in fake `BuildTarget`s for tests.

This diff removes that complexity. Now, to get the build file associated with
a `BuildTarget`, one must invoke `BuildTarget`'s new
`getBuildFile(ProjectFilesystem)` method, which throws a
`MissingBuildFileException` if there is no file at the path that corresponds
to the `BuildTarget`.

The `MissingBuildFileException` introduced in this diff is similar
to the `NoSuchBuildTargetException` in the `com.facebook.buck.parser`
package. The problem is that the `parser` package depends on the `model`
package, so a `BuildTarget` could not throw a `NoSuchBuildTarget` exception
itself without unwinding quite a few things. This is why the new `MissingBuildFileException`
was introduced.

Further, a common superclass, `BuildTargetException`, was introduced in order to
simplify catch blocks throughout the code. Its two child classes are
`NoSuchBuildTargetException` and `MissingBuildFileException`.

This diff makes `BuildTargetFactory` largely unnecessary, though it does
not delete it outright. Replacing the `BuildTarget(String, String)` constructor
with a `BuildTarget(String)` constructor that takes a single parameter and
splits on the colon itself will ultimately eliminate the need for
`BuildTargetFactory` altogether. This will be done in a follow-up diff.

Test Plan: Sandcastle builds.
38 files changed
tree: fe811cf1c6d82c6ecd168b5d1f0c571a96f6a125
  1. .idea/
  2. bin/
  3. config/
  4. docs/
  5. lib/
  6. pmd/
  7. scripts/
  8. src/
  9. test/
  10. testdata/
  11. third-party/
  12. .buckconfig
  13. .classpath
  14. .gitignore
  15. .project
  16. buck.iml
  17. build.xml
  18. DEFS
  19. LICENSE
  20. README.md
README.md

Buck

Buck is an Android build tool. To see what Buck can do for you, check out the documentation at http://facebook.github.io/buck/.

Installation

To build Buck, run the following:

git clone git@github.com:facebook/buck.git
cd buck
ant
./bin/buck --help

License

Apache License 2.0