Class BatonMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="baton-migrate",
          defaultPhase=VALIDATE,
          requiresDependencyResolution=COMPILE,
          threadSafe=true)
    public class BatonMojo
    extends org.apache.maven.plugin.AbstractMojo
    A Maven plugin that allows migration logic to be executed against a Maven module based on a classpath-provided migrations. These are intended to run every time the build runs such that they perform a migration or no-op appropriately.
    • Field Detail

      • project

        @Parameter(defaultValue="${project}",
                   readonly=true,
                   required=true)
        protected org.apache.maven.project.MavenProject project
        Enables access to the runtime properties associated with the project's POM configuration against which Baton is being executed.
      • baseDirectory

        @Parameter(property="baton.baseDirectory",
                   required=true,
                   defaultValue="${project.basedir}")
        protected File baseDirectory
        Base directory in which to operate.
      • sourceDirectory

        @Parameter(property="baton.sourceDirectory",
                   required=true,
                   defaultValue="${project.basedir}/src")
        protected File sourceDirectory
        Folder in which source files are located.
      • testDirectory

        @Parameter(property="baton.testDirectory",
                   required=false)
        protected File testDirectory
        Folder in which test files are located, if not already covered by sourceDirectory (e.g., with typical python project standards).
      • fileSets

        @Parameter
        protected org.apache.maven.shared.model.fileset.FileSet[] fileSets
        A list of fileSet rules to select files and directories. Will be defaulted based on project information if not specified.
      • migrationsFileName

        @Parameter(property="baton.migrationsConfigurationFile",
                   required=false,
                   defaultValue="migrations.json")
        protected String migrationsFileName
        The configurations file name to look for in the classpath (all matches will be used). Defaults to migrations.json.
      • deactivateMigrations

        @Parameter(property="baton.deactivateMigrations",
                   required=false)
        protected Set<String> deactivateMigrations
        Allows a list of migration names that should be deactivated. This provides an opportunity to turn off specific migrations that don't work as desired or a project just doesn't want in a "last mile" fashion.
      • backupOriginalMigratedFiles

        @Parameter(property="baton.backupOriginalMigratedFiles",
                   required=false,
                   defaultValue="true")
        protected boolean backupOriginalMigratedFiles
        Allows backup of original files prior to migration to be turned off.
      • backupCustomLocation

        @Parameter(property="baton.backupCustomLocation",
                   required=false)
        protected String backupCustomLocation
        Customizes the location where backup of original files prior to migration is performed. By default, the system temp directory is used.
      • numberOfBackupsToKeep

        @Parameter(property="baton.numberOfBackupsToKeep",
                   required=true,
                   defaultValue="10")
        protected int numberOfBackupsToKeep
        Allows the number of backups for original files prior to migration to be customized. This will impact the number of backups, not the total number. So if set to 5, you will have 5 *prior* backup files as well as one active backup. This is based on the file rotation library works.
    • Constructor Detail

      • BatonMojo

        public BatonMojo()
    • Method Detail

      • initializeObjectMapper

        protected com.fasterxml.jackson.databind.ObjectMapper initializeObjectMapper()
      • defaultFileSets

        protected void defaultFileSets()
      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • isActive

        protected boolean isActive​(MigrationTarget migrationTarget)
      • loadMigrations

        protected void loadMigrations()
        Scans the classpath for any migrations.json files and loads all defined MigrationTarget configurations.
      • loadMigrationsJson

        protected Map<String,​MigrationTarget> loadMigrationsJson​(File migrationsFile,
                                                                       Map<String,​MigrationTarget> migrationTargets)
        Loads all MigrationTargets contained within the given InputStream, which is expected to reference the desired migrations.json file to load.
        Parameters:
        migrationsFile - File referencing migrations.json file desired to load.
        migrationTargets - the migration targets already loaded to this point
        Returns:
        Map containing all loaded MigrationTargets with their corresponding name as the map key.
      • getFileSetsForTarget

        protected org.apache.maven.shared.model.fileset.FileSet[] getFileSetsForTarget​(MigrationTarget target)