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);
}
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);
}
}
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);
}
}
}
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());
}
}
}
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"));
}
Aggregations