diff --git a/ktlint/pom.xml b/ktlint/pom.xml index b1db3ba81d..f49c44b881 100644 --- a/ktlint/pom.xml +++ b/ktlint/pom.xml @@ -93,6 +93,21 @@ + + org.apache.maven + maven-model + ${aether.maven.provider.version} + + + org.apache.maven + maven-model-builder + ${aether.maven.provider.version} + + + org.apache.maven + maven-repository-metadata + ${aether.maven.provider.version} + com.google.guava guava diff --git a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt index b38b8bf34b..593b2408a2 100644 --- a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt +++ b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt @@ -40,6 +40,7 @@ import java.nio.file.Paths import java.security.MessageDigest import java.util.ArrayList import java.util.Arrays +import java.util.LinkedHashMap import java.util.NoSuchElementException import java.util.ResourceBundle import java.util.Scanner @@ -238,7 +239,7 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s } val start = System.currentTimeMillis() // load 3rd party ruleset(s) (if any) - val dependencyResolver by lazy { buildDependencyResolver() } + val dependencyResolver = lazy(LazyThreadSafetyMode.NONE) { buildDependencyResolver() } if (!rulesets.isEmpty()) { loadJARs(dependencyResolver, rulesets) } @@ -333,7 +334,7 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s } } - private fun loadReporter(dependencyResolver: MavenDependencyResolver): Reporter { + private fun loadReporter(dependencyResolver: Lazy): Reporter { data class ReporterTemplate(val id: String, val config: Map, var output: String?) val tpls = (if (reporters.isEmpty()) listOf("plain") else reporters) .map { reporter -> @@ -543,14 +544,14 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s return dependencyResolver } - private fun loadJARs(dependencyResolver: MavenDependencyResolver, artifacts: List) { + private fun loadJARs(dependencyResolver: Lazy, artifacts: List) { (ClassLoader.getSystemClassLoader() as java.net.URLClassLoader) .addURLs(artifacts.flatMap { artifact -> if (debug) { System.err.println("[DEBUG] Resolving $artifact") } val result = try { - dependencyResolver.resolve(DefaultArtifact(artifact)).map { it.toURI().toURL() } + dependencyResolver.value.resolve(DefaultArtifact(artifact)).map { it.toURI().toURL() } } catch (e: IllegalArgumentException) { val file = File(expandTilde(artifact)) if (!file.exists()) { diff --git a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/internal/MavenDependencyResolver.kt b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/internal/MavenDependencyResolver.kt index a01f015fcc..9d7466671a 100644 --- a/ktlint/src/main/kotlin/com/github/shyiko/ktlint/internal/MavenDependencyResolver.kt +++ b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/internal/MavenDependencyResolver.kt @@ -8,6 +8,7 @@ import org.eclipse.aether.artifact.Artifact import org.eclipse.aether.collection.CollectRequest import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory import org.eclipse.aether.graph.Dependency +import org.eclipse.aether.impl.DefaultServiceLocator import org.eclipse.aether.repository.LocalRepository import org.eclipse.aether.repository.RemoteRepository import org.eclipse.aether.repository.RepositoryPolicy @@ -32,6 +33,11 @@ class MavenDependencyResolver(baseDir: File, val repositories: Iterable?, impl: Class<*>?, ex: Throwable) { + throw ex + } + }) repoSystem = locator.getService(RepositorySystem::class.java) session = MavenRepositorySystemUtils.newSession() session.localRepositoryManager = repoSystem.newLocalRepositoryManager(session, LocalRepository(baseDir))