Class JavaApplication

java.lang.Object
io.micronaut.starter.feature.lang.java.JavaApplication
All Implemented Interfaces:
io.micronaut.core.naming.Described, io.micronaut.core.naming.Named, io.micronaut.core.order.Ordered, ApplicationFeature, Feature, JavaApplicationFeature

@Requires(property="micronaut.starter.feature.java.application.enabled", value="true", defaultValue="true") @Singleton public class JavaApplication extends Object implements JavaApplicationFeature
Represents the Java application feature that can be applied during project generation.
  • Constructor Details

    • JavaApplication

      public JavaApplication(ContextFactory contextFactory)
  • Method Details

    • mainClassName

      @Nullable public @Nullable String mainClassName(GeneratorContext generatorContext)
      Specified by:
      mainClassName in interface ApplicationFeature
    • getName

      public String getName()
      Description copied from interface: Feature
      The name of the feature. It must be unique.
      Specified by:
      getName in interface Feature
      Specified by:
      getName in interface io.micronaut.core.naming.Named
      Returns:
      the name of the feature
    • supports

      public boolean supports(Options options)
      Description copied from interface: Feature
      This method must be implemented to ensure it is only selectable for the desired application types. This method is not used for determining if a default feature should be applied.
      Specified by:
      supports in interface Feature
      Parameters:
      options - Options
      Returns:
      True if the feature can be selected by the user
    • apply

      public void apply(GeneratorContext generatorContext)
      Description copied from interface: Feature
      If this method is called for a given feature that means the feature was explicitly selected, included by default as a result of DefaultFeature.shouldApply(io.micronaut.starter.options.Options, java.util.Set), or added explicitly by another feature through FeatureContext.addFeature(Feature). At this point the feature list is set and cannot change.
      Specified by:
      apply in interface ApplicationFeature
      Specified by:
      apply in interface Feature
      Parameters:
      generatorContext - THe generator context
    • shouldGenerateApplicationFile

      protected boolean shouldGenerateApplicationFile(GeneratorContext generatorContext)
      Determines whether an application file should be generated based on the provided GeneratorContext. The decision is made based on the application type and the presence of the FunctionFeature.
      Parameters:
      generatorContext - the context used to generate the project
      Returns:
      true if an application file should be generated, false otherwise
    • addApplication

      protected void addApplication(GeneratorContext generatorContext, ModuleContext module)
      Adds the application template to the given ModuleContext. The application template is generated based on the provided GeneratorContext and ModuleContext. The template is added with the name "application" and is located at the path specified by the getPath() method.
      Parameters:
      generatorContext - the context used to generate the project
      module - the module context to which the application template is added
    • application

      protected com.fizzed.rocker.RockerModel application(GeneratorContext generatorContext, ModuleContext module)
      Generates the RockerModel for the application template based on the provided GeneratorContext and ModuleContext. The RockerModel is generated using the application template, passing in the project, features, JavaApplicationRenderingContext, and whether the Slf4jJulBridge feature is present. The JavaApplicationRenderingContext is constructed with the default environment and whether eager initialization of singletons is required.
      Parameters:
      generatorContext - the context used to generate the project
      module - the module context used to determine the default environment
      Returns:
      the RockerModel for the application template
    • addApplicationTest

      protected void addApplicationTest(GeneratorContext generatorContext, ModuleContext module)
      Adds an application test template to the given ModuleContext. The application test template is generated based on the provided GeneratorContext. The template is added with the name "applicationTest" and is located at the path specified by the getTestSourcePath() method of the GeneratorContext.
      Parameters:
      generatorContext - the context used to generate the project
      module - the module context to which the application test template is added
    • applicationTest

      protected com.fizzed.rocker.RockerModel applicationTest(GeneratorContext generatorContext)
      Generates the RockerModel for the application test template based on the provided GeneratorContext. The RockerModel is generated using a TestRockerModelProvider, which is constructed with various test templates. The test framework and project are retrieved from the GeneratorContext, and the transactional flag is determined based on the presence of the TransactionalNotSupported feature. The TestRockerModelProvider is then used to find the appropriate RockerModel based on the language and test framework.
      Parameters:
      generatorContext - the context used to generate the project
      Returns:
      the RockerModel for the application test template
    • getPath

      protected String getPath()
      Returns the path where the application Java file will be generated. The path is in the format "src/main/java/{packagePath}/Application.java", where {packagePath} is a placeholder that will be replaced with the actual package path during template rendering.
      Returns:
      the path to the application Java file