Skip to content

Commit 0462ef7

Browse files
Merge pull request #44171 from Thevakumar-Luheerathan/ballerina-lang-iss-44168-mast
Fix sticky flag
2 parents a84ade6 + ee5c4c6 commit 0462ef7

File tree

22 files changed

+150
-45
lines changed

22 files changed

+150
-45
lines changed

cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/BuildCommand.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ public void execute() {
226226
return;
227227
}
228228

229-
if (sticky == null) {
230-
sticky = false;
231-
}
232229

233230
// load project
234231
Project project;

cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PackCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ public void execute() {
159159

160160
Project project;
161161

162-
if (sticky == null) {
163-
sticky = false;
164-
}
165-
166162
BuildOptions buildOptions = constructBuildOptions();
167163

168164
// Throw an error if its a single file

cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ public void execute() {
220220
}
221221
}
222222

223-
if (sticky == null) {
224-
sticky = false;
225-
}
226-
227223
if (this.watch) {
228224
try {
229225
ProjectWatcher projectWatcher = new ProjectWatcher(

cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ public void execute() {
254254
}
255255
}
256256

257-
if (sticky == null) {
258-
sticky = false;
259-
}
260257
if (isParallelExecution) {
261258
this.outStream.println("WARNING: Running tests in parallel is an experimental feature");
262259
}

compiler/ballerina-lang/src/main/java/io/ballerina/projects/CompilationOptions.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public boolean offlineBuild() {
7878
}
7979

8080
boolean sticky() {
81-
return toBooleanTrueIfNull(this.sticky);
81+
return toBooleanDefaultIfNull(this.sticky);
8282
}
8383

8484
boolean experimental() {
@@ -266,13 +266,6 @@ private boolean toBooleanDefaultIfNull(Boolean bool) {
266266
return bool;
267267
}
268268

269-
private boolean toBooleanTrueIfNull(Boolean bool) {
270-
if (bool == null) {
271-
return true;
272-
}
273-
return bool;
274-
}
275-
276269
private String toStringDefaultIfNull(String value) {
277270
if (value == null) {
278271
return "";

compiler/ballerina-lang/src/main/java/io/ballerina/projects/bala/BalaProject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class BalaProject extends Project {
5555
*/
5656
public static BalaProject loadProject(ProjectEnvironmentBuilder environmentBuilder, Path balaPath) {
5757
PackageConfig packageConfig = PackageConfigCreator.createBalaProjectConfig(balaPath);
58-
BalaProject balaProject = new BalaProject(environmentBuilder, balaPath, BuildOptions.builder().build());
58+
BalaProject balaProject = new BalaProject(environmentBuilder, balaPath, BuildOptions.builder().setSticky(true)
59+
.build());
5960
balaProject.addPackage(packageConfig);
6061
return balaProject;
6162
}

compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ private BuildOptions setBuildOptions(TomlTableNode tomlTableNode) {
897897
Boolean dumpBuildTime =
898898
getBooleanFromBuildOptionsTableNode(tableNode, BuildOptions.OptionName.DUMP_BUILD_TIME.toString());
899899
Boolean sticky =
900-
getTrueFromBuildOptionsTableNode(tableNode, CompilerOptionName.STICKY.toString());
900+
getBooleanFromBuildOptionsTableNode(tableNode, CompilerOptionName.STICKY.toString());
901901
String cloud = "";
902902
if (topLevelNode != null) {
903903
cloud = getStringFromTomlTableNode(topLevelNode);
@@ -1000,23 +1000,6 @@ private boolean getBooleanFromTemplateNode(TomlTableNode tableNode, String key)
10001000
return false;
10011001
}
10021002

1003-
private boolean getTrueFromBuildOptionsTableNode(TomlTableNode tableNode, String key) {
1004-
TopLevelNode topLevelNode = tableNode.entries().get(key);
1005-
if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) {
1006-
return true;
1007-
}
1008-
1009-
if (topLevelNode.kind() == TomlType.KEY_VALUE) {
1010-
TomlKeyValueNode keyValueNode = (TomlKeyValueNode) topLevelNode;
1011-
TomlValueNode value = keyValueNode.value();
1012-
if (value.kind() == TomlType.BOOLEAN) {
1013-
TomlBooleanValueNode tomlBooleanValueNode = (TomlBooleanValueNode) value;
1014-
return tomlBooleanValueNode.getValue();
1015-
}
1016-
}
1017-
return true;
1018-
}
1019-
10201003
public static String getStringValueFromTomlTableNode(TomlTableNode tomlTableNode, String key) {
10211004
TopLevelNode topLevelNode = tomlTableNode.entries().get(key);
10221005
if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) {

project-api/project-api-test/src/test/java/io/ballerina/projects/test/PackageResolutionIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void testCase0001(ITestContext ctx) throws IOException {
130130
// Compare Dependencies.toml file
131131
// package_a ---> 1.0.2 patch version
132132
assertTomlFilesEquals(projectDirPath.resolve(DEPENDENCIES_TOML),
133-
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies-0001-2.toml"));
133+
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies-0001-3.toml"));
134134

135135
// 5. Build package_c again after deleting Dependencies.toml and build file, and setting sticky == false
136136
deleteDependenciesTomlAndBuildFile(projectDirPath);
@@ -212,7 +212,7 @@ public void testCase0003(ITestContext ctx) throws IOException {
212212
// Compare Dependencies.toml file
213213
// package_a ---> 1.0.2 version
214214
assertTomlFilesEquals(projectDirPath.resolve(DEPENDENCIES_TOML),
215-
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies-0003-2.toml"));
215+
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies-0003-1.toml"));
216216

217217
// 4. Build package_c again after deleting Dependencies.toml and build file, and setting sticky == false
218218
deleteDependenciesTomlAndBuildFile(projectDirPath);
@@ -386,7 +386,7 @@ public void testCase0007(ITestContext ctx) throws IOException {
386386
failIfDiagnosticsExists(buildProject2);
387387

388388
assertTomlFilesEquals(projectDirPath.resolve(DEPENDENCIES_TOML),
389-
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies-0007-1.toml"));
389+
projectDirPath.resolve(RESOURCE_DIR_NAME).resolve("Dependencies_NoSticky.toml"));
390390

391391
// No Sticky
392392
deleteBuildFile(projectDirPath);

project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBuildProject.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,48 @@ public void testConflictingJarsInNonBalPackages() {
24552455
" dependency of 'platformlib/pkg1'. Picking 'lib3-2.0.1.jar' over 'lib3-2.0.0.jar'.");
24562456
}
24572457

2458+
@Test(description = "Test sticky flag when not defined in Ballerina.toml")
2459+
public void testStickyFlagNotDefinedInToml() throws IOException {
2460+
Path projectPath = tempResourceDir.resolve("stickyTestProjs/projNullStickyInBalTom");
2461+
BuildOptions buildOptions = BuildOptions.builder().setSticky(false).build(); // CLI Sticky
2462+
BuildProject project = loadBuildProject(projectPath, buildOptions);
2463+
Assert.assertFalse(project.buildOptions().sticky());
2464+
buildOptions = BuildOptions.builder().setSticky(true).build(); // CLI Sticky
2465+
project = loadBuildProject(projectPath, buildOptions);
2466+
Assert.assertTrue(project.buildOptions().sticky());
2467+
buildOptions = BuildOptions.builder().build(); // CLI Sticky
2468+
project = loadBuildProject(projectPath, buildOptions);
2469+
Assert.assertFalse(project.buildOptions().sticky());
2470+
}
2471+
2472+
@Test(description = "Test sticky flag when set to false in Ballerina.toml")
2473+
public void testStickyFlagFalseInToml() throws IOException {
2474+
Path projectPath = tempResourceDir.resolve("stickyTestProjs/projFalseStickyInBalTom");
2475+
BuildOptions buildOptions = BuildOptions.builder().setSticky(false).build(); // CLI Sticky
2476+
BuildProject project = loadBuildProject(projectPath, buildOptions);
2477+
Assert.assertFalse(project.buildOptions().sticky());
2478+
buildOptions = BuildOptions.builder().setSticky(true).build(); // CLI Sticky
2479+
project = loadBuildProject(projectPath, buildOptions);
2480+
Assert.assertTrue(project.buildOptions().sticky());
2481+
buildOptions = BuildOptions.builder().build(); // CLI Sticky
2482+
project = loadBuildProject(projectPath, buildOptions);
2483+
Assert.assertFalse(project.buildOptions().sticky());
2484+
}
2485+
2486+
@Test(description = "Test sticky flag when set to true in Ballerina.toml")
2487+
public void testStickyFlagTrueInToml() throws IOException {
2488+
Path projectPath = tempResourceDir.resolve("stickyTestProjs/projTrueStickyInBalTom");
2489+
BuildOptions buildOptions = BuildOptions.builder().setSticky(false).build(); // CLI Sticky
2490+
BuildProject project = loadBuildProject(projectPath, buildOptions);
2491+
Assert.assertFalse(project.buildOptions().sticky());
2492+
buildOptions = BuildOptions.builder().setSticky(true).build(); // CLI Sticky
2493+
project = loadBuildProject(projectPath, buildOptions);
2494+
Assert.assertTrue(project.buildOptions().sticky());
2495+
buildOptions = BuildOptions.builder().build(); // CLI Sticky
2496+
project = loadBuildProject(projectPath, buildOptions);
2497+
Assert.assertTrue(project.buildOptions().sticky());
2498+
}
2499+
24582500
private static BuildProject loadBuildProject(Path projectPath) {
24592501
return loadBuildProject(projectPath, null);
24602502
}

project-api/project-api-test/src/test/resources/projects_for_resolution_integration_tests/package_f_1_0_0_remove_import_d/resources/Dependencies-0006-2.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
dependencies-toml-version = "2"
88
distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**"
99

10+
[[package]]
11+
org = "adv_res"
12+
name = "package_d"
13+
version = "1.0.0"
14+
1015
[[package]]
1116
org = "adv_res"
1217
name = "package_e"
13-
version = "2.0.0"
18+
version = "2.0.2"
19+
dependencies = [
20+
{org = "adv_res", name = "package_d"}
21+
]
1422
modules = [
1523
{org = "adv_res", packageName = "package_e", moduleName = "package_e"}
1624
]

0 commit comments

Comments
 (0)