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.ant.DependencyHelper.LibraryProcessor; 20 import com.android.sdklib.internal.project.IPropertySource; 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.Task; 25 import org.apache.tools.ant.types.Path; 26 import org.apache.tools.ant.types.Path.PathElement; 27 28 import java.io.File; 29 import java.util.List; 30 31 /** 32 * Task to get the list of Library Project for the current project. 33 * 34 */ 35 public class GetLibraryListTask extends Task { 36 37 private String mLibraryFolderPathOut; 38 39 setLibraryFolderPathOut(String libraryFolderPathOut)40 public void setLibraryFolderPathOut(String libraryFolderPathOut) { 41 mLibraryFolderPathOut = libraryFolderPathOut; 42 } 43 44 @Override execute()45 public void execute() throws BuildException { 46 execute(null); 47 } 48 execute(LibraryProcessor processor)49 public void execute(LibraryProcessor processor) throws BuildException { 50 51 if (mLibraryFolderPathOut == null) { 52 throw new BuildException("Missing attribute libraryFolderPathOut"); 53 } 54 55 final Project antProject = getProject(); 56 57 DependencyHelper helper = new DependencyHelper(antProject.getBaseDir(), 58 new IPropertySource() { 59 @Override 60 public String getProperty(String name) { 61 return antProject.getProperty(name); 62 } 63 }, 64 true /*verbose*/); 65 66 System.out.println("Library dependencies:"); 67 68 if (helper.getLibraryCount() > 0) { 69 System.out.println("\n------------------\nOrdered libraries:"); 70 71 helper.processLibraries(processor); 72 73 // Create a Path object of all the libraries in reverse order. 74 // This is important so that compilation of libraries happens 75 // in the reverse order. 76 Path rootPath = new Path(antProject); 77 78 List<File> libraries = helper.getLibraries(); 79 80 for (int i = libraries.size() - 1 ; i >= 0; i--) { 81 File library = libraries.get(i); 82 PathElement element = rootPath.createPathElement(); 83 element.setPath(library.getAbsolutePath()); 84 } 85 86 antProject.addReference(mLibraryFolderPathOut, rootPath); 87 } else { 88 System.out.println("No Libraries"); 89 } 90 } 91 getLibraryFolderPathOut()92 protected String getLibraryFolderPathOut() { 93 return mLibraryFolderPathOut; 94 } 95 } 96