Added pom.xml generation.

This commit is contained in:
Erik C. Thauvin 2017-04-25 09:11:06 -07:00
parent f5ab25b10e
commit 53cff85983
8 changed files with 173 additions and 48 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
**/.idea/tasks.xml
**/.idea/workspace.xml
*.iws
*.sublime-*
.classpath
.DS_Store
.gradle

View file

@ -1,6 +1,6 @@
# VersionEye plug-in for [Kobalt](http://beust.com/kobalt/home/index.html)
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Build Status](https://travis-ci.org/ethauvin/kobalt-versioneye.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-versioneye) [![Download](https://api.bintray.com/packages/ethauvin/maven/kobalt-versioneye/images/download.svg) ](https://bintray.com/ethauvin/maven/kobalt-versioneye/_latestVersion)
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Build Status](https://travis-ci.org/ethauvin/kobalt-versioneye.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-versioneye) [![Dependency Status](https://www.versioneye.com/user/projects/58ff729f6ac171425cd00acf/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/58ff729f6ac171425cd00acf) [![Download](https://api.bintray.com/packages/ethauvin/maven/kobalt-versioneye/images/download.svg) ](https://bintray.com/ethauvin/maven/kobalt-versioneye/_latestVersion)
[![VersionEye Logo](src/site/images/VersionEyeLogo.png)](https://www.versioneye.com)
@ -90,16 +90,17 @@ versionEye {
The values are:
| Value | Description | Default |
| :----------- | :---------------------------------------------------------------------------------------------- | :---------------------------- |
| `baseUrl` | For VersionEye Enterprise VM to use your own domain, e.g. `https://versioneye.my-company.com/` | `https://www.versioneye.com/` |
| `colors` | To enable (`true`) or disable (`false`) colors in the plug-in output. | `true` |
| `name` | The name of the VersionEye project, if none is specified the Kobalt project name will be used. | *none* |
| `quiet` | To completely disable output from the plug-in. | `false` |
| `org` | The VersionEye organization, if any. | *none* |
| `team` | The VersionEye team, if any. | *none* |
| `verbose` | To enable or disable extra information in the plug-in output. | `true` |
| `visibility` | To set the project's visibility on VersionEye, either `public` or `private` | `public` |
| Value | Description | Default |
| :----------- | :--------------------------------------------------------------------------------------------------------------------- | :---------------------------- |
| `baseUrl` | For VersionEye Enterprise VM to use your own domain, e.g. `https://versioneye.my-company.com/` | `https://www.versioneye.com/` |
| `colors` | To enable (`true`) or disable (`false`) colors in the plug-in output. | `true` |
| `name` | The name of the VersionEye project, if none is specified the Kobalt project name will be used. | *none* |
| `quiet` | To completely disable output from the plug-in. | `false` |
| `org` | The VersionEye organization, if any. | *none* |
| `pom` | Generate a [pom.xml](https://maven.apache.org/pom.html) for the project. See [Private vs. Public](#private-vs-public). | `false` |
| `team` | The VersionEye team, if any. | *none* |
| `verbose` | To enable or disable extra information in the plug-in output. | `true` |
| `visibility` | To set the project's visibility on VersionEye, either `public` or `private` | `public` |
Some of the parameters can be controlled temporarily from the command line, as follows:
@ -127,3 +128,26 @@ versionEye {
| `Fail.licensesUnknownCheck` | Will trigger a failure on unknown licenses. |
| `Fail.licensesCheck` | Will trigger a failure on licenses whitelist violations. Licenses and components whitelists can be configured on the [VersionEye](https://www.versioneye.com/) website. |
| `Fail.securityCheck` | Will trigger a failure on known security vulnerabilities, on by default. |
## Private vs. Public
By default, projects created using the VersionEye API are private. If your project is hosted on [GitHub](https://github.com) or [BitBucket](https://bitbucket.org) and would like to make it public on VersionEye. The plug-in can generate a [pom](https://maven.apache.org/pom.html) file compatible with VersionEye, as follows:
```
versionEye {
pom = true
...
}
```
and to generate the pom file, but **not** create a new project on VersionEye:
```bash
./kobaltw -Dve.create=false versionEye
```
Be sure to commit `pom.xml` on GitHub or BitBucket, and then import your project at:
* https://www.versioneye.com/projects/new
Finally, configure your [project key](#global-configuration).

View file

@ -6,8 +6,8 @@ import net.thauvin.erik.kobalt.plugin.versioneye.*
// ./kobaltw versionEye
val bs = buildScript {
//plugins(file("../kobaltBuild/libs/kobalt-versioneye-0.4.5.jar"))
plugins("net.thauvin.erik:kobalt-versioneye:")
repos(file("K:/maven/repository"))
plugins("net.thauvin.erik:kobalt-versioneye:0.4.5")
}
val p = project {
@ -44,8 +44,10 @@ val p = project {
// colors = true
// name = ""
// org = ""
pom = true
// quiet = false
// team = ""
temp = true
// verbose = true
// visibility = "public"

43
example/pom.xml Normal file
View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>0.1</version>
<name>example</name>
<description></description>
<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.47</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>kobalt-plugin-api</artifactId>
<version>0.878</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>(0,]</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -1,12 +1,20 @@
import com.beust.kobalt.*
import com.beust.kobalt.buildScript
import com.beust.kobalt.file
import com.beust.kobalt.plugin.packaging.assemble
import com.beust.kobalt.plugin.publish.autoGitTag
import com.beust.kobalt.plugin.publish.bintray
import org.apache.maven.model.*
import com.beust.kobalt.profile
import com.beust.kobalt.project
import net.thauvin.erik.kobalt.plugin.versioneye.*
import org.apache.maven.model.Developer
import org.apache.maven.model.License
import org.apache.maven.model.Model
import org.apache.maven.model.Scm
val bs = buildScript {
plugins("net.thauvin.erik:kobalt-maven-local:")
repos(localMaven())
repos(file("K:/maven/repository"))
plugins("net.thauvin.erik:kobalt-maven-local:0.5.2", "net.thauvin.erik:kobalt-versioneye:0.4.5")
}
val dev by profile()
@ -40,7 +48,7 @@ val p = project {
dependencies {
compile("com.beust:$kobaltDependency:")
compile("com.squareup.okhttp3:logging-interceptor:jar:3.6.0")
compile("com.squareup.okhttp3:logging-interceptor:jar:3.7.0")
}
dependenciesTest {
@ -48,7 +56,13 @@ val p = project {
}
assemble {
mavenJars {}
jar {
fatJar = true
}
mavenJars {
fatJar = true
}
}
autoGitTag {
@ -61,4 +75,8 @@ val p = project {
description = "Release version $version"
vcsTag = version
}
versionEye {
pom = true
}
}

View file

@ -35,7 +35,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.6.0</version>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>

View file

@ -67,6 +67,27 @@ open class Utils {
}
fun red(text: String, colors: Boolean = true): String {
if (!colors) {
return text
}
return AsciiArt.RED + text + AsciiArt.RESET
}
fun yellow(text: String, colors: Boolean = true): String {
if (!colors) {
return text
}
return AsciiArt.YELLOW + text + AsciiArt.RESET
}
fun green(text: String, colors: Boolean = true): String {
if (!colors) {
return text
}
return AsciiArt.GREEN + text + AsciiArt.RESET
}
fun redLight(count: Int, fail: Boolean, colors: Boolean): String {
return redLight(count.toString(), count, fail, colors)
}
@ -75,11 +96,11 @@ open class Utils {
fun redLight(text: String, count: Int, fail: Boolean, colors: Boolean): String {
if (colors) {
if (fail && count > 0) {
return AsciiArt.RED + text + AsciiArt.RESET
return red(text)
} else if (count > 0) {
return AsciiArt.YELLOW + text + AsciiArt.RESET
return yellow(text)
} else {
return AsciiArt.GREEN + text + AsciiArt.RESET
return green(text)
}
}
return text

View file

@ -36,13 +36,16 @@ import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.misc.*
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import com.google.inject.Inject
import com.google.inject.Singleton
import okhttp3.*
import okhttp3.logging.HttpLoggingInterceptor
import java.io.File
import java.io.FileOutputStream
import java.nio.file.Files
import java.nio.file.Paths
@ -53,13 +56,14 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
val taskContributor: TaskContributor) :
BasePlugin(), ITaskContributor, IConfigActor<VersionEyeConfig> by configActor {
private val API_KEY_PROPERTY = "versioneye.apiKey"
private val PROJECT_KEY_PROPERTY = "versioneye.projectKey"
private val COLORS_PROPERTY = "ve.colors"
private val VERBOSE_PROPERTY = "ve.verbose"
private val CREATE_PROPERTY = "ve.create"
private val PROJECT_KEY_PROPERTY = "versioneye.projectKey"
private val QUIET_PROPERTY = "ve.quiet"
private val VERBOSE_PROPERTY = "ve.verbose"
private val debug = System.getProperty("ve.debug", "false").toBoolean()
private val fiddler = System.getProperty("ve.fiddler", "false").toBoolean()
private val proxy = System.getProperty("ve.proxy", "-1").toInt()
private val httpClient = if (!debug) {
OkHttpClient()
@ -86,13 +90,12 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
@Task(name = "versionEye", description = "Update and check dependencies on VersionEye")
fun versionEye(project: Project): TaskResult {
if (fiddler) {
val port = 9898
log(1, " Using Fiddler proxy 127.0.0.1:$port")
if (proxy != -1) {
log(1, " Using proxy 127.0.0.1:$proxy")
System.setProperty("http.proxyHost", "127.0.0.1")
System.setProperty("https.proxyHost", "127.0.0.1")
System.setProperty("http.proxyPort", "$port")
System.setProperty("https.proxyPort", "$port")
System.setProperty("http.proxyPort", "$proxy")
System.setProperty("https.proxyPort", "$proxy")
}
val local = "${project.directory}/local.properties"
@ -132,11 +135,25 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
// Config parameters
config.colors = System.getProperty(COLORS_PROPERTY, config.colors.toString()).toBoolean()
config.verbose = System.getProperty(VERBOSE_PROPERTY, config.verbose.toString()).toBoolean()
config.quiet = System.getProperty(QUIET_PROPERTY, config.quiet.toString()).toBoolean()
config.verbose = System.getProperty(VERBOSE_PROPERTY, config.verbose.toString()).toBoolean()
// Get pom & proceed with update
val pom = context.generatePom(project)
// Write the pom
if (config.pom) {
File("pom.xml").writeText(pom)
// Don't create a new project
if (!System.getProperty(CREATE_PROPERTY, "true").toBoolean() && projectKey.isNullOrBlank()) {
log(1, " Be sure to commit pom.xml, and import your project at:")
log(1, Utils.yellow("\n\t${config.baseUrl}/projects/new\n", config.colors))
log(1, " Then configure your project key.")
return TaskResult()
}
}
val result = versionEyeUpdate(if (config.name.isNotBlank()) {
config.name
} else {
@ -145,7 +162,7 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
// Save properties
FileOutputStream(local).use { output ->
p.store(output, "")
p.store(output, null)
}
return result
@ -193,15 +210,13 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
}
// Set visibility
if (config.visibility.isNotBlank()) {
if (config.visibility.equals("private", true)) {
requestBody.addFormDataPart("visibility", "private")
} else if (config.visibility.equals("public", true)) {
requestBody.addFormDataPart("visibility", "public")
}
if (config.visibility.isNotBlank() && config.visibility.equals("private", true)) {
requestBody.addFormDataPart("visibility", "private")
} else {
requestBody.addFormDataPart("visibility", "public")
}
if (debug) {
if (config.temp) {
requestBody.addFormDataPart("temp", "true")
}
@ -215,16 +230,15 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor<VersionE
.post(requestBody.build())
.build()
// Execute and handle reques
// Execute and handle request
val response = httpClient.newCall(request).execute()
// Parse json response
val o = GsonBuilder().create().fromJson(response.body().charStream(), JsonObject::class.java)
if (!response.isSuccessful) {
warn("Unexpected response from VersionEye: $response")
// Parse json response
warn("Unexpected response from VersionEye: " + (o.get("error").asString ?: response.message()))
return TaskResult()
} else {
// Parse json response
val builder = GsonBuilder()
val o = builder.create().fromJson(response.body().charStream(), JsonObject::class.java)
// Get project key
if (projectKey.isNullOrBlank()) {
projectKey = o.get("id").asString
@ -384,8 +398,10 @@ class VersionEyeConfig {
val failSet: MutableSet<Fail> = mutableSetOf(Fail.securityCheck)
var name = ""
var org = ""
var pom = false
var quiet = false
var team = ""
var temp = false
var verbose = true
var visibility = "public"