Code review comment: I changed it as: > "invalid Ballerina source path, it should be a name of a module in a Ballerina project or a file with a '.bal' extension or an executable .jar file."

Code before review:
public void execute() {
if (this.helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(Constants.RUN_COMMAND);
this.errStream.println(commandUsageInfo);
return;
}
if (this.argList == null || this.argList.size() == 0) {
CommandUtil.printError(this.errStream,
"no ballerina program given.",
"ballerina run {<bal-file> | <module-name>}",
true);
Runtime.getRuntime().exit(1);
return;
}
if (null != this.debugPort) {
System.setProperty(SYSTEM_PROP_BAL_DEBUG, this.debugPort);
}
String[] programArgs = this.getProgramArgs(this.argList);
Path sourceRootPath = this.sourceRoot == null ? Paths.get(System.getProperty("user.dir")) :
Paths.get(this.sourceRoot);
Path sourcePath;
Path targetPath;
if (this.argList.get(0).endsWith(BLangConstants.BLANG_SRC_FILE_SUFFIX)) {
if (Paths.get(this.argList.get(0)).isAbsolute()) {
sourcePath = Paths.get(this.argList.get(0));
sourceRootPath = sourcePath.getParent();
} else {
sourcePath = sourceRootPath.resolve(this.argList.get(0));
}
if (Files.notExists(sourcePath)) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' Ballerina file does not exist.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
if (!Files.isRegularFile(sourcePath)) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' is not a Ballerina file. check if it is a symlink or a shortcut.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
try {
targetPath = Files.createTempDirectory("ballerina-run-" + System.nanoTime());
} catch (IOException e) {
throw LauncherUtils.createLauncherException("error occurred when creating executable.");
}
} else if (Files.exists(
sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(this.argList.get(0))) &&
Files.isDirectory(
sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(this.argList.get(0)))) {
if (!RepoUtils.isBallerinaProject(sourceRootPath)) {
CommandUtil.printError(this.errStream,
"you are trying to run a module that is not inside a project.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
if (Paths.get(argList.get(0)).isAbsolute()) {
CommandUtil.printError(this.errStream,
"you are trying to run a module by giving the absolute path. you only need give " +
"the name of the module.",
"ballerina run <module-name>",
true);
Runtime.getRuntime().exit(1);
return;
}
String moduleName = argList.get(0);
if (moduleName.endsWith("/")) {
moduleName = moduleName.substring(0, moduleName.length() - 1);
}
sourcePath = Paths.get(moduleName);
if (Files.notExists(sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(sourcePath))) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' module does not exist.",
"ballerina run <module-name>",
true);
Runtime.getRuntime().exit(1);
return;
}
targetPath = sourceRootPath.resolve(ProjectDirConstants.TARGET_DIR_NAME);
} else {
CommandUtil.printError(this.errStream,
"invalid Ballerina source path, it should either be a module name in a Ballerina project, a " +
"file with a \'" + BLangConstants.BLANG_SRC_FILE_SUFFIX + "\' extension or a .jar file.",
"ballerina run {<bal-file> | <module-name>}",
true);
Runtime.getRuntime().exit(1);
return;
}
sourceRootPath = sourceRootPath.normalize();
sourcePath = sourcePath == null ? null : sourcePath.normalize();
targetPath = targetPath.normalize();
CompilerContext compilerContext = new CompilerContext();
CompilerOptions options = CompilerOptions.getInstance(compilerContext);
options.put(PROJECT_DIR, sourceRootPath.toString());
options.put(OFFLINE, Boolean.toString(this.offline));
options.put(COMPILER_PHASE, CompilerPhase.BIR_GEN.toString());
options.put(LOCK_ENABLED, Boolean.toString(true));
options.put(SKIP_TESTS, Boolean.toString(true));
options.put(TEST_ENABLED, "true");
options.put(EXPERIMENTAL_FEATURES_ENABLED, Boolean.toString(this.experimentalFlag));
BuildContext buildContext = new BuildContext(sourceRootPath, targetPath, sourcePath, compilerContext);
buildContext.setOut(this.outStream);
buildContext.setErr(this.errStream);
boolean isSingleFileBuild = buildContext.getSourceType().equals(SINGLE_BAL_FILE);
TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder()
.addTask(new CleanTargetDirTask(), isSingleFileBuild)
.addTask(new CreateTargetDirTask())
.addTask(new CompileTask())
.addTask(new CreateBaloTask(), isSingleFileBuild)
.addTask(new CreateBirTask())
.addTask(new CopyNativeLibTask())
.addTask(new CreateJarTask(false))
.addTask(new CopyModuleJarTask())
.addTask(new CreateExecutableTask())
.addTask(new PrintExecutablePathTask(), isSingleFileBuild)
.addTask(new PrintRunningExecutableTask(!isSingleFileBuild))
.addTask(new RunExecutableTask(programArgs))
.build();
taskExecutor.executeTasks(buildContext);
}

Line under review: "file with a \'" + BLangConstants.BLANG_SRC_FILE_SUFFIX + "\' extension or a .jar file.",

