106106import static io .ballerina .projects .util .ProjectConstants .DEPENDENCIES_TOML ;
107107import static io .ballerina .projects .util .ProjectConstants .DEPENDENCY_GRAPH_JSON ;
108108import static io .ballerina .projects .util .ProjectConstants .EXEC_BACKUP_DIR_NAME ;
109+ import static io .ballerina .projects .util .ProjectConstants .GENERATED_MODULES_ROOT ;
109110import static io .ballerina .projects .util .ProjectConstants .LIB_DIR ;
110111import static io .ballerina .projects .util .ProjectConstants .MODULES_ROOT ;
111112import static io .ballerina .projects .util .ProjectConstants .PACKAGE_JSON ;
113+ import static io .ballerina .projects .util .ProjectConstants .RESOURCE_DIR_NAME ;
112114import static io .ballerina .projects .util .ProjectConstants .SETTINGS_FILE_NAME ;
113115import static io .ballerina .projects .util .ProjectConstants .TEST_DIR_NAME ;
114116import static io .ballerina .projects .util .ProjectConstants .TOOL_DIR ;
@@ -1331,13 +1333,35 @@ public static boolean isFilesModifiedSinceLastBuild(BuildJson buildJson, Project
13311333 boolean skipExecutable ) throws IOException {
13321334 List <File > srcFilesToEvaluate = getSrcFiles (project );
13331335 List <File > testSrcFilesToEvaluate = getTestSrcFiles (project );
1334- if (isProjectFilesModified (buildJson .getSrcMetaInfo (), srcFilesToEvaluate , project )) {
1336+
1337+ if (isProjectFilesModified (buildJson .getSrcMetaInfo (), srcFilesToEvaluate )) {
1338+ return true ;
1339+ }
1340+ if (isTestExecution && isProjectFilesModified (buildJson .getTestSrcMetaInfo (), testSrcFilesToEvaluate )) {
13351341 return true ;
13361342 }
1337- if (isTestExecution && isProjectFilesModified (buildJson .getTestSrcMetaInfo (), testSrcFilesToEvaluate ,
1338- project )) {
1343+ Path resourcesPath = project .sourceRoot ().resolve (RESOURCE_DIR_NAME );
1344+ if (Files .exists (resourcesPath )) {
1345+ List <File > filesInResourcesDir = getFilesInDir (resourcesPath );
1346+ if (isProjectFilesModified (buildJson .getResourcesMetaInfo (), filesInResourcesDir )) {
1347+ return true ;
1348+ }
1349+ } else if (buildJson .getResourcesMetaInfo () != null ) {
1350+ // resources/ directory existed in the previous build but not in the current build.
13391351 return true ;
13401352 }
1353+
1354+ Path generatedPath = project .sourceRoot ().resolve (GENERATED_MODULES_ROOT );
1355+ if (Files .exists (generatedPath )) {
1356+ List <File > filesInGeneratedDir = getFilesInDir (generatedPath );
1357+ if (isProjectFilesModified (buildJson .getGeneratedMetaInfo (), filesInGeneratedDir )) {
1358+ return true ;
1359+ }
1360+ } else if (buildJson .getGeneratedMetaInfo () != null ) {
1361+ // generated/ directory existed in the previous build but not in the current build.
1362+ return true ;
1363+ }
1364+
13411365 if (isSettingsFileModified (buildJson )) {
13421366 return true ;
13431367 }
@@ -1357,6 +1381,15 @@ public static boolean isFilesModifiedSinceLastBuild(BuildJson buildJson, Project
13571381 return isExecutableModified (buildJson , project );
13581382 }
13591383
1384+ public static List <File > getFilesInDir (Path dirPath ) throws IOException {
1385+ try (var paths = Files .walk (dirPath )) {
1386+ return paths
1387+ .filter (Files ::isRegularFile )
1388+ .map (Path ::toFile )
1389+ .toList ();
1390+ }
1391+ }
1392+
13601393 public static DependencyGraph <BuildProject > resolveWorkspaceDependencies (
13611394 WorkspaceProject workspaceProject , PrintStream outStream ) {
13621395 outStream .println ("Resolving workspace dependencies" );
@@ -1373,7 +1406,7 @@ public static DependencyGraph<BuildProject> resolveWorkspaceDependencies(
13731406
13741407 private static boolean isTomlFileModified (BuildJson .FileMetaInfo tomlFileMetaInfo , File tomlFile ) {
13751408 if (tomlFileMetaInfo == null ) {
1376- // No Cloud.toml in the project
1409+ // No metadata exists for this TOML file (file was not tracked in the previous build)
13771410 return tomlFile .exists ();
13781411 }
13791412 try {
@@ -1440,9 +1473,10 @@ private static boolean isTestArtifactsModified(BuildJson buildJson, Project proj
14401473 return false ;
14411474 }
14421475
1443- private static boolean isProjectFilesModified (BuildJson .FileMetaInfo [] fileMetaInfos , List <File > filesToEvaluate ,
1444- Project project ) {
1445- if (fileMetaInfos == null || filesToEvaluate .size () != fileMetaInfos .length ) {
1476+ private static boolean isProjectFilesModified (BuildJson .FileMetaInfo [] fileMetaInfos , List <File > filesToEvaluate ) {
1477+ if (fileMetaInfos == null ) {
1478+ return !filesToEvaluate .isEmpty ();
1479+ } else if (filesToEvaluate .size () != fileMetaInfos .length ) {
14461480 return true ;
14471481 }
14481482 for (BuildJson .FileMetaInfo fileMetaInfo : fileMetaInfos ) {
0 commit comments