mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
android artifacts: show "From module {0}" template if there is only 1 app module; do not show templates at all if there is no suitable modules
This commit is contained in:
+31
-18
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.android.compiler.artifact;
|
||||
|
||||
import com.intellij.facet.FacetModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.LibrarySourceItem;
|
||||
import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.ModuleOutputSourceItem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -58,47 +60,58 @@ public class AndroidApplicationArtifactType extends ArtifactType {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends ArtifactTemplate> getNewArtifactTemplates(@NotNull PackagingElementResolvingContext context) {
|
||||
return Collections.singletonList(new MyTemplate(context));
|
||||
final List<AndroidFacet> facets = new ArrayList<AndroidFacet>();
|
||||
|
||||
for (Module module : context.getModulesProvider().getModules()) {
|
||||
final FacetModel facetModel = context.getModulesProvider().getFacetModel(module);
|
||||
final AndroidFacet facet = facetModel.getFacetByType(AndroidFacet.ID);
|
||||
|
||||
if (facet != null && !facet.getConfiguration().LIBRARY_PROJECT) {
|
||||
facets.add(facet);
|
||||
}
|
||||
}
|
||||
|
||||
if (facets.size() == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(new MyTemplate(context.getProject(), facets));
|
||||
}
|
||||
|
||||
private class MyTemplate extends ArtifactTemplate {
|
||||
protected PackagingElementResolvingContext myContext;
|
||||
private final Project myProject;
|
||||
private final List<AndroidFacet> myFacets;
|
||||
|
||||
public MyTemplate(@NotNull PackagingElementResolvingContext context) {
|
||||
myContext = context;
|
||||
private MyTemplate(@NotNull Project project, @NotNull List<AndroidFacet> facets) {
|
||||
assert facets.size() > 0;
|
||||
myProject = project;
|
||||
myFacets = facets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "From module...";
|
||||
return myFacets.size() == 1
|
||||
? "From module '" + myFacets.get(0).getModule().getName() + "'"
|
||||
: "From module...";
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewArtifactConfiguration createArtifact() {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
|
||||
for (Module module : myContext.getModulesProvider().getModules()) {
|
||||
final AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
|
||||
if (facet != null && !facet.getConfiguration().LIBRARY_PROJECT) {
|
||||
modules.add(module);
|
||||
}
|
||||
}
|
||||
|
||||
final AndroidFacet facet = AndroidArtifactUtil.chooseAndroidApplicationModule(myContext.getProject(), modules);
|
||||
final AndroidFacet facet = myFacets.size() == 1
|
||||
? myFacets.get(0)
|
||||
: AndroidArtifactUtil.chooseAndroidApplicationModule(myProject, myFacets);
|
||||
if (facet == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final CompositePackagingElement<?> rootElement =
|
||||
AndroidApplicationArtifactType.this.createRootElement(facet.getModule().getName());
|
||||
rootElement.addFirstChild(new AndroidFinalPackageElement(myContext.getProject(), facet));
|
||||
rootElement.addFirstChild(new AndroidFinalPackageElement(myProject, facet));
|
||||
return new NewArtifactConfiguration(rootElement, facet.getModule().getName(), AndroidApplicationArtifactType.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUpArtifact(@NotNull Artifact artifact, @NotNull NewArtifactConfiguration configuration) {
|
||||
final AndroidFacet facet = AndroidArtifactUtil.getPackagedFacet(myContext.getProject(), artifact);
|
||||
final AndroidFacet facet = AndroidArtifactUtil.getPackagedFacet(myProject, artifact);
|
||||
|
||||
if (facet != null) {
|
||||
final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
|
||||
|
||||
+15
-5
@@ -18,12 +18,15 @@ import com.intellij.packaging.elements.PackagingElementResolvingContext;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
@@ -57,9 +60,16 @@ public class AndroidArtifactUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AndroidFacet chooseAndroidApplicationModule(@NotNull Project project, @NotNull List<Module> modules) {
|
||||
final ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, "Select Module",
|
||||
"Selected Android application module will be included in the created artifact with all dependencies");
|
||||
public static AndroidFacet chooseAndroidApplicationModule(@NotNull Project project,
|
||||
@NotNull List<AndroidFacet> facets) {
|
||||
final Map<Module, AndroidFacet> map = new HashMap<Module, AndroidFacet>();
|
||||
|
||||
for (AndroidFacet facet : facets) {
|
||||
map.put(facet.getModule(), facet);
|
||||
}
|
||||
String message = "Selected Android application module will be included in the created artifact with all dependencies";
|
||||
|
||||
final ChooseModulesDialog dialog = new ChooseModulesDialog(project, new ArrayList<Module>(map.keySet()), "Select Module", message);
|
||||
dialog.setSingleSelectionMode();
|
||||
dialog.show();
|
||||
final List<Module> selected = dialog.getChosenElements();
|
||||
@@ -70,9 +80,9 @@ public class AndroidArtifactUtil {
|
||||
final Module module = selected.get(0);
|
||||
final String moduleName = module.getName();
|
||||
|
||||
final AndroidFacet facet = AndroidFacet.getInstance(module);
|
||||
final AndroidFacet facet = map.get(module);
|
||||
if (facet == null) {
|
||||
final String message = "Cannot find Android facet for module " + moduleName;
|
||||
message = "Cannot find Android facet for module " + moduleName;
|
||||
Messages.showErrorDialog(project, message, CommonBundle.getErrorTitle());
|
||||
return null;
|
||||
}
|
||||
|
||||
+1
-12
@@ -14,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -56,24 +55,14 @@ public class AndroidFinalPackageElementType extends PackagingElementType<Android
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Module> facetsToModules(@NotNull Collection<AndroidFacet> facets) {
|
||||
final List<Module> result = new ArrayList<Module>(facets.size());
|
||||
for (AndroidFacet facet : facets) {
|
||||
result.add(facet.getModule());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends PackagingElement<?>> chooseAndCreate(@NotNull ArtifactEditorContext context,
|
||||
@NotNull Artifact artifact,
|
||||
@NotNull CompositePackagingElement<?> parent) {
|
||||
final List<AndroidFacet> facets = getAndroidApplicationFacets(context, context.getModulesProvider().getModules());
|
||||
final List<Module> modules = facetsToModules(facets);
|
||||
|
||||
final AndroidFacet facet = AndroidArtifactUtil.chooseAndroidApplicationModule(context.getProject(), modules);
|
||||
final AndroidFacet facet = AndroidArtifactUtil.chooseAndroidApplicationModule(context.getProject(), facets);
|
||||
if (facet == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user