Package net.revelc.code.formatter
Class FormatterMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- net.revelc.code.formatter.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 Summary
Constructors Constructor Description FormatterMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFormatFile(File file, net.revelc.code.formatter.FormatterMojo.ResultCollector rc, Properties hashCache, String basedirPath, boolean dryRun)
Format individual file.void
execute()
Execute.String
getCompilerCodegenTargetPlatform()
String
getCompilerCompliance()
String
getCompilerSources()
Charset
getEncoding()
File
getTargetDirectory()
-
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
-
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
Execute.- Specified by:
execute
in interfaceorg.apache.maven.plugin.Mojo
- Throws:
org.apache.maven.plugin.MojoExecutionException
- the mojo execution exceptionorg.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 filerc
- the rchashCache
- the hash cachebasedirPath
- the basedir pathdryRun
- the dry run- Throws:
IOException
- Signals that an I/O exception has occurred.org.eclipse.jface.text.BadLocationException
- the bad location exceptionorg.apache.maven.plugin.MojoFailureException
- the mojo failure exceptionorg.apache.maven.plugin.MojoExecutionException
- the mojo execution exception
-
getCompilerSources
public String getCompilerSources()
- Specified by:
getCompilerSources
in interfacenet.revelc.code.formatter.ConfigurationSource
-
getCompilerCompliance
public String getCompilerCompliance()
- Specified by:
getCompilerCompliance
in interfacenet.revelc.code.formatter.ConfigurationSource
-
getCompilerCodegenTargetPlatform
public String getCompilerCodegenTargetPlatform()
- Specified by:
getCompilerCodegenTargetPlatform
in interfacenet.revelc.code.formatter.ConfigurationSource
-
getTargetDirectory
public File getTargetDirectory()
- Specified by:
getTargetDirectory
in interfacenet.revelc.code.formatter.ConfigurationSource
-
getEncoding
public Charset getEncoding()
- Specified by:
getEncoding
in interfacenet.revelc.code.formatter.ConfigurationSource
-
-