Search in sources :

Example 21 with AndroidPlatform

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

the class GradleSpecificInitializer method checkAndSetSources.

private static void checkAndSetSources(@NotNull Sdk sdk) {
    VirtualFile[] storedSources = sdk.getRootProvider().getFiles(OrderRootType.SOURCES);
    if (storedSources.length > 0) {
        return;
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(sdk);
    if (platform != null) {
        SdkModificator sdkModificator = sdk.getSdkModificator();
        IAndroidTarget target = platform.getTarget();
        AndroidSdks.getInstance().findAndSetPlatformSources(target, sdkModificator);
        sdkModificator.commitChanges();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidSdkUtils.createNewAndroidPlatform(org.jetbrains.android.sdk.AndroidSdkUtils.createNewAndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 22 with AndroidPlatform

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

the class AndroidFacetImporterBase method isAppropriateSdk.

private boolean isAppropriateSdk(@NotNull Sdk sdk, MavenProject mavenProject) {
    if (!AndroidSdks.getInstance().isAndroidSdk(sdk)) {
        return false;
    }
    final String platformId = getPlatformFromConfig(mavenProject);
    final AndroidPlatform androidPlatform = AndroidPlatform.getInstance(sdk);
    if (androidPlatform == null) {
        return false;
    }
    final IAndroidTarget target = androidPlatform.getTarget();
    return (platformId == null || AndroidSdkUtils.targetHasId(target, platformId)) && AndroidSdkUtils.checkSdkRoots(sdk, target, true);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 23 with AndroidPlatform

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

the class AndroidLintTest method testGradlePlus.

/* Inspection disabled; these tests make network connection to MavenCentral and can change every time there
     is a new version available (which makes for unstable tests)

  public void testNewerAvailable() throws Exception {
    GradleDetector.REMOTE_VERSION.setEnabledByDefault(true);
    doTestWithFix(new AndroidLintInspectionToolProvider.AndroidLintNewerVersionAvailableInspection(),
                  "Update to 17.0.0", "build.gradle", "gradle");
  }
  */
public void testGradlePlus() throws Exception {
    // Needs a valid SDK; can't use the mock one in the test data.
    AndroidSdkData prevSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (prevSdkData == null) {
        Sdk androidSdk = createLatestAndroidSdk();
        AndroidPlatform androidPlatform = AndroidPlatform.getInstance(androidSdk);
        assertNotNull(androidPlatform);
        // Put default platforms in the list before non-default ones so they'll be looked at first.
        AndroidSdks.getInstance().setSdkData(androidPlatform.getSdkData());
    }
    //noinspection ConstantConditions
    File sdk = AndroidSdks.getInstance().tryToChooseAndroidSdk().getLocation();
    File appcompat = new File(sdk, "extras/android/m2repository/com/android/support/appcompat-v7/19.0.1".replace('/', File.separatorChar));
    if (!appcompat.exists()) {
        System.out.println("Not running " + this.getClass() + "#" + getName() + ": Needs SDK with Support Repo installed and " + "expected to find " + appcompat);
        return;
    }
    // NOTE: The android support repository must be installed in the SDK used by the test!
    doTestWithFix(new AndroidLintGradleDynamicVersionInspection(), "Replace with specific version", "build.gradle", "gradle");
    AndroidSdks.getInstance().setSdkData(prevSdkData);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 24 with AndroidPlatform

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

the class RenderErrorContributorTest method stripSdkHome.

private String stripSdkHome(@NotNull String html) {
    AndroidPlatform platform = AndroidPlatform.getInstance(myModule);
    assertNotNull(platform);
    String location = platform.getSdkData().getLocation().getPath();
    location = FileUtil.toSystemIndependentName(location);
    html = html.replace(location, "$SDK_HOME");
    return html;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform)

Example 25 with AndroidPlatform

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

the class AndroidJunitPatcherTest method getExampleClasspath.

private List<String> getExampleClasspath() {
    myRoot = normalize(myAndroidProject.getRootDir().getPath());
    List<String> exampleClassPath = Lists.newArrayList(myRoot + "/build/intermediates/classes/debug", myRoot + "/build/intermediates/classes/test/debug", myRoot + "/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/classes.jar", myRoot + "/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res", myRoot + "/build/intermediates/exploded-aar/com.android.support/support-v4/22.0.0/classes.jar", myRoot + "/build/intermediates/exploded-aar/com.android.support/support-v4/22.0.0/libs/internal_impl-22.0.0.jar", myRoot + "/build/intermediates/exploded-aar/com.android.support/support-v4/22.0.0/res", "/home/user/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar", "/idea/production/java-runtime", "/idea/production/junit_rt");
    myMockableAndroidJar = myRoot + "/build/intermediates/mockable-" + TestUtils.getLatestAndroidPlatform() + ".jar";
    AndroidPlatform androidPlatform = AndroidPlatform.getInstance(myModule);
    assertNotNull(androidPlatform);
    myRealAndroidJar = TestUtils.getPlatformFile("android.jar").toString();
    myResourcesDirs = ImmutableList.of(myRoot + "/build/intermediates/javaResources/debug", myRoot + "/build/intermediates/javaResources/test/debug");
    exampleClassPath.add(0, myMockableAndroidJar);
    exampleClassPath.add(0, myRealAndroidJar);
    myExampleClassPathSet = ImmutableSet.copyOf(exampleClassPath);
    // Sanity check. These should be fixed by the patcher.
    assertContainsElements(exampleClassPath, myRealAndroidJar);
    assertContainsElements(exampleClassPath, myMockableAndroidJar);
    assertDoesntContain(exampleClassPath, myResourcesDirs);
    assertFalse(Iterables.getLast(exampleClassPath).equals(myMockableAndroidJar));
    return exampleClassPath;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform)

Aggregations

AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)46 Module (com.intellij.openapi.module.Module)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 Nullable (org.jetbrains.annotations.Nullable)11 Project (com.intellij.openapi.project.Project)10 Sdk (com.intellij.openapi.projectRoots.Sdk)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 File (java.io.File)9 IOException (java.io.IOException)9 AndroidVersion (com.android.sdklib.AndroidVersion)8 NotNull (org.jetbrains.annotations.NotNull)6 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)5 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 RenderingException (com.android.tools.idea.layoutlib.RenderingException)3 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 SourceProvider (com.android.builder.model.SourceProvider)2 IDevice (com.android.ddmlib.IDevice)2