Search in sources :

Example 1 with Resolution

use of org.wso2.ballerinalang.compiler.packaging.Resolution 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 Resolution

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

the class RepoHierarchy method resolve.

public Resolution resolve(PackageID pkg) {
    log1(pkg);
    for (int i = 0; i < repos.length; i++) {
        Repo repo = repos[i];
        Patten patten = repo.calculate(pkg);
        if (patten != Patten.NULL) {
            Converter converter = repo.getConverterInstance();
            List<PackageSourceEntry> paths = patten.convertToSources(converter, pkg).collect(Collectors.toList());
            log2(repo, patten, paths);
            if (!paths.isEmpty()) {
                return new Resolution(getChildHierarchyForRepo(i), paths);
            }
        } else {
            log3(repo);
        }
    }
    log4();
    return Resolution.NOT_FOUND;
}
Also used : Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) PackageSourceEntry(org.ballerinalang.repository.PackageSourceEntry) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter)

Example 3 with Resolution

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

the class PackageLoader method loadPackageEntity.

private PackageEntity loadPackageEntity(PackageID pkgId) {
    updateVersionFromToml(pkgId);
    Resolution resolution = repos.resolve(pkgId);
    if (resolution == Resolution.NOT_FOUND) {
        return null;
    }
    return new GenericPackageSource(pkgId, resolution.sources, resolution.resolvedBy);
}
Also used : GenericPackageSource(org.wso2.ballerinalang.compiler.packaging.GenericPackageSource) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution)

Example 4 with Resolution

use of org.wso2.ballerinalang.compiler.packaging.Resolution 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 Resolution

use of org.wso2.ballerinalang.compiler.packaging.Resolution 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

Resolution (org.wso2.ballerinalang.compiler.packaging.Resolution)4 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 PackageSourceEntry (org.ballerinalang.repository.PackageSourceEntry)1 GenericPackageSource (org.wso2.ballerinalang.compiler.packaging.GenericPackageSource)1 Converter (org.wso2.ballerinalang.compiler.packaging.converters.Converter)1 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)1