Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame^] | 1 | set -e |
| 2 | |
| 3 | |
| 4 | destRepo="$(cd $(dirname $0)/../.. && pwd)" |
| 5 | tempDir="/tmp/import-temp-work" |
| 6 | rm -rf $tempDir |
| 7 | mkdir -p $tempDir |
| 8 | cd $tempDir |
| 9 | |
| 10 | function usage() { |
| 11 | echo "Usage: $0 filePathOfSupportLibRepoCheckout group:artifact:version [group:artifact:version...] |
| 12 | |
| 13 | This script downloads the specified artifacts copies them into the appropriate subdirectory of $destRepo/prebuilts/" |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | inputRepo=m2repository |
| 21 | stageRepo=m2staged |
| 22 | destAndroidRepo=$destRepo/prebuilts/gradle-plugin |
| 23 | destThirdPartyRepo=$destRepo/prebuilts/tools/common/m2/repository |
| 24 | |
| 25 | function createPom() { |
| 26 | pomPath="$PWD/pom.xml" |
| 27 | echo creating $pomPath |
| 28 | pomPrefix='<?xml version="1.0" encoding="UTF-8"?> |
| 29 | <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| 30 | <modelVersion>4.0.0</modelVersion> |
| 31 | <groupId>com.google.android.build</groupId> |
| 32 | <artifactId>m2repository</artifactId> |
| 33 | <version>1.0</version> |
| 34 | <dependencies> |
| 35 | ' |
| 36 | |
| 37 | pomSuffix=' |
| 38 | </dependencies> |
| 39 | <build> |
| 40 | <plugins> |
| 41 | <plugin> |
| 42 | <groupId>org.apache.maven.plugins</groupId> |
| 43 | <artifactId>maven-dependency-plugin</artifactId> |
| 44 | <version>2.8</version> |
| 45 | <executions> |
| 46 | <execution> |
| 47 | <id>default-cli</id> |
| 48 | <configuration> |
| 49 | <includeScope>runtime</includeScope> |
| 50 | <addParentPoms>true</addParentPoms> |
| 51 | <copyPom>true</copyPom> |
| 52 | <useRepositoryLayout>true</useRepositoryLayout> |
| 53 | <outputDirectory>m2repository</outputDirectory> |
| 54 | </configuration> |
| 55 | </execution> |
| 56 | </executions> |
| 57 | </plugin> |
| 58 | </plugins> |
| 59 | </build> |
| 60 | </project> |
| 61 | ' |
| 62 | |
| 63 | pomDependencies="" |
| 64 | |
| 65 | while [ "$1" != "" ]; do |
| 66 | echo importing $1 |
| 67 | dependencyText="$(echo $1 | sed 's|\([^:]*\):\([^:]*\):\([^:]*\)|\n <dependency>\n <groupId>\1</groupId>\n <artifactId>\2</artifactId>\n <version>\3</version>\n </dependency>|')" |
| 68 | pomDependencies="${pomDependencies}${dependencyText}" |
| 69 | shift |
| 70 | done |
| 71 | |
| 72 | if [ "${pomDependencies}" == "" ]; then |
| 73 | usage |
| 74 | fi |
| 75 | |
| 76 | echo "${pomPrefix}${pomDependencies}${pomSuffix}" > $pomPath |
| 77 | echo done creating $pomPath |
| 78 | } |
| 79 | |
| 80 | |
| 81 | function downloadDependencies() { |
| 82 | echo downloading and/or copying dependencies to $inputRepo |
| 83 | rm -rf $inputRepo |
| 84 | mvn dependency:copy-dependencies |
| 85 | #mvn dependency:copy-dependencies -Dclassifier=javadoc |
| 86 | mvn dependency:copy-dependencies -Dclassifier=sources |
| 87 | echo done placing dependencies in $inputRepo |
| 88 | } |
| 89 | |
| 90 | # generates an appropriately formatted repository for merging into existing repositories, |
| 91 | # by computing artifact metadata |
| 92 | function stageRepo() { |
| 93 | echo staging to $stageRepo |
| 94 | rm -rf $stageRepo |
| 95 | |
| 96 | for f in $(find $inputRepo -type f | grep -v '\.sha1$' | grep -v '\.md5'); do |
| 97 | md5=$(md5sum $f | sed 's/ .*//') |
| 98 | sha1=$(sha1sum $f | sed 's/ .*//') |
| 99 | relPath=$(echo $f | sed "s|$inputRepo/||") |
| 100 | relDir=$(dirname $relPath) |
| 101 | |
| 102 | fileName=$(basename $relPath) |
| 103 | writeChecksums="true" |
| 104 | |
| 105 | destDir="$stageRepo/$relDir" |
| 106 | destFile="$stageRepo/$relPath" |
| 107 | if [ "$fileName" == "maven-metadata-local.xml" ]; then |
| 108 | writeChecksums="false" |
| 109 | destFile="$destDir/maven-metadata.xml" |
| 110 | fi |
| 111 | |
| 112 | mkdir -p $destDir |
| 113 | if [ "$writeChecksums" == "true" ]; then |
| 114 | echo -n $md5 > "${destFile}.md5" |
| 115 | echo -n $sha1 > "${destFile}.sha1" |
| 116 | fi |
| 117 | cp $f $destFile |
| 118 | done |
| 119 | |
| 120 | echo done staging to $stageRepo |
| 121 | } |
| 122 | |
| 123 | function announceCopy() { |
| 124 | input=$1 |
| 125 | output=$2 |
| 126 | echo copying "$input" to "$output" |
| 127 | cp -rT $input $output |
| 128 | } |
| 129 | |
| 130 | function export() { |
| 131 | echo exporting |
| 132 | announceCopy $stageRepo/com/android $destAndroidRepo/com/android |
| 133 | rm -rf $stageRepo/com/android |
| 134 | announceCopy $stageRepo $destThirdPartyRepo |
| 135 | echo done exporting |
| 136 | } |
| 137 | |
| 138 | |
| 139 | function main() { |
| 140 | createPom "$@" |
| 141 | downloadDependencies |
| 142 | stageRepo |
| 143 | export |
| 144 | } |
| 145 | |
| 146 | main "$@" |