Created
December 1, 2015 03:40
-
-
Save pfn/3c8e89c0b8a1d87048f8 to your computer and use it in GitHub Desktop.
gradle dependency extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
modulere = re.compile("""\s*compile\s*['"]([^:]+):([^:]+):([^:@]+)(@aar)?['"]""") | |
repore = re.compile("""\s*maven\s*\{\s*url\s*['"]([^'"]+)['"]\s*\}\s*""") | |
script = file("mobile/build.gradle", "r") | |
lines = script.readlines() | |
def convertlines(acc, l): | |
repo = re.match(repore, l) | |
if repo and not "fabric" in l: | |
r = """ <repository> | |
<id>repo-%d</id> | |
<name>repo-%d</name> | |
<url>%s</url> | |
</repository>""" % (len(acc[0]), len(acc[0]), repo.group(1)) | |
acc[0].append(r) | |
module = re.match(modulere, l) | |
if module: | |
if module.lastindex == 4: | |
r = """ <dependency> | |
<groupId>%s</groupId> | |
<artifactId>%s</artifactId> | |
<version>%s</version> | |
<type>%s</type> | |
</dependency>""" % (module.group(1), module.group(2), module.group(3), module.group(4)[1:]) | |
else: | |
r = """ <dependency> | |
<groupId>%s</groupId> | |
<artifactId>%s</artifactId> | |
<version>%s</version> | |
</dependency>""" % (module.group(1), module.group(2), module.group(3)) | |
acc[1].append(r) | |
return acc | |
result = reduce(convertlines, lines, ([], [])) | |
print("""<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.extractor</groupId> | |
<artifactId>dependency-extractor</artifactId> | |
<version>6.0-SNAPSHOT</version> | |
<packaging>pom</packaging> | |
<name>dependency-extractor</name> | |
<repositories> | |
<repository> | |
<id>local-android</id> | |
<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url> | |
</repository> | |
<repository> | |
<id>local-google</id> | |
<url>file://${env.ANDROID_HOME}/extras/google/m2repository</url> | |
</repository> | |
""") | |
for r in result[0]: print(r) | |
print(""" </repositories> | |
<dependencies>""") | |
for r in result[1]: print(r) | |
print(""" </dependencies> | |
</project>""") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment