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