Skip to content

Commit

Permalink
Bug/revert 149 (#163)
Browse files Browse the repository at this point in the history
* Reverted Change #149 
* Minor version bumps
  • Loading branch information
SimonJPegg committed Sep 5, 2021
1 parent 4e4665d commit 668ef24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ updates:
ignore:
- dependency-name: "org.apache.maven:maven-plugin-api"
- dependency-name: "org.antipathy:*"
- dependency-name: "net.alchim31.maven:scala-maven-plugin:*"
- dependency-name: "org.scala-lang.modules:scala-xml_2.13:*"


18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

<properties>
<revision>0.SNAPSHOT</revision>
<version.commonsio>2.10.0</version.commonsio>
<version.commonsio>2.11.0</version.commonsio>
<version.commonslang>3.12.0</version.commonslang>
<version.commonsvalidator>1.7</version.commonsvalidator>
<version.java>1.8</version.java>
<version.maven.annotations>3.6.1</version.maven.annotations>
<version.maven>3.6.0</version.maven>
<version.scala.collection.compat>2.4.4</version.scala.collection.compat>
<version.mockito.core>3.11.2</version.mockito.core>
<version.scala.collection.compat>2.5.0</version.scala.collection.compat>
<version.mockito.core>3.12.4</version.mockito.core>
<version.scala.major>2.13</version.scala.major>
<version.scala.minor>.5</version.scala.minor>
<version.scala.xml>1.3.0</version.scala.xml>
Expand All @@ -62,7 +62,7 @@
<version.maven.plugin.resources>3.2.0</version.maven.plugin.resources>
<version.maven.plugin.scala>4.4.0</version.maven.plugin.scala> <!-- 2.12 build failing at higher version -->
<version.maven.plugin.scalatest>2.0.2</version.maven.plugin.scalatest>
<version.maven.plugin.scm>1.11.2</version.maven.plugin.scm>
<version.maven.plugin.scm>1.11.3</version.maven.plugin.scm>
<version.maven.plugin.scoverage>1.4.1</version.maven.plugin.scoverage>
<version.maven.plugin.source>3.2.1</version.maven.plugin.source>
<version.maven.plugin.surefire>2.22.2</version.maven.plugin.surefire>
Expand All @@ -86,11 +86,6 @@
<artifactId>scala-library</artifactId>
<version>${version.scala.major}${version.scala.minor}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${version.maven}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -131,6 +126,11 @@
<version>${version.scalatest}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_${version.scala.major}</artifactId>
Expand Down
74 changes: 14 additions & 60 deletions src/main/java/org/antipathy/mvn_scalafmt/FormatMojo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.antipathy.mvn_scalafmt;

import org.antipathy.mvn_scalafmt.model.Summary;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -11,9 +10,7 @@
import org.apache.maven.model.Repository;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
Expand All @@ -28,9 +25,9 @@ public class FormatMojo extends AbstractMojo {
private boolean skipTestSources;
@Parameter(property = "format.skipSources", defaultValue = "false")
private boolean skipSources;
@Parameter()
@Parameter(defaultValue = "${project.build.sourceDirectory}/../scala", required = true)
private List<File> sourceDirectories;
@Parameter()
@Parameter(defaultValue = "${project.build.testSourceDirectory}/../scala", required = true)
private List<File> testSourceDirectories;
@Parameter(property = "format.respectVersion", defaultValue = "false", required = true)
private boolean respectVersion;
Expand Down Expand Up @@ -65,13 +62,19 @@ private List<String> getRepositoriesUrls(List<Repository> repositories) {

public void execute() throws MojoExecutionException {

List<File> sources;
try {
sources = getSources();
} catch (IOException exception) {
throw new MojoExecutionException("Couldn't determine canonical sources", exception);
List<File> sources = new ArrayList<>();

if (!skipSources) {
sources.addAll(sourceDirectories);
} else {
getLog().warn("format.skipSources set, ignoring main directories");
}

if (!skipTestSources) {
sources.addAll(testSourceDirectories);
} else {
getLog().warn("format.skipTestSources set, ignoring validateOnly directories");
}
if (!sources.isEmpty()) {
try {

Expand All @@ -84,9 +87,7 @@ public void execute() throws MojoExecutionException {
showReformattedOnly,
branch,
project.getBasedir(),
useSpecifiedRepositories ?
getRepositoriesUrls(project.getRepositories()) :
new ArrayList<String>()
useSpecifiedRepositories ? getRepositoriesUrls(mavenRepositories) : new ArrayList<String>()
).format(sources);
getLog().info(result.toString());
if (validateOnly && result.unformattedFiles() != 0) {
Expand All @@ -100,51 +101,4 @@ public void execute() throws MojoExecutionException {
getLog().warn("No sources specified, skipping formatting");
}
}

private List<File> getSources() throws IOException {
HashSet<File> sources = new HashSet<>();
Build build = project.getBuild();

if (skipSources) {
getLog().warn("format.skipSources set, ignoring main directories");
} else if (sourceDirectories == null || sourceDirectories.isEmpty()) {
appendCanonicalSources(
sources,
project.getCompileSourceRoots(),
build.getSourceDirectory()
);
} else {
sources.addAll(sourceDirectories);
}

if (skipTestSources) {
getLog().warn("format.skipTestSources set, ignoring validateOnly directories");
} else if (testSourceDirectories == null || testSourceDirectories.isEmpty()) {
appendCanonicalSources(
sources,
project.getTestCompileSourceRoots(),
build.getTestSourceDirectory()
);
} else {
sources.addAll(testSourceDirectories);
}

return new ArrayList<>(sources);
}

private void appendCanonicalSources(
HashSet<File> sources,
List<String> sourceRoots,
String defaultSource
) throws IOException {
for (String source : sourceRoots) {
sources.add(getCanonicalFile(source));
}
sources.add(getCanonicalFile(defaultSource + "/../scala"));
}

private File getCanonicalFile(String relative) throws IOException {
return new File(project.getBasedir(), relative).getCanonicalFile();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import org.apache.maven.plugin.logging.Log

/** Class for writing formatted source files
*/
class FormattedFilesWriter(log: Log, val showReformattedOnly: Boolean)
extends FormatResultsWriter {
class FormattedFilesWriter(log: Log, val showReformattedOnly: Boolean) extends FormatResultsWriter {

protected val formattedDetail: String = "Correctly formatted"
protected val unformattedDetail: String = "Reformatted"
Expand Down

0 comments on commit 668ef24

Please sign in to comment.