use of com.android.builder.model.Variant in project android by JetBrains.
the class AndroidGradleProjectResolver method populateModuleContentRoots.
@Override
public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
ImportedModule importedModule = new ImportedModule(gradleModule);
ideModule.createChild(IMPORTED_MODULE, importedModule);
GradleProject gradleProject = gradleModule.getGradleProject();
GradleScript buildScript = null;
try {
buildScript = gradleProject.getBuildScript();
} catch (UnsupportedOperationException ignore) {
}
if (buildScript == null || !isAndroidGradleProject()) {
nextResolver.populateModuleContentRoots(gradleModule, ideModule);
return;
}
// do not derive module root dir based on *.iml file location
File moduleRootDirPath = new File(toSystemDependentName(ideModule.getData().getLinkedExternalProjectPath()));
AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
boolean androidProjectWithoutVariants = false;
String moduleName = gradleModule.getName();
if (androidProject != null) {
Variant selectedVariant = myVariantSelector.findVariantToSelect(androidProject);
if (selectedVariant == null) {
// If an Android project does not have variants, it would be impossible to build. This is a possible but invalid use case.
// For now we are going to treat this case as a Java library module, because everywhere in the IDE (e.g. run configurations,
// editors, test support, variants tool window, project building, etc.) we have the assumption that there is at least one variant
// per Android project, and changing that in the code base is too risky, for very little benefit.
// See https://code.google.com/p/android/issues/detail?id=170722
androidProjectWithoutVariants = true;
} else {
String variantName = selectedVariant.getName();
AndroidModuleModel model = new AndroidModuleModel(moduleName, moduleRootDirPath, androidProject, variantName);
ideModule.createChild(ANDROID_MODEL, model);
}
}
NativeAndroidProject nativeAndroidProject = resolverCtx.getExtraProject(gradleModule, NativeAndroidProject.class);
if (nativeAndroidProject != null) {
NdkModuleModel ndkModuleModel = new NdkModuleModel(moduleName, moduleRootDirPath, nativeAndroidProject);
ideModule.createChild(NDK_MODEL, ndkModuleModel);
}
File gradleSettingsFile = new File(moduleRootDirPath, FN_SETTINGS_GRADLE);
if (gradleSettingsFile.isFile() && androidProject == null && nativeAndroidProject == null) {
// This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
// compile it using Gradle. We still need to create the module to display files inside it.
createJavaProject(gradleModule, ideModule, false);
return;
}
BuildScriptClasspathModel buildScriptModel = resolverCtx.getExtraProject(BuildScriptClasspathModel.class);
String gradleVersion = buildScriptModel != null ? buildScriptModel.getGradleVersion() : null;
File buildFilePath = buildScript.getSourceFile();
GradleModuleModel gradleModuleModel = new GradleModuleModel(moduleName, gradleProject, buildFilePath, gradleVersion);
ideModule.createChild(GRADLE_MODULE_MODEL, gradleModuleModel);
if (nativeAndroidProject == null && (androidProject == null || androidProjectWithoutVariants)) {
// This is a Java lib module.
createJavaProject(gradleModule, ideModule, androidProjectWithoutVariants);
}
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class VariantSelectorTest method findVariantToSelectWithoutDebugVariant.
@Test
public void findVariantToSelectWithoutDebugVariant() {
Variant aVariant = mock(Variant.class);
Variant bVariant = mock(Variant.class);
when(myAndroidProject.getVariants()).thenReturn(Lists.newArrayList(bVariant, aVariant));
when(aVariant.getName()).thenReturn("a");
when(bVariant.getName()).thenReturn("b");
Variant variant = myVariantSelector.findVariantToSelect(myAndroidProject);
assertSame(aVariant, variant);
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class AndroidGradleClassJarProvider method getCompilerOutputRoot.
@Nullable
private static VirtualFile getCompilerOutputRoot(@NotNull AndroidModuleModel model) {
Variant variant = model.getSelectedVariant();
String variantName = variant.getName();
AndroidArtifact mainArtifactInfo = model.getMainArtifact();
File classesFolder = mainArtifactInfo.getClassesFolder();
//noinspection ConstantConditions
if (classesFolder == null) {
// For getOutput()
@SuppressWarnings("deprecation") AndroidArtifactOutput output = GradleUtil.getOutput(mainArtifactInfo);
File file = output.getMainOutputFile().getOutputFile();
File buildFolder = file.getParentFile().getParentFile();
// See AndroidContentRoot
classesFolder = new File(buildFolder, "classes");
}
File outFolder = new File(classesFolder, // Change variant name variant-release into variant/release directories
variantName.replace('-', File.separatorChar));
if (outFolder.exists()) {
return VfsUtil.findFileByIoFile(outFolder, true);
}
return null;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class AppResourceRepository method getResourceVisibility.
@NotNull
public ResourceVisibilityLookup getResourceVisibility(@NotNull AndroidFacet facet) {
// TODO: b/23032391
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
if (provider != null) {
AndroidProject androidProject = androidModel.getAndroidProject();
Variant variant = androidModel.getSelectedVariant();
return provider.get(androidProject, variant);
}
}
return ResourceVisibilityLookup.NONE;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class CompilerOutputModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
GradleVersion modelVersion = androidModel.getModelVersion();
if (modelVersion == null) {
// We are dealing with old model that does not have the 'class' folder.
return;
}
Variant selectedVariant = androidModel.getSelectedVariant();
File mainClassesFolder = selectedVariant.getMainArtifact().getClassesFolder();
JavaArtifact testArtifact = androidModel.getUnitTestArtifactInSelectedVariant();
File testClassesFolder = testArtifact == null ? null : testArtifact.getClassesFolder();
ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
myCompilerSettingsSetup.setOutputPaths(rootModel, mainClassesFolder, testClassesFolder);
}
Aggregations