From b5515a58b306c2a99e37a0930516e5da1759e078 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 17 Mar 2011 21:07:19 +0300 Subject: [PATCH] try to find existing suitable android sdk; remove old jdk dependency --- .../converter/AndroidModuleConverter1.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/android/src/org/jetbrains/android/converter/AndroidModuleConverter1.java b/plugins/android/src/org/jetbrains/android/converter/AndroidModuleConverter1.java index a8b296fd13a4..0008c0d06736 100644 --- a/plugins/android/src/org/jetbrains/android/converter/AndroidModuleConverter1.java +++ b/plugins/android/src/org/jetbrains/android/converter/AndroidModuleConverter1.java @@ -18,6 +18,7 @@ package org.jetbrains.android.converter; import com.intellij.conversion.CannotConvertException; import com.intellij.conversion.ConversionProcessor; import com.intellij.conversion.ModuleSettings; +import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkModificator; import com.intellij.openapi.roots.OrderRootType; @@ -31,6 +32,7 @@ import org.jetbrains.android.facet.AndroidFacetType; import org.jetbrains.android.sdk.AndroidPlatform; import org.jetbrains.android.sdk.AndroidSdkType; import org.jetbrains.android.sdk.AndroidSdkUtils; +import org.jetbrains.android.util.AndroidUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,14 +64,21 @@ public class AndroidModuleConverter1 extends ConversionProcessor if (platformName == null) return; + removeOldDependencies(moduleSettings, platformName); + confElement.removeContent(platformNameElement); + Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName); if (androidLibrary != null) { AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null); if (androidPlatform != null) { - Sdk androidSdk = - AndroidSdkUtils.createNewAndroidPlatform(androidPlatform.getTarget(), androidPlatform.getSdk().getLocation(), false); + + Sdk androidSdk = AndroidUtils.findAppropriateAndroidPlatform(androidPlatform.getTarget(), androidPlatform.getSdk()); + + if (androidSdk == null) { + androidSdk = AndroidSdkUtils.createNewAndroidPlatform(androidPlatform.getTarget(), androidPlatform.getSdk().getLocation(), false); + } SdkModificator modificator = androidSdk.getSdkModificator(); @@ -83,9 +92,6 @@ public class AndroidModuleConverter1 extends ConversionProcessor addNewDependency(moduleSettings, androidSdk.getName()); } } - - removeOldDependency(moduleSettings, platformName); - confElement.removeContent(platformNameElement); } @Nullable @@ -135,15 +141,20 @@ public class AndroidModuleConverter1 extends ConversionProcessor } } - private static void removeOldDependency(ModuleSettings moduleSettings, @NotNull String libName) { + private static void removeOldDependencies(ModuleSettings moduleSettings, @NotNull String libName) { Element moduleManagerElement = moduleSettings.getComponentElement(NEW_MODULE_MANAGER); if (moduleManagerElement != null) { for (Element entryElement : getChildren(moduleManagerElement, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME)) { + if (libName.equals(entryElement.getAttributeValue("name")) && "library".equals(entryElement.getAttributeValue("type")) && "application".equals(entryElement.getAttributeValue("level"))) { moduleManagerElement.removeContent(entryElement); } + + if ("jdk".equals(entryElement.getAttributeValue("type")) || "inheritedJdk".equals(entryElement.getAttributeValue("type"))) { + moduleManagerElement.removeContent(entryElement); + } } } }