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

Better pom generation.

This commit is contained in:
Cedric Beust 2016-07-11 22:34:20 -08:00
parent 71a9dac639
commit 86abfc3d80
4 changed files with 24 additions and 66 deletions

View file

@ -4,6 +4,7 @@ import com.beust.kobalt.TestConfig
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KFiles
import org.apache.maven.model.Model
import java.io.File
import java.util.*
import java.util.concurrent.Future
@ -18,9 +19,8 @@ open class Project(
@Directive open var artifactId: String? = null,
@Directive open var packaging: String? = null,
@Directive open var description : String = "",
@Directive open var scm : Scm? = null,
@Directive open var url: String? = null,
@Directive open var licenses: List<License> = arrayListOf<License>(),
@Directive open var pom: Model? = null,
@Directive open var dependsOn: ArrayList<Project> = arrayListOf<Project>(),
@Directive open var packageName: String? = group)
: IBuildConfig, IDependencyHolder by DependencyHolder() {
@ -164,18 +164,6 @@ class Dependencies(val project: Project,
fun native(vararg dep: String) = addToDependencies(project, nativeDependencies, dep)
}
class Scm(val connection: String, val developerConnection: String, val url: String)
class License(val name: String, val url: String) {
fun toMavenLicense() : org.apache.maven.model.License {
val result = org.apache.maven.model.License()
result.name = name
result.url = url
return result
}
}
class BuildConfig {
class Field(val name: String, val type: String, val value: Any) {
override fun hashCode() = name.hashCode()

View file

@ -21,9 +21,6 @@ class PomProject {
var description: String? = null
var url: String? = null
var packaging: String? = null
var licenses : Licenses? = null
var developers: Developers? = null
var scm: Scm? = null
var properties: Properties? = null
var parent: Parent? = null
@XmlElement(name = "dependencies") @JvmField
@ -46,12 +43,6 @@ class PomProject {
}
}
//fun main(argv: Array<String>) {
// val p = Pom2(File("/Users/beust/t/pom.xml"))
// val pom = p.pom
// println("Dependencies: " + pom.dependencies[0])
//}
class Either<E, V>(val exception: E?, val value: V?)
class Pom2(val pomProject: PomProject) {
@ -165,12 +156,6 @@ class Dependency {
}
}
class Scm {
var connection: String? = null
var developerConnection: String? = null
var url: String? = null
}
class Parent {
var groupId: String? = null
var artifactId: String? = null

View file

@ -7,14 +7,13 @@ import com.beust.kobalt.misc.log
import com.google.inject.assistedinject.Assisted
import org.apache.maven.model.Developer
import org.apache.maven.model.Model
import org.apache.maven.model.Scm
import org.apache.maven.model.io.xpp3.MavenXpp3Writer
import java.io.File
import java.io.StringWriter
import java.nio.charset.Charset
import javax.inject.Inject
public class PomGenerator @Inject constructor(@Assisted val project: Project) {
class PomGenerator @Inject constructor(@Assisted val project: Project) {
interface IFactory {
fun create(project: Project) : PomGenerator
}
@ -24,26 +23,24 @@ public class PomGenerator @Inject constructor(@Assisted val project: Project) {
requireNotNull(project.group, { "group mandatory on project ${project.name}" })
requireNotNull(project.artifactId, { "artifactId mandatory on project ${project.name}" })
val m = Model().apply {
name = project.name
artifactId = project.artifactId
groupId = project.group
version = project.version
description = project.description
licenses = project.licenses.map { it.toMavenLicense() }
url = project.url
scm = Scm().apply {
project.scm?.let {
url = it.url
connection = it.connection
developerConnection = it.developerConnection
val m =
if (project.pom == null) {
// No pom specified, create one with default values
Model().apply {
name = project.name
artifactId = project.artifactId
groupId = project.group
version = project.version
description = project.description
url = project.url
developers = listOf(Developer().apply {
name = SystemProperties.username
})
}
} else {
// Use the pom specified on the project
project.pom!!
}
}
with(Developer()) {
name = SystemProperties.username
m.addDeveloper(this)
}
//
// Dependencies

View file

@ -6,30 +6,18 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.Gpg
import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.Md5
import com.beust.kobalt.misc.CountingFileRequestBody
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.error
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import com.beust.kobalt.misc.*
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.gson.TypeAdapter
import com.google.gson.reflect.TypeToken
import com.google.inject.assistedinject.Assisted
import okhttp3.Credentials
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.RequestBody
import okhttp3.ResponseBody
import okhttp3.*
import retrofit2.Call
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.*
import java.io.File
import java.lang.reflect.Type
import javax.annotation.Nullable
@ -113,10 +101,10 @@ class BintrayApi @Inject constructor(val http: Http,
val jsonObject = JsonObject()
jsonObject.addNonNull("name", project.name)
jsonObject.addNonNull("desc", project.description)
jsonObject.addNonNull("vcs_url", project.scm?.url)
jsonObject.addNonNull("vcs_url", project.pom?.scm?.url)
jsonObject.addNonNull("website_url", project.url)
val licenses = JsonArray()
project.licenses.forEach {
project.pom?.licenses?.forEach {
licenses.add(it.name)
}
jsonObject.add("licenses", licenses)