Class CatalogService<T extends Catalog<T>>

    • Field Detail

      • USER_HOME

        protected static final Path USER_HOME
      • EXISTS_AND_WRITABLE

        protected static final Predicate<Path> EXISTS_AND_WRITABLE
      • IS_USER_HOME

        protected static final Predicate<Path> IS_USER_HOME
      • IS_ELIGIBLE_PROJECT_ROOT

        protected static final Predicate<Path> IS_ELIGIBLE_PROJECT_ROOT
      • HAS_POM_XML

        protected static final Predicate<Path> HAS_POM_XML
      • HAS_BUILD_GRADLE

        protected static final Predicate<Path> HAS_BUILD_GRADLE
      • objectMapper

        protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
      • catalogType

        protected final Class<T extends Catalog<T>> catalogType
    • Method Detail

      • readUserCatalog

        public Optional<T> readUserCatalog​(Optional<Path> userDir)
        Reads the plguin catalog from the user home.
        Parameters:
        userdir - An optional path pointing to the user directory.
        Returns:
        a catalog wrapped in optional or empty if the catalog is not present.
      • findProjectCatalogPath

        public Optional<Path> findProjectCatalogPath​(Path dir)
        Get the project catalog path relative to the specified path. The method will traverse from the specified path up to upmost directory that the user can write and is under version control seeking for a `.quarkus/cli/plugins/catalog.json`.
        Parameters:
        dir - the specified path
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • readCatalog

        public Optional<T> readCatalog​(Optional<Path> projectDir,
                                       Optional<Path> userDir)
        Read the catalog from project or fallback to global catalog.
        Parameters:
        projectDir - An optional path pointing to the project directory.
        userdir - An optional path pointing to the user directory
        Returns:
        the catalog
      • readCatalog

        public T readCatalog​(Path path)
        Read the catalog from the specified path.
        Parameters:
        path - the path to read the catalog from.
        Returns:
        the catalog
      • writeCatalog

        public void writeCatalog​(T catalog)
        Write the catalog to the specified Path. The method will create the directory structure if missing.
        Parameters:
        catalog - the catalog
        path - the path
      • getUserCatalogPath

        public Path getUserCatalogPath​(Optional<Path> userDir)
        Get the global catalog path that is under `.quarkus/cli/plugins/catalog.json` under the specified user home directory. The specified directory is optional and the method will fallback to the `user.home` system property. Using a different value if mostly needed for testing.
        Parameters:
        userDir - An optional user directory to use as a base path for the catalog lookup
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • getUserCatalogPath

        public Path getUserCatalogPath()
        Get the global catalog path that is under `~/.quarkus/cli/plugins/catalog.json`
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • getRelativeCatalogPath

        public Optional<Path> getRelativeCatalogPath​(Path dir)
        Get the catalog relative to the specified path.
        Parameters:
        dir - the specified path
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • getRelativeCatalogPath

        public Optional<Path> getRelativeCatalogPath​(Optional<Path> dir)
        Get the catalog relative to the current dir.
        Parameters:
        ouput - an OutputOptionMixin that can be used for tests to substitute current dir with a test directory.
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • getCatalogPath

        public Optional<Path> getCatalogPath​(Optional<Path> projectDir,
                                             Optional<Path> userDir)
        Get the project or user catalog path. The method with lookup the relative catalog path to the current dir and will fallback to the user catalog path.
        Parameters:
        projectDir - An optional path pointing to the project directory.
        userdir - An optional path pointing to the user directory
        Returns:
        the catalog path wrapped as Optional or empty if the catalog does not exist.
      • findProjectRoot

        public static Optional<Path> findProjectRoot​(Path dir)
        Get the project root of the specified path. The method will traverse from the specified path up to upmost directory that the user can write and is under version control.
        Parameters:
        dir - the specified path
        Returns:
        the project path wrapped as Optional or empty if the catalog does not exist.