diff --git a/README.md b/README.md new file mode 100644 index 0000000..06cb4d4 --- /dev/null +++ b/README.md @@ -0,0 +1,228 @@ +![](https://raw.github.com/wiki/EsotericSoftware/scar/images/logo.png) + +Please use the [Scar discussion group](http://groups.google.com/group/scar-users) for support. + +## Overview + +Scar is a collection of utilities that make it easier to do build related tasks using Java code. Building with Java code makes sense for Java developers. Rather than a complicated tool that caters to all needs, Scar is a simple tool that allows you to get what you need done in a simple, straightforward manner. Familiar tools and libraries can be used. Builds can be debugged like any other Java program. There is no new language to learn or XML attributes to look up. + +## Getting started + +Scar has the following key components: + +- The `Scar` class has static [utility methods](#Scar_utility_methods) for various tasks such as zip, unzip, jar, compile, etc. +- The `Paths` class conveniently collects file paths using globs (asterisks) or regex. +- The `Project` class is a generic project descriptor. It holds strings, numbers, paths, and other data about a project. +- The `Build` class takes a Project and uses the Scar class to compile sources and package a JAR. + +There are generally two ways of using Scar: + +### Code + +Create a new class and add a main method. Import the `Scar` and `Paths` classes, and use them to do whatever tasks you need: glob paths, zip files, etc. + +### Build class + +Use the `Build` class to do common build tasks on a project descriptor. The project descriptor is simply a map with convenience methods to get values (eg, as a list of file paths) and to do token replacement. The `Build` class looks in the project for specific values (source paths, dependency JARs, etc) and then compiles Java source and creates a JAR. For example, this builds a JAR from a project directory using the default project values: + +```java + Project project = Build.project("path to project dir"); + Build.build(project); +``` + +Running Scar on a directory runs Build.main which does the above two lines of code. + +```java + scar /path_to_project_dir/ +``` + +If the directory contains a "project.yaml" file, it is used to customize the project values. When writing code to build a project instead of the command line, the project values can be customized in code. + +## Projects + +The `Project` class is a project descriptor. It consists of a path to the root directory of the project and a HashMap holding some data. The `Project` class itself is a generic data structure and doesn't know anything about how the data will be used. The requirements for what should be specified in the project are determined by the tasks that need to be performed. + +Projects can be defined entirely in Java: + +```java + Project project = new Project(); + project.set("name", "AwesomeLib"); + ArrayList sourceDirs = new ArrayList(); + sourceDirs.add("src"); + sourceDirs.add("other"); + project.set("source", sourceDirs); +``` + +Projects can also be loaded from a [YAML](http://www.yaml.org/) file on disk. YAML is a human readable format that makes it easy to specify the project object graph. Scar uses the [YamlBeans](http://code.google.com/p/yamlbeans/) library to parse YAML. + +```yaml + name: AwesomeLib + source: + - src + - other +``` +```java + Project project = new Project("project.yaml"); +``` + +Separate from the object graph, a project can also store a "document" string. What is done with this string is left up to the code that is actually performing the tasks. The document can be set in Java with the `Project#setDocument(String)` method or in YAML by using the document separator "---": + +```yaml + name: AwesomeLib + source: + - src + - other + --- + System.out.println("The document data can be any text, "); + System.out.println("but is a convenient place to put code."); +``` + +## Paths + +Scar uses the [Wildcard](http://code.google.com/p/wildcard/) library to collect and manipulate files. For many tasks, the majority of the work is collecting the files to act upon, and Wildcard makes this easy. See the [Wildcard documentation](http://code.google.com/p/wildcard/) for how to construct paths. + +Paths used in project YAML files can be either a single entry or a list. They should use the [pipe delimited patterns](http://code.google.com/p/wildcard/#Pipe_delimited_patterns) format. Some [YAML examples](http://code.google.com/p/scar/#YAML_examples) are provided below. + +## The Build class + +The `Build` class has static methods that take a `Project` and perform various tasks, such as compile and JAR. The `Scar` class actually performs most tasks, the `Build` class just defines how to project descriptors are interpreted. Note that using the `Project` and `Build` classes are optional. Your own customized build system could be implemented using only the `Scar` and `Paths` classes. + +The `Build` class has the following conventions for the data in the project descriptor: + +
**Property** | **Description** |
name | The name of the project. Used to name the JAR. Default: The name of the directory containing the project YAML file. |
target | The directory to output build artifacts. Default: The directory containing the project YAML file, plus "../target/`name`". |
version | The version of the project. If available, used to name the JAR. Default: *blank* |
resources | Wildcard patterns for the files to include in the JAR. Default: `resources`, `src/main/resources`, and 'assets'. |
dist | Wildcard patterns for the files to include in the distribution, outside the JAR. Default: `dist`. |
source | Wildcard patterns for the Java files to compile. Default: `src|**/*.java` and `src/main/java|**/*.java`. |
classpath | Wildcard patterns for the files to include on the classpath. Default: `lib|**/*.jar` and `libs|**/*.jar`. |
dependencies | Relative or absolute paths to dependency project directories or YAML files. Default: *blank* |
include | Relative or absolute paths to project files to inherit properties from. Default: *blank* |
main | Name of the main class. Default: *blank* |