Search in sources :

Example 1 with RepoHierarchy

use of org.wso2.ballerinalang.compiler.packaging.RepoHierarchy in project ballerina by ballerina-lang.

the class RepoHierarchyTest method testFullOrder.

@Test
public void testFullOrder() {
    PackageID nonExisting = newPackageID("bad", "ok.pkg", "5");
    ArrayList<Integer> order = new ArrayList<>();
    RepoHierarchy subject = createSubject(order);
    Resolution resolution = subject.resolve(nonExisting);
    Assert.assertEquals(resolution, Resolution.NOT_FOUND);
    Assert.assertEquals(order, Arrays.asList(0, 1, 2, 3, 4));
}
Also used : ArrayList(java.util.ArrayList) PackageID(org.ballerinalang.model.elements.PackageID) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) Test(org.testng.annotations.Test)

Example 2 with RepoHierarchy

use of org.wso2.ballerinalang.compiler.packaging.RepoHierarchy in project ballerina by ballerina-lang.

the class PackageLoader method genRepoHierarchy.

private RepoHierarchy genRepoHierarchy(Path sourceRoot) {
    Path balHomeDir = HomeRepoUtils.createAndGetHomeReposPath();
    Path projectHiddenDir = sourceRoot.resolve(".ballerina");
    RepoHierarchyBuilder.RepoNode[] systemArr = loadSystemRepos();
    Converter<Path> converter = sourceDirectory.getConverter();
    Repo remote = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
    Repo homeCacheRepo = new CacheRepo(balHomeDir);
    Repo homeRepo = new ZipRepo(balHomeDir);
    Repo projectCacheRepo = new CacheRepo(projectHiddenDir);
    Repo projectRepo = new ZipRepo(projectHiddenDir);
    RepoHierarchyBuilder.RepoNode homeCacheNode;
    if (offline) {
        homeCacheNode = node(homeCacheRepo, systemArr);
    } else {
        homeCacheNode = node(homeCacheRepo, node(remote, systemArr));
    }
    RepoHierarchyBuilder.RepoNode nonLocalRepos = node(projectRepo, node(projectCacheRepo, homeCacheNode), node(homeRepo, homeCacheNode));
    RepoHierarchyBuilder.RepoNode fullRepoGraph;
    if (converter != null) {
        Repo programingSource = new ProgramingSourceRepo(converter);
        Repo projectSource = new ProjectSourceRepo(converter);
        fullRepoGraph = node(programingSource, node(projectSource, nonLocalRepos));
    } else {
        fullRepoGraph = nonLocalRepos;
    }
    return RepoHierarchyBuilder.build(fullRepoGraph);
}
Also used : Path(java.nio.file.Path) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)

Example 3 with RepoHierarchy

use of org.wso2.ballerinalang.compiler.packaging.RepoHierarchy in project ballerina by ballerina-lang.

the class RepoHierarchyTest method createSubject.

/**
 * <pre>
 *
 *  easy/too:0        good/i.am:1                                     ugly/ok.pkg:4
 *      |                 |           ,--- projectCacheRepo ---.            |
 *      v                 v          /            2             \           v
 * projectSource --- projectRepo ---<                            >--- homeCacheRepo
 *            0           1          \                          /           4
 *                                    `------- homeRepo -------'
 *                                                3
 * </pre>
 * Expected lookup order
 * <p>
 * <p>
 * 0. projectSource
 * 1. projectRepo
 * 2. homeRepo
 * 3. projectCacheRepo
 * 4. homeCacheRepo
 *
 * @param order list to remember order of invocation into
 */
private RepoHierarchy createSubject(List<Integer> order) {
    Repo projectSource = mockRepo(0, order);
    Repo projectRepo = mockRepo(1, order);
    Repo projectCacheRepo = mockRepo(2, order);
    Repo homeRepo = mockRepo(3, order);
    Repo homeCacheRepo = mockRepo(4, order);
    RepoHierarchyBuilder.RepoNode homeCacheNode = node(homeCacheRepo);
    return RepoHierarchyBuilder.build(node(projectSource, node(projectRepo, null, /* null nodes should be ignored */
    node(projectCacheRepo, homeCacheNode), node(homeRepo, homeCacheNode))));
}
Also used : Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder)

Example 4 with RepoHierarchy

use of org.wso2.ballerinalang.compiler.packaging.RepoHierarchy in project ballerina by ballerina-lang.

the class RepoHierarchyTest method testResolvingFromAnIntermediate.

@Test
public void testResolvingFromAnIntermediate() {
    RepoHierarchy subject;
    Resolution resolution;
    // Part 1
    PackageID repo1sPkg = newPackageID("good", "i.am", "1");
    ArrayList<Integer> order = new ArrayList<>();
    subject = createSubject(order);
    resolution = subject.resolve(repo1sPkg);
    Assert.assertNotEquals(resolution, Resolution.NOT_FOUND);
    Assert.assertEquals(order, Arrays.asList(0, 1));
    // Part 2
    order.clear();
    PackageID repo4sPkg = newPackageID("ugly", "ok.pkg", "4");
    subject = resolution.resolvedBy;
    subject.resolve(repo4sPkg);
    Assert.assertNotEquals(resolution, Resolution.NOT_FOUND);
    Assert.assertEquals(order, Arrays.asList(1, 2, 3, 4));
}
Also used : ArrayList(java.util.ArrayList) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) PackageID(org.ballerinalang.model.elements.PackageID) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) Test(org.testng.annotations.Test)

Example 5 with RepoHierarchy

use of org.wso2.ballerinalang.compiler.packaging.RepoHierarchy in project ballerina by ballerina-lang.

the class RepoHierarchyTest method testIdempotence.

@Test
public void testIdempotence() {
    RepoHierarchy subject;
    Resolution resolution;
    // Part 1
    PackageID repo0sPkg = newPackageID("easy", "too", "0");
    ArrayList<Integer> order = new ArrayList<>();
    subject = createSubject(order);
    resolution = subject.resolve(repo0sPkg);
    Assert.assertNotEquals(resolution, Resolution.NOT_FOUND);
    // Part 2
    order.clear();
    subject = resolution.resolvedBy;
    subject.resolve(repo0sPkg);
    Assert.assertNotEquals(resolution, Resolution.NOT_FOUND);
}
Also used : ArrayList(java.util.ArrayList) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) PackageID(org.ballerinalang.model.elements.PackageID) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)3 PackageID (org.ballerinalang.model.elements.PackageID)3 Test (org.testng.annotations.Test)3 RepoHierarchy (org.wso2.ballerinalang.compiler.packaging.RepoHierarchy)3 Resolution (org.wso2.ballerinalang.compiler.packaging.Resolution)3 RepoHierarchyBuilder (org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder)2 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)2 Path (java.nio.file.Path)1 CacheRepo (org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo)1 ProgramingSourceRepo (org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo)1 ProjectSourceRepo (org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)1 RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)1 ZipRepo (org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo)1