use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class FmHasDependencyMethod method exec.
@Override
public TemplateModel exec(List args) throws TemplateModelException {
if (args.size() < 1 || args.size() > 2) {
throw new TemplateModelException("Wrong arguments");
}
String artifact = ((TemplateScalarModel) args.get(0)).getAsString();
if (artifact.isEmpty()) {
return TemplateBooleanModel.FALSE;
}
// Determine the configuration to check, based on the second argument passed to the function. Defaults to "compile".
String configuration = SdkConstants.GRADLE_COMPILE_CONFIGURATION;
if (args.size() > 1) {
configuration = ((TemplateScalarModel) args.get(1)).getAsString();
}
if (myParamMap.containsKey(TemplateMetadata.ATTR_DEPENDENCIES_MULTIMAP)) {
Object untyped = myParamMap.get(TemplateMetadata.ATTR_DEPENDENCIES_MULTIMAP);
if (untyped instanceof SetMultimap) {
@SuppressWarnings("unchecked") SetMultimap<String, String> dependencies = (SetMultimap<String, String>) untyped;
for (String dependency : dependencies.get(configuration)) {
if (dependency.contains(artifact)) {
return TemplateBooleanModel.TRUE;
}
}
}
}
// Find the corresponding module, if any
String modulePath = (String) myParamMap.get(TemplateMetadata.ATTR_PROJECT_OUT);
if (modulePath != null) {
Module module = FmUtil.findModule(modulePath);
if (module != null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
// TODO: b/23032990
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
boolean dependsOn;
switch(configuration) {
case SdkConstants.GRADLE_COMPILE_CONFIGURATION:
dependsOn = GradleUtil.dependsOn(androidModel, artifact);
break;
case SdkConstants.GRADLE_ANDROID_TEST_COMPILE_CONFIGURATION:
dependsOn = GradleUtil.dependsOnAndroidTest(androidModel, artifact);
break;
default:
throw new TemplateModelException("Unknown dependency configuration " + configuration);
}
return dependsOn ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
}
}
}
// created project will return true since it will be by virtue of appcompat also being installed.)
if (artifact.contains(SdkConstants.APPCOMPAT_LIB_ARTIFACT) || artifact.contains(SdkConstants.SUPPORT_LIB_ARTIFACT)) {
// No dependencies: Base it off of the minApi and buildApi versions:
// If building with Lollipop, and targeting anything earlier than Lollipop, use appcompat.
// (Also use it if minApi is less than ICS.)
Object buildApiObject = myParamMap.get(TemplateMetadata.ATTR_BUILD_API);
Object minApiObject = myParamMap.get(TemplateMetadata.ATTR_MIN_API_LEVEL);
if (buildApiObject instanceof Integer && minApiObject instanceof Integer) {
int buildApi = (Integer) buildApiObject;
int minApi = (Integer) minApiObject;
return minApi >= 8 && ((buildApi >= 21 && minApi < 21) || minApi < 14) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
}
return TemplateBooleanModel.FALSE;
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class AndroidPluginGeneration method find.
@Nullable
public static AndroidPluginGeneration find(@NotNull Module module) {
AndroidModuleModel gradleModel = AndroidModuleModel.get(module);
if (gradleModel != null) {
try {
// only true for experimental plugin 0.6.0-betaX (or whenever the getPluginGeneration() was added) or later.
return gradleModel.getAndroidProject().getPluginGeneration() == GENERATION_COMPONENT ? COMPONENT : ORIGINAL;
} catch (UnsupportedMethodException t) {
// happens for 2.0.0-alphaX or earlier stable version plugins and 0.6.0-alphax or earlier experimental plugin versions.
}
}
// Now look at the applied plugins in the build.gradle file.
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
List<String> appliedPlugins = getValues(buildModel.appliedPlugins());
for (AndroidPluginGeneration generation : ourValues) {
if (appliedPlugins.contains(generation.getApplicationPluginId()) || appliedPlugins.contains(generation.getLibraryPluginId())) {
return generation;
}
}
}
return null;
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class ManifestPanel method describePosition.
private void describePosition(@NotNull HtmlBuilder sb, @NotNull AndroidFacet facet, @NotNull SourceFilePosition sourceFilePosition) {
SourceFile sourceFile = sourceFilePosition.getFile();
SourcePosition sourcePosition = sourceFilePosition.getPosition();
File file = sourceFile.getSourceFile();
if (file == GRADLE_MODEL_MARKER_FILE) {
VirtualFile gradleBuildFile = GradleUtil.getGradleBuildFile(facet.getModule());
if (gradleBuildFile != null) {
file = VfsUtilCore.virtualToIoFile(gradleBuildFile);
sb.addHtml("<a href=\"");
sb.add(file.toURI().toString());
sb.addHtml("\">");
sb.add(file.getName());
sb.addHtml("</a>");
sb.add(" injection");
} else {
sb.add("build.gradle injection (source location unknown)");
}
return;
}
AndroidLibrary library;
if (file != null) {
String source = null;
Module libraryModule = null;
Module[] modules = ModuleManager.getInstance(facet.getModule().getProject()).getModules();
VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vFile != null) {
Module module = ModuleUtilCore.findModuleForFile(vFile, facet.getModule().getProject());
if (module != null) {
if (modules.length >= 2) {
source = module.getName();
}
// AAR Library?
if (file.getPath().contains(EXPLODED_AAR)) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel != null) {
library = GradleUtil.findLibrary(file.getParentFile(), androidModel.getSelectedVariant(), androidModel.getModelVersion());
if (library != null) {
if (library.getProject() != null) {
libraryModule = GradleUtil.findModuleByGradlePath(facet.getModule().getProject(), library.getProject());
if (libraryModule != null) {
module = libraryModule;
source = module.getName();
} else {
source = library.getProject();
source = StringUtil.trimStart(source, ":");
}
} else {
MavenCoordinates coordinates = library.getResolvedCoordinates();
source = /*coordinates.getGroupId() + ":" +*/
coordinates.getArtifactId() + ":" + coordinates.getVersion();
}
}
}
}
}
IdeaSourceProvider provider = ManifestUtils.findManifestSourceProvider(facet, vFile);
if (provider != null) /*&& !provider.equals(facet.getMainIdeaSourceProvider())*/
{
String providerName = provider.getName();
if (source == null) {
source = providerName;
} else {
// "the app main manifest" - "app" is the module name, "main" is the source provider name
source = source + " " + providerName;
}
}
}
if (source == null) {
source = file.getName();
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
source += ":" + String.valueOf(sourcePosition);
}
}
sb.addHtml("<a href=\"");
boolean redirected = false;
if (libraryModule != null) {
AndroidFacet libraryFacet = AndroidFacet.getInstance(libraryModule);
if (libraryFacet != null) {
File manifestFile = libraryFacet.getMainSourceProvider().getManifestFile();
if (manifestFile.exists()) {
sb.add(manifestFile.toURI().toString());
redirected = true;
// Line numbers probably aren't right
sourcePosition = SourcePosition.UNKNOWN;
// TODO: Set URL which points to the element/attribute path
}
}
}
if (!redirected) {
sb.add(file.toURI().toString());
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartLine()));
sb.add(":");
sb.add(String.valueOf(sourcePosition.getStartColumn()));
}
}
sb.addHtml("\">");
sb.add(source);
sb.addHtml("</a>");
sb.add(" manifest");
if (FileUtil.filesEqual(file, VfsUtilCore.virtualToIoFile(myFile))) {
sb.add(" (this file)");
}
if (!SourcePosition.UNKNOWN.equals(sourcePosition)) {
sb.add(", line ");
sb.add(Integer.toString(sourcePosition.getStartLine()));
}
}
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class PostProjectBuildTasksExecutor method excludeOutputFolders.
private static void excludeOutputFolders(@NotNull AndroidFacet facet) {
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel == null) {
return;
}
File buildFolderPath = androidModel.getAndroidProject().getBuildFolder();
if (!buildFolderPath.isDirectory()) {
return;
}
Module module = facet.getModule();
if (module.getProject().isDisposed()) {
return;
}
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
try {
ContentEntry[] contentEntries = rootModel.getContentEntries();
ContentEntry parent = findParentContentEntry(buildFolderPath, contentEntries);
if (parent == null) {
rootModel.dispose();
return;
}
List<File> excludedFolderPaths = androidModel.getExcludedFolderPaths();
for (File folderPath : excludedFolderPaths) {
parent.addExcludeFolder(pathToIdeaUrl(folderPath));
}
} finally {
if (!rootModel.isDisposed()) {
rootModel.commit();
}
}
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class PostProjectBuildTasksExecutor method getMaxJavaLangLevel.
@VisibleForTesting
@Nullable
LanguageLevel getMaxJavaLangLevel() {
LanguageLevel maxLangLevel = null;
Module[] modules = ModuleManager.getInstance(myProject).getModules();
for (Module module : modules) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
continue;
}
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
LanguageLevel langLevel = androidModel.getJavaLanguageLevel();
if (langLevel != null && (maxLangLevel == null || maxLangLevel.compareTo(langLevel) < 0)) {
maxLangLevel = langLevel;
}
}
}
return maxLangLevel;
}
Aggregations