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() { |
Andrew Lewis | c05bbb6 | 2018-05-24 13:59:57 +0100 | [diff] [blame] | 11 | echo "Usage: $0 group:artifact:version[:classifier][@extension] [group:artifact:version[:classifier][@extension]...] |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 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 | |
Jeff Gaston | 796227a | 2018-07-13 16:52:32 -0400 | [diff] [blame] | 25 | |
| 26 | # usage: downloadArtifacts "$group:$artifact:$version[:classifier][@extension]..." |
| 27 | function downloadArtifacts() { |
| 28 | if [ "$1" == "" ]; then |
| 29 | usage |
| 30 | fi |
| 31 | echo downloading dependencies into $inputRepo |
| 32 | rm -rf $inputRepo |
| 33 | while [ "$1" != "" ]; do |
| 34 | echo importing $1 |
| 35 | IFS=@ read -r dependency extension <<< "$1" |
| 36 | IFS=: read -ra FIELDS <<< "${dependency}" |
| 37 | groupId="${FIELDS[0]}" |
| 38 | artifactId="${FIELDS[1]}" |
| 39 | version="${FIELDS[2]}" |
| 40 | classifier="${FIELDS[3]}" |
| 41 | |
| 42 | # download the actual artifact |
| 43 | downloadArtifact "$groupId" "$artifactId" "$version" "$classifier" "$extension" |
| 44 | |
| 45 | # try to download the sources jar |
| 46 | downloadArtifact "$groupId" "$artifactId" "$version" "sources" "jar" || true |
| 47 | |
| 48 | # go to next artifact |
| 49 | shift |
| 50 | done |
| 51 | echo done downloading dependencies |
| 52 | } |
| 53 | |
| 54 | # usage: downloadArtifact "$group" "$artifact" "$version" "$classifier" "$extension" |
| 55 | function downloadArtifact() { |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 56 | pomPath="$PWD/pom.xml" |
| 57 | echo creating $pomPath |
| 58 | pomPrefix='<?xml version="1.0" encoding="UTF-8"?> |
| 59 | <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"> |
| 60 | <modelVersion>4.0.0</modelVersion> |
| 61 | <groupId>com.google.android.build</groupId> |
| 62 | <artifactId>m2repository</artifactId> |
| 63 | <version>1.0</version> |
Aurimas Liutikas | 82a739e | 2018-04-03 10:39:30 -0700 | [diff] [blame] | 64 | <repositories> |
| 65 | <repository> |
| 66 | <id>google</id> |
| 67 | <name>Google</name> |
| 68 | <url>https://maven.google.com</url> |
| 69 | </repository> |
Jeff Gaston | f6923e3 | 2018-04-18 16:03:33 -0400 | [diff] [blame] | 70 | <repository> |
| 71 | <id>jcenter</id> |
| 72 | <name>JCenter</name> |
| 73 | <url>https://jcenter.bintray.com</url> |
| 74 | </repository> |
Aurimas Liutikas | 82a739e | 2018-04-03 10:39:30 -0700 | [diff] [blame] | 75 | </repositories> |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 76 | <dependencies> |
| 77 | ' |
| 78 | |
| 79 | pomSuffix=' |
| 80 | </dependencies> |
| 81 | <build> |
| 82 | <plugins> |
| 83 | <plugin> |
| 84 | <groupId>org.apache.maven.plugins</groupId> |
| 85 | <artifactId>maven-dependency-plugin</artifactId> |
| 86 | <version>2.8</version> |
| 87 | <executions> |
| 88 | <execution> |
| 89 | <id>default-cli</id> |
| 90 | <configuration> |
| 91 | <includeScope>runtime</includeScope> |
| 92 | <addParentPoms>true</addParentPoms> |
| 93 | <copyPom>true</copyPom> |
| 94 | <useRepositoryLayout>true</useRepositoryLayout> |
| 95 | <outputDirectory>m2repository</outputDirectory> |
| 96 | </configuration> |
| 97 | </execution> |
| 98 | </executions> |
| 99 | </plugin> |
| 100 | </plugins> |
| 101 | </build> |
| 102 | </project> |
| 103 | ' |
| 104 | |
Jeff Gaston | 796227a | 2018-07-13 16:52:32 -0400 | [diff] [blame] | 105 | |
| 106 | groupId="$1" |
| 107 | artifactId="$2" |
| 108 | version="$3" |
| 109 | classifier="$4" |
| 110 | extension="$5" |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 111 | pomDependencies="" |
| 112 | |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 113 | |
Jeff Gaston | 796227a | 2018-07-13 16:52:32 -0400 | [diff] [blame] | 114 | dependencyText=$(echo -e "\n <dependency>\n <groupId>${groupId}</groupId>\n <artifactId>${artifactId}</artifactId>\n <version>${version}</version>") |
| 115 | [ $classifier ] && dependencyText+=$(echo -e "\n <classifier>${classifier}</classifier>") |
| 116 | [ $extension ] && dependencyText+=$(echo -e "\n <type>${extension}</type>") |
| 117 | dependencyText+=$(echo -e "\n </dependency>") |
| 118 | |
| 119 | |
| 120 | pomDependencies="${pomDependencies}${dependencyText}" |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 121 | |
| 122 | echo "${pomPrefix}${pomDependencies}${pomSuffix}" > $pomPath |
| 123 | echo done creating $pomPath |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 124 | |
Jeff Gaston | 796227a | 2018-07-13 16:52:32 -0400 | [diff] [blame] | 125 | echo downloading one dependency into $inputRepo |
| 126 | mvn -f "$pomPath" dependency:copy-dependencies |
| 127 | echo done downloading one dependency into $inputRepo |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | # generates an appropriately formatted repository for merging into existing repositories, |
| 131 | # by computing artifact metadata |
| 132 | function stageRepo() { |
| 133 | echo staging to $stageRepo |
| 134 | rm -rf $stageRepo |
| 135 | |
| 136 | for f in $(find $inputRepo -type f | grep -v '\.sha1$' | grep -v '\.md5'); do |
| 137 | md5=$(md5sum $f | sed 's/ .*//') |
| 138 | sha1=$(sha1sum $f | sed 's/ .*//') |
| 139 | relPath=$(echo $f | sed "s|$inputRepo/||") |
| 140 | relDir=$(dirname $relPath) |
| 141 | |
| 142 | fileName=$(basename $relPath) |
| 143 | writeChecksums="true" |
| 144 | |
| 145 | destDir="$stageRepo/$relDir" |
| 146 | destFile="$stageRepo/$relPath" |
| 147 | if [ "$fileName" == "maven-metadata-local.xml" ]; then |
| 148 | writeChecksums="false" |
| 149 | destFile="$destDir/maven-metadata.xml" |
| 150 | fi |
| 151 | |
| 152 | mkdir -p $destDir |
| 153 | if [ "$writeChecksums" == "true" ]; then |
| 154 | echo -n $md5 > "${destFile}.md5" |
| 155 | echo -n $sha1 > "${destFile}.sha1" |
| 156 | fi |
| 157 | cp $f $destFile |
| 158 | done |
| 159 | |
| 160 | echo done staging to $stageRepo |
| 161 | } |
| 162 | |
| 163 | function announceCopy() { |
| 164 | input=$1 |
| 165 | output=$2 |
Jeff Gaston | 8d9231c | 2018-03-26 19:53:27 -0400 | [diff] [blame] | 166 | if stat $input > /dev/null 2>/dev/null; then |
| 167 | echo copying "$input" to "$output" |
| 168 | cp -rT $input $output |
| 169 | fi |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Yigit Boyar | db69c24 | 2018-04-30 09:09:05 -0700 | [diff] [blame] | 172 | function exportArtifact() { |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 173 | echo exporting |
| 174 | announceCopy $stageRepo/com/android $destAndroidRepo/com/android |
| 175 | rm -rf $stageRepo/com/android |
Jeff Gaston | f6923e3 | 2018-04-18 16:03:33 -0400 | [diff] [blame] | 176 | |
| 177 | announceCopy $stageRepo/androidx $destAndroidRepo/androidx |
| 178 | rm -rf $stageRepo/androidx |
| 179 | |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 180 | announceCopy $stageRepo $destThirdPartyRepo |
| 181 | echo done exporting |
| 182 | } |
| 183 | |
| 184 | |
| 185 | function main() { |
Jeff Gaston | 796227a | 2018-07-13 16:52:32 -0400 | [diff] [blame] | 186 | downloadArtifacts "$@" |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 187 | stageRepo |
Yigit Boyar | db69c24 | 2018-04-30 09:09:05 -0700 | [diff] [blame] | 188 | exportArtifact |
Jeff Gaston | 20c9bbc | 2018-03-07 15:25:43 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | main "$@" |