1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Implement localMaven().

This commit is contained in:
Cedric Beust 2016-07-07 19:05:39 -07:00
parent b988e2de23
commit ef516cd919
4 changed files with 53 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package com.beust.kobalt
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.dependency.FileDependency
import org.eclipse.aether.repository.Proxy
@ -72,3 +73,6 @@ fun authRepo(init: HostConfig.() -> Unit) = HostConfig().apply { init() }
@Directive
fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g)
@Directive
fun localMaven() = file(Kobalt.INJECTOR.getInstance(KobaltSettings::class.java).localMavenRepo.path)

View file

@ -92,7 +92,7 @@ open class JvmCompilerPlugin @Inject constructor(
return testContributor.run(project, context, configName,
dependencyManager.testDependencies(project, context))
} else {
log(1, "Couldn't find a test runner for project ${project.name}, did you specify a dependenciesTest{}?")
log(2, "Couldn't find a test runner for project ${project.name}, did you specify dependenciesTest{}?")
return TaskResult()
}
}

View file

@ -20,6 +20,9 @@ class KobaltSettingsXml {
@XmlElement(name = "local-repo") @JvmField
var localRepo: String = homeDir(KFiles.KOBALT_DOT_DIR, "repository")
@XmlElement(name = "local-maven-repo") @JvmField
var localMavenRepo: String = homeDir(KFiles.KOBALT_DOT_DIR, "localMavenRepo")
@XmlElement(name = "default-repos") @JvmField
var defaultRepos: DefaultReposXml? = null
@ -65,10 +68,15 @@ fun List<ProxyConfig>.getProxy(protocol:String) = find { it.type==protocol }
@Singleton
class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
/**
* Location of the local repo.
* Location of the cache repository.
*/
var localRepo = KFiles.makeDir(xmlFile.localRepo) // var for testing
/**
* Location of the local Maven repo for the task deployToLocalMaven
*/
val localMavenRepo = KFiles.makeDir(xmlFile.localMavenRepo)
val defaultRepos = xmlFile.defaultRepos?.repo
val proxyConfigs = with(xmlFile.proxies?.proxy) {

View file

@ -7,17 +7,21 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.DocUrl
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.maven.Md5
import com.beust.kobalt.maven.PomGenerator
import com.beust.kobalt.misc.*
import java.io.File
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import javax.inject.Inject
import javax.inject.Singleton
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER")
@Singleton
public class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGenerator.IFactory,
val bintrayFactory: BintrayApi.IFactory, val github: GithubApi2, val localProperties: LocalProperties)
: BasePlugin() {
val bintrayFactory: BintrayApi.IFactory, val github: GithubApi2, val localProperties: LocalProperties,
val settings: KobaltSettings) : BasePlugin() {
override val name = PLUGIN_NAME
@ -46,7 +50,7 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
requireNotNull(project.artifactId, { "Project $project should have a artifactId" })
}
private val VALID = arrayListOf(".jar", ".pom")
private val VALID = listOf(".jar", ".pom")
private fun findArtifactFiles(project: Project) : List<File> {
val result = files.findRecursively(File(project.directory, project.buildDirectory)) { file ->
@ -55,6 +59,38 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
return result
}
@Task(name = "deployToMavenLocal", description = "Deploy the artifact to Maven local",
dependsOn = arrayOf(TASK_GENERATE_POM, "assemble"))
fun taskDeployToMavenLocal(project: Project): TaskResult {
validateProject(project)
return deployToMavenLocal(project)
}
private fun deployToMavenLocal(project: Project) : TaskResult {
val files = findArtifactFiles(project)
val allFiles = arrayListOf<File>()
// Calculate an MD5 checksum for each file
files.forEach {
allFiles.add(it)
Md5.toMd5(it).let { md5 ->
val md5File = File(it.path + ".md5")
md5File.writeText(md5)
allFiles.add(md5File)
}
}
log(2, "Deploying to local maven " + settings.localMavenRepo)
val groupDir = project.group!!.replace('.', File.separatorChar)
val targetDir = KFiles.makeDir(KFiles.joinDir(settings.localMavenRepo.path, groupDir,
project.artifactId!!, project.version!!))
allFiles.forEach { file ->
log(1, " $file")
KFiles.copy(Paths.get(file.absolutePath), Paths.get(targetDir.path, file.name),
StandardCopyOption.REPLACE_EXISTING)
}
return TaskResult()
}
@Task(name = TASK_UPLOAD_BINTRAY, description = "Upload files to Bintray",
dependsOn = arrayOf(TASK_GENERATE_POM, "assemble"))
fun taskUploadBintray(project: Project): TaskResult {