Search in sources :

Example 6 with Patten

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

the class RepoTest method testProjectSourceRepo.

@Test
public void testProjectSourceRepo() {
    PackageID pkg = newPackageID("best_org", "this.pkg", "1.8.3");
    ProjectSourceRepo subject = new ProjectSourceRepo((PathConverter) null);
    Patten prospect = subject.calculate(pkg);
    Assert.assertEquals(prospect.toString(), "$/this.pkg/**~test~resources/*.bal");
}
Also used : PackageID(org.ballerinalang.model.elements.PackageID) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) Test(org.testng.annotations.Test)

Example 7 with Patten

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

the class RepoTest method testCacheRepo.

@Test
public void testCacheRepo() {
    PackageID pkg = newPackageID("nice_org", "any.pkg", "10.2.3");
    CacheRepo subject = new CacheRepo((PathConverter) null);
    Patten patten = subject.calculate(pkg);
    Assert.assertEquals(patten.toString(), "$/caches/*/nice_org/any.pkg/10.2.3/src/**~test~resources/*.bal");
}
Also used : CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) PackageID(org.ballerinalang.model.elements.PackageID) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) Test(org.testng.annotations.Test)

Example 8 with Patten

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

the class URIConverterTest method testURIConverter.

@Test
public void testURIConverter() {
    URI baseURI = URI.create("http://staging.central.ballerina.io:9090/");
    Patten patten = new Patten(path("natasha", "foo.bar", "1.0.5"));
    URIConverter subject = new URIConverter(baseURI);
    List<URI> urls = patten.convert(subject).collect(Collectors.toList());
    URI expected = URI.create("http://staging.central.ballerina.io:9090/natasha/foo.bar/1.0.5/");
    Assert.assertEquals(urls, Collections.singletonList(expected));
}
Also used : Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URIConverter(org.wso2.ballerinalang.compiler.packaging.converters.URIConverter) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 9 with Patten

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

the class PullCommand method execute.

@Override
public void execute() {
    if (helpFlag) {
        String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(parentCmdParser, "pull");
        outStream.println(commandUsageInfo);
        return;
    }
    if (argList == null || argList.size() == 0) {
        throw new BLangCompilerException("no package given");
    }
    if (argList.size() > 1) {
        throw new BLangCompilerException("too many arguments");
    }
    // Enable remote debugging
    if (null != debugPort) {
        System.setProperty(SYSTEM_PROP_BAL_DEBUG, debugPort);
    }
    String resourceName = argList.get(0);
    String orgName;
    String packageName;
    String version;
    // Get org-name
    int orgNameIndex = resourceName.indexOf("/");
    if (orgNameIndex != -1) {
        orgName = resourceName.substring(0, orgNameIndex);
    } else {
        throw new BLangCompilerException("no package-name provided");
    }
    // Get package name
    int packageNameIndex = resourceName.indexOf(":");
    if (packageNameIndex != -1) {
        // version is provided
        packageName = resourceName.substring(orgNameIndex + 1, packageNameIndex);
        version = resourceName.substring(packageNameIndex + 1, resourceName.length());
    } else {
        packageName = resourceName.substring(orgNameIndex + 1, resourceName.length());
        version = "*";
    }
    URI baseURI = URI.create("https://staging.central.ballerina.io:9090/");
    Repo remoteRepo = new RemoteRepo(baseURI);
    PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
    Patten patten = remoteRepo.calculate(packageID);
    if (patten != Patten.NULL) {
        Converter converter = remoteRepo.getConverterInstance();
        patten.convertToSources(converter, packageID).collect(Collectors.toList());
    } else {
        outStream.println("couldn't find package " + patten);
    }
    Runtime.getRuntime().exit(0);
}
Also used : RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) PackageID(org.ballerinalang.model.elements.PackageID) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URI(java.net.URI) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 10 with Patten

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

Aggregations

Patten (org.wso2.ballerinalang.compiler.packaging.Patten)20 Test (org.testng.annotations.Test)16 PackageID (org.ballerinalang.model.elements.PackageID)6 Path (java.nio.file.Path)5 URI (java.net.URI)3 ProjectSourceRepo (org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)3 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)3 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)2 PackageSourceEntry (org.ballerinalang.repository.PackageSourceEntry)2 Converter (org.wso2.ballerinalang.compiler.packaging.converters.Converter)2 PathConverter (org.wso2.ballerinalang.compiler.packaging.converters.PathConverter)2 CacheRepo (org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo)2 HomeRepo (org.wso2.ballerinalang.compiler.packaging.repo.HomeRepo)2 ObjRepo (org.wso2.ballerinalang.compiler.packaging.repo.ObjRepo)2 RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 MissingResourceException (java.util.MissingResourceException)1 URIConverter (org.wso2.ballerinalang.compiler.packaging.converters.URIConverter)1 JarRepo (org.wso2.ballerinalang.compiler.packaging.repo.JarRepo)1