// Android SDK // // Douglas Thrift // // $Id$ /* Copyright 2008 Douglas Thrift * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.douglasthrift.anttasks; import java.io.File; import java.util.Iterator; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.resources.FileResource; import org.apache.tools.ant.util.FileUtils; public class AndroidSDK extends Task { private String property_; public void setProperty(String property) { property_ = property; } @Override public void execute() { if (property_ == null) throw new BuildException("property not set"); Project project = getProject(); Path path = (Path)project.createDataType("path"); path.setPath(System.getenv("PATH")); FileUtils utils = FileUtils.getFileUtils(); for (Iterator iterator = path.iterator(); iterator.hasNext();) { File file = ((FileResource)iterator.next()).getFile(); if (utils.resolveFile(file, Os.isFamily(Os.FAMILY_WINDOWS) ? "aapt.exe" : "aapt").isFile()) { file = file.getParentFile(); if (new File(file, "android.jar").isFile()) { project.setNewProperty(property_, file.toString()); return; } } } throw new BuildException("android sdk not found"); } }