Skip to content

Commit

Permalink
fix: dependencies are correctly resolved after scalafmt is executed F…
Browse files Browse the repository at this point in the history
…ixes #32
  • Loading branch information
augi committed Jan 3, 2020
1 parent 049720a commit 23dcc6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.SourceSet
import org.scalafmt.interfaces.Scalafmt

import java.util.stream.Collectors

class ScalafmtFormatBase extends DefaultTask {
SourceSet sourceSet
ClassLoader cl = this.class.getClassLoader()
Expand All @@ -24,7 +22,7 @@ class ScalafmtFormatBase extends DefaultTask {
def configpath = ConfigFactory.get(logger,project,pluginExtension.configFilePath)
def misformattedFiles = new ArrayList<String>()

def formatter = globalFormatter.withMavenRepositories(repositories())
def formatter = globalFormatter.withMavenRepositories(*getRepositoriesUrls())

sourceSet.allSource.filter { File f -> canBeFormatted(f) }.each { File f ->
String contents = f.text
Expand All @@ -44,10 +42,8 @@ class ScalafmtFormatBase extends DefaultTask {
}
}

private String[] repositories() {
project.getRepositories().stream().map { repository ->
repository.properties.get("url").toString()
}.collect(Collectors.toList()).toArray(new String[0])
private List<String> getRepositoriesUrls() {
project.repositories.findAll { it.hasProperty('url') }.collect { it.url.toString() }
}

boolean canBeFormatted(File file) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cz.alenkacz.gradle.scalafmt

import org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Ignore
import spock.lang.Specification

import java.nio.file.Files
Expand Down Expand Up @@ -76,8 +76,7 @@ class ScalafmtCheckTaskTest extends Specification {
noExceptionThrown()
}

@Ignore
def "not fail Scala compilation with custom repository"() {
def "not fail on ArtifactResolveException with custom repository"() {
given:
def testProject = ProjectMother.basicProjectWithCorrectlyFormattedFile()
def project = ProjectBuilder.builder().withProjectDir(testProject.projectRoot).build()
Expand All @@ -95,6 +94,7 @@ class ScalafmtCheckTaskTest extends Specification {
project.tasks.compileScala.compile()

then:
noExceptionThrown()
thrown IllegalStateException // because compileScala is not fully configured
// notThrown DefaultLenientConfiguration.ArtifactResolveException // Only one exception condition is allowed per 'then' block
}
}

0 comments on commit 23dcc6b

Please sign in to comment.