ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/AndroidSDK.java
(Generate patch)

Comparing:
AntTasks/source/net/douglasthrift/anttasks/CommandTask.java (file contents), Revision 1114 by douglas, 2008-11-07T00:35:05-08:00 vs.
AntTasks/source/net/douglasthrift/anttasks/AndroidSDK.java (file contents), Revision 1115 by douglas, 2008-11-12T22:58:13-08:00

# Line 1 | Line 1
1 < // Command Task
1 > // Android SDK
2   //
3   // Douglas Thrift
4   //
# Line 23 | Line 23 | package net.douglasthrift.anttasks;
23  
24   import java.io.File;
25  
26 + import java.util.Iterator;
27 +
28 + import org.apache.tools.ant.BuildException;
29 + import org.apache.tools.ant.Project;
30   import org.apache.tools.ant.Task;
31 < import org.apache.tools.ant.taskdefs.ExecTask;
31 > import org.apache.tools.ant.taskdefs.condition.Os;
32   import org.apache.tools.ant.types.Path;
33 < import org.apache.tools.ant.types.Reference;
33 > import org.apache.tools.ant.types.resources.FileResource;
34 > import org.apache.tools.ant.util.FileUtils;
35  
36 < public abstract class CommandTask extends Task
36 > public class AndroidSDK extends Task
37   {
38 <        protected ExecTask command_;
38 >        private String property_;
39  
40 <        @Override
36 <        public void execute()
40 >        public void setProperty(String property)
41          {
42 <                command_.execute();
42 >                property_ = property;
43          }
44  
45 <        protected void command(String command)
45 >        @Override
46 >        public void execute()
47          {
48 <                command_ = (ExecTask)getProject().createTask("exec");
48 >                if (property_ == null)
49 >                        throw new BuildException("property not set");
50  
51 <                command_.setTaskName(getTaskName());
46 <                command_.setExecutable(command);
47 <                command_.setFailonerror(true);
48 <        }
51 >                Project project = getProject();
52  
53 <        protected void argument(File file)
51 <        {
52 <                command_.createArg().setFile(file);
53 <        }
53 >                Path path = (Path)project.createDataType("path");
54  
55 <        protected void argument(Path path)
56 <        {
57 <                command_.createArg().setPath(path);
58 <        }
55 >                path.setPath(System.getenv("PATH"));
56  
57 <        protected void argument(Reference reference)
61 <        {
62 <                command_.createArg().setPathref(reference);
63 <        }
57 >                FileUtils utils = FileUtils.getFileUtils();
58  
59 <        protected void argument(String value)
60 <        {
61 <                command_.createArg().setValue(value);
68 <        }
59 >                for (Iterator iterator = path.iterator(); iterator.hasNext();)
60 >                {
61 >                        File file = ((FileResource)iterator.next()).getFile();
62  
63 <        protected void arguments(String line)
64 <        {
65 <                command_.createArg().setLine(line);
73 <        }
63 >                        if (utils.resolveFile(file, Os.isFamily(Os.FAMILY_WINDOWS) ? "aapt.exe" : "aapt").isFile())
64 >                        {
65 >                                file = file.getParentFile();
66  
67 <        protected void arguments(Object... objects)
68 <        {
69 <                for (Object object : objects)
70 <                        if (object instanceof File)
71 <                                argument((File)object);
72 <                        else if (object instanceof Path)
73 <                                argument((Path)object);
74 <                        else if (object instanceof Reference)
75 <                                argument((Reference)object);
76 <                        else if (object instanceof String)
85 <                                argument((String)object);
86 <                        else
87 <                                assert (false);
67 >                                if (new File(file, "android.jar").isFile())
68 >                                {
69 >                                        project.setNewProperty(property_, file.toString());
70 >
71 >                                        return;
72 >                                }
73 >                        }
74 >                }
75 >
76 >                throw new BuildException("android sdk not found");
77          }
78   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines