@Nullable public IAndroidTarget findTargetByName(@NotNull String name) { for (IAndroidTarget target : getTargets()) { if (target.getName().equals(name)) { return target; } } return null; }
/** Displays the list of available Targets (Platforms and Add-ons) */ private void displayTargetList() { mSdkLog.printf("Available Android targets:\n"); int index = 1; for (IAndroidTarget target : mSdkManager.getTargets()) { mSdkLog.printf("id: %1$d or \"%2$s\"\n", index, target.hashString()); mSdkLog.printf(" Name: %s\n", target.getName()); if (target.isPlatform()) { mSdkLog.printf(" Type: Platform\n"); mSdkLog.printf(" API level: %s\n", target.getVersion().getApiString()); mSdkLog.printf(" Revision: %d\n", target.getRevision()); } else { mSdkLog.printf(" Type: Add-On\n"); mSdkLog.printf(" Vendor: %s\n", target.getVendor()); mSdkLog.printf(" Revision: %d\n", target.getRevision()); if (target.getDescription() != null) { mSdkLog.printf(" Description: %s\n", target.getDescription()); } mSdkLog.printf( " Based on Android %s (API level %s)\n", target.getVersionName(), target.getVersion().getApiString()); // display the optional libraries. IOptionalLibrary[] libraries = target.getOptionalLibraries(); if (libraries != null) { mSdkLog.printf(" Libraries:\n"); for (IOptionalLibrary library : libraries) { mSdkLog.printf(" * %1$s (%2$s)\n", library.getName(), library.getJarName()); mSdkLog.printf(String.format(" %1$s\n", library.getDescription())); } } } // get the target skins displaySkinList(target, " Skins: "); if (target.getUsbVendorId() != IAndroidTarget.NO_USB_ID) { mSdkLog.printf( " Adds USB support for devices (Vendor: 0x%04X)\n", target.getUsbVendorId()); } index++; } }
/** * Displays the list of available AVDs for the given AvdManager. * * @param avdManager */ public void displayAvdList(AvdManager avdManager) { mSdkLog.printf("Available Android Virtual Devices:\n"); AvdInfo[] avds = avdManager.getValidAvds(); for (int index = 0; index < avds.length; index++) { AvdInfo info = avds[index]; if (index > 0) { mSdkLog.printf("---------\n"); } mSdkLog.printf(" Name: %s\n", info.getName()); mSdkLog.printf(" Path: %s\n", info.getPath()); // get the target of the AVD IAndroidTarget target = info.getTarget(); if (target.isPlatform()) { mSdkLog.printf( " Target: %s (API level %s)\n", target.getName(), target.getVersion().getApiString()); } else { mSdkLog.printf(" Target: %s (%s)\n", target.getName(), target.getVendor()); mSdkLog.printf( " Based on Android %s (API level %s)\n", target.getVersionName(), target.getVersion().getApiString()); } // display some extra values. Map<String, String> properties = info.getProperties(); if (properties != null) { String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME); if (skin != null) { mSdkLog.printf(" Skin: %s\n", skin); } String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE); if (sdcard == null) { sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH); } if (sdcard != null) { mSdkLog.printf(" Sdcard: %s\n", sdcard); } String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT); if (snapshot != null) { mSdkLog.printf("Snapshot: %s\n", snapshot); } } } // Are there some unused AVDs? AvdInfo[] badAvds = avdManager.getBrokenAvds(); if (badAvds.length == 0) { return; } mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n"); boolean needSeparator = false; for (AvdInfo info : badAvds) { if (needSeparator) { mSdkLog.printf("---------\n"); } mSdkLog.printf(" Name: %s\n", info.getName() == null ? "--" : info.getName()); mSdkLog.printf(" Path: %s\n", info.getPath() == null ? "--" : info.getPath()); String error = info.getErrorMessage(); mSdkLog.printf(" Error: %s\n", error == null ? "Uknown error" : error); needSeparator = true; } }
/** * Prompts the user to setup a hardware config for a Platform-based AVD. * * @throws IOException */ private Map<String, String> promptForHardware( IAndroidTarget createTarget, Map<String, String> skinHardwareConfig) throws IOException { byte[] readLineBuffer = new byte[256]; String result; String defaultAnswer = "no"; mSdkLog.printf("%s is a basic Android platform.\n", createTarget.getName()); mSdkLog.printf("Do you wish to create a custom hardware profile [%s]", defaultAnswer); result = readLine(readLineBuffer).trim(); // handle default: if (result.length() == 0) { result = defaultAnswer; } if (getBooleanReply(result) == false) { // no custom config, return the skin hardware config in case there is one. return skinHardwareConfig; } mSdkLog.printf("\n"); // empty line // get the list of possible hardware properties File hardwareDefs = new File( mOsSdkFolder + File.separator + SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI); Map<String, HardwareProperty> hwMap = HardwareProperties.parseHardwareDefinitions(hardwareDefs, null /*sdkLog*/); HashMap<String, String> map = new HashMap<String, String>(); // we just want to loop on the HardwareProperties HardwareProperty[] hwProperties = hwMap.values().toArray(new HardwareProperty[hwMap.size()]); for (int i = 0; i < hwProperties.length; ) { HardwareProperty property = hwProperties[i]; String description = property.getDescription(); if (description != null) { mSdkLog.printf("%s: %s\n", property.getAbstract(), description); } else { mSdkLog.printf("%s\n", property.getAbstract()); } String defaultValue = property.getDefault(); String defaultFromSkin = skinHardwareConfig != null ? skinHardwareConfig.get(property.getName()) : null; if (defaultFromSkin != null) { mSdkLog.printf("%s [%s (from skin)]:", property.getName(), defaultFromSkin); } else if (defaultValue != null) { mSdkLog.printf("%s [%s]:", property.getName(), defaultValue); } else { mSdkLog.printf("%s (%s):", property.getName(), property.getType()); } result = readLine(readLineBuffer); if (result.length() == 0) { if (defaultFromSkin != null || defaultValue != null) { if (defaultFromSkin != null) { // we need to write this one in the AVD file map.put(property.getName(), defaultFromSkin); } mSdkLog.printf("\n"); // empty line i++; // go to the next property if we have a valid default value. // if there's no default, we'll redo this property } continue; } switch (property.getType()) { case BOOLEAN: try { if (getBooleanReply(result)) { map.put(property.getName(), "yes"); i++; // valid reply, move to next property } else { map.put(property.getName(), "no"); i++; // valid reply, move to next property } } catch (IOException e) { // display error, and do not increment i to redo this property mSdkLog.printf("\n%s\n", e.getMessage()); } break; case INTEGER: try { Integer.parseInt(result); map.put(property.getName(), result); i++; // valid reply, move to next property } catch (NumberFormatException e) { // display error, and do not increment i to redo this property mSdkLog.printf("\n%s\n", e.getMessage()); } break; case DISKSIZE: // TODO check validity map.put(property.getName(), result); i++; // valid reply, move to next property break; } mSdkLog.printf("\n"); // empty line } return map; }
@Override public String getName() { return myWrapee.getName(); }
/** Initialize the root values of the type infos based on the current framework values. */ private void initializeRootValues() { IProject project = mValues.project; for (TypeInfo type : sTypes) { // Clear all the roots for this type ArrayList<String> roots = type.getRoots(); if (roots.size() > 0) { roots.clear(); } // depending of the type of the seed, initialize the root in different ways Object rootSeed = type.getRootSeed(); if (rootSeed instanceof String) { // The seed is a single string, Add it as-is. roots.add((String) rootSeed); } else if (rootSeed instanceof String[]) { // The seed is an array of strings. Add them as-is. for (String value : (String[]) rootSeed) { roots.add(value); } } else if (rootSeed instanceof Integer && project != null) { // The seed is a descriptor reference defined in AndroidTargetData.DESCRIPTOR_* // In this case add all the children element descriptors defined, recursively, // and avoid infinite recursion by keeping track of what has already been added. // Note: if project is null, the root list will be empty since it has been // cleared above. // get the AndroidTargetData from the project IAndroidTarget target = null; AndroidTargetData data = null; target = Sdk.getCurrent().getTarget(project); if (target == null) { // A project should have a target. The target can be missing if the project // is an old project for which a target hasn't been affected or if the // target no longer exists in this SDK. Simply log the error and dismiss. AdtPlugin.log( IStatus.INFO, "NewXmlFile wizard: no platform target for project %s", //$NON-NLS-1$ project.getName()); continue; } else { data = Sdk.getCurrent().getTargetData(target); if (data == null) { // We should have both a target and its data. // However if the wizard is invoked whilst the platform is still being // loaded we can end up in a weird case where we have a target but it // doesn't have any data yet. // Lets log a warning and silently ignore this root. AdtPlugin.log( IStatus.INFO, "NewXmlFile wizard: no data for target %s, project %s", //$NON-NLS-1$ target.getName(), project.getName()); continue; } } IDescriptorProvider provider = data.getDescriptorProvider((Integer) rootSeed); ElementDescriptor descriptor = provider.getDescriptor(); if (descriptor != null) { HashSet<ElementDescriptor> visited = new HashSet<ElementDescriptor>(); initRootElementDescriptor(roots, descriptor, visited); } // Sort alphabetically. Collections.sort(roots); } } }
@Override public void execute() throws BuildException { Project antProject = getProject(); // get the SDK location String sdkLocation = antProject.getProperty(ProjectProperties.PROPERTY_SDK); // check if it's valid and exists if (sdkLocation == null || sdkLocation.length() == 0) { throw new BuildException("SDK Location is not set."); } File sdk = new File(sdkLocation); if (sdk.isDirectory() == false) { throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation)); } // get the target property value String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET); if (targetHashString == null) { throw new BuildException("Android Target is not set."); } // load up the sdk targets. final ArrayList<String> messages = new ArrayList<String>(); SdkManager manager = SdkManager.createManager( sdkLocation, new ISdkLog() { public void error(Throwable t, String errorFormat, Object... args) { if (errorFormat != null) { messages.add(String.format("Error: " + errorFormat, args)); } if (t != null) { messages.add("Error: " + t.getMessage()); } } public void printf(String msgFormat, Object... args) { messages.add(String.format(msgFormat, args)); } public void warning(String warningFormat, Object... args) { messages.add(String.format("Warning: " + warningFormat, args)); } }); if (manager == null) { // since we failed to parse the SDK, lets display the parsing output. for (String msg : messages) { System.out.println(msg); } throw new BuildException("Failed to parse SDK content."); } // resolve it IAndroidTarget androidTarget = manager.getTargetFromHashString(targetHashString); if (androidTarget == null) { throw new BuildException(String.format("Unable to resolve target '%s'", targetHashString)); } // display it System.out.println("Project Target: " + androidTarget.getName()); if (androidTarget.isPlatform() == false) { System.out.println("Vendor: " + androidTarget.getVendor()); } System.out.println("Platform Version: " + androidTarget.getApiVersionName()); System.out.println("API level: " + androidTarget.getApiVersionNumber()); // sets up the properties to find android.jar/framework.aidl String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR); String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL); antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar); antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl); // sets up the boot classpath // create the Path object Path bootclasspath = new Path(antProject); // create a PathElement for the framework jar PathElement element = bootclasspath.createPathElement(); element.setPath(androidJar); // create PathElement for each optional library. IOptionalLibrary[] libraries = androidTarget.getOptionalLibraries(); if (libraries != null) { HashSet<String> visitedJars = new HashSet<String>(); for (IOptionalLibrary library : libraries) { String jarPath = library.getJarPath(); if (visitedJars.contains(jarPath) == false) { visitedJars.add(jarPath); element = bootclasspath.createPathElement(); element.setPath(library.getJarPath()); } } } // finally sets the path in the project with a reference antProject.addReference(REF_CLASSPATH, bootclasspath); // find the file to import, and import it. String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES); // make sure the file exists. File templates = new File(templateFolder); if (templates.isDirectory() == false) { throw new BuildException( String.format("Template directory '%s' is missing.", templateFolder)); } // now check the rules file exists. File rules = new File(templateFolder, ANDROID_RULES); if (rules.isFile() == false) { throw new BuildException(String.format("Build rules file '%s' is missing.", templateFolder)); } // set the file location to import setFile(rules.getAbsolutePath()); // and import it super.execute(); }