diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java index f26e709e5fa5..5b0af5025dc9 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java @@ -278,6 +278,7 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() // clean the target directory(projects only) .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) + // Run build tools .addTask(new RunBallerinaPreBuildToolsTask(outStream)) // resolve maven dependencies in Ballerina.toml .addTask(new ResolveMavenDependenciesTask(outStream)) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java index 92dfcef9a32a..3601c443a8e8 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java @@ -23,6 +23,7 @@ import io.ballerina.cli.task.CreateDocsTask; import io.ballerina.cli.task.CreateTargetDirTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.projects.BuildOptions; import io.ballerina.projects.Project; import io.ballerina.projects.ProjectEnvironmentBuilder; @@ -181,6 +182,7 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new CreateTargetDirTask()) // create target directory. + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) // run build tools .addTask(new ResolveMavenDependenciesTask(outStream)) // resolve maven dependencies in Ballerina.toml .addTask(new CompileTask(outStream, errStream)) // compile the modules .addTask(new CreateDocsTask(outStream, outputPath)) // creates API documentation diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/GraphCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/GraphCommand.java index 0671757c0a41..67d86dbe604b 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/GraphCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/GraphCommand.java @@ -23,6 +23,7 @@ import io.ballerina.cli.task.CleanTargetDirTask; import io.ballerina.cli.task.CreateDependencyGraphTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.cli.utils.FileUtils; import io.ballerina.projects.BuildOptions; import io.ballerina.projects.Project; @@ -109,6 +110,7 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new CleanTargetDirTask(true, false), isSingleFileProject()) + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) .addTask(new ResolveMavenDependenciesTask(outStream)) .addTask(new CreateDependencyGraphTask(outStream, errStream)) .build(); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java index e950cad858ab..3a55e7909a15 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java @@ -7,6 +7,7 @@ import io.ballerina.cli.task.CreateBalaTask; import io.ballerina.cli.task.DumpBuildTimeTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.cli.utils.BuildTime; import io.ballerina.cli.utils.FileUtils; import io.ballerina.projects.BuildOptions; @@ -247,6 +248,7 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) .addTask(new ResolveMavenDependenciesTask(outStream)) .addTask(new CompileTask(outStream, errStream, true, isPackageModified, buildOptions.enableCache())) .addTask(new CreateBalaTask(outStream)) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java index 344f4979821e..00a4cf1cafc9 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java @@ -25,6 +25,7 @@ import io.ballerina.cli.task.CreateExecutableTask; import io.ballerina.cli.task.DumpBuildTimeTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.cli.task.RunProfilerTask; import io.ballerina.cli.utils.FileUtils; import io.ballerina.projects.BuildOptions; @@ -194,6 +195,7 @@ private TaskExecutor createTaskExecutor(boolean isPackageModified, String[] args boolean isSingleFileBuild) { return new TaskExecutor.TaskBuilder() .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) .addTask(new ResolveMavenDependenciesTask(outStream)) .addTask(new CompileTask(outStream, errStream, false, isPackageModified, buildOptions.enableCache())) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java index 4dbde7d5ce63..9f0616ebe246 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java @@ -24,6 +24,7 @@ import io.ballerina.cli.task.CompileTask; import io.ballerina.cli.task.DumpBuildTimeTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.cli.task.RunExecutableTask; import io.ballerina.cli.utils.BuildTime; import io.ballerina.cli.utils.FileUtils; @@ -233,6 +234,8 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() // clean target dir for projects .addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild) + // Run build tools + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) // resolve maven dependencies in Ballerina.toml .addTask(new ResolveMavenDependenciesTask(outStream)) // compile the modules diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java index 17cee10e564c..93f31170dcbe 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java @@ -23,6 +23,7 @@ import io.ballerina.cli.task.CompileTask; import io.ballerina.cli.task.DumpBuildTimeTask; import io.ballerina.cli.task.ResolveMavenDependenciesTask; +import io.ballerina.cli.task.RunBallerinaPreBuildToolsTask; import io.ballerina.cli.task.RunNativeImageTestTask; import io.ballerina.cli.task.RunTestsTask; import io.ballerina.cli.utils.BuildTime; @@ -341,6 +342,7 @@ public void execute() { TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new CleanTargetCacheDirTask(), isSingleFile) // clean the target cache dir(projects only) + .addTask(new RunBallerinaPreBuildToolsTask(outStream)) // run build tools .addTask(new ResolveMavenDependenciesTask(outStream)) // resolve maven dependencies in Ballerina.toml // compile the modules .addTask(new CompileTask(outStream, errStream, false, isPackageModified, buildOptions.enableCache())) diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/DocCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/DocCommandTest.java index ec3f3bc12fee..0c9f249c2d57 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/DocCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/DocCommandTest.java @@ -30,6 +30,8 @@ import java.nio.file.Paths; import java.util.Objects; +import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; + /** * Doc command tests. * @@ -81,4 +83,22 @@ public void testDocCommandWithCustomTarget() throws IOException { Files.delete(customTargetPath.resolve("apidocs").resolve("foo").resolve("winery").resolve("0.1.0") .resolve("index.html")); } + + @Test(description = "Test doc command on a ballerina project with build tool execution.") + public void testDocCommandWithBuildTool() throws IOException { + Path projectPath = this.testResources.resolve("doc_project_with_build_tool"); + System.setProperty("user.dir", projectPath.toString()); + DocCommand docCommand = new DocCommand(this.printStream, this.printStream, false); + docCommand.execute(); + + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("doc-with-build-tool.txt")); + + Assert.assertTrue(Files.exists(this.testResources.resolve("doc_project_with_build_tool").resolve("target") + .resolve("apidocs").resolve("foo").resolve("winery").resolve("0.1.0").resolve("index.html"))); + + Files.delete(this.testResources.resolve("doc_project_with_build_tool").resolve("target") + .resolve("apidocs").resolve("foo").resolve("winery").resolve("0.1.0").resolve("index.html")); + } } diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/GraphCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/GraphCommandTest.java index 0f82b3f03c0b..05ba384604ab 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/GraphCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/GraphCommandTest.java @@ -47,13 +47,12 @@ */ public class GraphCommandTest extends BaseCommandTest { private Path testResources; - private Path projectsWithDependencyConflicts; @BeforeClass public void setup() throws IOException { super.setup(); this.testResources = super.tmpDir.resolve("build-test-resources"); - projectsWithDependencyConflicts = this.testResources.resolve("projectsWithDependencyConflicts") + Path projectsWithDependencyConflicts = this.testResources.resolve("projectsWithDependencyConflicts") .resolve("package_p"); try { copyTestResourcesToTmpDir(); @@ -105,6 +104,19 @@ public void testPrintGraphForBalProjectWithNoDependencies() throws IOException { Assert.assertEquals(actualLog, expectedLog); } + @Test(description = "Print the dependency graph of a ballerina project with build tools") + public void testPrintGraphForBalProjectWithBuildTools() throws IOException { + Path balProjectPath = this.testResources.resolve("proper-build-tool"); + + GraphCommand graphCommand = new GraphCommand(balProjectPath, printStream, printStream, false); + new CommandLine(graphCommand).parseArgs(balProjectPath.toString()); + graphCommand.execute(); + + String actualLog = readFormattedOutput(); + String expectedLog = CommandOutputUtils.getOutput("graph-with-build-tool.txt"); + Assert.assertEquals(actualLog, expectedLog); + } + @Test(description = "Print the dependency graph of a valid ballerina project with dependencies") public void testPrintGraphForBalProjectWithDependencies() throws IOException { Path balProjectPath = this.testResources.resolve("projectsForDumpGraph").resolve("package_a"); diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java index d25063551c48..ddbc99ac4731 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java @@ -24,6 +24,7 @@ import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML; import static io.ballerina.projects.util.ProjectConstants.RESOURCE_DIR_NAME; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** * Pack command tests. @@ -251,6 +252,20 @@ public void testPackageWithTestOnlyJavaImports() throws IOException { .toFile().exists()); } + @Test(description = "Pack a project with a build tool execution") + public void testPackProjectWithBuildTool() throws IOException { + Path projectPath = this.testResources.resolve("proper-build-tool"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); + new CommandLine(packCommand).parseArgs(); + packCommand.execute(); + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("pack-project-with-build-tool.txt")); + Assert.assertTrue(projectPath.resolve("target").resolve("bala").resolve("foo-winery-any-0.1.0.bala") + .toFile().exists()); + } + @Test(description = "Pack a package with an empty Dependencies.toml") public void testPackageWithEmptyDependenciesToml() throws IOException { Path projectPath = this.testResources.resolve("validProjectWithDependenciesToml"); diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ProfileCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ProfileCommandTest.java index 3666ff2fd7ea..69c2af8fc44d 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ProfileCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ProfileCommandTest.java @@ -93,6 +93,30 @@ public void testRunBalProjectWithProfileFlag() throws IOException { ProjectUtils.deleteDirectory(projectPath.resolve("target")); } + @Test(description = "Profile a ballerina project with build tools") + public void testRunBalProjectWithProfileFlagWithBuildTools() throws IOException { + Path projectPath = this.testResources.resolve("projectForProfile").resolve("package_b"); + System.setProperty("user.dir", projectPath.toString()); + + java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); + System.setOut(new java.io.PrintStream(out)); + + ProfileCommand profileCommand = new ProfileCommand(projectPath, printStream, false); + profileCommand.execute(); + String buildLog = readOutput(true).replaceAll("\r", "").strip(); + Assert.assertEquals(buildLog, getOutput("profile-project-with-build-tool.txt")); + Path htmlPath = projectPath.resolve("target").resolve("profiler").resolve("ProfilerReport.html"); + Assert.assertTrue(htmlPath.toFile().exists()); + try { + String htmlContent = Files.readString(htmlPath); + Assert.assertTrue(htmlContent.contains("foo/package_b/0/main.main")); + Assert.assertTrue(htmlContent.contains("foo/package_b/0/$_init.$moduleInit")); + } catch (IOException e) { + Assert.fail("Error reading html file"); + } + ProjectUtils.deleteDirectory(projectPath.resolve("target")); + } + @Test(description = "Test profile command with help") public void testProfileCommandAndHelp() throws IOException { String[] args = {"--help"}; diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/RunCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/RunCommandTest.java index 2bd17c31445b..1c69db136a70 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/RunCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/RunCommandTest.java @@ -27,6 +27,7 @@ import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** * Run command tests. @@ -167,6 +168,18 @@ public void testRunValidBalProjectFromProjectDir() throws IOException { Files.delete(tempFile); } + @Test(description = "Run a project with a build tool execution") + public void testRunProjectWithBuildTool() throws IOException { + Path projectPath = this.testResources.resolve("proper-build-tool"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + RunCommand runCommand = new RunCommand(projectPath, printStream, false); + new CommandLine(runCommand).parseArgs(); + runCommand.execute(); + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("run-project-with-build-tool.txt")); + } + @Test(description = "Run a valid ballerina project with invalid argument") public void testRunCommandWithInvalidArg() { Path projectPath = this.testResources.resolve("validRunProject"); diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/TestCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/TestCommandTest.java index 69e164530728..8c8828dc0eb1 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/TestCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/TestCommandTest.java @@ -57,6 +57,7 @@ import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; import static io.ballerina.projects.util.ProjectConstants.RESOURCE_DIR_NAME; import static io.ballerina.projects.util.ProjectConstants.TARGET_DIR_NAME; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** * Test command tests. @@ -184,6 +185,18 @@ public void testTestBalProjectFromADifferentDirectory() throws IOException { Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("test-project.txt")); } + @Test(description = "Test a project with a build tool execution") + public void testTestProjectWithBuildTool() throws IOException { + Path projectPath = this.testResources.resolve("proper-build-tool-with-tests"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false); + new CommandLine(testCommand).parseArgs(); + testCommand.execute(); + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("test-project-with-build-tool.txt")); + } + @Test(description = "Test the heap dump generation for a project with an OOM error") public void testHeapDumpGenerationForOOM() { Path projectPath = this.testResources.resolve("oom-project"); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/doc-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/doc-with-build-tool.txt new file mode 100644 index 000000000000..b3769c1cf9ef --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/doc-with-build-tool.txt @@ -0,0 +1,8 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 +Generating API Documentation +Saved to: apidocs diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-with-build-tool.txt new file mode 100644 index 000000000000..aa14aa8d688c --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-with-build-tool.txt @@ -0,0 +1,11 @@ +Executing Build Tools + openapi(generate-delivery-client) + + +digraph "foo/winery:0.1.0" { + node [shape=record] + "foo/winery" [label="<0.1.0> foo/winery:0.1.0"]; + + // Edges + +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-build-tool.txt new file mode 100644 index 000000000000..552def66ca7b --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-build-tool.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 + +Creating bala + target/bala/foo-winery-any-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-project-with-build-tool.txt new file mode 100644 index 000000000000..c40c06d9d6e3 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-project-with-build-tool.txt @@ -0,0 +1,8 @@ +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/package_b:0.1.0 + +Generating executable + target/bin/package_b.jar \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-project-with-build-tool.txt new file mode 100644 index 000000000000..6c5704aca720 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-project-with-build-tool.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 + +Running executable + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-project-with-build-tool.txt new file mode 100644 index 000000000000..2db75311164b --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-project-with-build-tool.txt @@ -0,0 +1,6 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/doc-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/doc-with-build-tool.txt new file mode 100644 index 000000000000..b3769c1cf9ef --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/doc-with-build-tool.txt @@ -0,0 +1,8 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 +Generating API Documentation +Saved to: apidocs diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-with-build-tool.txt new file mode 100644 index 000000000000..aa14aa8d688c --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-with-build-tool.txt @@ -0,0 +1,11 @@ +Executing Build Tools + openapi(generate-delivery-client) + + +digraph "foo/winery:0.1.0" { + node [shape=record] + "foo/winery" [label="<0.1.0> foo/winery:0.1.0"]; + + // Edges + +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-build-tool.txt new file mode 100644 index 000000000000..552def66ca7b --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-build-tool.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 + +Creating bala + target/bala/foo-winery-any-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-project-with-build-tool.txt new file mode 100644 index 000000000000..c40c06d9d6e3 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-project-with-build-tool.txt @@ -0,0 +1,8 @@ +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/package_b:0.1.0 + +Generating executable + target/bin/package_b.jar \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-project-with-build-tool.txt new file mode 100644 index 000000000000..6c5704aca720 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-project-with-build-tool.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 + +Running executable + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-project-with-build-tool.txt new file mode 100644 index 000000000000..2db75311164b --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-project-with-build-tool.txt @@ -0,0 +1,6 @@ + +Executing Build Tools + openapi(generate-delivery-client) + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/Ballerina.toml new file mode 100644 index 000000000000..3a223747894e --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/Ballerina.toml @@ -0,0 +1,10 @@ +[package] +org = "foo" +name = "winery" +version = "0.1.0" + +[[tool.openapi]] +id = "generate-delivery-client" +filePath = "delivery.json" +targetModule = "delivery" +options.mode = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/math.bal b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/math.bal new file mode 100644 index 000000000000..e016155c97a8 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/math.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +# Calculates the value of the 'a' raised to the power of 'b'. +# ```ballerina +# float aPowerB = math:pow(3.2, 2.4); +# ``` +# +# + a - Base value +# + b - Exponential value +# + return - Calculated exponential value +public isolated function pow(float a, float b) returns float { + return 0; +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/modules/world/person.bal b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/modules/world/person.bal new file mode 100644 index 000000000000..0806ea4f8f43 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/doc_project_with_build_tool/modules/world/person.bal @@ -0,0 +1,49 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +# Represents a person object. +# +# + name - Name of the person +# + age - Age of the person in years +# + address - Address of the person +# + wealth - Account balance of the person +public class Person { + public string name = ""; + public int age=5; + public string address = ""; + public float wealth = 0; + + # Gets invoked to initialize the `Person` object. + # + # + name - Name of the person for the constructor + # + age - Age of the person for the constructor + public function init(string name, int age) { + } + + # Get the address of the person. + # + # + return - New address of the person + public function getAddress() returns string { + return self.address ; + } + + # Add wealth of the person. + # + # + amt - Amount to be added + # + rate - Interest rate + public function addWealth(int[] amt, float rate=1.5) { + } +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/Ballerina.toml new file mode 100644 index 000000000000..e87f2b421aa8 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/Ballerina.toml @@ -0,0 +1,10 @@ +[package] +org = "foo" +name = "package_b" +version = "0.1.0" + +[[tool.openapi]] +id = "generate-delivery-client" +filePath = "delivery.json" +targetModule = "delivery" +options.mode = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/main.bal new file mode 100644 index 000000000000..b21fd7c08fcd --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/main.bal @@ -0,0 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import foo/package_b.mod_a1; + +public function main() { + mod_a1:func1(); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/modules/mod_a1/mod1.bal b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/modules/mod_a1/mod1.bal new file mode 100644 index 000000000000..13165d2074d1 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectForProfile/package_b/modules/mod_a1/mod1.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +boolean num = float:isFinite(1.0); +int a = 10; + +public function func1() { + if (num) { + a = 20; + } else { + a = 30; + } +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/Ballerina.toml new file mode 100644 index 000000000000..3a223747894e --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/Ballerina.toml @@ -0,0 +1,10 @@ +[package] +org = "foo" +name = "winery" +version = "0.1.0" + +[[tool.openapi]] +id = "generate-delivery-client" +filePath = "delivery.json" +targetModule = "delivery" +options.mode = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/main.bal new file mode 100644 index 000000000000..4022ea49795c --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/main.bal @@ -0,0 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function main() { + return; +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/tests/main_tests.bal b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/tests/main_tests.bal new file mode 100644 index 000000000000..27292e90b584 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/proper-build-tool-with-tests/tests/main_tests.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +public function testRunMain() { + test:assertTrue(true, msg = "Failed!"); +}