com.android.repository.impl.manager
Class RepoManagerImpl

java.lang.Object
  extended by com.android.repository.api.RepoManager
      extended by com.android.repository.impl.manager.RepoManagerImpl

public class RepoManagerImpl
extends RepoManager

Main implementation of RepoManager. Loads local and remote RepoPackages synchronously and asynchronously into a RepositoryPackages instance from the given local path and from the registered RepositorySourceProviders, using the registered SchemaModules.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.repository.api.RepoManager
RepoManager.RepoLoadedCallback
 
Field Summary
 
Fields inherited from class com.android.repository.api.RepoManager
DEFAULT_EXPIRATION_PERIOD_MS
 
Constructor Summary
RepoManagerImpl(FileOp fop)
          Create a new RepoManagerImpl.
 
Method Summary
 java.io.File getLocalPath()
          Gets the path to the local repository root.
 RepositoryPackages getPackages()
          Gets the currently-loaded RepositoryPackages.
 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.
 java.util.Set<SchemaModule> getSchemaModules()
          Gets the currently-registered SchemaModules.
 java.util.Set<RepositorySourceProvider> getSourceProviders()
          Gets the currently registered RepositorySourceProviders.
 java.util.Set<RepositorySource> getSources(Downloader downloader, SettingsController settings, ProgressIndicator progress, boolean forceRefresh)
          Gets the actual RepositorySources from the registered RepositorySourceProviders.
 boolean load(long cacheExpirationMs, java.util.List<RepoManager.RepoLoadedCallback> onLocalComplete, java.util.List<RepoManager.RepoLoadedCallback> onSuccess, java.util.List<java.lang.Runnable> onError, ProgressRunner runner, Downloader downloader, SettingsController settings, boolean sync)
          Load the local and remote repositories.
 void markInvalid()
          Causes cached results to be considered expired.
 void registerLocalChangeListener(RepoManager.RepoLoadedCallback listener)
          Registers a listener that will be called whenever the local packages are reloaded and have changed.
 void registerRemoteChangeListener(RepoManager.RepoLoadedCallback listener)
          Register a listener that will be called whenever the remote packages are reloaded and have changed.
 void registerSchemaModule(SchemaModule module)
          Register an SchemaModule that can be used when parsing XML for this repo.
 void registerSourceProvider(RepositorySourceProvider provider)
          Adds a RepositorySourceProvider from which to get RepositorySources from which to download lists of available repository packages.
 void setFallbackLocalRepoLoader(FallbackLocalRepoLoader fallback)
          Sets the FallbackLocalRepoLoader to use when scanning the local repository for packages.
 void setFallbackRemoteRepoLoader(FallbackRemoteRepoLoader remote)
          Sets the FallbackRemoteRepoLoader to try when we encounter a remote xml file that the RepoManger can't read.
 void setLocalPath(java.io.File path)
          Sets the path to the local repository root.
 
Methods inherited from class com.android.repository.api.RepoManager
create, getCommonModule, getGenericModule, loadSynchronously
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepoManagerImpl

public RepoManagerImpl(@Nullable
                       FileOp fop)
Create a new RepoManagerImpl. Before anything can be loaded, at least a local path and/or at least one RepositorySourceProvider must be set.

Parameters:
fop - FileOp to use for local file operations. Should only be null if you're never planning to load a local repo using this RepoManagerImpl.
Method Detail

getLocalPath

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

Specified by:
getLocalPath in class RepoManager

setFallbackLocalRepoLoader

public void setFallbackLocalRepoLoader(@Nullable
                                       FallbackLocalRepoLoader fallback)
Sets the FallbackLocalRepoLoader to use when scanning the local repository for packages. This calls markInvalid(), so a complete load will occur the next time load(long, List, List, List, ProgressRunner, Downloader, SettingsController, boolean) is called.

Specified by:
setFallbackLocalRepoLoader in class RepoManager

setFallbackRemoteRepoLoader

public void setFallbackRemoteRepoLoader(@Nullable
                                        FallbackRemoteRepoLoader remote)
