Author: nmalin
Date: Fri Aug 9 15:18:16 2019
New Revision: 1864815
URL: http://svn.apache.org/viewvc?rev=1864815&view=rev
Log:
Implemented: Helper script to download the gradle wrapper
(OFBIZ-10145)
Add a helper script to download gradle-wrapper.jar and
gradle-wrapper.properties
at version 5.0.0 from bintray [1] when gradle/wrapper/gradle-wrapper.jar isn't
present.
To use it just run at the OFBiz root :
$ sh gradle/init-gradle-wrapper.sh
[1] https://dl.bintray.com/apacheofbiz/GradleWrapper/
[2] https://github.com/gradle/gradle/blob/v5.0.0/gradle/wrapper/
Added:
ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh
- copied, changed from r1861786,
ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh
Copied: ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh (from
r1861786, ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh)
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh?p2=ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh&p1=ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh&r1=1861786&r2=1864815&rev=1864815&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh (original)
+++ ofbiz/ofbiz-framework/trunk/gradle/init-gradle-wrapper.sh Fri Aug 9
15:18:16 2019
@@ -16,12 +16,20 @@
# specific language governing permissions and limitations
# under the License.
+# Variable for location
OFBIZ_HOME="$(pwd)"
GRADLE_OFBIZ_PATH="$OFBIZ_HOME/gradle"
GRADLE_WRAPPER_OFBIZ_PATH="$GRADLE_OFBIZ_PATH/wrapper"
+
+# version and uri to download the wrapper
RELEASE="5.0.0"
-#GRADLE_WRAPPER_URI="https://github.com/gradle/gradle/blob/v${RELEASE}/gradle/wrapper"
-GRADLE_WRAPPER_URI="https://svn.apache.org/repos/asf/ofbiz/tools/Buildbot/Gradle/Wrapper/trunk/"
+GRADLE_WRAPPER_URI="https://dl.bintray.com/apacheofbiz/GradleWrapper/v$RELEASE/"
+GRADLE_WRAPPER_URI_BACKUP="https://github.com/gradle/gradle/raw/v$RELEASE/gradle/wrapper/"
+
+# Embded checksum shasum to control the download
+SHASUM_GRADLE_WRAPPER_FILES="1d23286bcb9e7d3debff18c1b892b9dbb9a4ec6c
gradle/wrapper/gradle-wrapper.jar
+f9c2ad227ef1fe774cb0e141abfc431b05fc9fd4
gradle/wrapper/gradle-wrapper.properties"
+
GRADLE_WRAPPER_JAR="gradle-wrapper.jar"
GRADLE_WRAPPER_PROPERTIES="gradle-wrapper.properties"
GRADLE_WRAPPER_FILES="$GRADLE_WRAPPER_JAR $GRADLE_WRAPPER_PROPERTIES"
@@ -30,33 +38,62 @@ whereIsBinary() {
whereis $1 | grep /
}
+# Resolve the command to use for calling and realize the download
+downloadFile() {
+ if [ -n "$(whereIsBinary curl)" ]; then
+ GET_CMD="curl -L -o $GRADLE_WRAPPER_OFBIZ_PATH/$1 -s -w %{http_code}
$2/$1";
+ if [ "$($GET_CMD)" = "200" ]; then
+ return 0;
+ fi
+ elif [ -n "$(whereIsBinary wget)" ]; then
+ GET_CMD="wget -q -O $GRADLE_WRAPPER_OFBIZ_PATH/$1 --server-response
$2/$1";
+ GET_CMD="$GET_CMD"' 2>&1 > /dev/null | grep "HTTP/.* 200"';
+ if [ -n "$($GET_CMD)" ]; then
+ return 0;
+ fi
+ fi
+ return 1
+}
+
+# Call and if not succes try to use backup
+resolveFile() {
+ downloadFile $1 $GRADLE_WRAPPER_URI;
+ if [ $? -eq 1 ]; then
+ downloadFile $1 $GRADLE_WRAPPER_URI_BACKUP;
+ fi
+}
+
+echo " === Prepare operation ===";
+# Control that we work the script on a good directory
if [ ! -d "$GRADLE_OFBIZ_PATH" ]; then
echo "Location seems to be uncorrected, please take care to run 'sh
gradle/init-gradle-wrapper.sh' at the Apache OFBiz home";
- exit -1;
+ exit 1;
fi
-if [ ! -d "$GRADLE_WRAPPER_OFBIZ_PATH" ]; then
- mkdir $GRADLE_WRAPPER_OFBIZ_PATH
+# check if we have on binary to download missing wrapper
+if [ -z "$(whereIsBinary curl)" ] && [ -z "$(whereIsBinary wget)" ]; then
+ echo "No command curl or wget found, please install one or install yourself
gradle (more information see README.adoc or https://gradle.org/install)";
+ exit 1
fi
if [ ! -r "$GRADLE_WRAPPER_OFBIZ_PATH/$GRADLE_WRAPPER_JAR" ]; then
echo "$GRADLE_WRAPPER_OFBIZ_PATH/$GRADLE_WRAPPER_JAR not found, we
download it"
- if [ ! -r "$GRADLE_ZIP_RELEASE" ]; then
- if [ -n "$(whereIsBinary curl)" ]; then
- GET_CMD="curl -L -o";
- elif [ -n "$(whereIsBinary wget)" ]; then
- GET_CMD="wget -O";
- else
- echo "No command curl or wget found, please install one or install
yourself gradle (more information see https://gradle.org/install)";
- exit -1
- fi
- for fileToDownload in $GRADLE_WRAPPER_FILES; do
- $GET_CMD $GRADLE_WRAPPER_OFBIZ_PATH/$fileToDownload
$GRADLE_WRAPPER_URI/$fileToDownload?raw=true;
- done
- fi
+ for fileToDownload in $GRADLE_WRAPPER_FILES; do
+ echo " === Download $fileToDownload ===";
+ resolveFile $fileToDownload
+ done
if [ ! $? -eq 0 ]; then
rm -f $GRADLE_WRAPPER_OFBIZ_PATH/*
echo "\nDownload files $GRADLE_WRAPPER_FILES from $GRADLE_WRAPPER_URI
failed.\nPlease check the log to found the reason and run the script again."
fi
+ echo " === Control downloaded files ==="
+ if [ -n "$(whereIsBinary shasum)" ]; then
+ echo "$SHASUM_GRADLE_WRAPPER_FILES" | shasum -c -;
+ exit 0;
+ fi
+
+ echo " Warning: shasum not found, skip the control process"
+ exit 1;
fi
+echo " Nothing todo"