use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.
the class AddAndroidActivityPath method getDirectories.
private Map<String, Object> getDirectories() {
Map<String, Object> templateParameters = Maps.newHashMap();
Module module = getModule();
assert module != null;
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
}
// Read minSdkVersion and package from manifest and/or build.gradle files
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
AndroidModel androidModel = facet.getAndroidModel();
SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
if (sourceProvider1 != null && androidModel != null) {
String packageName = myState.get(KEY_PACKAGE_NAME);
assert packageName != null;
templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
}
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
String minSdkName = minSdkVersion.getApiString();
templateParameters.put(ATTR_MIN_API, minSdkName);
templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
try {
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
} catch (Exception e) {
LOG.info("Could not compute SHA1 hash of debug keystore.", e);
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
}
@SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
Project project = getProject();
assert project != null;
templateParameters.put(projectLocation, project.getBasePath());
// We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
// name as its containing project.
String moduleName = new File(module.getModuleFilePath()).getParentFile().getName();
templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
return templateParameters;
}
use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.
the class AndroidXmlSpellcheckingStrategy method inEnglish.
/**
* @return {@code true} if the given element is in an XML file that is in an English resource. Manifest files are considered to be in
* English, as are resources in base folders (unless a locale is explicitly defined on the root element).
*/
private static boolean inEnglish(PsiElement element) {
XmlFile file = PsiTreeUtil.getParentOfType(element, XmlFile.class);
if (file != null) {
String name = file.getName();
if (name.equals(ANDROID_MANIFEST_XML)) {
return true;
} else if (name.equals("generated.xml")) {
// Android Studio Workaround for issue https://code.google.com/p/android/issues/detail?id=76715
// If this a generated file like this:
// ${project}/${module}/build/generated/res/generated/{test?}/${flavors}/${build-type}/values/generated.xml
// ? If so, skip it.
AndroidFacet facet = AndroidFacet.getInstance(file);
VirtualFile virtualFile = file.getVirtualFile();
if (facet != null && facet.requiresAndroidModel() && virtualFile != null) {
AndroidModel androidModel = facet.getAndroidModel();
if (androidModel != null && androidModel.isGenerated(virtualFile)) {
return false;
}
}
} else if (isLintConfigElement(element)) {
// lint config file: should not be spell checked
return false;
}
PsiDirectory dir = file.getParent();
if (dir != null) {
String locale = LintUtils.getLocaleAndRegion(dir.getName());
if (locale == null) {
locale = getToolsLocale(file);
}
return locale == null || locale.startsWith("en") || locale.equals("b+en") || locale.startsWith("b+en+");
}
}
return false;
}
use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.
the class ModuleClassLoader method getExternalJars.
@Override
protected List<URL> getExternalJars() {
final Module module = myModuleReference.get();
if (module == null) {
return Collections.emptyList();
}
final List<URL> result = new ArrayList<>();
if (ThemeEditorProvider.THEME_EDITOR_ENABLE) {
URL customWidgetsUrl = ThemeEditorUtils.getCustomWidgetsJarUrl();
if (customWidgetsUrl != null) {
result.add(customWidgetsUrl);
}
}
List<VirtualFile> externalLibraries;
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && facet.requiresAndroidModel() && facet.getAndroidModel() != null) {
AndroidModel androidModel = facet.getAndroidModel();
externalLibraries = androidModel.getClassJarProvider().getModuleExternalLibraries(module);
} else {
externalLibraries = AndroidRootUtil.getExternalLibraries(module);
}
for (VirtualFile libFile : externalLibraries) {
if (EXT_JAR.equals(libFile.getExtension())) {
final File file = new File(libFile.getPath());
if (file.exists()) {
try {
result.add(SdkUtils.fileToUrl(file));
File aarDir = file.getParentFile();
if (aarDir != null && (aarDir.getPath().endsWith(DOT_AAR) || aarDir.getPath().contains(EXPLODED_AAR))) {
if (aarDir.getPath().contains(EXPLODED_AAR)) {
if (aarDir.getPath().endsWith(LIBS_FOLDER)) {
// Some libraries recently started packaging jars inside a sub libs folder inside jars
aarDir = aarDir.getParentFile();
}
// Gradle plugin version 1.2.x and later has classes in aar-dir/jars/
if (aarDir.getPath().endsWith(FD_JARS)) {
aarDir = aarDir.getParentFile();
}
}
AppResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
if (appResources != null) {
ResourceClassRegistry.get(module.getProject()).addAarLibrary(appResources, aarDir);
}
} else if (aarDir != null) {
// Build cache? We need to compute the package name in a slightly different way
File parentFile = aarDir.getParentFile();
if (parentFile != null) {
File manifest = new File(parentFile, ANDROID_MANIFEST_XML);
if (manifest.exists()) {
AppResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
if (appResources != null) {
FileResourceRepository repository = appResources.findRepositoryFor(parentFile);
if (repository != null) {
ResourceClassRegistry registry = ResourceClassRegistry.get(module.getProject());
registry.addLibrary(appResources, registry.getAarPackage(parentFile));
}
}
}
}
}
} catch (MalformedURLException e) {
LOG.error(e);
}
}
}
}
return result;
}
use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.
the class LintIdeProject method createModuleProject.
/** Creates a new module project */
@Nullable
private static LintModuleProject createModuleProject(@NonNull LintClient client, @NonNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
File dir = getLintProjectDirectory(module, facet);
if (dir == null)
return null;
LintModuleProject project = null;
if (facet == null) {
project = new LintModuleProject(client, dir, dir, module);
AndroidFacet f = findAndroidFacetInProject(module.getProject());
if (f != null) {
project.gradleProject = f.requiresAndroidModel();
}
} else if (facet.requiresAndroidModel()) {
AndroidModel androidModel = facet.getAndroidModel();
if (androidModel instanceof AndroidModuleModel) {
project = new LintGradleProject(client, dir, dir, facet, (AndroidModuleModel) androidModel);
} else {
project = new LintAndroidModelProject(client, dir, dir, facet, androidModel);
}
} else {
project = new LintAndroidProject(client, dir, dir, facet);
}
if (project != null) {
client.registerProject(dir, project);
}
return project;
}
use of com.android.tools.idea.model.AndroidModel in project kotlin by JetBrains.
the class IntellijLintUtils method getResourceDirectories.
/** Returns the resource directories to use for the given module */
@NotNull
public static List<File> getResourceDirectories(@NotNull AndroidFacet facet) {
if (facet.requiresAndroidModel()) {
AndroidModel androidModel = facet.getAndroidModel();
if (androidModel != null) {
List<File> resDirectories = new ArrayList<File>();
List<SourceProvider> sourceProviders = androidModel.getActiveSourceProviders();
for (SourceProvider provider : sourceProviders) {
for (File file : provider.getResDirectories()) {
if (file.isDirectory()) {
resDirectories.add(file);
}
}
}
return resDirectories;
}
}
return new ArrayList<File>(facet.getMainSourceProvider().getResDirectories());
}
Aggregations