Class AndroidSdkHandler


  • public final class AndroidSdkHandler
    extends java.lang.Object
    Android SDK interface to RepoManager. 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.String SDK_TEST_BASE_URL_ENV_VAR
      The name of the environment variable used to override the url of the primary repository, for testing.
      static 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.
    • 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, use getInstance(AndroidLocationsProvider, Path), unless you're in a unit test and need to specify a custom FileOp and/or androidFolder.
      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 custom RepoManager.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addCustomSourceProvider​(com.android.repository.api.RepositorySourceProvider provider, com.android.repository.api.ProgressIndicator progress)
      Add another RepositorySourceProvider.
      static com.android.repository.api.SchemaModule<AddonFactory> getAddonModule()  
      static java.util.List<com.android.repository.api.SchemaModule<?>> getAllModules()  
      java.nio.file.Path getAndroidFolder()  
      AndroidTargetManager getAndroidTargetManager​(com.android.repository.api.ProgressIndicator progress)
      Gets (and creates if necessary) an AndroidTargetManager based on our local sdk packages.
      BuildToolInfo getBuildToolInfo​(com.android.repository.Revision revision, com.android.repository.api.ProgressIndicator progress)
      Creates a the BuildToolInfo for the specificed build tools revision, if available.
      static com.android.repository.api.SchemaModule<SdkCommonFactory> getCommonModule()  
      com.android.repository.io.FileOp getFileOp()
      Deprecated. 
      static AndroidSdkHandler getInstance​(com.android.prefs.AndroidLocationsProvider locationProvider, java.nio.file.Path localPath)
      Get a AndroidSdkHandler instance.
      BuildToolInfo getLatestBuildTool​(com.android.repository.api.ProgressIndicator progress, boolean allowPreview)
      Returns a BuildToolInfo corresponding to the newest installed build tool RepoPackage, or null if none are installed (or if the allowPreview parameter is false and there was non-preview version available)
      BuildToolInfo getLatestBuildTool​(com.android.repository.api.ProgressIndicator progress, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview)
      Returns a BuildToolInfo corresponding to the newest installed build tool RepoPackage, or null if none are installed (or if the allowPreview parameter is false and there was non-preview version available)
      com.android.repository.api.LocalPackage getLatestLocalPackageForPrefix​(java.lang.String prefix, java.util.function.Predicate<com.android.repository.Revision> filter, boolean allowPreview, com.android.repository.api.ProgressIndicator progress)
      Suppose that prefix is p, and we have these local packages: p;1.1, p;1.2, p;2.1 What this should return is the package p;2.1.
      com.android.repository.api.LocalPackage getLatestLocalPackageForPrefix​(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.LocalPackage getLatestLocalPackageForPrefix​(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 the Collection of LocalPackages from RepoManager with the same prefix using RepositoryPackages.getLocalPackagesForPrefix(String) and forwards it to getLatestPackageFromPrefixCollection(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>
      P
      getLatestPackageFromPrefixCollection​(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.RemotePackage getLatestRemotePackageForPrefix​(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.RemotePackage getLatestRemotePackageForPrefix​(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.RemotePackage getLatestRemotePackageForPrefix​(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.LocalPackage getLocalPackage​(java.lang.String path, com.android.repository.api.ProgressIndicator progress)
      Convenience to get a package from the local repo.
      java.nio.file.Path getLocation()
      Gets the path of the local SDK, if set.
      static com.android.repository.api.SchemaModule<RepoFactory> getRepositoryModule()  
      com.android.repository.api.RepoManager getSdkManager​(com.android.repository.api.ProgressIndicator progress)
      Fetches RepoManager set up to interact with android SDK repositories.
      static com.android.repository.api.SchemaModule<SysImgFactory> getSysImgModule()  
      SystemImageManager getSystemImageManager​(com.android.repository.api.ProgressIndicator progress)
      Gets (and creates if necessary) a SystemImageManager based on our local sdk packages.
      com.android.repository.impl.sources.LocalSourceProvider getUserSourceProvider​(com.android.repository.api.ProgressIndicator progress)
      Gets the customizable RepositorySourceProvider.
      static void resetInstance​(java.nio.file.Path localPath)
      Force removal of a cached AndroidSdkHandler instance.
      java.nio.file.Path toCompatiblePath​(java.io.File file)
      Converts a File into a Path on the FileSystem used by this SDK.
      java.nio.file.Path toCompatiblePath​(java.lang.String file)
      Converts a String into a Path on the FileSystem used by this SDK.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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, use getInstance(AndroidLocationsProvider, Path), unless you're in a unit test and need to specify a custom FileOp and/or androidFolder.
      • 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 custom RepoManager.
        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 a AndroidSdkHandler instance.
        Parameters:
        locationProvider - a location provider to get the path to the .android folder.
        localPath - The path to the local SDK. If null this handler will only be used for remote operations.
      • resetInstance

        public static void resetInstance​(@NonNull
                                         java.nio.file.Path localPath)
        Force removal of a cached AndroidSdkHandler instance. 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)
        Fetches RepoManager set 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) a SystemImageManager based on our local sdk packages.
      • getAndroidTargetManager

        @NonNull
        public AndroidTargetManager getAndroidTargetManager​(@NonNull
                                                            com.android.repository.api.ProgressIndicator progress)
        Gets (and creates if necessary) an AndroidTargetManager based 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 - LocalPackage or RemotePackage
        T - Comparable that we map the suffix to.
        Parameters:
        packages - a Collection of packages which share a common prefix, from which we wish to extract the "Latest" package, as sorted with mapper and comparator on the suffixes.
        filter - the revision predicate that has to be satisfied by the returned package
        allowPreview - whether we allow returning a preview package.
        mapper - maps from path suffix to a Comparable, 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 with mapper and comparator on 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 that prefix is p, and we have these local packages: p;1.1, p;1.2, p;2.1 What this should return is the package p;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)
        See Also:
        , where is just the default order. Highest is latest.
      • 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 SchemaModule containing the common sdk-specific metadata. See sdk-common-XX.xsd.
      • getAddonModule

        @NonNull
        public static com.android.repository.api.SchemaModule<AddonFactory> getAddonModule()
        Returns:
        The SchemaModule containing the metadata for addon-type Repositorys. See sdk-addon-XX.xsd.
      • getRepositoryModule

        @NonNull
        public static com.android.repository.api.SchemaModule<RepoFactory> getRepositoryModule()
        Returns:
        The SchemaModule containing the metadata for the primary android SDK Repository (containin platforms etc.). See sdk-repository-XX.xsd.
      • getSysImgModule

        @NonNull
        public static com.android.repository.api.SchemaModule<SysImgFactory> getSysImgModule()
        Returns:
        The SchemaModule containing the metadata for system image-type Repositorys. 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 customizable RepositorySourceProvider. 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 another RepositorySourceProvider. All existing AndroidSdkHandlers and RepoManagers 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 a BuildToolInfo corresponding to the newest installed build tool RepoPackage, or null if none are installed (or if the allowPreview parameter is false and there was non-preview version available)
        Parameters:
        progress - a progress indicator
        allowPreview - 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 a BuildToolInfo corresponding to the newest installed build tool RepoPackage, or null if none are installed (or if the allowPreview parameter is false and there was non-preview version available)
        Parameters:
        progress - a progress indicator
        filter - the revision predicate to satisfy
        allowPreview - 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 the BuildToolInfo for the specificed build tools revision, if available.
        Parameters:
        revision - The build tools revision requested
        progress - ProgressIndicator for logging.
        Returns:
        The BuildToolInfo corresponding 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 our FileOp. 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 a File into a Path on the FileSystem used by this SDK.
      • toCompatiblePath

        @NonNull
        public java.nio.file.Path toCompatiblePath​(@NonNull
                                                   java.lang.String file)
        Converts a String into a Path on the FileSystem used by this SDK.