Search in sources :

Example 26 with AndroidPlatform

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

the class AndroidSdksTest method testCreateSdk.

public void testCreateSdk() {
    IAndroidTarget target = findAndroidTarget();
    String name = "testSdk";
    Sdk sdk = myAndroidSdks.create(target, mySdkPath, name, myJdk, true);
    assertNotNull(sdk);
    assertEquals(name, sdk.getName());
    verifyCorrectPath(sdk);
    AndroidSdkAdditionalData androidData = getAndroidSdkAdditionalData(sdk);
    assertSame(myJdk, androidData.getJavaSdk());
    AndroidPlatform androidPlatform = androidData.getAndroidPlatform();
    assertNotNull(androidPlatform);
    assertSame(target, androidPlatform.getTarget());
    File platformPath = new File(mySdkPath, join("platforms", androidData.getBuildTargetHashString()));
    // Check roots added to SDK
    Map<String, VirtualFile> classRootsByName = getSdkRootsByName(sdk, CLASSES);
    // android.jar and res folder
    assertThat(classRootsByName).hasSize(2);
    VirtualFile androidJar = classRootsByName.get("android.jar");
    File expectedAndroidJarPath = new File(platformPath, androidJar.getName());
    assertAbout(file()).that(virtualToIoFile(androidJar)).isEquivalentAccordingToCompareTo(expectedAndroidJarPath);
    VirtualFile resFolder = classRootsByName.get("res");
    File expectedResFolderPath = new File(platformPath, join("data", resFolder.getName()));
    assertAbout(file()).that(virtualToIoFile(resFolder)).isEquivalentAccordingToCompareTo(expectedResFolderPath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetHash.getTargetHashString(com.android.sdklib.AndroidTargetHash.getTargetHashString) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 27 with AndroidPlatform

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

the class IdeSdksTest method assertOneSdkPerAvailableTarget.

private void assertOneSdkPerAvailableTarget(@NotNull List<Sdk> sdks) {
    List<IAndroidTarget> platformTargets = Lists.newArrayList();
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(myAndroidSdkPath);
    assertNotNull(sdkData);
    for (IAndroidTarget target : sdkData.getTargets()) {
        if (target.isPlatform()) {
            platformTargets.add(target);
        }
    }
    assertEquals(platformTargets.size(), sdks.size());
    for (Sdk sdk : sdks) {
        AndroidPlatform androidPlatform = AndroidPlatform.getInstance(sdk);
        assertNotNull(androidPlatform);
        IAndroidTarget target = androidPlatform.getTarget();
        platformTargets.remove(target);
    }
    assertEquals(0, platformTargets.size());
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 28 with AndroidPlatform

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

the class AndroidPreviewPanelTest method testSimpleRender.

public void testSimpleRender() throws ParserConfigurationException, IOException, SAXException, InterruptedException {
    VirtualFile layout = myFixture.copyFileToProject("themeEditor/theme_preview_layout.xml", "res/layout/theme_preview_layout.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(layout);
    AtomicBoolean executorCalled = new AtomicBoolean(false);
    ExecutorService threadPool = Executors.newFixedThreadPool(1);
    Executor executor = (r) -> {
        // Run in a separate thread and wait for the result
        try {
            threadPool.submit(r).get(60, TimeUnit.SECONDS);
            executorCalled.set(true);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            throw new AssertionError("Unexpected exception", e);
        }
    };
    AndroidPreviewPanel.GraphicsLayoutRendererFactory graphicsFactory = (configuration1, parser, background) -> {
        Module module = configuration.getModule();
        AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
        assertNotNull(facet);
        AndroidPlatform platform = AndroidPlatform.getInstance(module);
        assertNotNull(platform);
        return GraphicsLayoutRenderer.create(facet, platform, getProject(), configuration, parser, background, SessionParams.RenderingMode.V_SCROLL, false);
    };
    AndroidPreviewPanel panel = new AndroidPreviewPanel(configuration, executor, graphicsFactory) {

        @Override
        public void invalidateGraphicsRenderer() {
            myInvalidateRunnable.run();
        }
    };
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader("<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"" + "     android:layout_width=\"match_parent\"" + "     android:layout_height=\"match_parent\"" + "     android:background=\"#0F0\">" + "     <TextView" + "       android:layout_width=\"wrap_content\"" + "       android:layout_height=\"wrap_content\"" + "       android:text=\"Hello world\"" + "       android:background=\"#F00\"/>" + "</LinearLayout>")));
    panel.setDocument(document);
    panel.setBounds(0, 0, 400, 100);
    //noinspection UndesirableClassUsage (we don't want to use HDPI images here)
    BufferedImage output = new BufferedImage(400, 100, BufferedImage.TYPE_INT_ARGB);
    panel.paintComponent(output.getGraphics());
    // Make sure that the executor got called since we were trying to render on the UI thread.
    assertTrue(executorCalled.get());
    BufferedImage goldenImage = ImageIO.read(new File(getTestDataPath() + "/themeEditor/previewPanel/golden.png"));
    assertImageSimilar("layout", goldenImage, output, 3);
    ViewInfo textView = panel.findViewAtPoint(new Point(0, 0));
    assertEquals("android.widget.TextView", textView.getClassName());
    threadPool.shutdownNow();
    threadPool.awaitTermination(30, TimeUnit.SECONDS);
    Disposer.dispose(panel);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) InputSource(org.xml.sax.InputSource) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) BufferedImage(java.awt.image.BufferedImage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) java.util.concurrent(java.util.concurrent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IOException(java.io.IOException) File(java.io.File) ImageDiffUtil.assertImageSimilar(com.android.tools.adtui.imagediff.ImageDiffUtil.assertImageSimilar) java.awt(java.awt) SessionParams(com.android.ide.common.rendering.api.SessionParams) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) SAXException(org.xml.sax.SAXException) Disposer(com.intellij.openapi.util.Disposer) ImageIO(javax.imageio.ImageIO) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Module(com.intellij.openapi.module.Module) AndroidTestCase(org.jetbrains.android.AndroidTestCase) Configuration(com.android.tools.idea.configurations.Configuration) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Configuration(com.android.tools.idea.configurations.Configuration) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Document(org.w3c.dom.Document) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) BufferedImage(java.awt.image.BufferedImage) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringReader(java.io.StringReader) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 29 with AndroidPlatform

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