Sets the FallbackRemoteRepoLoader to try when we encounter a remote xml file that the RepoManger can't read. This calls markInvalid(), so a complete load will occur the next time load(long, List, List, List, ProgressRunner, Downloader, SettingsController, boolean) is called.

Specified by:
setFallbackRemoteRepoLoader in class RepoManager

setLocalPath

public void setLocalPath(@Nullable
                         java.io.File path)
Sets the path to the local repository root. This calls markInvalid(), so a complete load will occur the next time load(long, List, List, List, ProgressRunner, Downloader, SettingsController, boolean) is called.

Specified by:
setLocalPath in class RepoManager

registerSourceProvider

public void registerSourceProvider(@NonNull
                                   RepositorySourceProvider provider)
Adds a RepositorySourceProvider from which to get RepositorySources from which to download lists of available repository packages. This calls markInvalid(), so a complete load will occur the next time load(long, List, List, List, ProgressRunner, Downloader, SettingsController, boolean) is called.

Specified by:
registerSourceProvider in class RepoManager

getSourceProviders

@NonNull
public java.util.Set<RepositorySourceProvider> getSourceProviders()
Description copied from class: RepoManager
Gets the currently registered RepositorySourceProviders. Should only be needed for testing.

Specified by:
getSourceProviders in class RepoManager

getSources

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

Specified by:
getSources in class RepoManager
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.

getSchemaModules

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

Specified by:
getSchemaModules in class RepoManager

registerSchemaModule

public void registerSchemaModule(@NonNull
                                 SchemaModule module)
Register an SchemaModule that can be used when parsing XML for this repo. This calls markInvalid(), so a complete load will occur the next time load(long, List, List, List, ProgressRunner, Downloader, SettingsController, boolean) is called.

Specified by:
registerSchemaModule in class RepoManager

markInvalid

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

Specified by:
markInvalid in class RepoManager

getResourceResolver

@Nullable
public org.w3c.dom.ls.LSResourceResolver getResourceResolver(@NonNull
                                                                      ProgressIndicator progress)
Description copied from class: RepoManager
Gets an LSResourceResolver that can find the XSDs for all versions of the currently-registered SchemaModules by namespace. Returns null if there is an error.

Specified by:
getResourceResolver in class RepoManager

getPackages

@NonNull
public RepositoryPackages getPackages()
Description copied from class: RepoManager
Gets the currently-loaded RepositoryPackages.

Specified by:
getPackages in class RepoManager

load

public boolean load(long cacheExpirationMs,
                    @Nullable
                    java.util.List<RepoManager.RepoLoadedCallback> onLocalComplete,
                    @Nullable
                    java.util.List<RepoManager.RepoLoadedCallback> onSuccess,
                    @Nullable
                    java.util.List<java.lang.Runnable> onError,
                    @NonNull
                    ProgressRunner runner,
                    @Nullable
                    Downloader downloader,
                    @Nullable
                    SettingsController settings,
                    boolean sync)
Description copied from class: RepoManager
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.

Specified by:
load in class RepoManager
Parameters:
cacheExpirationMs - How long must have passed since the last load for us to reload. Specify 0 to reload immediately.
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.
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). TODO: throw exception if cancelled
Returns:
true if a load was performed. false if cached results were fresh enough.

registerLocalChangeListener

public void registerLocalChangeListener(@NonNull
                                        RepoManager.RepoLoadedCallback listener)
Description copied from class: RepoManager
Registers a listener that will be called whenever the local packages are reloaded and have changed. The RepositoryPackages instance passed to the callback will contain only the local packages.

Specified by:
registerLocalChangeListener in class RepoManager

registerRemoteChangeListener

public void registerRemoteChangeListener(@NonNull
                                         RepoManager.RepoLoadedCallback listener)
Description copied from class: RepoManager
Register a listener that will be called whenever the remote packages are reloaded and have changed. The RepositoryPackages instance will contain the remote and local packages.

Specified by:
registerRemoteChangeListener in class RepoManager