Skip to content

Commit 47b3579

Browse files
authored
Initial version (SimonJPegg#1)
* develop: added gitignore * develop: added *.iml to gitignore * develop: added pom * develop: initial version * develop: added readme * develop: added tests
1 parent 5f01760 commit 47b3579

File tree

7 files changed

+424
-0
lines changed

7 files changed

+424
-0
lines changed

.gitignore

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
### Intellij ###
2+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
3+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
4+
*.iml
5+
6+
# User-specific stuff:
7+
.idea/**/workspace.xml
8+
.idea/**/tasks.xml
9+
.idea/dictionaries
10+
11+
# Sensitive or high-churn files:
12+
.idea/**/dataSources/
13+
.idea/**/dataSources.ids
14+
.idea/**/dataSources.xml
15+
.idea/**/dataSources.local.xml
16+
.idea/**/sqlDataSources.xml
17+
.idea/**/dynamic.xml
18+
.idea/**/uiDesigner.xml
19+
20+
# Gradle:
21+
.idea/**/gradle.xml
22+
.idea/**/libraries
23+
24+
# Mongo Explorer plugin:
25+
.idea/**/mongoSettings.xml
26+
27+
## File-based project format:
28+
*.iws
29+
30+
## Plugin-specific files:
31+
32+
# IntelliJ
33+
/out/
34+
35+
# mpeltonen/sbt-idea plugin
36+
.idea_modules/
37+
38+
# JIRA plugin
39+
atlassian-ide-plugin.xml
40+
41+
# Cursive Clojure plugin
42+
.idea/replstate.xml
43+
44+
# Crashlytics plugin (for Android Studio and IntelliJ)
45+
com_crashlytics_export_strings.xml
46+
crashlytics.properties
47+
crashlytics-build.properties
48+
fabric.properties
49+
50+
### Intellij Patch ###
51+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
52+
53+
# *.iml
54+
# modules.xml
55+
# .idea/misc.xml
56+
# *.ipr
57+
58+
### Java ###
59+
# Compiled class file
60+
*.class
61+
62+
# Log file
63+
*.log
64+
65+
# BlueJ files
66+
*.ctxt
67+
68+
# Mobile Tools for Java (J2ME)
69+
.mtj.tmp/
70+
71+
# Package Files #
72+
*.jar
73+
*.war
74+
*.ear
75+
*.zip
76+
*.tar.gz
77+
*.rar
78+
79+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
80+
hs_err_pid*
81+
82+
### Maven ###
83+
target/
84+
pom.xml.tag
85+
pom.xml.releaseBackup
86+
pom.xml.versionsBackup
87+
pom.xml.next
88+
release.properties
89+
dependency-reduced-pom.xml
90+
buildNumber.properties
91+
.mvn/timing.properties
92+
93+
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
94+
!/.mvn/wrapper/maven-wrapper.jar
95+
96+
### Scala ###

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Synopsis
2+
3+
This is a wrapper that allows you to use the [Scalafmt](https://github.com/olafurpg/scalafmt/) formatter in Mvn.
4+
current Scalafmt version is 0.6.5
5+
6+
## Usage
7+
8+
To include it into your pom.xml, just specify some lines as below in the phase you want to format your code:
9+
10+
```xml
11+
<plugin>
12+
<groupId>org.antipathy</groupId>
13+
<artifactId>mvn-scalafmt</artifactId>
14+
<version>0.1</version>
15+
<configuration>
16+
<configLocation>${project.basedir}/path/to/scalafmt.conf</configLocation>
17+
</configuration>
18+
<executions>
19+
<execution>
20+
<phase>validate</phase>
21+
<goals>
22+
<goal>format</goal>
23+
</goals>
24+
</execution>
25+
</executions>
26+
</plugin>
27+
```
28+
29+
##Debug
30+
If you are finding an strange behaviour with the plugin you can check the exit from scalafmt using -X mvn option which provides Debug log.
31+
Also you can remove from your ~/.scalafmt the jar that is copied in order to use the plugin from maven.

pom.xml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.antipathy</groupId>
5+
<artifactId>mvn-scalafmt</artifactId>
6+
<packaging>maven-plugin</packaging>
7+
<version>0.1</version>
8+
<name>Scalafmt Maven Plugin</name>
9+
<description>Maven plugin for ScalaFmt</description>
10+
<url>https://github.com/SimonJPegg/mvn_scalafmt</url>
11+
12+
<licenses>
13+
<license>
14+
<name>Apache License, Version 2.0</name>
15+
<url>https://github.com/SimonJPegg/mvn_scalafmt/blob/master/LICENSE.md</url>
16+
<distribution>repo</distribution>
17+
</license>
18+
</licenses>
19+
20+
<developers>
21+
<developer>
22+
<name>Ciaran Kearney</name>
23+
<email>[email protected]</email>
24+
<organization>Antipathy.org</organization>
25+
<organizationUrl>http://www.antipathy.org</organizationUrl>
26+
</developer>
27+
</developers>
28+
29+
<scm>
30+
<url>https://github.com/SimonJPegg/mvn_scalafmt</url>
31+
<connection>scm:git:git://github.com/SimonJPegg/mvn_scalafmt.git</connection>
32+
<developerConnection>scm:git:[email protected]/SimonJPegg/mvn_scalafmt.git</developerConnection>
33+
</scm>
34+
35+
<properties>
36+
<maven.version>3.3.9</maven.version>
37+
<maven.annotations.version>3.4</maven.annotations.version>
38+
<scala.version>2.11.2</scala.version>
39+
<scala.major.version>2.11</scala.major.version>
40+
<scalafmt.version>0.6.5</scalafmt.version>
41+
<commonslang.verson>2.6</commonslang.verson>
42+
<scala-maven-plugin.version>3.2.1</scala-maven-plugin.version>
43+
<maven-compiler-plugin.version>2.0.2</maven-compiler-plugin.version>
44+
<java.version>1.7</java.version>
45+
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
46+
<nexus-staging-maven-plugin.version>1.6.3</nexus-staging-maven-plugin.version>
47+
<scalatest.version>2.2.4</scalatest.version>
48+
</properties>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>org.scala-lang</groupId>
53+
<artifactId>scala-library</artifactId>
54+
<version>${scala.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.apache.maven</groupId>
58+
<artifactId>maven-plugin-api</artifactId>
59+
<version>${maven.version}</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.apache.maven.plugin-tools</groupId>
63+
<artifactId>maven-plugin-annotations</artifactId>
64+
<version>${maven.annotations.version}</version>
65+
<scope>provided</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.geirsson</groupId>
69+
<artifactId>scalafmt-core_${scala.major.version}</artifactId>
70+
<version>${scalafmt.version}</version>
71+
<scope>compile</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.geirsson</groupId>
75+
<artifactId>scalafmt-cli_${scala.major.version}</artifactId>
76+
<version>${scalafmt.version}</version>
77+
<scope>compile</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>commons-lang</groupId>
81+
<artifactId>commons-lang</artifactId>
82+
<version>${commonslang.verson}</version>
83+
<scope>compile</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.scalatest</groupId>
87+
<artifactId>scalatest_${scala.major.version}</artifactId>
88+
<version>${scalatest.version}</version>
89+
<scope>test</scope>
90+
</dependency>
91+
</dependencies>
92+
93+
<distributionManagement>
94+
<snapshotRepository>
95+
<id>ossrh</id>
96+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
97+
</snapshotRepository>
98+
<repository>
99+
<id>ossrh</id>
100+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
101+
</repository>
102+
</distributionManagement>
103+
104+
<profiles>
105+
<profile>
106+
<id>release</id>
107+
<activation>
108+
<activeByDefault>false</activeByDefault>
109+
</activation>
110+
<build>
111+
<pluginManagement>
112+
<plugins>
113+
<plugin>
114+
<groupId>net.alchim31.maven</groupId>
115+
<artifactId>scala-maven-plugin</artifactId>
116+
<version>${scala-maven-plugin.version}</version>
117+
</plugin>
118+
<plugin>
119+
<groupId>org.apache.maven.plugins</groupId>
120+
<artifactId>maven-compiler-plugin</artifactId>
121+
<version>${maven-compiler-plugin.version}</version>
122+
<configuration>
123+
<source>${java.version}</source>
124+
<target>${java.version}</target>
125+
</configuration>
126+
</plugin>
127+
</plugins>
128+
</pluginManagement>
129+
<plugins>
130+
<plugin>
131+
<groupId>net.alchim31.maven</groupId>
132+
<artifactId>scala-maven-plugin</artifactId>
133+
<executions>
134+
<execution>
135+
<id>scala-compile-first</id>
136+
<phase>process-resources</phase>
137+
<goals>
138+
<goal>add-source</goal>
139+
<goal>compile</goal>
140+
</goals>
141+
</execution>
142+
<execution>
143+
<id>scala-test-compile</id>
144+
<phase>process-test-resources</phase>
145+
<goals>
146+
<goal>testCompile</goal>
147+
</goals>
148+
</execution>
149+
</executions>
150+
</plugin>
151+
<plugin>
152+
<groupId>org.apache.maven.plugins</groupId>
153+
<artifactId>maven-gpg-plugin</artifactId>
154+
<version>${maven-gpg-plugin.version}</version>
155+
<executions>
156+
<execution>
157+
<id>sign-artifacts</id>
158+
<phase>verify</phase>
159+
<goals>
160+
<goal>sign</goal>
161+
</goals>
162+
</execution>
163+
</executions>
164+
</plugin>
165+
166+
<plugin>
167+
<groupId>org.sonatype.plugins</groupId>
168+
<artifactId>nexus-staging-maven-plugin</artifactId>
169+
<version>${nexus-staging-maven-plugin.version}</version>
170+
<extensions>true</extensions>
171+
<configuration>
172+
<serverId>ossrh</serverId>
173+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
174+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
175+
</configuration>
176+
</plugin>
177+
178+
<plugin>
179+
<groupId>org.apache.maven.plugins</groupId>
180+
<artifactId>maven-source-plugin</artifactId>
181+
<executions>
182+
<execution>
183+
<id>attach-sources</id>
184+
<goals>
185+
<goal>jar</goal>
186+
</goals>
187+
</execution>
188+
</executions>
189+
</plugin>
190+
<plugin>
191+
<groupId>org.apache.maven.plugins</groupId>
192+
<artifactId>maven-javadoc-plugin</artifactId>
193+
<executions>
194+
<execution>
195+
<id>attach-javadocs</id>
196+
<goals>
197+
<goal>jar</goal>
198+
</goals>
199+
</execution>
200+
</executions>
201+
<configuration>
202+
<additionalparam>-Xdoclint:none</additionalparam>
203+
</configuration>
204+
</plugin>
205+
</plugins>
206+
</build>
207+
</profile>
208+
</profiles>
209+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.antipathy.scalafmtmvn;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.apache.maven.plugin.AbstractMojo;
5+
import org.apache.maven.plugin.MojoExecutionException;
6+
import org.apache.maven.plugins.annotations.Mojo;
7+
import org.apache.maven.plugins.annotations.Parameter;
8+
9+
/**
10+
* Get the location of the config file and pass to Formatter
11+
*/
12+
@Mojo(name = "format")
13+
public class FormatMojo extends AbstractMojo {
14+
15+
@Parameter(property="format.configLocation",defaultValue="")
16+
private String configLocation;
17+
18+
public void execute() throws MojoExecutionException {
19+
if(StringUtils.isEmpty(configLocation)) {
20+
throw new MojoExecutionException("No configuration file specified");
21+
} else {
22+
getLog().info("Formatting with config: " + configLocation);
23+
try {
24+
Formatter.format(configLocation);
25+
} catch (Exception e) {
26+
throw new MojoExecutionException("Error formatting Scala files", e);
27+
}
28+
}
29+
}
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.antipathy.scalafmtmvn
2+
3+
import org.scalafmt.Error.UnableToParseCliOptions
4+
import org.scalafmt.cli.{ Cli, CliOptions }
5+
6+
/**
7+
* Gets calls scalafmt with the config file specified at configLocation
8+
*/
9+
object Formatter {
10+
11+
/**
12+
* Gets calls scalafmt with the config file specified at configLocation
13+
* @param configLocation the location of a scalafmt.conf file
14+
*/
15+
def format(configLocation: String): Unit =
16+
Cli.getConfig(Array[String]("--config", configLocation), CliOptions.default) match {
17+
case Some(x) => Cli.run(x)
18+
case None =>
19+
throw new IllegalArgumentException(s"unable to pase config at $configLocation",
20+
UnableToParseCliOptions)
21+
}
22+
}

0 commit comments

Comments
 (0)