blob: 5624821f45a0e101694d09f39f7d307ad8db9f23 [file] [log] [blame]
Siva Velusamy2a5a1df2014-06-10 17:55:03 -07001// 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
Siva Velusamyf970b9a2014-06-10 14:28:48 -07005//
Siva Velusamy2a5a1df2014-06-10 17:55:03 -07006// 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"
Siva Velusamyf970b9a2014-06-10 14:28:48 -070010
Joe Baker-Malone600a2722015-06-23 16:35:16 -070011ext.outPath = System.env.OUT_DIR
Chris Warrington70e261e2015-07-07 15:21:07 -070012if (outPath != null) {
13 ext.outFile = new File(outPath)
14} else {
Joe Baker-Malone600a2722015-06-23 16:35:16 -070015 outPath = '../../out'
Chris Warrington70e261e2015-07-07 15:21:07 -070016 ext.outFile = new File(projectDir, outPath)
Joe Baker-Malone600a2722015-06-23 16:35:16 -070017}
18
Siva Velusamyf970b9a2014-06-10 14:28:48 -070019repositories {
20 maven { url '../../prebuilts/tools/common/m2/repository' }
Joe Baker-Malone600a2722015-06-23 16:35:16 -070021 maven { url outPath + '/repo' }
Siva Velusamyf970b9a2014-06-10 14:28:48 -070022}
23
Siva Velusamyf970b9a2014-06-10 14:28:48 -070024ext {
Siva Velusamyf970b9a2014-06-10 14:28:48 -070025 // list of plugins whose manifest should be examined to identify dependencies
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070026 adtPlugins = new File(projectDir, 'plugins').listFiles().findAll { it.name.startsWith("com.android") }
27
28 //
29 def eclipseBuildDeps = new File(projectDir, "../../prebuilts/eclipse-build-deps").getCanonicalFile()
30 targetComponents = [
31 "platform": new File(eclipseBuildDeps, "platform/org.eclipse.platform-4.2.2.zip"),
32 "cdt" : new File(eclipseBuildDeps, "cdt/cdt-master-8.0.2.zip"),
33 "emf" : new File(eclipseBuildDeps, "emf/emf-xsd-Update-2.9.1.zip"),
34 "jdt" : new File(eclipseBuildDeps, "jdt/org.eclipse.jdt.source-4.2.2.zip"),
35 "wtp" : new File(eclipseBuildDeps, "wtp/wtp-repo-R-3.3.2-20120210195245.zip"),
36 "gef" : new File(eclipseBuildDeps, "gef/GEF-Update-3.9.1.zip"),
37 "pde" : new File(eclipseBuildDeps, "pde/org.eclipse.pde-3.8.zip"),
38 "egit" : new File(eclipseBuildDeps, "egit/org.eclipse.egit.repository-2.2.0.201212191850-r.zip"),
39 ]
Siva Velusamy59200082014-06-12 21:31:19 -070040
41 buildNumber = System.getenv("BUILD_NUMBER")
42 if (buildNumber == null) {
43 buildNumber = "SNAPSHOT"
44 }
Siva Velusamyf970b9a2014-06-10 14:28:48 -070045}
46
47// a mapping from the library names as used inside the plugin's MANIFEST.MF to the Maven artifact id
48def artifacts = [
49 // tools/base and tools/swt dependencies
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070050 'manifest-merger' : "com.android.tools.build:manifest-merger:$ext.baseVersion",
51 'ddmlib' : "com.android.tools.ddms:ddmlib:$ext.baseVersion",
52 'ddmuilib' : "com.android.tools.ddms:ddmuilib:$ext.baseVersion",
53 'layoutlib-api' : "com.android.tools.layoutlib:layoutlib-api:$ext.baseVersion",
54 'lint-api' : "com.android.tools.lint:lint-api:$ext.baseVersion",
55 'lint-checks' : "com.android.tools.lint:lint-checks:$ext.baseVersion",
56 'asset-studio' : "com.android.tools:asset-studio:$ext.baseVersion",
Xavier Ducrohet841a6762014-12-12 21:25:20 -080057 'annotations' : "com.android.tools:annotations:$ext.baseVersion",
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070058 'common' : "com.android.tools:common:$ext.baseVersion",
59 'dvlib' : "com.android.tools:dvlib:$ext.baseVersion",
60 'hierarchyviewer2lib' : "com.android.tools:hierarchyviewer2lib:$ext.baseVersion",
61 'ninepatch' : "com.android.tools:ninepatch:$ext.baseVersion",
62 'rule-api' : "com.android.tools:rule-api:$ext.baseVersion",
63 'sdk-common' : "com.android.tools:sdk-common:$ext.baseVersion",
64 'sdklib' : "com.android.tools:sdklib:$ext.baseVersion",
65 'sdkstats' : "com.android.tools:sdkstats:$ext.baseVersion",
66 'sdkuilib' : "com.android.tools:sdkuilib:$ext.baseVersion",
67 'swtmenubar' : "com.android.tools:swtmenubar:$ext.baseVersion",
68 'testutils' : "com.android.tools:testutils:$ext.baseVersion",
69 'traceview' : "com.android.tools:traceview:$ext.baseVersion",
70 'uiautomatorviewer' : "com.android.tools:uiautomatorviewer:$ext.baseVersion",
Siva Velusamyf970b9a2014-06-10 14:28:48 -070071
72 // prebuilts
Siva Velusamyf970b9a2014-06-10 14:28:48 -070073 'ant-glob' : 'com.android.tools.external:ant-glob:1.0',
Tor Norbye22289162014-12-19 18:10:05 -080074 'asm-5.0.3' : 'org.ow2.asm:asm:5.0.3',
75 'asm-analysis-5.0.3' : 'org.ow2.asm:asm-analysis:5.0.3',
76 'asm-tree-5.0.3' : 'org.ow2.asm:asm-tree:5.0.3',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070077 'commons-codec-1.4' : 'commons-codec:commons-codec:1.4',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070078 'commons-compress-1.0' : 'org.apache.commons:commons-compress:1.8.1',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070079 'commons-logging-1.1.1' : 'commons-logging:commons-logging:1.1.1',
Siva Velusamy6a136cd2015-04-06 18:17:11 -070080 'easymock' : 'org.easymock:easymock:3.3',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070081 'freemarker-2.3.20' : 'org.freemarker:freemarker:2.3.20',
Siva Velusamy539e3572014-10-27 11:32:39 -070082 'guava-17.0' : 'com.google.guava:guava:17.0',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070083 'host-libprotobuf-java-2.3.0-lite' : 'com.android.tools.external:libprotobuf-java-lite:2.3.0',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070084 'httpclient-4.1.1' : 'org.apache.httpcomponents:httpclient:4.1.1',
85 'httpcore-4.1' : 'org.apache.httpcomponents:httpcore:4.1',
86 'httpmime-4.1' : 'org.apache.httpcomponents:httpmime:4.1',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070087 'jcommon-1.0.12' : 'jfree:jcommon:1.0.12',
88 'jfreechart-1.0.9' : 'jfree:jfreechart:1.0.9',
89 'jfreechart-swt-1.0.9' : 'jfree:jfreechart-swt:1.0.9',
90 'kxml2-2.3.0' : 'net.sf.kxml:kxml2:2.3.0',
91 'liblzf-1.0' : 'com.android.tools.external:liblzf:1.0',
Tor Norbyed63e2402015-01-07 11:36:04 -080092 'lombok-ast-0.2.3' : 'com.android.tools.external.lombok:lombok-ast:0.2.3',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070093 'propertysheet' : 'com.android.tools.external:propertysheet:1.0',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070094]
95
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070096configurations {
97 compile
98}
99
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700100dependencies {
101 compile artifacts.values()
102}
103
104task copydeps << {
105 // get the resolved dependencies from the compile configuration
106 def resolvedDependencies = configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
107
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700108 // generate a map from "xy.jar" -> "/path/to/xy-1.0.jar"
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700109 def artifactMap = [:]
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700110 resolvedDependencies.each { dependency ->
111 def dependencyId = dependency.getName()
112 def artifactName = artifacts.find{ it.value == dependencyId}?.key
113
114 // get the jar file corresponding to the dependency
115 def artifact = getArtifact(dependency)
116 artifactMap.put(artifactName + ".jar", artifact)
117 }
118
119 project.adtPlugins.each { File pluginFile ->
120 def manifestDeps = getManifestDependencies(new File(pluginFile, "META-INF/MANIFEST.MF"))
121 logger.info("Dependencies for " + pluginFile.toString() + ": " + manifestDeps.join(","))
122
123 File dest = new File(pluginFile, "libs")
124 if (!manifestDeps.isEmpty() && !dest.isDirectory()) {
125 dest.mkdirs()
126 }
127
128 manifestDeps.each {
129 if (!artifactMap.containsKey(it)) {
130 throw new RuntimeException("No resolved artifact for: " + it + ", required for: "
131 + pluginFile.getPath())
132 }
133
134 String destName = artifactMap.get(it)
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700135 logger.info("\tCopying " + destName + " to " + dest)
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700136 ant.copy(file: destName, tofile: new File(dest, it))
137 }
138 }
139}
140
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700141// unzip eclipse prebuilts into the out folder to create a target platform for the build
142task unzipTargetPlatform << {
Joe Baker-Malone600a2722015-06-23 16:35:16 -0700143 File targetDir = new File(outFile, "/host/maven/target").getCanonicalFile()
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700144 targetDir.mkdirs()
145
146 project.targetComponents.each { String k, File v ->
147 File d = new File(targetDir, k)
148 logger.info("Unzipping " + v.getPath() + " into: " + d.getPath())
149 ant.unzip(src: v, dest: d)
150 }
151}
152
153task buildEclipse(type: Exec, dependsOn: unzipTargetPlatform) {
154 def maven = new File(projectDir, "../../prebuilts/eclipse/maven/apache-maven-3.2.1/bin/mvn").getCanonicalFile()
Joe Baker-Malone600a2722015-06-23 16:35:16 -0700155 def androidOut = outFile.getCanonicalPath()
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700156 environment("M2_HOME", maven.getParentFile().getParentFile().getCanonicalPath())
157 workingDir projectDir
Siva Velusamy59200082014-06-12 21:31:19 -0700158 commandLine maven.getCanonicalPath(), "-s", "settings.xml", "-DforceContextQualifier=$project.buildNumber", "-DANDROID_OUT=$androidOut", "package"
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700159}
160
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700161private File getArtifact(ResolvedDependency dependency) {
162 if (dependency.moduleArtifacts.size() != 1) {
163 String msg = String.format("Each dependency is expected to map to a single jar file, " +
164 "but %s maps to the following artifacts: %s",
165 dependency,
166 dependency.moduleArtifacts.collect { it.file })
167 throw new RuntimeException(msg);
168 }
169
170 return dependency.moduleArtifacts.iterator().next().file
171}
172
173// parse a plugin's manifest file and return the list of jar dependencies expected to be
174// bundled inside
175private List<String> getManifestDependencies(File manifest) {
176 if (manifest == null || !manifest.exists()) {
177 return []
178 }
179
180 def entries = []
181
182 def fis = new FileInputStream(manifest)
183 try {
184 java.util.jar.Manifest m = new java.util.jar.Manifest(fis)
185 def classPath = m.getMainAttributes().getValue("Bundle-ClassPath")
186 if (classPath == null) {
187 return []
188 }
189
190 classPath.split(',').each {
191 if (!it.equals(".")) {
192 if (!it.startsWith("libs/") || !it.endsWith(".jar")) {
193 throw new RuntimeException(
194 "Unexpected classpath entry: " + it + " in file: " + manifest)
195 }
196
197 entries.add(it.substring("libs/".length()))
198 }
199 }
200 } finally {
201 fis.close()
202 }
203
204 return entries
205}