use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.
the class InitCommand method execute.
@Override
public void execute() {
PrintStream out = System.out;
// Get source root path.
Path projectPath = Paths.get(System.getProperty(USER_DIR));
Scanner scanner = new Scanner(System.in, Charset.defaultCharset().name());
try {
Manifest manifest = null;
if (helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(parentCmdParser, "init");
outStream.println(commandUsageInfo);
return;
}
List<SrcFile> sourceFiles = new ArrayList<>();
if (interactiveFlag) {
// Check if Ballerina.toml file needs to be created.
out.print("Create Ballerina.toml [yes/y, no/n]: (y) ");
String createToml = scanner.nextLine().trim();
if (createToml.equalsIgnoreCase("yes") || createToml.equalsIgnoreCase("y") || createToml.isEmpty()) {
manifest = new Manifest();
String defaultOrg = guessOrgName();
// Get org name.
out.print("Organization name: (" + defaultOrg + ") ");
String orgName = scanner.nextLine().trim();
manifest.setName(orgName.isEmpty() ? defaultOrg : orgName);
String version;
do {
out.print("Version: (" + DEFAULT_VERSION + ") ");
version = scanner.nextLine().trim();
version = version.isEmpty() ? DEFAULT_VERSION : version;
} while (!validateVersion(out, version));
manifest.setVersion(version);
}
String srcInput;
boolean validInput = false;
boolean first = true;
do {
if (first) {
out.print("Ballerina source [service/s, main/m]: (s) ");
} else {
out.print("Ballerina source [service/s, main/m, finish/f]: (f) ");
}
srcInput = scanner.nextLine().trim();
if (srcInput.equalsIgnoreCase("service") || srcInput.equalsIgnoreCase("s") || (first && srcInput.isEmpty())) {
out.print("Package for the service : (no package) ");
String packageName = scanner.nextLine().trim();
SrcFile srcFile = new SrcFile(packageName, SrcFile.SrcFileType.SERVICE);
sourceFiles.add(srcFile);
} else if (srcInput.equalsIgnoreCase("main") || srcInput.equalsIgnoreCase("m")) {
out.print("Package for the main : (no package) ");
String packageName = scanner.nextLine().trim();
SrcFile srcFile = new SrcFile(packageName, SrcFile.SrcFileType.MAIN);
sourceFiles.add(srcFile);
} else if (srcInput.isEmpty() || srcInput.equalsIgnoreCase("f")) {
validInput = true;
} else {
out.println("Invalid input");
}
first = false;
} while (!validInput);
out.print("\n");
} else {
manifest = new Manifest();
manifest.setName(guessOrgName());
manifest.setVersion(DEFAULT_VERSION);
if (isDirEmpty(projectPath)) {
SrcFile srcFile = new SrcFile("", SrcFile.SrcFileType.SERVICE);
sourceFiles.add(srcFile);
}
}
InitHandler.initialize(projectPath, manifest, sourceFiles);
out.println("Ballerina project initialized");
} catch (IOException e) {
out.println("Error occurred while creating project: " + e.getMessage());
}
}
use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.
the class InitHandlerTest method testGeneratedSourceContent.
@Test(description = "Test if the generated source are runnable.", enabled = false)
public void testGeneratedSourceContent() throws IOException {
Manifest manifest = new Manifest();
manifest.setName("wso2");
manifest.setVersion("1.0.0");
SrcFile packageFile = new SrcFile("wso2_abc", SrcFile.SrcFileType.SERVICE);
SrcFile mainFile = new SrcFile("main_runner", SrcFile.SrcFileType.MAIN);
List<SrcFile> srcFiles = new ArrayList<>();
srcFiles.add(packageFile);
srcFiles.add(mainFile);
InitHandler.initialize(tmpDir, manifest, srcFiles);
Path tomlFile = tmpDir.resolve("Ballerina.toml");
byte[] tomlFileBytes = Files.readAllBytes(tomlFile);
String tomlFileContents = new String(tomlFileBytes, Charset.defaultCharset());
Assert.assertTrue(tomlFileContents.contains("[project]"), "Project header missing in Ballerina.toml");
Assert.assertTrue(tomlFileContents.contains("org-name = \"" + manifest.getName() + "\""), "Org-Name missing in Ballerina.toml");
Assert.assertTrue(tomlFileContents.contains("version = \"" + manifest.getVersion() + "\""), "Version missing in Ballerina.toml");
Path servicesBalFile = tmpDir.resolve(packageFile.getName()).resolve("services.bal");
Path mainBalFile = tmpDir.resolve(mainFile.getName());
Assert.assertTrue(Files.exists(servicesBalFile), "Package not generated.");
Assert.assertTrue(Files.exists(mainBalFile), "Main file not generated.");
CompileResult serviceFileCompileResult = BCompileUtil.compile(servicesBalFile.getParent().toString());
Assert.assertFalse(serviceFileCompileResult.getDiagnostics().length > 0, "Errors found in the generated service files.");
CompileResult mainFileCompileResult = BCompileUtil.compile(mainBalFile.toString());
Assert.assertFalse(mainFileCompileResult.getDiagnostics().length > 0, "Errors found in the generated service files.");
}
use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.
the class ManifestProcessor method getManifest.
/**
* Get the manifest object by passing the ballerina toml file.
*
* @param charStream toml file content as a char stream
* @return manifest object
*/
private static Manifest getManifest(CharStream charStream) {
Manifest manifest = new Manifest();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new ManifestBuildListener(manifest), TomlProcessor.parseTomlContent(charStream));
return manifest;
}
use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.
the class ManifestProcessorTest method testMultiplePatches.
@Test(description = "Multiple patches added to the patches section has an effect")
public void testMultiplePatches() throws IOException {
Manifest manifest = ManifestProcessor.parseTomlContentFromString("[patches] \n " + "string-utils = {version = \"1.5.2\" } \n " + "jquery = { version = \"2.2.1\" } \n");
Assert.assertEquals(manifest.getPatches().get(0).getPackageName(), "string-utils");
Assert.assertEquals(manifest.getPatches().get(0).getVersion(), "1.5.2");
Assert.assertEquals(manifest.getPatches().get(1).getPackageName(), "jquery");
Assert.assertEquals(manifest.getPatches().get(1).getVersion(), "2.2.1");
}
use of org.ballerinalang.toml.model.Manifest in project ballerina by ballerina-lang.
the class ManifestProcessorTest method testAttributeWithMultilineComments.
@Test(description = "Attribute with multiline comments doesn't have an effect")
public void testAttributeWithMultilineComments() throws IOException {
Manifest manifest = ManifestProcessor.parseTomlContentFromString("[project] \n" + "# Name of the package \n #This is the package congif section \n org-name = \"foo/string\"");
Assert.assertEquals(manifest.getName(), "foo/string");
}
Aggregations