diff options
Diffstat (limited to 'anttasks')
-rw-r--r-- | anttasks/src/anttasks.properties | 1 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/ComputeDependencyTask.java | 4 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/DependencyHelper.java | 12 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/GetLibraryListTask.java | 4 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/GetProjectPropertyTask.java | 72 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/TaskHelper.java | 43 |
6 files changed, 125 insertions, 11 deletions
diff --git a/anttasks/src/anttasks.properties b/anttasks/src/anttasks.properties index 446bbe1..e0854f4 100644 --- a/anttasks/src/anttasks.properties +++ b/anttasks/src/anttasks.properties @@ -1,6 +1,7 @@ checkenv: com.android.ant.CheckEnvTask gettype: com.android.ant.GetTypeTask gettarget: com.android.ant.GetTargetTask +getproperty: com.android.ant.GetProjectPropertyTask getlibs: com.android.ant.GetLibraryListTask dependency: com.android.ant.ComputeDependencyTask testedprojectclasspath: com.android.ant.ComputeProjectClasspathTask diff --git a/anttasks/src/com/android/ant/ComputeDependencyTask.java b/anttasks/src/com/android/ant/ComputeDependencyTask.java index 512f425..fda4e17 100644 --- a/anttasks/src/com/android/ant/ComputeDependencyTask.java +++ b/anttasks/src/com/android/ant/ComputeDependencyTask.java @@ -251,6 +251,10 @@ public class ComputeDependencyTask extends GetLibraryListTask { public String getProperty(String name) { return antProject.getProperty(name); } + + @Override + public void debugPrint() { + } }, jars); // and create a Path object for them diff --git a/anttasks/src/com/android/ant/DependencyHelper.java b/anttasks/src/com/android/ant/DependencyHelper.java index c2a6694..0019b8b 100644 --- a/anttasks/src/com/android/ant/DependencyHelper.java +++ b/anttasks/src/com/android/ant/DependencyHelper.java @@ -140,17 +140,7 @@ public class DependencyHelper { mProjectFolder = projectFolder; mVerbose = verbose; - ProjectProperties properties = ProjectProperties.load(projectFolder.getAbsolutePath(), - PropertyType.ANT); - - if (properties == null) { - properties = ProjectProperties.load(projectFolder.getAbsolutePath(), - PropertyType.PROJECT); - } else { - properties.makeWorkingCopy().merge(PropertyType.PROJECT); - } - - mProperties = properties; + mProperties = TaskHelper.getProperties(projectFolder.getAbsolutePath()); init(projectFolder); } diff --git a/anttasks/src/com/android/ant/GetLibraryListTask.java b/anttasks/src/com/android/ant/GetLibraryListTask.java index e2d5dd7..97d1773 100644 --- a/anttasks/src/com/android/ant/GetLibraryListTask.java +++ b/anttasks/src/com/android/ant/GetLibraryListTask.java @@ -60,6 +60,10 @@ public class GetLibraryListTask extends Task { public String getProperty(String name) { return antProject.getProperty(name); } + + @Override + public void debugPrint() { + } }, true /*verbose*/); diff --git a/anttasks/src/com/android/ant/GetProjectPropertyTask.java b/anttasks/src/com/android/ant/GetProjectPropertyTask.java new file mode 100644 index 0000000..1713cb7 --- /dev/null +++ b/anttasks/src/com/android/ant/GetProjectPropertyTask.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * 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 com.android.ant; + +import com.android.sdklib.SdkConstants; +import com.android.sdklib.internal.project.ProjectProperties; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +import java.io.File; + +public class GetProjectPropertyTask extends Task { + + private String mProjectPath; + private String mBinName; + private String mSrcName; + + public void setProjectPath(String projectPath) { + mProjectPath = projectPath; + } + + public void setBin(String binName) { + mBinName = binName; + } + + public void setSrc(String srcName) { + mSrcName = srcName; + } + + @Override + public void execute() throws BuildException { + if (mProjectPath == null) { + throw new BuildException("Missing attribute projectPath"); + } + + ProjectProperties props = TaskHelper.getProperties(mProjectPath); + + if (mBinName != null) { + handleProp(props, "out.dir", mBinName, SdkConstants.FD_OUTPUT); + } + + if (mSrcName != null) { + handleProp(props, "source.dir", mSrcName, SdkConstants.FD_SOURCES); + } + + } + + private void handleProp(ProjectProperties props, String inName, String outName, + String defaultValue) { + String value = props.getProperty(inName); + if (value == null) { + value = defaultValue; + } + getProject().setProperty(outName, new File(mProjectPath, value).getAbsolutePath()); + + } +} diff --git a/anttasks/src/com/android/ant/TaskHelper.java b/anttasks/src/com/android/ant/TaskHelper.java index 8a3d6bc..8a9128c 100644 --- a/anttasks/src/com/android/ant/TaskHelper.java +++ b/anttasks/src/com/android/ant/TaskHelper.java @@ -16,8 +16,11 @@ package com.android.ant; +import com.android.annotations.NonNull; import com.android.sdklib.SdkConstants; import com.android.sdklib.internal.project.ProjectProperties; +import com.android.sdklib.internal.project.ProjectProperties.PropertyType; +import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -95,4 +98,44 @@ final class TaskHelper { return paths[0]; } + + /** + * Returns the ProjectProperties for a given project path. + * This loads and merge all the .properties files in the same way that Ant does it. + * + * Note that this does not return all the Ant properties but only the one customized by the + * project's own build.xml file. + * + * If the project has no .properties files, this returns an empty {@link ProjectProperties} + * with type {@link PropertyType#PROJECT}. + * + * @param projectPath the path to the project root folder. + * @return a ProjectProperties. + */ + @NonNull + static ProjectProperties getProperties(@NonNull String projectPath) { + // the import order is local, ant, project so we need to respect this. + PropertyType[] types = PropertyType.getOrderedTypes(); + + // make a working copy of the first non null props and then merge the rest into it. + ProjectProperties properties = null; + for (int i = 0 ; i < types.length ; i++) { + properties = ProjectProperties.load(projectPath, types[i]); + + if (properties != null) { + ProjectPropertiesWorkingCopy workingCopy = properties.makeWorkingCopy(); + for (int k = i + 1 ; k < types.length ; k++) { + workingCopy.merge(types[k]); + } + + // revert back to a read-only version + properties = workingCopy.makeReadOnlyCopy(); + + return properties; + } + } + + // return an empty object with type PropertyType.PROJECT (doesn't actually matter). + return ProjectProperties.createEmpty(projectPath, PropertyType.PROJECT); + } } |