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

This commit is contained in:
The Android Open Source Project
2009-02-10 15:43:58 -08:00
parent 5a4d0fa291
commit e3c5766074
95 changed files with 6116 additions and 2460 deletions

View File

@@ -181,7 +181,7 @@ public class ApkBuilder extends BaseBuilder {
return mMakeFinalPackage;
}
}
/**
* {@link IZipEntryFilter} to filter out everything that is not a standard java resources.
* <p/>Used in {@link SignedJarBuilder#writeZip(java.io.InputStream, IZipEntryFilter)} when
@@ -215,6 +215,7 @@ public class ApkBuilder extends BaseBuilder {
// First thing we do is go through the resource delta to not
// lose it if we have to abort the build for any reason.
ApkDeltaVisitor dv = null;
if (kind == FULL_BUILD) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Start_Full_Apk_Build);
@@ -233,22 +234,13 @@ public class ApkBuilder extends BaseBuilder {
mConvertToDex = true;
mBuildFinalPackage = true;
} else {
ApkDeltaVisitor dv = new ApkDeltaVisitor(this, sourceList, outputFolder);
dv = new ApkDeltaVisitor(this, sourceList, outputFolder);
delta.accept(dv);
// save the state
mPackageResources |= dv.getPackageResources();
mConvertToDex |= dv.getConvertToDex();
mBuildFinalPackage |= dv.getMakeFinalPackage();
if (dv.mXmlError) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Xml_Error);
// if there was some XML errors, we just return w/o doing
// anything since we've put some markers in the files anyway
return referencedProjects;
}
}
// also go through the delta for all the referenced projects, until we are forced to
@@ -258,13 +250,13 @@ public class ApkBuilder extends BaseBuilder {
IJavaProject referencedJavaProject = referencedJavaProjects[i];
delta = getDelta(referencedJavaProject.getProject());
if (delta != null) {
ReferencedProjectDeltaVisitor dv = new ReferencedProjectDeltaVisitor(
ReferencedProjectDeltaVisitor refProjectDv = new ReferencedProjectDeltaVisitor(
referencedJavaProject);
delta.accept(dv);
delta.accept(refProjectDv);
// save the state
mConvertToDex |= dv.needDexConvertion();
mBuildFinalPackage |= dv.needMakeFinalPackage();
mConvertToDex |= refProjectDv.needDexConvertion();
mBuildFinalPackage |= refProjectDv.needMakeFinalPackage();
}
}
}
@@ -307,29 +299,14 @@ public class ApkBuilder extends BaseBuilder {
// At this point, we can abort the build if we have to, as we have computed
// our resource delta and stored the result.
abortOnBadSetup(javaProject);
// check if we have finished loading the SDK.
if (AdtPlugin.getDefault().getSdkLoadStatus(javaProject) != LoadStatus.LOADED) {
// we exit silently
return referencedProjects;
}
// Now check the compiler compliance level, not displaying the error
// message since this is not the first builder.
if (ProjectHelper.checkCompilerCompliance(getProject())
!= ProjectHelper.COMPILER_COMPLIANCE_OK) {
return referencedProjects;
}
// now check if the project has problem marker already
if (ProjectHelper.hasError(project, true)) {
// we found a marker with error severity: we abort the build.
// Since this is going to happen every time we save a file while
// errors are remaining, we do not force the display of the console, which
// would, in most cases, show on top of the Problem view (which is more
// important in that case).
if (dv != null && dv.mXmlError) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Project_Has_Errors);
Messages.Xml_Error);
// if there was some XML errors, we just return w/o doing
// anything since we've put some markers in the files anyway
return referencedProjects;
}

View File

@@ -19,10 +19,13 @@ package com.android.ide.eclipse.adt.build;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.project.ProjectHelper;
import com.android.ide.eclipse.adt.sdk.LoadStatus;
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.BaseProjectHelper;
import com.android.ide.eclipse.common.project.XmlErrorHandler;
import com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -34,6 +37,8 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -841,4 +846,53 @@ abstract class BaseBuilder extends IncrementalProjectBuilder {
return oslibraryList.toArray(new String[oslibraryList.size()]);
}
/**
* Aborts the build if the SDK/project setups are broken. This does not
* display any errors.
*
* @param javaProject The {@link IJavaProject} being compiled.
* @throws CoreException
*/
protected final void abortOnBadSetup(IJavaProject javaProject) throws CoreException {
// check if we have finished loading the SDK.
if (AdtPlugin.getDefault().getSdkLoadStatus(javaProject) != LoadStatus.LOADED) {
// we exit silently
stopBuild("SDK is not loaded yet");
}
// check the compiler compliance level.
if (ProjectHelper.checkCompilerCompliance(getProject()) !=
ProjectHelper.COMPILER_COMPLIANCE_OK) {
// we exit silently
stopBuild(Messages.Compiler_Compliance_Error);
}
// Check that the SDK directory has been setup.
String osSdkFolder = AdtPlugin.getOsSdkFolder();
if (osSdkFolder == null || osSdkFolder.length() == 0) {
stopBuild(Messages.No_SDK_Setup_Error);
}
IAndroidTarget projectTarget = Sdk.getCurrent().getTarget(javaProject.getProject());
if (projectTarget == null) {
// no target. error has been output by the container initializer:
// exit silently.
stopBuild("Project has no target");
}
}
/**
* Throws an exception to cancel the build.
*
* @param error the error message
* @param args the printf-style arguments to the error message.
* @throws CoreException
*/
protected final void stopBuild(String error, Object... args) throws CoreException {
throw new CoreException(new Status(IStatus.CANCEL, AdtPlugin.PLUGIN_ID,
String.format(error, args)));
}
}

