@@ -36,6 +36,10 @@ export const RESULT_CACHE_STATES = Object.freeze({
3636 * @property {string } signature Signature of the cached stage
3737 * @property {@ui5/fs/AbstractReader } stage Reader for the cached stage
3838 * @property {string[] } writtenResourcePaths Array of resource paths written by the task
39+ * @property {Map<string, Map<string, {string|number|boolean|undefined}>> } projectTagOperations
40+ * Map of resource paths to their tags that were set or cleared during this stage's execution, for project tags
41+ * @property {Map<string, Map<string, {string|number|boolean|undefined}>> } buildTagOperations
42+ * Map of resource paths to their tags that were set or cleared during this stage's execution, for build tags
3943 */
4044
4145export default class ProjectBuildCache {
@@ -116,6 +120,7 @@ export default class ProjectBuildCache {
116120 */
117121 async prepareProjectBuildAndValidateCache ( dependencyReader ) {
118122 this . #currentProjectReader = this . #project. getReader ( ) ;
123+
119124 this . #currentDependencyReader = dependencyReader ;
120125
121126 if ( this . #combinedIndexState === INDEX_STATES . INITIAL ) {
@@ -295,9 +300,9 @@ export default class ProjectBuildCache {
295300 */
296301 async #importStages( stageSignatures ) {
297302 const stageNames = Object . keys ( stageSignatures ) ;
298- if ( this . #project. getStage ( ) ?. getId ( ) === "initial" ) {
303+ if ( this . #project. getProjectResources ( ) . getStage ( ) ?. getId ( ) === "initial" ) {
299304 // Only initialize stages once
300- this . #project. initStages ( stageNames ) ;
305+ this . #project. getProjectResources ( ) . initStages ( stageNames ) ;
301306 }
302307 const importedStages = await Promise . all ( stageNames . map ( async ( stageName ) => {
303308 const stageSignature = stageSignatures [ stageName ] ;
@@ -308,13 +313,14 @@ export default class ProjectBuildCache {
308313 }
309314 return [ stageName , stageCache ] ;
310315 } ) ) ;
311- this . #project. useResultStage ( ) ;
316+ this . #project. getProjectResources ( ) . useResultStage ( ) ;
312317 const writtenResourcePaths = new Set ( ) ;
313318 for ( const [ stageName , stageCache ] of importedStages ) {
314319 // Check whether the stage differs form the one currently in use
315320 if ( this . #currentStageSignatures. get ( stageName ) ?. join ( "-" ) !== stageCache . signature ) {
316321 // Set stage
317- this . #project. setStage ( stageName , stageCache . stage ) ;
322+ this . #project. getProjectResources ( ) . setStage ( stageName , stageCache . stage ,
323+ stageCache . projectTagOperations , stageCache . buildTagOperations ) ;
318324
319325 // Store signature for later use in result stage signature calculation
320326 this . #currentStageSignatures. set ( stageName , stageCache . signature . split ( "-" ) ) ;
@@ -387,7 +393,7 @@ export default class ProjectBuildCache {
387393 // Store current project reader (= state of the previous stage) for later use (e.g. in recordTaskResult)
388394 this . #currentProjectReader = this . #project. getReader ( ) ;
389395 // Switch project to new stage
390- this . #project. useStage ( stageName ) ;
396+ this . #project. getProjectResources ( ) . useStage ( stageName ) ;
391397 log . verbose ( `Preparing task execution for task ${ taskName } in project ${ this . #project. getName ( ) } ...` ) ;
392398 if ( ! taskCache ) {
393399 log . verbose ( `No task cache found` ) ;
@@ -420,7 +426,8 @@ export default class ProjectBuildCache {
420426 const stageCache = await this . #findStageCache( stageName , stageSignatures ) ;
421427 const oldStageSig = this . #currentStageSignatures. get ( stageName ) ?. join ( "-" ) ;
422428 if ( stageCache ) {
423- this . #project. setStage ( stageName , stageCache . stage ) ;
429+ this . #project. getProjectResources ( ) . setStage ( stageName , stageCache . stage ,
430+ stageCache . projectTagOperations , stageCache . buildTagOperations ) ;
424431
425432 // Check whether the stage actually changed
426433 if ( stageCache . signature !== oldStageSig ) {
@@ -541,7 +548,7 @@ export default class ProjectBuildCache {
541548 return ;
542549 }
543550 log . verbose ( `Found cached stage with signature ${ stageSignature } ` ) ;
544- const { resourceMapping, resourceMetadata} = stageMetadata ;
551+ const { resourceMapping, resourceMetadata, projectTagOperations , buildTagOperations } = stageMetadata ;
545552 let writtenResourcePaths ;
546553 let stageReader ;
547554 if ( resourceMapping ) {
@@ -570,10 +577,13 @@ export default class ProjectBuildCache {
570577 writtenResourcePaths = Object . keys ( resourceMetadata ) ;
571578 stageReader = this . #createReaderForStageCache( stageName , stageSignature , resourceMetadata ) ;
572579 }
580+
573581 return {
574582 signature : stageSignature ,
575583 stage : stageReader ,
576584 writtenResourcePaths,
585+ projectTagOperations : tagOpsToMap ( projectTagOperations ) ,
586+ buildTagOperations : tagOpsToMap ( buildTagOperations ) ,
577587 } ;
578588 } ) ) ;
579589 return stageCache ;
@@ -610,10 +620,12 @@ export default class ProjectBuildCache {
610620 const taskCache = this . #taskCache. get ( taskName ) ;
611621
612622 // Identify resources written by task
613- const stage = this . #project. getStage ( ) ;
623+ const stage = this . #project. getProjectResources ( ) . getStage ( ) ;
614624 const stageWriter = stage . getWriter ( ) ;
615625 const writtenResources = await stageWriter . byGlob ( "/**/*" ) ;
616626 const writtenResourcePaths = writtenResources . map ( ( res ) => res . getOriginalPath ( ) ) ;
627+ const { projectTagOperations, buildTagOperations} =
628+ this . #project. getProjectResources ( ) . getResourceTagOperations ( ) ;
617629
618630 let stageSignature ;
619631 if ( cacheInfo ) {
@@ -654,8 +666,8 @@ export default class ProjectBuildCache {
654666
655667 // Store resulting stage in stage cache
656668 this . #stageCache. addSignature (
657- this . #getStageNameForTask( taskName ) , stageSignature , this . #project. getStage ( ) ,
658- writtenResourcePaths ) ;
669+ this . #getStageNameForTask( taskName ) , stageSignature , this . #project. getProjectResources ( ) . getStage ( ) ,
670+ writtenResourcePaths , projectTagOperations , buildTagOperations ) ;
659671
660672 // Update task cache with new metadata
661673 log . verbose ( `Task ${ taskName } produced ${ writtenResourcePaths . length } resources` ) ;
@@ -733,7 +745,7 @@ export default class ProjectBuildCache {
733745 */
734746 async setTasks ( taskNames ) {
735747 const stageNames = taskNames . map ( ( taskName ) => this . #getStageNameForTask( taskName ) ) ;
736- this . #project. initStages ( stageNames ) ;
748+ this . #project. getProjectResources ( ) . initStages ( stageNames ) ;
737749
738750 // TODO: Rename function? We simply use it to have a point in time right before the project is built
739751 }
@@ -749,7 +761,7 @@ export default class ProjectBuildCache {
749761 * @returns {Promise<string[]> } Array of changed resource paths since the last build
750762 */
751763 async allTasksCompleted ( ) {
752- this . #project. useResultStage ( ) ;
764+ this . #project. getProjectResources ( ) . useResultStage ( ) ;
753765 if ( this . #combinedIndexState === INDEX_STATES . INITIAL ) {
754766 this . #combinedIndexState = INDEX_STATES . FRESH ;
755767 }
@@ -763,6 +775,10 @@ export default class ProjectBuildCache {
763775 return changedPaths ;
764776 }
765777
778+ buildFinished ( ) {
779+ this . #project. getProjectResources ( ) . buildFinished ( ) ;
780+ }
781+
766782 /**
767783 * Generates the stage name for a given task
768784 *
@@ -947,7 +963,8 @@ export default class ProjectBuildCache {
947963 `with build signature ${ this . #buildSignature} ` ) ;
948964 const stageQueue = this . #stageCache. flushCacheQueue ( ) ;
949965 await Promise . all ( stageQueue . map ( async ( [ stageId , stageSignature ] ) => {
950- const { stage} = this . #stageCache. getCacheForSignature ( stageId , stageSignature ) ;
966+ const { stage, projectTagOperations, buildTagOperations} =
967+ this . #stageCache. getCacheForSignature ( stageId , stageSignature ) ;
951968 const writer = stage . getWriter ( ) ;
952969
953970 let metadata ;
@@ -974,7 +991,8 @@ export default class ProjectBuildCache {
974991 const resourceMetadata = await this . #writeStageResources( resources , stageId , stageSignature ) ;
975992 metadata = { resourceMetadata} ;
976993 }
977-
994+ metadata . projectTagOperations = tagOpsToObject ( projectTagOperations ) ;
995+ metadata . buildTagOperations = tagOpsToObject ( buildTagOperations ) ;
978996 await this . #cacheManager. writeStageCache (
979997 this . #project. getId ( ) , this . #buildSignature, stageId , stageSignature , metadata ) ;
980998 } ) ) ;
@@ -1183,3 +1201,23 @@ function createStageSignature(projectSignature, dependencySignature) {
11831201function createDependencySignature ( stageDependencySignatures ) {
11841202 return crypto . createHash ( "sha256" ) . update ( stageDependencySignatures . join ( "" ) ) . digest ( "hex" ) ;
11851203}
1204+
1205+ function tagOpsToMap ( tagOps ) {
1206+ const map = new Map ( ) ;
1207+ for ( const [ resourcePath , tags ] of Object . entries ( tagOps ) ) {
1208+ map . set ( resourcePath , new Map ( Object . entries ( tags ) ) ) ;
1209+ }
1210+ return map ;
1211+ }
1212+
1213+ /**
1214+ * @param {Map<string, Map<string, {string|number|boolean|undefined}>> } tagOps
1215+ * Map of resource paths to their tag operations
1216+ */
1217+ function tagOpsToObject ( tagOps ) {
1218+ const obj = Object . create ( null ) ;
1219+ for ( const [ resourcePath , tags ] of tagOps . entries ( ) ) {
1220+ obj [ resourcePath ] = Object . fromEntries ( tags . entries ( ) ) ;
1221+ }
1222+ return obj ;
1223+ }
0 commit comments