Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
AndroidSDKManager checks the validity of preferences
Browse files Browse the repository at this point in the history
AndroidSDKManager throws an exception if the SDK preferences for android
is not defined. This will allow UI components to correctly handle the
case by via status handlers. This also fixes bug JBIDE-16913.
  • Loading branch information
gorkem committed Jan 31, 2014
1 parent 34cfb16 commit 3b911ed
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public interface AndroidConstants {
public static final String FILE_XML_STRINGS = "strings.xml";
public static final String FILE_XML_BUILD ="build.xml";
public static final String PREF_ANDROID_SDK_LOCATION = "Android_SDK_Loc";

public static final int STATUS_CODE_ANDROID_SDK_NOT_DEFINED= 200;

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void launch(ILaunchConfiguration configuration, String mode,
throw new CoreException(new Status(IStatus.ERROR, AndroidCore.PLUGIN_ID,
"Failed to connect with the device or emulator. We will attempt to reconnect, please try running your application again."));
}
AndroidSDKManager sdk = new AndroidSDKManager();
AndroidSDKManager sdk = AndroidSDKManager.getManager();

HybridProject project = HybridProject.getHybridProject(getProject(configuration));
WidgetModel model = WidgetModel.getModel(project);
Expand Down Expand Up @@ -88,7 +88,7 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
String mode, IProgressMonitor monitor) throws CoreException {
// Start ADB Server
boolean runOnDevice = configuration.getAttribute(AndroidLaunchConstants.ATTR_IS_DEVICE_LAUNCH, false);
AndroidSDKManager sdk = new AndroidSDKManager();
AndroidSDKManager sdk = AndroidSDKManager.getManager();
if(!runOnDevice){
sdk.killADBServer();
}
Expand Down Expand Up @@ -153,7 +153,7 @@ public boolean preLaunchCheck(ILaunchConfiguration configuration,
}

private AndroidDevice getEmulator() throws CoreException{
AndroidSDKManager sdk = new AndroidSDKManager();
AndroidSDKManager sdk = AndroidSDKManager.getManager();
List<AndroidDevice> devices = sdk.listDevices();
for (AndroidDevice androidDevice : devices) {
if ( androidDevice.isEmulator() && androidDevice.getState() == AndroidDevice.STATE_DEVICE )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public IStatus isLibraryConsistent() {

public void preCompile(IProgressMonitor monitor) throws CoreException{
AndroidSDK sdk = AndroidProjectUtils.selectBestValidTarget();
AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();
File projectDir = libraryRoot.append("framework").toFile();
if(!projectDir.isDirectory()){
throw new CoreException(HybridMobileStatus.newMissingEngineStatus(null, "Library for the Active Hybrid Mobile Engine for Android is incomplete. No framework directory is present."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public AndroidProjectGenerator(IProject project, File generationFolder,String pl
@Override
protected void generateNativeFiles(HybridMobileLibraryResolver resolver) throws CoreException {

AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();

HybridProject hybridProject = HybridProject.getHybridProject(getProject());
if(hybridProject == null ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static File getPlatformWWWDirectory(File projectDirectory) {
* ,</ul>
*/
public static AndroidSDK selectBestValidTarget() throws CoreException {
AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();
List<AndroidSDK> targets = sdkManager.listTargets();
if(targets == null || targets.isEmpty() ){
throw new CoreException(new Status(IStatus.ERROR, AndroidCore.PLUGIN_ID, "No Android targets were found, Please create a target"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.jboss.tools.aerogear.hybrid.android.core.AndroidConstants;
import org.jboss.tools.aerogear.hybrid.android.core.AndroidCore;
import org.jboss.tools.aerogear.hybrid.core.HybridProjectConventions;
import org.jboss.tools.aerogear.hybrid.core.internal.util.ExternalProcessUtility;
import org.jboss.tools.aerogear.hybrid.core.internal.util.HybridMobileStatus;
import org.jboss.tools.aerogear.hybrid.core.internal.util.TextDetectingStreamListener;

/**
Expand Down Expand Up @@ -235,16 +239,22 @@ public String getErrorString(){



public AndroidSDKManager() {
private AndroidSDKManager(String tools, String platform) {
toolsDir = tools;
platformTools = platform;
}

public static AndroidSDKManager getManager() throws CoreException{
String sdkDir = AndroidCore.getSDKLocation();
if(sdkDir == null )
throw new IllegalStateException("No SDK is defined to work with the Android SDK Manager");

if(!sdkDir.endsWith(File.separator)){
sdkDir = sdkDir+ File.separator;
if(sdkDir == null ){
throw new CoreException(new HybridMobileStatus(IStatus.ERROR, AndroidCore.PLUGIN_ID, AndroidConstants.STATUS_CODE_ANDROID_SDK_NOT_DEFINED,
"Android SDK location is not defined", null));
}
toolsDir = sdkDir+ "tools" + File.separator;
platformTools = sdkDir +"platform-tools" + File.separator;
Path path = new Path(sdkDir);
IPath tools = path.append("tools").addTrailingSeparator();
IPath platform = path.append("platform-tools").addTrailingSeparator();
AndroidSDKManager sdk = new AndroidSDKManager(tools.toOSString(), platform.toOSString());
return sdk;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AndroidDeviceLaunchShortcut extends HybridProjectLaunchShortcut {
protected boolean validateBuildToolsReady() throws CoreException {
if(!SDKLocationHelper.defineSDKLocationIfNecessary())
return false;
AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();
List<AndroidSDK> targets = sdkManager.listTargets();
if(targets == null || targets.isEmpty() ){
throw new CoreException(new Status(IStatus.ERROR, AndroidUI.PLUGIN_ID, "No targets to build against"));
Expand Down Expand Up @@ -74,7 +74,7 @@ protected String getLaunchConfigurationTypeID() {
private AndroidDevice getDeviceToRun() {
if (deviceToRun == null) {
try {
AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();
List<AndroidDevice> devices = sdkManager.listDevices();
for (AndroidDevice androidDevice : devices) {
if (!androidDevice.isEmulator()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected boolean validateBuildToolsReady() throws CoreException {
if(!SDKLocationHelper.defineSDKLocationIfNecessary())
return false;

AndroidSDKManager sdkManager = new AndroidSDKManager();
AndroidSDKManager sdkManager = AndroidSDKManager.getManager();
List<AndroidSDK> targets = sdkManager.listTargets();
if(targets == null || targets.isEmpty() ){
throw new CoreException(new Status(IStatus.ERROR, AndroidUI.PLUGIN_ID, "No targets to build against"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public void widgetSelected(SelectionEvent e) {
logFilterTxt = new Text(grpEmulator, SWT.BORDER);
logFilterTxt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
logFilterTxt.addListener(SWT.Modify, dirtyListener);
AndroidSDKManager sdk = new AndroidSDKManager();
try {
AndroidSDKManager sdk = AndroidSDKManager.getManager();
List<String> avds = sdk.listAVDs();
for (String string : avds) {
AVDCombo.add(string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setValidateStrategy(int value) {
public AndroidPreferencePage() {
super(GRID);
setPreferenceStore(HybridUI.getDefault().getPreferenceStore());
setDescription("Settings for Hybrid Mobile Application development");
setDescription("Android settings for Hybrid Mobile Application development");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.statushandlers.StatusManager;
import org.jboss.tools.aerogear.hybrid.ui.HybridUI;

Expand All @@ -25,8 +26,9 @@ public void handle(IStatus status) {

@Override
public void handle(CoreException e) {
StatusManager platformStatusMgr = StatusManager.getManager();
platformStatusMgr.handle(e,HybridUI.PLUGIN_ID);
IStatus exceptionStatus = e.getStatus();
handle(new Status(exceptionStatus.getSeverity(), HybridUI.PLUGIN_ID,
e.getLocalizedMessage(), e) );
}

}

0 comments on commit 3b911ed

Please sign in to comment.