Search in sources :

Example 1 with RemoteRepo

use of org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo 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 2 with RemoteRepo

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

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

the class PushUtils method resolvePkgPathInRemoteRepo.

/**
 * Get URI of the package from the remote repo.
 *
 * @param packageID packageID object
 * @return full URI path of the package relative to the remote repo
 */
private static String resolvePkgPathInRemoteRepo(PackageID packageID) {
    Repo<URI> remoteRepo = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
    Patten patten = remoteRepo.calculate(packageID);
    if (patten == Patten.NULL) {
        throw new BLangCompilerException("Couldn't find package " + packageID.toString());
    }
    Converter<URI> converter = remoteRepo.getConverterInstance();
    List<URI> uris = patten.convert(converter).collect(Collectors.toList());
    if (uris.isEmpty()) {
        throw new BLangCompilerException("Couldn't find package " + packageID.toString());
    }
    return uris.get(0).toString();
}
Also used : BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URI(java.net.URI)

Aggregations

RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)3 URI (java.net.URI)2 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)2 Patten (org.wso2.ballerinalang.compiler.packaging.Patten)2 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)2 Path (java.nio.file.Path)1 PackageID (org.ballerinalang.model.elements.PackageID)1 RepoHierarchyBuilder (org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder)1 Converter (org.wso2.ballerinalang.compiler.packaging.converters.Converter)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 ZipRepo (org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo)1 Name (org.wso2.ballerinalang.compiler.util.Name)1