From 99f163f42055e219f5518f4602d244c4549f3cc0 Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Tue, 29 Jul 2014 09:20:13 -0700 Subject: Accumulate NOTICE files from prebuilts This CL concatenates the NOTICE files from all the prebuilt library dependencies of the android plugin into a single NOTICE file that is placed inside the plugin. Change-Id: I614b616474bde5440dece6efb1656b200bd30f0c --- build/scripts/layouts.gant | 48 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index d80746e17790..55053c774bc4 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -589,6 +589,7 @@ private Set findModuleDependencies(List modules) { libroots = lib.getRoots(JpsOrderRootType.COMPILED) // only want compile (and not test) libroots.each { paths.addAll(JpsPathUtil.urlToFile(it.getUrl()).getAbsolutePath()); + projectBuilder.stage("Module: " + m.getName() + ", Dependency: " + it.getUrl()); } } } @@ -597,6 +598,34 @@ private Set findModuleDependencies(List modules) { return paths; } +// Obtain the absolute path to the NOTICE file corresponding to the given jar file. +// The NOTICE file is assumed to be present in the same folder as the jar file. It is an error if it is missing +private File getNoticeFileForJar(String jarPath) { + File parentFile = new File(jarPath).getParentFile() + File notice = new File(parentFile, "NOTICE") + if (!notice.exists()) { + notice = new File(parentFile, "NOTICE.txt") + } + if (!notice.exists()) { + notice = new File(parentFile, "LICENSE.txt") + } + if (!notice.exists()) { + notice = new File(parentFile, "LICENSE") + } + + return notice +} + +private void appendToFile(File to, File from) { + if (from.exists()) { + to.append(from.getName() + ":\n") + to.append(from.getText("UTF-8"), "UTF-8") + projectBuilder.stage("Appending NOTICE file: " + from.getAbsolutePath()) + } else { + projectBuilder.stage("Skipping non-existent NOTICE file: " + from.getAbsolutePath()) + } +} + def layoutPlugin(String moduleName) { layoutPlugin(moduleName, moduleName, {}) } @@ -726,6 +755,10 @@ def layoutAndroid() { include(name: "**/*.jar") } + jar("androidAnnotations.jar") { + fileset(dir: "${home}/../adt/idea/android/annotations") + } + // Add Additional libraries that the Android plugin depends on that come from TOOLS_PREBUILTS. // Note: This is a HACK: rather than encoding the full path, we should really query // the project model for the classpath just like we do for the androidModules' dependencies @@ -755,16 +788,23 @@ def layoutAndroid() { } } - jar("androidAnnotations.jar") { - fileset(dir: "${home}/../adt/idea/android/annotations") - } - // copy over dependencies of all android modules androidModuleDeps = findModuleDependencies(androidModules) androidModuleDeps.each { fileset(file: it) } + // Create a single NOTICE file with the contents of all the NOTICES of the dependencies. + // I couldn't figure out the right ant commands to be able to change the name of the file + // when copying, so we'll just call it by its final name (NOTICE) + File noticeFile = new File(System.getProperty("java.io.tmpdir") + File.separator + "NOTICE") + noticeFile.deleteOnExit() + androidModuleDeps.each { + appendToFile(noticeFile, getNoticeFileForJar(it)) + } + appendToFile(noticeFile, new File("${home}/../../prebuilts/tools/common/m2/repository/org/freemarker/freemarker/2.3.20/NOTICE")) + fileset(file: noticeFile.getPath()) + jar("android-common.jar") { module("android-common") } -- cgit v1.2.3