Search in sources :

Example 16 with Manifest

use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.

the class ManifestProcessorTest method testAttributeWithSingleComment.

@Test(description = "Attribute with single comment doesn't have an effect")
public void testAttributeWithSingleComment() throws IOException {
    Manifest manifest = ManifestProcessor.parseTomlContentFromString("[project] \n" + "#Name of the package \n org-name = \"foo\"");
    Assert.assertEquals(manifest.getName(), "foo");
}
Also used : Manifest(org.ballerinalang.toml.model.Manifest) Test(org.testng.annotations.Test)

Example 17 with Manifest

use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.

the class ManifestProcessorTest method testVersion.

@Test(description = "Version in package section has an effect")
public void testVersion() throws IOException {
    Manifest manifest = ManifestProcessor.parseTomlContentFromString("[project]\n" + "version = \"1.0.0\"");
    Assert.assertEquals(manifest.getVersion(), "1.0.0");
}
Also used : Manifest(org.ballerinalang.toml.model.Manifest) Test(org.testng.annotations.Test)

Example 18 with Manifest

use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.

the class TomlFileToManifestTest method testTomlFile.

@Test(description = "Test which covers all the attributes tested above")
public void testTomlFile() throws IOException {
    Manifest manifest = ManifestProcessor.parseTomlContentFromFile(resource_dir + "example.toml");
    Assert.assertEquals(manifest.getName(), "foo");
    Assert.assertEquals(manifest.getVersion(), "1.0.0");
    Assert.assertEquals(manifest.getDescription(), "This is a sample description which contains " + "information");
    Assert.assertEquals(manifest.getDocumentationURL(), "https://ballerinalang.org/docs/api/0.95.5/");
    Assert.assertEquals(manifest.getHomepageURL(), "https://ballerinalang.org/");
    Assert.assertEquals(manifest.getRepositoryURL(), "https://github.com/ballerinalang/ballerina");
    Assert.assertEquals(manifest.getReadmeFilePath(), "https://github.com/ballerinalang/composer/blob/" + "master/README.md");
    Assert.assertEquals(manifest.getAuthors().get(0), "tyler@wso2.com");
    Assert.assertEquals(manifest.getAuthors().get(1), "manu@wso2.com");
    Assert.assertEquals(manifest.getKeywords().get(0), "ballerina");
    Assert.assertEquals(manifest.getKeywords().get(2), "crypto");
    Assert.assertEquals(manifest.getKeywords().size(), 3);
    Assert.assertEquals(manifest.getDependencies().size(), 6);
    Assert.assertEquals(manifest.getDependencies().get(0).getPackageName(), "synchapi");
    Assert.assertEquals(manifest.getDependencies().get(0).getVersion(), "0.9.2");
    Assert.assertEquals(manifest.getDependencies().get(1).getLocation(), "src/libc");
    Assert.assertEquals(manifest.getDependencies().get(1).getPackageName(), "libc");
    Assert.assertEquals(manifest.getDependencies().get(2).getPackageName(), "string-utils");
    Assert.assertEquals(manifest.getDependencies().get(3).getLocation(), null);
    Assert.assertEquals(manifest.getDependencies().get(4).getPackageName(), "toml");
    Assert.assertEquals(manifest.getDependencies().get(4).getVersion(), "0.4.6");
    Assert.assertEquals(manifest.getDependencies().get(5).getLocation(), "src/core/jobapi");
    Assert.assertEquals(manifest.getDependencies().get(5).getPackageName(), "jobapi.core");
}
Also used : Manifest(org.ballerinalang.toml.model.Manifest) Test(org.testng.annotations.Test)

Example 19 with Manifest

use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.

the class TextDocumentServiceUtil method getProjectManifestDetails.

/**
 * Get the project manifest details.
 *
 * @param sourceRoot source root of the project dir
 * @return {@link String} organization name
 */
