Package com.android.sdklib.repository
Class AndroidSdkHandler
- java.lang.Object
-
- com.android.sdklib.repository.AndroidSdkHandler
-
public final class AndroidSdkHandler extends java.lang.ObjectAndroid SDK interface toRepoManager. Ensures that the proper android sdk-specific schemas and source providers are registered, and provides android sdk-specific package logic (pending as adoption continues).
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSDK_TEST_BASE_URL_ENV_VARThe name of the environment variable used to override the url of the primary repository, for testing.static java.lang.StringSDK_TEST_BASE_URL_PROPERTYThe name of the system property used to override the url of the primary repository, for testing.
-
Constructor Summary
Constructors Constructor Description AndroidSdkHandler(java.nio.file.Path localPath, java.nio.file.Path androidFolder, com.android.repository.io.FileOp fop)Don't use this, usegetInstance(AndroidLocationsProvider, Path), unless you're in a unit test and need to specify a customFileOpand/orandroidFolder.AndroidSdkHandler(java.nio.file.Path localPath, java.nio.file.Path androidFolder, com.android.repository.io.FileOp fop, com.android.repository.api.RepoManager repoManager)Don't use this either, unless you're in a unit test and need to specify a customRepoManager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddCustomSourceProvider(com.android.repository.api.RepositorySourceProvider provider, com.android.repository.api.ProgressIndicator progress)Add anotherRepositorySourceProvider.static com.android.repository.api.SchemaModule<AddonFactory>getAddonModule()static java.util.List<com.android.repository.api.SchemaModule<?>>getAllModules()java.nio.file.PathgetAndroidFolder()AndroidTargetManagergetAndroidTargetManager(com.android.repository.api.ProgressIndicator progress)Gets (and creates if necessary) anAndroidTargetManagerbased on our local sdk packages.BuildToolInfogetBuildToolInfo(com.android.repository.Revision revision, com.android.repository.api.ProgressIndicator progress)Creates a theBuildToolInfofor the specificed build tools revision, if available.static com.android.repository.api.SchemaModule<SdkCommonFactory>getCommonModule()com.android.repository.io.FileOpgetFileOp()Deprecated.static AndroidSdkHandlergetInstance(com.android.prefs.AndroidLocationsProvider locationProvider, java.nio.file.Path localPath)Get aAndroidSdkHandlerinstance.BuildToolInfogetLatestBuildTool(com.android.repository.api.ProgressIndicator progress, boolean allowPreview)Returns aBuildToolInfocorresponding to the newest installed build toolRepoPackage, ornullif none are installed (or if theallowPreviewparameter is false and there was non-preview version available)BuildToolInfogetLatestBuildTool(com.android.repository.api.ProgressIndicator progress, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview)Returns aBuildToolInfocorresponding to the newest installed build toolRepoPackage, ornullif none are installed (or if theallowPreviewparameter is false and there was non-preview version available)com.android.repository.api.LocalPackagegetLatestLocalPackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, com.android.repository.api.ProgressIndicator progress)Suppose thatprefixisp, and we have these local packages:p;1.1,p;1.2,p;2.1What this should return is the packagep;2.1.com.android.repository.api.LocalPackagegetLatestLocalPackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, java.util.function.Function<java.lang.String,? extends java.lang.Comparable> mapper, com.android.repository.api.ProgressIndicator progress)<T> com.android.repository.api.LocalPackagegetLatestLocalPackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, java.util.function.Function<java.lang.String,T> mapper, java.util.Comparator<T> comparator, com.android.repository.api.ProgressIndicator progress)This grabs theCollectionofLocalPackages fromRepoManagerwith the same prefix usingRepositoryPackages.getLocalPackagesForPrefix(String)and forwards it togetLatestPackageFromPrefixCollection(java.util.Collection<P>, java.util.function.Predicate<com.android.repository.Revision>, boolean, java.util.function.Function<java.lang.String, T>, java.util.Comparator<T>)static <P extends com.android.repository.api.RepoPackage,T>
PgetLatestPackageFromPrefixCollection(java.util.Collection<P> packages, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, java.util.function.Function<java.lang.String,T> mapper, java.util.Comparator<T> comparator)com.android.repository.api.RemotePackagegetLatestRemotePackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, com.android.repository.api.ProgressIndicator progress)com.android.repository.api.RemotePackagegetLatestRemotePackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, java.util.function.Function<java.lang.String,? extends java.lang.Comparable> mapper, com.android.repository.api.ProgressIndicator progress)<T> com.android.repository.api.RemotePackagegetLatestRemotePackageForPrefix(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, java.util.function.Function<java.lang.String,T> mapper, java.util.Comparator<T> comparator, com.android.repository.api.ProgressIndicator progress)com.android.repository.api.LocalPackagegetLocalPackage(java.lang.String path, com.android.repository.api.ProgressIndicator progress)Convenience to get a package from the local repo.java.nio.file.PathgetLocation()Gets the path of the local SDK, if set.static com.android.repository.api.SchemaModule<RepoFactory>getRepositoryModule()com.android.repository.api.RepoManagergetSdkManager(com.android.repository.api.ProgressIndicator progress)FetchesRepoManagerset up to interact with android SDK repositories.static com.android.repository.api.SchemaModule<SysImgFactory>getSysImgModule()SystemImageManagergetSystemImageManager(com.android.repository.api.ProgressIndicator progress)Gets (and creates if necessary) aSystemImageManagerbased on our local sdk packages.com.android.repository.impl.sources.LocalSourceProvidergetUserSourceProvider(com.android.repository.api.ProgressIndicator progress)Gets the customizableRepositorySourceProvider.static voidresetInstance(java.nio.file.Path localPath)Force removal of a cachedAndroidSdkHandlerinstance.java.nio.file.PathtoCompatiblePath(java.io.File file)Converts aFileinto aPathon theFileSystemused by this SDK.java.nio.file.PathtoCompatiblePath(java.lang.String file)Converts aStringinto aPathon theFileSystemused by this SDK.
-
-
-
Field Detail
-
SDK_TEST_BASE_URL_ENV_VAR
public static final java.lang.String SDK_TEST_BASE_URL_ENV_VAR
The name of the environment variable used to override the url of the primary repository, for testing.- See Also:
- Constant Field Values
-
SDK_TEST_BASE_URL_PROPERTY
public static final java.lang.String SDK_TEST_BASE_URL_PROPERTY
The name of the system property used to override the url of the primary repository, for testing.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AndroidSdkHandler
public AndroidSdkHandler(@Nullable java.nio.file.Path localPath, @Nullable java.nio.file.Path androidFolder, @NonNull com.android.repository.io.FileOp fop)Don't use this, usegetInstance(AndroidLocationsProvider, Path), unless you're in a unit test and need to specify a customFileOpand/orandroidFolder.
-
AndroidSdkHandler
public AndroidSdkHandler(@Nullable java.nio.file.Path localPath, @Nullable java.nio.file.Path androidFolder, @NonNull com.android.repository.io.FileOp fop, @NonNull com.android.repository.api.RepoManager repoManager)Don't use this either, unless you're in a unit test and need to specify a customRepoManager.- See Also:
AndroidSdkHandler(Path, Path, FileOp)
-
-
Method Detail
-
getInstance
@NonNull public static AndroidSdkHandler getInstance(@NonNull com.android.prefs.AndroidLocationsProvider locationProvider, @Nullable java.nio.file.Path localPath)
Get aAndroidSdkHandlerinstance.- Parameters:
locationProvider- a location provider to get the path to the .android folder.localPath- The path to the local SDK. Ifnullthis handler will only be used for remote operations.
-
resetInstance
public static void resetInstance(@NonNull java.nio.file.Path localPath)Force removal of a cachedAndroidSdkHandlerinstance. This will force a reparsing of the SDK next time a component is looked up.- Parameters:
localPath- The path to the local SDK.
-
getSdkManager
@NonNull public com.android.repository.api.RepoManager getSdkManager(@NonNull com.android.repository.api.ProgressIndicator progress)FetchesRepoManagerset up to interact with android SDK repositories. It should not cached by callers of this method, since any changes to the fundamental properties of the manager (fallback loaders, local path) will cause a new instance to be created.
-
getSystemImageManager
@NonNull public SystemImageManager getSystemImageManager(@NonNull com.android.repository.api.ProgressIndicator progress)
Gets (and creates if necessary) aSystemImageManagerbased on our local sdk packages.
-
getAndroidTargetManager
@NonNull public AndroidTargetManager getAndroidTargetManager(@NonNull com.android.repository.api.ProgressIndicator progress)
Gets (and creates if necessary) anAndroidTargetManagerbased on our local sdk packages.
-
getLocation
@Nullable public java.nio.file.Path getLocation()
Gets the path of the local SDK, if set.
-
getAndroidFolder
@Nullable public java.nio.file.Path getAndroidFolder()
-
getLocalPackage
@Nullable public com.android.repository.api.LocalPackage getLocalPackage(@NonNull java.lang.String path, @NonNull com.android.repository.api.ProgressIndicator progress)Convenience to get a package from the local repo.
-
getLatestPackageFromPrefixCollection
@Nullable public static <P extends com.android.repository.api.RepoPackage,T> P getLatestPackageFromPrefixCollection(@NonNull java.util.Collection<P> packages, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull java.util.function.Function<java.lang.String,T> mapper, @NonNull java.util.Comparator<T> comparator)- Type Parameters:
P-LocalPackageorRemotePackageT-Comparablethat we map the suffix to.- Parameters:
packages- aCollectionof packages which share a commonprefix, from which we wish to extract the "Latest" package, as sorted withmapperandcomparatoron the suffixes.filter- the revision predicate that has to be satisfied by the returned packageallowPreview- whether we allow returning a preview package.mapper- maps from path suffix to aComparable, so that we can sort the packages by suffix.comparator- how to sort suffixes after mapping them.- Returns:
- the "Latest" package from the
Collection, as sorted withmapperandcomparatoron the last path component.
-
getLatestLocalPackageForPrefix
@Nullable public com.android.repository.api.LocalPackage getLatestLocalPackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull com.android.repository.api.ProgressIndicator progress)Suppose thatprefixisp, and we have these local packages:p;1.1,p;1.2,p;2.1What this should return is the packagep;2.1. We operate on the path suffix since we have no guarantee that the package revision is the same as used in the path. We also have no guarantee that the format of the path even matches, so we ignore the packages that don't fit the format.- See Also:
where is just converting path suffix to . Suffixes that are not valid s are assumed to be , and would be the lowest.,for how the conversion is done.
-
getLatestLocalPackageForPrefix
@Nullable public com.android.repository.api.LocalPackage getLatestLocalPackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull java.util.function.Function<java.lang.String,? extends java.lang.Comparable> mapper, @NonNull com.android.repository.api.ProgressIndicator progress)
-
getLatestLocalPackageForPrefix
@Nullable public <T> com.android.repository.api.LocalPackage getLatestLocalPackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull java.util.function.Function<java.lang.String,T> mapper, @NonNull java.util.Comparator<T> comparator, @NonNull com.android.repository.api.ProgressIndicator progress)This grabs theCollectionofLocalPackages fromRepoManagerwith the same prefix usingRepositoryPackages.getLocalPackagesForPrefix(String)and forwards it togetLatestPackageFromPrefixCollection(java.util.Collection<P>, java.util.function.Predicate<com.android.repository.Revision>, boolean, java.util.function.Function<java.lang.String, T>, java.util.Comparator<T>)
-
getLatestRemotePackageForPrefix
@Nullable public com.android.repository.api.RemotePackage getLatestRemotePackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull com.android.repository.api.ProgressIndicator progress)
-
getLatestRemotePackageForPrefix
@Nullable public com.android.repository.api.RemotePackage getLatestRemotePackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull java.util.function.Function<java.lang.String,? extends java.lang.Comparable> mapper, @NonNull com.android.repository.api.ProgressIndicator progress)
-
getLatestRemotePackageForPrefix
@Nullable public <T> com.android.repository.api.RemotePackage getLatestRemotePackageForPrefix(@NonNull java.lang.String prefix, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, @NonNull java.util.function.Function<java.lang.String,T> mapper, @NonNull java.util.Comparator<T> comparator, @NonNull com.android.repository.api.ProgressIndicator progress)
-
getCommonModule
@NonNull public static com.android.repository.api.SchemaModule<SdkCommonFactory> getCommonModule()
- Returns:
- The
SchemaModulecontaining the common sdk-specific metadata. See sdk-common-XX.xsd.
-
getAddonModule
@NonNull public static com.android.repository.api.SchemaModule<AddonFactory> getAddonModule()
- Returns:
- The
SchemaModulecontaining the metadata for addon-typeRepositorys. See sdk-addon-XX.xsd.
-
getRepositoryModule
@NonNull public static com.android.repository.api.SchemaModule<RepoFactory> getRepositoryModule()
- Returns:
- The
SchemaModulecontaining the metadata for the primary android SDKRepository(containin platforms etc.). See sdk-repository-XX.xsd.
-
getSysImgModule
@NonNull public static com.android.repository.api.SchemaModule<SysImgFactory> getSysImgModule()
- Returns:
- The
SchemaModulecontaining the metadata for system image-typeRepositorys. See sdk-sys-img-XX.xsd.
-
getAllModules
@NonNull public static java.util.List<com.android.repository.api.SchemaModule<?>> getAllModules()
- Returns:
- A list of all the known
SchemaModules
-
getUserSourceProvider
@Nullable public com.android.repository.impl.sources.LocalSourceProvider getUserSourceProvider(@NonNull com.android.repository.api.ProgressIndicator progress)Gets the customizableRepositorySourceProvider. Can be null if there's a problem with the user's environment.
-
addCustomSourceProvider
public static void addCustomSourceProvider(@NonNull com.android.repository.api.RepositorySourceProvider provider, @NonNull com.android.repository.api.ProgressIndicator progress)Add anotherRepositorySourceProvider. All existingAndroidSdkHandlers andRepoManagers are invalidated, and all future instances will include the new provider.
-
getLatestBuildTool
@Nullable public BuildToolInfo getLatestBuildTool(@NonNull com.android.repository.api.ProgressIndicator progress, boolean allowPreview)
Returns aBuildToolInfocorresponding to the newest installed build toolRepoPackage, ornullif none are installed (or if theallowPreviewparameter is false and there was non-preview version available)- Parameters:
progress- a progress indicatorallowPreview- ignore preview build tools version unless this parameter is true
-
getLatestBuildTool
@Nullable public BuildToolInfo getLatestBuildTool(@NonNull com.android.repository.api.ProgressIndicator progress, @Nullable java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview)
Returns aBuildToolInfocorresponding to the newest installed build toolRepoPackage, ornullif none are installed (or if theallowPreviewparameter is false and there was non-preview version available)- Parameters:
progress- a progress indicatorfilter- the revision predicate to satisfyallowPreview- ignore preview build tools version unless this parameter is true
-
getBuildToolInfo
@Nullable public BuildToolInfo getBuildToolInfo(@NonNull com.android.repository.Revision revision, @NonNull com.android.repository.api.ProgressIndicator progress)
Creates a theBuildToolInfofor the specificed build tools revision, if available.- Parameters:
revision- The build tools revision requestedprogress-ProgressIndicatorfor logging.- Returns:
- The
BuildToolInfocorresponding to the specified build tools package, or null if that revision is not installed.
-
getFileOp
@NonNull public com.android.repository.io.FileOp getFileOp()
Deprecated.Gets ourFileOp. Useful so both the sdk handler and file op don't both have to be injected everywhere.
-
toCompatiblePath
@NonNull public java.nio.file.Path toCompatiblePath(@NonNull java.io.File file)Converts aFileinto aPathon theFileSystemused by this SDK.
-
toCompatiblePath
@NonNull public java.nio.file.Path toCompatiblePath(@NonNull java.lang.String file)Converts aStringinto aPathon theFileSystemused by this SDK.
-
-