Class ModuleUtils

java.lang.Object
io.helidon.inject.tools.ModuleUtils

public class ModuleUtils extends Object
Module specific utils.
  • Field Details

    • REAL_MODULE_INFO_JAVA_NAME

      public static final String REAL_MODULE_INFO_JAVA_NAME
      The "real" module-info.java file name.
      See Also:
    • MODULE_INFO_JAVA_NAME

      public static final String MODULE_INFO_JAVA_NAME
      The injection generated (e.g., module-info.java.inject) file name.
      See Also:
    • APPLICATION_PACKAGE_FILE_NAME

      public static final String APPLICATION_PACKAGE_FILE_NAME
      The file name written to ./target/inject/ to track the last package name generated for this application. This application package name is what we fall back to for the application name and the module name if not otherwise specified directly.
      See Also:
  • Method Details

    • toSuggestedGeneratedPackageName

      public static String toSuggestedGeneratedPackageName(Collection<TypeName> typeNames, String defaultPackageName, io.helidon.inject.tools.ModuleInfoDescriptor descriptor)
      Returns the suggested package name to use.
      Parameters:
      typeNames - the set of types that are being code generated
      defaultPackageName - the default package name to use if all options are exhausted
      descriptor - the module-info descriptor
      Returns:
      the suggested package name
    • toSuggestedGeneratedPackageName

      public static String toSuggestedGeneratedPackageName(Collection<TypeName> typeNames, String defaultPackageName)
      Returns the suggested package name to use.
      Parameters:
      typeNames - the set of types that are being code generated
      defaultPackageName - the default package name to use if all options are exhausted
      Returns:
      the suggested package name
    • toSuggestedModuleName

      public static Optional<String> toSuggestedModuleName(Path basePath, Path sourcePath, boolean defaultToUnnamed)
      Extract the module name, first attempting the source path (test or main), and if not found using the base path, presumably having basePath being a parent in the sourcePath hierarchy.
      Parameters:
      basePath - the secondary path to try if module-info was not found in the source path
      sourcePath - the source path
      defaultToUnnamed - if true, will return the default name, otherwise empty is returned
      Returns:
      the module name suggested to use, most appropriate for the name of Application or ModuleComponent
    • inferSourceOrTest

      public static String inferSourceOrTest(Path path)
      Attempts to infer 'test' or base '' given the path.
      Parameters:
      path - the path
      Returns:
      'test' or '' (for base non-test)
    • toSourcePath

      public static Optional<Path> toSourcePath(Path filePath, TypeElement type)
      Translates to the source path coordinate given a source file and type name. Only available during annotation processing.
      Parameters:
      filePath - the source file path
      type - the type name
      Returns:
      the source path, or empty if it cannot be inferred
    • toBasePath

      public static Path toBasePath(String sourcePath)
      Returns the base module path given its source path.
      Parameters:
      sourcePath - the source path
      Returns:
      the base path
    • isUnnamedModuleName

      public static boolean isUnnamedModuleName(String moduleName)
      Returns true if the given module name is unnamed.
      Parameters:
      moduleName - the module name to check
      Returns:
      true if the provided module name is unnamed
    • loadAppPackageName

      public static Optional<String> loadAppPackageName(Path scratchPath)
      Attempts to load the app package name from what was previously recorded.
      Parameters:
      scratchPath - the scratch directory path
      Returns:
      the app package name that was loaded
    • saveAppPackageName

      public static void saveAppPackageName(Path scratchPath, String packageName)
      Persist the package name into scratch for later usage.
      Parameters:
      scratchPath - the scratch directory path
      packageName - the package name
      Throws:
      ToolsException - if there are any errors creating or writing the content