aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src/com
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-06-01 18:28:08 -0700
committerXavier Ducrohet <xav@android.com>2012-06-05 14:41:24 -0700
commit665f681e4881a7472f8ebcb7c4fb9a6771aada29 (patch)
tree74e5b5a85b6d6ee61e53d9e596b0d07db0c3902b /anttasks/src/com
parentea3f581acc01a02550df1137b3adcd8ea5755852 (diff)
downloadsdk-665f681e4881a7472f8ebcb7c4fb9a6771aada29.zip
sdk-665f681e4881a7472f8ebcb7c4fb9a6771aada29.tar.gz
sdk-665f681e4881a7472f8ebcb7c4fb9a6771aada29.tar.bz2
Projects can now access aidl files from their libraries.
Library projects now copy their aidl files into bin/aidl. Aidl is now called with this import path for all referenced library projects. Also added a test project. Change-Id: I7f94489e87450be67a16ed7198f85b8b472f5025
Diffstat (limited to 'anttasks/src/com')
-rw-r--r--anttasks/src/com/android/ant/AidlExecTask.java47
-rw-r--r--anttasks/src/com/android/ant/ComputeDependencyTask.java20
-rw-r--r--anttasks/src/com/android/ant/MultiFilesTask.java49
3 files changed, 92 insertions, 24 deletions
diff --git a/anttasks/src/com/android/ant/AidlExecTask.java b/anttasks/src/com/android/ant/AidlExecTask.java
index bead9e0..1315dd7 100644
--- a/anttasks/src/com/android/ant/AidlExecTask.java
+++ b/anttasks/src/com/android/ant/AidlExecTask.java
@@ -16,11 +16,15 @@
package com.android.ant;
+import com.android.sdklib.io.FileOp;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.Path;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -40,8 +44,10 @@ public class AidlExecTask extends MultiFilesTask {
private String mExecutable;
private String mFramework;
+ private Path mLibraryBinFolderPath;
private String mGenFolder;
private final ArrayList<Path> mPaths = new ArrayList<Path>();
+ private String mAidlOutFolder;
private class AidlProcessor implements SourceProcessor {
@@ -68,6 +74,13 @@ public class AidlExecTask extends MultiFilesTask {
task.createArg().setValue("-I" + importFolder);
}
+ // add all the library aidl folders to access parcelables that are in libraries
+ if (mLibraryBinFolderPath != null) {
+ for (String importFolder : mLibraryBinFolderPath.list()) {
+ task.createArg().setValue("-I" + importFolder);
+ }
+ }
+
// set auto dependency file creation
task.createArg().setValue("-a");
@@ -75,6 +88,24 @@ public class AidlExecTask extends MultiFilesTask {
// execute it.
task.execute();
+
+ // if we reach here, it was successful (execute throws an exception otherwise).
+ // Copy the file into the bin/aidl directory.
+ String relative = filePath.substring(sourceFolder.length());
+ if (relative.charAt(0) == '/' || relative.charAt(0) == File.separatorChar) {
+ relative = relative.substring(1);
+ }
+
+ try {
+ File dest = new File(mAidlOutFolder, relative);
+ File parent = dest.getParentFile();
+ parent.mkdirs();
+
+ FileOp op = new FileOp();
+ op.copyFile(new File(filePath), dest);
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
}
@Override
@@ -102,7 +133,6 @@ public class AidlExecTask extends MultiFilesTask {
break;
}
}
-
}
/**
@@ -117,10 +147,21 @@ public class AidlExecTask extends MultiFilesTask {
mFramework = TaskHelper.checkSinglePath("framework", value);
}
+ public void setLibraryBinFolderPathRefid(String libraryBinFolderPathRefid) {
+ Object libBinRef = getProject().getReference(libraryBinFolderPathRefid);
+ if (libBinRef instanceof Path) {
+ mLibraryBinFolderPath = (Path) libBinRef;
+ }
+ }
+
public void setGenFolder(Path value) {
mGenFolder = TaskHelper.checkSinglePath("genFolder", value);
}
+ public void setaidlOutFolder(Path value) {
+ mAidlOutFolder = TaskHelper.checkSinglePath("aidlOutFolder", value);
+ }
+
public Path createSource() {
Path p = new Path(getProject());
mPaths.add(p);
@@ -138,8 +179,10 @@ public class AidlExecTask extends MultiFilesTask {
if (mGenFolder == null) {
throw new BuildException("AidlExecTask's 'genFolder' is required.");
}
+ if (mAidlOutFolder == null) {
+ throw new BuildException("AidlExecTask's 'aidlOutFolder' is required.");
+ }
processFiles(new AidlProcessor(), mPaths, mGenFolder);
}
-
}
diff --git a/anttasks/src/com/android/ant/ComputeDependencyTask.java b/anttasks/src/com/android/ant/ComputeDependencyTask.java
index 62d5917..62572c8 100644
--- a/anttasks/src/com/android/ant/ComputeDependencyTask.java
+++ b/anttasks/src/com/android/ant/ComputeDependencyTask.java
@@ -58,6 +58,7 @@ public class ComputeDependencyTask extends GetLibraryListTask {
private String mLibraryPackagesOut;
private String mJarLibraryPathOut;
private String mLibraryNativeFolderPathOut;
+ private String mLibraryBinFolderPathOut;
private int mTargetApi = -1;
private boolean mVerbose = false;
@@ -77,6 +78,10 @@ public class ComputeDependencyTask extends GetLibraryListTask {
mJarLibraryPathOut = jarLibraryPathOut;
}
+ public void setLibraryBinFolderPathOut(String libraryBinFolderPathOut) {
+ mLibraryBinFolderPathOut = libraryBinFolderPathOut;
+ }
+
public void setLibraryNativeFolderPathOut(String libraryNativeFolderPathOut) {
mLibraryNativeFolderPathOut = libraryNativeFolderPathOut;
}
@@ -110,6 +115,9 @@ public class ComputeDependencyTask extends GetLibraryListTask {
if (mLibraryNativeFolderPathOut == null) {
throw new BuildException("Missing attribute libraryNativeFolderPathOut");
}
+ if (mLibraryBinFolderPathOut == null) {
+ throw new BuildException("Missing attribute libraryBinFolderPathOut");
+ }
if (mTargetApi == -1) {
throw new BuildException("Missing attribute targetApi");
}
@@ -123,6 +131,7 @@ public class ComputeDependencyTask extends GetLibraryListTask {
final Path manifestFilePath = new Path(antProject);
final Path resFolderPath = new Path(antProject);
final Path nativeFolderPath = new Path(antProject);
+ final Path binFolderPath = new Path(antProject);
final StringBuilder packageStrBuilder = new StringBuilder();
LibraryProcessorFor3rdPartyJars processor = new LibraryProcessorFor3rdPartyJars() {
@@ -144,12 +153,17 @@ public class ComputeDependencyTask extends GetLibraryListTask {
element = resFolderPath.createPathElement();
element.setPath(libRootPath + "/" + SdkConstants.FD_RESOURCES);
-
// get the folder for the native libraries. Always $PROJECT/libs
- // FIXME: support renamed folder.
+ // FIXME: support renamed folder and/or move libs to bin/libs/
element = nativeFolderPath.createPathElement();
element.setPath(libRootPath + "/" + SdkConstants.FD_NATIVE_LIBS);
+ // get the bin folder. $PROJECT/bin for now
+ // FIXME: support renamed folder.
+ element = binFolderPath.createPathElement();
+ element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
+ "/" + SdkConstants.FD_AIDL);
+
// get the package from the manifest.
FileWrapper manifest = new FileWrapper(libRootPath,
SdkConstants.FN_ANDROID_MANIFEST_XML);
@@ -206,6 +220,7 @@ public class ComputeDependencyTask extends GetLibraryListTask {
// (the task themselves can handle a ref to an empty Path)
antProject.addReference(mLibraryNativeFolderPathOut, nativeFolderPath);
antProject.addReference(mLibraryManifestFilePathOut, manifestFilePath);
+ antProject.addReference(mLibraryBinFolderPathOut, binFolderPath);
// the rest is done only if there's a library.
if (hasLibraries) {
@@ -249,6 +264,5 @@ public class ComputeDependencyTask extends GetLibraryListTask {
if (mVerbose) {
System.out.println();
}
-
}
}
diff --git a/anttasks/src/com/android/ant/MultiFilesTask.java b/anttasks/src/com/android/ant/MultiFilesTask.java
index 7d4a884..c90a0b9 100644
--- a/anttasks/src/com/android/ant/MultiFilesTask.java
+++ b/anttasks/src/com/android/ant/MultiFilesTask.java
@@ -61,7 +61,7 @@ class MultiFilesTask extends BuildTypedTask {
}
// gather all the source files from all the source folders.
- Map<String, String> sourceFiles = getFileListByExtension(taskProject, sourceFolders,
+ Map<String, String> sourceFiles = getFilesByNameEntryFilter(sourceFolders,
"**/*." + extension);
if (sourceFiles.size() > 0) {
processor.displayMessage(DisplayType.FOUND, sourceFiles.size());
@@ -69,14 +69,15 @@ class MultiFilesTask extends BuildTypedTask {
// go look for all dependency files in the gen folder. This will have all dependency
// files but we can filter them based on the first pre-req file.
- Map<String, String> depFiles = getFileListByExtension(taskProject, genFolder, "**/*.d");
+ Iterator<?> depFiles = getFilesByNameEntryFilter(genFolder, "**/*.d");
// parse all the dep files and keep the ones that are of the proper type and check if
// they require compilation again.
Map<String, String> toCompile = new HashMap<String, String>();
ArrayList<File> toRemove = new ArrayList<File>();
ArrayList<String> depsToRemove = new ArrayList<String>();
- for (String depFile : depFiles.keySet()) {
+ while (depFiles.hasNext()) {
+ String depFile = depFiles.next().toString();
DependencyGraph graph = new DependencyGraph(depFile, null /*watchPaths*/);
// get the source file. it's the first item in the pre-reqs
@@ -145,34 +146,44 @@ class MultiFilesTask extends BuildTypedTask {
}
}
- private Map<String, String> getFileListByExtension(Project taskProject,
- List<String> sourceFolders, String filter) {
- HashMap<String, String> sourceFiles = new HashMap<String, String>();
- for (String sourceFolder : sourceFolders) {
- sourceFiles.putAll(getFileListByExtension(taskProject, sourceFolder, filter));
+ /**
+ * Returns a list of files found in given folders, all matching a given filter.
+ * The result is a map of (file, folder).
+ * @param folders the folders to search
+ * @param filter the filter for the files. Typically a glob.
+ * @return a map of (file, folder)
+ */
+ private Map<String, String> getFilesByNameEntryFilter(List<String> folders, String filter) {
+ Map<String, String> sourceFiles = new HashMap<String, String>();
+
+ for (String folder : folders) {
+ Iterator<?> iterator = getFilesByNameEntryFilter(folder, filter);
+
+ while (iterator.hasNext()) {
+ sourceFiles.put(iterator.next().toString(), folder);
+ }
}
return sourceFiles;
}
- private Map<String, String> getFileListByExtension(Project taskProject,
- String sourceFolder, String filter) {
- HashMap<String, String> sourceFiles = new HashMap<String, String>();
+ /**
+ * Returns a list of files found in a given folder, matching a given filter.
+ * @param folder the folder to search
+ * @param filter the filter for the files. Typically a glob.
+ * @return an iterator.
+ */
+ private Iterator<?> getFilesByNameEntryFilter(String folder, String filter) {
+ Project taskProject = getProject();
// create a fileset to find all the files in the folder
FileSet fs = new FileSet();
fs.setProject(taskProject);
- fs.setDir(new File(sourceFolder));
+ fs.setDir(new File(folder));
NameEntry include = fs.createInclude();
include.setName(filter);
// loop through the results of the file set
- Iterator<?> iter = fs.iterator();
- while (iter.hasNext()) {
- sourceFiles.put(iter.next().toString(), sourceFolder);
- }
-
- return sourceFiles;
+ return fs.iterator();
}
-
}