Search in sources :

Example 1 with AndroidSdkType

use of org.jetbrains.android.sdk.AndroidSdkType in project kotlin by JetBrains.

the class IntellijLintClient method getSdkHome.

@Nullable
@Override
public File getSdkHome() {
    Module module = getModule();
    if (module != null) {
        Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk();
        if (moduleSdk != null && moduleSdk.getSdkType() instanceof AndroidSdkType) {
            String path = moduleSdk.getHomePath();
            if (path != null) {
                File home = new File(path);
                if (home.exists()) {
                    return home;
                }
            }
        }
    }
    File sdkHome = super.getSdkHome();
    if (sdkHome != null) {
        return sdkHome;
    }
    for (Module m : ModuleManager.getInstance(myProject).getModules()) {
        Sdk moduleSdk = ModuleRootManager.getInstance(m).getSdk();
        if (moduleSdk != null) {
            if (moduleSdk.getSdkType() instanceof AndroidSdkType) {
                String path = moduleSdk.getHomePath();
                if (path != null) {
                    File home = new File(path);
                    if (home.exists()) {
                        return home;
                    }
                }
            }
        }
    }
    return IdeSdks.getAndroidSdkPath();
}
Also used : AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) AndroidSdk(com.android.tools.idea.welcome.install.AndroidSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidSdkType

use of org.jetbrains.android.sdk.AndroidSdkType in project android by JetBrains.

the class LintIdeClient method getSdkHome.

@Nullable
@Override
public File getSdkHome() {
    Module module = getModule();
    if (module != null) {
        Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk();
        if (moduleSdk != null && moduleSdk.getSdkType() instanceof AndroidSdkType) {
            String path = moduleSdk.getHomePath();
            if (path != null) {
                File home = new File(path);
                if (home.exists()) {
                    return home;
                }
            }
        }
    }
    File sdkHome = super.getSdkHome();
    if (sdkHome != null) {
        return sdkHome;
    }
    for (Module m : ModuleManager.getInstance(myProject).getModules()) {
        Sdk moduleSdk = ModuleRootManager.getInstance(m).getSdk();
        if (moduleSdk != null) {
            if (moduleSdk.getSdkType() instanceof AndroidSdkType) {
                String path = moduleSdk.getHomePath();
                if (path != null) {
                    File home = new File(path);
                    if (home.exists()) {
                        return home;
                    }
                }
            }
        }
    }
    return IdeSdks.getInstance().getAndroidSdkPath();
}
Also used : AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceFile(com.android.ide.common.res2.ResourceFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AndroidSdkType

use of org.jetbrains.android.sdk.AndroidSdkType in project android by JetBrains.

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
    if (module == null) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    PathsList classPath = javaParameters.getClassPath();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return;
    }
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    if (!(data instanceof AndroidSdkAdditionalData)) {
        return;
    }
    AndroidPlatform platform = ((AndroidSdkAdditionalData) data).getAndroidPlatform();
    if (platform == null) {
        return;
    }
    classPath.remove(platform.getTarget().getPath(IAndroidTarget.ANDROID_JAR));
    // Move the mockable android jar to the end.
    String mockableJarPath = null;
    for (String path : classPath.getPathList()) {
        if (new File(FileUtil.toSystemDependentName(path)).getName().startsWith("mockable-android")) {
            // PathsList stores strings - use the one that's actually stored there.
            mockableJarPath = path;
            break;
        }
    }
    if (mockableJarPath != null) {
        classPath.remove(mockableJarPath);
        classPath.addTail(mockableJarPath);
    }
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Example 4 with AndroidSdkType

use of org.jetbrains.android.sdk.AndroidSdkType in project android by JetBrains.

the class AndroidSdkResolveScopeProvider method getResolveScope.

@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
    if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID))
        return null;
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    JdkOrderEntry entry = ContainerUtil.findInstance(index.getOrderEntriesForFile(file), JdkOrderEntry.class);
    final Sdk sdk = entry == null ? null : entry.getJdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return null;
    }
    return new MyJdkScope(project, entry, index.isInLibrarySource(file));
}
Also used : JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)4 AndroidSdkType (org.jetbrains.android.sdk.AndroidSdkType)4 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)3 ResourceFile (com.android.ide.common.res2.ResourceFile)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidSdk (com.android.tools.idea.welcome.install.AndroidSdk)1 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)1 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 PathsList (com.intellij.util.PathsList)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)1