Search in sources :

Example 1 with Credentials

use of org.eclipse.ceylon.common.config.Credentials in project ceylon by eclipse.

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(org.eclipse.ceylon.common.config.Repositories) Repository(org.eclipse.ceylon.common.config.Repositories.Repository) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) BuildException(org.apache.tools.ant.BuildException) Credentials(org.eclipse.ceylon.common.config.Credentials)

Example 2 with Credentials

use of org.eclipse.ceylon.common.config.Credentials in project ceylon by eclipse.

the class RepositoriesTest method assertRepository.

private void assertRepository(Repository repo, String name, String url, String user, String password) {
    Assert.assertNotNull(repo);
    Assert.assertEquals(name, repo.getName());
    Assert.assertEquals(url, repo.getUrl());
    Credentials credentials = repo.getCredentials();
    Assert.assertEquals(user, credentials != null ? credentials.getUser() : null);
    Assert.assertEquals(password, credentials != null ? credentials.getPassword() : null);
}
Also used : Credentials(org.eclipse.ceylon.common.config.Credentials)

Aggregations

Credentials (org.eclipse.ceylon.common.config.Credentials)2 BuildException (org.apache.tools.ant.BuildException)1 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)1 Repositories (org.eclipse.ceylon.common.config.Repositories)1 Repository (org.eclipse.ceylon.common.config.Repositories.Repository)1