#!/bin/bash set -e readonly DEST_REPO="$(dirname $(readlink -f "$0"))/../.." readonly INPUT_REPO="m2repository" readonly STAGE_REPO="m2staged" readonly DEST_ANDROID_REPO="${DEST_REPO}/prebuilts/manifest-merger" if ! TEMP_DIR=$(mktemp -d); then echo "ERROR: failed to create dir" exit 1 fi readonly TEMP_DIR function cleanup() { rm -rf "${TEMP_DIR}" } trap cleanup EXIT cd "${TEMP_DIR}" function usage() { cat < "${pomFile}" 4.0.0 com.google.android.build m2repository 1.0 google Google https://maven.google.com jcenter JCenter https://jcenter.bintray.com ${groupId} ${artifactId} ${version} EOF if [ -n "${classifier}" ]; then cat <> "${pomFile}" ${classifier} EOF fi if [ -n "${extension}" ]; then cat <> "${pomFile}" ${extension} EOF fi cat <> "${pomFile}" org.apache.maven.plugins maven-dependency-plugin 2.8 default-cli runtime true true true m2repository EOF echo "done creating ${pomFile}" } # usage: downloadArtifact "$group" "$artifact" "$version" "$classifier" "$extension" function downloadArtifact() { local -r pomFile="${PWD}/pom.xml" generatePomFile "${pomFile}" "$@" echo "downloading one dependency into ${INPUT_REPO}" mvn -f "${pomFile}" dependency:copy-dependencies echo "done downloading one dependency into ${INPUT_REPO}" } # generates an appropriately formatted repository for merging into existing repositories, # by computing artifact metadata function createStageRepo() ( echo "staging to ${STAGE_REPO}" rm -rf "${STAGE_REPO}" for f in $(find "${INPUT_REPO}" -type f ! -name "*.sha1" ! -name "*.md5"); do local relPath="${f##${INPUT_REPO}}" local relDir=$(dirname "${relPath}") local fileName=$(basename "${relPath}") local writeChecksums=true local destDir="${STAGE_REPO}/${relDir}" local destFile="${STAGE_REPO}/${relPath}" if [ "${fileName}" == "maven-metadata-local.xml" ]; then writeChecksums=false destFile="${destDir}/maven-metadata.xml" fi mkdir -p "${destDir}" if ${writeChecksums}; then local md5=$(md5sum "${f}" | sed 's/ .*//') local sha1=$(sha1sum "${f}" | sed 's/ .*//') echo -n ${md5} > "${destFile}.md5" echo -n ${sha1} > "${destFile}.sha1" fi cp "${f}" "${destFile}" done echo "done staging to ${STAGE_REPO}" ) function announceCopy() { local -r input="$1" local -r output="$2" if [ -e "${input}" ]; then echo "copying '${input}' to '${output}'" cp -rT "${input}" "${output}" fi } function exportArtifact() { echo "exporting" mkdir -p "${DEST_ANDROID_REPO}/com/android" announceCopy "${STAGE_REPO}/com/android" "${DEST_ANDROID_REPO}/com/android" rm -rf "${STAGE_REPO}/com/android" echo "done exporting" } function main() { downloadArtifacts "$@" createStageRepo exportArtifact } main "$@"