1 |
douglas |
1115 |
// Android SDK |
2 |
douglas |
1107 |
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
/* Copyright 2008 Douglas Thrift |
8 |
|
|
* |
9 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
10 |
|
|
* you may not use this file except in compliance with the License. |
11 |
|
|
* You may obtain a copy of the License at |
12 |
|
|
* |
13 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
14 |
|
|
* |
15 |
|
|
* Unless required by applicable law or agreed to in writing, software |
16 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
17 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 |
|
|
* See the License for the specific language governing permissions and |
19 |
|
|
* limitations under the License. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
package net.douglasthrift.anttasks; |
23 |
|
|
|
24 |
douglas |
1112 |
import java.io.File; |
25 |
|
|
|
26 |
douglas |
1115 |
import java.util.Iterator; |
27 |
|
|
|
28 |
|
|
import org.apache.tools.ant.BuildException; |
29 |
|
|
import org.apache.tools.ant.Project; |
30 |
douglas |
1107 |
import org.apache.tools.ant.Task; |
31 |
douglas |
1115 |
import org.apache.tools.ant.taskdefs.condition.Os; |
32 |
douglas |
1112 |
import org.apache.tools.ant.types.Path; |
33 |
douglas |
1115 |
import org.apache.tools.ant.types.resources.FileResource; |
34 |
|
|
import org.apache.tools.ant.util.FileUtils; |
35 |
douglas |
1107 |
|
36 |
douglas |
1115 |
public class AndroidSDK extends Task |
37 |
douglas |
1107 |
{ |
38 |
douglas |
1115 |
private String property_; |
39 |
douglas |
1112 |
|
40 |
douglas |
1115 |
public void setProperty(String property) |
41 |
douglas |
1108 |
{ |
42 |
douglas |
1115 |
property_ = property; |
43 |
douglas |
1108 |
} |
44 |
douglas |
1112 |
|
45 |
douglas |
1115 |
@Override |
46 |
|
|
public void execute() |
47 |
douglas |
1112 |
{ |
48 |
douglas |
1115 |
if (property_ == null) |
49 |
|
|
throw new BuildException("property not set"); |
50 |
douglas |
1112 |
|
51 |
douglas |
1115 |
Project project = getProject(); |
52 |
douglas |
1112 |
|
53 |
douglas |
1115 |
Path path = (Path)project.createDataType("path"); |
54 |
douglas |
1112 |
|
55 |
douglas |
1115 |
path.setPath(System.getenv("PATH")); |
56 |
douglas |
1112 |
|
57 |
douglas |
1115 |
FileUtils utils = FileUtils.getFileUtils(); |
58 |
douglas |
1112 |
|
59 |
douglas |
1115 |
for (Iterator iterator = path.iterator(); iterator.hasNext();) |
60 |
|
|
{ |
61 |
|
|
File file = ((FileResource)iterator.next()).getFile(); |
62 |
douglas |
1112 |
|
63 |
douglas |
1115 |
if (utils.resolveFile(file, Os.isFamily(Os.FAMILY_WINDOWS) ? "aapt.exe" : "aapt").isFile()) |
64 |
|
|
{ |
65 |
|
|
file = file.getParentFile(); |
66 |
douglas |
1112 |
|
67 |
douglas |
1115 |
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 |
douglas |
1112 |
} |
78 |
douglas |
1107 |
} |