Code after addressing the review:
public void execute() {
if (this.helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(Constants.RUN_COMMAND);
this.errStream.println(commandUsageInfo);
return;
}
if (this.argList == null || this.argList.size() == 0) {
CommandUtil.printError(this.errStream,
"no ballerina program given.",
"ballerina run {<bal-file> | <module-name> | <executable-jar>}",
true);
Runtime.getRuntime().exit(1);
return;
}
if (null != this.debugPort) {
System.setProperty(SYSTEM_PROP_BAL_DEBUG, this.debugPort);
}
String[] programArgs = this.getProgramArgs(this.argList);
Path sourceRootPath = this.sourceRoot == null ? Paths.get(System.getProperty("user.dir")) :
Paths.get(this.sourceRoot);
Path sourcePath;
Path targetPath;
if (this.argList.get(0).endsWith(BLangConstants.BLANG_SRC_FILE_SUFFIX)) {
if (Paths.get(this.argList.get(0)).isAbsolute()) {
sourcePath = Paths.get(this.argList.get(0));
sourceRootPath = sourcePath.getParent();
} else {
sourcePath = sourceRootPath.resolve(this.argList.get(0));
}
if (Files.notExists(sourcePath)) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' Ballerina file does not exist.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
if (!Files.isRegularFile(sourcePath)) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' is not a Ballerina file. check if it is a symlink or a shortcut.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
try {
targetPath = Files.createTempDirectory("ballerina-run-" + System.nanoTime());
} catch (IOException e) {
throw LauncherUtils.createLauncherException("error occurred when creating executable.");
}
} else if (Files.exists(
sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(this.argList.get(0))) &&
Files.isDirectory(
sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(this.argList.get(0)))) {
if (!RepoUtils.isBallerinaProject(sourceRootPath)) {
CommandUtil.printError(this.errStream,
"you are trying to run a module that is not inside a project.",
null,
false);
Runtime.getRuntime().exit(1);
return;
}
if (Paths.get(argList.get(0)).isAbsolute()) {
CommandUtil.printError(this.errStream,
"you are trying to run a module by giving the absolute path. you only need give " +
"the name of the module.",
"ballerina run <module-name>",
true);
Runtime.getRuntime().exit(1);
return;
}
String moduleName = argList.get(0);
if (moduleName.endsWith("/")) {
moduleName = moduleName.substring(0, moduleName.length() - 1);
}
sourcePath = Paths.get(moduleName);
if (Files.notExists(sourceRootPath.resolve(ProjectDirConstants.SOURCE_DIR_NAME).resolve(sourcePath))) {
CommandUtil.printError(this.errStream,
"'" + sourcePath + "' module does not exist.",
"ballerina run <module-name>",
true);
Runtime.getRuntime().exit(1);
return;
}
targetPath = sourceRootPath.resolve(ProjectDirConstants.TARGET_DIR_NAME);
} else {
CommandUtil.printError(this.errStream,
"invalid Ballerina source path. It should either be a name of a module in a Ballerina project, " +
"a file with a '" + BLangConstants.BLANG_SRC_FILE_SUFFIX + "' extension, or an executable '" +
BLANG_COMPILED_JAR_EXT + "' file.",
"ballerina run {<bal-file> | <module-name> | <executable-jar>}",
true);
Runtime.getRuntime().exit(1);
return;
}
sourceRootPath = sourceRootPath.normalize();
sourcePath = sourcePath == null ? null : sourcePath.normalize();
targetPath = targetPath.normalize();
CompilerContext compilerContext = new CompilerContext();
CompilerOptions options = CompilerOptions.getInstance(compilerContext);
options.put(PROJECT_DIR, sourceRootPath.toString());
options.put(OFFLINE, Boolean.toString(this.offline));
options.put(COMPILER_PHASE, CompilerPhase.BIR_GEN.toString());
options.put(LOCK_ENABLED, Boolean.toString(true));
options.put(SKIP_TESTS, Boolean.toString(true));
options.put(TEST_ENABLED, "true");
options.put(EXPERIMENTAL_FEATURES_ENABLED, Boolean.toString(this.experimentalFlag));
BuildContext buildContext = new BuildContext(sourceRootPath, targetPath, sourcePath, compilerContext);
buildContext.setOut(this.outStream);
buildContext.setErr(this.errStream);
boolean isSingleFileBuild = buildContext.getSourceType().equals(SINGLE_BAL_FILE);
TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder()
.addTask(new CleanTargetDirTask(), isSingleFileBuild)
.addTask(new CreateTargetDirTask())
.addTask(new CompileTask())
.addTask(new CreateBaloTask(), isSingleFileBuild)
.addTask(new CreateBirTask())
.addTask(new CopyNativeLibTask())
.addTask(new CreateJarTask(false))
.addTask(new CopyModuleJarTask())
.addTask(new CreateExecutableTask())
.addTask(new PrintExecutablePathTask(), isSingleFileBuild)
.addTask(new PrintRunningExecutableTask(!isSingleFileBuild))
.addTask(new RunExecutableTask(programArgs))
.build();
taskExecutor.executeTasks(buildContext);
}