public static Manifest getProjectManifestDetails(String sourceRoot) {
    Path tomlFile = Paths.get(sourceRoot, ProjectDirConstants.MANIFEST_FILE_NAME);
    Manifest manifest = new Manifest();
    if (Files.exists(tomlFile)) {
        try {
            manifest = ManifestProcessor.parseTomlContentFromFile(tomlFile.toString());
        } catch (IOException e) {
            manifest = new Manifest();
        }
    }
    return manifest;
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) Manifest(org.ballerinalang.toml.model.Manifest)

Example 20 with Manifest

use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.

the class PushUtils method pushPackages.

/**
 * Push/Uploads packages to the central repository.
 *
 * @param packageName   path of the package folder to be pushed
 * @param installToRepo if it should be pushed to central or home
 */
public static void pushPackages(String packageName, String installToRepo) {
    String accessToken = getAccessTokenOfCLI();
    Manifest manifest = readManifestConfigurations();
    if (manifest.getName() == null && manifest.getVersion() == null) {
        throw new BLangCompilerException("An org-name and package version is required when pushing. " + "This is not specified in Ballerina.toml inside the project");
    }
    String orgName = manifest.getName();
    String version = manifest.getVersion();
    PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
    Path prjDirPath = Paths.get(".").toAbsolutePath().normalize().resolve(ProjectDirConstants.DOT_BALLERINA_DIR_NAME);
    // Get package path from project directory path
    Path pkgPathFromPrjtDir = Paths.get(prjDirPath.toString(), "repo", Names.ANON_ORG.getValue(), packageName, Names.DEFAULT_VERSION.getValue(), packageName + ".zip");
    if (installToRepo == null) {
        if (accessToken == null) {
            // TODO: get bal home location dynamically
            throw new BLangCompilerException("Access token is missing in ~/ballerina_home/Settings.toml file.\n" + "Please visit https://central.ballerina.io/cli-token");
        }
        // Push package to central
        String resourcePath = resolvePkgPathInRemoteRepo(packageID);
        URI balxPath = URI.create(String.valueOf(PushUtils.class.getClassLoader().getResource("ballerina.push.balx")));
        String msg = orgName + "/" + packageName + ":" + version + " [project repo -> central]";
        ExecutorUtils.execute(balxPath, accessToken, resourcePath, pkgPathFromPrjtDir.toString(), msg);
    } else {
        if (!installToRepo.equals("home")) {
            throw new BLangCompilerException("Unknown repository provided to push the package");
        }
        Path balHomeDir = HomeRepoUtils.createAndGetHomeReposPath();
        Path targetDirectoryPath = Paths.get(balHomeDir.toString(), "repo", orgName, packageName, version, packageName + ".zip");
        if (Files.exists(targetDirectoryPath)) {
            throw new BLangCompilerException("Ballerina package exists in the home repository");
        } else {
            try {
                Files.createDirectories(targetDirectoryPath);
                Files.copy(pkgPathFromPrjtDir, targetDirectoryPath, StandardCopyOption.REPLACE_EXISTING);
                outStream.println(orgName + "/" + packageName + ":" + version + " [project repo -> home repo]");
            } catch (IOException e) {
                throw new BLangCompilerException("Error occurred when creating directories in the home repository");
            }
        }
    }
}
Also used : Path(java.nio.file.Path) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException) PackageID(org.ballerinalang.model.elements.PackageID) IOException(java.io.IOException) Manifest(org.ballerinalang.toml.model.Manifest) URI(java.net.URI) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

Manifest (org.ballerinalang.toml.model.Manifest)29 Test (org.testng.annotations.Test)25 Path (java.nio.file.Path)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 SrcFile (org.ballerinalang.packerina.init.models.SrcFile)2 PrintStream (java.io.PrintStream)1 URI (java.net.URI)1 Scanner (java.util.Scanner)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)1 CompileResult (org.ballerinalang.launcher.util.CompileResult)1 PackageID (org.ballerinalang.model.elements.PackageID)1 Name (org.wso2.ballerinalang.compiler.util.Name)1