#!/bin/bash # Call like this: analyzeProduct.sh [ ...] # Updates Eclipse .launch files with the bundles needed for starting an SAP Sailing server based on the current feature.xml. # The .launch files must be in the workspace format that was introduced with Eclipse 2019-12. The script prints an error when no matching # replacement section could be found. # Will output two sections in format # # # # # section of the # .product definition in which case the start level and auto start values are copied from the # .product's section. NL=$'\n' GIT_ROOT=`dirname $0`/../../.. echo "GIT ROOT: $GIT_ROOT" features=$(cat "$1" | grep "feature id=" | sed -e 's/^.*feature id="\([^"]*\)".*$/\1/') echo ' *** Features ***' echo "$features" feature_xml_files=$(for i in $features; do echo "${GIT_ROOT}/java/$i/feature.xml"; done) echo "$feature_xml_files" # Determine the bundles with a specific configuration in the .product file: autostart_bundles=$(cat "$1" | grep "plugin id=.* startLevel=" | sed -e 's/^.* id="\(.*\)" autoStart="\(.*\)" startLevel="\([0-9-]*\)".*$/\1 \3 \2/') echo ' *** Autostart Bundles ***' echo "$autostart_bundles" # These autostart bundles need to be updated accordingly in the .launch configuration # so they have the correct startLevel and autostart settings. The autostart bundles # may occur either in the target_bundles or the workspace_bundles attribute in the .launch # configuration. All other entries in the .launch configuration are set to @default:default. # Now collect the bundles from the feature.xml files, split by workspace vs. target: for feature in $features; do feature_xml_file=${GIT_ROOT}/java/$feature/feature.xml bundles_in_feature=$(cat "$feature_xml_file" | grep "id=\"" | grep -v "id=\"$feature\"" | sed -e 's/^.*id="\([^"]*\)".*$/\1/') echo ' *** Bundles in feature' $feature '***' echo "$bundles_in_feature" for bundle in $bundles_in_feature; do # find out whether we have a non-default configuration for the bundle echo "$autostart_bundles" | grep -q '^'${bundle}' [^ ]* true$' if [ "$?" == "0" ]; then # found a configuration for the bundle echo ' *** Found a non-default configuration for bundle '${bundle}' ***' bundle_spec_for_launch=$(echo "$autostart_bundles" | grep '^'${bundle}' [^ ]* [^ ]*$' | sed -e 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\)$/\1\\@\2:\3/') else bundle_spec_for_launch="${bundle}\@default:default" fi if [[ $feature =~ .runtime$ ]]; then # contribute to target_bundles target_bundles="${target_bundles}${NL}" else # contribute to workspace_bundles workspace_bundles="${workspace_bundles}${NL}" fi done done echo ' *** Target Bundles ***' echo "${target_bundles}" echo ' *** Workspace Bundles ***' echo "${workspace_bundles}" # Now patch the .launch file if provided while [ "$2" != "" ]; do if grep -q key=\"target_bundles\" "$2"; then echo "Not patching $2 ... please use script for eclipse 2019-09 or older" else echo "Patching $2 ..." if echo "$2" | grep -q winddbTest; then launchEscape=$'\@default:default' patched_workspace_bundles="${workspace_bundles}${NL}${NL}" else patched_workspace_bundles="${workspace_bundles}" fi selected_target_bundles="${target_bundles}${NL}<\/setAttribute>" patched_workspace_bundles="${patched_workspace_bundles}${NL}<\/setAttribute>" # Used Perl CLI options: #0 -> specifies the record separator, as you alread found out, it defaults to \0 so it does not terminate before the end of the text file. Ensures that the regular expression is applied over the whole file. #p -> apply looping wrapper, see perl man page #e -> denotes the (regular) expression that is goint ot be applied. #i -> inplace editing of files perl -i -p0e "s/.*?<\/setAttribute>/${selected_target_bundles}/s" "$2" perl -i -p0e "s/.*?<\/setAttribute>/${patched_workspace_bundles}/s" "$2" # remove eventuelly created bak files (this happens at least on windows platform) rm -f "$2.bak" fi shift done