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)
|
# 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>
|
<KobaltProjectSettings>
|
||||||
<option name="autoDownloadKobalt" value="true" />
|
<option name="autoDownloadKobalt" value="true" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<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">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
@ -407,13 +407,14 @@
|
||||||
<component name="libraryTable">
|
<component name="libraryTable">
|
||||||
<library name="kobalt.jar">
|
<library name="kobalt.jar">
|
||||||
<CLASSES>
|
<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>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<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.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>
|
</SOURCES>
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -47,7 +47,7 @@ val p = project {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile("com.beust:$kobaltDependency:0.862")
|
compile("com.beust:$kobaltDependency:0.863")
|
||||||
compile("org.apache.maven:maven-settings-builder:3.3.9")
|
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.DefaultSettingsBuilderFactory
|
||||||
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest
|
import org.apache.maven.settings.building.DefaultSettingsBuildingRequest
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
||||||
|
@ -46,39 +47,35 @@ public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
||||||
|
|
||||||
var mvnLocalPath: String? = null
|
var mvnLocalPath: String? = null
|
||||||
|
|
||||||
override val name = "kobalt-maven-local"
|
override val name = "Maven Local Repository"
|
||||||
|
|
||||||
init {
|
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 factory = DefaultSettingsBuilderFactory()
|
||||||
val builder = factory.newInstance()
|
val builder = factory.newInstance()
|
||||||
val settings = DefaultSettingsBuildingRequest()
|
val settings = DefaultSettingsBuildingRequest()
|
||||||
|
|
||||||
val localProps = Properties().apply {
|
settings.systemProperties = System.getProperties()
|
||||||
FileInputStream("local.properties").use { fis -> load(fis) }
|
settings.userSettingsFile = File(userHome, ".m2/settings.xml")
|
||||||
}
|
|
||||||
|
|
||||||
val sysProps = System.getProperties()
|
val m2Home = System.getenv("M2_HOME")
|
||||||
|
|
||||||
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")
|
|
||||||
if (m2Home != null) {
|
if (m2Home != null) {
|
||||||
settings.globalSettingsFile = File(m2Home, "conf/settings.xml")
|
settings.globalSettingsFile = File(m2Home, "conf/settings.xml")
|
||||||
}
|
}
|
||||||
|
@ -86,11 +83,16 @@ public class MavenLocalPlugin : BasePlugin(), ILocalMavenRepoPathInterceptor {
|
||||||
val result = builder.build(settings)
|
val result = builder.build(settings)
|
||||||
mvnLocalPath = result.effectiveSettings.localRepository
|
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.")
|
warn("Unable to parse local maven settings.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun repoPath(currentPath: String): String {
|
override fun repoPath(currentPath: String): String {
|
||||||
if (mvnLocalPath != null) {
|
if (mvnLocalPath != null) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<kobalt-plugin>
|
<kobalt-plugin>
|
||||||
<name>kobalt-maven-local</name>
|
<name>Maven Local Repository</name>
|
||||||
<plugin-actors>
|
<plugin-actors>
|
||||||
<class-name>net.thauvin.erik.kobalt.plugin.maven.local.MavenLocalPlugin</class-name>
|
<class-name>net.thauvin.erik.kobalt.plugin.maven.local.MavenLocalPlugin</class-name>
|
||||||
</plugin-actors>
|
</plugin-actors>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue