Class FormatterMojo

  • All Implemented Interfaces:
    net.revelc.code.formatter.ConfigurationSource, org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    ValidateMojo

    @Mojo(name="format",
          defaultPhase=PROCESS_SOURCES,
          requiresProject=true,
          threadSafe=true)
    public class FormatterMojo
    extends org.apache.maven.plugin.AbstractMojo
    implements net.revelc.code.formatter.ConfigurationSource
    A Maven plugin mojo to format Java source code using the Eclipse code formatter. Mojo parameters allow customizing formatting by specifying the config XML file, line endings, compiler version, and source code locations. Reformatting source files is avoided using an sha512 hash of the content, comparing to the original hash to the hash after formatting and a cached hash.
    Author:
    jecki, Matt Blanchette, marvin.froeder
    • Constructor Detail

      • FormatterMojo

        public FormatterMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Execute.
        Specified by:
        execute in interface org.apache.maven.plugin.Mojo
        Throws:
        org.apache.maven.plugin.MojoExecutionException - the mojo execution exception
        org.apache.maven.plugin.MojoFailureException - the mojo failure exception
        See Also:
        Mojo.execute()
      • doFormatFile

        protected void doFormatFile​(File file,
                                    net.revelc.code.formatter.FormatterMojo.ResultCollector rc,
                                    Properties hashCache,
                                    String basedirPath,
                                    boolean dryRun)
                             throws IOException,
                                    org.eclipse.jface.text.BadLocationException,
                                    org.apache.maven.plugin.MojoFailureException,
                                    org.apache.maven.plugin.MojoExecutionException
        Format individual file.
        Parameters:
        file - the file
        rc - the rc
        hashCache - the hash cache
        basedirPath - the basedir path
        dryRun - the dry run
        Throws:
        IOException - Signals that an I/O exception has occurred.
        org.eclipse.jface.text.BadLocationException - the bad location exception
        org.apache.maven.plugin.MojoFailureException - the mojo failure exception
        org.apache.maven.plugin.MojoExecutionException - the mojo execution exception
      • getCompilerSources

        public String getCompilerSources()
        Specified by:
        getCompilerSources in interface net.revelc.code.formatter.ConfigurationSource
      • getCompilerCompliance

        public String getCompilerCompliance()
        Specified by:
        getCompilerCompliance in interface net.revelc.code.formatter.ConfigurationSource
      • getCompilerCodegenTargetPlatform

        public String getCompilerCodegenTargetPlatform()
        Specified by:
        getCompilerCodegenTargetPlatform in interface net.revelc.code.formatter.ConfigurationSource
      • getTargetDirectory

        public File getTargetDirectory()
        Specified by:
        getTargetDirectory in interface net.revelc.code.formatter.ConfigurationSource
      • getEncoding

        public Charset getEncoding()
        Specified by:
        getEncoding in interface net.revelc.code.formatter.ConfigurationSource