#!/bin/sh

set -e

for pomfile in `find . -name pom.xml -print`
do
  echo "processing $pomfile"
  for rename in \
    "hippo-ecm                                      hippo-package" \
    "hippo-ecm-package                              hippo-package-cms" \
    "hippo-ecm-package-war                          hippo-package-cms-war" \
    "hippo-ecm-package-ear                          hippo-package-cms-ear" \
    "hippo-ecm-package-test                         hippo-package-cms-test" \
    "hippo-ecm-package-resources                    hippo-package-cms-resources" \
    "hippo-ecm-package-dependencies                 hippo-package-cms-dependencies" \
    "hippo-ecm-quickstart                           hippo-quickstart" \
    "hippo-ecm-quickstart-war                       hippo-quickstart-war" \
    "hippo-ecm-quickstart-ear                       hippo-quickstart-ear" \
    "hippo-ecm-quickstart-test                      hippo-quickstart-test" \
    "hippo-ecm-quickstart-bin                       hippo-quickstart-bin" \
    "hippo-ecm-repository                           hippo-repository" \
    "hippo-ecm-repository-tools                     hippo-repository-tools" \
    "hippo-ecm-repository-tools-documentation       hippo-repository-tools-documentation" \
    "hippo-ecm-repository-tools-testutils           hippo-repository-tools-testutils" \
    "hippo-ecm-addon-sample                         hippo-repository-sample" \
    "hippo-ecm-addon-sample-common                  hippo-repository-sample-common" \
    "hippo-ecm-addon-sample-repository              hippo-repository-sample-repository" \
    "hippo-ecm-cms                                  hippo-cms" \
    "hippo-ecm-addon                                hippo-cms" \
    "hippo-ecm-frontend                             hippo-cms" \
    "hippo-ecm-addon-standards                      hippo-cms" \
    "hippo-ecm-addon-cms                            hippo-cms" \
    "hippo-ecm-addon-reporting                      hippo-cms" \
    "hippo-ecm-addon-search                         hippo-cms" \
    "hippo-ecm-frontend-engine                      hippo-cms-engine" \
    "hippo-ecm-frontend-plugins                     hippo-cms-plugins" \
    "hippo-ecm-frontend-engine-test                 hippo-cms-test" \
    "hippo-ecm-package-config                       hippo-cms-config" \
    "hippo-ecm-package-skin                         hippo-cms-skin" \
    "hippo-ecm-tools                                hippo-cms-tools" \
    "hippo-ecm-tools-development-content            hippo-cms-tools-development-content" \
    "hippo-ecm-tools-eclipse                        hippo-cms-tools-eclipse" \
    "hippo-ecm-tools-upgrade                        hippo-cms-tools-upgrade" \
    "hippo-ecm-addon-xinha-frontend                 hippo-cms-xinha-integration" \
    "hippo-ecm-addon-xinha                          hippo-cms-xinha-resources" \
    "hippo-ecm-addon-xinha-test                     hippo-cms-xinha-test" \
    "hippo-ecm-frontend-application                 hippo-cms-application" \
    "hippo-ecm-package-layout                       hippo-cms-layout" \
    "hippo-ecm-addon-builtin-frontend               hippo-cms-builtin" \
    "hippo-ecm-addon-cms-admin                      hippo-cms-admin" \
    "hippo-ecm-addon-cms-browse                     hippo-cms-browse" \
    "hippo-ecm-addon-cms-dashboard                  hippo-cms-dashboard" \
    "hippo-ecm-addon-cms-edit                       hippo-cms-edit" \
    "hippo-ecm-addon-cms-root                       hippo-cms-rootpage" \
    "hippo-ecm-addon-editor                         hippo-cms-editor" \
    "hippo-ecm-addon-editor-common                  hippo-cms-editor-common" \
    "hippo-ecm-addon-editor-frontend                hippo-cms-editor-frontend" \
    "hippo-ecm-addon-editor-repository              hippo-cms-editor-repository" \
    "hippo-ecm-addon-editor-test                    hippo-cms-editor-test" \
    "hippo-ecm-addon-gallery                        hippo-cms-gallery" \
    "hippo-ecm-addon-gallery-common                 hippo-cms-gallery-common" \
    "hippo-ecm-addon-gallery-frontend               hippo-cms-gallery-frontend" \
    "hippo-ecm-addon-gallery-repository             hippo-cms-gallery-repository" \
    "hippo-ecm-addon-gotolink                       hippo-cms-gotolink" \
    "hippo-ecm-addon-reporting-frontend             hippo-cms-reporting" \
    "hippo-ecm-addon-search-frontend                hippo-cms-search" \
    "hippo-ecm-addon-standards-frontend             hippo-cms-api" \
    "hippo-ecm-addon-versioning                     hippo-cms-versioning" \
    "hippo-ecm-addon-workflow                       hippo-cms-workflowmenu" \
    "hippo-ecm-addon-yui                            hippo-cms-yui" \
    "hippo-ecm-addon-translation                    hippo-cms-translation" \
    "hippo-ecm-addon-translation-test               hippo-cms-translation-test" \
    "hippo-ecm-addon-translation-common             hippo-cms-translation-common" \
    "hippo-ecm-addon-translation-frontend           hippo-cms-translation-frontend" \
    "hippo-ecm-addon-translation-repository         hippo-cms-translation-repository" \
    "hippo-ecm-api                                  hippo-repository-api" \
    "hippo-ecm-repository-checker                   hippo-repository-checker  " \
    "hippo-ecm-repository-connector                 hippo-repository-connector" \
    "hippo-ecm-repository-engine                    hippo-repository-engine   " \
    "hippo-ecm-repository-jca                       hippo-repository-jca      " \
    "hippo-ecm-repository-modules                   hippo-repository-modules  " \
    "hippo-ecm-repository-provider                  hippo-repository-provider " \
    "hippo-ecm-repository-servlets                  hippo-repository-servlets " \
    "hippo-ecm-repository-test                      hippo-repository-test     " \
    "hippo-ecm-repository-upgrade                   hippo-repository-upgrade  " \
    "hippo-ecm-repository-utilities                 hippo-repository-utilities" \
    "hippo-ecm-repository-application               hippo-repository-application" \
    "hippo-ecm-addon-builtin-common                 hippo-repository-builtin" \
    "hippo-ecm-addon-builtin-repository             hippo-repository-config" \
    "hippo-ecm-addon-sample-common                  hippo-repository-sample-common" \
    "hippo-ecm-addon-sample-repository              hippo-repository-sample-repository" \
    "hippo-ecm-addon-sample-test                    hippo-repository-sample-test" \
    "hippo-ecm-addon-ldap-repository                hippo-repository-ldap" \
    "hippo-ecm-tools-documentation                  hippo-repository-tools-documentation" \
    "hippo-ecm-tools-testutils                      hippo-repository-tools-testutils" \
    "hippo-ecm-addon-reviewed-action-common         hippo-reviewedactions-common" \
    "hippo-ecm-addon-reviewed-action-frontend       hippo-reviewedactions-frontend" \
    "hippo-ecm-addon-reviewed-action-repository     hippo-reviewedactions-repository" \
    "hippo-ecm-addon-reviewed-action-test           hippo-reviewedactions-test" \
    "hippo-ecm-package-dependencies                 hippo-package-cms-dependencies" \
    "hippo-ecm-package-resources                    hippo-package-cms-resources" \
    "hippo-ecm-package-war                          hippo-package-cms-war" \
    "hippo-ecm-package-ear                          hippo-package-cms-ear" \
    "hippo-ecm-quickstart-bin                       hippo-quickstart-cms-bin" \
    "hippo-ecm-quickstart-war                       hippo-quickstart-cms-war" \
    "hippo-ecm-quickstart-ear                       hippo-quickstart-cms-ear" \
    "hippo-ecm-quickstart-portal-test               hippo-quickstart-cms-portal-test" \
    "hippo-ecm-addon-defaultcontent-frontend        hippo-addon-defaultcontent-frontend" \
    "hippo-ecm-addon-defaultcontent-repository      hippo-addon-defaultcontent-repository" \
    "hippo-ecm-addon-faceteddate-frontend           hippo-addon-faceteddate-frontend" \
    "hippo-ecm-addon-faceteddate-repository         hippo-addon-faceteddate-repository" \
    "hippo-ecm-addon-reviewed-action                hippo-addon-publication-workflow" \
    "hippo-ecm-addon-reviewed-action-common         hippo-addon-publication-workflow-common" \
    "hippo-ecm-addon-reviewed-action-repository     hippo-addon-publication-workflow-repository" \
    "hippo-ecm-addon-reviewed-action-frontend       hippo-addon-publication-workflow-frontend" \
    "hippo-ecm-addon-faceteddate                    hippo-addon-faceteddate" \
    "hippo-ecm-addon-faceteddate-repository         hippo-addon-faceteddate-repository" \
    "hippo-ecm-addon-faceteddate-frontend           hippo-addon-faceteddate-frontend" \
    "hippo-ecm-addon-defaultcontent                 hippo-addon-defaultcontent" \
    "hippo-ecm-addon-defaultcontent-repository      hippo-addon-defaultcontent-repository" \
    "hippo-ecm-addon-defaultcontent-frontend        hippo-addon-defaultcontent-frontend" \
    "hippo-ecm-tools-projectexport                  hippo-addon-projectexport"
  do
    fromname=`echo $rename | awk '{print $1}'`
    toname=`echo $rename | awk '{print $2}'`
    sed -e "s/>$fromname</>$toname</g" < $pomfile > $pomfile~
    cat < $pomfile~ > $pomfile
  done
  sed -e "s/>org.hippoecm</>org.onehippo</g"  < $pomfile > $pomfile~
  cat < $pomfile~ > $pomfile
  rm $pomfile~
done

set +e

find . -name .svn -prune -o -name target -prune -o -name pom.xml | xargs grep -l artifact.*hippo-ecm | sed 's/$/ still contains reference to hippo-ecm project/'

exit 0
