Package com.android.repository.api
Class RepoManager
- java.lang.Object
-
- com.android.repository.api.RepoManager
-
- Direct Known Subclasses:
RepoManagerImpl
public abstract class RepoManager extends java.lang.ObjectPrimary interface for interacting with repository packages.To set up an
RepoManager:- Register the
SchemaModules used to parse the package.xml files and remote repositories used by this repo usingregisterSchemaModule(SchemaModule) - Set the path where the repo is installed locally using
setLocalPath(Path). - If your local repo might contain packages created by a previous system, set a
FallbackLocalRepoLoaderthat can recognize and convert those packages usingsetFallbackLocalRepoLoader(FallbackLocalRepoLoader). - Add
RepositorySourceProviders to provide URLs for remotely-available packages. - If some sources might be in a format used by a previous system, set a
FallbackRemoteRepoLoaderthat can read and convert them.
To load the local and remote packages, use
load(long, List, List, List, ProgressRunner, Downloader, SettingsController)
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
RepositoryPackagesobject fromgetPackages().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classRepoManager.DummyProgressRunnerstatic interfaceRepoManager.RepoLoadedListenerCallback for when repository load is completed/partially completed.
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_EXPIRATION_PERIOD_MSAfter 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
Constructors Constructor Description RepoManager()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddLocalChangeListener(RepoManager.RepoLoadedListener listener)Registers a listener that will be called whenever the local packages are reloaded and have changed.abstract voidaddRemoteChangeListener(RepoManager.RepoLoadedListener listener)Register a listener that will be called whenever the remote packages are reloaded and have changed.static RepoManagercreate()static SchemaModule<CommonFactory>getCommonModule()Gets the coreSchemaModulecreated by the RepoManager itself.static SchemaModule<GenericFactory>getGenericModule()Gets theSchemaModulecreated by the RepoManager that includes the trivial generictypeDetailstype.abstract PackageOperationgetInProgressInstallOperation(RepoPackage remotePackage)Gets the previously-registered installer that is currently installing the given package, ornullif there is none.abstract java.nio.file.PathgetLocalPath()Gets the path to the local repository root.abstract RepositoryPackagesgetPackages()Gets the currently-loadedRepositoryPackages.abstract org.w3c.dom.ls.LSResourceResolvergetResourceResolver(ProgressIndicator progress)Gets anLSResourceResolverthat can find the XSDs for all versions of the currently-registeredSchemaModules by namespace.abstract java.util.List<SchemaModule<?>>getSchemaModules()Gets the currently-registeredSchemaModules.abstract java.util.List<RepositorySourceProvider>getSourceProviders()Gets the currently registeredRepositorySourceProviders.abstract java.util.List<RepositorySource>getSources(Downloader downloader, ProgressIndicator progress, boolean forceRefresh)Gets the actualRepositorySources from the registeredRepositorySourceProviders.abstract voidinstallBeginning(RepoPackage repoPackage, PackageOperation installer)Record that the given package is in the process of being installed by the given installer.abstract voidinstallEnded(RepoPackage repoPackage)Record that the given package is no longer in the process of being installed (that is, install completed either successfully or unsuccessfully).abstract voidload(long cacheExpirationMs, java.util.List<RepoManager.RepoLoadedListener> onLocalComplete, java.util.List<RepoManager.RepoLoadedListener> onSuccess, java.util.List<java.lang.Runnable> onError, ProgressRunner runner, Downloader downloader, SettingsController settings)Loads the local and remote repositories asynchronously.booleanloadSynchronously(long cacheExpirationMs, ProgressIndicator progress, Downloader downloader, SettingsController settings)Loads the local and remote repositories synchronously.abstract voidloadSynchronously(long cacheExpirationMs, java.util.List<RepoManager.RepoLoadedListener> onLocalComplete, java.util.List<RepoManager.RepoLoadedListener> onSuccess, java.util.List<java.lang.Runnable> onError, ProgressRunner runner, Downloader downloader, SettingsController settings)Loads the local and remote repositories synchronously.abstract voidmarkInvalid()Causes cached results to be considered expired.abstract voidmarkLocalCacheInvalid()Causes the cached results of the local repositories to be considered expired.abstract voidregisterSchemaModule(SchemaModule<?> module)Register anSchemaModulethat can be used when parsing XML for this repo.abstract voidregisterSourceProvider(RepositorySourceProvider provider)Adds aRepositorySourceProviderfrom which to getRepositorySources from which to download lists of available repository packages.abstract booleanreloadLocalIfNeeded(ProgressIndicator progress)Check to see if there have been any changes to the local repo since the last load.abstract voidremoveLocalChangeListener(RepoManager.RepoLoadedListener listener)Removes the listener previously added by callingaddLocalChangeListener(com.android.repository.api.RepoManager.RepoLoadedListener).abstract voidremoveRemoteChangeListener(RepoManager.RepoLoadedListener listener)Removes the listener previously added by callingaddRemoteChangeListener(com.android.repository.api.RepoManager.RepoLoadedListener).abstract voidsetFallbackLocalRepoLoader(FallbackLocalRepoLoader local)Sets theFallbackLocalRepoLoaderto use when scanning the local repository for packages.abstract voidsetFallbackRemoteRepoLoader(FallbackRemoteRepoLoader remote)Sets theFallbackRemoteRepoLoaderto try when we encounter a remote xml file that the RepoManger can't read.abstract voidsetLocalPath(java.nio.file.Path path)Sets the path to the local repository root.
-
-
-
Method Detail
-
create
@NonNull public static RepoManager create()
- Returns:
- A new
RepoManager.
-
registerSchemaModule
public abstract void registerSchemaModule(@NonNull SchemaModule<?> module)Register anSchemaModulethat can be used when parsing XML for this repo.
-
getSchemaModules
@NonNull public abstract java.util.List<SchemaModule<?>> getSchemaModules()
Gets the currently-registeredSchemaModules. This probably shouldn't be used except by code within the RepoManager or unit tests.
-
getCommonModule
@NonNull public static SchemaModule<CommonFactory> getCommonModule()
Gets the coreSchemaModulecreated by the RepoManager itself. Contains the base definition of repository, package, revision, etc.
-
getGenericModule
@NonNull public static SchemaModule<GenericFactory> getGenericModule()
Gets theSchemaModulecreated by the RepoManager that includes the trivial generictypeDetailstype.
-
setLocalPath
public abstract void setLocalPath(@Nullable java.nio.file.Path path)Sets the path to the local repository root.
-
getLocalPath
@Nullable public abstract java.nio.file.Path 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 theFallbackLocalRepoLoaderto use when scanning the local repository for packages.
-
registerSourceProvider
public abstract void registerSourceProvider(@NonNull RepositorySourceProvider provider)Adds aRepositorySourceProviderfrom which to getRepositorySources from which to download lists of available repository packages.
-
getSourceProviders
@NonNull public abstract java.util.List<RepositorySourceProvider> getSourceProviders()
Gets the currently registeredRepositorySourceProviders. Should only be needed for testing.
-
getSources
public abstract java.util.List<RepositorySource> getSources(@Nullable Downloader downloader, @NonNull ProgressIndicator progress, boolean forceRefresh)
Gets the actualRepositorySources from the registeredRepositorySourceProviders.Probably should only be needed by a repository UI.
- Parameters:
downloader- TheDownloaderto use for downloading source lists, if needed.progress- AProgressIndicatorfor source providers to use to show their progress and for logging.forceRefresh- IndividualRepositorySourceProviders may cache their results. IfforceRefreshis 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 theFallbackRemoteRepoLoaderto try when we encounter a remote xml file that the RepoManger can't read.
-
load
public abstract void load(long cacheExpirationMs, @Nullable java.util.List<RepoManager.RepoLoadedListener> onLocalComplete, @Nullable java.util.List<RepoManager.RepoLoadedListener> onSuccess, @Nullable java.util.List<java.lang.Runnable> onError, @NonNull ProgressRunner runner, @Nullable Downloader downloader, @Nullable SettingsController settings)Loads the local and remote repositories asynchronously.- Parameters:
cacheExpirationMs- How long must have passed since the last load for us to reload. Specify0to reload immediately.onLocalComplete- When loading, the local repo load happens first, and should be relatively fast. When complete, theonLocalCompleteRepoManager.RepoLoadedListeners are run. Will be called with aRepositoryPackagesthat contains only the local packages.onSuccess- Callbacks that are run when the entire load (local and remote) has completed successfully. Called with anRepositoryPackagescontaining both the local and remote packages.onError- Callbacks that are run when there's an error at some point during the load.runner- TheProgressRunnerto use for any tasks started during the load, including running the callbacks.downloader- TheDownloaderto 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.TODO: throw exception if cancelled
-
loadSynchronously
@Slow public abstract void loadSynchronously(long cacheExpirationMs, @Nullable java.util.List<RepoManager.RepoLoadedListener> onLocalComplete, @Nullable java.util.List<RepoManager.RepoLoadedListener> onSuccess, @Nullable java.util.List<java.lang.Runnable> onError, @NonNull ProgressRunner runner, @Nullable Downloader downloader, @Nullable SettingsController settings)Loads the local and remote repositories synchronously. 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. Specify0to reload immediately.onLocalComplete- When loading, the local repo load happens first, and should be relatively fast. When complete, theonLocalCompleteRepoManager.RepoLoadedListeners are run. Will be called with aRepositoryPackagesthat contains only the local packages.onSuccess- Callbacks that are run when the entire load (local and remote) has completed successfully. Called with anRepositoryPackagescontaining both the local and remote packages.onError- Callbacks that are run when there's an error at some point during the load.runner- TheProgressRunnerto use for any tasks started during the load, including running the callbacks.downloader- TheDownloaderto 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. TODO: throw exception if cancelled
-
loadSynchronously
@Slow public final boolean loadSynchronously(long cacheExpirationMs, @NonNull ProgressIndicator progress, @Nullable Downloader downloader, @Nullable SettingsController settings)Loads the local and remote repositories synchronously.- Parameters:
cacheExpirationMs- How long must have passed since the last load for us to reload. Specify0to reload immediately.progress- TheProgressIndicatorto use for showing progress and logging.downloader- TheDownloaderto 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.- Returns:
trueif the load was successful (including if cached results were returned), false otherwise.
-
markInvalid
public abstract void markInvalid()
Causes cached results to be considered expired. The next timeload(long, List, List, List, ProgressRunner, Downloader, SettingsController)is called, a complete load will be done.
-
markLocalCacheInvalid
public abstract void markLocalCacheInvalid()
Causes the cached results of the local repositories to be considered expired. The next timeload(long, List, List, List, ProgressRunner, Downloader, SettingsController)is called, the load will be done only for the local repositories, the remotes being loaded from the cache if possible.
-
reloadLocalIfNeeded
public abstract boolean reloadLocalIfNeeded(@NonNull ProgressIndicator progress)Check to see if there have been any changes to the local repo since the last load. This includes scanning the local repo for packages, but does not involve any reading or parsing of package metadata files. If there have been any changes, or if the cache is older than the default timeout, the local packages will be reloaded.- Returns:
trueif the load was successful,falseotherwise}.
-
getPackages
@NonNull public abstract RepositoryPackages getPackages()
Gets the currently-loadedRepositoryPackages.
-
getResourceResolver
@Nullable public abstract org.w3c.dom.ls.LSResourceResolver getResourceResolver(@NonNull ProgressIndicator progress)Gets anLSResourceResolverthat can find the XSDs for all versions of the currently-registeredSchemaModules by namespace. Returns null if there is an error.
-
addLocalChangeListener
public abstract void addLocalChangeListener(@NonNull RepoManager.RepoLoadedListener listener)Registers a listener that will be called whenever the local packages are reloaded and have changed. TheRepositoryPackagesinstance passed to the callback will contain only the local packages.
-
removeLocalChangeListener
public abstract void removeLocalChangeListener(@NonNull RepoManager.RepoLoadedListener listener)Removes the listener previously added by callingaddLocalChangeListener(com.android.repository.api.RepoManager.RepoLoadedListener).
-
addRemoteChangeListener
public abstract void addRemoteChangeListener(@NonNull RepoManager.RepoLoadedListener listener)Register a listener that will be called whenever the remote packages are reloaded and have changed. TheRepositoryPackagesinstance will contain the remote and local packages.
-
removeRemoteChangeListener
public abstract void removeRemoteChangeListener(@NonNull RepoManager.RepoLoadedListener listener)Removes the listener previously added by callingaddRemoteChangeListener(com.android.repository.api.RepoManager.RepoLoadedListener).
-
installBeginning
public abstract void installBeginning(@NonNull RepoPackage repoPackage, @NonNull PackageOperation installer)Record that the given package is in the process of being installed by the given installer.
-
installEnded
public abstract void installEnded(@NonNull RepoPackage repoPackage)Record that the given package is no longer in the process of being installed (that is, install completed either successfully or unsuccessfully).
-
getInProgressInstallOperation
@Nullable public abstract PackageOperation getInProgressInstallOperation(@NonNull RepoPackage remotePackage)
Gets the previously-registered installer that is currently installing the given package, ornullif there is none.
-
-