View File

@@ -20,7 +20,6 @@ import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.project.FixLaunchConfig;
import com.android.ide.eclipse.adt.project.ProjectHelper;
import com.android.ide.eclipse.adt.sdk.LoadStatus;
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.AndroidManifestHelper;
@@ -224,7 +223,7 @@ public class PreCompilerBuilder extends BaseBuilder {
public PreCompilerBuilder() {
super();
}
// build() returns a list of project from which this project depends for future compilation.
@SuppressWarnings("unchecked") //$NON-NLS-1$
@Override
@@ -274,15 +273,6 @@ public class PreCompilerBuilder extends BaseBuilder {
mergeAidlFileModifications(dv.getAidlToCompile(),
dv.getAidlToRemove());
}
// if there was some XML errors, we just return w/o doing
// anything since we've put some markers in the files anyway.
if (dv.mXmlError) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Xml_Error);
return null;
}
// get the java package from the visitor
javaPackage = dv.getManifestPackage();
@@ -295,39 +285,19 @@ public class PreCompilerBuilder extends BaseBuilder {
// At this point we have stored what needs to be build, so we can
// do some high level test and abort if needed.
// check if we have finished loading the SDK.
if (AdtPlugin.getDefault().getSdkLoadStatus(javaProject) != LoadStatus.LOADED) {
// we exit silently
return null;
}
// check the compiler compliance level, not displaying the error message
// since this is not the first builder.
if (ProjectHelper.checkCompilerCompliance(getProject())
!= ProjectHelper.COMPILER_COMPLIANCE_OK) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Compiler_Compliance_Error);
return null;
}
// Check that the SDK directory has been setup.
String osSdkFolder = AdtPlugin.getOsSdkFolder();
if (osSdkFolder == null || osSdkFolder.length() == 0) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.No_SDK_Setup_Error);
markProject(AdtConstants.MARKER_ADT, Messages.No_SDK_Setup_Error,
IMarker.SEVERITY_ERROR);
return null;
}
abortOnBadSetup(javaProject);
IAndroidTarget projectTarget = Sdk.getCurrent().getTarget(project);
if (projectTarget == null) {
// no target. error has been output by the container initializer: exit silently.
return null;
// if there was some XML errors, we just return w/o doing
// anything since we've put some markers in the files anyway.
if (dv != null && dv.mXmlError) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.Xml_Error);
// This interrupts the build. The next builders will not run.
stopBuild(Messages.Xml_Error);
}
// get the manifest file
IFile manifest = AndroidManifestHelper.getManifest(project);
@@ -336,7 +306,9 @@ public class PreCompilerBuilder extends BaseBuilder {
AndroidConstants.FN_ANDROID_MANIFEST);
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
return null;
// This interrupts the build. The next builders will not run.
stopBuild(msg);
}
// lets check the XML of the manifest first, if that hasn't been done by the
@@ -353,7 +325,9 @@ public class PreCompilerBuilder extends BaseBuilder {
String msg = String.format(Messages.s_Contains_Xml_Error,
AndroidConstants.FN_ANDROID_MANIFEST);
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, msg);
return null;
// This interrupts the build. The next builders will not run.
stopBuild(msg);
}
// get the java package from the parser
@@ -366,7 +340,9 @@ public class PreCompilerBuilder extends BaseBuilder {
AndroidConstants.FN_ANDROID_MANIFEST);
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
msg);
return null;
// This interrupts the build. The next builders will not run.
stopBuild(msg);
}
// at this point we have the java package. We need to make sure it's not a different package
@@ -409,7 +385,8 @@ public class PreCompilerBuilder extends BaseBuilder {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project, message);
// abort
return null;
// This interrupts the build. The next builders will not run.
stopBuild(message);
}
@@ -430,6 +407,8 @@ public class PreCompilerBuilder extends BaseBuilder {
String osResPath = resLocation.toOSString();
String osManifestPath = manifestLocation.toOSString();
IAndroidTarget projectTarget = Sdk.getCurrent().getTarget(project);
// remove the aapt markers
removeMarkersFromFile(manifest, AndroidConstants.MARKER_AAPT);
removeMarkersFromContainer(resFolder, AndroidConstants.MARKER_AAPT);
@@ -517,20 +496,25 @@ public class PreCompilerBuilder extends BaseBuilder {
Messages.AAPT_Error);
// abort if exec failed.
return null;
// This interrupts the build. The next builders will not run.
stopBuild(Messages.AAPT_Error);
}
} catch (IOException e1) {
// something happen while executing the process,
// mark the project and exit
String msg = String.format(Messages.AAPT_Exec_Error, array.get(0));
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
return null;
// This interrupts the build. The next builders will not run.
stopBuild(msg);
} catch (InterruptedException e) {
// we got interrupted waiting for the process to end...
// mark the project and exit
String msg = String.format(Messages.AAPT_Exec_Error, array.get(0));
markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
return null;
// This interrupts the build. The next builders will not run.
stopBuild(msg);
}
// if the return code was OK, we refresh the folder that

