com.android.repository.api
Class RepoManager

java.lang.Object
  extended by com.android.repository.api.RepoManager
Direct Known Subclasses:
RepoManagerImpl

public abstract class RepoManager
extends java.lang.Object

Primary interface for interacting with repository packages. To set up an RepoManager:

To load the local and remote packages, use load(long, List, List, List, boolean, ProgressRunner, Downloader, SettingsController, boolean)
TODO: it would be nice if this could be redesigned such that load didn't need to be called explicitly, or there was a better way to know if packages were or need to be loaded.

To use the loaded packages, get an RepositoryPackages object from getPackages().


Nested Class Summary
static interface RepoManager.RepoLoadedCallback
          Callback for when repository load is completed/partially completed.
 
Field Summary
static long DEFAULT_EXPIRATION_PERIOD_MS
          After loading the repository, this is the amount of time that must pass before we consider it to be stale and need to be reloaded.
 
Constructor Summary
RepoManager()
           
 
Method Summary
static RepoManager create(FileOp fop)
           
abstract  SchemaModule getCommonModule()
          Gets the core SchemaModule created by the RepoManager itself.
abstract  java.io.File getLocalPath()
          Gets the path to the local repository root.
abstract  RepositoryPackages getPackages()
          Gets the currently-loaded RepositoryPackages.
abstract  org.w3c.dom.ls.LSResourceResolver getResourceResolver(ProgressIndicator progress)
          Gets an LSResourceResolver that can find the XSDs for all versions of the currently-registered SchemaModules by namespace.
abstract  java.util.Set<SchemaModule> getSchemaModules()
          Gets the currently-registered SchemaModules.
abstract  java.util.Set<RepositorySourceProvider> getSourceProviders()
          Gets the currently registered RepositorySourceProviders.
abstract  java.util.Set<RepositorySource> getSources(Downloader downloader, SettingsController settings, ProgressIndicator progress, boolean forceRefresh)
          Gets the actual RepositorySources from the registered RepositorySourceProviders.
abstract  boolean load(long cacheExpirationMs, java.util.List<RepoManager.RepoLoadedCallback> onLocalComplete, java.util.List<RepoManager.RepoLoadedCallback> onSuccess, java.util.List<java.lang.Runnable> onError, boolean forceRefresh, ProgressRunner runner, Downloader downloader, SettingsController settings, boolean sync)
          Load the local and remote repositories.
abstract  void markInvalid()
          Causes cached results to be considered expired.
abstract  void registerSchemaModule(SchemaModule module)
          Register an SchemaModule that can be used when parsing XML for this repo.
abstract  void registerSourceProvider(RepositorySourceProvider provider)
          Adds a RepositorySourceProvider from which to get RepositorySources from which to download lists of available repository packages.
abstract  void setFallbackLocalRepoLoader(FallbackLocalRepoLoader local)
          Sets the FallbackLocalRepoLoader to use when scanning the local repository for packages.
abstract  void setFallbackRemoteRepoLoader(FallbackRemoteRepoLoader remote)
          Sets the FallbackRemoteRepoLoader to try when we encounter a remote xml file that the RepoManger can't read.
abstract  void setLocalPath(java.io.File path)
          Sets the path to the local repository root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION_PERIOD_MS

public static final long DEFAULT_EXPIRATION_PERIOD_MS
After loading the repository, this is the amount of time that must pass before we consider it to be stale and need to be reloaded.

Constructor Detail

RepoManager

public RepoManager()
Method Detail

create

@NonNull
public static RepoManager create(@NonNull
                                         FileOp fop)
Parameters:
fop - The FileOp to use for local filesystem operations. Probably FileOpUtils.create() unless part of a unit test.
Returns:
A new RepoManager.

registerSchemaModule

public abstract void registerSchemaModule(@NonNull
                                          SchemaModule module)
Register an SchemaModule that can be used when parsing XML for this repo.


getSchemaModules

@NonNull
public abstract java.util.Set<SchemaModule> getSchemaModules()
Gets the currently-registered SchemaModules. This probably shouldn't be used except by code within the RepoManager or unit tests.


getCommonModule

@NonNull
public abstract SchemaModule getCommonModule()
Gets the core SchemaModule created by the RepoManager itself. Contains the base definition of repository, package, revision, etc.


setLocalPath

