Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/org/scalariform/ScalariformMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public class ScalariformMojo extends AbstractMojo {
*/
protected String baseDir;

/**
* Source file encoding, e.g. UTF-8. If not set, defaults to the platform default encoding.
*
* @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
*/
protected String encoding;

/**
* @parameter default-value=false
*/
Expand Down Expand Up @@ -122,7 +129,7 @@ public class ScalariformMojo extends AbstractMojo {

public void execute() throws MojoExecutionException {

MojoFormatter.format(baseDir, this.getLog(),
MojoFormatter.format(baseDir, encoding, this.getLog(),
alignParameters,
alignSingleLineCaseStatements,
alignSingleLineCaseStatements_maxArrowIndent,
Expand Down
9 changes: 6 additions & 3 deletions src/main/scala/org/scalariform/MojoFormatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.io.{ File, FilenameFilter, FileFilter }

import scala.collection.JavaConversions._

import scala.io.Source
import scala.io.{Codec, Source}

import org.apache.maven.plugin.logging.Log

Expand Down Expand Up @@ -41,6 +41,7 @@ object MojoFormatter {
}

def format(path: String,
sourceEncoding: String,
log: Log,
alignParameters: Boolean,
alignSingleLineCaseStatements: Boolean,
Expand Down Expand Up @@ -87,14 +88,16 @@ object MojoFormatter {

val files = findScalaFiles(path)

val sourceCodec = Option(sourceEncoding).map(Codec.apply)

var count = 0

files.foreach { file ⇒
try {
val original = Source.fromFile(file).mkString
val original = Source.fromFile(file)(sourceCodec getOrElse implicitly[Codec]).mkString
val formatted = ScalaFormatter.format(original, preferences)
if (original != formatted) {
writeText(file, formatted)
writeText(file, formatted, sourceCodec map (_.name))
count += 1
}
} catch {
Expand Down