diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b59dd67 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/openjdk:8-jdk + + working_directory: ~/repo + + environment: + JVM_OPTS: -Xmx3200m + TERM: dumb + + steps: + - checkout + - restore_cache: + keys: + - kobalt-dependencies-{{ checksum "kobalt/src/Build.kt" }} + # fallback to using the latest cache if no exact match is found + - kobalt-dependencies- + + - run: + name: Check Versions + command: ./kobaltw checkVersions + + - save_cache: + paths: ~/.kobalt + key: kobalt-dependencies-{{ checksum "kobalt/src/Build.kt" }} + + - run: + name: Assemble & Test + command: ./kobaltw assemble test + + - store_artifacts: + path: kobaltBuild/test-output/ + destination: test-output + - store_test_results: + path: kobaltBuild/test-output/ \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6ec2ae2 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# batch files are specific to windows and always crlf +*.bat eol=crlf diff --git a/.gitignore b/.gitignore index 80a944b..fbd6166 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ **/.idea/tasks.xml **/.idea/workspace.xml *.iws -.DS_Store +*.sublime-* .classpath +.DS_Store .gradle .kobalt .nb-gradle @@ -18,12 +19,13 @@ /example/libs /gen /gradle.properties +/libs /out /proguard-project.txt /project.properties /target /test-output -Thumbs.db ehthumbs.db kobaltBuild local.properties +Thumbs.db \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index 3423376..9480ac9 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,5 +1,8 @@ + + + - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index dd6ad28..6b87c48 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,6 @@ - diff --git a/.idea/scopes/Copyright.xml b/.idea/scopes/Copyright.xml new file mode 100644 index 0000000..0727526 --- /dev/null +++ b/.idea/scopes/Copyright.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/scopes/Source.xml b/.idea/scopes/Source.xml deleted file mode 100644 index 9f7d724..0000000 --- a/.idea/scopes/Source.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index aa9226e..6b6a336 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,7 @@ cache: - $HOME/.m2 - $HOME/.kobalt -script: ./kobaltw clean assemble +before_cache: + - rm -rf .kobalt/* + +script: ./kobaltw clean assemble test diff --git a/LICENSE.TXT b/LICENSE.TXT index 84fe1dc..f30d392 100644 --- a/LICENSE.TXT +++ b/LICENSE.TXT @@ -1,4 +1,4 @@ -Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) +Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net) All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index fddb4f6..316d7cf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # 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) [![release](https://img.shields.io/github/release/ethauvin/kobalt-versioneye.svg)](https://github.com/ethauvin/kobalt-versioneye/releases/latest) [![Build Status](https://travis-ci.org/ethauvin/kobalt-versioneye.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-versioneye) [![CircleCI](https://circleci.com/gh/ethauvin/kobalt-versioneye/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/kobalt-versioneye/tree/master) [![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) +[![VersionEye Logo](https://github.com/ethauvin/kobalt-versioneye/raw/master/src/site/images/VersionEyeLogo.png)](https://www.versioneye.com) The plug-in will create and update projects on [VersionEye](https://www.versioneye.com/), a service that notifies you about outdated dependencies, security vulnerabilities and license violations. @@ -20,9 +20,9 @@ val p = project { group = "com.example" artifactId = name version = "0.1" - + versionEye { - + } } ``` @@ -30,7 +30,7 @@ val p = project { To create or update your project on VersionEye, you will need an API key. If you are [signed up](https://www.versioneye.com/signup), you can find your API Key [here](https://www.versioneye.com/settings/api): -[![VersionEye API Key](src/site/images/VersionEyeApiKey.png)](https://www.versioneye.com/settings/api) +[![VersionEye API Key](https://github.com/ethauvin/kobalt-versioneye/raw/master/src/site/images/VersionEyeApiKey.png)](https://www.versioneye.com/settings/api) To create your project on VersionEye simply use your API Key as follows @@ -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: @@ -126,4 +127,27 @@ versionEye { | `Fail.dependenciesCheck` | Will triggered a failure on outdated dependencies. | | `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. | \ No newline at end of file +| `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). \ No newline at end of file diff --git a/clean.sh b/clean.sh new file mode 100644 index 0000000..552252d --- /dev/null +++ b/clean.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +DEBUG=false + +rm="rm -rf" + +if [ "$DEBUG" = true ]; then + rm="echo rm -rf" +fi + +buildkt="kobalt/src/Build.kt" + +name=$(cat $buildkt | grep -m 1 "name = " | cut -d"\"" -f 2) +group=$(cat $buildkt | grep -m 1 "group = " | cut -d"\"" -f 2) + +if [ -z "$1" ]; then + version=$(cat $buildkt | grep -m 1 "version = " | cut -d"\"" -f 2) +else + version="$1" +fi + +maven="/k/maven/repository/${group//.//}/${name}/${version}" +kobalt="$HOME/.kobalt/cache/${group//.//}/${name}/${version}" +localRepo="$HOME/.kobalt/localMavenRepo/${group//.//}/${name}/${version}" + +read -p "Delete version ${version}? " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + for dir in "$kobalt" "$maven" "$localRepo"; do + if [ -d "$dir" ]; then + echo -e "Deleting : \e[32;1m$dir\e[0m" + $rm "$dir" + else + echo -e "Not Found: \e[31;1m$dir\e[0m" + fi + done +fi \ No newline at end of file diff --git a/example/example.iml b/example/example.iml deleted file mode 100644 index f96dda4..0000000 --- a/example/example.iml +++ /dev/null @@ -1,484 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt index 766bcc1..05337da 100644 --- a/example/kobalt/src/Build.kt +++ b/example/kobalt/src/Build.kt @@ -6,6 +6,7 @@ import net.thauvin.erik.kobalt.plugin.versioneye.* // ./kobaltw versionEye val bs = buildScript { + repos(localMaven()) plugins("net.thauvin.erik:kobalt-versioneye:") } @@ -16,20 +17,12 @@ val p = project { artifactId = name version = "0.1" - sourceDirectories { - path("src/main/kotlin") - } - - sourceDirectoriesTest { - path("src/test/kotlin") - } - dependencies { compile("com.beust:jcommander:1.47") //compile("org.slf4j:slf4j-api:") compile("ch.qos.logback:logback-core:0.5") compile("ch.qos.logback:logback-classic:1.1.7") - compile("commons-httpclient:commons-httpclient:jar:3.1") + compile("commons-httpclient:commons-httpclient:3.1") compile("com.beust:kobalt-plugin-api:0.878") } @@ -51,8 +44,10 @@ val p = project { // colors = true // name = "" // org = "" + pom = true // quiet = false // team = "" + temp = true // verbose = true // visibility = "public" diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties index f3cd7d1..a6a4316 100644 --- a/example/kobalt/wrapper/kobalt-wrapper.properties +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.6 \ No newline at end of file +kobalt.version=1.0.90 diff --git a/example/pom.xml b/example/pom.xml new file mode 100644 index 0000000..7b9976b --- /dev/null +++ b/example/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + com.example + example + 0.1 + example + + + + com.beust + jcommander + 1.47 + + + ch.qos.logback + logback-core + 0.5 + + + ch.qos.logback + logback-classic + 1.1.7 + + + commons-httpclient + commons-httpclient + 3.1 + + + com.beust + kobalt-plugin-api + 0.878 + + + org.testng + testng + (0,] + test + + + diff --git a/kobalt-versioneye.iml b/kobalt-versioneye.iml index 0f2eb63..939539f 100644 --- a/kobalt-versioneye.iml +++ b/kobalt-versioneye.iml @@ -1,6 +1,6 @@ - + @@ -12,10 +12,73 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -85,9 +148,72 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -201,15 +327,6 @@ - - - - - - - - - @@ -246,19 +363,73 @@ - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -354,15 +525,6 @@ - - - - - - - - - @@ -426,8 +588,35 @@ + + + + + + + + + - + + + + + + + + + + + + + + + + + + + @@ -435,5 +624,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/Build.kt.iml b/kobalt/Build.kt.iml index 66ab158..a832213 100644 --- a/kobalt/Build.kt.iml +++ b/kobalt/Build.kt.iml @@ -1,8 +1,8 @@ - - - + + + @@ -10,22 +10,33 @@ - + - + - + - + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 61a096a..eb19a69 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,37 +1,30 @@ import com.beust.kobalt.buildScript -import com.beust.kobalt.file -import com.beust.kobalt.misc.kobaltLog -import com.beust.kobalt.plugin.application.application +import com.beust.kobalt.localMaven import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.publish.autoGitTag import com.beust.kobalt.plugin.publish.bintray +import com.beust.kobalt.profile import com.beust.kobalt.project import net.thauvin.erik.kobalt.plugin.versioneye.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 -import java.io.File - -val semver = "0.4.4" val bs = buildScript { - val p = with(File("kobaltBuild/libs/kobalt-versioneye-$semver.jar")) { - if (exists()) { - kobaltLog(1, " >>> Using: $path") - file(path) - } else { - "net.thauvin.erik:kobalt-versioneye:" - } - } - plugins(p) + repos(localMaven()) + plugins("net.thauvin.erik:kobalt-maven-local:", "net.thauvin.erik:kobalt-versioneye:") } +val dev by profile() +val kobaltDependency = if (dev) "kobalt" else "kobalt-plugin-api" + val p = project { name = "kobalt-versioneye" group = "net.thauvin.erik" artifactId = name - version = semver + version = "0.4.6" pom = Model().apply { description = "VersionEye plug-in for the Kobalt build system." @@ -52,83 +45,41 @@ val p = project { }) } - sourceDirectories { - path("src/main/kotlin") - } - - sourceDirectoriesTest { - path("src/test/kotlin") - } - dependencies { - compile("com.beust:kobalt-plugin-api:") + compileOnly("com.beust:$kobaltDependency:") + compile("org.jetbrains.kotlin:kotlin-stdlib:1.1.51") + compile("com.squareup.okhttp3:logging-interceptor:jar:3.9.0") } dependenciesTest { - compile("org.testng:testng:") - - } - - assemble { - mavenJars {} - } - - bintray { - publish = true - } -} - -val example = project(p) { - - name = "example" - group = "com.example" - artifactId = name - version = "0.1" - directory = "example" - - sourceDirectories { - path("src/main/kotlin") - } - - sourceDirectoriesTest { - path("src/test/kotlin") - } - - dependencies { - compile("com.beust:jcommander:1.47") - //compile("org.slf4j:slf4j-api:") - compile("ch.qos.logback:logback-core:0.5") - compile("ch.qos.logback:logback-classic:1.1.7") - compile("commons-httpclient:commons-httpclient:jar:3.1") - compile("com.beust:kobalt-plugin-api:0.878") - } - - - - dependenciesTest { - compile("org.testng:testng:") + compile("org.testng:testng:6.12") } assemble { jar { + fatJar = true + } + + mavenJars { + fatJar = true } } - application { - mainClass = "com.example.MainKt" + autoGitTag { + enabled = true + push = false + message = "Version $version" + } + + bintray { + publish = true + description = "Release version $version" + vcsTag = version } versionEye { - // baseUrl = "https://www.versioneye.com/" - // colors = true - // name = "" - // org = "" - // quiet = false - // team = "" - // verbose = true - // visibility = "public" - - //failOn(Fail.licensesUnknownCheck, Fail.licensesCheck, Fail.securityCheck, Fail.dependenciesCheck) + org = "thauvin" + team = "Owners" + pom = true } -} - +} \ No newline at end of file diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index f3cd7d1..a6a4316 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=1.0.6 \ No newline at end of file +kobalt.version=1.0.90 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..22488cf --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + net.thauvin.erik + kobalt-versioneye + 0.4.6 + kobalt-versioneye + VersionEye plug-in for the Kobalt build system. + https://github.com/ethauvin/kobalt-versioneye + + + BSD 3-Clause + https://opensource.org/licenses/BSD-3-Clause + + + + + ethauvin + Erik C. Thauvin + erik@thauvin.net + + + + https://github.com/ethauvin/kobalt-versioneye.git + git@github.com:ethauvin/kobalt-versioneye.git + https://github.com/ethauvin/kobalt-versioneye + + + + com.squareup.okhttp3 + logging-interceptor + 3.8.0 + + + org.testng + testng + 6.11 + test + + + diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt index 4188480..b8a86ce 100644 --- a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyePlugin.kt @@ -44,6 +44,8 @@ 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 @@ -54,13 +56,22 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor 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 httpClient = OkHttpClient() + private val proxy = System.getProperty("ve.proxy", "-1").toInt() + + private val httpClient = if (!debug) { + OkHttpClient() + } else { + OkHttpClient().newBuilder().addInterceptor( + HttpLoggingInterceptor({ message -> log(2, "[HTTP] $message") }) + .apply { level = HttpLoggingInterceptor.Level.BODY }).build() + } // ITaskContributor override fun tasksFor(project: Project, context: KobaltContext): List = taskContributor.dynamicTasks @@ -79,15 +90,15 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor @@ -124,11 +135,25 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor - p.store(output, "") + p.store(output, null) } return result @@ -185,15 +210,13 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor 0 - val isFailLicense = Utils.isFail(config.failSet, Fail.licensesCheck) && licenses_red > 0 - val isFailUnknown = Utils.isFail(config.failSet, Fail.licensesUnknownCheck) && licenses_unknown > 0 - val isFailSecurity = Utils.isFail(config.failSet, Fail.securityCheck) && sv_count > 0 + val isFailDeps = VersionEyeUtils.isFail(config.failSet, Fail.dependenciesCheck) && out_number > 0 + val isFailLicense = VersionEyeUtils.isFail(config.failSet, Fail.licensesCheck) && licenses_red > 0 + val isFailUnknown = VersionEyeUtils.isFail(config.failSet, Fail.licensesUnknownCheck) && licenses_unknown > 0 + val isFailSecurity = VersionEyeUtils.isFail(config.failSet, Fail.securityCheck) && sv_count > 0 // Unknown dependencies var unknownDeps = 0 @@ -258,14 +280,14 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor UNKNOWN", unknownDeps, false, config.colors)) + depsInfo.append(VersionEyeUtils.redLight(" - $depName -> UNKNOWN", unknownDeps, false, config.colors)) } else if (dep.get("outdated").asBoolean) { if (depsInfo.isNotEmpty()) { depsInfo.append(lf) } - depsInfo.append(Utils.redLight(" - $depName -> " + depsInfo.append(VersionEyeUtils.redLight(" - $depName -> " + curVer.asString, out_number, isFailDeps, config.colors) - + Utils.alt(isFailDeps && !config.colors)) + + VersionEyeUtils.alt(isFailDeps && !config.colors)) } // Parse licenses @@ -296,9 +318,9 @@ class VersionEyePlugin @Inject constructor(val configActor: ConfigActor = mutableSetOf(Fail.securityCheck) var name = "" var org = "" + var pom = false var quiet = false var team = "" + var temp = false var verbose = true var visibility = "public" diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/Utils.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtils.kt similarity index 79% rename from src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/Utils.kt rename to src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtils.kt index 57a38fa..c3733c8 100644 --- a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/Utils.kt +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtils.kt @@ -1,5 +1,5 @@ /* - * Utils.kt + * VersionEyeUtils.kt * * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. @@ -34,7 +34,7 @@ package net.thauvin.erik.kobalt.plugin.versioneye import com.beust.kobalt.AsciiArt import com.beust.kobalt.misc.log -open class Utils { +open class VersionEyeUtils private constructor() { companion object { // Non-colors failure fun alt(failed: Boolean): String { @@ -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 diff --git a/src/test/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtilsTest.kt b/src/test/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtilsTest.kt new file mode 100644 index 0000000..3778931 --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/kobalt/plugin/versioneye/VersionEyeUtilsTest.kt @@ -0,0 +1,103 @@ +/* + * VersionEyeUtilsTest.kt + * + * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.thauvin.erik.kobalt.plugin.versioneye + +import com.beust.kobalt.AsciiArt +import org.testng.Assert +import org.testng.annotations.Test + +@Test +class VersionEyeUtilsTest { + val text = "This is a test" + + @Test + fun alt() { + Assert.assertEquals(VersionEyeUtils.alt(false), "", "alt(false") + Assert.assertEquals(VersionEyeUtils.alt(true), " [FAILED]", "alt(true)") + } + + @Test + fun plural() { + val singular = "foo" + val plural = "s" + Assert.assertEquals(VersionEyeUtils.plural(singular, 0, plural), singular, "plural($singular, count:0, $plural)") + Assert.assertEquals(VersionEyeUtils.plural(singular, 1, plural), singular, "plural($singular, count:1, $plural)") + Assert.assertEquals(VersionEyeUtils.plural(singular, 2, plural), singular + plural, "plural($singular, count:2," + + "$plural)") + + val text = "vulnerabilit" + val y = "y" + val ies = "ies" + Assert.assertEquals(VersionEyeUtils.plural(text, 0, ies, y), text + y, "plural($text, count:0, $ies, $y)") + Assert.assertEquals(VersionEyeUtils.plural(text, 1, ies, y), text + y, "plural($text, count:1, $ies, $y)") + Assert.assertEquals(VersionEyeUtils.plural(text, 2, ies, y), text + ies, "plural($text, count:2, $ies, $y)") + } + + @Test + fun red() { + Assert.assertEquals(VersionEyeUtils.red(text), AsciiArt.RED + text + AsciiArt.RESET, "red($text)") + Assert.assertEquals(VersionEyeUtils.red(text, false), text, "red($text)") + } + + @Test + fun yellow() { + Assert.assertEquals(VersionEyeUtils.yellow(text), AsciiArt.YELLOW + text + AsciiArt.RESET, "yellow($text)") + Assert.assertEquals(VersionEyeUtils.yellow(text, false), text, "yellow($text)") + } + + @Test + fun green() { + Assert.assertEquals(VersionEyeUtils.green(text), AsciiArt.GREEN + text + AsciiArt.RESET, "green($text)") + Assert.assertEquals(VersionEyeUtils.green(text, false), text, "green($text)") + } + + @Test + fun redLight() { + Assert.assertEquals(VersionEyeUtils.redLight(text, 1, true, true), AsciiArt.RED + text + AsciiArt.RESET, + "redLight($text, count:1, fail:true, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(text, 1, false, true), AsciiArt.YELLOW + text + AsciiArt.RESET, + "redLight($text, count:1, fail:false, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(text, 0, false, true), AsciiArt.GREEN + text + AsciiArt.RESET, + "redLight($text, count:0, fail:false, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(text, 1, false, false), text, + "redLight($text, count:1, fail:false, colors:false)") + + Assert.assertEquals(VersionEyeUtils.redLight(1, true, true), AsciiArt.RED + 1 + AsciiArt.RESET, + "redLight(count:1, fail:true, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(1, false, true), AsciiArt.YELLOW + 1 + AsciiArt.RESET, + "redLight(count:1, fail:false, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(0, false, true), AsciiArt.GREEN + 0 + AsciiArt.RESET, + "redLight(count:0, fail:false, colors:true)") + Assert.assertEquals(VersionEyeUtils.redLight(1, false, false), "1", + "redLight(count:1, fail:false, colors:false)") + } +} \ No newline at end of file