Search in sources :

Example 1 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 2 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 3 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)

Example 4 with AndroidPlatform

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

the class AddAndroidActivityPath method getDirectories.

private Map<String, Object> getDirectories() {
    Map<String, Object> templateParameters = Maps.newHashMap();
    Module module = getModule();
    assert module != null;
    AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null;
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null) {
        templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
        templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
    }
    // Read minSdkVersion and package from manifest and/or build.gradle files
    AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
    AndroidModel androidModel = facet.getAndroidModel();
    SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
    if (sourceProvider1 != null && androidModel != null) {
        String packageName = myState.get(KEY_PACKAGE_NAME);
        assert packageName != null;
        templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
    }
    AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
    String minSdkName = minSdkVersion.getApiString();
    templateParameters.put(ATTR_MIN_API, minSdkName);
    templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
    templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
    templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
    try {
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
    } catch (Exception e) {
        LOG.info("Could not compute SHA1 hash of debug keystore.", e);
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
    }
    @SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
    Project project = getProject();
    assert project != null;
    templateParameters.put(projectLocation, project.getBasePath());
    // We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
    // name as its containing project.
    String moduleName = new File(module.getModuleFilePath()).getParentFile().getName();
    templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
    return templateParameters;
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) SourceProvider(com.android.builder.model.SourceProvider) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) Project(com.intellij.openapi.project.Project) AndroidModel(com.android.tools.idea.model.AndroidModel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with AndroidPlatform

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

the class GraphicsLayoutRenderer method create.

/**
   * Creates a new {@link GraphicsLayoutRenderer}.
   * @param configuration The configuration to use when rendering.
   * @param parser A layout pull-parser.
   * @param backgroundColor If not null, this will be use to set the global Android window background
   * @throws AlreadyDisposedException if the module is disposed while create is running
   * @throws InitializationException if layoutlib fails to initialize.
   * @throws UnsupportedLayoutlibException if the used layoutlib version is too old to run with this class
   */
@NotNull
public static GraphicsLayoutRenderer create(@NotNull Configuration configuration, @NotNull ILayoutPullParser parser, @Nullable Color backgroundColor, boolean hasHorizontalScroll, boolean hasVerticalScroll) throws InitializationException {
    Module module = configuration.getModule();
    if (module.isDisposed()) {
        throw new AlreadyDisposedException("Module was already disposed");
    }
    AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
    if (facet == null) {
        throw new InitializationException("Unable to get AndroidFacet");
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        throw new UnsupportedLayoutlibException("No Android SDK found.");
    }
    SessionParams.RenderingMode renderingMode;
    if (hasVerticalScroll && hasHorizontalScroll) {
        renderingMode = SessionParams.RenderingMode.FULL_EXPAND;
    } else if (hasVerticalScroll) {
        renderingMode = SessionParams.RenderingMode.V_SCROLL;
    } else if (hasHorizontalScroll) {
        renderingMode = SessionParams.RenderingMode.H_SCROLL;
    } else {
        renderingMode = SessionParams.RenderingMode.NORMAL;
    }
    return create(facet, platform, module.getProject(), configuration, parser, backgroundColor, renderingMode, true);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)48 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 IOException (java.io.IOException)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 File (java.io.File)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 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)3 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)3 SourceProvider (com.android.builder.model.SourceProvider)2