#!/bin/bash
# Garbage Collection of I-builds which are not referenced by the composite.

BUILD_TYPE="I"
ACTION="echo"
#ACTION="rm -rf"

# Use comm(1) to compute the difference betwenn all the existing folders and the children which are actually referenced in the composite.
#
# Col #1: exists, not referenced (can be removed)
# Col #2: does not exist, referenced
# Col #3: exists & referenced
#
# comm -23: only keep column 1
$ACTION $(comm -23 <(find . -maxdepth 1 -type d | grep "/$BUILD_TYPE" | sed -e 's|./||' | sort) <(cat <(unzip -p compositeArtifacts.jar compositeArtifacts.xml) <(unzip -p compositeContent.jar compositeContent.xml) | grep '<child ' | sort -u | cut -d"'" -f2))

