Package io.quarkus.cli.plugin
Class CatalogService<T extends Catalog<T>>
- java.lang.Object
-
- io.quarkus.cli.plugin.CatalogService<T>
-
- Direct Known Subclasses:
JBangCatalogService,PluginCatalogService
public class CatalogService<T extends Catalog<T>> extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>catalogTypeprotected static Predicate<Path>EXISTS_AND_WRITABLEprotected static Predicate<Path>GIT_ROOTprotected static Predicate<Path>HAS_BUILD_GRADLEprotected static Predicate<Path>HAS_POM_XMLprotected static Predicate<Path>IS_ELIGIBLE_PROJECT_ROOTprotected static Predicate<Path>IS_USER_HOMEprotected com.fasterxml.jackson.databind.ObjectMapperobjectMapperprotected Predicate<Path>projectRootprotected Function<Path,Path>relativePathprotected static PathUSER_HOME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Path>findProjectCatalogPath(Path dir)Get the project catalog path relative to the specified path.Optional<Path>findProjectCatalogPath(Optional<Path> dir)static Optional<Path>findProjectRoot(Path dir)Get the project root of the specified path.Optional<Path>getCatalogPath(Optional<Path> projectDir, Optional<Path> userDir)Get the project or user catalog path.Optional<Path>getRelativeCatalogPath(Path dir)Get the catalog relative to the specified path.Optional<Path>getRelativeCatalogPath(Optional<Path> dir)Get the catalog relative to the current dir.PathgetUserCatalogPath()Get the global catalog path that is under `~/.quarkus/cli/plugins/catalog.json`PathgetUserCatalogPath(Optional<Path> userDir)Get the global catalog path that is under `.quarkus/cli/plugins/catalog.json` under the specified user home directory.TreadCatalog(Path path)Read the catalog from the specified path.Optional<T>readCatalog(Optional<Path> projectDir, Optional<Path> userDir)Read the catalog from project or fallback to global catalog.Optional<T>readProjectCatalog(Optional<Path> dir)Optional<T>readUserCatalog(Optional<Path> userDir)Reads the plguin catalog from the user home.voidwriteCatalog(T catalog)Write the catalog to the specifiedPath.
-
-
-
Field Detail
-
USER_HOME
protected static final Path USER_HOME
-
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
-
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
Optionalor 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 specifiedPath. The method will create the directory structure if missing.- Parameters:
catalog- the catalogpath- 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
Optionalor 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
Optionalor 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
Optionalor 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- anOutputOptionMixinthat can be used for tests to substitute current dir with a test directory.- Returns:
- the catalog path wrapped as
Optionalor 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
Optionalor 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
Optionalor empty if the catalog does not exist.
-
-