blob: 86716904322dc7d5567c17eb6537b482ca01d309 [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
11repositories {
12 maven { url '../../prebuilts/tools/common/m2/repository' }
13 maven { url '../../out/repo' }
14}
15
Siva Velusamyf970b9a2014-06-10 14:28:48 -070016ext {
Siva Velusamyf970b9a2014-06-10 14:28:48 -070017 // list of plugins whose manifest should be examined to identify dependencies
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070018 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 ]
Siva Velusamy59200082014-06-12 21:31:19 -070032
33 buildNumber = System.getenv("BUILD_NUMBER")
34 if (buildNumber == null) {
35 buildNumber = "SNAPSHOT"
36 }
Siva Velusamyf970b9a2014-06-10 14:28:48 -070037}
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
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070042 '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",
Siva Velusamyf970b9a2014-06-10 14:28:48 -070062
63 // prebuilts
Siva Velusamyf970b9a2014-06-10 14:28:48 -070064 'ant-glob' : 'com.android.tools.external:ant-glob:1.0',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070065 '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',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070068 'commons-codec-1.4' : 'commons-codec:commons-codec:1.4',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070069 'commons-compress-1.0' : 'org.apache.commons:commons-compress:1.8.1',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070070 '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',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070075 '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',
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070078 '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',
Siva Velusamyf970b9a2014-06-10 14:28:48 -070085]
86
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070087configurations {
88 compile
89}
90
Siva Velusamyf970b9a2014-06-10 14:28:48 -070091dependencies {
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
Siva Velusamy2a5a1df2014-06-10 17:55:03 -070099 // generate a map from "xy.jar" -> "/path/to/xy-1.0.jar"
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700100 def artifactMap = [:]
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700101 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)
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700126 logger.info("\tCopying " + destName + " to " + dest)
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700127 ant.copy(file: destName, tofile: new File(dest, it))
128 }
129 }
130}
131
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700132// 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
Siva Velusamy59200082014-06-12 21:31:19 -0700149 commandLine maven.getCanonicalPath(), "-s", "settings.xml", "-DforceContextQualifier=$project.buildNumber", "-DANDROID_OUT=$androidOut", "package"
Siva Velusamy2a5a1df2014-06-10 17:55:03 -0700150}
151
Siva Velusamyf970b9a2014-06-10 14:28:48 -0700152private 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}