the class AndroidToolWindowFactory method checkFacetAndSdk.

private static void checkFacetAndSdk(Project project, @NotNull final ConsoleView console) {
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    if (facets.size() == 0) {
        console.clear();
        console.print(AndroidBundle.message("android.logcat.no.android.facets.error"), ConsoleViewContentType.ERROR_OUTPUT);
        return;
    }
    final AndroidFacet facet = facets.get(0);
    AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
    if (platform == null) {
        console.clear();
        final Module module = facet.getModule();
        if (!AndroidMavenUtil.isMavenizedModule(module)) {
            console.print("Please ", ConsoleViewContentType.ERROR_OUTPUT);
            console.printHyperlink("configure", new HyperlinkInfo() {

                @Override
                public void navigate(Project project) {
                    AndroidSdkUtils.openModuleDependenciesConfigurable(module);
                }
            });
            console.print(" Android SDK\n", ConsoleViewContentType.ERROR_OUTPUT);
        } else {
            console.print(AndroidBundle.message("android.maven.cannot.parse.android.sdk.error", module.getName()) + '\n', ConsoleViewContentType.ERROR_OUTPUT);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 30 with AndroidPlatform

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

the class AndroidModuleConverter1 method process.

@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
    Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
    assert confElement != null;
    Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
    String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
    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) {
            IAndroidTarget target = androidPlatform.getTarget();
            Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
            if (androidSdk == null) {
                androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
                if (androidSdk != null) {
                    final SdkModificator modificator = androidSdk.getSdkModificator();
                    for (OrderRootType type : OrderRootType.getAllTypes()) {
                        for (VirtualFile root : androidLibrary.getFiles(type)) {
                            modificator.addRoot(root, type);
                        }
                    }
                    modificator.commitChanges();
                }
            }
            if (androidSdk != null) {
                addNewDependency(moduleSettings, androidSdk.getName());
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderRootType(com.intellij.openapi.roots.OrderRootType) Element(org.jdom.Element) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Library(com.intellij.openapi.roots.libraries.Library) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

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