View File

@@ -19,16 +19,20 @@ package com.android.ide.eclipse.adt.build;
import com.android.ide.eclipse.adt.AdtConstants;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.project.ProjectHelper;
import com.android.ide.eclipse.adt.sdk.LoadStatus;
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.BaseProjectHelper;
import com.android.sdklib.IAndroidTarget;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import java.util.Map;
@@ -36,7 +40,7 @@ import java.util.Map;
* Resource manager builder whose only purpose is to refresh the resource folder
* so that the other builder use an up to date version.
*/
public class ResourceManagerBuilder extends IncrementalProjectBuilder {
public class ResourceManagerBuilder extends BaseBuilder {
public static final String ID = "com.android.ide.eclipse.adt.ResourceManagerBuilder"; //$NON-NLS-1$
@@ -72,6 +76,38 @@ public class ResourceManagerBuilder extends IncrementalProjectBuilder {
BaseProjectHelper.addMarker(project, AdtConstants.MARKER_ADT, errorMessage,
IMarker.SEVERITY_ERROR);
AdtPlugin.printErrorToConsole(project, errorMessage);
// interrupt the build. The next builders will not run.
stopBuild(errorMessage);
}
// Check that the SDK directory has been setup.
String osSdkFolder = AdtPlugin.getOsSdkFolder();
if (osSdkFolder == null || osSdkFolder.length() == 0) {
AdtPlugin.printBuildToConsole(AdtConstants.BUILD_VERBOSE, project,
Messages.No_SDK_Setup_Error);
markProject(AdtConstants.MARKER_ADT, Messages.No_SDK_Setup_Error,
IMarker.SEVERITY_ERROR);
// This interrupts the build. The next builders will not run.
stopBuild(Messages.No_SDK_Setup_Error);
}
// check if we have finished loading the SDK.
IJavaProject javaProject = JavaCore.create(project);
if (AdtPlugin.getDefault().getSdkLoadStatus(javaProject) != LoadStatus.LOADED) {
// we exit silently
// This interrupts the build. The next builders will not run.
stopBuild("SDK is not loaded yet");
}
// check the project has a target
IAndroidTarget projectTarget = Sdk.getCurrent().getTarget(project);
if (projectTarget == null) {
// no target. marker has been set by the container initializer: exit silently.
// This interrupts the build. The next builders will not run.
stopBuild("Project has no target");
}
// Check the preference to be sure we are supposed to refresh

View File

@@ -35,8 +35,8 @@ import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.common.project.AndroidManifestHelper;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkManager;
import com.android.sdklib.vm.VmManager;
import com.android.sdklib.vm.VmManager.VmInfo;
import com.android.sdklib.avd.AvdManager;
import com.android.sdklib.avd.AvdManager.AvdInfo;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -74,7 +74,7 @@ import java.util.regex.Pattern;
public final class AndroidLaunchController implements IDebugBridgeChangeListener,
IDeviceChangeListener, IClientChangeListener {
private static final String FLAG_VM = "-vm"; //$NON-NLS-1$
private static final String FLAG_AVD = "-avd"; //$NON-NLS-1$
private static final String FLAG_NETDELAY = "-netdelay"; //$NON-NLS-1$
private static final String FLAG_NETSPEED = "-netspeed"; //$NON-NLS-1$
private static final String FLAG_WIPE_DATA = "-wipe-data"; //$NON-NLS-1$
@@ -228,9 +228,9 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
public boolean mNoBootAnim = LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM;
/**
* Vm Name.
* AVD Name.
*/
public String mVmName = null;
public String mAvdName = null;
public String mNetworkSpeed = EmulatorConfigTab.getSpeed(
LaunchConfigDelegate.DEFAULT_SPEED);
@@ -262,7 +262,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
try {
mVmName = config.getAttribute(LaunchConfigDelegate.ATTR_VM_NAME, mVmName);
mAvdName = config.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, mAvdName);
} catch (CoreException e) {
}
@@ -531,8 +531,8 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
wc.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
LaunchConfigDelegate.DEFAULT_TARGET_MODE);
// default VM: None
wc.setAttribute(LaunchConfigDelegate.ATTR_VM_NAME, (String)null);
// default AVD: None
wc.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, (String)null);
// set the default network speed
wc.setAttribute(LaunchConfigDelegate.ATTR_SPEED,
@@ -629,12 +629,12 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
// get the SDK
Sdk currentSdk = Sdk.getCurrent();
VmManager vmManager = currentSdk.getVmManager();
AvdManager avdManager = currentSdk.getAvdManager();
// get the project target
final IAndroidTarget projectTarget = currentSdk.getTarget(project);
// FIXME: check errors on missing sdk, vm manager, or project target.
// FIXME: check errors on missing sdk, AVD manager, or project target.
// device chooser response object.
final DeviceChooserResponse response = new DeviceChooserResponse();
@@ -644,81 +644,81 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
* - Manually Mode
* Always display a UI that lets a user see the current running emulators/devices.
* The UI must show which devices are compatibles, and allow launching new emulators
* with compatible (and not yet running) VM.
* with compatible (and not yet running) AVD.
* - Automatic Way
* * Preferred VM set.
* If Preferred VM is not running: launch it.
* Launch the application on the preferred VM.
* * No preferred VM.
* * Preferred AVD set.
* If Preferred AVD is not running: launch it.
* Launch the application on the preferred AVD.
* * No preferred AVD.
* Count the number of compatible emulators/devices.
* If != 1, display a UI similar to manual mode.
* If == 1, launch the application on this VM/device.
* If == 1, launch the application on this AVD/device.
*/
if (config.mTargetMode == AndroidLaunchConfiguration.AUTO_TARGET_MODE) {
// if we are in automatic target mode, we need to find the current devices
Device[] devices = AndroidDebugBridge.getBridge().getDevices();
// first check if we have a preferred VM name, and if it actually exists, and is valid
// first check if we have a preferred AVD name, and if it actually exists, and is valid
// (ie able to run the project).
// We need to check this in case the VM was recreated with a different target that is
// We need to check this in case the AVD was recreated with a different target that is
// not compatible.
VmInfo preferredVm = null;
if (config.mVmName != null) {
preferredVm = vmManager.getVm(config.mVmName);
if (projectTarget.isCompatibleBaseFor(preferredVm.getTarget()) == false) {
preferredVm = null;
AvdInfo preferredAvd = null;
if (config.mAvdName != null) {
preferredAvd = avdManager.getAvd(config.mAvdName);
if (projectTarget.isCompatibleBaseFor(preferredAvd.getTarget()) == false) {
preferredAvd = null;
AdtPlugin.printErrorToConsole(project, String.format(
"Preferred VM '%1$s' is not compatible with the project target '%2$s'. Looking for a compatible VM...",
config.mVmName, projectTarget.getName()));
"Preferred AVD '%1$s' is not compatible with the project target '%2$s'. Looking for a compatible AVD...",
config.mAvdName, projectTarget.getName()));
}
}
if (preferredVm != null) {
if (preferredAvd != null) {
// look for a matching device
for (Device d : devices) {
String deviceVm = d.getVmName();
if (deviceVm != null && deviceVm.equals(config.mVmName)) {
String deviceAvd = d.getAvdName();
if (deviceAvd != null && deviceAvd.equals(config.mAvdName)) {
response.mustContinue = true;
response.mustLaunchEmulator = false;
response.deviceToUse = d;
AdtPlugin.printToConsole(project, String.format(
"Automatic Target Mode: Preferred VM '%1$s' is available on emulator '%2$s'",
config.mVmName, d));
"Automatic Target Mode: Preferred AVD '%1$s' is available on emulator '%2$s'",
config.mAvdName, d));
continueLaunch(response, project, launch, launchInfo, config);
return;
}
}
// at this point we have a valid preferred VM that is not running.
// at this point we have a valid preferred AVD that is not running.
// We need to start it.
response.mustContinue = true;
response.mustLaunchEmulator = true;
response.vmToLaunch = preferredVm;
response.avdToLaunch = preferredAvd;
AdtPlugin.printToConsole(project, String.format(
"Automatic Target Mode: Preferred VM '%1$s' is not available. Launching new emulator.",
config.mVmName));
"Automatic Target Mode: Preferred AVD '%1$s' is not available. Launching new emulator.",
config.mAvdName));
continueLaunch(response, project, launch, launchInfo, config);
return;
}
// no (valid) preferred VM? look for one.
HashMap<Device, VmInfo> compatibleRunningVms = new HashMap<Device, VmInfo>();
// no (valid) preferred AVD? look for one.
HashMap<Device, AvdInfo> compatibleRunningAvds = new HashMap<Device, AvdInfo>();
boolean hasDevice = false; // if there's 1+ device running, we may force manual mode,
// as we cannot always detect proper compatibility with
// devices. This is the case if the project target is not
// a standard platform
for (Device d : devices) {
String deviceVm = d.getVmName();
if (deviceVm != null) { // physical devices return null.
VmInfo info = vmManager.getVm(deviceVm);
String deviceAvd = d.getAvdName();
if (deviceAvd != null) { // physical devices return null.
AvdInfo info = avdManager.getAvd(deviceAvd);
if (info != null && projectTarget.isCompatibleBaseFor(info.getTarget())) {
compatibleRunningVms.put(d, info);
compatibleRunningAvds.put(d, info);
}
} else {
if (projectTarget.isPlatform()) { // means this can run on any device as long
@@ -728,7 +728,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
int apiNumber = Integer.parseInt(apiString);
if (apiNumber >= projectTarget.getApiVersionNumber()) {
// device is compatible with project
compatibleRunningVms.put(d, null);
compatibleRunningAvds.put(d, null);
continue;
}
} catch (NumberFormatException e) {
@@ -741,54 +741,54 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
// depending on the number of devices, we'll simulate an automatic choice
// from the device chooser or simply show up the device chooser.
if (hasDevice == false && compatibleRunningVms.size() == 0) {
if (hasDevice == false && compatibleRunningAvds.size() == 0) {
// if zero emulators/devices, we launch an emulator.
// We need to figure out which VM first.
// We need to figure out which AVD first.
// we are going to take the closest VM. ie a compatible VM that has the API level
// we are going to take the closest AVD. ie a compatible AVD that has the API level
// closest to the project target.
VmInfo[] vms = vmManager.getVms();
VmInfo defaultVm = null;
for (VmInfo vm : vms) {
if (projectTarget.isCompatibleBaseFor(vm.getTarget())) {
if (defaultVm == null ||
vm.getTarget().getApiVersionNumber() <
defaultVm.getTarget().getApiVersionNumber()) {
defaultVm = vm;
AvdInfo[] avds = avdManager.getAvds();
AvdInfo defaultAvd = null;
for (AvdInfo avd : avds) {
if (projectTarget.isCompatibleBaseFor(avd.getTarget())) {
if (defaultAvd == null ||
avd.getTarget().getApiVersionNumber() <
defaultAvd.getTarget().getApiVersionNumber()) {
defaultAvd = avd;
}
}
}
if (defaultVm != null) {
if (defaultAvd != null) {
response.mustContinue = true;
response.mustLaunchEmulator = true;
response.vmToLaunch = defaultVm;
response.avdToLaunch = defaultAvd;
AdtPlugin.printToConsole(project, String.format(
"Automatic Target Mode: launching new emulator with compatible VM '%1$s'",
defaultVm.getName()));
"Automatic Target Mode: launching new emulator with compatible AVD '%1$s'",
defaultAvd.getName()));
continueLaunch(response, project, launch, launchInfo, config);
return;
} else {
// FIXME: ask the user if he wants to create a VM.
// we found no compatible VM.
// FIXME: ask the user if he wants to create a AVD.
// we found no compatible AVD.
AdtPlugin.printErrorToConsole(project, String.format(
"Failed to find a VM compatible with target '%1$s'. Launch aborted.",
"Failed to find a AVD compatible with target '%1$s'. Launch aborted.",
projectTarget.getName()));
launch.stopLaunch();
return;
}
} else if (hasDevice == false && compatibleRunningVms.size() == 1) {
Entry<Device, VmInfo> e = compatibleRunningVms.entrySet().iterator().next();
} else if (hasDevice == false && compatibleRunningAvds.size() == 1) {
Entry<Device, AvdInfo> e = compatibleRunningAvds.entrySet().iterator().next();
response.mustContinue = true;
response.mustLaunchEmulator = false;
response.deviceToUse = e.getKey();
// get the VmInfo, if null, the device is a physical device.
VmInfo vmInfo = e.getValue();
if (vmInfo != null) {
message = String.format("Automatic Target Mode: using existing emulator '%1$s' running compatible VM '%2$s'",
// get the AvdInfo, if null, the device is a physical device.
AvdInfo avdInfo = e.getValue();
if (avdInfo != null) {
message = String.format("Automatic Target Mode: using existing emulator '%1$s' running compatible AVD '%2$s'",
response.deviceToUse, e.getValue().getName());
} else {
message = String.format("Automatic Target Mode: using device '%1$s'",
@@ -801,7 +801,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
// if more than one device, we'll bring up the DeviceChooser dialog below.
if (compatibleRunningVms.size() >= 2) {
if (compatibleRunningAvds.size() >= 2) {
message = "Automatic Target Mode: Several compatible targets. Please select a target device.";
} else if (hasDevice) {
message = "Automatic Target Mode: Unable to detect device compatibility. Please select a target device.";
@@ -849,7 +849,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
synchronized (sListLock) {
mWaitingForEmulatorLaunches.add(launchInfo);
AdtPlugin.printToConsole(project, "Launching a new emulator.");
boolean status = launchEmulator(config, response.vmToLaunch);
boolean status = launchEmulator(config, response.avdToLaunch);
if (status == false) {
// launching the emulator failed!
@@ -1323,7 +1323,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
}
}
private boolean launchEmulator(AndroidLaunchConfiguration config, VmInfo vmToLaunch) {
private boolean launchEmulator(AndroidLaunchConfiguration config, AvdInfo avdToLaunch) {
// split the custom command line in segments
ArrayList<String> customArgs = new ArrayList<String>();
@@ -1353,8 +1353,8 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
ArrayList<String> list = new ArrayList<String>();
list.add(AdtPlugin.getOsAbsoluteEmulator());
list.add(FLAG_VM);
list.add(vmToLaunch.getName());
list.add(FLAG_AVD);
list.add(avdToLaunch.getName());
if (config.mNetworkSpeed != null) {
list.add(FLAG_NETSPEED);

View File

@@ -31,7 +31,7 @@ import com.android.ide.eclipse.adt.debug.launching.AndroidLaunchController.Delay
import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.ddms.DdmsPlugin;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.vm.VmManager.VmInfo;
import com.android.sdklib.avd.AvdManager.AvdInfo;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -70,10 +70,10 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
private final static int ICON_WIDTH = 16;
private final static String PREFS_COL_SERIAL = "deviceChooser.serial"; //$NON-NLS-1$
private final static String PREFS_COL_STATE = "deviceChooser.state"; //$NON-NLS-1$
private final static String PREFS_COL_VM = "deviceChooser.vm"; //$NON-NLS-1$
private final static String PREFS_COL_STATE = "deviceChooser.state"; //$NON-NLS-1$
private final static String PREFS_COL_AVD = "deviceChooser.avd"; //$NON-NLS-1$
private final static String PREFS_COL_TARGET = "deviceChooser.target"; //$NON-NLS-1$
private final static String PREFS_COL_DEBUG = "deviceChooser.debug"; //$NON-NLS-1$
private final static String PREFS_COL_DEBUG = "deviceChooser.debug"; //$NON-NLS-1$
private Table mDeviceTable;
private TableViewer mViewer;
@@ -149,8 +149,8 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
return mNoMatchImage;
}
} else {
// get the VmInfo
VmInfo info = mSdk.getVmManager().getVm(device.getVmName());
// get the AvdInfo
AvdInfo info = mSdk.getAvdManager().getAvd(device.getAvdName());
if (info == null) {
return mWarningImage;
}
@@ -171,13 +171,13 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
return device.getSerialNumber();
case 1:
if (device.isEmulator()) {
return device.getVmName();
return device.getAvdName();
} else {
return "N/A"; // devices don't have VM names.
return "N/A"; // devices don't have AVD names.
}
case 2:
if (device.isEmulator()) {
VmInfo info = mSdk.getVmManager().getVm(device.getVmName());
AvdInfo info = mSdk.getAvdManager().getAvd(device.getAvdName());
if (info == null) {
return "?";
}
@@ -221,7 +221,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
public static class DeviceChooserResponse {
public boolean mustContinue;
public boolean mustLaunchEmulator;
public VmInfo vmToLaunch;
public AvdInfo avdToLaunch;
public Device deviceToUse;
}
@@ -314,9 +314,9 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener
SWT.LEFT, "AAA+AAAAAAAAAAAAAAAAAAA", //$NON-NLS-1$
PREFS_COL_SERIAL, store);
TableHelper.createTableColumn(mDeviceTable, "VM Name",
TableHelper.createTableColumn(mDeviceTable, "AVD Name",
SWT.LEFT, "engineering", //$NON-NLS-1$
PREFS_COL_VM, store);
PREFS_COL_AVD, store);
TableHelper.createTableColumn(mDeviceTable, "Target",
SWT.LEFT, "AAA+Android 9.9.9", //$NON-NLS-1$

View File

@@ -80,7 +80,7 @@ public class LaunchConfigDelegate extends LaunchConfigurationDelegate {
*/
public static final String ATTR_ACTIVITY = AdtPlugin.PLUGIN_ID + ".activity"; //$NON-NLS-1$
public static final String ATTR_VM_NAME = AdtPlugin.PLUGIN_ID + ".vm"; //$NON-NLS-1$
public static final String ATTR_AVD_NAME = AdtPlugin.PLUGIN_ID + ".avd"; //$NON-NLS-1$
public static final String ATTR_SPEED = AdtPlugin.PLUGIN_ID + ".speed"; //$NON-NLS-1$

View File

@@ -22,9 +22,9 @@ import com.android.ide.eclipse.adt.sdk.Sdk;
import com.android.ide.eclipse.common.project.BaseProjectHelper;
import com.android.ide.eclipse.ddms.DdmsPlugin;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.vm.VmManager;
import com.android.sdklib.vm.VmManager.VmInfo;
import com.android.sdkuilib.VmSelector;
import com.android.sdklib.avd.AvdManager;
import com.android.sdklib.avd.AvdManager.AvdInfo;
import com.android.sdkuilib.AvdSelector;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@@ -75,7 +75,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
private Button mAutoTargetButton;
private Button mManualTargetButton;
private VmSelector mPreferredVmSelector;
private AvdSelector mPreferredAvdSelector;
private Combo mSpeedCombo;
@@ -163,11 +163,11 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
}
});
new Label(targetModeGroup, SWT.NONE).setText("Preferred VM");
VmInfo[] vms = new VmInfo[0];
mPreferredVmSelector = new VmSelector(targetModeGroup, vms,
new Label(targetModeGroup, SWT.NONE).setText("Preferred Android Virtual Device");
AvdInfo[] avds = new AvdInfo[0];
mPreferredAvdSelector = new AvdSelector(targetModeGroup, avds,
false /*allowMultipleSelection*/);
mPreferredVmSelector.setSelectionListener(new SelectionAdapter() {
mPreferredAvdSelector.setSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateLaunchConfigurationDialog();
@@ -277,7 +277,7 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
* @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
*/
public void initializeFrom(ILaunchConfiguration configuration) {
VmManager vmManager = Sdk.getCurrent().getVmManager();
AvdManager avdManager = Sdk.getCurrent().getAvdManager();
boolean value = LaunchConfigDelegate.DEFAULT_TARGET_MODE; // true == automatic
try {
@@ -311,34 +311,34 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
}
}
// update the VM list
VmInfo[] vms = null;
if (vmManager != null) {
vms = vmManager.getVms();
// update the AVD list
AvdInfo[] avds = null;
if (avdManager != null) {
avds = avdManager.getAvds();
}
IAndroidTarget projectTarget = null;
if (project != null) {
projectTarget = Sdk.getCurrent().getTarget(project);
} else {
vms = null; // no project? we don't want to display any "compatible" VMs.
avds = null; // no project? we don't want to display any "compatible" AVDs.
}
mPreferredVmSelector.setVms(vms, projectTarget);
mPreferredAvdSelector.setAvds(avds, projectTarget);
stringValue = "";
try {
stringValue = configuration.getAttribute(LaunchConfigDelegate.ATTR_VM_NAME,
stringValue = configuration.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME,
stringValue);
} catch (CoreException e) {
// let's not do anything here, we'll use the default value
}
if (stringValue != null && stringValue.length() > 0 && vmManager != null) {
VmInfo targetVm = vmManager.getVm(stringValue);
mPreferredVmSelector.setSelection(targetVm);
if (stringValue != null && stringValue.length() > 0 && avdManager != null) {
AvdInfo targetAvd = avdManager.getAvd(stringValue);
mPreferredAvdSelector.setSelection(targetAvd);
} else {
mPreferredVmSelector.setSelection(null);
mPreferredAvdSelector.setSelection(null);
}
value = LaunchConfigDelegate.DEFAULT_WIPE_DATA;
@@ -404,11 +404,11 @@ public class EmulatorConfigTab extends AbstractLaunchConfigurationTab {
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
mAutoTargetButton.getSelection());
VmInfo vm = mPreferredVmSelector.getFirstSelected();
if (vm != null) {
configuration.setAttribute(LaunchConfigDelegate.ATTR_VM_NAME, vm.getName());
AvdInfo avd = mPreferredAvdSelector.getFirstSelected();
if (avd != null) {
configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, avd.getName());
} else {
configuration.setAttribute(LaunchConfigDelegate.ATTR_VM_NAME, (String)null);
configuration.setAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, (String)null);
}
configuration.setAttribute(LaunchConfigDelegate.ATTR_SPEED,
mSpeedCombo.getSelectionIndex());

View File

@@ -361,7 +361,7 @@ public final class ProjectHelper {
}
/**
* Returns a {@link IProject} by its running application name, as it returned by the VM.
* Returns a {@link IProject} by its running application name, as it returned by the AVD.
* <p/>
* <var>applicationName</var> will in most case be the package declared in the manifest, but
* can, in some cases, be a custom process name declared in the manifest, in the

View File

@@ -23,9 +23,9 @@ import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.ISdkLog;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import com.android.sdklib.avd.AvdManager;
import com.android.sdklib.project.ProjectProperties;
import com.android.sdklib.project.ProjectProperties.PropertyType;
import com.android.sdklib.vm.VmManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
@@ -52,7 +52,7 @@ public class Sdk {
private static Sdk sCurrentSdk = null;
private final SdkManager mManager;
private final VmManager mVmManager;
private final AvdManager mAvdManager;
private final HashMap<IProject, IAndroidTarget> mProjectMap =
new HashMap<IProject, IAndroidTarget>();
@@ -95,13 +95,13 @@ public class Sdk {
// get an SdkManager object for the location
SdkManager manager = SdkManager.createManager(sdkLocation, log);
if (manager != null) {
VmManager vmManager = null;
AvdManager avdManager = null;
try {
vmManager = new VmManager(manager, log);
avdManager = new AvdManager(manager, log);
} catch (AndroidLocationException e) {
log.error(e, "Error parsing the VMs");
log.error(e, "Error parsing the AVDs");
}
sCurrentSdk = new Sdk(manager, vmManager);
sCurrentSdk = new Sdk(manager, avdManager);
return sCurrentSdk;
} else {
StringBuilder sb = new StringBuilder("Error Loading the SDK:\n");
@@ -255,16 +255,16 @@ public class Sdk {
}
/**
* Returns the {@link VmManager}. If the VmManager failed to parse the VM folder, this could
* Returns the {@link AvdManager}. If the AvdManager failed to parse the AVD folder, this could
* be <code>null</code>.
*/
public VmManager getVmManager() {
return mVmManager;
public AvdManager getAvdManager() {
return mAvdManager;
}
private Sdk(SdkManager manager, VmManager vmManager) {
private Sdk(SdkManager manager, AvdManager avdManager) {
mManager = manager;
mVmManager = vmManager;
mAvdManager = avdManager;
// pre-compute some paths
mDocBaseUrl = getDocumentationBaseUrl(mManager.getLocation() +

View File

@@ -187,10 +187,10 @@ public final class CustomViewDescriptorService {
/**
* Computes (if needed) and returns the {@link ElementDescriptor} for the specified type.
*
* @param type
* @param type
* @param project
* @param typeHierarchy
* @return A ViewElementDescriptor
* @return A ViewElementDescriptor or null if type or typeHierarchy is null.
*/
private ViewElementDescriptor getDescriptor(IType type, IProject project,
ITypeHierarchy typeHierarchy) {
@@ -198,12 +198,17 @@ public final class CustomViewDescriptorService {
List<ElementDescriptor> builtInList = null;
Sdk currentSdk = Sdk.getCurrent();
IAndroidTarget target = currentSdk.getTarget(project);
IAndroidTarget target = currentSdk == null ? null : currentSdk.getTarget(project);
if (target != null) {
AndroidTargetData data = currentSdk.getTargetData(target);
builtInList = data.getLayoutDescriptors().getViewDescriptors();
}
// give up if there's no type
if (type == null) {
return null;
}
String canonicalName = type.getFullyQualifiedName();
if (builtInList != null) {
@@ -218,6 +223,11 @@ public final class CustomViewDescriptorService {
}
// it's not a built-in class? Lets look if the superclass is built-in
// give up if there's no type
if (typeHierarchy == null) {
return null;
}
IType parentType = typeHierarchy.getSuperclass(type);
if (parentType != null) {
ViewElementDescriptor parentDescriptor = getDescriptor(parentType, project,

View File

@@ -79,7 +79,7 @@ public abstract class UiAbstractTextAttributeNode extends UiAttributeNode
public void updateValue(Node xml_attribute_node) {
mCurrentValue = DEFAULT_VALUE;
if (xml_attribute_node != null) {
mCurrentValue = xml_attribute_node.getNodeValue().trim();
mCurrentValue = xml_attribute_node.getNodeValue();
}
if (isValid() && !getTextWidgetValue().equals(mCurrentValue)) {
@@ -101,7 +101,7 @@ public abstract class UiAbstractTextAttributeNode extends UiAttributeNode
public void commit() {
UiElementNode parent = getUiParent();
if (parent != null && isValid() && isDirty()) {
String value = getTextWidgetValue().trim();
String value = getTextWidgetValue();
if (parent.commitAttributeToXml(this, value)) {
mCurrentValue = value;
setDirty(false);