Search in sources :

Example 86 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project kotlin by JetBrains.

the class IntellijLintProject method findAndroidModule.

/** Find an Android module that depends on this module; prefer app modules over library modules */
@Nullable
private static Module findAndroidModule(@NonNull final Module module) {
    // Search for dependencies of this module
    Graph<Module> graph = ApplicationManager.getApplication().runReadAction(new Computable<Graph<Module>>() {

        @Override
        public Graph<Module> compute() {
            com.intellij.openapi.project.Project project = module.getProject();
            if (project.isDisposed()) {
                return null;
            }
            return ModuleManager.getInstance(project).moduleGraph();
        }
    });
    if (graph == null) {
        return null;
    }
    Set<AndroidFacet> facets = Sets.newHashSet();
    HashSet<Module> seen = Sets.newHashSet();
    seen.add(module);
    addAndroidModules(facets, seen, graph, module);
    // Prefer Android app modules
    for (AndroidFacet facet : facets) {
        if (!facet.isLibraryProject()) {
            return facet.getModule();
        }
    }
    // Resort to library modules if no app module depends directly on it
    if (!facets.isEmpty()) {
        return facets.iterator().next().getModule();
    }
    return null;
}
Also used : Project(com.android.tools.klint.detector.api.Project) Graph(com.intellij.util.graph.Graph) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 87 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project kotlin by JetBrains.

the class AndroidLintExternalAnnotator method collectInformation.

@Override
public State collectInformation(@NotNull PsiFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return null;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null && !IntellijLintProject.hasAndroidModule(module.getProject())) {
        return null;
    }
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) {
        return null;
    }
    final FileType fileType = file.getFileType();
    if (fileType == FileTypes.PLAIN_TEXT) {
        if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
            return null;
        }
    } else if (fileType != KotlinFileType.INSTANCE && fileType != StdFileTypes.PROPERTIES) {
        return null;
    }
    final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
    if (issues.size() == 0) {
        return null;
    }
    return new State(module, vFile, file.getText(), issues);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Issue(com.android.tools.klint.detector.api.Issue) KotlinFileType(org.jetbrains.kotlin.idea.KotlinFileType) FileType(com.intellij.openapi.fileTypes.FileType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 88 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class PostProjectBuildTasksExecutorTest method addAndroidFacet.

private static void addAndroidFacet(@NotNull Module module) {
    FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel facetModel = facetManager.createModifiableModel();
    try {
        AndroidFacet facet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
        facetModel.addFacet(facet);
    } finally {
        facetModel.commit();
    }
}
Also used : ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 89 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.

the class AndroidRunConfigurationSetupStepTest method testSetUpModuleWithAndroidFacetAndAppProject.

public void testSetUpModuleWithAndroidFacetAndAppProject() {
    Module module = getModule();
    AndroidFacet androidFacet = createAndAddAndroidFacet(module);
    androidFacet.getProperties().PROJECT_TYPE = PROJECT_TYPE_APP;
    mySetupStep.setUpModule(module, null);
    verify(myRunConfigurations).createRunConfiguration(androidFacet);
}
Also used : Module(com.intellij.openapi.module.Module) Facets.createAndAddAndroidFacet(com.android.tools.idea.testing.Facets.createAndAddAndroidFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 90 with AndroidFacet

use of org.jetbrains.android.facet.AndroidFacet 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)

Aggregations

AndroidFacet (org.jetbrains.android.facet.AndroidFacet)299 Module (com.intellij.openapi.module.Module)122 VirtualFile (com.intellij.openapi.vfs.VirtualFile)73 NotNull (org.jetbrains.annotations.NotNull)61 Nullable (org.jetbrains.annotations.Nullable)51 Project (com.intellij.openapi.project.Project)39 File (java.io.File)29 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)28 PsiFile (com.intellij.psi.PsiFile)24 XmlFile (com.intellij.psi.xml.XmlFile)20 PsiElement (com.intellij.psi.PsiElement)17 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)16 XmlTag (com.intellij.psi.xml.XmlTag)16 ArrayList (java.util.ArrayList)16 Manifest (org.jetbrains.android.dom.manifest.Manifest)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)13 ResourceFolderType (com.android.resources.ResourceFolderType)11 Configuration (com.android.tools.idea.configurations.Configuration)10 PsiClass (com.intellij.psi.PsiClass)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)10