Search in sources :

Example 1 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class RepositoriesTest method testSetRepositories.

@Test
public void testSetRepositories() {
    CeylonConfig configCopy = testConfig.copy();
    Repositories testRepos = Repositories.withConfig(configCopy);
    Map<String, Repository[]> repomap = testRepos.getRepositories();
    Repository[] reps = { new Repositories.SimpleRepository("", "./mods", null) };
    repomap.put(Repositories.REPO_TYPE_LOCAL_LOOKUP, reps);
    testRepos.setRepositories(repomap);
    Repository[] lookup = testRepos.getLocalLookupRepositories();
    Assert.assertTrue(lookup.length == 1);
    assertRepository(lookup[0], "%lookup-1", "./mods", null, null);
}
Also used : Repositories(org.eclipse.ceylon.common.config.Repositories) Repository(org.eclipse.ceylon.common.config.Repositories.Repository) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) Test(org.junit.Test)

Example 2 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithPrompt.

@Test
public void testRepoWithPrompt() {
    mockPrompt.prompts.put("Password for bar at https://modules.ceylon-lang.org:", "repopassword");
    Repository repository = repos.getRepository("repo-with-prompted");
    Assert.assertNotNull(repository);
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    Assert.assertEquals("repopassword", new String(up.getPassword()));
    mockPrompt.assertSeenOnlyGivenPrompts();
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Example 3 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithFooAndKeystoreMissing.

@Test
public void testRepoWithFooAndKeystoreMissing() {
    Authentication.setPasswordPrompt(mockPrompt);
    Repository repository = repos.getRepository("repo-with-keystorefoo");
    Assert.assertNull(repository.getCredentials().getPassword());
    Assert.assertEquals("fooalias", repository.getCredentials().getAlias());
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    mockPrompt.assertSeenNoPrompts();
    try {
        up.getPassword();
        Assert.fail();
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("The default keystore (foofile) does not exist")) {
            throw e;
        }
    }
    mockPrompt.assertSeenNoPrompts();
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Example 4 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository in project ceylon by eclipse.

the class AuthenticationTest method testRepoWithFoo.

@Test
public void testRepoWithFoo() throws Exception {
    String keystoreSectionName = null;
    String storeFilename = "foofile";
    File storeFile = new File(testDir, storeFilename);
    String repoPass = "foopassword";
    String alias = "fooalias";
    String storePass = "foostorepass";
    String entryPass = "fooentrypass";
    createStore(testConfig, keystoreSectionName, storeFilename, storeFile, repoPass, alias, storePass, storePass);
    mockPrompt.prompts.put("Password for default keystore (foofile):", storePass);
    Authentication.setPasswordPrompt(mockPrompt);
    Repository repository = repos.getRepository("repo-with-keystorefoo");
    Assert.assertNull(repository.getCredentials().getPassword());
    Assert.assertEquals(alias, repository.getCredentials().getAlias());
    UsernamePassword up = Authentication.fromConfig(testConfig).getUsernameAndPassword(repository.getCredentials());
    Assert.assertNotNull(up);
    mockPrompt.assertSeenNoPrompts();
    Assert.assertEquals(repoPass, new String(up.getPassword()));
    mockPrompt.assertSeenOnlyGivenPrompts();
    Assert.assertEquals(repository.getCredentials().getUser(), up.getUser());
    // Get the password again
    up.getPassword();
    // Check we're not prompted again
    mockPrompt.assertSeenOnlyGivenPrompts();
}
Also used : Repository(org.eclipse.ceylon.common.config.Repositories.Repository) File(java.io.File) UsernamePassword(org.eclipse.ceylon.common.config.Authentication.UsernamePassword) Test(org.junit.Test)

Example 5 with Repository

use of org.eclipse.ceylon.common.config.Repositories.Repository 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)

Aggregations

Repository (org.eclipse.ceylon.common.config.Repositories.Repository)10 Test (org.junit.Test)9 UsernamePassword (org.eclipse.ceylon.common.config.Authentication.UsernamePassword)6 File (java.io.File)4 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)3 Repositories (org.eclipse.ceylon.common.config.Repositories)3 BuildException (org.apache.tools.ant.BuildException)1 Credentials (org.eclipse.ceylon.common.config.Credentials)1