commit da9aad15e42edc5cf4c62c6be5a0629d21b8d859 Author: Erik C. Thauvin Date: Tue Jan 2 17:45:11 2018 -0800 Initial commit 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 new file mode 100644 index 0000000..fbd6166 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +**/.idea/dictionaries +**/.idea/gradle.xml +**/.idea/libraries +**/.idea/tasks.xml +**/.idea/workspace.xml +*.iws +*.sublime-* +.classpath +.DS_Store +.gradle +.kobalt +.nb-gradle +.project +.settings +/bin +/build +/deploy +/dist +/example/libs +/gen +/gradle.properties +/libs +/out +/proguard-project.txt +/project.properties +/target +/test-output +ehthumbs.db +kobaltBuild +local.properties +Thumbs.db \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..8ff795e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,53 @@ + + + + \ No newline at end of file diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml new file mode 100644 index 0000000..539392b --- /dev/null +++ b/.idea/kobalt.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9dea2e2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..33e190f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6b6a336 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: java + +jdk: + - oraclejdk8 + +before_install: + - chmod +x kobaltw + +install: true + +cache: + directories: + - $HOME/.m2 + - $HOME/.kobalt + +before_cache: + - rm -rf .kobalt/* + +script: ./kobaltw clean assemble test diff --git a/LICENSE.TXT b/LICENSE.TXT new file mode 100644 index 0000000..b7ddd7f --- /dev/null +++ b/LICENSE.TXT @@ -0,0 +1,27 @@ +Copyright (c) 2018, 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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e6c1825 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# pom2xml 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) [![release](http://github-release-version.herokuapp.com/github/ethauvin/kobalt-pom2xml/release.svg?style=flat)](https://github.com/ethauvin/kobalt-pom2xml/releases/latest) [![Build Status](https://travis-ci.org/ethauvin/kobalt-pom2xml.svg?branch=master)](https://travis-ci.org/ethauvin/kobalt-pom2xml) [![Known Vulnerabilities](https://snyk.io/test/github/ethauvin/kobalt-pom2xml/badge.svg)](https://snyk.io/test/github/ethauvin/kobalt-pom2xml) [![CircleCI](https://circleci.com/gh/ethauvin/kobalt-pom2xml/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/kobalt-pom2xml/tree/master) [![Download](https://api.bintray.com/packages/ethauvin/maven/kobalt-pom2xml/images/download.svg) ](https://bintray.com/ethauvin/maven/kobalt-pom2xml/_latestVersion) + + +The plug-in will generate a [Project Object Model](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) (POM) XML file for your project. + +To use the plug-in include the following in `Build.kt` file: + +```kotlin +import net.thauvin.erik.kobalt.plugin.pom2xml.* + +val bs = buildScript { + plugins("net.thauvin.erik:kobalt-pom2xml:") +} + +val p = project { + name = "example" + group = "com.example" + artifactId = name + version = "0.1" + + pom2xml { + + } +} +``` + +The `pom.xml` file will be created in the project's directory. + +[View Example](https://github.com/ethauvin/kobalt-pom2xml/blob/master/example/kobalt/src/Build.kt) + +## Parameters + +The following optional configuration parameters are available. + +Attribute | Description +:---------------|:---------------------------------------------------------------------------------- +`name` | The directory location to save the POM file to, defaults to the project directory. +`loc` | The name of the POM file, defaults to `pom.xml`. + +For example: + +```kotlin + pom2xml { + name = "pom-test.xml" + loc = "foo/bar" + } +``` \ 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/kobalt/src/Build.kt b/example/kobalt/src/Build.kt new file mode 100644 index 0000000..476d477 --- /dev/null +++ b/example/kobalt/src/Build.kt @@ -0,0 +1,46 @@ +import com.beust.kobalt.* +import com.beust.kobalt.plugin.application.* +import com.beust.kobalt.plugin.packaging.* +import net.thauvin.erik.kobalt.plugin.pom2xml.* + +// ./kobaltw pom2xml + +val bs = buildScript { + repos(localMaven()) + plugins("net.thauvin.erik:kobalt-pom2xml:0.1.0") +} + +val p = project { + + name = "example" + group = "com.example" + artifactId = name + version = "0.1" + + 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:3.1") + compile("com.beust:kobalt-plugin-api:0.878") + } + + dependenciesTest { + compile("org.testng:testng:") + } + + assemble { + jar { + } + } + + application { + mainClass = "com.example.MainKt" + } + + pom2xml { + // loc = "foo/bar" + // filename = "pom-example.xml" + } +} \ No newline at end of file diff --git a/example/kobalt/wrapper/kobalt-wrapper.jar b/example/kobalt/wrapper/kobalt-wrapper.jar new file mode 100644 index 0000000..7c076e6 Binary files /dev/null and b/example/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties new file mode 100644 index 0000000..2ca7e45 --- /dev/null +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=1.0.93 diff --git a/example/kobaltw b/example/kobaltw new file mode 100644 index 0000000..c5186d5 --- /dev/null +++ b/example/kobaltw @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/example/kobaltw.bat b/example/kobaltw.bat new file mode 100644 index 0000000..d578071 --- /dev/null +++ b/example/kobaltw.bat @@ -0,0 +1,4 @@ +@echo off +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* 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/example/src/main/kotlin/com/example/Main.kt b/example/src/main/kotlin/com/example/Main.kt new file mode 100644 index 0000000..1df958f --- /dev/null +++ b/example/src/main/kotlin/com/example/Main.kt @@ -0,0 +1,3 @@ +package com.example + +fun main(args: Array) = println("\n\nHello Kotlin world from Kobalt\n\n") \ No newline at end of file diff --git a/example/src/test/kotlin/com/example/MainTest.kt b/example/src/test/kotlin/com/example/MainTest.kt new file mode 100644 index 0000000..96458e9 --- /dev/null +++ b/example/src/test/kotlin/com/example/MainTest.kt @@ -0,0 +1,8 @@ +package com.example + +import org.testng.annotations.Test + +class ExampleTest { + @Test + fun f() = println("Running test") +} \ No newline at end of file diff --git a/kobalt-pom2xml.iml b/kobalt-pom2xml.iml new file mode 100644 index 0000000..f0d4f8e --- /dev/null +++ b/kobalt-pom2xml.iml @@ -0,0 +1,709 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/Build.kt.iml b/kobalt/Build.kt.iml new file mode 100644 index 0000000..19c4d31 --- /dev/null +++ b/kobalt/Build.kt.iml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt new file mode 100644 index 0000000..ed3a622 --- /dev/null +++ b/kobalt/src/Build.kt @@ -0,0 +1,77 @@ +import com.beust.kobalt.buildScript +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 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 { + repos(localMaven()) + plugins("net.thauvin.erik:kobalt-maven-local:") +} + +val dev by profile() +val kobaltDependency = if (dev) "kobalt-plugin-api" else "kobalt-plugin-api" + +val p = project { + + name = "kobalt-pom2xml" + group = "net.thauvin.erik" + artifactId = name + version = "0.1.0" + + pom = Model().apply { + description = "pom2xml plug-in for the Kobalt build system." + url = "https://github.com/ethauvin/kobalt-pom2xml" + licenses = listOf(License().apply { + name = "BSD 3-Clause" + url = "https://opensource.org/licenses/BSD-3-Clause" + }) + scm = Scm().apply { + url = "https://github.com/ethauvin/kobalt-pom2xml" + connection = "https://github.com/ethauvin/kobalt-pom2xml.git" + developerConnection = "git@github.com:ethauvin/kobalt-pom2xml.git" + } + developers = listOf(Developer().apply { + id = "ethauvin" + name = "Erik C. Thauvin" + email = "erik@thauvin.net" + }) + } + + dependencies { + compile("com.beust:$kobaltDependency:") + compile("org.jetbrains.kotlin:kotlin-stdlib:1.2.10") + } + + dependenciesTest { + compile("org.testng:testng:6.12") + } + + assemble { + jar { + fatJar = true + } + + mavenJars { + fatJar = true + } + } + + autoGitTag { + enabled = true + push = false + message = "Version $version" + } + + bintray { + publish = true + description = "Release version $version" + vcsTag = version + } +} \ No newline at end of file diff --git a/kobalt/wrapper/kobalt-wrapper.jar b/kobalt/wrapper/kobalt-wrapper.jar new file mode 100644 index 0000000..7c076e6 Binary files /dev/null and b/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties new file mode 100644 index 0000000..b4f7041 --- /dev/null +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=1.0.93 \ No newline at end of file diff --git a/kobaltw b/kobaltw new file mode 100644 index 0000000..c5186d5 --- /dev/null +++ b/kobaltw @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/kobaltw.bat b/kobaltw.bat new file mode 100644 index 0000000..d578071 --- /dev/null +++ b/kobaltw.bat @@ -0,0 +1,4 @@ +@echo off +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* diff --git a/src/main/kotlin/net/thauvin/erik/kobalt/plugin/pom2xml/Pom2XmlPlugin.kt b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/pom2xml/Pom2XmlPlugin.kt new file mode 100644 index 0000000..edbb137 --- /dev/null +++ b/src/main/kotlin/net/thauvin/erik/kobalt/plugin/pom2xml/Pom2XmlPlugin.kt @@ -0,0 +1,101 @@ +/* + * VersionEyePlugin.kt + * + * Copyright (c) 2018, 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.pom2xml + +import com.beust.kobalt.Plugins +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.warn +import com.google.inject.Inject +import com.google.inject.Singleton + +import java.io.File + +@Singleton +class Pom2XmlPlugin @Inject constructor(private val configActor: ConfigActor, + private val taskContributor: TaskContributor) : + BasePlugin(), ITaskContributor, IConfigActor by configActor { + + // ITaskContributor + override fun tasksFor(project: Project, context: KobaltContext): List = taskContributor.dynamicTasks + + companion object { + const val NAME: String = "pom2xml" + } + + override val name = NAME + + override fun apply(project: Project, context: KobaltContext) { + super.apply(project, context) + taskContributor.addVariantTasks(this, project, context, "pom2xml", group = "publish", + runTask = { pom2xml(project) }) + } + + @Suppress("MemberVisibilityCanPrivate") + @Task(name = "pom2xml", description = "Generate Project Object Model XML file") + fun pom2xml(project: Project): TaskResult { + + // Load configuration + configurationFor(project)?.let { config -> + if (config.name.isNotBlank()) { + val loc = File(config.loc + if (config.loc.endsWith(File.separator)) "" else File.separator) + if (loc.isDirectory) { + // Write POM + File(loc, config.name).writeText(context.generatePom(project)) + } else { + warn("Invalid POM file location: ${loc.absolutePath}") + } + } else { + warn("Invalid POM file name: ${config.name}") + } + } + + return TaskResult() + } +} + +@Directive +class Pom2XmlConfig { + var loc = "." + var name = "pom.xml" +} + +@Suppress("unused") +@Directive +fun Project.pom2xml(init: Pom2XmlConfig.() -> Unit) { + Pom2XmlConfig().let { config -> + config.init() + (Plugins.findPlugin(Pom2XmlPlugin.NAME) as Pom2XmlPlugin).addConfiguration(this, config) + } +} diff --git a/src/main/resources/META-INF/kobalt-plugin.xml b/src/main/resources/META-INF/kobalt-plugin.xml new file mode 100644 index 0000000..c62c3e5 --- /dev/null +++ b/src/main/resources/META-INF/kobalt-plugin.xml @@ -0,0 +1,6 @@ + + pom2xml + + net.thauvin.erik.kobalt.plugin.pom2xml.Pom2XmlPlugin + + \ No newline at end of file