Reworked logic.
This commit is contained in:
parent
c9e1ffd616
commit
1bba4e041f
7 changed files with 41 additions and 36 deletions
|
@ -1,3 +1,5 @@
|
|||
# Maven Local Repository plug-in for [Kobalt](http://beust.com/kobalt/home/index.html)
|
||||
|
||||
[](https://travis-ci.org/ethauvin/kobalt-maven-local)
|
||||
[](http://opensource.org/licenses/BSD-3-Clause) [](https://travis-ci.org/ethauvin/kobalt-maven-local)
|
||||
|
||||
The plug-in will detect the Maven Local Repository location, similarly to Gradle's [mavenLocal()](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html#org.gradle.api.artifacts.dsl.RepositoryHandler:mavenLocal()) repository handler.
|
|
@ -128,7 +128,7 @@
|
|||
<KobaltProjectSettings>
|
||||
<option name="autoDownloadKobalt" value="true" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="kobaltHome" value="$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.861" />
|
||||
<option name="kobaltHome" value="$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.862" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@ -407,13 +407,14 @@
|
|||
<component name="libraryTable">
|
||||
<library name="kobalt.jar">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.861/kobalt/wrapper/kobalt-0.861.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.862/kobalt/wrapper/kobalt-0.862.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.861/kobalt/wrapper/kobalt-0.861.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.861/kobalt/wrapper/kobalt-0.861.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.861/kobalt/wrapper/kobalt-0.861.jar!/" />
|
||||
<root url="jar://$USER_HOME$/.kobalt/wrapper/dist/kobalt-0.862/kobalt/wrapper/kobalt-0.862.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
|
|
|
@ -47,7 +47,7 @@ val p = project {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile("com.beust:$kobaltDependency:0.862")
|
||||
compile("com.beust:$kobaltDependency:0.863")
|
||||
compile("org.apache.maven:maven-settings-builder:3.3.9")
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
kobalt.version=0.862
|
||||
kobalt.version=0.864
|
|
@ -38,7 +38,8 @@ import com.beust.kobalt.misc.warn
|
|||
import org.apache.maven.settings.building.DefaultSettingsBuilderFactory
|
||||
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
|
||||
public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
||||
|
@ -46,39 +47,35 @@ public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
|||
|
||||
var mvnLocalPath: String? = null
|
||||
|
||||
override val name = "kobalt-maven-local"
|
||||
override val name = "Maven Local Repository"
|
||||
|
||||
init {
|
||||
if (System.getProperties().containsKey(MAVEN_LOCAL_REPO_PROPERTY)) {
|
||||
mvnLocalPath = System.getProperty(MAVEN_LOCAL_REPO_PROPERTY)
|
||||
} else {
|
||||
val p = Properties()
|
||||
Paths.get("local.properties").let { path ->
|
||||
if (path.toFile().exists()) {
|
||||
Files.newInputStream(path).use {
|
||||
p.load(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.containsKey(MAVEN_LOCAL_REPO_PROPERTY)) {
|
||||
mvnLocalPath = p.getProperty(MAVEN_LOCAL_REPO_PROPERTY)
|
||||
}
|
||||
}
|
||||
|
||||
if (mvnLocalPath.isNullOrBlank()) {
|
||||
val userHome = System.getProperty("user.home")
|
||||
val factory = DefaultSettingsBuilderFactory()
|
||||
val builder = factory.newInstance()
|
||||
val settings = DefaultSettingsBuildingRequest()
|
||||
|
||||
val localProps = Properties().apply {
|
||||
FileInputStream("local.properties").use { fis -> load(fis) }
|
||||
}
|
||||
settings.systemProperties = System.getProperties()
|
||||
settings.userSettingsFile = File(userHome, ".m2/settings.xml")
|
||||
|
||||
val sysProps = System.getProperties()
|
||||
|
||||
if (localProps.containsKey(MAVEN_LOCAL_REPO_PROPERTY)) {
|
||||
val mvnLocalProp = localProps.getProperty(MAVEN_LOCAL_REPO_PROPERTY, "")
|
||||
if (mvnLocalProp.length > 0) {
|
||||
mvnLocalPath = mvnLocalProp
|
||||
}
|
||||
} else if (sysProps.containsKey(MAVEN_LOCAL_REPO_PROPERTY)) {
|
||||
val mvnLocalProp = sysProps.getProperty(MAVEN_LOCAL_REPO_PROPERTY, "")
|
||||
if (mvnLocalProp.length > 0) {
|
||||
mvnLocalPath = mvnLocalProp
|
||||
}
|
||||
} else {
|
||||
settings.systemProperties = sysProps
|
||||
if (localProps.isNotEmpty()) {
|
||||
if (localProps.containsKey(MAVEN_LOCAL_REPO_PROPERTY)) {
|
||||
sysProps.put(MAVEN_LOCAL_REPO_PROPERTY, localProps.getProperty(MAVEN_LOCAL_REPO_PROPERTY))
|
||||
}
|
||||
}
|
||||
settings.userSettingsFile = File(System.getProperty("user.home"), ".m2/settings.xml")
|
||||
|
||||
val m2Home = System.getProperty("M2_HOME")
|
||||
val m2Home = System.getenv("M2_HOME")
|
||||
if (m2Home != null) {
|
||||
settings.globalSettingsFile = File(m2Home, "conf/settings.xml")
|
||||
}
|
||||
|
@ -86,11 +83,16 @@ public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
|||
val result = builder.build(settings)
|
||||
mvnLocalPath = result.effectiveSettings.localRepository
|
||||
|
||||
if (mvnLocalPath == null) {
|
||||
if (mvnLocalPath.isNullOrBlank()) {
|
||||
val path = File(userHome, ".m2/repository")
|
||||
if (path.isDirectory) {
|
||||
mvnLocalPath = path.absolutePath
|
||||
} else {
|
||||
warn("Unable to parse local maven settings.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun repoPath(currentPath: String): String {
|
||||
if (mvnLocalPath != null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<kobalt-plugin>
|
||||
<name>kobalt-maven-local</name>
|
||||
<name>Maven Local Repository</name>
|
||||
<plugin-actors>
|
||||
<class-name>net.thauvin.erik.kobalt.plugin.maven.local.MavenLocalPlugin</class-name>
|
||||
</plugin-actors>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue