1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ant; 18 19 import com.android.sdklib.internal.project.ProjectProperties; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Task; 23 24 import java.io.File; 25 26 public class GetProjectPathsTask extends Task { 27 28 private String mProjectPath; 29 private String mBinName; 30 private String mSrcName; 31 setProjectPath(String projectPath)32 public void setProjectPath(String projectPath) { 33 mProjectPath = projectPath; 34 } 35 setBinOut(String binName)36 public void setBinOut(String binName) { 37 mBinName = binName; 38 } 39 setSrcOut(String srcName)40 public void setSrcOut(String srcName) { 41 mSrcName = srcName; 42 } 43 44 @Override execute()45 public void execute() throws BuildException { 46 if (mProjectPath == null) { 47 throw new BuildException("Missing attribute projectPath"); 48 } 49 50 ProjectProperties props = TaskHelper.getProperties(mProjectPath); 51 52 if (mBinName != null) { 53 handleProp(props, "out.dir", mBinName); 54 } 55 56 if (mSrcName != null) { 57 handleProp(props, "source.dir", mSrcName); 58 } 59 60 } 61 handleProp(ProjectProperties props, String inName, String outName)62 private void handleProp(ProjectProperties props, String inName, String outName) { 63 String value = props.getProperty(inName); 64 if (value == null) { 65 value = TaskHelper.getDefault(inName); 66 } 67 getProject().setProperty(outName, new File(mProjectPath, value).getAbsolutePath()); 68 69 } 70 } 71