From 753bf96c7792e13aa3885a84cb201c81fe59fd58 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Wed, 24 Apr 2024 10:07:58 +0530 Subject: [PATCH] Delay empty project check to CompileTask --- .../io/ballerina/cli/cmd/BuildCommand.java | 9 --- .../io/ballerina/cli/cmd/GraphCommand.java | 9 +-- .../io/ballerina/cli/cmd/PackCommand.java | 10 --- .../io/ballerina/cli/cmd/ProfileCommand.java | 7 -- .../java/io/ballerina/cli/cmd/RunCommand.java | 8 --- .../io/ballerina/cli/cmd/TestCommand.java | 8 --- .../io/ballerina/cli/task/CompileTask.java | 15 ++++ .../cli/task/CreateDependencyGraphTask.java | 5 +- .../ballerina/cli/cmd/BuildCommandTest.java | 68 ++++++++++++++----- .../ballerina/cli/cmd/GraphCommandTest.java | 64 ++++++++++++++--- .../io/ballerina/cli/cmd/PackCommandTest.java | 48 ++++++++++--- .../ballerina/cli/cmd/ProfileCommandTest.java | 52 +++++++++++++- .../io/ballerina/cli/cmd/RunCommandTest.java | 32 ++++++++- .../io/ballerina/cli/cmd/TestCommandTest.java | 29 +++++++- .../unix/build-empty-nondefault-module.txt | 2 +- .../unix/build-empty-package.txt | 2 +- .../build-empty-project-with-build-tools.txt | 9 +++ ...ild-empty-project-with-compiler-plugin.txt | 2 +- .../graph-empty-project-with-build-tools.txt | 11 +++ .../unix/pack-empty-package.txt | 2 +- .../pack-empty-project-with-build-tools.txt | 9 +++ ...profile-empty-project-with-build-tools.txt | 9 +++ .../run-empty-project-with-build-tools.txt | 9 +++ .../test-empty-project-with-build-tools.txt | 7 ++ .../windows/build-empty-nondefault-module.txt | 2 +- .../windows/build-empty-package.txt | 2 +- .../build-empty-project-with-build-tools.txt | 9 +++ ...ild-empty-project-with-compiler-plugin.txt | 2 +- .../graph-empty-project-with-build-tools.txt | 11 +++ .../windows/pack-empty-package.txt | 2 +- .../pack-empty-project-with-build-tools.txt | 9 +++ ...profile-empty-project-with-build-tools.txt | 9 +++ .../run-empty-project-with-build-tools.txt | 9 +++ .../test-empty-project-with-build-tools.txt | 7 ++ .../emptyProjectWithBuildTool/Ballerina.toml | 10 +++ .../Dependencies.toml | 23 +++++++ .../emptyProjectWithBuildTool/delivery.json | 0 37 files changed, 420 insertions(+), 101 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-empty-project-with-build-tools.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Dependencies.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/delivery.json 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 a42387625891..27ad6ce675a4 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 @@ -33,7 +33,6 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import org.ballerinalang.toml.exceptions.SettingsTomlException; import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; @@ -256,14 +255,6 @@ public void execute() { } } - // If project is empty - if (ProjectUtils.isProjectEmpty(project)) { - CommandUtil.printError(this.errStream, "package is empty. Please add at least one .bal file.", null, - false); - CommandUtil.exitError(this.exitWhenFinish); - return; - } - // Validate Settings.toml file try { RepoUtils.readSettings(); 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 92b2412cc01c..debe72d8224d 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 @@ -31,7 +31,6 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import org.ballerinalang.toml.exceptions.SettingsTomlException; import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; @@ -65,7 +64,7 @@ public class GraphCommand implements BLauncherCmd { private boolean helpFlag; @CommandLine.Option(names = {"--offline"}, description = "Print the dependency graph offline without downloading " + - "dependencies.", defaultValue = "false") + "dependencies.") private boolean offline; @CommandLine.Option(names = "--sticky", description = "stick to exact versions locked (if exists)", @@ -100,14 +99,8 @@ public void execute() { return; } - if (ProjectUtils.isProjectEmpty(this.project)) { - printErrorAndExit("package is empty. Please add at least one .bal file."); - return; - } - validateSettingsToml(); - TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() .addTask(new CleanTargetDirTask(true, false), isSingleFileProject()) .addTask(new RunBuildToolsTask(outStream), isSingleFileProject()) 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 5fc2a1b755b8..bfd7caca362c 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 @@ -15,7 +15,6 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import io.ballerina.toml.semantic.TomlType; import io.ballerina.toml.semantic.ast.TomlTableNode; import org.ballerinalang.toml.exceptions.SettingsTomlException; @@ -160,15 +159,6 @@ public void execute() { return; } - // If project is empty - if (ProjectUtils.isProjectEmpty(project) && project.currentPackage().compilerPluginToml().isEmpty() && - project.currentPackage().balToolToml().isEmpty()) { - CommandUtil.printError(this.errStream, "package is empty. Please add at least one .bal file.", null, - false); - CommandUtil.exitError(this.exitWhenFinish); - return; - } - // Check `[package]` section is available when compile if (project.currentPackage().ballerinaToml().get().tomlDocument().toml().getTable("package") .isEmpty()) { 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 da76ac2defc7..1522c331f9e5 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 @@ -35,7 +35,6 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import picocli.CommandLine; import java.io.PrintStream; @@ -118,12 +117,6 @@ public void execute() { CommandUtil.exitError(this.exitWhenFinish); return; } - if (ProjectUtils.isProjectEmpty(project)) { - CommandUtil.printError(this.errStream, "package is empty. Please add at least one .bal file.", - null, false); - CommandUtil.exitError(this.exitWhenFinish); - return; - } boolean isPackageModified = isProjectUpdated(project); TaskExecutor taskExecutor = createTaskExecutor(isPackageModified, args, buildOptions, project.kind() == ProjectKind.SINGLE_FILE_PROJECT); 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 debd61345784..d6823eddaa24 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 @@ -34,7 +34,6 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import picocli.CommandLine; import java.io.PrintStream; @@ -228,13 +227,6 @@ public void execute() { } } - // If project is empty - if (ProjectUtils.isProjectEmpty(project)) { - CommandUtil.printError(this.errStream, "package is empty. Please add at least one .bal file.", null, false); - CommandUtil.exitError(this.exitWhenFinish); - return; - } - // Check package files are modified after last build boolean isPackageModified = isProjectUpdated(project); TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder() 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 c837653ee6a8..9023dfed44a2 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 @@ -35,7 +35,6 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import picocli.CommandLine; import java.io.PrintStream; @@ -280,13 +279,6 @@ public void execute() { } } - // If project is empty - if (ProjectUtils.isProjectEmpty(project)) { - CommandUtil.printError(this.errStream, "package is empty. Please add at least one .bal file.", null, false); - CommandUtil.exitError(this.exitWhenFinish); - return; - } - // Sets the debug port as a system property, which will be used when setting up debug args before running tests. if (this.debugPort != null) { System.setProperty(SYSTEM_PROP_BAL_DEBUG, this.debugPort); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index ba0bd8f7aeba..c8327dc85e98 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -86,6 +86,9 @@ public CompileTask(PrintStream out, @Override public void execute(Project project) { + if (ProjectUtils.isProjectEmpty(project) && skipCompilationForBalPack(project)) { + throw createLauncherException("package is empty. Please add at least one .bal file."); + } this.out.println("Compiling source"); String sourceName; @@ -317,4 +320,16 @@ private void addDiagnosticForProvidedPlatformLibs(Project project, List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-project-with-compiler-plugin.txt")); + } + } - Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-empty-project-with-compiler-plugin.txt")); + @Test(description = "Build an empty package with code generator build tools") + public void testBuildEmptyProjectWithBuildTools() throws IOException { + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString(), testDistCacheDirectory, projectEnvironmentBuilder); + Path projectPath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); + new CommandLine(buildCommand).parseArgs(); + buildCommand.execute(); + } + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("build-empty-project-with-build-tools.txt")); } @Test(description = "Build an empty package with tests only") @@ -683,10 +708,13 @@ public void testBuildEmptyNonDefaultModule() throws IOException { BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); new CommandLine(buildCommand).parseArgs(); - buildCommand.execute(); - String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-empty-nondefault-module.txt")); + try { + buildCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-nondefault-module.txt")); + } } @Test(description = "Build a package with an invalid user name") @@ -803,11 +831,13 @@ public void testBuildEmptyPackage() throws IOException { BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); new CommandLine(buildCommand).parseArgs(); - buildCommand.execute(); - - String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-empty-package.txt")); + try { + buildCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } } @Test(description = "Build an empty package with compiler plugin") @@ -817,11 +847,13 @@ public void testBuildEmptyPackageWithCompilerPlugin() throws IOException { BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); new CommandLine(buildCommand).parseArgs(); - buildCommand.execute(); - - String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-empty-package.txt")); + try { + buildCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } } @Test(description = "Build a ballerina project with the flag dump-graph") 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 05ba384604ab..5800390e3e84 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 @@ -18,8 +18,15 @@ package io.ballerina.cli.cmd; +import io.ballerina.cli.launcher.BLauncherException; +import io.ballerina.projects.ProjectEnvironmentBuilder; +import io.ballerina.projects.environment.Environment; +import io.ballerina.projects.environment.EnvironmentBuilder; +import io.ballerina.projects.util.BuildToolUtils; import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.test.BCompileUtil; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -38,8 +45,14 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Objects; +import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; +import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; +import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; + /** * Graph command tests. * @@ -47,10 +60,17 @@ */ public class GraphCommandTest extends BaseCommandTest { private Path testResources; + private Path testDistCacheDirectory; + private ProjectEnvironmentBuilder projectEnvironmentBuilder; @BeforeClass public void setup() throws IOException { super.setup(); + Path testBuildDirectory = Paths.get("build").toAbsolutePath(); + testDistCacheDirectory = testBuildDirectory.resolve(DIST_CACHE_DIRECTORY); + Path customUserHome = Paths.get("build", "user-home"); + Environment environment = EnvironmentBuilder.getBuilder().setUserHome(customUserHome).build(); + projectEnvironmentBuilder = ProjectEnvironmentBuilder.getBuilder(environment); this.testResources = super.tmpDir.resolve("build-test-resources"); Path projectsWithDependencyConflicts = this.testResources.resolve("projectsWithDependencyConflicts") .resolve("package_p"); @@ -203,10 +223,32 @@ public void testEmptyBalProjectGraph() throws IOException { GraphCommand graphCommand = new GraphCommand(emptyPackagePath, printStream, printStream, false); new CommandLine(graphCommand).parseArgs(emptyPackagePath.toString()); - graphCommand.execute(); + try { + graphCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } + } + @Test(description = "Call bal graph for an empty project with build tools") + public void testEmptyBalProjectGraphWithBuildTools() throws IOException { + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString(), testDistCacheDirectory, projectEnvironmentBuilder); + Path emptyPackagePath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(emptyPackagePath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty(USER_DIR_PROPERTY, emptyPackagePath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + GraphCommand graphCommand = new GraphCommand(emptyPackagePath, printStream, printStream, false); + new CommandLine(graphCommand).parseArgs(emptyPackagePath.toString()); + graphCommand.execute(); + } String actualLog = readFormattedOutput(); - String expectedLog = "ballerina: package is empty. Please add at least one .bal file."; + String expectedLog = CommandOutputUtils.getOutput("graph-empty-project-with-build-tools.txt"); Assert.assertEquals(actualLog, expectedLog); } @@ -359,14 +401,20 @@ private void copyTestResourcesToTmpDir() throws URISyntaxException, IOException private void compileAndCacheTestDependencies() { Path dumpGraphResourcePath = this.testResources.resolve("projectsForDumpGraph"); - BCompileUtil.compileAndCacheBala(dumpGraphResourcePath.resolve("package_c").toString()); - BCompileUtil.compileAndCacheBala(dumpGraphResourcePath.resolve("package_b").toString()); + BCompileUtil.compileAndCacheBala(dumpGraphResourcePath.resolve("package_c").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); + BCompileUtil.compileAndCacheBala(dumpGraphResourcePath.resolve("package_b").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); Path dependencyConflictPath = this.testResources.resolve("projectsWithDependencyConflicts"); - BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_0_0").toString()); - BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_0_2").toString()); - BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_1_0").toString()); - BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_2_1_0").toString()); + BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_0_0").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); + BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_0_2").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); + BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_1_1_0").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); + BCompileUtil.compileAndCacheBala(dependencyConflictPath.resolve("package_o_2_1_0").toString(), + testDistCacheDirectory, projectEnvironmentBuilder); } private String readFormattedOutput() throws IOException { 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 ddbc99ac4731..545a411a73eb 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 @@ -1,8 +1,11 @@ package io.ballerina.cli.cmd; import io.ballerina.cli.launcher.BLauncherException; +import io.ballerina.projects.util.BuildToolUtils; import io.ballerina.projects.util.ProjectUtils; import org.ballerinalang.test.BCompileUtil; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -17,12 +20,14 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Objects; import static io.ballerina.cli.cmd.CommandOutputUtils.assertTomlFilesEquals; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML; +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.USER_DIR_PROPERTY; @@ -320,6 +325,26 @@ public void testPackEmptyProjectWithCompilerPlugin() throws IOException { getOutput("compile-empty-project-with-compiler-plugin.txt")); } + @Test(description = "Pack an empty package with compiler plugin") + public void testPackEmptyProjectWithBuildTools() throws IOException { + Path testDistCacheDirectory = Paths.get("build").toAbsolutePath().resolve(DIST_CACHE_DIRECTORY); + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString(), testDistCacheDirectory); + Path projectPath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty("user.dir", projectPath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + 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-empty-project-with-build-tools.txt")); + } + @Test(description = "Pack an empty package as a tool") public void testPackEmptyProjectWithTool() throws IOException { Path projectPath = this.testResources.resolve("emptyProjectWithTool"); @@ -382,10 +407,13 @@ public void testPackEmptyNonDefaultModule() throws IOException { 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("build-empty-nondefault-module.txt")); + try { + packCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-nondefault-module.txt")); + } Assert.assertFalse(projectPath.resolve("target").resolve("bala") .resolve("wso2-emptyNonDefaultModule-any-0.1.0.bala").toFile().exists()); } @@ -439,11 +467,13 @@ public void testPackEmptyPackage() throws IOException { 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-empty-package.txt")); + try { + packCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("pack-empty-package.txt")); + } } @Test(description = "Pack an empty package with compiler plugin") 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 69c2af8fc44d..a7407659e087 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 @@ -18,12 +18,18 @@ package io.ballerina.cli.cmd; +import io.ballerina.cli.launcher.BLauncherException; +import io.ballerina.projects.util.BuildToolUtils; import io.ballerina.projects.util.ProjectUtils; +import org.ballerinalang.test.BCompileUtil; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; import java.io.IOException; @@ -32,9 +38,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Objects; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; +import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; +import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** * Profile command tests. @@ -72,7 +82,7 @@ public void setup() throws IOException { @Test(description = "Profile a ballerina project") public void testRunBalProjectWithProfileFlag() throws IOException { Path projectPath = this.testResources.resolve("projectForProfile").resolve("package_a"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); System.setOut(new java.io.PrintStream(out)); @@ -96,7 +106,7 @@ public void testRunBalProjectWithProfileFlag() throws IOException { @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()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); System.setOut(new java.io.PrintStream(out)); @@ -121,7 +131,7 @@ public void testRunBalProjectWithProfileFlagWithBuildTools() throws IOException public void testProfileCommandAndHelp() throws IOException { String[] args = {"--help"}; Path projectPath = this.testResources.resolve("projectForProfile").resolve("package_a"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); ProfileCommand profileCommand = new ProfileCommand(projectPath, printStream, false); new CommandLine(profileCommand).parseArgs(args); profileCommand.execute(); @@ -129,6 +139,42 @@ public void testProfileCommandAndHelp() throws IOException { "generate flame graph")); } + @Test(description = "Profile an empty package") + public void testProfileEmptyProject() throws IOException { + Path projectPath = this.testResources.resolve("emptyPackage"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + + ProfileCommand profileCommand = new ProfileCommand(projectPath, printStream, false); + new CommandLine(profileCommand).parseArgs(); + try { + profileCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } + } + + @Test(description = "Profile an empty package with code generator build tools") + public void testProfileEmptyProjectWithBuildTools() throws IOException { + Path testDistCacheDirectory = Paths.get("build").toAbsolutePath().resolve(DIST_CACHE_DIRECTORY); + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString()); + Path projectPath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + ProfileCommand profileCommand = new ProfileCommand(projectPath, printStream, false); + new CommandLine(profileCommand).parseArgs(); + profileCommand.execute(); + } + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("profile-empty-project-with-build-tools.txt")); + } + @AfterSuite public void cleanUp() throws IOException { Files.deleteIfExists(logFile); 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 b676e08347b7..4a77567ab513 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 @@ -5,14 +5,18 @@ import io.ballerina.projects.ProjectEnvironmentBuilder; import io.ballerina.projects.environment.Environment; import io.ballerina.projects.environment.EnvironmentBuilder; +import io.ballerina.projects.util.BuildToolUtils; import io.ballerina.projects.util.ProjectUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.ballerinalang.test.BCompileUtil; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; import java.io.File; @@ -23,9 +27,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; import java.util.Objects; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; +import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; @@ -404,10 +410,32 @@ public void testRunEmptyPackage() throws IOException { RunCommand runCommand = new RunCommand(projectPath, printStream, false); new CommandLine(runCommand).parseArgs(); - runCommand.execute(); + try { + runCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } + } + @Test(description = "Run an empty package with code generator build tools") + public void testRunEmptyProjectWithBuildTools() throws IOException { + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString(), testDistCacheDirectory, projectEnvironmentBuilder); + Path projectPath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + RunCommand runCommand = new RunCommand(projectPath, printStream, false); + new CommandLine(runCommand).parseArgs(); + runCommand.execute(); + } String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("build-empty-package.txt")); + Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("run-empty-project-with-build-tools.txt")); } @AfterSuite 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 8c8828dc0eb1..abdb3cee4fd7 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 @@ -23,6 +23,7 @@ import io.ballerina.projects.ProjectEnvironmentBuilder; import io.ballerina.projects.environment.Environment; import io.ballerina.projects.environment.EnvironmentBuilder; +import io.ballerina.projects.util.BuildToolUtils; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; import org.apache.commons.codec.digest.DigestUtils; @@ -48,10 +49,12 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; +import java.util.List; import java.util.Objects; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; import static io.ballerina.cli.cmd.CommandOutputUtils.readFileAsString; +import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; import static io.ballerina.projects.util.ProjectConstants.BUILD_FILE; import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML; import static io.ballerina.projects.util.ProjectConstants.DIST_CACHE_DIRECTORY; @@ -397,10 +400,32 @@ public void testTestEmptyPackage() throws IOException { TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false); new CommandLine(testCommand).parseArgs(); - testCommand.execute(); + try { + testCommand.execute(); + } catch (BLauncherException e) { + List messages = e.getMessages(); + Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(messages.get(0), getOutput("build-empty-package.txt")); + } + } + @Test(description = "Test an empty project with build tools") + public void testTestEmptyProjectWithBuildTools() throws IOException { + BCompileUtil.compileAndCacheBala(testResources.resolve("buildToolResources").resolve("tools") + .resolve("ballerina-generate-file").toString(), testDistCacheDirectory, projectEnvironmentBuilder); + Path projectPath = this.testResources.resolve("emptyProjectWithBuildTool"); + replaceDependenciesTomlContent(projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", + RepoUtils.getBallerinaShortVersion()); + System.setProperty("user.dir", projectPath.toString()); + try (MockedStatic repoUtils = Mockito.mockStatic( + BuildToolUtils.class, Mockito.CALLS_REAL_METHODS)) { + repoUtils.when(BuildToolUtils::getCentralBalaDirPath).thenReturn(testDistCacheDirectory.resolve("bala")); + TestCommand testCommand = new TestCommand(projectPath, printStream, printStream, false); + new CommandLine(testCommand).parseArgs(); + testCommand.execute(); + } String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("build-empty-package.txt")); + Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("test-empty-project-with-build-tools.txt")); } static class Copy extends SimpleFileVisitor { diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-nondefault-module.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-nondefault-module.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-nondefault-module.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-nondefault-module.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-package.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-package.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-package.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-package.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..b3bd9fbed5c5 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-compiler-plugin.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-empty-project-with-compiler-plugin.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..ddb7ad6836bf --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/graph-empty-project-with-build-tools.txt @@ -0,0 +1,11 @@ +Executing Build Tools + generate_file(generate_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-empty-package.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..42fd76ca4abd --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_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-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..b3bd9fbed5c5 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/profile-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..a913e9323177 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/run-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_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-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..5998be05c90d --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/test-empty-project-with-build-tools.txt @@ -0,0 +1,7 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + No tests found diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-nondefault-module.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-nondefault-module.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-nondefault-module.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-nondefault-module.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-package.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-package.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-package.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-package.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..b3bd9fbed5c5 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-compiler-plugin.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-empty-project-with-compiler-plugin.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..ddb7ad6836bf --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/graph-empty-project-with-build-tools.txt @@ -0,0 +1,11 @@ +Executing Build Tools + generate_file(generate_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-empty-package.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package.txt index f861586b4830..d3918962590f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package.txt @@ -1 +1 @@ -ballerina: package is empty. Please add at least one .bal file. +error: package is empty. Please add at least one .bal file. \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..42fd76ca4abd --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_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-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..b3bd9fbed5c5 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/profile-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..a913e9323177 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/run-empty-project-with-build-tools.txt @@ -0,0 +1,9 @@ + +Executing Build Tools + generate_file(generate_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-empty-project-with-build-tools.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-empty-project-with-build-tools.txt new file mode 100644 index 000000000000..5998be05c90d --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/test-empty-project-with-build-tools.txt @@ -0,0 +1,7 @@ + +Executing Build Tools + generate_file(generate_client) + +Compiling source + foo/winery:0.1.0 + No tests found diff --git a/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Ballerina.toml new file mode 100644 index 000000000000..83afa27d772f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Ballerina.toml @@ -0,0 +1,10 @@ +[package] +org = "foo" +name = "winery" +version = "0.1.0" + +[[tool.generate_file]] +id = "generate_client" +filePath = "delivery.json" +targetModule = "mod_generate" +options.fileName = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Dependencies.toml b/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Dependencies.toml new file mode 100644 index 000000000000..f2dc8118f835 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/Dependencies.toml @@ -0,0 +1,23 @@ + # AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**" + +[[package]] +org = "foo" +name = "winery" +version = "0.1.0" +modules = [ + {org = "foo", packageName = "winery", moduleName = "winery"} +] + +[[tool]] +id = "generate_file" +org = "foo" +name = "ballerina_generate_file" +version = "0.1.0" + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/emptyProjectWithBuildTool/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1