use of com.android.annotations.VisibleForTesting in project atlas by alibaba.
the class BasePlugin method createAndroidTasks.
@VisibleForTesting
final void createAndroidTasks(boolean force) {
// Make sure unit tests set the required fields.
checkState(extension.getBuildToolsRevision() != null, "buildToolsVersion is not specified.");
checkState(extension.getCompileSdkVersion() != null, "compileSdkVersion is not specified.");
ndkHandler.setCompileSdkVersion(extension.getCompileSdkVersion());
// get current plugins and look for the default Java plugin.
if (project.getPlugins().hasPlugin(JavaPlugin.class)) {
throw new BadPluginException("The 'java' plugin has been applied, but it is not compatible with the Android plugins.");
}
ensureTargetSetup();
// See AppPluginDslTest
if (!force && (!project.getState().getExecuted() || project.getState().getFailure() != null) && SdkHandler.sTestSdkFolder == null) {
return;
}
if (hasCreatedTasks) {
return;
}
hasCreatedTasks = true;
extension.disableWrite();
ProcessRecorder.getProject(project.getPath()).setBuildToolsVersion(extension.getBuildToolsRevision().toString());
// setup SDK repositories.
sdkHandler.addLocalRepositories(project);
taskManager.addDataBindingDependenciesIfNecessary(extension.getDataBinding());
addDependencies(project);
ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_CREATE_ANDROID_TASKS, project.getPath(), null, new Recorder.Block<Void>() {
@Override
public Void call() throws Exception {
variantManager.createAndroidTasks();
ApiObjectFactory apiObjectFactory = new ApiObjectFactory(androidBuilder, extension, variantFactory, instantiator);
for (BaseVariantData variantData : variantManager.getVariantDataList()) {
apiObjectFactory.create(variantData);
}
return null;
}
});
// Create and read external native build JSON files depending on what's happening right
// now.
//
// CREATE PHASE:
// Creates JSONs by shelling out to external build system when:
// - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
// AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
// - *and* AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL is set
// or JSON files don't exist or are out-of-date.
// Create phase may cause ProcessException (from cmake.exe for example)
//
// READ PHASE:
// Reads and deserializes JSONs when:
// - Any one of AndroidProject.PROPERTY_INVOKED_FROM_IDE,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY_ADVANCED,
// AndroidProject.PROPERTY_BUILD_MODEL_ONLY,
// AndroidProject.PROPERTY_REFRESH_EXTERNAL_NATIVE_MODEL are set.
// Read phase may produce IOException if the file can't be read for standard IO reasons.
// Read phase may produce JsonSyntaxException in the case that the content of the file is
// corrupt.
boolean forceRegeneration = AndroidGradleOptions.refreshExternalNativeModel(project);
if (ExternalNativeBuildTaskUtils.shouldRegenerateOutOfDateJsons(project)) {
ThreadRecorder.get().record(ExecutionType.VARIANT_MANAGER_EXTERNAL_NATIVE_CONFIG_VALUES, project.getPath(), null, new Recorder.Block<Void>() {
@Override
public Void call() throws Exception {
for (BaseVariantData variantData : variantManager.getVariantDataList()) {
ExternalNativeJsonGenerator generator = variantData.getScope().getExternalNativeJsonGenerator();
if (generator != null) {
// This will generate any out-of-date or non-existent JSONs.
// When refreshExternalNativeModel() is true it will also
// force update all JSONs.
generator.build(forceRegeneration);
variantData.getScope().addExternalNativeBuildConfigValues(generator.readExistingNativeBuildConfigurations());
}
}
return null;
}
});
}
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class IconPreviewFactory method load.
/**
* Load preview images for each component into a file cache.
* Each combination of theme, device density, and API level will have its own cache.
*
* @param configuration a hardware configuration to generate previews for
* @param palette a palette with the components to generate previews of
* @param reload if true replace the existing preview images
* @param requestedIds for testing only: gather the IDs of the components whose previews were requested
* @param generatedIds for testing only: gather the IDs of the components whose preview images where generated
* @return true if the images were loaded, false if they already existed
*/
@VisibleForTesting
boolean load(@NotNull final Configuration configuration, @NotNull final Palette palette, boolean reload, @Nullable final List<String> requestedIds, @Nullable final List<String> generatedIds) {
File cacheDir = getPreviewCacheDirForConfiguration(configuration);
String[] files = cacheDir.list();
if (files != null && files.length > 0) {
// The previews have already been generated.
if (!reload) {
return false;
}
FileUtil.delete(cacheDir);
}
ApplicationManager.getApplication().runReadAction(new Computable<Void>() {
@Override
public Void compute() {
List<StringBuilder> sources = Lists.newArrayList();
loadSources(sources, requestedIds, palette.getItems());
for (StringBuilder source : sources) {
String preview = String.format(LINEAR_LAYOUT, CONTAINER_ID, source);
addResultToCache(renderImage(myExecutorService, myRenderTimeoutSeconds, getRenderTask(configuration), preview), generatedIds, configuration);
}
return null;
}
});
return true;
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class ModuleResourceRepository method createForTest.
@NotNull
@VisibleForTesting
public static ModuleResourceRepository createForTest(@NotNull AndroidFacet facet, @NotNull Collection<VirtualFile> resourceDirectories, @NotNull Collection<LocalResourceRepository> otherDelegates) {
assert ApplicationManager.getApplication().isUnitTestMode();
List<LocalResourceRepository> delegates = new ArrayList<LocalResourceRepository>(resourceDirectories.size() + otherDelegates.size());
for (VirtualFile resourceDirectory : resourceDirectories) {
delegates.add(ResourceFolderRegistry.get(facet, resourceDirectory));
}
delegates.addAll(otherDelegates);
return new ModuleResourceRepository(facet, delegates);
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class ViewLoader method loadAndParseRClass.
@VisibleForTesting
void loadAndParseRClass(@NotNull String className) throws ClassNotFoundException, InconvertibleClassError {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("loadAndParseRClass(%s)", anonymizeClassName(className)));
}
Class<?> aClass = myLoadedClasses.get(className);
AppResourceRepository appResources = AppResourceRepository.getAppResources(myModule, true);
if (aClass == null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" The R class is not loaded.");
}
final ModuleClassLoader moduleClassLoader = getModuleClassLoader();
final boolean isClassLoaded = moduleClassLoader.isClassLoaded(className);
aClass = moduleClassLoader.loadClass(className);
if (!isClassLoaded && aClass != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format(" Class found in module %s, first time load.", anonymize(myModule)));
}
// This is the first time we've found the resources. The dynamic R classes generated for aar libraries are now stale and must be
// regenerated. Clear the ModuleClassLoader and reload the R class.
myLoadedClasses.clear();
ModuleClassLoader.clearCache(myModule);
myModuleClassLoader = null;
aClass = getModuleClassLoader().loadClass(className);
if (appResources != null) {
appResources.resetDynamicIds(true);
}
} else {
if (LOG.isDebugEnabled()) {
if (isClassLoaded) {
LOG.debug(String.format(" Class already loaded in module %s.", anonymize(myModule)));
}
}
}
if (aClass != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" Class loaded");
}
assert myLogger != null;
myLoadedClasses.put(className, aClass);
myLogger.setHasLoadedClasses(true);
}
}
if (aClass != null) {
final Map<ResourceType, TObjectIntHashMap<String>> res2id = new EnumMap<>(ResourceType.class);
final TIntObjectHashMap<Pair<ResourceType, String>> id2res = new TIntObjectHashMap<>();
final Map<IntArrayWrapper, String> styleableId2res = new HashMap<>();
if (parseClass(aClass, id2res, styleableId2res, res2id)) {
if (appResources != null) {
appResources.setCompiledResources(id2res, styleableId2res, res2id);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("END loadAndParseRClass(%s)", anonymizeClassName(className)));
}
}
use of com.android.annotations.VisibleForTesting in project android by JetBrains.
the class AvdDisplayList method getScreenSize.
/**
* @return the device screen size of this AVD
*/
@VisibleForTesting
static Dimension getScreenSize(@NotNull AvdInfo info) {
DeviceManagerConnection deviceManager = DeviceManagerConnection.getDefaultDeviceManagerConnection();
Device device = deviceManager.getDevice(info.getDeviceName(), info.getDeviceManufacturer());
if (device == null) {
return null;
}
return device.getScreenSize(device.getDefaultState().getOrientation());
}
Aggregations