Search in sources :

Example 16 with PackageID

use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.

the class PackageLoader method updateVersionFromToml.

private void updateVersionFromToml(PackageID pkgId) {
    String orgName = pkgId.orgName.value;
    String pkgName = pkgId.name.value;
    String pkgAlias = orgName + "/" + pkgName;
    // TODO: make getDependencies return a map
    Optional<Dependency> dependency = manifest.getDependencies().stream().filter(d -> d.getPackageName().equals(pkgAlias)).findFirst();
    if (dependency.isPresent()) {
        if (pkgId.version.value.isEmpty()) {
            pkgId.version = new Name(dependency.get().getVersion());
        } else {
            throw new BLangCompilerException("dependency version in Ballerina.toml mismatches" + " with the version in the source for package " + pkgAlias);
        }
    }
}
Also used : SystemPackageRepositoryProvider(org.ballerinalang.spi.SystemPackageRepositoryProvider) Arrays(java.util.Arrays) PackageSource(org.ballerinalang.repository.PackageSource) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) PROJECT_DIR(org.ballerinalang.compiler.CompilerOptionName.PROJECT_DIR) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) IdentifierNode(org.ballerinalang.model.tree.IdentifierNode) Converter(org.wso2.ballerinalang.compiler.packaging.converters.Converter) Names(org.wso2.ballerinalang.compiler.util.Names) RepoHierarchy(org.wso2.ballerinalang.compiler.packaging.RepoHierarchy) URI(java.net.URI) Path(java.nio.file.Path) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) PackageID(org.ballerinalang.model.elements.PackageID) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Manifest(org.ballerinalang.toml.model.Manifest) OFFLINE(org.ballerinalang.compiler.CompilerOptionName.OFFLINE) Resolution(org.wso2.ballerinalang.compiler.packaging.Resolution) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) Optional(java.util.Optional) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) ManifestProcessor(org.ballerinalang.toml.parser.ManifestProcessor) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ArrayList(java.util.ArrayList) Dependency(org.ballerinalang.toml.model.Dependency) RepoHierarchyBuilder.node(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder.node) HomeRepoUtils(org.wso2.ballerinalang.util.HomeRepoUtils) PackageRepository(org.ballerinalang.repository.PackageRepository) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) TreeBuilder(org.ballerinalang.model.TreeBuilder) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectDirs(org.wso2.ballerinalang.compiler.util.ProjectDirs) StreamSupport(java.util.stream.StreamSupport) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Name(org.wso2.ballerinalang.compiler.util.Name) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) PackageEntity(org.ballerinalang.repository.PackageEntity) Parser(org.wso2.ballerinalang.compiler.parser.Parser) Paths(java.nio.file.Paths) GenericPackageSource(org.wso2.ballerinalang.compiler.packaging.GenericPackageSource) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) Collections(java.util.Collections) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) Dependency(org.ballerinalang.toml.model.Dependency) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 17 with PackageID

use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.

the class ZipUtils method generateBalo.

/**
 * Generates the balo/zip of the package.
 *
 * @param bLangPackage bLangPackage node
 * @param projectPath  project path
 * @param paths        paths of bal files inside the package
 */
static void generateBalo(BLangPackage bLangPackage, String projectPath, Stream<Path> paths) {
    PackageID packageID = bLangPackage.packageID;
    Path destPath = Paths.get(projectPath).resolve(".ballerina").resolve("repo").resolve(packageID.getOrgName().getValue()).resolve(packageID.getName().getValue()).resolve(packageID.getPackageVersion().getValue());
    if (!Files.exists(destPath)) {
        try {
            Files.createDirectories(destPath);
        } catch (IOException e) {
            throw new BLangCompilerException("Error occurred when creating directories in " + "./ballerina/repo/ to save the generated balo");
        }
    }
    String fileName = packageID.getName() + ".zip";
    String baloDirPath = destPath.resolve(fileName).toString();
    createArchive(paths, baloDirPath);
}
Also used : Path(java.nio.file.Path) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) PackageID(org.ballerinalang.model.elements.PackageID) IOException(java.io.IOException)

Example 18 with PackageID

use of org.ballerinalang.model.elements.PackageID 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 19 with PackageID

use of org.ballerinalang.model.elements.PackageID 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)

Example 20 with PackageID

use of org.ballerinalang.model.elements.PackageID in project ballerina by ballerina-lang.

the class RepoTest method testProjectObjRepo.

@Test
public void testProjectObjRepo() {
    PackageID pkg = newPackageID("my_org", "my.pkg", "1.2.3");
    ObjRepo subject = new ObjRepo((PathConverter) null);
    Patten patten = subject.calculate(pkg);
    Assert.assertEquals(patten.toString(), "$/repo/my_org/my.pkg/1.2.3/obj/my.pkg.balo");
}
Also used : PackageID(org.ballerinalang.model.elements.PackageID) ObjRepo(org.wso2.ballerinalang.compiler.packaging.repo.ObjRepo) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) Test(org.testng.annotations.Test)

Aggregations

PackageID (org.ballerinalang.model.elements.PackageID)23 Name (org.wso2.ballerinalang.compiler.util.Name)10 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)8 Path (java.nio.file.Path)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)7 List (java.util.List)6 Patten (org.wso2.ballerinalang.compiler.packaging.Patten)6 RepoHierarchy (org.wso2.ballerinalang.compiler.packaging.RepoHierarchy)6 IOException (java.io.IOException)5 URI (java.net.URI)5 Collectors (java.util.stream.Collectors)5 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)5 Resolution (org.wso2.ballerinalang.compiler.packaging.Resolution)5 Names (org.wso2.ballerinalang.compiler.util.Names)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Set (java.util.Set)4 CacheRepo (org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo)4