• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Script used to build ADT plugins, IDE and monitor
2// There are 2 major tasks done by this plugin:
3//    copydeps: copies tools/base, tools/swt and prebuilt jars into plugins' libs folder
4//    buildEclipse: builds Eclipse by running Tycho from the commandline
5//
6// Usage: $ ANDROID_SRC/tools/gradlew -i -b /path/to/this/build.gradle copydeps|buildEclipse
7
8// get tools/base version
9apply from: "../../tools/buildSrc/base/version.gradle"
10
11repositories {
12    maven { url '../../prebuilts/tools/common/m2/repository' }
13    maven { url '../../out/repo' }
14}
15
16ext {
17    // list of plugins whose manifest should be examined to identify dependencies
18    adtPlugins = new File(projectDir, 'plugins').listFiles().findAll { it.name.startsWith("com.android") }
19
20    //
21    def eclipseBuildDeps = new File(projectDir, "../../prebuilts/eclipse-build-deps").getCanonicalFile()
22    targetComponents = [
23            "platform": new File(eclipseBuildDeps, "platform/org.eclipse.platform-4.2.2.zip"),
24            "cdt"     : new File(eclipseBuildDeps, "cdt/cdt-master-8.0.2.zip"),
25            "emf"     : new File(eclipseBuildDeps, "emf/emf-xsd-Update-2.9.1.zip"),
26            "jdt"     : new File(eclipseBuildDeps, "jdt/org.eclipse.jdt.source-4.2.2.zip"),
27            "wtp"     : new File(eclipseBuildDeps, "wtp/wtp-repo-R-3.3.2-20120210195245.zip"),
28            "gef"     : new File(eclipseBuildDeps, "gef/GEF-Update-3.9.1.zip"),
29            "pde"     : new File(eclipseBuildDeps, "pde/org.eclipse.pde-3.8.zip"),
30            "egit"    : new File(eclipseBuildDeps, "egit/org.eclipse.egit.repository-2.2.0.201212191850-r.zip"),
31    ]
32
33    buildNumber = System.getenv("BUILD_NUMBER")
34    if (buildNumber == null) {
35        buildNumber = "SNAPSHOT"
36    }
37}
38
39// a mapping from the library names as used inside the plugin's MANIFEST.MF to the Maven artifact id
40def artifacts = [
41        // tools/base and tools/swt dependencies
42        'manifest-merger'     : "com.android.tools.build:manifest-merger:$ext.baseVersion",
43        'ddmlib'              : "com.android.tools.ddms:ddmlib:$ext.baseVersion",
44        'ddmuilib'            : "com.android.tools.ddms:ddmuilib:$ext.baseVersion",
45        'layoutlib-api'       : "com.android.tools.layoutlib:layoutlib-api:$ext.baseVersion",
46        'lint-api'            : "com.android.tools.lint:lint-api:$ext.baseVersion",
47        'lint-checks'         : "com.android.tools.lint:lint-checks:$ext.baseVersion",
48        'asset-studio'        : "com.android.tools:asset-studio:$ext.baseVersion",
49        'common'              : "com.android.tools:common:$ext.baseVersion",
50        'dvlib'               : "com.android.tools:dvlib:$ext.baseVersion",
51        'hierarchyviewer2lib' : "com.android.tools:hierarchyviewer2lib:$ext.baseVersion",
52        'ninepatch'           : "com.android.tools:ninepatch:$ext.baseVersion",
53        'rule-api'            : "com.android.tools:rule-api:$ext.baseVersion",
54        'sdk-common'          : "com.android.tools:sdk-common:$ext.baseVersion",
55        'sdklib'              : "com.android.tools:sdklib:$ext.baseVersion",
56        'sdkstats'            : "com.android.tools:sdkstats:$ext.baseVersion",
57        'sdkuilib'            : "com.android.tools:sdkuilib:$ext.baseVersion",
58        'swtmenubar'          : "com.android.tools:swtmenubar:$ext.baseVersion",
59        'testutils'           : "com.android.tools:testutils:$ext.baseVersion",
60        'traceview'           : "com.android.tools:traceview:$ext.baseVersion",
61        'uiautomatorviewer'   : "com.android.tools:uiautomatorviewer:$ext.baseVersion",
62
63        // prebuilts
64        'ant-glob'                         : 'com.android.tools.external:ant-glob:1.0',
65        'asm-4.0'                          : 'org.ow2.asm:asm:4.0',
66        'asm-analysis-4.0'                 : 'org.ow2.asm:asm-analysis:4.0',
67        'asm-tree-4.0'                     : 'org.ow2.asm:asm-tree:4.0',
68        'commons-codec-1.4'                : 'commons-codec:commons-codec:1.4',
69        'commons-compress-1.0'             : 'org.apache.commons:commons-compress:1.8.1',
70        'commons-logging-1.1.1'            : 'commons-logging:commons-logging:1.1.1',
71        'easymock'                         : 'org.easymock:easymock:2.4',
72        'freemarker-2.3.20'                : 'org.freemarker:freemarker:2.3.20',
73        'guava-15.0'                       : 'com.google.guava:guava:15.0',
74        'host-libprotobuf-java-2.3.0-lite' : 'com.android.tools.external:libprotobuf-java-lite:2.3.0',
75        'httpclient-4.1.1'                 : 'org.apache.httpcomponents:httpclient:4.1.1',
76        'httpcore-4.1'                     : 'org.apache.httpcomponents:httpcore:4.1',
77        'httpmime-4.1'                     : 'org.apache.httpcomponents:httpmime:4.1',
78        'jcommon-1.0.12'                   : 'jfree:jcommon:1.0.12',
79        'jfreechart-1.0.9'                 : 'jfree:jfreechart:1.0.9',
80        'jfreechart-swt-1.0.9'             : 'jfree:jfreechart-swt:1.0.9',
81        'kxml2-2.3.0'                      : 'net.sf.kxml:kxml2:2.3.0',
82        'liblzf-1.0'                       : 'com.android.tools.external:liblzf:1.0',
83        'lombok-ast-0.2.2'                 : 'com.android.tools.external.lombok:lombok-ast:0.2.2',
84        'propertysheet'                    : 'com.android.tools.external:propertysheet:1.0',
85]
86
87configurations {
88    compile
89}
90
91dependencies {
92    compile artifacts.values()
93}
94
95task copydeps << {
96    // get the resolved dependencies from the compile configuration
97    def resolvedDependencies = configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
98
99    // generate a map from "xy.jar" -> "/path/to/xy-1.0.jar"
100    def artifactMap = [:]
101    resolvedDependencies.each { dependency ->
102        def dependencyId = dependency.getName()
103        def artifactName = artifacts.find{ it.value == dependencyId}?.key
104
105        // get the jar file corresponding to the dependency
106        def artifact = getArtifact(dependency)
107        artifactMap.put(artifactName + ".jar", artifact)
108    }
109
110    project.adtPlugins.each { File pluginFile ->
111        def manifestDeps = getManifestDependencies(new File(pluginFile, "META-INF/MANIFEST.MF"))
112        logger.info("Dependencies for " + pluginFile.toString() + ": " + manifestDeps.join(","))
113
114        File dest = new File(pluginFile, "libs")
115        if (!manifestDeps.isEmpty() && !dest.isDirectory()) {
116            dest.mkdirs()
117        }
118
119        manifestDeps.each {
120            if (!artifactMap.containsKey(it)) {
121                throw new RuntimeException("No resolved artifact for: " + it + ", required for: "
122                        + pluginFile.getPath())
123            }
124
125            String destName = artifactMap.get(it)
126            logger.info("\tCopying " + destName + " to " + dest)
127            ant.copy(file: destName, tofile: new File(dest, it))
128        }
129    }
130}
131
132// unzip eclipse prebuilts into the out folder to create a target platform for the build
133task unzipTargetPlatform << {
134    File targetDir = new File(projectDir, "../../out/host/maven/target").getCanonicalFile()
135    targetDir.mkdirs()
136
137    project.targetComponents.each { String k, File v ->
138        File d = new File(targetDir, k)
139        logger.info("Unzipping " + v.getPath() + " into: " + d.getPath())
140        ant.unzip(src: v, dest: d)
141    }
142}
143
144task buildEclipse(type: Exec, dependsOn: unzipTargetPlatform) {
145    def maven = new File(projectDir, "../../prebuilts/eclipse/maven/apache-maven-3.2.1/bin/mvn").getCanonicalFile()
146    def androidOut = new File(projectDir, "../../out").getCanonicalPath()
147    environment("M2_HOME", maven.getParentFile().getParentFile().getCanonicalPath())
148    workingDir projectDir
149    commandLine maven.getCanonicalPath(), "-s", "settings.xml", "-DforceContextQualifier=$project.buildNumber", "-DANDROID_OUT=$androidOut", "package"
150}
151
152private File getArtifact(ResolvedDependency dependency) {
153    if (dependency.moduleArtifacts.size() != 1) {
154        String msg = String.format("Each dependency is expected to map to a single jar file, " +
155                "but %s maps to the following artifacts: %s",
156                dependency,
157                dependency.moduleArtifacts.collect { it.file })
158        throw new RuntimeException(msg);
159    }
160
161    return dependency.moduleArtifacts.iterator().next().file
162}
163
164// parse a plugin's manifest file and return the list of jar dependencies expected to be
165// bundled inside
166private List<String> getManifestDependencies(File manifest) {
167    if (manifest == null || !manifest.exists()) {
168        return []
169    }
170
171    def entries = []
172
173    def fis = new FileInputStream(manifest)
174    try {
175        java.util.jar.Manifest m = new java.util.jar.Manifest(fis)
176        def classPath = m.getMainAttributes().getValue("Bundle-ClassPath")
177        if (classPath == null) {
178            return []
179        }
180
181        classPath.split(',').each {
182            if (!it.equals(".")) {
183                if (!it.startsWith("libs/") || !it.endsWith(".jar")) {
184                    throw new RuntimeException(
185                            "Unexpected classpath entry: " + it + " in file: " + manifest)
186                }
187
188                entries.add(it.substring("libs/".length()))
189            }
190        }
191    } finally {
192        fis.close()
193    }
194
195    return entries
196}
197