use of com.android.builder.model.Variant in project android by JetBrains.
the class GradleSignStep method _init.
@Override
public void _init() {
myAndroidModel = AndroidModuleModel.get(myWizard.getFacet());
PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
String lastSelectedBuildType = properties.getValue(PROPERTY_BUILD_TYPE);
myBuildTypeComboModel.removeAllElements();
Set<String> buildTypes = myAndroidModel == null ? Collections.<String>emptySet() : myAndroidModel.getBuildTypes();
for (String buildType : buildTypes) {
myBuildTypeComboModel.addElement(buildType);
if ((lastSelectedBuildType == null && buildType.equals("release")) || buildType.equals(lastSelectedBuildType)) {
myBuildTypeComboModel.setSelectedItem(buildType);
}
}
myFlavorsListModel.clear();
List<String> productFlavors;
if (myAndroidModel == null || myAndroidModel.getProductFlavors().isEmpty()) {
productFlavors = Collections.emptyList();
} else {
// if there are multiple flavors, we want the merged flavor list
Set<String> mergedFlavors = Sets.newHashSet();
for (Variant v : myAndroidModel.getAndroidProject().getVariants()) {
mergedFlavors.add(ExportSignedPackageWizard.getMergedFlavorName(v));
}
productFlavors = Lists.newArrayList(mergedFlavors);
Collections.sort(productFlavors);
}
TIntArrayList lastSelectedIndices = new TIntArrayList(productFlavors.size());
String[] flavors = properties.getValues(PROPERTY_FLAVORS);
Set<String> lastSelectedFlavors = flavors == null ? Collections.<String>emptySet() : Sets.newHashSet(flavors);
for (int i = 0; i < productFlavors.size(); i++) {
String flavor = productFlavors.get(i);
myFlavorsListModel.addElement(flavor);
if (lastSelectedFlavors.contains(flavor)) {
lastSelectedIndices.add(i);
}
}
myFlavorsList.setSelectedIndices(lastSelectedIndices.toNativeArray());
String lastApkFolderPath = properties.getValue(PROPERTY_APK_PATH);
File lastApkFolder;
if (lastApkFolderPath != null) {
lastApkFolder = new File(lastApkFolderPath);
} else {
if (myAndroidModel == null) {
lastApkFolder = VfsUtilCore.virtualToIoFile(myWizard.getProject().getBaseDir());
} else {
lastApkFolder = myAndroidModel.getRootDirPath();
}
}
myApkPathField.setText(lastApkFolder.getAbsolutePath());
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
myApkPathField.addBrowseFolderListener("Select APK Destination Folder", null, myWizard.getProject(), descriptor);
GradleVersion modelVersion = null;
if (myAndroidModel != null) {
modelVersion = myAndroidModel.getModelVersion();
}
boolean enabled = modelVersion != null && modelVersion.compareIgnoringQualifiers(MIN_SIGNATURE_SELECTION_VERSION) >= 0;
myV1JarSignatureCheckBox.setEnabled(enabled);
myV1JarSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V1_SIGN));
myV2FullAPKSignatureCheckBox.setEnabled(enabled);
myV2FullAPKSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V2_SIGN));
// Set HTML label here; the visual editor does not like the " " part so set the text here.
mySignatureHelpLabel.setText("<html><a href=\"\">Signature Help</a></html>");
mySignatureHelpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
mySignatureHelpLabel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri;
try {
uri = new URI("http://developer.android.com/about/versions/nougat/android-7.0.html#apk_signature_v2");
} catch (URISyntaxException ex) {
throw new AssertionError(ex);
}
try {
desktop.browse(uri);
} catch (IOException ex) {
LOG.error("Failed to open URI '" + uri + "'", ex);
}
}
}
}
});
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class ProjectProfileSelectionDialog method createProjectStructureTree.
private void createProjectStructureTree() {
CheckboxTree.CheckboxTreeCellRenderer renderer = new CheckboxTree.CheckboxTreeCellRenderer() {
@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();
ColoredTreeCellRenderer textRenderer = getTextRenderer();
if (data instanceof ModuleTreeElement) {
ModuleTreeElement moduleElement = (ModuleTreeElement) data;
textRenderer.append(moduleElement.myModule.getName());
if (!moduleElement.myConflicts.isEmpty()) {
boolean allResolved = true;
for (Conflict conflict : moduleElement.myConflicts) {
if (!conflict.isResolved()) {
allResolved = false;
break;
}
}
SimpleTextAttributes attributes = allResolved ? UNRESOLVED_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
textRenderer.append(" ");
textRenderer.append(myConflicts.size() == 1 ? "[Conflict]" : "[Conflicts]", attributes);
}
textRenderer.setIcon(AllIcons.Actions.Module);
} else if (data instanceof String) {
textRenderer.append((String) data, SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES);
textRenderer.setIcon(AndroidIcons.Variant);
} else if (data instanceof DependencyTreeElement) {
DependencyTreeElement dependency = (DependencyTreeElement) data;
textRenderer.append(dependency.myModule.getName());
if (!StringUtil.isEmpty(dependency.myVariant)) {
textRenderer.append(" (" + dependency.myVariant + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
Icon icon = dependency.myConflict != null ? AllIcons.RunConfigurations.TestFailed : AllIcons.RunConfigurations.TestPassed;
textRenderer.setIcon(icon);
}
}
}
};
CheckedTreeNode rootNode = new FilterAwareCheckedTreeNode(null);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module[] modules = moduleManager.getModules();
Arrays.sort(modules, ModulesAlphaComparator.INSTANCE);
Map<String, Module> modulesByGradlePath = Maps.newHashMap();
for (Module module : modules) {
String gradlePath = GradleUtil.getGradlePath(module);
if (StringUtil.isEmpty(gradlePath)) {
// We always want to include it, therefore we don't give users a chance to uncheck it in the "Project Structure" pane.
continue;
}
modulesByGradlePath.put(gradlePath, module);
ModuleTreeElement moduleElement = new ModuleTreeElement(module);
CheckedTreeNode moduleNode = new FilterAwareCheckedTreeNode(moduleElement);
rootNode.add(moduleNode);
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel == null) {
continue;
}
Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();
for (Variant variant : androidModel.getAndroidProject().getVariants()) {
for (AndroidLibrary library : getDirectLibraryDependencies(variant, androidModel)) {
gradlePath = library.getProject();
if (gradlePath == null) {
continue;
}
Module dependency = modulesByGradlePath.get(gradlePath);
if (dependency == null) {
dependency = GradleUtil.findModuleByGradlePath(myProject, gradlePath);
}
if (dependency == null) {
continue;
}
Conflict conflict = getConflict(dependency);
modulesByGradlePath.put(gradlePath, dependency);
DependencyTreeElement dependencyElement = new DependencyTreeElement(dependency, gradlePath, library.getProjectVariant(), conflict);
dependenciesByVariant.put(variant.getName(), dependencyElement);
}
}
List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet());
Collections.sort(variantNames);
List<String> consolidatedVariants = Lists.newArrayList();
List<String> variantsToSkip = Lists.newArrayList();
int variantCount = variantNames.size();
for (int i = 0; i < variantCount; i++) {
String variant1 = variantNames.get(i);
if (variantsToSkip.contains(variant1)) {
continue;
}
Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1);
for (int j = i + 1; j < variantCount; j++) {
String variant2 = variantNames.get(j);
Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2);
if (set1.equals(set2)) {
variantsToSkip.add(variant2);
if (!consolidatedVariants.contains(variant1)) {
consolidatedVariants.add(variant1);
}
consolidatedVariants.add(variant2);
}
}
String variantName = variant1;
if (!consolidatedVariants.isEmpty()) {
variantName = Joiner.on(", ").join(consolidatedVariants);
}
DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
moduleNode.add(variantNode);
List<DependencyTreeElement> dependencyElements = Lists.newArrayList(set1);
Collections.sort(dependencyElements);
for (DependencyTreeElement dependencyElement : dependencyElements) {
if (dependencyElement.myConflict != null) {
moduleElement.addConflict(dependencyElement.myConflict);
}
variantNode.add(new DefaultMutableTreeNode(dependencyElement));
}
consolidatedVariants.clear();
}
}
myProjectStructureTree = new CheckboxTreeView(renderer, rootNode) {
@Override
protected void onNodeStateChanged(@NotNull CheckedTreeNode node) {
Module module = null;
Object data = node.getUserObject();
if (data instanceof ModuleTreeElement) {
module = ((ModuleTreeElement) data).myModule;
}
if (module == null) {
return;
}
boolean updated = false;
Enumeration variantNodes = myConflictTree.myRoot.children();
while (variantNodes.hasMoreElements()) {
Object child = variantNodes.nextElement();
if (!(child instanceof CheckedTreeNode)) {
continue;
}
CheckedTreeNode variantNode = (CheckedTreeNode) child;
Enumeration moduleNodes = variantNode.children();
while (moduleNodes.hasMoreElements()) {
child = moduleNodes.nextElement();
if (!(child instanceof CheckedTreeNode)) {
continue;
}
CheckedTreeNode moduleNode = (CheckedTreeNode) child;
data = moduleNode.getUserObject();
if (!(data instanceof Conflict.AffectedModule)) {
continue;
}
Conflict.AffectedModule affected = (Conflict.AffectedModule) data;
boolean checked = node.isChecked();
if (module.equals(affected.getTarget()) && moduleNode.isChecked() != checked) {
affected.setSelected(checked);
moduleNode.setChecked(checked);
updated = true;
}
}
}
if (updated) {
repaintAll();
}
}
};
myProjectStructureTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myProjectStructureTree.setRootVisible(false);
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class ModuleVariantsInfoDialog method createDependenciesTree.
@NotNull
private static JTree createDependenciesTree(@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 DependencyTreeElement) {
DependencyTreeElement dependency = (DependencyTreeElement) data;
appendModule(dependency.myModule, dependency.myVariant);
}
}
}
};
//noinspection ConstantConditions
CheckedTreeNode root = new CheckedTreeNode(null);
AndroidProject androidProject = GradleUtil.getAndroidProject(module);
assert androidProject != null;
Multimap<String, DependencyTreeElement> dependenciesByVariant = HashMultimap.create();
for (Variant variant : androidProject.getVariants()) {
for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
String gradlePath = library.getProject();
if (gradlePath == null) {
continue;
}
Module dependency = GradleUtil.findModuleByGradlePath(module.getProject(), gradlePath);
if (dependency != null) {
DependencyTreeElement element = new DependencyTreeElement(dependency, library.getProjectVariant());
dependenciesByVariant.put(variant.getName(), element);
}
}
}
// Consolidate variants. This means if "debug" and "release" have the same dependencies, we show only one node as "debug, release".
List<String> variantNames = Lists.newArrayList(dependenciesByVariant.keySet());
Collections.sort(variantNames);
List<String> consolidatedVariants = Lists.newArrayList();
List<String> variantsToSkip = Lists.newArrayList();
int variantCount = variantNames.size();
for (int i = 0; i < variantCount; i++) {
String variant1 = variantNames.get(i);
if (variantsToSkip.contains(variant1)) {
continue;
}
Collection<DependencyTreeElement> set1 = dependenciesByVariant.get(variant1);
for (int j = i + 1; j < variantCount; j++) {
String variant2 = variantNames.get(j);
Collection<DependencyTreeElement> set2 = dependenciesByVariant.get(variant2);
if (set1.equals(set2)) {
variantsToSkip.add(variant2);
if (!consolidatedVariants.contains(variant1)) {
consolidatedVariants.add(variant1);
}
consolidatedVariants.add(variant2);
}
}
String variantName = variant1;
if (!consolidatedVariants.isEmpty()) {
variantName = Joiner.on(", ").join(consolidatedVariants);
}
DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
root.add(variantNode);
List<DependencyTreeElement> dependencies = Lists.newArrayList(set1);
Collections.sort(dependencies);
for (DependencyTreeElement dependency : dependencies) {
variantNode.add(new DefaultMutableTreeNode(dependency));
}
consolidatedVariants.clear();
}
CheckboxTree tree = new CheckboxTree(renderer, root);
tree.setRootVisible(false);
TreeUtil.expandAll(tree);
return tree;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class GradleApkProvider method getApks.
@Override
@NotNull
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
if (androidModel == null) {
LOG.warn("Android model is null. Sync might have failed");
return Collections.emptyList();
}
Variant selectedVariant = androidModel.getSelectedVariant();
List<ApkInfo> apkList = Lists.newArrayList();
// install apk (note that variant.getOutputFile() will point to a .aar in the case of a library)
int projectType = androidModel.getProjectType();
if (projectType == PROJECT_TYPE_APP || projectType == PROJECT_TYPE_INSTANTAPP) {
File apk = getApk(selectedVariant, device);
apkList.add(new ApkInfo(apk, myApplicationIdProvider.getPackageName()));
}
if (myTest) {
AndroidArtifact testArtifactInfo = androidModel.getAndroidTestArtifactInSelectedVariant();
if (testArtifactInfo != null) {
AndroidArtifactOutput output = GradleUtil.getOutput(testArtifactInfo);
File testApk = output.getMainOutputFile().getOutputFile();
String testPackageName = myApplicationIdProvider.getTestPackageName();
// Cannot be null if initialized.
assert testPackageName != null;
apkList.add(new ApkInfo(testApk, testPackageName));
}
if (androidModel.getFeatures().isTestedTargetVariantsSupported()) {
apkList.addAll(0, getTargetedApks(selectedVariant, device));
}
}
return apkList;
}
use of com.android.builder.model.Variant in project android by JetBrains.
the class GradleApplicationIdProvider method getTestPackageName.
@Override
public String getTestPackageName() throws ApkProvisionException {
AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
// This is a Gradle project, there must be an AndroidGradleModel.
assert androidModel != null;
// In the case of Gradle projects, either the merged flavor provides a test package name,
// or we just append ".test" to the source package name
Variant selectedVariant = androidModel.getSelectedVariant();
String testPackageName = selectedVariant.getMergedFlavor().getTestApplicationId();
return (testPackageName != null) ? testPackageName : getPackageName() + DEFAULT_TEST_PACKAGE_SUFFIX;
}
Aggregations