diff options
Diffstat (limited to 'eclipse')
-rw-r--r-- | eclipse/build.gradle | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/eclipse/build.gradle b/eclipse/build.gradle new file mode 100644 index 0000000..18c8642 --- /dev/null +++ b/eclipse/build.gradle @@ -0,0 +1,155 @@ +// Build script used to copy non OSGI dependencies into each ADT plugin's libs folder +// +// Usage: $ gradle -q copydeps + +repositories { + maven { url '../../prebuilts/tools/common/m2/repository' } + maven { url '../../out/repo' } +} + +configurations { + compile +} + +ext { + // the current version of tools/base and tools/swt + toolsVersion = "22.9.1" + + // list of plugins whose manifest should be examined to identify dependencies + adtPlugins = new File('plugins').listFiles().findAll { it.name.startsWith("com.android") } +} + +// a mapping from the library names as used inside the plugin's MANIFEST.MF to the Maven artifact id +def artifacts = [ + // tools/base and tools/swt dependencies + 'manifest-merger' : "com.android.tools.build:manifest-merger:$ext.toolsVersion", + 'ddmlib' : "com.android.tools.ddms:ddmlib:$ext.toolsVersion", + 'ddmuilib' : "com.android.tools.ddms:ddmuilib:$ext.toolsVersion", + 'layoutlib-api' : "com.android.tools.layoutlib:layoutlib-api:$ext.toolsVersion", + 'lint-api' : "com.android.tools.lint:lint-api:$ext.toolsVersion", + 'lint-checks' : "com.android.tools.lint:lint-checks:$ext.toolsVersion", + 'asset-studio' : "com.android.tools:asset-studio:$ext.toolsVersion", + 'common' : "com.android.tools:common:$ext.toolsVersion", + 'dvlib' : "com.android.tools:dvlib:$ext.toolsVersion", + 'hierarchyviewer2lib' : "com.android.tools:hierarchyviewer2lib:$ext.toolsVersion", + 'ninepatch' : "com.android.tools:ninepatch:$ext.toolsVersion", + 'rule-api' : "com.android.tools:rule-api:$ext.toolsVersion", + 'sdk-common' : "com.android.tools:sdk-common:$ext.toolsVersion", + 'sdklib' : "com.android.tools:sdklib:$ext.toolsVersion", + 'sdkstats' : "com.android.tools:sdkstats:$ext.toolsVersion", + 'sdkuilib' : "com.android.tools:sdkuilib:$ext.toolsVersion", + 'swtmenubar' : "com.android.tools:swtmenubar:$ext.toolsVersion", + 'testutils' : "com.android.tools:testutils:$ext.toolsVersion", + 'traceview' : "com.android.tools:traceview:$ext.toolsVersion", + 'uiautomatorviewer' : "com.android.tools:uiautomatorviewer:$ext.toolsVersion", + + // prebuilts + 'lombok-ast-0.2.2' : 'com.android.tools.external.lombok:lombok-ast:0.2.2', + 'ant-glob' : 'com.android.tools.external:ant-glob:1.0', + 'liblzf-1.0' : 'com.android.tools.external:liblzf:1.0', + 'host-libprotobuf-java-2.3.0-lite' : 'com.android.tools.external:libprotobuf-java-lite:2.3.0', + 'propertysheet' : 'com.android.tools.external:propertysheet:1.0', + 'guava-15.0' : 'com.google.guava:guava:15.0', + 'commons-codec-1.4' : 'commons-codec:commons-codec:1.4', + 'commons-logging-1.1.1' : 'commons-logging:commons-logging:1.1.1', + 'jcommon-1.0.12' : 'jfree:jcommon:1.0.12', + 'jfreechart-swt-1.0.9' : 'jfree:jfreechart-swt:1.0.9', + 'jfreechart-1.0.9' : 'jfree:jfreechart:1.0.9', + 'kxml2-2.3.0' : 'net.sf.kxml:kxml2:2.3.0', + 'commons-compress-1.0' : 'org.apache.commons:commons-compress:1.8.1', + 'httpclient-4.1.1' : 'org.apache.httpcomponents:httpclient:4.1.1', + 'httpcore-4.1' : 'org.apache.httpcomponents:httpcore:4.1', + 'httpmime-4.1' : 'org.apache.httpcomponents:httpmime:4.1', + 'freemarker-2.3.20' : 'org.freemarker:freemarker:2.3.20', + 'asm-analysis-4.0' : 'org.ow2.asm:asm-analysis:4.0', + 'asm-tree-4.0' : 'org.ow2.asm:asm-tree:4.0', + 'asm-4.0' : 'org.ow2.asm:asm:4.0', + 'easymock' : 'org.easymock:easymock:2.4', +] + +dependencies { + compile artifacts.values() +} + +task copydeps << { + // get the resolved dependencies from the compile configuration + def resolvedDependencies = configurations.compile.resolvedConfiguration.firstLevelModuleDependencies + + def artifactMap = [:] + + resolvedDependencies.each { dependency -> + def dependencyId = dependency.getName() + def artifactName = artifacts.find{ it.value == dependencyId}?.key + + // get the jar file corresponding to the dependency + def artifact = getArtifact(dependency) + artifactMap.put(artifactName + ".jar", artifact) + } + + project.adtPlugins.each { File pluginFile -> + def manifestDeps = getManifestDependencies(new File(pluginFile, "META-INF/MANIFEST.MF")) + logger.info("Dependencies for " + pluginFile.toString() + ": " + manifestDeps.join(",")) + + File dest = new File(pluginFile, "libs") + if (!manifestDeps.isEmpty() && !dest.isDirectory()) { + dest.mkdirs() + } + + manifestDeps.each { + if (!artifactMap.containsKey(it)) { + throw new RuntimeException("No resolved artifact for: " + it + ", required for: " + + pluginFile.getPath()) + } + + String destName = artifactMap.get(it) + logger.info("Copying " + destName + " to " + dest) + ant.copy(file: destName, tofile: new File(dest, it)) + } + } +} + +private File getArtifact(ResolvedDependency dependency) { + if (dependency.moduleArtifacts.size() != 1) { + String msg = String.format("Each dependency is expected to map to a single jar file, " + + "but %s maps to the following artifacts: %s", + dependency, + dependency.moduleArtifacts.collect { it.file }) + throw new RuntimeException(msg); + } + + return dependency.moduleArtifacts.iterator().next().file +} + +// parse a plugin's manifest file and return the list of jar dependencies expected to be +// bundled inside +private List<String> getManifestDependencies(File manifest) { + if (manifest == null || !manifest.exists()) { + return [] + } + + def entries = [] + + def fis = new FileInputStream(manifest) + try { + java.util.jar.Manifest m = new java.util.jar.Manifest(fis) + def classPath = m.getMainAttributes().getValue("Bundle-ClassPath") + if (classPath == null) { + return [] + } + + classPath.split(',').each { + if (!it.equals(".")) { + if (!it.startsWith("libs/") || !it.endsWith(".jar")) { + throw new RuntimeException( + "Unexpected classpath entry: " + it + " in file: " + manifest) + } + + entries.add(it.substring("libs/".length())) + } + } + } finally { + fis.close() + } + + return entries +} |