1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package vogar.commands;
18
19import java.io.File;
20import java.util.Arrays;
21import java.util.Collection;
22import java.util.List;
23import vogar.Classpath;
24import vogar.Log;
25import vogar.util.Strings;
26
27/**
28 * A javac command.
29 */
30public final class Javac {
31    private final Command.Builder builder;
32
33    public Javac(Log log, String javac) {
34        builder = new Command.Builder(log);
35        builder.args(javac);
36    }
37
38    public Javac bootClasspath(Classpath classpath) {
39        builder.args("-bootclasspath", classpath.toString());
40        return this;
41    }
42
43    public Javac classpath(File... path) {
44        return classpath(Classpath.of(path));
45    }
46
47    public Javac classpath(Classpath classpath) {
48        builder.args("-classpath", classpath.toString());
49        return this;
50    }
51
52    public Javac sourcepath(File... path) {
53        builder.args("-sourcepath", Classpath.of(path).toString());
54        return this;
55    }
56
57    public Javac sourcepath(Collection<File> path) {
58        builder.args("-sourcepath", Classpath.of(path).toString());
59        return this;
60    }
61
62    public Javac destination(File directory) {
63        builder.args("-d", directory.toString());
64        return this;
65    }
66
67    public Javac debug() {
68        builder.args("-g");
69        return this;
70    }
71
72    public Javac extra(List<String> extra) {
73        builder.args(extra);
74        return this;
75    }
76
77    public List<String> compile(Collection<File> files) {
78        return builder.args((Object[]) Strings.objectsToStrings(files)).execute();
79    }
80
81    public List<String> compile(File... files) {
82        return compile(Arrays.asList(files));
83    }
84}
85