blob: ec895dddfab5cf2d73f7fb57f076c58200363752 [file] [log] [blame]
David Ostrovsky72623a12013-05-30 01:05:56 +02001# Copyright (C) 2013 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
David Ostrovsky2536d062013-11-14 00:35:07 +010015from os import path
16
David Ostrovsky2536d062013-11-14 00:35:07 +010017REPO_ROOTS = {
18 'GERRIT': 'http://gerrit-maven.storage.googleapis.com',
David Ostrovskya2707972014-01-17 09:04:35 +010019 'GERRIT_API': 'https://gerrit-api.commondatastorage.googleapis.com/release',
David Ostrovsky2536d062013-11-14 00:35:07 +010020 'MAVEN_CENTRAL': 'http://repo1.maven.org/maven2',
21 'MAVEN_LOCAL': 'file://' + path.expanduser('~/.m2/repository'),
22}
23
David Pursehouse15a9f532014-06-23 10:55:20 +090024
David Ostrovsky2536d062013-11-14 00:35:07 +010025def resolve_url(url, redirects):
26 """ Resolve URL of a Maven artifact.
27
28 prefix:path is passed as URL. prefix identifies known or custom
29 repositories that can be rewritten in redirects set, passed as
30 second arguments.
31
32 A special case is supported, when prefix neither exists in
33 REPO_ROOTS, no in redirects set: the url is returned as is.
34 This enables plugins to pass custom maven_repository URL as is
35 directly to maven_jar().
36
37 Returns a resolved path for Maven artifact.
38 """
39 s = url.find(':')
40 if s < 0:
41 return url
42 scheme, rest = url[:s], url[s+1:]
43 if scheme in redirects:
44 root = redirects[scheme]
45 elif scheme in REPO_ROOTS:
46 root = REPO_ROOTS[scheme]
47 else:
48 return url
49 root = root.rstrip('/')
50 rest = rest.lstrip('/')
51 return '/'.join([root, rest])