Search in sources :

Example 11 with Patten

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

the class BinaryFileWriter method writeExecutableBinary.

public void writeExecutableBinary(BLangPackage packageNode) {
    String fileName = getOutputFileName(packageNode, BLANG_EXEC_FILE_SUFFIX);
    writeExecutableBinary(packageNode, fileName);
    // Generate balo
    Path path = this.sourceDirectory.getPath();
    if (Files.isDirectory(path.resolve(ProjectDirConstants.DOT_BALLERINA_DIR_NAME))) {
        ProjectSourceRepo projectSourceRepo = new ProjectSourceRepo(path);
        Patten packageIDPattern = projectSourceRepo.calculate(packageNode.packageID);
        Stream<Path> pathStream = packageIDPattern.convert(projectSourceRepo.getConverterInstance());
        pathStream = Stream.concat(pathStream, packageIDPattern.sibling(path("Ballerina.md")).convert(projectSourceRepo.getConverterInstance()));
        String prjPath = projectSourceRepo.getConverterInstance().toString();
        ZipUtils.generateBalo(packageNode, prjPath, pathStream);
    }
}
Also used : Path(java.nio.file.Path) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)

Example 12 with Patten

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

the class URIConverter method finalize.

public Stream<PackageSourceEntry> finalize(URI u, PackageID packageID) {
    String orgName = packageID.getOrgName().getValue();
    String pkgName = packageID.getName().getValue();
    Path destDirPath = HomeRepoUtils.createAndGetHomeReposPath().resolve(Paths.get("repo", orgName, pkgName));
    createDirectory(destDirPath);
    try {
        String fullPkgPath = orgName + "/" + pkgName;
        executor.execute(pullBalxLocation, u.toString(), destDirPath.toString(), fullPkgPath, File.separator);
        // TODO Simplify using ZipRepo
        Patten pattern = new Patten(Patten.WILDCARD_DIR, Patten.path(pkgName + ".zip"), Patten.path("src"), Patten.WILDCARD_SOURCE);
        return pattern.convertToSources(new ZipConverter(destDirPath), packageID);
    } catch (Exception ignore) {
    }
    return Stream.of();
}
Also used : Path(java.nio.file.Path) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URISyntaxException(java.net.URISyntaxException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException)

Example 13 with Patten

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

Example 14 with Patten

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

the class PathConverterIntegrationTest method testBalSearch.

@Test
public void testBalSearch() {
    Patten patten = new Patten(path("very"), Patten.WILDCARD_SOURCE);
    PathConverter subject = new PathConverter(tempDirectory);
    Stream<Path> pathStream = patten.convert(subject);
    List<Path> paths = pathStream.collect(Collectors.toList());
    Assert.assertEquals(paths.size(), 1);
    Assert.assertEquals(paths.get(0).toString(), tempFile.toString());
}
Also used : Path(java.nio.file.Path) PathConverter(org.wso2.ballerinalang.compiler.packaging.converters.PathConverter) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) Test(org.testng.annotations.Test)

Example 15 with Patten

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

the class PattenTest method testReduction.

@Test
public void testReduction() {
    Converter<String> mock = mockResolver("root-dir", (a, b) -> a + " > " + b, null, null);
    Patten subject = new Patten(path("hello", "world"));
    List<String> strings = subject.convert(mock).collect(Collectors.toList());
    Assert.assertEquals(strings, Collections.singletonList("root-dir > hello > world"));
}
Also used : Patten(org.wso2.ballerinalang.compiler.packaging.Patten) Test(org.testng.annotations.Test)

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