Skip to content

Commit fd7973b

Browse files
committed
Consider Cloud.toml for cache invalidation
1 parent 9737e53 commit fd7973b

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import static io.ballerina.projects.util.ProjectConstants.BAL_TOOL_JSON;
103103
import static io.ballerina.projects.util.ProjectConstants.BAL_TOOL_TOML;
104104
import static io.ballerina.projects.util.ProjectConstants.BLANG_SOURCE_EXT;
105+
import static io.ballerina.projects.util.ProjectConstants.CLOUD_TOML;
105106
import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML;
106107
import static io.ballerina.projects.util.ProjectConstants.DEPENDENCY_GRAPH_JSON;
107108
import static io.ballerina.projects.util.ProjectConstants.EXEC_BACKUP_DIR_NAME;
@@ -1340,7 +1341,10 @@ public static boolean isFilesModifiedSinceLastBuild(BuildJson buildJson, Project
13401341
if (isSettingsFileModified(buildJson)) {
13411342
return true;
13421343
}
1343-
if (isBallerinaTomlFileModified(buildJson, project)) {
1344+
if (isTomlFileModified(buildJson.getBallerinaTomlMetaInfo(), project.sourceRoot().resolve(BALLERINA_TOML).toFile())) {
1345+
return true;
1346+
}
1347+
if (isTomlFileModified(buildJson.getCloudTomlMetaInfo(), project.sourceRoot().resolve(CLOUD_TOML).toFile())) {
13441348
return true;
13451349
}
13461350
if (isTestExecution) {
@@ -1366,21 +1370,20 @@ public static DependencyGraph<BuildProject> resolveWorkspaceDependencies(
13661370
return projectDependencyGraph;
13671371
}
13681372

1369-
private static boolean isBallerinaTomlFileModified(BuildJson buildJson, Project project) {
1373+
private static boolean isTomlFileModified(BuildJson.FileMetaInfo tomlFileMetaInfo, File tomlFile) {
1374+
if (tomlFileMetaInfo == null) {
1375+
// No Cloud.toml in the project
1376+
return tomlFile.exists();
1377+
}
13701378
try {
1371-
File ballerinaTomlFile = project.sourceRoot().resolve(BALLERINA_TOML).toFile();
1372-
if (ballerinaTomlFile.exists() && ballerinaTomlFile.isFile()) {
1373-
long lastModified = ballerinaTomlFile.lastModified();
1374-
long size = Files.size(ballerinaTomlFile.toPath());
1375-
BuildJson.FileMetaInfo ballerinaTomlFileMetaInfo = buildJson.getBallerinaTomlMetaInfo();
1376-
if (ballerinaTomlFileMetaInfo == null) {
1377-
return true;
1378-
}
1379-
if (ballerinaTomlFileMetaInfo.getSize() == size &&
1380-
ballerinaTomlFileMetaInfo.getLastModifiedTime() == lastModified) {
1379+
if (tomlFile.exists() && tomlFile.isFile()) {
1380+
long lastModified = tomlFile.lastModified();
1381+
long size = Files.size(tomlFile.toPath());
1382+
if (tomlFileMetaInfo.getSize() == size &&
1383+
tomlFileMetaInfo.getLastModifiedTime() == lastModified) {
13811384
return false;
13821385
}
1383-
return !getSHA256Digest(ballerinaTomlFile).equals(ballerinaTomlFileMetaInfo.getHash());
1386+
return !getSHA256Digest(tomlFile).equals(tomlFileMetaInfo.getHash());
13841387
}
13851388
return true;
13861389
} catch (IOException | NoSuchAlgorithmException e) {

cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateFingerprintTask.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void execute(Project project) {
6565
createFingerPrintForArtifacts(project, buildJson, isTestExecution, skipExecutable);
6666
createFingerPrintForSettingsToml(buildJson);
6767
createFingerPrintForBallerinaToml(buildJson, project);
68+
createFingerPrintForCloudToml(buildJson, project);
6869
writeBuildFile(buildFilePath, buildJson);
6970
} catch (JsonSyntaxException | IOException | NoSuchAlgorithmException e) {
7071
// ignore
@@ -78,6 +79,16 @@ private void createFingerPrintForBallerinaToml(BuildJson buildJson, Project proj
7879
buildJson.setBallerinaTomlMetaInfo(ballerinaTomlMetaInfo);
7980
}
8081

82+
private void createFingerPrintForCloudToml(BuildJson buildJson, Project project) throws
83+
IOException, NoSuchAlgorithmException {
84+
File cloudTomlFile = project.sourceRoot().resolve(ProjectConstants.CLOUD_TOML).toFile();
85+
if (!cloudTomlFile.exists()) {
86+
return;
87+
}
88+
BuildJson.FileMetaInfo cloudTomlMetaInfo = getFileMetaInfo(cloudTomlFile);
89+
buildJson.setCloudTomlMetaInfo(cloudTomlMetaInfo);
90+
}
91+
8192
private static void createFingerPrintForProjectFiles(Project project, BuildJson buildJson, boolean isTestExecution)
8293
throws IOException, NoSuchAlgorithmException {
8394
List<BuildJson.FileMetaInfo> fileMetaInfoList = new ArrayList<>();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public class BuildJson {
7575
@SerializedName(BALLERINA_TOML_META_INFO)
7676
private FileMetaInfo ballerinaTomlMetaInfo;
7777

78+
public static final String CLOUD_TOML_META_INFO = "cloud_toml_meta_info";
79+
@SerializedName(CLOUD_TOML_META_INFO)
80+
private FileMetaInfo cloudTomlMetaInfo;
81+
7882
public static final String TEST_ARTIFACT_META_INFO = "test_artifact_meta_info";
7983
@SerializedName(TEST_ARTIFACT_META_INFO)
8084
private FileMetaInfo[] testArtifactMetaInfo;
@@ -219,6 +223,14 @@ public void setTestClassPath(String testClassPath) {
219223
this.testClassPath = testClassPath;
220224
}
221225

226+
public void setCloudTomlMetaInfo(FileMetaInfo cloudTomlMetaInfo) {
227+
this.cloudTomlMetaInfo = cloudTomlMetaInfo;
228+
}
229+
230+
public FileMetaInfo getCloudTomlMetaInfo() {
231+
return cloudTomlMetaInfo;
232+
}
233+
222234
public static class FileMetaInfo {
223235
private String file;
224236
private String hash;

0 commit comments

Comments
 (0)