use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class SdkModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
File androidSdkHomePath = IdeSdks.getInstance().getAndroidSdkPath();
// Android SDK may be not configured in IntelliJ
if (androidSdkHomePath == null) {
assert !IdeInfo.getInstance().isAndroidStudio();
logAndroidSdkHomeNotFound();
return;
}
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
LanguageLevel languageLevel = androidModel.getJavaLanguageLevel();
if (languageLevel != null) {
moduleModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class).setLanguageLevel(languageLevel);
}
AndroidProject androidProject = androidModel.getAndroidProject();
String compileTarget = androidProject.getCompileTarget();
Sdk sdk = myAndroidSdks.findSuitableAndroidSdk(compileTarget);
if (sdk == null) {
sdk = myAndroidSdks.tryToCreate(androidSdkHomePath, compileTarget);
if (sdk == null) {
// If SDK was not created, this might be an add-on.
sdk = findMatchingSdkForAddon(androidProject);
}
}
if (sdk == null) {
showPlatformNotFoundError(module, compileTarget);
return;
}
moduleModel.setSdk(sdk);
String sdkPath = sdk.getHomePath();
if (sdkPath == null) {
sdkPath = "<path not set>";
}
getLog().info(String.format("Set Android SDK '%1$s' (%2$s) to module '%3$s'", sdk.getName(), sdkPath, module.getName()));
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class AndroidGradleProjectResolver method createModule.
@Override
@NotNull
public DataNode<ModuleData> createModule(@NotNull IdeaModule gradleModule, @NotNull DataNode<ProjectData> projectDataNode) {
AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
if (androidProject != null && !isSupportedVersion(androidProject)) {
AndroidStudioEvent.Builder event = AndroidStudioEvent.newBuilder();
// @formatter:off
event.setCategory(GRADLE_SYNC).setKind(GRADLE_SYNC_FAILURE).setGradleSyncFailure(UNSUPPORTED_ANDROID_MODEL_VERSION).setGradleVersion(androidProject.getModelVersion());
// @formatter:on
UsageTracker.getInstance().log(event);
String msg = getUnsupportedModelVersionErrorMsg(getModelVersion(androidProject));
throw new IllegalStateException(msg);
}
if (isAndroidGradleProject()) {
return doCreateModule(gradleModule, projectDataNode);
} else {
return nextResolver.createModule(gradleModule, projectDataNode);
}
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class ModuleVariantsInfoDialog method createDependentsTree.
@NotNull
private static JTree createDependentsTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
Object data = ((DefaultMutableTreeNode) value).getUserObject();
if (data instanceof String) {
appendVariant((String) data);
} else if (data instanceof DependentTreeElement) {
DependentTreeElement dependent = (DependentTreeElement) data;
String variant = null;
if (!dependent.myVariants.isEmpty()) {
variant = Joiner.on(", ").join(dependent.myVariants);
}
appendModule(dependent.myModule, variant);
}
}
}
};
//noinspection ConstantConditions
CheckedTreeNode root = new CheckedTreeNode(null);
AndroidProject androidProject = GradleUtil.getAndroidProject(module);
assert androidProject != null;
String gradlePath = GradleUtil.getGradlePath(module);
assert gradlePath != null;
Multimap<String, DependentTreeElement> dependentsByVariant = HashMultimap.create();
ModuleManager moduleManager = ModuleManager.getInstance(module.getProject());
for (Module dependent : moduleManager.getModuleDependentModules(module)) {
AndroidProject dependentProject = GradleUtil.getAndroidProject(dependent);
if (dependentProject == null) {
continue;
}
DependentTreeElement element = new DependentTreeElement(dependent);
for (Variant variant : dependentProject.getVariants()) {
for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
if (gradlePath.equals(library.getProject())) {
element.addVariant(variant.getName());
String projectVariant = library.getProjectVariant();
if (StringUtil.isNotEmpty(projectVariant)) {
dependentsByVariant.put(projectVariant, element);
}
}
}
}
}
List<String> variantNames = Lists.newArrayList(dependentsByVariant.keySet());
Collections.sort(variantNames);
for (String variantName : variantNames) {
Collection<DependentTreeElement> dependents = dependentsByVariant.get(variantName);
if (!dependents.isEmpty()) {
List<DependentTreeElement> sortedDependents = Lists.newArrayList(dependents);
Collections.sort(sortedDependents);
DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
for (DependentTreeElement dependent : dependents) {
variantNode.add(new DefaultMutableTreeNode(dependent));
}
root.add(variantNode);
}
}
CheckboxTree tree = new CheckboxTree(renderer, root);
tree.setRootVisible(false);
TreeUtil.expandAll(tree);
return tree;
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class ExportSignedPackageTest method ignore_testNoFlavors.
// ignored: http://b.android.com/226579
public void ignore_testNoFlavors() {
AndroidProject androidProject = getAndroidProject("no_flavors");
assertNotNull(androidProject);
// debug and release
assertEquals(2, androidProject.getVariants().size());
List<String> assembleTasks = ExportSignedPackageWizard.getAssembleTasks("", androidProject, "release", Collections.<String>emptyList());
assertEquals(1, assembleTasks.size());
assertEquals(":assembleRelease", assembleTasks.get(0));
}
use of com.android.builder.model.AndroidProject in project android by JetBrains.
the class ExportSignedPackageTest method getAndroidProject.
/**
* Returns the {@link com.android.builder.model.AndroidProject} given the gradle project root.
* Note that this works only single module projects (only one build.gradle)
*/
@Nullable
private static AndroidProject getAndroidProject(String projectPath) {
File androidPlugin = new File(AndroidTestBase.getAndroidPluginHome());
File projectDir = new File(androidPlugin, BASE_PATH + projectPath);
GradleConnector connector = GradleConnector.newConnector();
connector.forProjectDirectory(projectDir);
connector.useDistribution(new DistributionLocator().getDistributionFor(GradleVersion.version("2.2.1")));
AndroidProject model = null;
ProjectConnection connection = connector.connect();
try {
model = connection.getModel(AndroidProject.class);
} finally {
connection.close();
}
return model;
}
Aggregations