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 77c84410c35c..35426cba90a7 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; @@ -260,14 +259,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 0ff8898eded7..d9162b35f9af 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; @@ -164,15 +163,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 9671f211a027..38239adba4ab 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; @@ -122,12 +121,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 3b5b93ca8687..2868bc69c0cb 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 @@ -37,7 +37,6 @@ import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.internal.model.Target; import io.ballerina.projects.util.ProjectConstants; -import io.ballerina.projects.util.ProjectUtils; import picocli.CommandLine; import java.io.IOException; @@ -238,12 +237,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; - } Target target; try { if (project.kind().equals(ProjectKind.BUILD_PROJECT)) { 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 4bd550aa036f..181b86af3e4a 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 @@ -37,7 +37,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; @@ -289,13 +288,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..629be46a4e6a 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,13 +20,16 @@ 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; import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** @@ -65,7 +71,7 @@ public void setup() throws IOException { @Test(description = "Test package command") public void testPackCommand() throws IOException { Path projectPath = this.testResources.resolve(VALID_PROJECT); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -80,7 +86,7 @@ public void testPackCommand() throws IOException { @Test(description = "Pack a library package") public void testPackProject() throws IOException { Path projectPath = this.testResources.resolve("validLibraryProject"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -107,7 +113,7 @@ public void testRunBalProjectWithAllCompilerPlugins() throws IOException { .toAbsolutePath().toString()); Path projectPath = this.testResources.resolve("compiler-plugins").resolve("log_creator_combined_plugin"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -141,7 +147,7 @@ public void testRunBalProjectWithAllCompilerPlugins() throws IOException { @Test(description = "Pack an application package") public void testPackApplicationPackage() { Path projectPath = this.testResources.resolve("validApplicationProject"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); try { @@ -155,7 +161,7 @@ public void testPackApplicationPackage() { @Test(description = "Pack a Standalone Ballerina file") public void testPackStandaloneFile() throws IOException { Path projectPath = this.testResources.resolve("valid-bal-file").resolve("hello_world.bal"); - System.setProperty("user.dir", this.testResources.resolve("valid-bal-file").toString()); + System.setProperty(USER_DIR, this.testResources.resolve("valid-bal-file").toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -166,7 +172,7 @@ public void testPackStandaloneFile() throws IOException { @Test(description = "Pack a package with platform libs") public void testPackageWithPlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("validGraalvmCompatibleProjectWithPlatformLibs"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -181,7 +187,7 @@ public void testPackageWithPlatformLibs() throws IOException { @Test(description = "Pack a package with java11 platform libs") public void testPackageWithJava11PlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("projectWithJava11PlatformLibs"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -202,7 +208,7 @@ public void testPackageWithJava11PlatformLibs() throws IOException { @Test(description = "Pack a package with java11 and java17 platform libs") public void testPackageWithJava11andJava17PlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("projectWithJava11and17PlatformLibs"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -225,7 +231,7 @@ public void testPackageWithJava11andJava17PlatformLibs() throws IOException { @Test(description = "Pack a package with testOnly platform libs") public void testPackageWithTestOnlyPlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("projectWithTestOnlyPlatformLibs"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -240,7 +246,7 @@ public void testPackageWithTestOnlyPlatformLibs() throws IOException { @Test(description = "Pack a package with ballerina/java imports only in tests") public void testPackageWithTestOnlyJavaImports() throws IOException { Path projectPath = this.testResources.resolve("projectWithTestOnlyJavaImports"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -269,7 +275,7 @@ public void testPackProjectWithBuildTool() throws IOException { @Test(description = "Pack a package with an empty Dependencies.toml") public void testPackageWithEmptyDependenciesToml() throws IOException { Path projectPath = this.testResources.resolve("validProjectWithDependenciesToml"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -289,7 +295,7 @@ public void testPackageWithEmptyDependenciesToml() throws IOException { @Test(description = "Pack a package without root package in Dependencies.toml") public void testPackageWithoutRootPackageInDependenciesToml() throws IOException { Path projectPath = this.testResources.resolve("validProjectWoRootPkgInDepsToml"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); @@ -307,7 +313,7 @@ public void testPackageWithoutRootPackageInDependenciesToml() throws IOException @Test(description = "Pack an empty package with compiler plugin") public void testPackEmptyProjectWithCompilerPlugin() throws IOException { Path projectPath = this.testResources.resolve("emptyProjectWithCompilerPlugin"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -320,10 +326,30 @@ 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"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -339,7 +365,7 @@ public void testPackEmptyProjectWithTool() throws IOException { @Test(description = "Pack an empty package with tests only") public void testPackEmptyProjectWithTestsOnly() { Path projectPath = this.testResources.resolve("emptyProjectWithTestsOnly"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -352,7 +378,7 @@ public void testPackEmptyProjectWithTestsOnly() { @Test(description = "Pack an empty package with Non Default modules") public void testPackEmptyProjectWithNonDefaultModules() { Path projectPath = this.testResources.resolve("emptyProjectWithNonDefaultModules"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -365,7 +391,7 @@ public void testPackEmptyProjectWithNonDefaultModules() { @Test(description = "Pack an empty package with Non Default modules with Tests only") public void testPackEmptyProjectWithNonDefaultModulesTestOnly() { Path projectPath = this.testResources.resolve("emptyProjectWithNonDefaultModulesTestOnly"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -378,14 +404,17 @@ public void testPackEmptyProjectWithNonDefaultModulesTestOnly() { @Test(description = "Pack an empty package with empty Non Default") public void testPackEmptyNonDefaultModule() throws IOException { Path projectPath = this.testResources.resolve("emptyNonDefaultModule"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, 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("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()); } @@ -394,7 +423,7 @@ public void testPackEmptyNonDefaultModule() throws IOException { public void testCustomTargetDir() throws IOException { Path projectPath = this.testResources.resolve(VALID_PROJECT); Path customTargetDir = projectPath.resolve("customTargetDir"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true, customTargetDir); @@ -415,7 +444,7 @@ public void testCustomTargetDir() throws IOException { public void testCustomTargetDirWithRelativePath() throws IOException { Path projectPath = this.testResources.resolve(VALID_PROJECT); Path customTargetDir = projectPath.resolve("./customTargetDir"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true, customTargetDir); @@ -435,15 +464,17 @@ public void testCustomTargetDirWithRelativePath() throws IOException { @Test(description = "Pack an empty package") public void testPackEmptyPackage() throws IOException { Path projectPath = this.testResources.resolve("emptyPackage"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, 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-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") @@ -451,7 +482,7 @@ public void testPackEmptyPackageWithCompilerPlugin() throws IOException { Path projectPath = this.testResources.resolve("emptyPackageWithCompilerPlugin"); replaceDependenciesTomlContent( projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", RepoUtils.getBallerinaShortVersion()); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -476,7 +507,7 @@ public void testPackNonTemplatePackageWithACompilerPackageDependency() throws IO // BALA should contain the source documents modified by the compiler plugin Path projectPath = this.testResources.resolve("projects-using-compiler-plugins") .resolve("package_plugin_code_modify_user_not_template"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -501,7 +532,7 @@ public void testPackTemplatePackageWithACompilerPackageDependency() throws IOExc // BALA should contain the original source documents and not documents modified by the compiler plugin Path projectPath = this.testResources.resolve("projects-using-compiler-plugins") .resolve("package_plugin_code_modify_user_template"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); @@ -522,7 +553,7 @@ public void testPackTemplatePackageWithACompilerPackageDependency() throws IOExc @Test(description = "Pack a library package with platform libraries") public void testPackProjectWithPlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs1"); - System.setProperty("user.dir", projectPath.toString()); + System.setProperty(USER_DIR, projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); 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 a908855e40c9..62f2f4049295 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; @@ -58,13 +59,14 @@ 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; 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; import static io.ballerina.projects.util.ProjectConstants.TEST_RUNTIME_MAIN_ARGS_FILE; +import static io.ballerina.projects.util.ProjectConstants.USER_DIR_PROPERTY; /** * Test command tests. @@ -404,10 +406,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")); } @Test(description = "Test the emission of testable fat jar for a project with tests") 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