update 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #! /bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. # update a cordova/android project's command line tools
  20. #
  21. # USAGE
  22. # ./update [path]
  23. #
  24. set -e
  25. if [ -z "$1" ] || [ "$1" == "-h" ]
  26. then
  27. echo 'usage: update path'
  28. echo "Make sure the Android SDK tools folder is in your PATH!"
  29. exit 0
  30. fi
  31. BUILD_PATH="$( cd "$( dirname "$0" )/.." && pwd )"
  32. VERSION=$(cat "$BUILD_PATH"/VERSION)
  33. PROJECT_PATH="${1:-'./example'}"
  34. if [ ! -d "$PROJECT_PATH" ]
  35. then
  36. echo "The project path has to exist for it to be updated"
  37. exit 0
  38. fi
  39. # cleanup after exit and/or on error
  40. function on_exit {
  41. if [ -f "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js ]
  42. then
  43. rm "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js
  44. fi
  45. if [ -f "$BUILD_PATH"/framework/cordova-$VERSION.jar ]
  46. then
  47. rm "$BUILD_PATH"/framework/cordova-$VERSION.jar
  48. fi
  49. }
  50. function createAppInfoJar {
  51. (cd "$BUILD_PATH"/bin/templates/cordova/ApplicationInfo &&
  52. javac ApplicationInfo.java &&
  53. jar -cfe ../appinfo.jar ApplicationInfo ApplicationInfo.class
  54. )
  55. }
  56. function on_error {
  57. echo "An unexpected error occurred: $previous_command exited with $?"
  58. echo "Deleting project..."
  59. [ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH"
  60. exit 1
  61. }
  62. function replace {
  63. local pattern=$1
  64. local filename=$2
  65. # Mac OS X requires -i argument
  66. if [[ "$OSTYPE" =~ "darwin" ]]
  67. then
  68. /usr/bin/sed -i '' -e $pattern "$filename"
  69. elif [[ "$OSTYPE" =~ "linux" ]]
  70. then
  71. /bin/sed -i -e $pattern "$filename"
  72. fi
  73. }
  74. # we do not want the script to silently fail
  75. trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
  76. trap on_error ERR
  77. trap on_exit EXIT
  78. ANDROID_BIN="${ANDROID_BIN:=$( which android )}"
  79. TARGET=$("$ANDROID_BIN" list targets | grep id: | tail -1 | cut -f 2 -d ' ' )
  80. API_LEVEL=$("$ANDROID_BIN" list target | grep "API level:" | tail -n 1 | cut -f 2 -d ':' | tr -d ' ')
  81. # check that build targets exist
  82. if [ -z "$TARGET" ] || [ -z "$API_LEVEL" ]
  83. then
  84. echo "No Android Targets are installed. Please install at least one via the android SDK"
  85. exit 1
  86. fi
  87. # if this a distribution release no need to build a jar
  88. if [ ! -e "$BUILD_PATH"/cordova-$VERSION.jar ] && [ -d "$BUILD_PATH"/framework ]
  89. then
  90. # update the cordova-android framework for the desired target
  91. "$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
  92. if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then
  93. # Use curl to get the jar (TODO: Support Apache Mirrors)
  94. curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null
  95. unzip commons-codec-1.7-bin.zip &> /dev/null
  96. mkdir -p "$BUILD_PATH"/framework/libs
  97. cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs
  98. # cleanup yo
  99. rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7
  100. fi
  101. # compile cordova.js and cordova.jar
  102. (cd "$BUILD_PATH"/framework && ant jar &> /dev/null )
  103. fi
  104. # copy cordova.js, cordova.jar and res/xml
  105. if [ -d "$BUILD_PATH"/framework ]
  106. then
  107. cp "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js "$PROJECT_PATH"/assets/www/cordova-$VERSION.js
  108. cp "$BUILD_PATH"/framework/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar
  109. else
  110. cp "$BUILD_PATH"/cordova-$VERSION.js "$PROJECT_PATH"/assets/www/cordova-$VERSION.js
  111. cp "$BUILD_PATH"/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar
  112. fi
  113. # creating cordova folder and copying run/build/log/launch scripts
  114. cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar
  115. cp "$BUILD_PATH"/bin/templates/cordova/cordova "$PROJECT_PATH"/cordova/cordova
  116. cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build
  117. cp "$BUILD_PATH"/bin/templates/cordova/release "$PROJECT_PATH"/cordova/release
  118. cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
  119. cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
  120. cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run