public abstract void setLocalPath(@Nullable
                                  java.io.File path)
Sets the path to the local repository root.


getLocalPath

@Nullable
public abstract java.io.File getLocalPath()
Gets the path to the local repository root. This probably shouldn't be needed except by the repository manager and unit tests.


setFallbackLocalRepoLoader

public abstract void setFallbackLocalRepoLoader(@Nullable
                                                FallbackLocalRepoLoader local)
Sets the FallbackLocalRepoLoader to use when scanning the local repository for packages.


registerSourceProvider

public abstract void registerSourceProvider(@NonNull
                                            RepositorySourceProvider provider)
Adds a RepositorySourceProvider from which to get RepositorySources from which to download lists of available repository packages.


getSourceProviders

@NonNull
public abstract java.util.Set<RepositorySourceProvider> getSourceProviders()
Gets the currently registered RepositorySourceProviders. Should only be needed for testing.


getSources

public abstract java.util.Set<RepositorySource> getSources(@Nullable
                                                           Downloader downloader,
                                                           @Nullable
                                                           SettingsController settings,
                                                           @NonNull
                                                           ProgressIndicator progress,
                                                           boolean forceRefresh)
Gets the actual RepositorySources from the registered RepositorySourceProviders. Probably should only be needed by a repository UI.

Parameters:
downloader - The Downloader to use for downloading source lists, if needed.
settings - The settings to use when downloading or reading source lists.
progress - A ProgressIndicator for source providers to use to show their progress and for logging.
forceRefresh - Individual RepositorySourceProviders may cache their results. If forceRefresh is true, specifies that they should reload rather than returning cached results.
Returns:
The RepositorySources obtained from the providers.

setFallbackRemoteRepoLoader

public abstract void setFallbackRemoteRepoLoader(@Nullable
                                                 FallbackRemoteRepoLoader remote)
Sets the FallbackRemoteRepoLoader to try when we encounter a remote xml file that the RepoManger can't read.


load

public abstract boolean load(long cacheExpirationMs,
                             @NonNull
                             java.util.List<RepoManager.RepoLoadedCallback> onLocalComplete,
                             @NonNull
                             java.util.List<RepoManager.RepoLoadedCallback> onSuccess,
                             @NonNull
                             java.util.List<java.lang.Runnable> onError,
                             boolean forceRefresh,
                             @NonNull
                             ProgressRunner runner,
                             @Nullable
                             Downloader downloader,
                             @Nullable
                             SettingsController settings,
                             boolean sync)
Load the local and remote repositories. In callbacks, be careful of invoking tasks synchronously on other threads (e.g. the swing ui thread), since they might also be used by the {@link ProgressRunner) passed in.

Parameters:
cacheExpirationMs - How long must have passed since the last load for us to reload even if forceRefresh isn't specified.
onLocalComplete - When loading, the local repo load happens first, and should be relatively fast. When complete, the onLocalComplete RepoManager.RepoLoadedCallbacks are run. Will be called with a RepositoryPackages that contains only the local packages.
onSuccess - Callbacks that are run when the entire load (local and remote) has completed successfully. Called with an RepositoryPackages containing both the local and remote packages.
onError - Callbacks that are run when there's an error at some point during the load.
forceRefresh - If true, reload the local and remote packages even if cacheExpirationMs has not passed.
runner - The ProgressRunner to use for any tasks started during the load, including running the callbacks.
downloader - The Downloader to use for downloading remote files, including any remote list of repo sources and the remote repositories themselves.
settings - The settings to use during the load, including for example proxy settings used when fetching remote files.
sync - If true, load synchronously. If false, load asynchronously (this method should return quickly, and the onSuccess callbacks can be used to process the completed results).
Returns:
true if a load was performed. false if cached results were fresh enough.

markInvalid

public abstract void markInvalid()
Causes cached results to be considered expired. The next time load(long, List, List, List, boolean, ProgressRunner, Downloader, SettingsController, boolean) is called, a complete load will be done.


getPackages

@NonNull
public abstract RepositoryPackages getPackages()
Gets the currently-loaded RepositoryPackages.


getResourceResolver

@NonNull
public abstract org.w3c.dom.ls.LSResourceResolver getResourceResolver(@NonNull
                                                                              ProgressIndicator progress)
Gets an LSResourceResolver that can find the XSDs for all versions of the currently-registered SchemaModules by namespace.