Search in sources :

Example 16 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class AndroidSdkUtils method isGlassInstalled.

public static boolean isGlassInstalled() {
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(AndroidSdkUtils.class);
    AndroidSdkHandler handler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    Collection<IAndroidTarget> targets = handler.getAndroidTargetManager(progress).getTargets(progress);
    for (IAndroidTarget target : targets) {
        if (!target.isPlatform() && target.getName().startsWith("Glass Development Kit")) {
            return true;
        }
    }
    return false;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 17 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class AndroidSdkUtils method findAppropriateAndroidPlatform.

@Nullable
public static Sdk findAppropriateAndroidPlatform(@NotNull IAndroidTarget target, @NotNull AndroidSdkData sdkData, boolean forMaven) {
    for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
        String homePath = sdk.getHomePath();
        AndroidSdks androidSdks = AndroidSdks.getInstance();
        if (homePath != null && androidSdks.isAndroidSdk(sdk)) {
            AndroidSdkData currentSdkData = getSdkData(homePath);
            if (sdkData.equals(currentSdkData)) {
                AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
                if (data != null) {
                    IAndroidTarget currentTarget = data.getBuildTarget(currentSdkData);
                    if (currentTarget != null && target.hashString().equals(currentTarget.hashString()) && checkSdkRoots(sdk, target, forMaven)) {
                        return sdk;
                    }
                }
            }
        }
    }
    return null;
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) ModuleRootModificationUtil.setModuleSdk(com.intellij.openapi.roots.ModuleRootModificationUtil.setModuleSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class AndroidSdkUtils method createNewAndroidPlatform.

/**
   * Creates a new IDEA Android SDK. User is prompt for the paths of the Android SDK and JDK if necessary.
   *
   * @param sdkPath the path of Android SDK.
   * @return the created IDEA Android SDK, or {@null} if it was not possible to create it.
   */
@Nullable
public static Sdk createNewAndroidPlatform(@Nullable String sdkPath, boolean promptUser) {
    Sdk jdk = Jdks.getInstance().chooseOrCreateJavaSdk();
    if (sdkPath != null && jdk != null) {
        sdkPath = toSystemIndependentName(sdkPath);
        IAndroidTarget target = findBestTarget(sdkPath);
        if (target != null) {
            Sdk sdk = AndroidSdks.getInstance().create(target, new File(sdkPath), AndroidSdks.getInstance().chooseNameForNewLibrary(target), jdk, true);
            if (sdk != null) {
                return sdk;
            }
        }
    }
    String jdkPath = jdk == null ? null : jdk.getHomePath();
    return promptUser ? promptUserForSdkCreation(null, sdkPath, jdkPath) : null;
}
Also used : ModuleRootModificationUtil.setModuleSdk(com.intellij.openapi.roots.ModuleRootModificationUtil.setModuleSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class AndroidTestBase method createLatestAndroidSdk.

public static Sdk createLatestAndroidSdk() {
    String sdkPath = TestUtils.getSdk().toString();
    String platformDir = TestUtils.getLatestAndroidPlatform();
    Sdk sdk = ProjectJdkTable.getInstance().createSdk("android_test_sdk", AndroidSdkType.getInstance());
    SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.setHomePath(sdkPath);
    VirtualFile androidJar = JarFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/android.jar!/");
    sdkModificator.addRoot(androidJar, OrderRootType.CLASSES);
    VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/data/res");
    sdkModificator.addRoot(resFolder, OrderRootType.CLASSES);
    VirtualFile docsFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/docs/reference");
    if (docsFolder != null) {
        sdkModificator.addRoot(docsFolder, JavadocOrderRootType.getInstance());
    }
    AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(sdk);
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdkPath);
    assertNotNull(sdkData);
    IAndroidTarget target = null;
    IAndroidTarget[] targets = sdkData.getTargets();
    for (IAndroidTarget t : targets) {
        if (t.getLocation().contains(platformDir)) {
            target = t;
            break;
        }
    }
    assertNotNull(target);
    data.setBuildTarget(target);
    sdkModificator.setSdkAdditionalData(data);
    ExternalAnnotationsSupport.attachJdkAnnotations(sdkModificator);
    sdkModificator.commitChanges();
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 20 with IAndroidTarget

use of com.android.sdklib.IAndroidTarget in project android by JetBrains.

the class ThemeEditorUtils method getModuleThemeQualifiedNamesList.

/**
   * Returns the list of the qualified names of all the user-defined themes available from a given module
   */
@NotNull
public static ImmutableList<String> getModuleThemeQualifiedNamesList(@NotNull Module module) {
    AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null;
    ConfigurationManager manager = facet.getConfigurationManager();
    // We create a new ResourceResolverCache instead of using cache from myConfiguration to optimize memory instead of time/speed,
    // because we are about to create a lot of instances of ResourceResolver here that won't be used outside of this method
    final ResourceResolverCache resolverCache = new ResourceResolverCache(manager);
    final IAndroidTarget target = manager.getTarget();
    final Map<ResourceValue, Boolean> cache = new HashMap<ResourceValue, Boolean>();
    final Set<String> themeNamesSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
    ResourceFolderVisitor visitor = new ResourceFolderVisitor() {

        @Override
        public void visitResourceFolder(@NotNull LocalResourceRepository resources, String moduleName, @NotNull String variantName, boolean isSelected) {
            if (!isSelected) {
                return;
            }
            for (String simpleThemeName : resources.getItemsOfType(ResourceType.STYLE)) {
                String themeStyleResourceUrl = SdkConstants.STYLE_RESOURCE_PREFIX + simpleThemeName;
                List<ResourceItem> themeItems = resources.getResourceItem(ResourceType.STYLE, simpleThemeName);
                assert themeItems != null;
                for (ResourceItem themeItem : themeItems) {
                    ResourceResolver resolver = resolverCache.getResourceResolver(target, themeStyleResourceUrl, themeItem.getConfiguration());
                    ResourceValue themeItemResourceValue = themeItem.getResourceValue(false);
                    assert themeItemResourceValue != null;
                    if (resolver.isTheme(themeItemResourceValue, cache)) {
                        themeNamesSet.add(simpleThemeName);
                        break;
                    }
                }
            }
        }
    };
    acceptResourceResolverVisitor(facet, visitor);
    return ImmutableList.copyOf(themeNamesSet);
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) NotNull(org.jetbrains.annotations.NotNull) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) ResourceResolverCache(com.android.tools.idea.configurations.ResourceResolverCache) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceItem(com.android.ide.common.res2.ResourceItem) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IAndroidTarget (com.android.sdklib.IAndroidTarget)105 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Module (com.intellij.openapi.module.Module)17 NotNull (org.jetbrains.annotations.NotNull)16 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)14 File (java.io.File)13 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)13 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)13 AndroidVersion (com.android.sdklib.AndroidVersion)11 Device (com.android.sdklib.devices.Device)11 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)9 State (com.android.sdklib.devices.State)8 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)8 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)8 Configuration (com.android.tools.idea.configurations.Configuration)7 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)7 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)6