Search in sources :

Example 26 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class AndroidRunConfigurationBase method getFastDeployDevices.

@Nullable
private static DeviceFutures getFastDeployDevices(@NotNull Executor executor, @NotNull AndroidFacet facet, @NotNull AndroidSessionInfo info) {
    if (!InstantRunSettings.isInstantRunEnabled()) {
        InstantRunManager.LOG.info("Instant run not enabled in settings");
        return null;
    }
    if (!info.getExecutorId().equals(executor.getId())) {
        String msg = String.format("Cannot Instant Run since old executor (%1$s) doesn't match current executor (%2$s)", info.getExecutorId(), executor.getId());
        InstantRunManager.LOG.info(msg);
        return null;
    }
    List<IDevice> devices = info.getDevices();
    if (devices == null || devices.isEmpty()) {
        InstantRunManager.LOG.info("Cannot Instant Run since we could not locate the devices from the existing launch session");
        return null;
    }
    if (devices.size() > 1) {
        InstantRunManager.LOG.info("Last run was on > 1 device, not reusing devices and prompting again");
        return null;
    }
    AndroidModuleModel model = AndroidModuleModel.get(facet);
    AndroidVersion version = devices.get(0).getVersion();
    InstantRunGradleSupport status = InstantRunGradleUtils.getIrSupportStatus(model, version);
    if (status != SUPPORTED) {
        InstantRunManager.LOG.info("Cannot Instant Run: " + status);
        return null;
    }
    return DeviceFutures.forDevices(devices);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) IDevice(com.android.ddmlib.IDevice) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, @NotNull JavaParameters javaParameters) {
    // Only patch if the project is a Gradle project.
    if (module == null || !isBuildWithGradle(module.getProject())) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
    if (testArtifact == null) {
        return;
    }
    PathsList classPath = javaParameters.getClassPath();
    TestArtifactSearchScopes testScopes = TestArtifactSearchScopes.get(module);
    if (testScopes == null) {
        return;
    }
    // Filter the library / module dependencies that are in android test
    FileRootSearchScope excludeScope = testScopes.getUnitTestExcludeScope();
    // complexity. TODO change the {@code PathList} API.
    for (String path : classPath.getPathList()) {
        if (excludeScope.accept(new File(path))) {
            classPath.remove(path);
        }
    }
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        return;
    }
    String originalClassPath = classPath.getPathsString();
    try {
        handlePlatformJar(classPath, platform, testArtifact);
        handleJavaResources(module, androidModel, classPath);
    } catch (RuntimeException e) {
        throw new RuntimeException(String.format("Error patching the JUnit class path. Original class path:%n%s", originalClassPath), e);
    }
}
Also used : JavaArtifact(com.android.builder.model.JavaArtifact) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) File(java.io.File)

Example 28 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class ExcludedRoots method addLibraryPaths.

private void addLibraryPaths(@NotNull Module module) {
    AndroidModuleModel model = AndroidModuleModel.get(module);
    if (model != null) {
        BaseArtifact exclude = myAndroidTest ? model.getUnitTestArtifactInSelectedVariant() : model.getAndroidTestArtifactInSelectedVariant();
        BaseArtifact include = myAndroidTest ? model.getAndroidTestArtifactInSelectedVariant() : model.getUnitTestArtifactInSelectedVariant();
        if (exclude != null) {
            addLibraryPaths(exclude, model);
        }
        if (include != null) {
            removeLibraryPaths(include, model);
        }
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel)

Example 29 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class ExcludedRoots method addFolderPathsFromExcludedModules.

private void addFolderPathsFromExcludedModules() {
    for (Module module : myExcludedModules) {
        ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
        for (ContentEntry entry : rootManager.getContentEntries()) {
            for (SourceFolder sourceFolder : entry.getSourceFolders()) {
                myExcludedRoots.add(urlToFilePath(sourceFolder.getUrl()));
            }
            CompilerModuleExtension compiler = rootManager.getModuleExtension(CompilerModuleExtension.class);
            String url = compiler.getCompilerOutputUrl();
            if (isNotEmpty(url)) {
                myExcludedRoots.add(urlToFilePath(url));
            }
        }
        AndroidModuleModel androidModuleModel = AndroidModuleModel.get(module);
        if (androidModuleModel != null) {
            myExcludedRoots.add(androidModuleModel.getMainArtifact().getJavaResourcesFolder());
        }
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Example 30 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.

the class AndroidTestRunConfiguration method supportsRunningLibraryProjects.

@Override
protected Pair<Boolean, String> supportsRunningLibraryProjects(@NotNull AndroidFacet facet) {
    if (!facet.requiresAndroidModel()) {
        // Non Gradle projects always require an application
        return Pair.create(Boolean.FALSE, AndroidBundle.message("android.cannot.run.library.project.error"));
    }
    // TODO: Resolve direct AndroidGradleModel dep (b/22596984)
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel == null) {
        return Pair.create(Boolean.FALSE, AndroidBundle.message("android.cannot.run.library.project.error"));
    }
    // Gradle only supports testing against a single build type (which could be anything, but is "debug" build type by default)
    // Currently, the only information the model exports that we can use to detect whether the current build type
    // is testable is by looking at the test task name and checking whether it is null.
    AndroidArtifact testArtifact = androidModel.getAndroidTestArtifactInSelectedVariant();
    String testTask = testArtifact != null ? testArtifact.getAssembleTaskName() : null;
    return new Pair<Boolean, String>(testTask != null, AndroidBundle.message("android.cannot.run.library.project.in.this.buildtype"));
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidArtifact(com.android.builder.model.AndroidArtifact) Pair(com.intellij.openapi.util.Pair)

Aggregations

AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)117 Module (com.intellij.openapi.module.Module)54 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)26 File (java.io.File)24 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)18 AndroidProject (com.android.builder.model.AndroidProject)12 GradleVersion (com.android.ide.common.repository.GradleVersion)11 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)10 Project (com.intellij.openapi.project.Project)9 Variant (com.android.builder.model.Variant)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 PsiFile (com.intellij.psi.PsiFile)5 AndroidArtifact (com.android.builder.model.AndroidArtifact)4 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)4 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)4 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 AndroidVersion (com.android.sdklib.AndroidVersion)3