Search in sources :

Example 1 with CeylonConfig

use of com.redhat.ceylon.common.config.CeylonConfig in project ceylon-compiler by ceylon.

the class CeylonConfigValueAntTask method execute.

@Override
public void execute() throws BuildException {
    Java7Checker.check();
    if (key == null) {
        throw new BuildException("'key' is a required attribute for 'ceylon-config-value'");
    }
    if (property == null) {
        throw new BuildException("'property' is a required attribute for 'ceylon-config-value'");
    }
    CeylonConfig config = getConfig();
    String[] values = config.getOptionValues(key);
    setConfigValueAsProperty(values, property);
}
Also used : CeylonConfig(com.redhat.ceylon.common.config.CeylonConfig) BuildException(org.apache.tools.ant.BuildException)

Example 2 with CeylonConfig

use of com.redhat.ceylon.common.config.CeylonConfig in project ceylon-compiler by ceylon.

the class CompilerConfig method instance.

public static CeylonConfig instance(Context context) {
    CeylonConfig instance = context.get(CeylonConfig.class);
    if (instance == null) {
        Options options = Options.instance(context);
        String cwd = options.get(OptionName.CEYLONCWD);
        if (cwd == null) {
            cwd = ".";
        }
        instance = CeylonConfig.createFromLocalDir(new File(cwd));
        context.put(CeylonConfig.class, instance);
    }
    return instance;
}
Also used : Options(com.sun.tools.javac.util.Options) CeylonConfig(com.redhat.ceylon.common.config.CeylonConfig) File(java.io.File)

Example 3 with CeylonConfig

use of com.redhat.ceylon.common.config.CeylonConfig in project ceylon-compiler by ceylon.

the class CeylonConfigAntTask method execute.

@Override
public void execute() throws BuildException {
    Java7Checker.check();
    CeylonConfig config = getConfig();
    for (String key : config.getOptionNames(null)) {
        String[] values = config.getOptionValues(key);
        setConfigValueAsProperty(values, getPrefix() + key);
    }
}
Also used : CeylonConfig(com.redhat.ceylon.common.config.CeylonConfig)

Example 4 with CeylonConfig

use of com.redhat.ceylon.common.config.CeylonConfig in project ceylon-compiler by ceylon.

the class CeylonConfigRepositoryAntTask method execute.

@Override
public void execute() throws BuildException {
    Java7Checker.check();
    if (name == null && type == null) {
        throw new BuildException("Either the 'name' or 'type' attribute has to be specified for 'ceylon-config-repository'");
    }
    if (name != null && type != null) {
        throw new BuildException("The 'name' and 'type' attributes cannot both be specified for 'ceylon-config-repository'");
    }
    if (key == null) {
        throw new BuildException("'key' is a required attribute for 'ceylon-config-repository'");
    }
    if (property == null) {
        throw new BuildException("'property' is a required attribute for 'ceylon-config-value'");
    }
    CeylonConfig config = getConfig();
    Repositories reps = Repositories.withConfig(config);
    Repository rep;
    String repdesc;
    if (name != null) {
        rep = reps.getRepository(name);
        repdesc = "of name '" + name + "'";
    } else {
        rep = reps.getRepositoryByTypeWithDefaults(type.name());
        repdesc = "of type '" + type.name() + "'";
    }
    if (rep != null) {
        String value = null;
        switch(key) {
            case name:
                value = rep.getName();
                break;
            case url:
                value = rep.getUrl();
                break;
            default:
                Credentials cred = rep.getCredentials();
                if (cred != null) {
                    switch(key) {
                        case user:
                            value = cred.getUser();
                            break;
                        case password:
                            value = cred.getPassword();
                            break;
                        case keystore:
                            value = cred.getKeystore();
                            break;
                        case alias:
                            value = cred.getAlias();
                            break;
                        default:
                    }
                } else {
                    log("No credentials found for repository " + repdesc, Project.MSG_WARN);
                }
        }
        if (value != null) {
            setProjectProperty(property, value);
        }
    } else {
        log("Repository " + repdesc + " not found", Project.MSG_WARN);
    }
}
Also used : Repositories(com.redhat.ceylon.common.config.Repositories) Repository(com.redhat.ceylon.common.config.Repositories.Repository) CeylonConfig(com.redhat.ceylon.common.config.CeylonConfig) BuildException(org.apache.tools.ant.BuildException) Credentials(com.redhat.ceylon.common.config.Credentials)

Example 5 with CeylonConfig

use of com.redhat.ceylon.common.config.CeylonConfig in project ceylon-compiler by ceylon.

the class CeylonNewTool method buildPromptedEnv.

private Environment buildPromptedEnv() {
    Environment env = new Environment();
    // TODO Tidy up how we create and what's in this initial environment
    if (project.getDirectory() != null) {
        env.put("base.dir", applyCwd(project.getDirectory()).getAbsolutePath());
    }
    env.put("ceylon.home", System.getProperty(Constants.PROP_CEYLON_HOME_DIR));
    //env.put("ceylon.system.repo", System.getProperty("ceylon.system.repo"));
    env.put("ceylon.version.number", Versions.CEYLON_VERSION_NUMBER);
    env.put("ceylon.version.major", Integer.toString(Versions.CEYLON_VERSION_MAJOR));
    env.put("ceylon.version.minor", Integer.toString(Versions.CEYLON_VERSION_MINOR));
    env.put("ceylon.version.release", Integer.toString(Versions.CEYLON_VERSION_RELEASE));
    env.put("ceylon.version.name", Versions.CEYLON_VERSION_NAME);
    Set<String> seenKeys = new HashSet<>();
    List<Variable> vars = new LinkedList<>(project.getVariables());
    while (!vars.isEmpty()) {
        Variable var = vars.remove(0);
        if (seenKeys.contains(var.getKey())) {
            throw new RuntimeException("Variables for project do not form a tree");
        }
        seenKeys.add(var.getKey());
        // TODO Use the value from rest if there is one, only prompting if 
        // there is not
        // TODO The problem with this is: "How does the user figure out 
        // what option they need to specify on the command line
        // in order to avoid being prompted for it interactively?"
        // Each subtool could provide their own getters and setters
        // but they requires we write a subtool for each project
        // It would be nice if we didn't have to do that, but could just
        // drive the whole thing from a script in the templates dir.
        vars.addAll(0, var.initialize(getProjectName(), env));
    }
    String sourceFolder = Constants.DEFAULT_SOURCE_DIR;
    String baseDir = env.get("base.dir");
    if (project.getDirectory() == null) {
        project.setDirectory(new File(baseDir));
    }
    try {
        CeylonConfig config = CeylonConfig.createFromLocalDir(new File(baseDir));
        List<File> srcs = DefaultToolOptions.getCompilerSourceDirs(config);
        if (!srcs.isEmpty()) {
            sourceFolder = srcs.get(0).getPath();
        } else {
            sourceFolder = Constants.DEFAULT_SOURCE_DIR;
        }
    } catch (Exception e) {
    // Ignore any errors
    }
    env.put("source.folder", sourceFolder);
    log(env);
    return env;
}
Also used : CeylonConfig(com.redhat.ceylon.common.config.CeylonConfig) File(java.io.File) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

CeylonConfig (com.redhat.ceylon.common.config.CeylonConfig)5 File (java.io.File)2 BuildException (org.apache.tools.ant.BuildException)2 Credentials (com.redhat.ceylon.common.config.Credentials)1 Repositories (com.redhat.ceylon.common.config.Repositories)1 Repository (com.redhat.ceylon.common.config.Repositories.Repository)1 Options (com.sun.tools.javac.util.Options)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1