@Override public boolean equals(Object obj) { if (obj == null) return false; if (obj.getClass() != getClass()) return false; AndroidSdkData sdkData = (AndroidSdkData) obj; return FileUtil.pathsEqual(getLocation(), sdkData.getLocation()); }
@Override public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) { final List<String> javaSdks = Lists.newArrayList(); final Sdk[] sdks = sdkModel.getSdks(); for (Sdk jdk : sdks) { if (Jdks.isApplicableJdk(jdk)) { javaSdks.add(jdk.getName()); } } if (javaSdks.isEmpty()) { Messages.showErrorDialog( AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found"); return false; } MessageBuildingSdkLog log = new MessageBuildingSdkLog(); AndroidSdkData sdkData = getSdkData(sdk); if (sdkData == null) { String errorMessage = !log.getErrorMessage().isEmpty() ? log.getErrorMessage() : AndroidBundle.message("cannot.parse.sdk.error"); Messages.showErrorDialog(errorMessage, "SDK Parsing Error"); return false; } IAndroidTarget[] targets = sdkData.getTargets(); if (targets.length == 0) { if (Messages.showOkCancelDialog( AndroidBundle.message("no.android.targets.error"), CommonBundle.getErrorTitle(), "Open SDK Manager", Messages.CANCEL_BUTTON, Messages.getErrorIcon()) == Messages.OK) { RunAndroidSdkManagerAction.runSpecificSdkManager(null, sdkData.getLocation()); } return false; } String[] targetNames = new String[targets.length]; String newestPlatform = null; AndroidVersion version = null; for (int i = 0; i < targets.length; i++) { IAndroidTarget target = targets[i]; String targetName = getTargetPresentableName(target); targetNames[i] = targetName; if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) { newestPlatform = targetName; version = target.getVersion(); } } AndroidNewSdkDialog dialog = new AndroidNewSdkDialog( null, javaSdks, javaSdks.get(0), Arrays.asList(targetNames), newestPlatform != null ? newestPlatform : targetNames[0]); if (!dialog.showAndGet()) { return false; } String name = javaSdks.get(dialog.getSelectedJavaSdkIndex()); Sdk jdk = sdkModel.findSdk(name); IAndroidTarget target = targets[dialog.getSelectedTargetIndex()]; String sdkName = chooseNameForNewLibrary(target); setUpSdk(sdk, sdkName, sdks, target, jdk, true); return true; }
@Override public boolean setupSdkPaths(Sdk sdk, SdkModel sdkModel) { final List<String> javaSdks = new ArrayList<String>(); final Sdk[] sdks = sdkModel.getSdks(); for (Sdk jdk : sdks) { if (AndroidSdkUtils.isApplicableJdk(jdk)) { javaSdks.add(jdk.getName()); } } if (javaSdks.isEmpty()) { Messages.showErrorDialog( AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found"); return false; } int choice = Messages.showChooseDialog( "Please select Java SDK", "Select Internal Java Platform", ArrayUtil.toStringArray(javaSdks), javaSdks.get(0), Messages.getQuestionIcon()); if (choice == -1) { return false; } final String name = javaSdks.get(choice); final Sdk jdk = sdkModel.findSdk(name); MessageBuildingSdkLog log = new MessageBuildingSdkLog(); AndroidSdkData sdkData = AndroidSdkData.parse(sdk.getHomePath(), log); if (sdkData == null) { String errorMessage = log.getErrorMessage().length() > 0 ? log.getErrorMessage() : AndroidBundle.message("cannot.parse.sdk.error"); Messages.showErrorDialog(errorMessage, "SDK Parsing Error"); return false; } IAndroidTarget[] targets = sdkData.getTargets(); if (targets.length == 0) { Messages.showErrorDialog( AndroidBundle.message("no.android.targets.error"), CommonBundle.getErrorTitle()); return false; } String[] targetNames = new String[targets.length]; String newestPlatform = null; AndroidVersion version = null; for (int i = 0; i < targets.length; i++) { IAndroidTarget target = targets[i]; String targetName = AndroidSdkUtils.getTargetPresentableName(target); targetNames[i] = targetName; if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) { newestPlatform = targetName; version = target.getVersion(); } } choice = Messages.showChooseDialog( "Select build target", "Create New Android SDK", targetNames, newestPlatform != null ? newestPlatform : targetNames[0], Messages.getQuestionIcon()); if (choice == -1) { return false; } AndroidSdkUtils.setUpSdk(sdk, jdk, sdks, targets[choice], true); return true; }