package com.redhat.ceylon.common.tool;

import java.io.File;
import java.util.List;

import com.redhat.ceylon.common.FileUtil;

public abstract class CeylonBaseTool implements Tool {
    protected File cwd;
    public String verbose;
    protected List<String> defines;

    public File getCwd() {
        return cwd;
    }
    
    @OptionArgument(longName="cwd", argumentName="dir")
    @Description("Specifies the current working directory for this tool. " +
            "(default: the directory where the tool is run from)")
    public void setCwd(File cwd) {
        this.cwd = cwd;
    }
    
    public String getVerbose() {
        return verbose;
    }
    
    @Option(shortName='d')
    @OptionArgument(argumentName = "flags")
    @Description("Produce verbose output. " +
            "If no `flags` are given then be verbose about everything, " +
            "otherwise just be verbose about the flags which are present. " +
            "Allowed flags include: `all`, `loader`.")
    public void setVerbose(String verbose) {
        this.verbose = verbose;
    }
    
    @OptionArgument(shortName='D', argumentName = "key>=<value")
    @Description("Set a system property")
    public void setDefine(List<String> defines) {
        this.defines = defines;
    }
    
    protected void setSystemProperties() {
        if (defines != null) {
            for (String prop : defines) {
                int p = prop.indexOf('=');
                if (p > 0) {
                    String key = prop.substring(0, p);
                    String val = prop.substring(p + 1);
                    System.setProperty(key, val);
                }
            }
        }
    }

    protected File validCwd() {
        return (cwd != null) ? cwd : new File(".");
    }

    protected List<File> applyCwd(List<File> files) {
        return FileUtil.applyCwd(getCwd(), files);
    }

    protected File applyCwd(File file) {
        return FileUtil.applyCwd(getCwd(), file);
    }
}

@@ -119,16 +119,66 @@
 ileUtil;
+%0Aimport com.redhat.ceylon.common.tools.CeylonTool;
 %0A%0Apublic
@@ -2020,11 +2020,187 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void initialize(CeylonTool mainTool) throws Exception %7B%0A        // Empty default implementation for simple tools that don't need initialization%0A    %7D
 %0A%7D%0A

Make it slightly easier for a class to implement `Tool`