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"));
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class TestArtifactSearchScopes method resolveDependencies.
@VisibleForTesting
void resolveDependencies() {
AndroidModuleModel androidModel = getAndroidModel();
if (androidModel == null || alreadyResolved) {
return;
}
mainDependencies = extractMainDependencies(androidModel);
androidTestDependencies = extractAndroidTestDependencies(androidModel);
unitTestDependencies = extractUnitTestDependencies(androidModel);
// mainDependencies' mainDependencies should be merged to own mainDependencies, others shouldn't be merged
mergeSubmoduleDependencies(mainDependencies, mainDependencies, null, null);
// androidTestDependencies' mainDependencies and androidTestDependencies should be merged to own androidTestDependencies, others
// shouldn't be merged
mergeSubmoduleDependencies(androidTestDependencies, androidTestDependencies, androidTestDependencies, null);
// unitTestDependencies' mainDependencies and unitTestDependencies should be merged to own unitTestDependencies, others shouldn't be
// merged
mergeSubmoduleDependencies(unitTestDependencies, unitTestDependencies, null, unitTestDependencies);
alreadyResolved = true;
}
Aggregations