use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ThemeEditorUtils method getModuleThemeQualifiedNamesList.
/**
* Returns the list of the qualified names of all the user-defined themes available from a given module
*/
@NotNull
public static ImmutableList<String> getModuleThemeQualifiedNamesList(@NotNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
ConfigurationManager manager = facet.getConfigurationManager();
// We create a new ResourceResolverCache instead of using cache from myConfiguration to optimize memory instead of time/speed,
// because we are about to create a lot of instances of ResourceResolver here that won't be used outside of this method
final ResourceResolverCache resolverCache = new ResourceResolverCache(manager);
final IAndroidTarget target = manager.getTarget();
final Map<ResourceValue, Boolean> cache = new HashMap<ResourceValue, Boolean>();
final Set<String> themeNamesSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
ResourceFolderVisitor visitor = new ResourceFolderVisitor() {
@Override
public void visitResourceFolder(@NotNull LocalResourceRepository resources, String moduleName, @NotNull String variantName, boolean isSelected) {
if (!isSelected) {
return;
}
for (String simpleThemeName : resources.getItemsOfType(ResourceType.STYLE)) {
String themeStyleResourceUrl = SdkConstants.STYLE_RESOURCE_PREFIX + simpleThemeName;
List<ResourceItem> themeItems = resources.getResourceItem(ResourceType.STYLE, simpleThemeName);
assert themeItems != null;
for (ResourceItem themeItem : themeItems) {
ResourceResolver resolver = resolverCache.getResourceResolver(target, themeStyleResourceUrl, themeItem.getConfiguration());
ResourceValue themeItemResourceValue = themeItem.getResourceValue(false);
assert themeItemResourceValue != null;
if (resolver.isTheme(themeItemResourceValue, cache)) {
themeNamesSet.add(simpleThemeName);
break;
}
}
}
}
};
acceptResourceResolverVisitor(facet, visitor);
return ImmutableList.copyOf(themeNamesSet);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ThemeEditorUtils method getMinApiLevel.
public static int getMinApiLevel(@NotNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return 1;
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
return moduleInfo.getMinSdkVersion().getApiLevel();
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ThemeEditorUtils method acceptResourceResolverVisitor.
/**
* Visits every ResourceFolderRepository. It visits every resource in order, meaning that the later calls may override resources from
* previous ones.
*/
public static void acceptResourceResolverVisitor(@NotNull final AndroidFacet mainFacet, @NotNull final ResourceFolderVisitor visitor) {
// Get all the dependencies of the module in reverse order (first one is the lowest priority one)
List<AndroidFacet> dependencies = Lists.reverse(AndroidUtils.getAllAndroidDependencies(mainFacet.getModule(), true));
// The order of iteration here is important since the resources from the mainFacet will override those in the dependencies.
for (AndroidFacet dependency : Iterables.concat(dependencies, ImmutableList.of(mainFacet))) {
AndroidModuleModel androidModel = AndroidModuleModel.get(dependency);
if (androidModel == null) {
// For non gradle module, get the main source provider
SourceProvider provider = dependency.getMainSourceProvider();
for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), true);
}
} else {
// For gradle modules, get all source providers and go through them
// We need to iterate the providers in the returned to make sure that they correctly override each other
List<SourceProvider> activeProviders = androidModel.getActiveSourceProviders();
for (SourceProvider provider : activeProviders) {
for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), true);
}
}
// Not go through all the providers that are not in the activeProviders
ImmutableSet<SourceProvider> selectedProviders = ImmutableSet.copyOf(activeProviders);
for (SourceProvider provider : androidModel.getAllSourceProviders()) {
if (!selectedProviders.contains(provider)) {
for (LocalResourceRepository resourceRepository : getResourceFolderRepositoriesFromSourceSet(dependency, provider)) {
visitor.visitResourceFolder(resourceRepository, dependency.getName(), provider.getName(), false);
}
}
}
}
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class DrawableRendererEditor method configureRenderTask.
@NotNull
public static RenderTask configureRenderTask(@NotNull final Module module, @NotNull final Configuration configuration) {
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
final RenderService service = RenderService.get(facet);
RenderTask task = service.createTask(null, configuration, DRAWABLE_RENDER_LOGGER, null);
assert task != null;
return task;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class GradleBuildInvoker method findAndAddGradleBuildTasks.
private static void findAndAddGradleBuildTasks(@NotNull Module module, @NotNull BuildMode buildMode, @NotNull List<String> tasks, @NotNull TestCompileType testCompileType) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
return;
}
String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
if (isEmpty(gradlePath)) {
// Gradle project path is never, ever null. If the path is empty, it shows as ":". We had reports of this happening. It is likely that
// users manually added the Android-Gradle facet to a project. After all it is likely not to be a Gradle module. Better quit and not
// build the module.
String msg = String.format("Module '%1$s' does not have a Gradle path. It is likely that this module was manually added by the user.", module.getName());
getLogger().info(msg);
return;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null) {
JpsAndroidModuleProperties properties = androidFacet.getProperties();
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
switch(buildMode) {
// Intentional fall-through.
case CLEAN:
case SOURCE_GEN:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
break;
case ASSEMBLE:
tasks.add(createBuildTask(gradlePath, properties.ASSEMBLE_TASK_NAME));
// Add assemble tasks for tests.
if (testCompileType != TestCompileType.NONE) {
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getAssembleTaskName());
}
}
break;
default:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
// no *.class files and would be just a waste of time.
if (testCompileType != TestCompileType.UNIT_TESTS) {
addTaskIfSpecified(tasks, gradlePath, properties.COMPILE_JAVA_TASK_NAME);
}
// Add compile tasks for tests.
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getCompileTaskName());
}
break;
}
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet != null && javaFacet.getConfiguration().BUILDABLE) {
String gradleTaskName = javaFacet.getGradleTaskName(buildMode);
if (gradleTaskName != null) {
tasks.add(createBuildTask(gradlePath, gradleTaskName));
}
if (testCompileType == TestCompileType.UNIT_TESTS) {
tasks.add(createBuildTask(gradlePath, JavaFacet.TEST_CLASSES_TASK_NAME));
}
}
}
}
Aggregations