Skip to content

Commit 668ef24

Browse files
authored
Bug/revert 149 (#163)
* Reverted Change #149 * Minor version bumps
1 parent 4e4665d commit 668ef24

File tree

4 files changed

+26
-71
lines changed

4 files changed

+26
-71
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ updates:
99
ignore:
1010
- dependency-name: "org.apache.maven:maven-plugin-api"
1111
- dependency-name: "org.antipathy:*"
12+
- dependency-name: "net.alchim31.maven:scala-maven-plugin:*"
13+
- dependency-name: "org.scala-lang.modules:scala-xml_2.13:*"
1214

1315

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535

3636
<properties>
3737
<revision>0.SNAPSHOT</revision>
38-
<version.commonsio>2.10.0</version.commonsio>
38+
<version.commonsio>2.11.0</version.commonsio>
3939
<version.commonslang>3.12.0</version.commonslang>
4040
<version.commonsvalidator>1.7</version.commonsvalidator>
4141
<version.java>1.8</version.java>
4242
<version.maven.annotations>3.6.1</version.maven.annotations>
4343
<version.maven>3.6.0</version.maven>
44-
<version.scala.collection.compat>2.4.4</version.scala.collection.compat>
45-
<version.mockito.core>3.11.2</version.mockito.core>
44+
<version.scala.collection.compat>2.5.0</version.scala.collection.compat>
45+
<version.mockito.core>3.12.4</version.mockito.core>
4646
<version.scala.major>2.13</version.scala.major>
4747
<version.scala.minor>.5</version.scala.minor>
4848
<version.scala.xml>1.3.0</version.scala.xml>
@@ -62,7 +62,7 @@
6262
<version.maven.plugin.resources>3.2.0</version.maven.plugin.resources>
6363
<version.maven.plugin.scala>4.4.0</version.maven.plugin.scala> <!-- 2.12 build failing at higher version -->
6464
<version.maven.plugin.scalatest>2.0.2</version.maven.plugin.scalatest>
65-
<version.maven.plugin.scm>1.11.2</version.maven.plugin.scm>
65+
<version.maven.plugin.scm>1.11.3</version.maven.plugin.scm>
6666
<version.maven.plugin.scoverage>1.4.1</version.maven.plugin.scoverage>
6767
<version.maven.plugin.source>3.2.1</version.maven.plugin.source>
6868
<version.maven.plugin.surefire>2.22.2</version.maven.plugin.surefire>
@@ -86,11 +86,6 @@
8686
<artifactId>scala-library</artifactId>
8787
<version>${version.scala.major}${version.scala.minor}</version>
8888
</dependency>
89-
<dependency>
90-
<groupId>org.apache.maven</groupId>
91-
<artifactId>maven-core</artifactId>
92-
<version>${version.maven}</version>
93-
</dependency>
9489
<dependency>
9590
<groupId>org.apache.maven</groupId>
9691
<artifactId>maven-plugin-api</artifactId>
@@ -131,6 +126,11 @@
131126
<version>${version.scalatest}</version>
132127
<scope>test</scope>
133128
</dependency>
129+
<dependency>
130+
<groupId>org.apache.maven</groupId>
131+
<artifactId>maven-project</artifactId>
132+
<version>2.2.1</version>
133+
</dependency>
134134
<dependency>
135135
<groupId>org.scala-lang.modules</groupId>
136136
<artifactId>scala-xml_${version.scala.major}</artifactId>
Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.antipathy.mvn_scalafmt;
22

33
import org.antipathy.mvn_scalafmt.model.Summary;
4-
import org.apache.maven.model.Build;
54
import org.apache.maven.plugin.AbstractMojo;
65
import org.apache.maven.plugin.MojoExecutionException;
76
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -11,9 +10,7 @@
1110
import org.apache.maven.model.Repository;
1211

1312
import java.io.File;
14-
import java.io.IOException;
1513
import java.util.ArrayList;
16-
import java.util.HashSet;
1714
import java.util.List;
1815

1916
/**
@@ -28,9 +25,9 @@ public class FormatMojo extends AbstractMojo {
2825
private boolean skipTestSources;
2926
@Parameter(property = "format.skipSources", defaultValue = "false")
3027
private boolean skipSources;
31-
@Parameter()
28+
@Parameter(defaultValue = "${project.build.sourceDirectory}/../scala", required = true)
3229
private List<File> sourceDirectories;
33-
@Parameter()
30+
@Parameter(defaultValue = "${project.build.testSourceDirectory}/../scala", required = true)
3431
private List<File> testSourceDirectories;
3532
@Parameter(property = "format.respectVersion", defaultValue = "false", required = true)
3633
private boolean respectVersion;
@@ -65,13 +62,19 @@ private List<String> getRepositoriesUrls(List<Repository> repositories) {
6562

6663
public void execute() throws MojoExecutionException {
6764

68-
List<File> sources;
69-
try {
70-
sources = getSources();
71-
} catch (IOException exception) {
72-
throw new MojoExecutionException("Couldn't determine canonical sources", exception);
65+
List<File> sources = new ArrayList<>();
66+
67+
if (!skipSources) {
68+
sources.addAll(sourceDirectories);
69+
} else {
70+
getLog().warn("format.skipSources set, ignoring main directories");
7371
}
7472

73+
if (!skipTestSources) {
74+
sources.addAll(testSourceDirectories);
75+
} else {
76+
getLog().warn("format.skipTestSources set, ignoring validateOnly directories");
77+
}
7578
if (!sources.isEmpty()) {
7679
try {
7780

@@ -84,9 +87,7 @@ public void execute() throws MojoExecutionException {
8487
showReformattedOnly,
8588
branch,
8689
project.getBasedir(),
87-
useSpecifiedRepositories ?
88-
getRepositoriesUrls(project.getRepositories()) :
89-
new ArrayList<String>()
90+
useSpecifiedRepositories ? getRepositoriesUrls(mavenRepositories) : new ArrayList<String>()
9091
).format(sources);
9192
getLog().info(result.toString());
9293
if (validateOnly && result.unformattedFiles() != 0) {
@@ -100,51 +101,4 @@ public void execute() throws MojoExecutionException {
100101
getLog().warn("No sources specified, skipping formatting");
101102
}
102103
}
103-
104-
private List<File> getSources() throws IOException {
105-
HashSet<File> sources = new HashSet<>();
106-
Build build = project.getBuild();
107-
108-
if (skipSources) {
109-
getLog().warn("format.skipSources set, ignoring main directories");
110-
} else if (sourceDirectories == null || sourceDirectories.isEmpty()) {
111-
appendCanonicalSources(
112-
sources,
113-
project.getCompileSourceRoots(),
114-
build.getSourceDirectory()
115-
);
116-
} else {
117-
sources.addAll(sourceDirectories);
118-
}
119-
120-
if (skipTestSources) {
121-
getLog().warn("format.skipTestSources set, ignoring validateOnly directories");
122-
} else if (testSourceDirectories == null || testSourceDirectories.isEmpty()) {
123-
appendCanonicalSources(
124-
sources,
125-
project.getTestCompileSourceRoots(),
126-
build.getTestSourceDirectory()
127-
);
128-
} else {
129-
sources.addAll(testSourceDirectories);
130-
}
131-
132-
return new ArrayList<>(sources);
133-
}
134-
135-
private void appendCanonicalSources(
136-
HashSet<File> sources,
137-
List<String> sourceRoots,
138-
String defaultSource
139-
) throws IOException {
140-
for (String source : sourceRoots) {
141-
sources.add(getCanonicalFile(source));
142-
}
143-
sources.add(getCanonicalFile(defaultSource + "/../scala"));
144-
}
145-
146-
private File getCanonicalFile(String relative) throws IOException {
147-
return new File(project.getBasedir(), relative).getCanonicalFile();
148-
}
149-
150104
}

src/main/scala/org/antipathy/mvn_scalafmt/io/FormattedFilesWriter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import org.apache.maven.plugin.logging.Log
77

88
/** Class for writing formatted source files
99
*/
10-
class FormattedFilesWriter(log: Log, val showReformattedOnly: Boolean)
11-
extends FormatResultsWriter {
10+
class FormattedFilesWriter(log: Log, val showReformattedOnly: Boolean) extends FormatResultsWriter {
1211

1312
protected val formattedDetail: String = "Correctly formatted"
1413
protected val unformattedDetail: String = "Reformatted"

0 commit comments

Comments
 (0)