Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ina-lang into fix-42728
  • Loading branch information
chiranSachintha committed May 21, 2024
2 parents 141c255 + e03f9c6 commit f68436c
Show file tree
Hide file tree
Showing 118 changed files with 2,041 additions and 609 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public interface BLauncherCmd {
* @return usage info for the specified command
*/
static String getCommandUsageInfo(String commandName) {
if (commandName == null) {
throw LauncherUtils.createUsageExceptionWithHelp("invalid command");
}

String fileName = "cli-help/ballerina-" + commandName + ".help";
try {
return BCompileUtil.readFileAsString(fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.ballerina.projects.internal.PackageDiagnostic;
import io.ballerina.projects.internal.ProjectDiagnosticErrorCode;
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 io.ballerina.tools.diagnostics.DiagnosticInfo;
Expand Down Expand Up @@ -168,15 +167,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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ public class BallerinaCliCommands {
public static final String HELP = "help";
public static final String VERSION = "version";
public static final String RUN = "run";
public static final String ENCRYPT = "encrypt";
public static final String HOME = "home";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Utility methods for compile Ballerina files.
Expand All @@ -31,9 +29,6 @@
*/
public class BCompileUtil {

//TODO find a way to remove below line.
private static Path resourceDir = Paths.get("src/test/resources").toAbsolutePath();

public static String readFileAsString(String path) throws IOException {
InputStream is = ClassLoader.getSystemResourceAsStream(path);
InputStreamReader inputStreamREader = null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -317,4 +320,16 @@ private void addDiagnosticForProvidedPlatformLibs(Project project, List<Diagnost
}
}
}

/**
* If CompileTask is triggered by `bal pack` command, and project does not have CompilerPlugin.toml or BalTool.toml,
* skip the compilation if project is empty. The project should be evaluated for emptiness before calling this.
*
* @param project project instance
* @return true if compilation should be skipped, false otherwise
*/
private boolean skipCompilationForBalPack(Project project) {
return (!compileForBalPack || project.currentPackage().compilerPluginToml().isEmpty() &&
project.currentPackage().balToolToml().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.ballerina.projects.Project;
import io.ballerina.projects.ProjectException;
import io.ballerina.projects.ProjectKind;
import io.ballerina.projects.util.ProjectUtils;
import io.ballerina.tools.diagnostics.Diagnostic;
import org.ballerinalang.central.client.CentralClientConstants;

Expand All @@ -48,7 +49,9 @@ public CreateDependencyGraphTask(PrintStream err, PrintStream out) {

@Override
public void execute(Project project) {

if (ProjectUtils.isProjectEmpty(project)) {
throw createLauncherException("package is empty. Please add at least one .bal file.");
}
System.setProperty(CentralClientConstants.ENABLE_OUTPUT_STREAM, "true");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ public void execute(Project project) {
boolean hasOptionErrors = false;
try {
// validate the options toml and report diagnostics
hasOptionErrors = validateOptionsToml(toolEntry.optionsToml(), toolEntry.id().value(),
toolEntry.type());
hasOptionErrors = validateOptionsToml(toolEntry.optionsToml(), toolEntry.type());
if (hasOptionErrors) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(
ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_FAILED.diagnosticId(),
Expand Down Expand Up @@ -223,16 +222,16 @@ public void execute(Project project) {
this.outStream.println();
}

private boolean validateOptionsToml(Toml optionsToml, String toolId, Tool.Field toolType) throws IOException {
private boolean validateOptionsToml(Toml optionsToml, Tool.Field toolType) throws IOException {
if (optionsToml == null) {
return validateEmptyOptionsToml(toolId, toolType);
return validateEmptyOptionsToml(toolType);
}
FileUtils.validateToml(optionsToml, toolType.value(), toolClassLoader);
optionsToml.diagnostics().forEach(outStream::println);
return !Diagnostics.filterErrors(optionsToml.diagnostics()).isEmpty();
}

private boolean validateEmptyOptionsToml(String toolId, Tool.Field toolType) throws IOException {
private boolean validateEmptyOptionsToml(Tool.Field toolType) throws IOException {
Schema schema = Schema.from(FileUtils.readSchema(toolType.value(), toolClassLoader));
List<String> requiredFields = schema.required();
if (!requiredFields.isEmpty()) {
Expand All @@ -247,8 +246,6 @@ private boolean validateEmptyOptionsToml(String toolId, Tool.Field toolType) thr
}
return true;
}
this.outStream.printf("WARNING: Validation of tool options of '%s' for '%s' is skipped due to " +
"no tool options found%n", toolType.value(), toolId);
return false;
}

Expand Down
Loading

0 comments on commit f68436c

Please sign in to comment.