import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

public class CompilerExample2 {
    public static void main(String... arguments) {
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fileManager =
            javac.getStandardFileManager(null, null, null);
        Options options = Options.parse(javac, fileManager, arguments);
        System.out.println(options);
        if (!options.getUnrecognizedOptions().isEmpty())
            throw new IllegalArgumentException(
                options.getUnrecognizedOptions().toString());

        Iterable<? extends JavaFileObject> fileObjects =
            fileManager.getJavaFileObjectsFromFiles(options.getFiles());

        CompilationTask task = javac.getTask(null, fileManager, null,
            options.getRecgonizedOptions(),
            options.getClassNames(), fileObjects);

        System.exit(task.call() ? 0 : 1);
    }
}
