# Copied and adapted from prebuilts/tools set -e destRepo="$(cd $(dirname $0)/../.. && pwd)" tempDir="/tmp/import-temp-work" rm -rf $tempDir mkdir -p $tempDir cd $tempDir function usage() { echo "Usage: $0 group:artifact:version[:classifier][@extension] [group:artifact:version[:classifier][@extension]...] This script downloads the specified artifacts copies them into the appropriate subdirectory of $destRepo/prebuilts/" exit 1 } inputRepo=m2repository stageRepo=m2staged destAndroidRepo=$destRepo/prebuilts/openeuicc-deps/gradle destThirdPartyRepo=$destRepo/prebuilts/openeuicc-deps/repository # usage: downloadArtifacts "$group:$artifact:$version[:classifier][@extension]..." function downloadArtifacts() { if [ "$1" == "" ]; then usage fi echo downloading dependencies into $inputRepo rm -rf $inputRepo while [ "$1" != "" ]; do echo importing $1 IFS=@ read -r dependency extension <<< "$1" IFS=: read -ra FIELDS <<< "${dependency}" groupId="${FIELDS[0]}" artifactId="${FIELDS[1]}" version="${FIELDS[2]}" classifier="${FIELDS[3]}" # download the actual artifact downloadArtifact "$groupId" "$artifactId" "$version" "$classifier" "$extension" # try to download the sources jar downloadArtifact "$groupId" "$artifactId" "$version" "sources" "jar" || true # go to next artifact shift done echo done downloading dependencies } # usage: downloadArtifact "$group" "$artifact" "$version" "$classifier" "$extension" function downloadArtifact() { pomPath="$PWD/pom.xml" echo creating $pomPath pomPrefix=' 4.0.0 com.google.android.build m2repository 1.0 mavenCentral Maven Central https://repo.maven.apache.org/maven2 jcenter JCenter https://jcenter.bintray.com ' pomSuffix=' org.apache.maven.plugins maven-dependency-plugin 2.8 default-cli runtime true true true m2repository ' groupId="$1" artifactId="$2" version="$3" classifier="$4" extension="$5" pomDependencies="" dependencyText=$(echo -e "\n \n ${groupId}\n ${artifactId}\n ${version}") [ $classifier ] && dependencyText+=$(echo -e "\n ${classifier}") [ $extension ] && dependencyText+=$(echo -e "\n ${extension}") dependencyText+=$(echo -e "\n ") pomDependencies="${pomDependencies}${dependencyText}" echo "${pomPrefix}${pomDependencies}${pomSuffix}" > $pomPath echo done creating $pomPath echo downloading one dependency into $inputRepo mvn -f "$pomPath" dependency:copy-dependencies echo done downloading one dependency into $inputRepo } # generates an appropriately formatted repository for merging into existing repositories, # by computing artifact metadata function stageRepo() { echo staging to $stageRepo rm -rf $stageRepo for f in $(find $inputRepo -type f | grep -v '\.sha1$' | grep -v '\.md5'); do md5=$(md5sum $f | sed 's/ .*//') sha1=$(sha1sum $f | sed 's/ .*//') relPath=$(echo $f | sed "s|$inputRepo/||") relDir=$(dirname $relPath) fileName=$(basename $relPath) writeChecksums="true" destDir="$stageRepo/$relDir" destFile="$stageRepo/$relPath" if [ "$fileName" == "maven-metadata-local.xml" ]; then writeChecksums="false" destFile="$destDir/maven-metadata.xml" fi mkdir -p $destDir if [ "$writeChecksums" == "true" ]; then echo -n $md5 > "${destFile}.md5" echo -n $sha1 > "${destFile}.sha1" fi cp $f $destFile done echo done staging to $stageRepo } function announceCopy() { input=$1 output=$2 if stat $input > /dev/null 2>/dev/null; then echo copying "$input" to "$output" cp -rT $input $output fi } function exportArtifact() { echo exporting announceCopy $stageRepo/com/android $destAndroidRepo/com/android rm -rf $stageRepo/com/android announceCopy $stageRepo/androidx $destAndroidRepo/androidx rm -rf $stageRepo/androidx announceCopy $stageRepo $destThirdPartyRepo echo done exporting } function main() { downloadArtifacts "$@" stageRepo exportArtifact } main "$@"