try to find existing suitable android sdk; remove old jdk dependency

This commit is contained in:
Eugene Kudelevsky
2011-03-17 21:26:43 +03:00
parent 5f24d8865c
commit b5515a58b3
@@ -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<ModuleSettings>
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<ModuleSettings>
addNewDependency(moduleSettings, androidSdk.getName());
}
}
removeOldDependency(moduleSettings, platformName);
confElement.removeContent(platformNameElement);
}
@Nullable
@@ -135,15 +141,20 @@ public class AndroidModuleConverter1 extends ConversionProcessor<ModuleSettings>
}
}
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);
}
}
}
}