migrate.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. # This script creates a new branch then migrate all the maven stuff in it and commit that branch.
  6. # then it runs mvn install to check that everything is still running
  7. # Useful commands while testing
  8. # rm -rf migration/tmp plugins
  9. # git checkout pr/migration_script -f
  10. # git add .; git commit -m "Add migration script" --amend
  11. # ./migrate.sh
  12. # mvn clean install -DskipTests
  13. GIT_BRANCH="refactoring/add_lang"
  14. # Insert a new text after a given line
  15. # insertLinesAfter text_to_find text_to_add newLine_separator filename
  16. # insertLinesAfter "<\/project>" " <modules>= <\/modules>" "§" "pom.xml"
  17. function insertLinesAfter() {
  18. # echo "## modify $4 with $2"
  19. sed "s/$1/$1$3$2/" $4 | tr "$3" "\n" > $4.new
  20. mv $4.new $4
  21. }
  22. # Insert a new text before a given line
  23. # insertLinesBefore text_to_find text_to_add newLine_separator filename
  24. # insertLinesBefore "<\/project>" " <modules>= <\/modules>" "§" "pom.xml"
  25. function insertLinesBefore() {
  26. # echo "## modify $4 with $2"
  27. sed "s/$1/$2$3$1/" $4 | tr "$3" "\n" > $4.new
  28. mv $4.new $4
  29. }
  30. # Replace text in a file
  31. # replaceLine old_text new_text filename
  32. # replaceLine "old" "new" "pom.xml"
  33. function replaceLine() {
  34. # echo "## modify $3 with $2"
  35. sed "s/^$1/$2/" $3 > $3.new
  36. mv $3.new $3
  37. }
  38. # Remove lines in a file
  39. # removeLines from_text_included to_text_included filename
  40. # removeLines "old" "new" "pom.xml"
  41. function removeLines() {
  42. # echo "## remove lines in $3 from $1 to $2"
  43. sed "/$1/,/$2/d" $3 > $3.new
  44. mv $3.new $3
  45. }
  46. # Migrate a plugin
  47. # migratePlugin short_name
  48. function migratePlugin() {
  49. PLUGIN_GIT_REPO="https://github.com/elastic/elasticsearch-$1.git"
  50. git remote add remote_$1 $PLUGIN_GIT_REPO
  51. git fetch remote_$1 > /dev/null 2>/dev/null
  52. echo "## Add $1 module from $PLUGIN_GIT_REPO"
  53. # echo "### fetch $1 project from $PLUGIN_GIT_REPO in plugins"
  54. # If you want to run that locally, uncomment this line and comment one below
  55. #cp -R ../elasticsearch-$1/* plugins/$1
  56. # git clone $PLUGIN_GIT_REPO plugins/$1 > /dev/null 2>/dev/null
  57. git checkout -b migrate_$1 remote_$1/master > /dev/null 2>/dev/null
  58. git remote rm remote_$1 > /dev/null 2>/dev/null
  59. mkdir -p plugins/$1
  60. git mv -k * plugins/$1 > /dev/null 2>/dev/null
  61. git rm .gitignore > /dev/null 2>/dev/null
  62. # echo "### change $1 groupId to org.elasticsearch.plugins"
  63. # Change the groupId to avoid conflicts with existing 2.0.0 versions.
  64. replaceLine " <groupId>org.elasticsearch<\/groupId>" " <groupId>org.elasticsearch.plugin<\/groupId>" "plugins/$1/pom.xml"
  65. # echo "### cleanup $1 pom.xml"
  66. removeLines "<issueManagement>" "<\/issueManagement>" "plugins/$1/pom.xml"
  67. removeLines "<repositories>" "<\/repositories>" "plugins/$1/pom.xml"
  68. removeLines "<url>" "<\/scm>" "plugins/$1/pom.xml"
  69. # echo "### remove version 3.0.0-SNAPSHOT from $1 pom.xml"
  70. # All plugins for ES 2.0.0 uses 3.0.0-SNAPSHOT version number
  71. replaceLine " <version>3.0.0-SNAPSHOT<\/version>" "" "plugins/$1/pom.xml"
  72. # echo "### remove unused dev-tools and .git dirs and LICENSE.txt and CONTRIBUTING.md files"
  73. rm -r plugins/$1/dev-tools
  74. rm -rf plugins/$1/.git
  75. rm plugins/$1/LICENSE.txt
  76. rm plugins/$1/CONTRIBUTING.md
  77. # echo "### commit changes"
  78. git add --all .
  79. git commit -m "add $1 module" > /dev/null
  80. git checkout $GIT_BRANCH
  81. git merge -m "migrate branch for $1" migrate_$1 > /dev/null 2>/dev/null
  82. # We can now add plugin module
  83. insertLinesBefore " <\/modules>" " <module>$1<\/module>" "§" "plugins/pom.xml"
  84. git add .
  85. git commit -m "add $1 module" > /dev/null
  86. git branch -D migrate_$1
  87. }
  88. echo "# STEP 0 : prepare the job"
  89. # echo "## create git $GIT_BRANCH work branch"
  90. # It first clean the existing branch if any
  91. echo "(You can safely ignore branch not found below)"
  92. git branch -D $GIT_BRANCH > /dev/null || :
  93. # Create the new branch
  94. git branch $GIT_BRANCH > /dev/null
  95. git checkout $GIT_BRANCH > /dev/null 2>/dev/null
  96. echo "# STEP 4 : Migrate plugins"
  97. # Analysis
  98. migratePlugin "lang-python"
  99. migratePlugin "lang-javascript"
  100. echo "you can now run:"
  101. echo "mvn clean install -DskipTests"