auto import from //branches/cupcake/...@126645

This commit is contained in:
The Android Open Source Project
2009-01-15 16:12:07 -08:00
parent 95cf464c5a
commit b8d704a517
62 changed files with 1680 additions and 668 deletions

View File

@@ -17,6 +17,8 @@
package com.android.sdklib;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
@@ -35,11 +37,13 @@ final class AddOnTarget implements IAndroidTarget {
private final String mJarName;
private final String mJarPath;
private final String mName;
private final String mDescription;
OptionalLibrary(String jarName, String jarPath, String name) {
OptionalLibrary(String jarName, String jarPath, String name, String description) {
mJarName = jarName;
mJarPath = jarPath;
mName = name;
mDescription = description;
}
public String getJarName() {
@@ -53,6 +57,10 @@ final class AddOnTarget implements IAndroidTarget {
public String getName() {
return mName;
}
public String getDescription() {
return mDescription;
}
}
private final String mLocation;
@@ -70,11 +78,11 @@ final class AddOnTarget implements IAndroidTarget {
* @param vendor the vendor name of the add-on
* @param description the add-on description
* @param libMap A map containing the optional libraries. The map key is the fully-qualified
* library name. The value is the .jar filename
* library name. The value is a 2 string array with the .jar filename, and the description.
* @param basePlatform the platform the add-on is extending.
*/
AddOnTarget(String location, String name, String vendor, String description,
Map<String, String> libMap, PlatformTarget basePlatform) {
Map<String, String[]> libMap, PlatformTarget basePlatform) {
if (location.endsWith(File.separator) == false) {
location = location + File.separator;
}
@@ -86,12 +94,16 @@ final class AddOnTarget implements IAndroidTarget {
mBasePlatform = basePlatform;
// handle the optional libraries.
mLibraries = new IOptionalLibrary[libMap.size()];
int index = 0;
for (Entry<String, String> entry : libMap.entrySet()) {
mLibraries[index++] = new OptionalLibrary(entry.getValue(),
mLocation + SdkConstants.OS_ADDON_LIBS_FOLDER + entry.getValue(),
entry.getKey());
if (libMap != null) {
mLibraries = new IOptionalLibrary[libMap.size()];
int index = 0;
for (Entry<String, String[]> entry : libMap.entrySet()) {
String jarFile = entry.getValue()[0];
String desc = entry.getValue()[1];
mLibraries[index++] = new OptionalLibrary(jarFile,
mLocation + SdkConstants.OS_ADDON_LIBS_FOLDER + jarFile,
entry.getKey(), desc);
}
}
}
@@ -135,6 +147,8 @@ final class AddOnTarget implements IAndroidTarget {
return mLocation + SdkConstants.OS_IMAGES_FOLDER;
case SKINS:
return mLocation + SdkConstants.OS_SKINS_FOLDER;
case DOCS:
return mLocation + SdkConstants.FD_DOCS + File.separator;
default :
return mBasePlatform.getPath(pathId);
}
@@ -223,6 +237,11 @@ final class AddOnTarget implements IAndroidTarget {
public void setSkins(String[] skins) {
mSkins = skins;
// we mix the add-on and base platform skins
HashSet<String> skinSet = new HashSet<String>();
skinSet.addAll(Arrays.asList(skins));
skinSet.addAll(Arrays.asList(mBasePlatform.getSkins()));
mSkins = skinSet.toArray(new String[skinSet.size()]);
}
}

View File

@@ -58,11 +58,14 @@ public interface IAndroidTarget extends Comparable<IAndroidTarget> {
public static int CATEGORIES = 17;
/** OS Path to the "sources" folder. */
public static int SOURCES = 18;
/** OS Path to the target specific docs */
public static int DOCS = 19;
public interface IOptionalLibrary {
String getName();
String getJarName();
String getJarPath();
String getDescription();
}
/**
@@ -82,7 +85,6 @@ public interface IAndroidTarget extends Comparable<IAndroidTarget> {
/**
* Returns the full name of the target, possibly including vendor name.
* @return
*/
String getFullName();

View File

@@ -201,7 +201,18 @@ public final class SdkConstants {
public final static String OS_ADDON_LIBS_FOLDER = FD_ADDON_LIBS + File.separator;
/* Skin default */
/** Skin default **/
public final static String SKIN_DEFAULT = "default";
/** Returns the appropriate name for the 'android' command, which is 'android.bat' for
* Windows and 'android' for all other platforms. */
public static String AndroidCmdName() {
String os = System.getProperty("os.name");
String cmd = "android";
if (os.startsWith("Windows")) {
cmd += ".bat";
}
return cmd;
}
}

View File

@@ -48,6 +48,9 @@ public final class SdkManager {
private final static Pattern PATTERN_PROP = Pattern.compile(
"^([a-zA-Z0-9._-]+)\\s*=\\s*(.*)\\s*$");
private final static Pattern PATTERN_LIB_DATA = Pattern.compile(
"^([a-zA-Z0-9._-]+\\.jar);(.*)$", Pattern.CASE_INSENSITIVE);
/** the location of the SDK */
private final String mSdkLocation;
private IAndroidTarget[] mTargets;
@@ -96,7 +99,9 @@ public final class SdkManager {
/**
* Returns a target from a hash that was generated by {@link IAndroidTarget#hashString()}.
* @param hash the hash
*
* @param hash the {@link IAndroidTarget} hash string.
* @return The matching {@link IAndroidTarget} or null.
*/
public IAndroidTarget getTargetFromHashString(String hash) {
if (hash != null) {
@@ -213,13 +218,12 @@ public final class SdkManager {
File[] addons = addonFolder.listFiles();
for (File addon : addons) {
// Add-ons have to be folders. Ignore files and no need to warn about them.
if (addon.isDirectory()) {
AddOnTarget target = loadAddon(addon, list, log);
if (target != null) {
list.add(target);
}
} else if (log != null) {
log.warning("Ignoring add-on '%1$s', not a folder.", addon.getName());
}
}
@@ -247,24 +251,24 @@ public final class SdkManager {
File addOnManifest = new File(addon, SdkConstants.FN_MANIFEST_INI);
if (addOnManifest.isFile()) {
Map<String, String> map = parsePropertyFile(addOnManifest, log);
Map<String, String> propertyMap = parsePropertyFile(addOnManifest, log);
if (map != null) {
if (propertyMap != null) {
// look for some specific values in the map.
// we require name, vendor, and api
String name = map.get(ADDON_NAME);
String name = propertyMap.get(ADDON_NAME);
if (name == null) {
displayAddonManifestError(log, addon.getName(), ADDON_NAME);
return null;
}
String vendor = map.get(ADDON_VENDOR);
String vendor = propertyMap.get(ADDON_VENDOR);
if (vendor == null) {
displayAddonManifestError(log, addon.getName(), ADDON_VENDOR);
return null;
}
String api = map.get(ADDON_API);
String api = propertyMap.get(ADDON_API);
PlatformTarget baseTarget = null;
if (api == null) {
displayAddonManifestError(log, addon.getName(), ADDON_API);
@@ -302,22 +306,42 @@ public final class SdkManager {
}
// get the optional description
String description = map.get(ADDON_DESCRIPTION);
String description = propertyMap.get(ADDON_DESCRIPTION);
// get the optional libraries
String librariesValue = map.get(ADDON_LIBRARIES);
String librariesValue = propertyMap.get(ADDON_LIBRARIES);
Map<String, String[]> libMap = null;
// split in the string into the values we care about
String[] libraries = librariesValue.split(";");
Map<String, String> libMap = null;
if (libraries.length > 0) {
libMap = new HashMap<String, String>();
for (String lib : libraries) {
String[] values = lib.split(":");
if (values.length == 2) {
libMap.put(values[0], values[1]);
} else {
// TODO: log error
if (librariesValue != null) {
librariesValue = librariesValue.trim();
if (librariesValue.length() > 0) {
// split in the string into the libraries name
String[] libraries = librariesValue.split(";");
if (libraries.length > 0) {
libMap = new HashMap<String, String[]>();
for (String libName : libraries) {
libName = libName.trim();
// get the library data from the properties
String libData = propertyMap.get(libName);
if (libData != null) {
// split the jar file from the description
Matcher m = PATTERN_LIB_DATA.matcher(libData);
if (m.matches()) {
libMap.put(libName, new String[] {
m.group(1), m.group(2) });
} else if (log != null) {
log.error(null,
"Ignoring library '%1$s', property value has wrong format\n\t%2$s",
libName, libData);
}
} else if (log != null) {
log.error(null,
"Ignoring library '%1$s', missing property value",
libName, libData);
}
}
}
}
}

View File

@@ -89,13 +89,43 @@ public class ProjectCreator {
String packageName, String activityName, IAndroidTarget target,
boolean isTestProject) {
// check project folder exists.
// create project folder if it does not exist
File projectFolder = new File(folderPath);
if (projectFolder.isDirectory() == false) {
mLog.error(null, "Folder '%s' does not exist. Aborting...", folderPath);
return;
if (!projectFolder.exists()) {
boolean created = false;
Throwable t = null;
try {
created = projectFolder.mkdirs();
} catch (Exception e) {
t = e;
}
if (created) {
println("Created project directory: %1$s", projectFolder);
} else {
mLog.error(t, "Could not create directory: %1$s", projectFolder);
return;
}
} else {
Exception e = null;
String error = null;
try {
String[] content = projectFolder.list();
if (content == null) {
error = "Project directory %1$s is not a directory.";
} else if (content.length != 0) {
error = "Project directory %1$s is not empty. Please consider using '%2$s update' instead.";
}
} catch (Exception e1) {
e = e1;
}
if (e != null || error != null) {
mLog.error(e, error, projectFolder, SdkConstants.AndroidCmdName());
}
}
try {
// first create the project properties.
@@ -110,6 +140,11 @@ public class ProjectCreator {
PropertyType.DEFAULT);
defaultProperties.setAndroidTarget(target);
defaultProperties.save();
// create an empty build.properties
ProjectProperties buildProperties = ProjectProperties.create(folderPath,
PropertyType.BUILD);
buildProperties.save();
// create the map for place-holders of values to replace in the templates
final HashMap<String, String> keywords = new HashMap<String, String>();
@@ -190,7 +225,7 @@ public class ProjectCreator {
* corresponding value in the created file.
*
* @param templateName the name of to the template file
* @param dest the path to the destination file, relative to the project
* @param destFile the path to the destination file, relative to the project
* @param placeholderMap a map of (place-holder, value) to create the file from the template.
* @param target the Target of the project that will be providing the template.
* @throws ProjectCreateException
@@ -211,7 +246,7 @@ public class ProjectCreator {
* corresponding value in the created file.
*
* @param templateName the name of to the template file
* @param dest the path to the destination file, relative to the project
* @param destFile the path to the destination file, relative to the project
* @param placeholderMap a map of (place-holder, value) to create the file from the template.
* @throws ProjectCreateException
*/
@@ -261,7 +296,6 @@ public class ProjectCreator {
println("Added file %1$s", destFile);
}
/**
* Prints a message unless silence is enabled.
* @param format Format for String.format

View File

@@ -66,7 +66,7 @@ public final class ProjectProperties {
"# This file must be checked in Version Control Systems.\n" +
"# \n" +
"# To customize properties used by the Ant build system use,\n" +
"# \"build.properties\", and override values to adapt the script to your" +
"# \"build.properties\", and override values to adapt the script to your\n" +
"# project structure.\n" +
"\n";
@@ -74,17 +74,18 @@ public final class ProjectProperties {
// 1-------10--------20--------30--------40--------50--------60--------70--------80
"# This file is used to override default values used by the Ant build system.\n" +
"# \n" +
"# This file must be checked in Version Control Systems, as it is" +
"# This file must be checked in Version Control Systems, as it is\n" +
"# integral to the build system of your project.\n" +
"# \n" +
"# Use this file to change values like:\n" +
"# application-package\n:" +
"# the name of your application package as defined in the manifest.\n" +
"# Used by the 'uninstall' rule.\n"+
"# source-folder\n:" +
"# the name of the source folder. Default is 'src'.\n" +
"# out-folder\n:" +
"# the name of the output folder. Default is 'bin'\n" +
"\n" +
"# The name of your application package as defined in the manifest.\n" +
"# Used by the 'uninstall' rule.\n"+
"#application-package=com.example.myproject\n" +
"\n" +
"# The name of the source folder.\n" +
"#source-folder=src\n" +
"\n" +
"# The name of the output folder.\n" +
"#out-folder=bin\n" +
"\n";
private final static Map<String, String> COMMENT_MAP = new HashMap<String, String>();
@@ -104,7 +105,9 @@ public final class ProjectProperties {
/**
* Loads a project properties file and return a {@link ProjectProperties} object
* containing the properties
*
* @param projectFolderOsPath the project folder.
* @param type One the possible {@link PropertyType}s.
*/
public static ProjectProperties load(String projectFolderOsPath, PropertyType type) {
File projectFolder = new File(projectFolderOsPath);
@@ -119,7 +122,44 @@ public final class ProjectProperties {
}
return null;
}
/**
* Merges all properties from the given file into the current properties.
* <p/>
* This emulates the Ant behavior: existing properties are <em>not</em> overriden.
* Only new undefined properties become defined.
* <p/>
* Typical usage:
* <ul>
* <li>Create a ProjectProperties with {@link PropertyType#BUILD}
* <li>Merge in values using {@link PropertyType#DEFAULT}
* <li>The result is that this contains all the properties from default plus those
* overridden by the build.properties file.
* </ul>
*
* @param type One the possible {@link PropertyType}s.
* @return this object, for chaining.
*/
public ProjectProperties merge(PropertyType type) {
File projectFolder = new File(mProjectFolderOsPath);
if (projectFolder.isDirectory()) {
File defaultFile = new File(projectFolder, type.mFilename);
if (defaultFile.isFile()) {
Map<String, String> map = SdkManager.parsePropertyFile(defaultFile, null /* log */);
if (map != null) {
for(Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (!mProperties.containsKey(key) && value != null) {
mProperties.put(key, value);
}
}
}
}
}
return this;
}
/**
* Creates a new project properties object, with no properties.
* <p/>The file is not created until {@link #save()} is called.
@@ -185,10 +225,9 @@ public final class ProjectProperties {
/**
* Private constructor.
* Use {@link #load(String)} or {@link #create(String)} to instantiate.
* @param projectFolderOsPath
* @param map
* @param type
* <p/>
* Use {@link #load(String, PropertyType)} or {@link #create(String, PropertyType)}
* to instantiate.
*/
private ProjectProperties(String projectFolderOsPath, Map<String, String> map,
PropertyType type) {

View File

@@ -91,8 +91,8 @@ public class HardwareProperties {
}
/**
* Parses the harware definition file.
* @param buildProp the property file to parse
* Parses the hardware definition file.
* @param file the property file to parse
* @param log the ISdkLog object receiving warning/error from the parsing.
* @return the map of (key,value) pairs, or null if the parsing failed.
*/

View File

@@ -20,7 +20,6 @@ import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.ISdkLog;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import java.io.File;
@@ -54,20 +53,20 @@ public final class VmManager {
String name;
String path;
IAndroidTarget target;
public String getName() {
return name;
}
public String getPath() {
return path;
}
public IAndroidTarget getTarget() {
return target;
}
}
private final ArrayList<VmInfo> mVmList = new ArrayList<VmInfo>();
private ISdkLog mSdkLog;
@@ -75,7 +74,7 @@ public final class VmManager {
mSdkLog = sdkLog;
buildVmList(sdk);
}
/**
* Returns the existing VMs.
* @return a newly allocated arrays containing all the VMs.
@@ -83,7 +82,7 @@ public final class VmManager {
public VmInfo[] getVms() {
return mVmList.toArray(new VmInfo[mVmList.size()]);
}
/**
* Returns the {@link VmInfo} matching the given <var>name</var>.
* @return the matching VmInfo or <code>null</code> if none were found.
@@ -99,7 +98,7 @@ public final class VmManager {
}
/**
* Creates a new VM.
* Creates a new VM. It is expected that there is no existing VM with this name already.
* @param parentFolder the folder to contain the VM. A new folder will be created in this
* folder with the name of the VM
* @param name the name of the VM
@@ -109,27 +108,25 @@ public final class VmManager {
* @param sdcardSize the size of a local sdcard to create. Can be 0 for no local sdcard.
* @param hardwareConfig the hardware setup for the VM
*/
public static void createVm(String parentFolder, String name, IAndroidTarget target,
public VmInfo createVm(String parentFolder, String name, IAndroidTarget target,
String skinName, String sdcardPath, int sdcardSize, Map<String,String> hardwareConfig,
ISdkLog log) {
// now write the ini file in the vmRoot folder.
// get the Android prefs location.
try {
File rootDirectory = new File(parentFolder);
if (rootDirectory.isDirectory() == false) {
if (log != null) {
log.error(null, "%s does not exists.", parentFolder);
log.error(null, "Folder %s does not exist.", parentFolder);
}
return;
return null;
}
File vmFolder = new File(parentFolder, name + ".avm");
if (vmFolder.exists()) {
if (log != null) {
log.error(null, "%s already exists.", vmFolder.getAbsolutePath());
log.error(null, "Folder %s is in the way.", vmFolder.getAbsolutePath());
}
return;
return null;
}
// create the vm folder.
@@ -164,13 +161,29 @@ public final class VmManager {
// Config file
values.clear();
if (skinName != null) {
values.put("skin", skinName);
} else {
values.put("skin", SdkConstants.SKIN_DEFAULT);
// check that the skin name is valid
String[] skinNames = target.getSkins();
boolean found = false;
for (String n : skinNames) {
if (n.equals(skinName)) {
values.put("skin", skinName);
found = true;
break;
}
}
if (found == false && log != null) {
log.warning("Skin '%1$s' does not exists, using default skin.", skinName);
}
}
if (sdcardPath != null) {
values.put("sdcard", sdcardPath);
File sdcard = new File(sdcardPath);
if (sdcard.isFile()) {
values.put("sdcard", sdcardPath);
} else if (log != null) {
log.warning("sdcarad image '%1$s' does not exists.", sdcardPath);
}
} else if (sdcardSize != 0) {
// TODO: create sdcard image.
}
@@ -182,21 +195,36 @@ public final class VmManager {
File configIniFile = new File(vmFolder, CONFIG_INI);
createConfigIni(configIniFile, values);
if (target.isPlatform()) {
System.out.println(String.format(
"Created VM '%s' based on %s", name, target.getName()));
} else {
System.out.println(String.format(
"Created VM '%s' based on %s (%s)", name, target.getName(),
target.getVendor()));
if (log != null) {
if (target.isPlatform()) {
log.printf("Created VM '%s' based on %s\n", name, target.getName());
} else {
log.printf(
"Created VM '%s' based on %s (%s)\n", name, target.getName(),
target.getVendor());
}
}
// create the VmInfo object, and add it to the list
VmInfo vmInfo = new VmInfo();
vmInfo.name = name;
vmInfo.path = vmFolder.getAbsolutePath();
vmInfo.target = target;
mVmList.add(vmInfo);
return vmInfo;
} catch (AndroidLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (log != null) {
log.error(e, null);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (log != null) {
log.error(e, null);
}
}
return null;
}
private void buildVmList(SdkManager sdk) throws AndroidLocationException {